import type { LucideIcon } from 'lucide-react'; import { Moon, Sun } from 'lucide-react'; import { SidebarMenu, SidebarMenuButton, SidebarMenuItem, } from '@/components/ui/sidebar'; import type { ResolvedAppearance } from '@/hooks/use-appearance'; import { useAppearance } from '@/hooks/use-appearance'; import { cn } from '@/lib/utils'; const options: { value: ResolvedAppearance; icon: LucideIcon; label: string; }[] = [ { value: 'light', icon: Sun, label: 'Light' }, { value: 'dark', icon: Moon, label: 'Dark' }, ]; /** * Light or dark, in the sidebar just above the user. One click each. * Someone who never chose follows their device, and the switch shows how the page looks now. * The choice is saved in this browser and a cookie, the same as Settings → Appearance. * With the sidebar folded to icons it becomes one button that flips between the two. */ export function ThemeSwitch() { const { resolvedAppearance, updateAppearance } = useAppearance(); const other = resolvedAppearance === 'dark' ? 'light' : 'dark'; const OtherIcon = other === 'dark' ? Moon : Sun; return (
{options.map(({ value, icon: Icon, label }) => { const active = resolvedAppearance === value; return ( ); })}
updateAppearance(other)} tooltip={{ children: other === 'dark' ? 'Switch to dark theme' : 'Switch to light theme', }} data-test="theme-toggle" > {other === 'dark' ? 'Switch to dark theme' : 'Switch to light theme'}
); }