Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

33 changes: 21 additions & 12 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Comment thread
Vikram-sardiwal marked this conversation as resolved.
Resolved

Expand All @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
}
Comment on lines 176 to 180

.navbar-content {
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -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,
Expand Down
41 changes: 17 additions & 24 deletions src/components/Dark-Mode.jsx
Original file line number Diff line number Diff line change
@@ -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]);
Comment on lines +16 to +19

const isDark = currentTheme === "dark";
const isDark = theme === "dark";

return (
<div
Expand All @@ -39,7 +32,7 @@ function DarkMode() {
id="toggle"
name="toggle"
checked={isDark}
onChange={printToggle}
onChange={() => setTheme((currentTheme) => currentTheme === "dark" ? "light" : "dark")}
aria-label={isDark ? "Switch to light mode" : "Switch to dark mode"}
/>

Expand Down
3 changes: 3 additions & 0 deletions src/components/Navbar.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { NavLink } from "react-router-dom";
import DarkMode from "./Dark-Mode.jsx";

function Navbar() {
return (
Expand Down Expand Up @@ -30,6 +31,8 @@ function Navbar() {
Contributing
</a>
</nav>

<DarkMode />
</div>
</header>
);
Expand Down
43 changes: 31 additions & 12 deletions src/index.css
Original file line number Diff line number Diff line change
@@ -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;
}
}