Skip to content

Commit 1470200

Browse files
committed
feat(web): VS Code-style custom theme system
Add a theme registry with built-in palettes, custom theme storage, import/export, and an inline editor. - New themes/ module: registry, transport, builtin, types - applyThemeToDocument materializes Tailwind --alpha(...) -> color-mix on emit so runtime <style> overrides don't collapse to white/black - duplicateTheme of the default theme returns an empty patch so tokens fall back through resolveTokens against the live default - Settings: new Appearance page with a theme list panel - Per-row Edit/Duplicate/Export/Copy JSON/Delete actions - Inline editor with Form/JSON modes, light/dark variant tabs, sticky header (Save/Cancel + Unsaved badge), and AlertDialog confirms - Color mode selector moved here from General settings - index.css: extract scrollbar/noise styles to CSS custom properties - useTheme: track activeThemeId, sync across tabs
1 parent 3754c80 commit 1470200

17 files changed

Lines changed: 2487 additions & 76 deletions

‎apps/web/src/components/settings/AppearanceSettings.tsx‎

Lines changed: 417 additions & 0 deletions
Large diffs are not rendered by default.

‎apps/web/src/components/settings/SettingsPanels.tsx‎

Lines changed: 0 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -74,21 +74,6 @@ import {
7474
useServerProviders,
7575
} from "../../rpc/serverState";
7676

77-
const THEME_OPTIONS = [
78-
{
79-
value: "system",
80-
label: "System",
81-
},
82-
{
83-
value: "light",
84-
label: "Light",
85-
},
86-
{
87-
value: "dark",
88-
label: "Dark",
89-
},
90-
] as const;
91-
9277
const TIMESTAMP_FORMAT_LABELS = {
9378
locale: "System default",
9479
"12-hour": "12-hour",
@@ -448,7 +433,6 @@ export function useSettingsRestore(onRestored?: () => void) {
448433
}
449434

450435
export function GeneralSettingsPanel() {
451-
const { theme, setTheme } = useTheme();
452436
const settings = useSettings();
453437
const { updateSettings } = useUpdateSettings();
454438
const [openingPathByTarget, setOpeningPathByTarget] = useState({
@@ -794,39 +778,6 @@ export function GeneralSettingsPanel() {
794778
return (
795779
<SettingsPageContainer>
796780
<SettingsSection title="General">
797-
<SettingsRow
798-
title="Theme"
799-
description="Choose how T3 Code looks across the app."
800-
resetAction={
801-
theme !== "system" ? (
802-
<SettingResetButton label="theme" onClick={() => setTheme("system")} />
803-
) : null
804-
}
805-
control={
806-
<Select
807-
value={theme}
808-
onValueChange={(value) => {
809-
if (value === "system" || value === "light" || value === "dark") {
810-
setTheme(value);
811-
}
812-
}}
813-
>
814-
<SelectTrigger className="w-full sm:w-40" aria-label="Theme preference">
815-
<SelectValue>
816-
{THEME_OPTIONS.find((option) => option.value === theme)?.label ?? "System"}
817-
</SelectValue>
818-
</SelectTrigger>
819-
<SelectPopup align="end" alignItemWithTrigger={false}>
820-
{THEME_OPTIONS.map((option) => (
821-
<SelectItem hideIndicator key={option.value} value={option.value}>
822-
{option.label}
823-
</SelectItem>
824-
))}
825-
</SelectPopup>
826-
</Select>
827-
}
828-
/>
829-
830781
<SettingsRow
831782
title="Time format"
832783
description="System default follows your browser or OS clock preference."

‎apps/web/src/components/settings/SettingsSidebarNav.tsx‎

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
11
import { useCallback, type ComponentType } from "react";
2-
import { ArchiveIcon, ArrowLeftIcon, GitBranchIcon, Link2Icon, Settings2Icon } from "lucide-react";
2+
import {
3+
ArchiveIcon,
4+
ArrowLeftIcon,
5+
GitBranchIcon,
6+
Link2Icon,
7+
PaletteIcon,
8+
Settings2Icon,
9+
} from "lucide-react";
310
import { useCanGoBack, useNavigate } from "@tanstack/react-router";
411

512
import {
@@ -15,6 +22,7 @@ import {
1522

1623
export type SettingsSectionPath =
1724
| "/settings/general"
25+
| "/settings/appearance"
1826
| "/settings/source-control"
1927
| "/settings/connections"
2028
| "/settings/archived";
@@ -25,6 +33,7 @@ export const SETTINGS_NAV_ITEMS: ReadonlyArray<{
2533
icon: ComponentType<{ className?: string }>;
2634
}> = [
2735
{ label: "General", to: "/settings/general", icon: Settings2Icon },
36+
{ label: "Appearance", to: "/settings/appearance", icon: PaletteIcon },
2837
{ label: "Source Control", to: "/settings/source-control", icon: GitBranchIcon },
2938
{ label: "Connections", to: "/settings/connections", icon: Link2Icon },
3039
{ label: "Archive", to: "/settings/archived", icon: ArchiveIcon },
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
import { describe, expect, it } from "vitest";
2+
3+
import type { ThemeDefinition } from "../../themes/types";
4+
import { setThemeDescription, setThemeName, setTokenValue } from "./ThemeEditor";
5+
6+
const BASE: ThemeDefinition = {
7+
id: "test",
8+
name: "Test",
9+
builtIn: false,
10+
};
11+
12+
describe("setTokenValue", () => {
13+
it("sets a token on the requested variant without mutating the source", () => {
14+
const next = setTokenValue(BASE, "dark", "primary", "#ff0000");
15+
expect(next).not.toBe(BASE);
16+
expect(next.dark).toEqual({ primary: "#ff0000" });
17+
expect(BASE.dark).toBeUndefined();
18+
});
19+
20+
it("removes a token when the value is empty", () => {
21+
const seeded: ThemeDefinition = {
22+
...BASE,
23+
light: { primary: "#abc", background: "#fff" },
24+
};
25+
const next = setTokenValue(seeded, "light", "primary", "");
26+
expect(next.light).toEqual({ background: "#fff" });
27+
});
28+
29+
it("merges into the same variant only", () => {
30+
const seeded: ThemeDefinition = {
31+
...BASE,
32+
light: { primary: "#abc" },
33+
dark: { primary: "#def" },
34+
};
35+
const next = setTokenValue(seeded, "light", "background", "#fff");
36+
expect(next.light).toEqual({ primary: "#abc", background: "#fff" });
37+
expect(next.dark).toEqual({ primary: "#def" });
38+
});
39+
});
40+
41+
describe("setThemeName", () => {
42+
it("returns a new theme with the updated name", () => {
43+
const next = setThemeName(BASE, "Renamed");
44+
expect(next.name).toBe("Renamed");
45+
expect(BASE.name).toBe("Test");
46+
});
47+
});
48+
49+
describe("setThemeDescription", () => {
50+
it("sets the description when non-empty", () => {
51+
const next = setThemeDescription(BASE, "A theme");
52+
expect(next.description).toBe("A theme");
53+
});
54+
55+
it("removes the description when empty", () => {
56+
const seeded: ThemeDefinition = { ...BASE, description: "old" };
57+
const next = setThemeDescription(seeded, "");
58+
expect(next.description).toBeUndefined();
59+
expect("description" in next).toBe(false);
60+
});
61+
});

0 commit comments

Comments
 (0)