-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmode-toggle.tsx
More file actions
61 lines (56 loc) · 1.72 KB
/
mode-toggle.tsx
File metadata and controls
61 lines (56 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import { MonitorIcon, MoonIcon, SunIcon } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuRadioGroup,
DropdownMenuRadioItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { type UserTheme, useTheme } from "./theme-provider";
type ThemeToggleProps = {
getTheme?: () => UserTheme;
};
function ThemeIcon({ theme }: { theme: UserTheme }) {
const iconClass = "h-[1.2rem] w-[1.2rem]";
if (theme === "system") {
return <MonitorIcon className={iconClass} />;
}
if (theme === "dark") {
return <MoonIcon className={iconClass} />;
}
return <SunIcon className={iconClass} />;
}
export function ModeToggle({ getTheme }: ThemeToggleProps) {
const { setTheme, userTheme } = useTheme();
const theme = getTheme ? getTheme() : userTheme;
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="icon">
<ThemeIcon theme={theme} />
<span className="sr-only">Toggle theme</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="center">
<DropdownMenuRadioGroup
value={theme}
onValueChange={(value) => setTheme(value as UserTheme)}
>
<DropdownMenuRadioItem value="light">
<SunIcon />
Light
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="dark">
<MoonIcon />
Dark
</DropdownMenuRadioItem>
<DropdownMenuRadioItem value="system">
<MonitorIcon />
System
</DropdownMenuRadioItem>
</DropdownMenuRadioGroup>
</DropdownMenuContent>
</DropdownMenu>
);
}