Files

46 lines
1.2 KiB
TypeScript
Raw Permalink Normal View History

"use client";
2025-12-15 16:08:40 +03:30
import { Moon, Sun } from "lucide-react";
import { useTheme } from "next-themes";
import { useEffect, useState } from "react";
import { Button } from "@/components/ui/button";
import { cn } from "@/lib/utils";
2025-12-15 16:08:40 +03:30
export function ThemeToggle({ className }: { className?: string }) {
const { theme, setTheme } = useTheme();
const [mounted, setMounted] = useState(false);
2025-12-15 16:08:40 +03:30
useEffect(() => {
setMounted(true);
}, []);
2025-12-15 16:08:40 +03:30
if (!mounted) {
return (
<Button
variant="ghost"
size="icon"
className={cn("relative", className)}
aria-label="تغییر تم"
2025-12-15 16:08:40 +03:30
>
<Sun />
2025-12-15 16:08:40 +03:30
</Button>
);
2025-12-15 16:08:40 +03:30
}
return (
<Button
variant="ghost"
size="icon"
className={cn(
"relative text-muted-foreground hover:text-foreground",
className
)}
onClick={() => setTheme(theme === "dark" ? "light" : "dark")}
aria-label="تغییر تم"
2025-12-15 16:08:40 +03:30
>
<Sun className="rotate-0 scale-100 transition-all duration-300 dark:-rotate-90 dark:scale-0" />
<Moon className="absolute rotate-90 scale-0 transition-all duration-300 dark:rotate-0 dark:scale-100" />
2025-12-15 16:08:40 +03:30
</Button>
);
2025-12-15 16:08:40 +03:30
}