44 lines
1.1 KiB
TypeScript
44 lines
1.1 KiB
TypeScript
'use client'
|
|
|
|
import { Moon, Sun } from 'lucide-react'
|
|
import { useTheme } from 'next-themes'
|
|
import { useEffect, useState } from 'react'
|
|
import { Button } from '@/components/ui/button'
|
|
import { cn } from '@/lib/utils'
|
|
|
|
export function ThemeToggle() {
|
|
const { theme, setTheme } = useTheme()
|
|
const [mounted, setMounted] = useState(false)
|
|
|
|
useEffect(() => {
|
|
setMounted(true)
|
|
}, [])
|
|
|
|
if (!mounted) {
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
className="size-9 rounded-lg"
|
|
aria-label="Toggle theme"
|
|
>
|
|
<Sun className="size-4" />
|
|
</Button>
|
|
)
|
|
}
|
|
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
|
|
className="size-9 rounded-lg transition-all duration-300 hover:bg-muted"
|
|
aria-label="Toggle theme"
|
|
>
|
|
<Sun className="size-4 rotate-0 scale-100 transition-all duration-300 dark:-rotate-90 dark:scale-0" />
|
|
<Moon className="absolute size-4 rotate-90 scale-0 transition-all duration-300 dark:rotate-0 dark:scale-100" />
|
|
</Button>
|
|
)
|
|
}
|
|
|