mirror of
https://github.com/dograh-hq/dograh.git
synced 2026-06-10 08:05:22 +02:00
29 lines
890 B
TypeScript
29 lines
890 B
TypeScript
"use client";
|
|
|
|
import { Moon,Sun } from "lucide-react";
|
|
import { useEffect, useState } from "react";
|
|
|
|
import { Button } from "@/components/ui/button";
|
|
|
|
export default function ThemeToggle() {
|
|
const [theme, setTheme] = useState("light");
|
|
|
|
useEffect(() => {
|
|
const storedTheme = localStorage.getItem("theme") || "light";
|
|
setTheme(storedTheme);
|
|
document.documentElement.classList.toggle("dark", storedTheme === "dark");
|
|
}, []);
|
|
|
|
const toggleTheme = () => {
|
|
const newTheme = theme === "light" ? "dark" : "light";
|
|
setTheme(newTheme);
|
|
localStorage.setItem("theme", newTheme);
|
|
document.documentElement.classList.toggle("dark", newTheme === "dark");
|
|
};
|
|
|
|
return (
|
|
<Button variant="outline" className="absolute top-4 right-4" onClick={toggleTheme}>
|
|
{theme === "light" ? <Moon className="h-5 w-5" /> : <Sun className="h-5 w-5" />}
|
|
</Button>
|
|
);
|
|
}
|