'use client'; import { useMemo } from 'react'; import { Computer, Moon, Sun } from 'lucide-react'; import { useTheme } from 'next-themes'; import { cn } from '../lib/utils'; import { Button } from '../shadcn/button'; import { Card, CardContent, CardDescription, CardHeader, CardTitle, } from '../shadcn/card'; import { DropdownMenu, DropdownMenuContent, DropdownMenuGroup, DropdownMenuItem, DropdownMenuLabel, DropdownMenuSub, DropdownMenuSubContent, DropdownMenuSubTrigger, DropdownMenuTrigger, } from '../shadcn/dropdown-menu'; import { Trans } from './trans'; const MODES = ['light', 'dark', 'system']; export function ModeToggle(props: { className?: string }) { const { setTheme, theme } = useTheme(); const Items = useMemo(() => { return MODES.map((mode) => { const isSelected = theme === mode; return ( { setTheme(mode); setCookeTheme(mode); }} > ); }); }, [setTheme, theme]); return ( } > Toggle theme {Items} ); } export function SubMenuModeToggle() { const { setTheme, theme, resolvedTheme } = useTheme(); const MenuItems = useMemo( () => MODES.map((mode) => { const isSelected = theme === mode; return ( { setTheme(mode); setCookeTheme(mode); }} > ); }), [setTheme, theme], ); return ( {MenuItems} {MenuItems} ); } function setCookeTheme(theme: string) { document.cookie = `theme=${theme}; path=/; max-age=31536000`; } function Icon({ theme }: { theme: string | undefined }) { switch (theme) { case 'light': return ; case 'dark': return ; case 'system': return ; } } export function ThemePreferenceCard({ currentTheme, }: { currentTheme: string; }) { const { setTheme, theme = currentTheme } = useTheme(); return ( {MODES.map((mode) => { const isSelected = theme === mode; return ( { setTheme(mode); setCookeTheme(mode); }} > {mode === 'light' && } {mode === 'dark' && } {mode === 'system' && } ); })} ); }