feat(theme): add custom UI color palettes
This commit is contained in:
1 parent
c81466d0db
commit
8996da7d9a
15 files changed
+618
-37
No files matched your search
@@ -107,4 +107,45 @@ describe("useTheme on Linux", () => {
|
||||
await flushDynamicImport();
|
||||
expect(setTheme).toHaveBeenLastCalledWith("light");
|
||||
});
|
||||
|
||||
it("injects custom UI colors as inline CSS variables and removes them when leaving the custom palette", async () => {
|
||||
const theme = await loadTheme();
|
||||
theme.setThemePalette("custom");
|
||||
await flushDynamicImport();
|
||||
theme.setCustomUiColors({ ...theme.customUiColors.value, background: "#123456", primary: "#abcdef" });
|
||||
|
||||
expect(theme.themePalette.value).toBe("custom");
|
||||
expect(document.documentElement.style.getPropertyValue("--background")).toBe("rgb(18 52 86)");
|
||||
expect(document.documentElement.style.getPropertyValue("--primary")).toBe("rgb(171 205 239)");
|
||||
expect(document.documentElement.style.getPropertyValue("--dbx-primary-rgb")).toBe("171, 205, 239");
|
||||
expect(document.documentElement.style.getPropertyValue("--sidebar")).toBe("rgb(250 250 250)");
|
||||
// Derived paired foregrounds are applied and readable against their surfaces.
|
||||
expect(document.documentElement.style.getPropertyValue("--card-foreground")).toBe("rgb(10 10 10)");
|
||||
expect(document.documentElement.style.getPropertyValue("--primary-foreground")).toBe("rgb(10 10 10)");
|
||||
|
||||
theme.setThemePalette("pearl");
|
||||
await flushDynamicImport();
|
||||
expect(document.documentElement.style.getPropertyValue("--background")).toBe("");
|
||||
expect(document.documentElement.style.getPropertyValue("--dbx-primary-rgb")).toBe("");
|
||||
});
|
||||
|
||||
it("applies a separate custom color set in dark mode and switches sets with the mode", async () => {
|
||||
const theme = await loadTheme("dark");
|
||||
theme.setThemePalette("custom");
|
||||
await flushDynamicImport();
|
||||
|
||||
// Dark mode uses the dark custom set by default (not the light defaults).
|
||||
expect(document.documentElement.style.getPropertyValue("--background")).toBe("rgb(19 20 22)");
|
||||
expect(document.documentElement.style.getPropertyValue("--foreground")).toBe("rgb(215 215 219)");
|
||||
|
||||
theme.setCustomUiColors({ ...theme.customUiColorsDark.value, background: "#1a1b1e" });
|
||||
expect(document.documentElement.style.getPropertyValue("--background")).toBe("rgb(26 27 30)");
|
||||
|
||||
// Switching to light mode re-applies the light custom set.
|
||||
theme.setThemeMode("light");
|
||||
await flushDynamicImport();
|
||||
expect(document.documentElement.style.getPropertyValue("--background")).toBe("rgb(255 255 255)");
|
||||
expect(theme.customUiColors.value.background).toBe("#ffffff");
|
||||
expect(theme.customUiColorsDark.value.background).toBe("#1a1b1e");
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user