mirror of
https://github.com/hex248/sprint.git
synced 2026-02-08 02:33:01 +00:00
light/dark mode
This commit is contained in:
30
packages/frontend/src/components/theme-toggle.tsx
Normal file
30
packages/frontend/src/components/theme-toggle.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
import { Moon, Sun } from "lucide-react";
|
||||
import { useTheme } from "@/components/theme-provider";
|
||||
import { Button } from "@/components/ui/button";
|
||||
import { cn } from "@/lib/utils";
|
||||
|
||||
function ThemeToggle({ className }: { className?: string }) {
|
||||
const { theme, setTheme } = useTheme();
|
||||
const resolvedTheme =
|
||||
theme === "system"
|
||||
? window.matchMedia("(prefers-color-scheme: dark)").matches
|
||||
? "dark"
|
||||
: "light"
|
||||
: theme;
|
||||
const isDark = resolvedTheme === "dark";
|
||||
|
||||
return (
|
||||
<Button
|
||||
type="button"
|
||||
variant="dummy"
|
||||
size="icon"
|
||||
className={cn("hover:text-muted-foreground", className)}
|
||||
onClick={() => setTheme(isDark ? "light" : "dark")}
|
||||
title={isDark ? "Switch to light mode" : "Switch to dark mode"}
|
||||
>
|
||||
{isDark ? <Sun className="size-5" /> : <Moon className="size-5" />}
|
||||
</Button>
|
||||
);
|
||||
}
|
||||
|
||||
export default ThemeToggle;
|
||||
Reference in New Issue
Block a user