Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 | 2x 23x 23x | import React from 'react';
import { useTheme } from '../context/ThemeContext';
interface ThemeToggleProps {
className?: string;
}
const ThemeToggle: React.FC<ThemeToggleProps> = ({ className = '' }) => {
const { theme, toggleTheme } = useTheme();
return (
<button
onClick={toggleTheme}
className={`relative inline-flex items-center justify-center w-10 h-10 rounded-lg transition-colors focus:outline-none focus:ring-2 focus:ring-neo-green-400 ${
theme === 'dark'
? 'bg-slate-700 hover:bg-slate-600'
: 'bg-gray-200 hover:bg-gray-300'
} ${className}`}
aria-label={`Switch to ${theme === 'dark' ? 'light' : 'dark'} mode`}
>
<span className="sr-only">Toggle theme</span>
{/* Sun icon */}
<svg
xmlns="http://www.w3.org/2000/svg"
className={`h-5 w-5 absolute transform transition-all ${
theme === 'dark'
? 'opacity-0 rotate-90 scale-75'
: 'opacity-100 rotate-0'
}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M12 3v1m0 16v1m9-9h-1M4 12H3m15.364 6.364l-.707-.707M6.343 6.343l-.707-.707m12.728 0l-.707.707M6.343 17.657l-.707.707M16 12a4 4 0 11-8 0 4 4 0 018 0z"
/>
</svg>
{/* Moon icon */}
<svg
xmlns="http://www.w3.org/2000/svg"
className={`h-5 w-5 absolute transform transition-all ${
theme === 'dark'
? 'opacity-100 rotate-0'
: 'opacity-0 -rotate-90 scale-75'
}`}
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
strokeWidth={2}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
d="M20.354 15.354A9 9 0 018.646 3.646 9.003 9.003 0 0012 21a9.003 9.003 0 008.354-5.646z"
/>
</svg>
</button>
);
};
export default ThemeToggle; |