41 lines
1.2 KiB
TypeScript
41 lines
1.2 KiB
TypeScript
import { useEffect, useState } from 'react'
|
|
import { useTheme } from 'next-themes'
|
|
import { MoonIcon, SunIcon } from '@heroicons/react/outline'
|
|
import DropMenu from './DropMenu'
|
|
import { MangoIcon } from './icons'
|
|
|
|
const THEMES = [
|
|
{ name: 'Light', icon: <SunIcon className="h-4 w-4" /> },
|
|
{ name: 'Dark', icon: <MoonIcon className="h-4 w-4" /> },
|
|
{ name: 'Mango', icon: <MangoIcon className="stroke-current h-4 w-4" /> },
|
|
]
|
|
|
|
const ThemeSwitch = () => {
|
|
const [mounted, setMounted] = useState(false)
|
|
const { theme, setTheme } = useTheme()
|
|
|
|
// When mounted on client, now we can show the UI
|
|
useEffect(() => setMounted(true), [])
|
|
|
|
return (
|
|
<div id="themes-tip">
|
|
{mounted ? (
|
|
<DropMenu
|
|
button={
|
|
<div className="bg-th-bkg-4 default-transition flex items-center justify-center rounded-full w-8 h-8 text-th-fgd-1 focus:outline-none hover:text-th-primary">
|
|
{THEMES.find((t) => t.name === theme).icon}
|
|
</div>
|
|
}
|
|
value={theme}
|
|
onChange={(theme) => setTheme(theme)}
|
|
options={THEMES}
|
|
/>
|
|
) : (
|
|
<div className="bg-th-bkg-3 rounded-full w-8 h-8" />
|
|
)}
|
|
</div>
|
|
)
|
|
}
|
|
|
|
export default ThemeSwitch
|