Handle system theme properly

This commit is contained in:
Ategon 2025-01-19 13:54:16 -05:00
parent 095e8d73c0
commit 166c9ac876

View file

@ -6,7 +6,7 @@ import { useTheme } from "next-themes";
export default function ThemeToggle() {
const [isSpinning, setIsSpinning] = useState<boolean>(false);
const { theme, setTheme } = useTheme();
const { setTheme, resolvedTheme } = useTheme();
const [mounted, setMounted] = useState<boolean>(false);
useEffect(() => {
@ -19,7 +19,7 @@ export default function ThemeToggle() {
setIsSpinning(true);
setTimeout(() => setIsSpinning(false), 500);
setTheme(theme === "dark" ? "light" : "dark");
setTheme(resolvedTheme === "dark" ? "light" : "dark");
};
if (!mounted) {
@ -33,8 +33,8 @@ export default function ThemeToggle() {
className={`${isSpinning && "animate-[spin_0.5s_ease-out]"} `}
>
<div className="duration-500 ease-in-out transition-all transform text-[#333] dark:text-white hover:scale-125">
{theme === "dark" && <Moon />}
{theme === "light" && <Sun />}
{resolvedTheme === "dark" && <Moon />}
{resolvedTheme === "light" && <Sun />}
</div>
</div>
);