Skip to content

Commit

Permalink
[UI v2] feat: Adds theme switch in settings
Browse files Browse the repository at this point in the history
  • Loading branch information
devinvillarosa committed Jan 31, 2025
1 parent 2e9c2ab commit 0250771
Showing 1 changed file with 28 additions and 2 deletions.
30 changes: 28 additions & 2 deletions ui-v2/src/components/settings/theme-switch.tsx
Original file line number Diff line number Diff line change
@@ -1,15 +1,41 @@
import { Icon } from "@/components/ui/icons";
import { Switch } from "@/components/ui/switch";

// TODO: Switch for dark mode provider
import { useLocalStorage } from "@/hooks/use-local-storage";
import { useEffect } from "react";

const isOSDarkModePreferred = window.matchMedia(
"(prefers-color-scheme: dark)",
).matches;

type ColorScheme = "light" | "dark";

export const ThemeSwitch = () => {
const [colorScheme, setColorScheme] = useLocalStorage<ColorScheme>(
"color-scheme",
isOSDarkModePreferred ? "dark" : "light",
);

// Synchornizes document to dark mode theme
useEffect(() => {
if (colorScheme === "dark") {
document.body.classList.add("dark");
} else {
document.body.classList.remove("dark");
}
}, [colorScheme]);

return (
<div className="flex flex-col gap-1">
<label htmlFor="theme-switch">Theme</label>
<div className="flex gap-2 items-center">
<Icon id="Sun" className="h-4 w-4" />
<Switch />
<Switch
checked={colorScheme === "dark"}
onCheckedChange={(checked) =>
setColorScheme(checked ? "dark" : "light")
}
/>
<Icon id="Moon" className="h-7 w-4" />
</div>
</div>
Expand Down

0 comments on commit 0250771

Please sign in to comment.