mirror of
https://github.com/SamyRai/turash.git
synced 2025-12-26 23:01:33 +00:00
43 lines
1.2 KiB
TypeScript
43 lines
1.2 KiB
TypeScript
import React from 'react';
|
|
import { motion, AnimatePresence } from 'framer-motion';
|
|
import { useTheme } from '@/contexts/ThemeContext.tsx';
|
|
import Button from '@/components/ui/Button.tsx';
|
|
import { Moon, Sun } from 'lucide-react';
|
|
|
|
const ThemeToggle = () => {
|
|
const { theme, setTheme } = useTheme();
|
|
|
|
const toggleTheme = () => {
|
|
setTheme(theme === 'dark' ? 'light' : 'dark');
|
|
};
|
|
|
|
return (
|
|
<Button
|
|
variant="ghost"
|
|
size="sm"
|
|
className="w-9 h-9 p-0"
|
|
onClick={toggleTheme}
|
|
aria-label="Toggle theme"
|
|
>
|
|
<AnimatePresence mode="wait" initial={false}>
|
|
<motion.span
|
|
key={theme}
|
|
initial={{ y: -20, opacity: 0, rotate: -90 }}
|
|
animate={{ y: 0, opacity: 1, rotate: 0 }}
|
|
exit={{ y: 20, opacity: 0, rotate: 90 }}
|
|
transition={{ duration: 0.2 }}
|
|
className="flex items-center justify-center"
|
|
>
|
|
{theme === 'dark' ? (
|
|
<Sun className="h-4 h-5 text-current w-4 w-5" />
|
|
) : (
|
|
<Moon className="h-4 h-5 text-current w-4 w-5" />
|
|
)}
|
|
</motion.span>
|
|
</AnimatePresence>
|
|
</Button>
|
|
);
|
|
};
|
|
|
|
export default ThemeToggle;
|