feat: sync embedded analytics theme with parent app
This commit is contained in:
29
lib/theme-sync.ts
Normal file
29
lib/theme-sync.ts
Normal file
@@ -0,0 +1,29 @@
|
||||
import type { Theme } from "./theme";
|
||||
|
||||
export type ResolvedTheme = "light" | "dark";
|
||||
|
||||
export function resolveStoredTheme(
|
||||
theme: Theme,
|
||||
prefersDark: boolean,
|
||||
): ResolvedTheme {
|
||||
if (theme === "system") {
|
||||
return prefersDark ? "dark" : "light";
|
||||
}
|
||||
|
||||
return theme;
|
||||
}
|
||||
|
||||
export function resolveIncomingThemeMode(
|
||||
mode: unknown,
|
||||
prefersDark: boolean,
|
||||
): ResolvedTheme | null {
|
||||
if (mode === "light" || mode === "dark") {
|
||||
return mode;
|
||||
}
|
||||
|
||||
if (mode === "auto" || mode === "system") {
|
||||
return prefersDark ? "dark" : "light";
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
Reference in New Issue
Block a user