mirror of
https://github.com/parsis-foundation/parsis.foundation.git
synced 2026-10-30 20:47:22 +00:00
- Transform from personal site to foundation/NGO site - Focus on education, research, AI, cryptography, open governance - Update all translations and navigation - Update package.json metadata
38 lines
1.1 KiB
TypeScript
38 lines
1.1 KiB
TypeScript
'use client';
|
|
|
|
import { useEffect, useState } from 'react';
|
|
import { Sun, Moon } from 'lucide-react';
|
|
|
|
export function ThemeToggle() {
|
|
const [theme, setTheme] = useState<'dark' | 'light'>('dark');
|
|
|
|
useEffect(() => {
|
|
const saved = localStorage.getItem('theme') as 'dark' | 'light' | null;
|
|
if (saved) {
|
|
setTheme(saved);
|
|
document.documentElement.classList.toggle('light', saved === 'light');
|
|
}
|
|
}, []);
|
|
|
|
const toggleTheme = () => {
|
|
const newTheme = theme === 'dark' ? 'light' : 'dark';
|
|
setTheme(newTheme);
|
|
localStorage.setItem('theme', newTheme);
|
|
document.documentElement.classList.toggle('light', newTheme === 'light');
|
|
};
|
|
|
|
return (
|
|
<button
|
|
onClick={toggleTheme}
|
|
className="flex h-9 w-9 items-center justify-center rounded-lg border border-white/10 bg-card/50 transition-colors hover:bg-card"
|
|
aria-label={theme === 'dark' ? 'Switch to light mode' : 'Switch to dark mode'}
|
|
>
|
|
{theme === 'dark' ? (
|
|
<Sun className="h-4 w-4 text-muted-foreground" />
|
|
) : (
|
|
<Moon className="h-4 w-4 text-muted-foreground" />
|
|
)}
|
|
</button>
|
|
);
|
|
}
|