diff --git a/packages/react/src/MainLayout.tsx b/packages/react/src/MainLayout.tsx index f0feab0..da8a21d 100644 --- a/packages/react/src/MainLayout.tsx +++ b/packages/react/src/MainLayout.tsx @@ -1,51 +1,78 @@ -import { useState } from "react"; +import { useEffect, useState } from "react"; import { Link, Outlet, useLocation } from "react-router-dom"; import { Button } from "../components/Button"; import RouteObject from "./RouteObject"; import { Toaster } from "@components/Toast"; +import { Popover, PopoverContent, PopoverTrigger } from "@components/Popover"; -type Theme = "light" | "dark"; +type Theme = "light" | "dark" | "system"; function ThemeButton() { - const [theme, _setTheme] = useState("light"); - function setTheme(t: Theme) { - _setTheme(t); - document.documentElement.classList.toggle("dark", t === "dark"); - } + const [theme, setTheme] = useState( + (localStorage.getItem("theme") as Theme) || "system" + ); + useEffect(() => { + document.documentElement.classList.toggle("dark", theme === "dark"); + document.documentElement.classList.toggle("system", theme === "system"); + localStorage.setItem("theme", theme); + }, [theme]); return ( - + + + + + + + + + + ); }