1
- import { IconMoon , IconSun } from '@tabler/icons-react'
1
+ import { useEffect } from 'react'
2
+ import { IconCheck , IconMoon , IconSun } from '@tabler/icons-react'
3
+ import { cn } from '@/lib/utils'
4
+ import {
5
+ DropdownMenu ,
6
+ DropdownMenuContent ,
7
+ DropdownMenuItem ,
8
+ DropdownMenuTrigger ,
9
+ } from '@/components/ui/dropdown-menu'
2
10
import { useTheme } from './theme-provider'
3
11
import { Button } from './custom/button'
4
- import { useEffect } from 'react'
5
12
6
13
export default function ThemeSwitch ( ) {
7
14
const { theme, setTheme } = useTheme ( )
@@ -14,14 +21,40 @@ export default function ThemeSwitch() {
14
21
metaThemeColor && metaThemeColor . setAttribute ( 'content' , themeColor )
15
22
} , [ theme ] )
16
23
24
+ console . log ( theme )
25
+
17
26
return (
18
- < Button
19
- size = 'icon'
20
- variant = 'ghost'
21
- className = 'rounded-full'
22
- onClick = { ( ) => setTheme ( theme === 'light' ? 'dark' : 'light' ) }
23
- >
24
- { theme === 'light' ? < IconMoon size = { 20 } /> : < IconSun size = { 20 } /> }
25
- </ Button >
27
+ < DropdownMenu >
28
+ < DropdownMenuTrigger asChild >
29
+ < Button variant = 'ghost' size = 'icon' className = 'scale-95 rounded-full' >
30
+ < IconSun className = 'size-[1.2rem] rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0' />
31
+ < IconMoon className = 'absolute size-[1.2rem] rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100' />
32
+ < span className = 'sr-only' > Toggle theme</ span >
33
+ </ Button >
34
+ </ DropdownMenuTrigger >
35
+ < DropdownMenuContent align = 'end' >
36
+ < DropdownMenuItem onClick = { ( ) => setTheme ( 'light' ) } >
37
+ Light{ ' ' }
38
+ < IconCheck
39
+ size = { 14 }
40
+ className = { cn ( 'ml-auto' , theme !== 'light' && 'hidden' ) }
41
+ />
42
+ </ DropdownMenuItem >
43
+ < DropdownMenuItem onClick = { ( ) => setTheme ( 'dark' ) } >
44
+ Dark
45
+ < IconCheck
46
+ size = { 14 }
47
+ className = { cn ( 'ml-auto' , theme !== 'dark' && 'hidden' ) }
48
+ />
49
+ </ DropdownMenuItem >
50
+ < DropdownMenuItem onClick = { ( ) => setTheme ( 'system' ) } >
51
+ System
52
+ < IconCheck
53
+ size = { 14 }
54
+ className = { cn ( 'ml-auto' , theme !== 'system' && 'hidden' ) }
55
+ />
56
+ </ DropdownMenuItem >
57
+ </ DropdownMenuContent >
58
+ </ DropdownMenu >
26
59
)
27
60
}
0 commit comments