Skip to content

Commit

Permalink
Move dark mode to html tag and make sure bg is set correctly (#110)
Browse files Browse the repository at this point in the history
  • Loading branch information
daviesgeek authored Sep 12, 2024
1 parent 3e7c0f8 commit 46da102
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
2 changes: 1 addition & 1 deletion frontend/index.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!doctype html>
<html lang="en" class="dark:bg-gray-950">
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
Expand Down
12 changes: 11 additions & 1 deletion frontend/src/components/Layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,16 @@ export const Layout = ({ children }: { children: React.ReactNode }) => {
const { pathname } = useLocation();
const [isDark, setIsDark] = useState(false);

// make sure the root element is updated with the dark class
// move this out eventually
useEffect(() => {
if (isDark) {
document.documentElement.classList.add("dark", "bg-gray-950");
} else {
document.documentElement.classList.remove("dark", "bg-gray-950");
}
}, [isDark]);

useEffect(() => {
// set the initial state of the theme based on the user's preference
if (
Expand Down Expand Up @@ -46,7 +56,7 @@ export const Layout = ({ children }: { children: React.ReactNode }) => {
}, []);

return (
<div className={isDark ? "dark" : ""}>
<div>
<Menu isDark={isDark} onDarkChange={(dark) => setIsDark(dark)} />

<div
Expand Down

0 comments on commit 46da102

Please sign in to comment.