Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[UI v2] feat: Adds Server Settings component #16901

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
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",
);

// Synchronizes 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