Add dark mode toggle to settings #7

Open
zaphostingpreview wants to merge 2 commits from feature/dark-mode-toggle into main
2 changed files with 19 additions and 0 deletions
+4
View File
@@ -8,3 +8,7 @@ Customer control panel frontend. Built with Next.js + TypeScript.
npm install npm install
npm run dev npm run dev
``` ```
## Dark mode
Toggle dark mode from Settings > Appearance.
+15
View File
@@ -0,0 +1,15 @@
import { useState, useEffect } from "react";
export function useDarkMode() {
const [enabled, setEnabled] = useState(() => {
if (typeof window === "undefined") return false;
return localStorage.getItem("theme") === "dark";
Review

Consider using matchMedia to respect the OS preference as the initial default.

Consider using `matchMedia` to respect the OS preference as the initial default.
});
useEffect(() => {
document.documentElement.classList.toggle("dark", enabled);
localStorage.setItem("theme", enabled ? "dark" : "light");
}, [enabled]);
return { enabled, toggle: () => setEnabled((v) => !v) };
}