peppa/apps/web/components/ThemeToggle.tsx
2026-11-15 14:25:03 +05:00

22 lines
797 B
TypeScript

"use client";
import { Moon, Sun } from "lucide-react";
import { Button } from "@/components/ui/button";
import { THEME_COOKIE } from "@/lib/theme";
import { useT } from "@/components/I18n";
/** Dark ⇄ light; the choice lives in a cookie for a year (the root layout reads it). */
export function ThemeToggle() {
const t = useT();
const toggle = () => {
const dark = document.documentElement.classList.toggle("dark");
document.cookie = `${THEME_COOKIE}=${dark ? "dark" : "light"}; path=/; max-age=31536000; samesite=lax`;
};
return (
<Button variant="ghost" size="icon-sm" onClick={toggle} aria-label={t("Сменить тему")} title={t("Сменить тему")}>
<Sun className="hidden dark:block" />
<Moon className="dark:hidden" />
</Button>
);
}