chatbot-template/components/theme-toggle.tsx

32 lines
743 B
TypeScript
Raw Normal View History

2023-06-02 15:33:48 -04:00
'use client'
2023-05-19 12:33:56 -04:00
import * as React from 'react'
2023-06-02 15:33:48 -04:00
import { useTheme } from 'next-themes'
import { Moon, Sun } from 'lucide-react'
2023-05-19 12:33:56 -04:00
2023-06-02 15:33:48 -04:00
import { Button } from '@/components/ui/button'
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] = React.useTransition()
2023-05-19 12:33:56 -04:00
return (
<Button
variant="ghost"
size="icon"
onClick={() => {
startTransition(() => {
2023-06-02 15:33:48 -04:00
setTheme(theme === 'light' ? 'dark' : 'light')
})
}}
2023-05-19 12:33:56 -04:00
>
{!theme ? null : theme === 'dark' ? (
<Moon className="h-4 w-4 transition-all" />
) : (
<Sun className="h-4 w-4 transition-all" />
)}
<span className="sr-only">Toggle theme</span>
2023-05-19 12:33:56 -04:00
</Button>
2023-06-02 15:33:48 -04:00
)
2023-05-19 12:33:56 -04:00
}