11'use client' ;
22
3- import { MoonIcon , SunIcon } from '@phosphor-icons/react' ;
3+ import { MonitorIcon , MoonIcon , SunIcon } from '@phosphor-icons/react' ;
44import { useTheme } from 'next-themes' ;
55import { Button } from '@/components/ui/button' ;
66import { cn } from '@/lib/utils' ;
@@ -10,11 +10,18 @@ type ThemeTogglerProps = {
1010} ;
1111
1212export function ThemeToggle ( { className } : ThemeTogglerProps ) {
13- const { resolvedTheme , setTheme } = useTheme ( ) ;
13+ const { theme , setTheme } = useTheme ( ) ;
1414
1515 const switchTheme = ( ) => {
16- setTheme ( resolvedTheme === 'dark' ? 'light' : 'dark' ) ;
16+ if ( theme === 'system' ) {
17+ setTheme ( 'light' ) ;
18+ } else if ( theme === 'light' ) {
19+ setTheme ( 'dark' ) ;
20+ } else {
21+ setTheme ( 'system' ) ;
22+ }
1723 } ;
24+
1825 return (
1926 < Button
2027 aria-label = "Toggle theme"
@@ -27,12 +34,26 @@ export function ThemeToggle({ className }: ThemeTogglerProps) {
2734 variant = "ghost"
2835 >
2936 < SunIcon
30- className = "dark:-rotate-90 h-5 w-5 rotate-0 scale-100 not-dark:text-primary transition-all duration-300 dark:scale-0"
37+ className = { cn (
38+ 'h-5 w-5 transition-all duration-300' ,
39+ theme === 'light' ? 'scale-100 rotate-0' : 'scale-0 -rotate-90'
40+ ) }
3141 size = { 32 }
3242 weight = "duotone"
3343 />
3444 < MoonIcon
35- className = "absolute h-5 w-5 rotate-90 scale-0 not-dark:text-primary transition-all duration-300 dark:rotate-0 dark:scale-100"
45+ className = { cn (
46+ 'absolute h-5 w-5 transition-all duration-300' ,
47+ theme === 'dark' ? 'scale-100 rotate-0' : 'scale-0 rotate-90'
48+ ) }
49+ size = { 32 }
50+ weight = "duotone"
51+ />
52+ < MonitorIcon
53+ className = { cn (
54+ 'absolute h-5 w-5 transition-all duration-300' ,
55+ theme === 'system' ? 'scale-100 rotate-0' : 'scale-0 rotate-90'
56+ ) }
3657 size = { 32 }
3758 weight = "duotone"
3859 />
0 commit comments