chatbot-template/components/theme-toggle.tsx

32 lines
752 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'
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'
2023-06-13 16:02:07 +04:00
import { IconMoon, IconSun } from '@/components/ui/icons'
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' ? (
2023-06-13 16:02:07 +04:00
<IconMoon className="transition-all" />
) : (
2023-06-13 16:02:07 +04:00
<IconSun className="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
}