'use client' import { MoonIcon, SunIcon } from '@heroicons/react/20/solid' import { useTheme } from 'next-themes' import { useEffect, useState } from 'react' import { cn } from '@/utils/cn' const themes = [ { id: 'light', name: 'Light Mode', icon: SunIcon }, { id: 'dark', name: 'Dark Mode', icon: MoonIcon }, // { id: 'system', name: 'System Preference', icon: Cog6ToothIcon }, ] export function ThemeSwitch() { const { theme: initialTheme, setTheme: persistTheme } = useTheme() const [theme, setTheme] = useState() const Icon = themes.find((t) => t.id === theme)?.icon ?? SunIcon useEffect(() => { setTheme(initialTheme) // eslint-disable-next-line react-hooks/exhaustive-deps }, []) const setThemeAndPersist = () => { const nextTheme = theme === 'light' ? 'dark' : 'light' persistTheme(nextTheme) setTheme(nextTheme) } return (
) }