-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathmode-toggle.tsx
47 lines (43 loc) · 1.43 KB
/
mode-toggle.tsx
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
'use client';
import * as React from 'react';
import { ChevronDownIcon, MoonIcon, SunIcon } from '@radix-ui/react-icons';
import { useTheme } from 'next-themes';
import { Button } from '@/components/ui/button';
import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from '@/components/ui/dropdown-menu';
export function ModeToggle() {
const { setTheme, theme } = useTheme();
return (
<DropdownMenu>
<DropdownMenuTrigger asChild>
<Button variant="outline" className="justify-start rounded-[10px]">
{theme === 'light' && (
<div className="flex justify-between w-full scale-100 dark:scale-0">
<p>Light mode</p>
<ChevronDownIcon className="w-5 h-5" />
</div>
)}
{theme === 'dark' && (
<div className=" flex justify-between w-full scale-0 dark:scale-100">
<p>Dark mode</p>
<ChevronDownIcon className="w-5 h-5" />
</div>
)}
<span className="sr-only">Toggle theme</span>
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="start" className="w-52">
<DropdownMenuItem onClick={() => setTheme('light')}>
Light mode
</DropdownMenuItem>
<DropdownMenuItem onClick={() => setTheme('dark')}>
Dark mode
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
);
}