ui: switch theme color to match dark mode
This commit is contained in:
parent
52ca34a600
commit
299b1efe8b
1 changed files with 20 additions and 2 deletions
|
|
@ -28,6 +28,11 @@ const isLocalStorageAvailable = () => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const HEADER_COLORS = {
|
||||||
|
light: "#ffffff",
|
||||||
|
dark: "#0d0d0d",
|
||||||
|
};
|
||||||
|
|
||||||
export function ThemeProvider({
|
export function ThemeProvider({
|
||||||
children,
|
children,
|
||||||
defaultTheme = "system",
|
defaultTheme = "system",
|
||||||
|
|
@ -53,10 +58,19 @@ export function ThemeProvider({
|
||||||
? "dark"
|
? "dark"
|
||||||
: "light";
|
: "light";
|
||||||
|
|
||||||
|
document
|
||||||
|
.querySelector("meta[name=theme-color]")
|
||||||
|
?.setAttribute(
|
||||||
|
"content",
|
||||||
|
HEADER_COLORS[systemTheme] || HEADER_COLORS.light
|
||||||
|
);
|
||||||
root.classList.add(systemTheme);
|
root.classList.add(systemTheme);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document
|
||||||
|
.querySelector("meta[name=theme-color]")
|
||||||
|
?.setAttribute("content", HEADER_COLORS[theme] || HEADER_COLORS.light);
|
||||||
root.classList.add(theme);
|
root.classList.add(theme);
|
||||||
}, [theme]);
|
}, [theme]);
|
||||||
|
|
||||||
|
|
@ -86,14 +100,18 @@ export const useTheme = () => {
|
||||||
|
|
||||||
const isWindowAvailable = () => {
|
const isWindowAvailable = () => {
|
||||||
return typeof window !== "undefined" && window !== null;
|
return typeof window !== "undefined" && window !== null;
|
||||||
}
|
};
|
||||||
|
|
||||||
export const useDisplayedTheme = () => {
|
export const useDisplayedTheme = () => {
|
||||||
const { theme, setTheme } = useTheme();
|
const { theme, setTheme } = useTheme();
|
||||||
|
|
||||||
if (theme === "system") {
|
if (theme === "system") {
|
||||||
return {
|
return {
|
||||||
theme: isWindowAvailable() && window.matchMedia("(prefers-color-scheme: dark)").matches ? "dark" : "light",
|
theme:
|
||||||
|
isWindowAvailable() &&
|
||||||
|
window.matchMedia("(prefers-color-scheme: dark)").matches
|
||||||
|
? "dark"
|
||||||
|
: "light",
|
||||||
setTheme,
|
setTheme,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue