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.

86 changes: 68 additions & 18 deletions src/App.css
Original file line number Diff line number Diff line change
Expand Up @@ -23,55 +23,68 @@
}

/* Dark Mode Toggle */
.dark-toggle {
padding: 3px;
width: fit-content;
.theme-toggle {
display: inline-flex;
align-items: center;
position: relative;
background: #222;
border-radius: 30px;
}

.toggle-checkbox {
opacity: 0;
position: absolute;
width: 0;
height: 0;
}

.switch {
margin: 0;
width: 50px;
background: #222;
height: 27px;
background: #333;
display: flex;
align-items: center;
justify-content: space-between;
border-radius: 30px;
position: relative;
gap: 0;
padding: 0 5px;
cursor: pointer;
user-select: none;
}

.switcher {
background: #fff;
position: absolute;
left: 0;
left: 2px;
height: 23px;
width: 23px;
border-radius: 50%;
transition: 0.3s ease-out;
transition: transform 0.3s ease-out;
}

.icon {
display: flex;
font-size: 13px;
}

.toggle-checkbox:checked + .switch .switcher {
transform: translateX(calc(50px - 23px));
transform: translateX(23px);
}

html[data-theme="dark"] {
color-scheme: dark;
}

html[data-theme="dark"] .welcome h1 {
color: #f4f4f5;
}

html[data-theme="dark"] .welcome p {
color: #ddd;
color: #a1a1aa;
}

html[data-theme="dark"] .welcome code {
background: #27272a;
color: #f4f4f5;
}

/* Error Page */
Expand Down Expand Up @@ -199,6 +212,12 @@ html[data-theme="dark"] .welcome p {
flex-shrink: 0;
}

.navbar-actions {
display: flex;
align-items: center;
gap: 1.5rem;
}

.navbar-links {
display: flex;
gap: 1.75rem;
Expand Down Expand Up @@ -238,17 +257,21 @@ html[data-theme="dark"] .welcome p {
}

html[data-theme="dark"] .navbar {
background: rgba(0, 0, 0, 0.85);
border-bottom-color: #222;
background: rgba(18, 18, 18, 0.85);
border-bottom-color: #27272a;
}

html[data-theme="dark"] .navbar-brand,
html[data-theme="dark"] .navbar-link.active {
color: #7da2c3;
html[data-theme="dark"] .navbar-brand {
color: #f4f4f5;
}

html[data-theme="dark"] .navbar-link {
color: #9fb8cc;
color: #a1a1aa;
}

html[data-theme="dark"] .navbar-link:hover,
html[data-theme="dark"] .navbar-link.active {
color: #f4f4f5;
}

@media (max-width: 600px) {
Expand All @@ -259,7 +282,12 @@ html[data-theme="dark"] .navbar-link {
.navbar-content {
flex-direction: column;
align-items: flex-start;
gap: 0.6rem;
gap: 0.8rem;
}

.navbar-actions {
width: 100%;
justify-content: space-between;
}

.navbar-links {
Expand Down Expand Up @@ -311,6 +339,28 @@ html[data-theme="dark"] .navbar-link {
color: #666;
}

html[data-theme="dark"] .footer {
background: #18181b;
border-top-color: #27272a;
}

html[data-theme="dark"] .footer h3,
html[data-theme="dark"] .footer-links a {
color: #f4f4f5;
}

html[data-theme="dark"] .footer p {
color: #a1a1aa;
}

html[data-theme="dark"] .error-sub {
color: #e4e4e7;
}

html[data-theme="dark"] .home-button {
color: #8e8dd3;
}

@media (max-width: 600px) {
.footer {
padding: 1.5rem 1rem;
Expand Down
51 changes: 21 additions & 30 deletions src/components/Dark-Mode.jsx
Original file line number Diff line number Diff line change
@@ -1,45 +1,36 @@
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 { useState, useEffect } from "react";

const newTheme = currentTheme === "dark" ? "light" : "dark";
function DarkMode() {
const [theme, setTheme] = useState(() => {
const savedTheme = localStorage.getItem("theme");
if (savedTheme) {
return savedTheme;
}
return window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light";
});

rootEl.setAttribute("data-theme", newTheme);
localStorage.setItem("theme", newTheme);
}
useEffect(() => {
document.documentElement.setAttribute("data-theme", theme);
localStorage.setItem("theme", theme);
}, [theme]);

const currentTheme =
rootEl.getAttribute("data-theme") ||
(window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light");
const toggleTheme = () => {
setTheme((prevTheme) => (prevTheme === "dark" ? "light" : "dark"));
};

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

return (
<div
className="theme-toggle"
role="group"
aria-label="Theme selection"
>
<div className="theme-toggle" role="group" aria-label="Theme selection">
<input
type="checkbox"
className="toggle-checkbox"
id="toggle"
name="toggle"
checked={isDark}
onChange={printToggle}
onChange={toggleTheme}
aria-label={isDark ? "Switch to light mode" : "Switch to dark mode"}
/>

Expand Down
46 changes: 25 additions & 21 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 All @@ -9,27 +10,30 @@ function Navbar() {
React Open Source
</NavLink>

<nav className="navbar-links">
<NavLink to="/" end className="navbar-link">
Home
</NavLink>
<a
href="https://github.com/Vikram-sardiwal/react-open-source"
className="navbar-link"
target="_blank"
rel="noopener noreferrer"
>
GitHub
</a>
<a
href="https://github.com/Vikram-sardiwal/react-open-source/blob/main/CONTRIBUTING.md"
className="navbar-link"
target="_blank"
rel="noopener noreferrer"
>
Contributing
</a>
</nav>
<div className="navbar-actions">
<nav className="navbar-links">
<NavLink to="/" end className="navbar-link">
Home
</NavLink>
<a
href="https://github.com/Vikram-sardiwal/react-open-source"
className="navbar-link"
target="_blank"
rel="noopener noreferrer"
>
GitHub
</a>
<a
href="https://github.com/Vikram-sardiwal/react-open-source/blob/main/CONTRIBUTING.md"
className="navbar-link"
target="_blank"
rel="noopener noreferrer"
>
Contributing
</a>
</nav>
<DarkMode />
</div>
</div>
</header>
);
Expand Down
12 changes: 4 additions & 8 deletions src/index.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@ body {
margin: 0;
background-color: #ffffff;
color: #213547;
transition: background 0.3s ease-in, color 0.3s ease-in;
transition: background-color 0.3s ease, color 0.3s ease;
}

html[data-theme="dark"] {
color-scheme: dark;

body {
background: #000;
color: #7DA2C3;
}
html[data-theme="dark"] body {
background-color: #121212;
color: #e4e4e7;
}