2025-04-17 08:45:49 +00:00
|
|
|
"use client";
|
|
|
|
|
|
|
|
import { useTheme } from "next-themes";
|
|
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
2025-06-13 06:03:17 +00:00
|
|
|
import { MoonIcon, SunIcon } from "lucide-react";
|
2025-04-17 08:45:49 +00:00
|
|
|
|
2025-06-13 06:03:17 +00:00
|
|
|
export const ThemeToggle = () => {
|
2025-04-17 08:45:49 +00:00
|
|
|
const { resolvedTheme, setTheme } = useTheme();
|
2025-06-13 06:03:17 +00:00
|
|
|
const alternateTheme = resolvedTheme === "dark" ? "light" : "dark";
|
2025-04-17 08:45:49 +00:00
|
|
|
const [mounted, setMounted] = useState(false);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
setMounted(true);
|
|
|
|
}, []);
|
|
|
|
|
|
|
|
return (
|
|
|
|
<Button
|
|
|
|
size="icon"
|
|
|
|
variant="outline"
|
2025-06-13 06:03:17 +00:00
|
|
|
onClick={() => setTheme(alternateTheme)}
|
|
|
|
aria-label={
|
|
|
|
mounted ? `Switch to ${alternateTheme} theme` : "Toggle theme"
|
|
|
|
}
|
2025-04-17 08:45:49 +00:00
|
|
|
>
|
2025-06-13 06:03:17 +00:00
|
|
|
<MoonIcon
|
|
|
|
size={16}
|
|
|
|
className="shrink-0 scale-0 opacity-0 transition-all dark:scale-100 dark:opacity-100"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
|
|
|
<SunIcon
|
|
|
|
size={16}
|
|
|
|
className="absolute shrink-0 scale-100 opacity-100 transition-all dark:scale-0 dark:opacity-0"
|
|
|
|
aria-hidden="true"
|
|
|
|
/>
|
2025-04-17 08:45:49 +00:00
|
|
|
</Button>
|
|
|
|
);
|
2025-06-13 06:03:17 +00:00
|
|
|
};
|