diff --git a/src/layouts/DarkLightToggle.tsx b/src/layouts/DarkLightToggle.tsx index 7272c0518..f0bf6ce90 100644 --- a/src/layouts/DarkLightToggle.tsx +++ b/src/layouts/DarkLightToggle.tsx @@ -1,9 +1,17 @@ +import { joinClasses } from "@/utils/common"; import React from "react"; export default function DarkLightToggle() { - const [isdark, setIsdark] = React.useState( - localStorage.getItem("isdark") === "true" ? true : false, - ); + function isWindowDarkMode(): boolean { + return window.matchMedia("(prefers-color-scheme: dark)").matches; + } + + const [isdark, setIsdark] = React.useState(() => { + if (localStorage.getItem("isdark") === "true") return true; + if (localStorage.getItem("isdark") === "false") return false; + return isWindowDarkMode(); + }); + React.useEffect(() => { localStorage.setItem("isdark", JSON.stringify(isdark)); }, [isdark]); @@ -13,15 +21,16 @@ export default function DarkLightToggle() { setIsdark(!isdark)} /> {/* sun icon */} @@ -29,7 +38,10 @@ export default function DarkLightToggle() { {/* moon icon */} diff --git a/src/themes/README.md b/src/themes/README.md deleted file mode 100644 index e86c6e5c8..000000000 --- a/src/themes/README.md +++ /dev/null @@ -1 +0,0 @@ -# Themes \ No newline at end of file