mango-ui-v3/components/ThemeSwitch.tsx

37 lines
1.0 KiB
TypeScript
Raw Normal View History

import { useEffect, useState } from 'react'
import { useTheme } from 'next-themes'
import { MoonIcon, SunIcon } from '@heroicons/react/outline'
import DropMenu from './DropMenu'
2021-04-15 06:22:39 -07:00
import { MangoIcon } from './icons'
const THEMES = [
2021-04-19 06:45:59 -07:00
{ name: 'Light', icon: <SunIcon className="w-5" /> },
{ name: 'Dark', icon: <MoonIcon className="w-5" /> },
{ name: 'Mango', icon: <MangoIcon className="stroke-current" /> },
]
const ThemeSwitch = () => {
const [mounted, setMounted] = useState(false)
const { theme, setTheme } = useTheme()
// When mounted on client, now we can show the UI
useEffect(() => setMounted(true), [])
if (!mounted) return null
return (
<DropMenu
button={
2021-04-19 06:45:59 -07:00
<div className="h-5">{THEMES.find((t) => t.name === theme).icon}</div>
}
2021-04-14 18:54:23 -07:00
buttonClassName="w-10 h-10 flex items-center justify-center hover:text-th-primary rounded-md focus:outline-none"
value={theme}
onChange={(theme) => setTheme(theme)}
options={THEMES}
toolTipContent="Change Theme"
/>
)
}
export default ThemeSwitch