From 371d04d83615203b3a26e6ad7dd618b5a1af7037 Mon Sep 17 00:00:00 2001 From: Roshan Sinhabhu Date: Mon, 31 Aug 2026 14:43:37 +0530 Subject: [PATCH] fix: Fix the dark mode and make the mode toggle switch in the navbar --- package-lock.json | 8 ------- src/App.css | 33 +++++++++++++++++---------- src/components/Dark-Mode.jsx | 41 ++++++++++++++-------------------- src/components/Navbar.jsx | 3 +++ src/index.css | 43 ++++++++++++++++++++++++++---------- 5 files changed, 72 insertions(+), 56 deletions(-) diff --git a/package-lock.json b/package-lock.json index 60164f1..f8f91f2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -54,7 +54,6 @@ "integrity": "sha512-RgHBCvtjbOK2gXSNBNIkNoEc9qoVEtau3hj8gEqKQuL3HZAibKarWFEI3Lfm6EYKkLalOh8eSrj9b+ch9H/VBA==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@babel/code-frame": "^7.29.7", "@babel/generator": "^7.29.7", @@ -1325,7 +1324,6 @@ "integrity": "sha512-vfEqpXTvwT91yhmwdfouStN2hSKwTvyRs8qpLfADyrq/kxDw0hZM7Wk9Ug1FELj8hIby+S/+kQCSRFF32nv2Qw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@types/prop-types": "*", "csstype": "^3.2.2" @@ -1375,7 +1373,6 @@ "integrity": "sha512-lGq+9yr1/GuAWaVYIHRjvvySG5/4VfKIvC8EWxStPdcDh/Ka7FG3twP6v4d5BkravUilhIAsG4Qj83t02LWUPQ==", "dev": true, "license": "MIT", - "peer": true, "bin": { "acorn": "bin/acorn" }, @@ -1658,7 +1655,6 @@ } ], "license": "MIT", - "peer": true, "dependencies": { "baseline-browser-mapping": "^2.10.44", "caniuse-lite": "^1.0.30001806", @@ -2258,7 +2254,6 @@ "deprecated": "This version is no longer supported. Please see https://eslint.org/version-support for other options.", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "@eslint-community/eslint-utils": "^4.2.0", "@eslint-community/regexpp": "^4.6.1", @@ -3994,7 +3989,6 @@ "resolved": "https://registry.npmjs.org/react/-/react-18.3.1.tgz", "integrity": "sha512-wS+hAgJShR0KhEvPJArfuPVN1+Hz1t0Y6n5jLrGQbkb4urgPE/0Rve+1kMB1v/oWgHgm4WIcV+i7F2pTVj+2iQ==", "license": "MIT", - "peer": true, "dependencies": { "loose-envify": "^1.1.0" }, @@ -4007,7 +4001,6 @@ "resolved": "https://registry.npmjs.org/react-dom/-/react-dom-18.3.1.tgz", "integrity": "sha512-5m4nQKp+rZRb09LNH59GM4BxTh9251/ylbKIbpe7TpGxfJ+9kv6BLkLBXIjjspbgbnIBNqlI23tRnTWT0snUIw==", "license": "MIT", - "peer": true, "dependencies": { "loose-envify": "^1.1.0", "scheduler": "^0.23.2" @@ -4827,7 +4820,6 @@ "integrity": "sha512-o5a9xKjbtuhY6Bi5S3+HvbRERmouabWbyUcpXXUA1u+GNUKoROi9byOJ8M0nHbHYHkYICiMlqxkg1KkYmm25Sw==", "dev": true, "license": "MIT", - "peer": true, "dependencies": { "esbuild": "^0.21.3", "postcss": "^8.4.43", diff --git a/src/App.css b/src/App.css index 73a237a..5dd6f88 100644 --- a/src/App.css +++ b/src/App.css @@ -23,11 +23,11 @@ } /* Dark Mode Toggle */ -.dark-toggle { +.theme-toggle { padding: 3px; width: fit-content; position: relative; - background: #222; + background: var(--switch-bg, #222); border-radius: 30px; } @@ -39,7 +39,7 @@ .switch { margin: 0; width: 50px; - background: #222; + background: var(--switch-bg, #222); display: flex; align-items: center; justify-content: space-between; @@ -66,14 +66,23 @@ transform: translateX(calc(50px - 23px)); } -html[data-theme="dark"] { - color-scheme: dark; -} - html[data-theme="dark"] .welcome p { color: #ddd; } +html[data-theme="dark"] .footer { + background: var(--card-bg, #1f2937); + border-top-color: var(--border-color, #374151); +} + +html[data-theme="dark"] .footer p, +html[data-theme="dark"] .footer h3, +html[data-theme="dark"] .footer-links a, +html[data-theme="dark"] .error-sub, +html[data-theme="dark"] .home-button { + color: var(--text-color, #e5e7eb); +} + /* Error Page */ .error-container { display: flex; @@ -165,9 +174,9 @@ html[data-theme="dark"] .welcome p { z-index: 10; width: 100%; padding: 0.9rem 1.5rem; - background: rgba(255, 255, 255, 0.85); + background: var(--navbar-bg); backdrop-filter: blur(8px); - border-bottom: 1px solid #ececec; + border-bottom: 1px solid var(--border-color); } .navbar-content { @@ -187,7 +196,7 @@ html[data-theme="dark"] .welcome p { font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; - color: #213547; + color: var(--navbar-text); text-decoration: none; } @@ -207,7 +216,7 @@ html[data-theme="dark"] .welcome p { .navbar-link { position: relative; - color: #444; + color: var(--navbar-link); text-decoration: none; font-weight: 500; font-size: 0.95rem; @@ -229,7 +238,7 @@ html[data-theme="dark"] .welcome p { .navbar-link:hover, .navbar-link.active { - color: #213547; + color: var(--navbar-text); } .navbar-link:hover::after, diff --git a/src/components/Dark-Mode.jsx b/src/components/Dark-Mode.jsx index 4a98db4..bcf052d 100644 --- a/src/components/Dark-Mode.jsx +++ b/src/components/Dark-Mode.jsx @@ -1,31 +1,24 @@ -function DarkMode() { - const rootEl = document.documentElement; - - const savedTheme = localStorage.getItem("theme"); - if (savedTheme) { - rootEl.setAttribute("data-theme", savedTheme); - } - - function printToggle() { - const currentTheme = - rootEl.getAttribute("data-theme") || - (window.matchMedia("(prefers-color-scheme: dark)").matches - ? "dark" - : "light"); +import { useEffect, useState } from "react"; - const newTheme = currentTheme === "dark" ? "light" : "dark"; +function DarkMode() { + const [theme, setTheme] = useState(() => { + const savedTheme = localStorage.getItem("theme"); - rootEl.setAttribute("data-theme", newTheme); - localStorage.setItem("theme", newTheme); - } + if (savedTheme) { + return savedTheme; + } - const currentTheme = - rootEl.getAttribute("data-theme") || - (window.matchMedia("(prefers-color-scheme: dark)").matches + return window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" - : "light"); + : "light"; + }); + + useEffect(() => { + document.documentElement.setAttribute("data-theme", theme); + localStorage.setItem("theme", theme); + }, [theme]); - const isDark = currentTheme === "dark"; + const isDark = theme === "dark"; return (
setTheme((currentTheme) => currentTheme === "dark" ? "light" : "dark")} aria-label={isDark ? "Switch to light mode" : "Switch to dark mode"} /> diff --git a/src/components/Navbar.jsx b/src/components/Navbar.jsx index f5ff7a7..cc233ac 100644 --- a/src/components/Navbar.jsx +++ b/src/components/Navbar.jsx @@ -1,4 +1,5 @@ import { NavLink } from "react-router-dom"; +import DarkMode from "./Dark-Mode.jsx"; function Navbar() { return ( @@ -30,6 +31,8 @@ function Navbar() { Contributing + +
); diff --git a/src/index.css b/src/index.css index 871f432..65f871f 100644 --- a/src/index.css +++ b/src/index.css @@ -1,24 +1,43 @@ :root { font-family: system-ui, Avenir, Helvetica, Arial, sans-serif; - color-scheme: light dark; + color-scheme: light; + --bg-color: #ffffff; + --text-color: #213547; + --muted-text: #444; + --card-bg: #f8f8f8; + --border-color: #e5e5e5; + --navbar-bg: rgba(255, 255, 255, 0.85); + --navbar-text: #213547; + --navbar-link: #444; + --switch-bg: #222; +} + +html[data-theme="dark"] { + color-scheme: dark; + --bg-color: #111827; + --text-color: #e5e7eb; + --muted-text: #d1d5db; + --card-bg: #1f2937; + --border-color: #374151; + --navbar-bg: rgba(17, 24, 39, 0.85); + --navbar-text: #dbeafe; + --navbar-link: #cbd5e1; + --switch-bg: #374151; } * { box-sizing: border-box; } +html, +body, +#root { + min-height: 100%; +} + body { margin: 0; - background-color: #ffffff; - color: #213547; + background-color: var(--bg-color); + color: var(--text-color); transition: background 0.3s ease-in, color 0.3s ease-in; } - -html[data-theme="dark"] { - color-scheme: dark; - - body { - background: #000; - color: #7DA2C3; - } -} \ No newline at end of file