ui: switch theme color to match dark mode

This commit is contained in:
Nathan Lamy 2025-07-31 01:13:01 +02:00
parent 52ca34a600
commit 299b1efe8b

View file

@ -28,6 +28,11 @@ const isLocalStorageAvailable = () => {
);
};
const HEADER_COLORS = {
light: "#ffffff",
dark: "#0d0d0d",
};
export function ThemeProvider({
children,
defaultTheme = "system",
@ -53,10 +58,19 @@ export function ThemeProvider({
? "dark"
: "light";
document
.querySelector("meta[name=theme-color]")
?.setAttribute(
"content",
HEADER_COLORS[systemTheme] || HEADER_COLORS.light
);
root.classList.add(systemTheme);
return;
}
document
.querySelector("meta[name=theme-color]")
?.setAttribute("content", HEADER_COLORS[theme] || HEADER_COLORS.light);
root.classList.add(theme);
}, [theme]);
@ -86,14 +100,18 @@ export const useTheme = () => {
const isWindowAvailable = () => {
return typeof window !== "undefined" && window !== null;
}
};
export const useDisplayedTheme = () => {
const { theme, setTheme } = useTheme();
if (theme === "system") {
return {
theme: isWindowAvailable() && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light",
theme:
isWindowAvailable() &&
window.matchMedia("(prefers-color-scheme: dark)").matches
? "dark"
: "light",
setTheme,
};
}