import { useCallback, useState } from 'react'; import { setTheme, useTheme, type ThemePref } from '@/lib/theme'; import { Button } from './Button'; import { Icon, type IconName } from './Icon'; import { Popover } from './Popover'; import styles from './ThemeMenu.module.css'; const OPTIONS: { value: ThemePref; label: string; icon: IconName }[] = [ { value: 'system', label: '跟随系统', icon: 'auto' }, { value: 'light', label: '亮色', icon: 'sun' }, { value: 'dark', label: '暗色', icon: 'moon' }, ]; export function ThemeMenu() { const theme = useTheme(); const [open, setOpen] = useState(false); const close = useCallback(() => setOpen(false), []); const current = OPTIONS.find((o) => o.value === theme) ?? OPTIONS[0]; return ( setOpen((v) => !v)} />} >
{OPTIONS.map((o) => ( ))}
); }