Skip to content

Commit 85c6016

Browse files
committed
feat(web): add theme gallery and custom palettes
1 parent 91a03e0 commit 85c6016

11 files changed

Lines changed: 733 additions & 186 deletions

File tree

‎apps/desktop/src/clientPersistence.test.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ const clientSettings: ClientSettings = {
6363
sidebarProjectSortOrder: "manual",
6464
sidebarThreadSortOrder: "created_at",
6565
timestampFormat: "24-hour",
66+
theme: "system",
67+
customCSS: "",
6668
};
6769

6870
const savedRegistryRecord: PersistedSavedEnvironmentRecord = {

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

Lines changed: 256 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
1-
import { ArchiveIcon, ArchiveX, LoaderIcon, PlusIcon, RefreshCwIcon } from "lucide-react";
1+
import {
2+
ArchiveIcon,
3+
ArchiveX,
4+
CheckIcon,
5+
LoaderIcon,
6+
PlusIcon,
7+
RefreshCwIcon,
8+
} from "lucide-react";
29
import { useQueryClient } from "@tanstack/react-query";
310
import { useCallback, useMemo, useRef, useState } from "react";
411
import {
@@ -10,7 +17,7 @@ import {
1017
type ScopedThreadRef,
1118
} from "@t3tools/contracts";
1219
import { scopeThreadRef } from "@t3tools/client-runtime";
13-
import { DEFAULT_UNIFIED_SETTINGS } from "@t3tools/contracts/settings";
20+
import { DEFAULT_UNIFIED_SETTINGS, type ThemeMode } from "@t3tools/contracts/settings";
1421
import { createModelSelection } from "@t3tools/shared/model";
1522
import { Equal } from "effect";
1623
import { APP_VERSION } from "../../branding";
@@ -25,7 +32,7 @@ import { ProviderModelPicker } from "../chat/ProviderModelPicker";
2532
import { TraitsPicker } from "../chat/TraitsPicker";
2633
import { resolveAndPersistPreferredEditor } from "../../editorPreferences";
2734
import { isElectron } from "../../env";
28-
import { useTheme } from "../../hooks/useTheme";
35+
import { useTheme, THEMES } from "../../hooks/useTheme";
2936
import { useSettings, useUpdateSettings } from "../../hooks/useSettings";
3037
import { useThreadActions } from "../../hooks/useThreadActions";
3138
import {
@@ -74,21 +81,179 @@ import {
7481
useServerProviders,
7582
} from "../../rpc/serverState";
7683

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-
},
84+
const BUILT_IN_THEME_OPTIONS = [
85+
{ value: "system", label: "System" },
86+
{ value: "light", label: "Light" },
87+
{ value: "dark", label: "Dark" },
88+
...Object.entries(THEMES).map(([value, definition]) => ({
89+
value: value as Exclude<ThemeMode, "system" | "light" | "dark" | "custom">,
90+
label: definition.label,
91+
})),
9092
] as const;
9193

94+
function themePreviewTokens(value: ThemeMode) {
95+
if (value === "system" || value === "light") {
96+
return {
97+
background: "0 0% 100%",
98+
foreground: "220 18% 16%",
99+
card: "0 0% 100%",
100+
primary: "262 83% 58%",
101+
secondary: "220 14% 96%",
102+
accent: "220 14% 92%",
103+
border: "220 13% 88%",
104+
};
105+
}
106+
107+
if (value === "dark") {
108+
return {
109+
background: "220 18% 10%",
110+
foreground: "220 20% 92%",
111+
card: "220 18% 12%",
112+
primary: "262 83% 68%",
113+
secondary: "220 18% 16%",
114+
accent: "220 18% 22%",
115+
border: "220 18% 20%",
116+
};
117+
}
118+
119+
const customTheme = THEMES[value as keyof typeof THEMES];
120+
return {
121+
background: customTheme?.colors.bg ?? "0 0% 10%",
122+
foreground: customTheme?.colors.fg ?? "0 0% 90%",
123+
card: customTheme?.colors.card ?? "0 0% 14%",
124+
primary: customTheme?.colors.primary ?? "0 0% 90%",
125+
secondary: customTheme?.colors.secondary ?? "0 0% 18%",
126+
accent: customTheme?.colors.accent ?? "0 0% 24%",
127+
border: customTheme?.colors.secondary ?? "0 0% 18%",
128+
};
129+
}
130+
131+
function ThemePreview({ themeMode, selected }: { themeMode: ThemeMode; selected: boolean }) {
132+
const tokens = themePreviewTokens(themeMode);
133+
const sidebarBackground =
134+
themeMode === "light" || themeMode === "system"
135+
? "0 0% 98%"
136+
: `color-mix(in srgb, hsl(${tokens.background}) 82%, black)`;
137+
138+
return (
139+
<div
140+
className="relative h-28 overflow-hidden rounded-xl border shadow-sm"
141+
style={
142+
{
143+
backgroundColor: `hsl(${tokens.background})`,
144+
borderColor: `hsl(${tokens.border})`,
145+
color: `hsl(${tokens.foreground})`,
146+
} as React.CSSProperties
147+
}
148+
>
149+
<div className="absolute inset-0 opacity-[0.06] [background-image:radial-gradient(circle_at_top_right,currentColor_0,transparent_42%)]" />
150+
<div className="grid h-full grid-cols-[30%_1fr]">
151+
<div
152+
className="border-r p-2"
153+
style={{
154+
backgroundColor:
155+
themeMode === "light" || themeMode === "system"
156+
? `hsl(${sidebarBackground})`
157+
: sidebarBackground,
158+
borderColor: `hsl(${tokens.border})`,
159+
}}
160+
>
161+
<div className="mb-2 flex items-center gap-1.5">
162+
<div
163+
className="size-2 rounded-full"
164+
style={{ backgroundColor: `hsl(${tokens.primary})` }}
165+
/>
166+
<div
167+
className="h-1.5 w-8 rounded-full opacity-85"
168+
style={{ backgroundColor: `hsl(${tokens.foreground})` }}
169+
/>
170+
</div>
171+
<div className="space-y-1.5">
172+
<div
173+
className="h-4 rounded-md"
174+
style={{ backgroundColor: `hsl(${tokens.secondary})` }}
175+
/>
176+
<div
177+
className="h-4 rounded-md"
178+
style={{ backgroundColor: `hsl(${tokens.accent})`, opacity: 0.8 }}
179+
/>
180+
<div
181+
className="h-4 w-3/4 rounded-md opacity-70"
182+
style={{ backgroundColor: `hsl(${tokens.secondary})` }}
183+
/>
184+
</div>
185+
</div>
186+
<div className="p-2">
187+
<div
188+
className="mb-2 flex items-center justify-between rounded-md border px-2 py-1"
189+
style={{
190+
backgroundColor: `hsl(${tokens.card})`,
191+
borderColor: `hsl(${tokens.border})`,
192+
}}
193+
>
194+
<div
195+
className="h-1.5 w-10 rounded-full opacity-70"
196+
style={{ backgroundColor: `hsl(${tokens.foreground})` }}
197+
/>
198+
<div
199+
className="h-4 w-4 rounded-md"
200+
style={{ backgroundColor: `hsl(${tokens.secondary})` }}
201+
/>
202+
</div>
203+
<div className="space-y-2">
204+
<div
205+
className="ml-auto w-3/4 rounded-lg px-2 py-1.5"
206+
style={{
207+
backgroundColor: `hsl(${tokens.primary})`,
208+
color: `hsl(${tokens.background})`,
209+
}}
210+
>
211+
<div className="h-1.5 w-full rounded-full bg-current opacity-35" />
212+
</div>
213+
<div
214+
className="w-4/5 rounded-lg border px-2 py-1.5"
215+
style={{
216+
backgroundColor: `hsl(${tokens.card})`,
217+
borderColor: `hsl(${tokens.border})`,
218+
}}
219+
>
220+
<div
221+
className="mb-1 h-1.5 w-5/6 rounded-full opacity-75"
222+
style={{ backgroundColor: `hsl(${tokens.foreground})` }}
223+
/>
224+
<div
225+
className="h-1.5 w-2/3 rounded-full opacity-40"
226+
style={{ backgroundColor: `hsl(${tokens.foreground})` }}
227+
/>
228+
</div>
229+
</div>
230+
<div
231+
className="absolute bottom-2 right-2 left-[calc(30%+0.5rem)] flex items-center gap-1 rounded-md border px-2 py-1"
232+
style={{
233+
backgroundColor: `hsl(${tokens.card})`,
234+
borderColor: `hsl(${tokens.border})`,
235+
}}
236+
>
237+
<div
238+
className="h-1.5 flex-1 rounded-full opacity-40"
239+
style={{ backgroundColor: `hsl(${tokens.foreground})` }}
240+
/>
241+
<div
242+
className="h-5 w-6 rounded-md"
243+
style={{ backgroundColor: `hsl(${tokens.primary})` }}
244+
/>
245+
</div>
246+
</div>
247+
</div>
248+
{selected ? (
249+
<div className="absolute top-2 right-2 flex size-5 items-center justify-center rounded-full border border-white/35 bg-primary text-primary-foreground shadow-sm">
250+
<CheckIcon className="size-3" />
251+
</div>
252+
) : null}
253+
</div>
254+
);
255+
}
256+
92257
const TIMESTAMP_FORMAT_LABELS = {
93258
locale: "System default",
94259
"12-hour": "12-hour",
@@ -448,7 +613,6 @@ export function useSettingsRestore(onRestored?: () => void) {
448613
}
449614

450615
export function GeneralSettingsPanel() {
451-
const { theme, setTheme } = useTheme();
452616
const settings = useSettings();
453617
const { updateSettings } = useUpdateSettings();
454618
const [openingPathByTarget, setOpeningPathByTarget] = useState({
@@ -794,39 +958,6 @@ export function GeneralSettingsPanel() {
794958
return (
795959
<SettingsPageContainer>
796960
<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-
830961
<SettingsRow
831962
title="Time format"
832963
description="System default follows your browser or OS clock preference."
@@ -1492,3 +1623,78 @@ export function ArchivedThreadsPanel() {
14921623
</SettingsPageContainer>
14931624
);
14941625
}
1626+
1627+
export function ThemesPanel() {
1628+
const { theme, setTheme, customCSS } = useTheme();
1629+
const { updateSettings } = useUpdateSettings();
1630+
1631+
const handleCustomCSSChange = useCallback(
1632+
(next: string) => {
1633+
updateSettings({ customCSS: next });
1634+
},
1635+
[updateSettings],
1636+
);
1637+
1638+
return (
1639+
<SettingsPageContainer>
1640+
<SettingsSection title="Theme">
1641+
<div className="grid grid-cols-1 gap-4 p-4 sm:grid-cols-2 xl:grid-cols-3">
1642+
{BUILT_IN_THEME_OPTIONS.map((t) => {
1643+
const isSelected = theme === t.value;
1644+
return (
1645+
<button
1646+
key={t.value}
1647+
type="button"
1648+
className={`flex flex-col gap-3 rounded-2xl border p-3 text-left transition-all ${
1649+
isSelected
1650+
? "border-primary bg-accent/30 ring-1 ring-primary"
1651+
: "border-border/60 hover:border-muted-foreground/40 hover:bg-accent/15"
1652+
}`}
1653+
onClick={() => setTheme(t.value as ThemeMode)}
1654+
>
1655+
<ThemePreview themeMode={t.value as ThemeMode} selected={isSelected} />
1656+
<div className="flex items-center justify-between gap-3">
1657+
<div>
1658+
<div className="text-sm font-medium text-foreground">{t.label}</div>
1659+
<div className="text-xs text-muted-foreground">
1660+
{t.value === "system"
1661+
? "Follows your OS appearance"
1662+
: t.value === "light"
1663+
? "Default light UI"
1664+
: t.value === "dark"
1665+
? "Default dark UI"
1666+
: "Built-in theme"}
1667+
</div>
1668+
</div>
1669+
{isSelected ? (
1670+
<span className="rounded-full bg-primary/12 px-2 py-1 text-[11px] font-medium text-primary">
1671+
Active
1672+
</span>
1673+
) : null}
1674+
</div>
1675+
</button>
1676+
);
1677+
})}
1678+
</div>
1679+
</SettingsSection>
1680+
1681+
<SettingsSection title="Custom CSS">
1682+
<div className="space-y-2 px-4 py-2">
1683+
<p className="text-xs text-muted-foreground">
1684+
Add custom CSS to further customize the theme. Use CSS variables like{" "}
1685+
<code className="text-[10px]">--background</code>,{" "}
1686+
<code className="text-[10px]">--foreground</code>,{" "}
1687+
<code className="text-[10px]">--primary</code>, etc.
1688+
</p>
1689+
<textarea
1690+
className="min-h-[200px] w-full rounded-md border border-border bg-background p-3 font-mono text-xs focus:border-primary focus:outline-none focus:ring-1 focus:ring-primary"
1691+
value={customCSS}
1692+
onChange={(e) => handleCustomCSSChange(e.target.value)}
1693+
placeholder={`/* Example: Change the primary color */\n--primary: 210 100% 50%;\n\n/* Or add custom styles */\nbody {\n font-family: 'Fira Code', monospace;\n}`}
1694+
spellCheck={false}
1695+
/>
1696+
</div>
1697+
</SettingsSection>
1698+
</SettingsPageContainer>
1699+
);
1700+
}

‎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 {
@@ -17,6 +24,7 @@ export type SettingsSectionPath =
1724
| "/settings/general"
1825
| "/settings/source-control"
1926
| "/settings/connections"
27+
| "/settings/themes"
2028
| "/settings/archived";
2129

2230
export const SETTINGS_NAV_ITEMS: ReadonlyArray<{
@@ -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: "Themes", to: "/settings/themes", 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 },

0 commit comments

Comments
 (0)