2023-06-02 15:33:48 -04:00
|
|
|
'use client'
|
2023-05-19 12:33:56 -04:00
|
|
|
|
2023-06-02 15:33:48 -04:00
|
|
|
import { useTheme } from 'next-themes'
|
2023-05-19 12:33:56 -04:00
|
|
|
|
2023-06-02 15:33:48 -04:00
|
|
|
import { Button } from '@/components/ui/button'
|
|
|
|
|
import { Moon, Sun } from 'lucide-react'
|
|
|
|
|
import { useTransition } from 'react'
|
2023-05-19 12:33:56 -04:00
|
|
|
|
|
|
|
|
export function ThemeToggle() {
|
2023-06-02 15:33:48 -04:00
|
|
|
const { setTheme, theme } = useTheme()
|
|
|
|
|
const [_, startTransition] = useTransition()
|
2023-05-19 12:33:56 -04:00
|
|
|
return (
|
|
|
|
|
<Button
|
|
|
|
|
variant="ghost"
|
2023-06-07 16:17:59 +04:00
|
|
|
size="sm"
|
2023-05-19 12:33:56 -04:00
|
|
|
className="p-0 leading-4 h-4 font-normal w-full"
|
2023-05-19 14:13:38 -04:00
|
|
|
onClick={() => {
|
|
|
|
|
startTransition(() => {
|
2023-06-02 15:33:48 -04:00
|
|
|
setTheme(theme === 'light' ? 'dark' : 'light')
|
|
|
|
|
})
|
2023-05-19 14:13:38 -04:00
|
|
|
}}
|
2023-05-19 12:33:56 -04:00
|
|
|
>
|
|
|
|
|
<span className="flex flex-row justify-between text-xs text-zinc-900 dark:text-zinc-400 w-full">
|
|
|
|
|
<span className="">Toggle theme</span>
|
2023-06-02 15:33:48 -04:00
|
|
|
{!theme ? null : theme === 'dark' ? (
|
2023-05-19 12:33:56 -04:00
|
|
|
<Moon className="h-4 transition-all" />
|
|
|
|
|
) : (
|
|
|
|
|
<Sun className="h-4 transition-all" />
|
|
|
|
|
)}
|
|
|
|
|
</span>
|
|
|
|
|
</Button>
|
2023-06-02 15:33:48 -04:00
|
|
|
)
|
2023-05-19 12:33:56 -04:00
|
|
|
}
|