20 lines
725 B
TypeScript
20 lines
725 B
TypeScript
"use client";
|
|
|
|
import { Moon, Sun } from "lucide-react";
|
|
import { Button } from "@/components/ui/button";
|
|
import { THEME_COOKIE } from "@/lib/theme";
|
|
|
|
/** Dark ⇄ light; the choice lives in a cookie for a year (the root layout reads it). */
|
|
export function ThemeToggle() {
|
|
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="Сменить тему" title="Сменить тему">
|
|
<Sun className="hidden dark:block" />
|
|
<Moon className="dark:hidden" />
|
|
</Button>
|
|
);
|
|
}
|