1- " use client"
1+ ' use client' ;
22
3- import { useTheme } from " next-themes"
4- import { Monitor , Sun , Moon } from " lucide-react"
5- import { motion } from " framer-motion"
6- import { useEffect , useState } from " react"
3+ import { useTheme } from ' next-themes' ;
4+ import { Monitor , Sun , Moon } from ' lucide-react' ;
5+ import { motion } from ' framer-motion' ;
6+ import { useEffect , useState } from ' react' ;
77
88const themes = [
9- { value : " system" , icon : Monitor , label : " System theme" } ,
10- { value : " light" , icon : Sun , label : " Light theme" } ,
11- { value : " dark" , icon : Moon , label : " Dark theme" } ,
12- ] as const
9+ { value : ' system' , icon : Monitor , label : ' System theme' } ,
10+ { value : ' light' , icon : Sun , label : ' Light theme' } ,
11+ { value : ' dark' , icon : Moon , label : ' Dark theme' } ,
12+ ] as const ;
1313
1414export function ThemeToggle ( ) {
15- const { theme, setTheme } = useTheme ( )
16- const [ mounted , setMounted ] = useState ( false )
15+ const { theme, setTheme } = useTheme ( ) ;
16+ const [ mounted , setMounted ] = useState ( false ) ;
1717
1818 useEffect ( ( ) => {
19- setMounted ( true )
20- } , [ ] )
19+ setMounted ( true ) ;
20+ } , [ ] ) ;
2121
2222 if ( ! mounted ) {
2323 return (
2424 < div className = "flex h-9 items-center gap-1 rounded-full bg-neutral-100 p-1 dark:border dark:border-neutral-800 dark:bg-neutral-950" >
2525 { themes . map ( ( { value, icon : Icon } ) => (
26- < div key = { value } className = "relative flex h-7 w-7 items-center justify-center rounded-full" >
26+ < div
27+ key = { value }
28+ className = "relative flex h-7 w-7 items-center justify-center rounded-full"
29+ >
2730 < Icon className = "h-4 w-4 text-neutral-500 dark:text-neutral-400" />
2831 </ div >
2932 ) ) }
3033 </ div >
31- )
34+ ) ;
3235 }
3336
3437 return (
@@ -38,18 +41,25 @@ export function ThemeToggle() {
3841 key = { value }
3942 onClick = { ( ) => setTheme ( value ) }
4043 aria-label = { label }
41- className = "relative flex h-7 w-7 items-center justify-center rounded-full"
44+ className = "theme-toggle-btn relative flex h-7 w-7 items-center justify-center rounded-full"
4245 >
4346 { theme === value && (
4447 < motion . div
4548 layoutId = "theme-active"
4649 className = "absolute inset-0 rounded-full bg-white shadow-sm dark:bg-neutral-800"
47- transition = { { type : " spring" , stiffness : 400 , damping : 30 } }
50+ transition = { { type : ' spring' , stiffness : 400 , damping : 30 } }
4851 />
4952 ) }
50- < Icon className = "relative z-10 h-4 w-4 text-neutral-500 dark:text-neutral-400" />
53+ < Icon className = "relative z-10 h-4 w-4 text-neutral-500 dark:text-neutral-400 transition-colors " />
5154 </ button >
5255 ) ) }
56+
57+ < style jsx > { `
58+ .theme-toggle-btn:hover :global(svg),
59+ .theme-toggle-btn:focus-visible :global(svg) {
60+ color: var(--accent-primary);
61+ }
62+ ` } </ style >
5363 </ div >
54- )
55- }
64+ ) ;
65+ }
0 commit comments