| 12345678910111213141516171819202122232425262728293031323334 |
- 'use client';
- import * as React from 'react';
- import { Moon, Sun } from 'lucide-react';
- import { useTheme } from 'next-themes';
- import { cn } from '@/lib/utils';
- export function ThemeToggle() {
- const { theme, setTheme } = useTheme();
- const [mounted, setMounted] = React.useState(false);
- React.useEffect(() => {
- setMounted(true);
- }, []);
- if (!mounted) {
- return null;
- }
- return (
- <button
- onClick={() => setTheme(theme === 'dark' ? 'light' : 'dark')}
- className={cn(
- 'relative inline-flex h-10 w-10 items-center justify-center rounded-lg',
- 'border border-input bg-background hover:bg-accent hover:text-accent-foreground',
- 'transition-colors focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring'
- )}
- aria-label="Toggle theme"
- >
- <Sun className="h-5 w-5 rotate-0 scale-100 transition-all dark:-rotate-90 dark:scale-0" />
- <Moon className="absolute h-5 w-5 rotate-90 scale-0 transition-all dark:rotate-0 dark:scale-100" />
- </button>
- );
- }
|