import { useState, useEffect } from 'react'; import { Sun, Moon, Monitor } from 'lucide-react'; /** * ThemeToggle - Minimal icon-only theme switcher * Linear-inspired: subtle, clean, unobtrusive */ type Theme = 'light' | 'dark' | 'system'; export default function ThemeToggle() { const [theme, setTheme] = useState('system'); useEffect(() => { const savedTheme = localStorage.getItem('theme') as Theme | null; if (savedTheme) { setTheme(savedTheme); applyTheme(savedTheme); } else { applyTheme('system'); } }, []); function applyTheme(newTheme: Theme) { const root = window.document.documentElement; root.classList.remove('light', 'dark'); if (newTheme === 'system') { const systemTheme = window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light'; root.classList.add(systemTheme); } else { root.classList.add(newTheme); } } function cycleTheme() { const order: Theme[] = ['light', 'dark', 'system']; const nextIndex = (order.indexOf(theme) + 1) % order.length; const newTheme = order[nextIndex]; setTheme(newTheme); localStorage.setItem('theme', newTheme); applyTheme(newTheme); } const Icon = theme === 'light' ? Sun : theme === 'dark' ? Moon : Monitor; const label = theme === 'light' ? 'Light' : theme === 'dark' ? 'Dark' : 'System'; return ( ); }