feat(web): add modular theme library #5226
MergedStiensWout(GitHub profile, opens in a new tab)merged 118 commits into
main fromrefs/pull/5226/headmerged by juliusmarminge View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
- apps/web/src/components/settings/SettingsPanels.tsx lines 1137 to 1144OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -949,0 +1124,21 @@1124+ open: boolean;1125+ onOpenChange: (open: boolean) => void;1126+ onCreated: (theme: ThemeDefinition) => void;1127+ initialAppearance: ThemeAppearance;1128+}) {1129+ const [name, setName] = useState("");1130+ const [modeSelection, setModeSelection] = useState<ThemeEditorModeSelection>("single");1131+ const [activeAppearance, setActiveAppearance] = useState<ThemeAppearance>(initialAppearance);1132+ const [colorsByAppearance, setColorsByAppearance] = useState<ThemeEditorColorsByAppearance>(() =>1133+ getThemeEditorColorsByAppearance(),1134+ );1135+ const [error, setError] = useState<string | null>(null);1136+1137+ useEffect(() => {1138+ if (!open) return;1139+ setName("");1140+ setModeSelection("single");1141+ setActiveAppearance(initialAppearance);1142+ setColorsByAppearance(getThemeEditorColorsByAppearance());1143+ setError(null);1144+ }, [initialAppearance, open]);apps/web/src/themePalette.ts line 598OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +578,21 @@578+ terminalBackground: "--app-theme-terminal-background",579+ terminalForeground: "--app-theme-terminal-foreground",580+ terminalCursor: "--app-theme-terminal-cursor",581+ terminalSelection: "--app-theme-terminal-selection-background",582+ terminalScrollbar: "--app-theme-terminal-scrollbar",583+ terminalScrollbarHover: "--app-theme-terminal-scrollbar-hover",584+};585+586+export function applyThemePalette(theme: ThemePreference, appearance?: ThemeAppearance): void {587+ if (typeof document === "undefined") return;588+589+ const root = document.documentElement;590+ if (!root?.style) return;591+592+ const palette = getThemeDefinition(theme);593+594+ if (palette) {595+ root.dataset.themeId = palette.id;596+ // A bare theme id follows the global appearance preference. Only an597+ // explicit `theme:light`/`theme:dark` preference should override it.598+ const mode = explicitThemeMode(theme) ?? appearance ?? palette.appearance;apps/web/src/hooks/useTheme.ts line 615Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -318 +392,21 @@392+ writeFollowSystemPreference(nextFollowSystem);393+ } catch (cause) {394+ const error = isThemeStorageError(cause)395+ ? cause396+ : new ThemeStorageError({397+ operation: "write",398+ storageKey: THEME_FOLLOW_SYSTEM_STORAGE_KEY,399+ cause,400+ });401+ console.error(error.message, {402+ operation: error.operation,403+ storageKey: error.storageKey,404+ ...safeErrorLogAttributes(error),405+ });406+ return;407+ }408+ applyTheme(getStored(), true);409+ emitChange();410+ }, []);411+318412 // Keep DOM in sync on mount/changeapps/web/src/components/chat/MessagesTimeline.tsx lines 1369 to 1369OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -1370,4 +1366,4 @@13701366 ) : null}13711367 <div className="min-w-0 px-2.5 py-2">13721368 {props.annotation.comment ? (1373- <div className="max-w-80 truncate text-xs font-medium text-foreground/90">1369+ <div className="max-w-80 truncate text-message-foreground text-xs font-medium">apps/web/src/components/settings/SettingsPanels.tsx line 1302OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -949,0 +1399,21 @@1399+ />1400+ </div>1401+ );1402+}1403+1404+function ThemeImportDialog({1405+ open,1406+ onOpenChange,1407+ onImported,1408+}: {1409+ open: boolean;1410+ onOpenChange: (open: boolean) => void;1411+ onImported: (theme: ThemeDefinition) => void;1412+}) {1413+ const fileInputRef = useRef<HTMLInputElement>(null);1414+ const [json, setJson] = useState("");1415+ const [fileName, setFileName] = useState<string | null>(null);1416+ const [error, setError] = useState<string | null>(null);1417+ const [isReading, setIsReading] = useState(false);1418+1419+ useEffect(() => {
- apps/web/src/hooks/useTheme.ts line 339OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -272,3 +333,7 @@272333 themeStorageReadFailure = null;273334 applyTheme(getStored(), true);274335 emitChange();336+ } else if (e.key === THEME_FOLLOW_SYSTEM_STORAGE_KEY) {337+ applyTheme(getStored(), true);338+ emitChange();339+ } else if (e.key === CUSTOM_THEMES_STORAGE_KEY) {apps/web/src/hooks/useTheme.ts lines 406 to 408OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -317 +388,21 @@317388389+ const setFollowSystem = useCallback((nextFollowSystem: boolean) => {390+ if (typeof window === "undefined") return;391+ try {392+ writeFollowSystemPreference(nextFollowSystem);393+ } catch (cause) {394+ const error = isThemeStorageError(cause)395+ ? cause396+ : new ThemeStorageError({397+ operation: "write",398+ storageKey: THEME_FOLLOW_SYSTEM_STORAGE_KEY,399+ cause,400+ });401+ console.error(error.message, {402+ operation: error.operation,403+ storageKey: error.storageKey,404+ ...safeErrorLogAttributes(error),405+ });406+ return;407+ }408+ applyTheme(getStored(), true);apps/web/src/components/settings/SettingsPanels.tsx lines 1758 to 1765OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -950,0 +1745,21 @@1745+ (checked: boolean) => {1746+ setFollowSystem(checked);1747+ setTheme(1748+ checked1749+ ? (activeTheme?.id ?? "system")1750+ : activeTheme1751+ ? themePreferenceForMode(activeTheme, initialAppearance)1752+ : initialAppearance,1753+ );1754+ },1755+ [activeTheme, initialAppearance, setFollowSystem, setTheme],1756+ );1757+1758+ const handleRemoveTheme = useCallback(1759+ (customTheme: ThemeDefinition) => {1760+ if (!window.confirm(`Remove the “${customTheme.label}” theme?`)) return;1761+ removeCustomTheme(customTheme.id);1762+ if (getThemeDefinition(theme)?.id === customTheme.id) setTheme("system");1763+ },1764+ [setTheme, theme],1765+ );apps/web/src/components/settings/SettingsPanels.tsx lines 1922 to 1922OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -979,20 +1922 @@979- onValueChange={(value) => {980- if (value === "system" || value === "light" || value === "dark") {981- setTheme(value);982- }983- }}984- >985- <SelectTrigger className="w-full sm:w-40" aria-label="Theme preference">986- <SelectValue>987- {THEME_OPTIONS.find((option) => option.value === theme)?.label ?? "System"}988- </SelectValue>989- </SelectTrigger>990- <SelectPopup align="end" alignItemWithTrigger={false}>991- {THEME_OPTIONS.map((option) => (992- <SelectItem hideIndicator key={option.value} value={option.value}>993- {option.label}994- </SelectItem>995- ))}996- </SelectPopup>997- </Select>998- }1922+ <SettingsSection title="Appearance">apps/web/src/themePalette.ts line 253Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +191,21 @@191+ for (const listener of customThemeListeners) listener();192+}193+194+export function invalidateCustomThemes() {195+ customThemesSnapshot = null;196+ notifyCustomThemeListeners();197+}198+199+export function getCustomThemes(): ReadonlyArray<ThemeDefinition> {200+ if (customThemesSnapshot === null) {201+ customThemesSnapshot = readCustomThemesFromStorage();202+ }203+ return customThemesSnapshot;204+}205+206+export function subscribeToCustomThemes(listener: () => void): () => void {207+ customThemeListeners.add(listener);208+ if (typeof window === "undefined") {209+ return () => customThemeListeners.delete(listener);210+ }211+ const handleStorage = (event: StorageEvent) => {apps/web/src/themePalette.ts lines 532 to 537OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +517,21 @@517+518+ const id = value.id === undefined ? themeIdFromName(name) : value.id;519+ if (!isThemeId(id)) {520+ throw new Error("Theme ids may only contain lowercase letters, numbers, and hyphens.");521+ }522+ if (RESERVED_THEME_IDS.has(id)) {523+ throw new Error(`The theme id "${id}" is reserved.`);524+ }525+526+ const overrides = parseThemeColorOverrides(rawColors);527+528+ const fallback = appearance === "dark" ? T3_CHAT_DARK_THEME.colors : T3_CHAT_THEME.colors;529+ const variants: Partial<Record<ThemeAppearance, ThemeColors>> = {};530+ if (value.variants !== undefined) {531+ if (!isRecord(value.variants)) throw new Error("Theme variants must be an object.");532+ for (const [variantAppearance, variantColors] of Object.entries(value.variants)) {533+ if (!isThemeAppearance(variantAppearance)) {534+ throw new Error('Theme variants may only be named "light" or "dark".');535+ }536+ const variantFallback =537+ variantAppearance === "dark" ? T3_CHAT_DARK_THEME.colors : T3_CHAT_THEME.colors;
- apps/web/src/index.css line 1071OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -991,0 +1051,21 @@1051+/* Theme files are expressed in app color roles and mapped to the existing1052+ semantic surface tokens here. Keep this block after the sidebar-version1053+ compatibility overrides so both navigation implementations receive the1054+ same palette. Success, info, provider, and channel identity colors remain1055+ independent; error, warning, and update roles are themeable below. */1056+html[data-theme-id],1057+html.dark[data-theme-id] {1058+ --background: var(--app-theme-canvas);1059+ --app-chrome-background: var(--app-theme-chrome);1060+ --surface-raised: var(--app-theme-surface-raised);1061+ --foreground: var(--app-theme-text);1062+ --card: var(--app-theme-surface);1063+ --card-foreground: var(--app-theme-text);1064+ --popover: var(--app-theme-surface-overlay);1065+ --popover-foreground: var(--app-theme-text);1066+ --primary: var(--app-theme-accent);1067+ --primary-foreground: var(--app-theme-accent-foreground);1068+ --secondary: var(--app-theme-secondary);1069+ --secondary-foreground: var(--app-theme-secondary-foreground);1070+ --muted: var(--app-theme-muted);1071+ --muted-foreground: var(--app-theme-muted-foreground);
- @@ -26,0 +141,21 @@141+ storedTheme === "system" ||142+ isT3Chat ||143+ customTheme !== null;144+ const theme = hasStoredTheme && storedTheme ? storedTheme : "system";145+ const isDark = customTheme146+ ? customTheme.mode === "dark"147+ : isT3Chat148+ ? t3ChatMode === "dark"149+ : followSystem150+ ? prefersDark151+ : theme === "dark";152+ if (isT3Chat || customTheme !== null) {153+ document.documentElement.dataset.themeId = isT3Chat ? "t3-chat" : customTheme.theme.id;154+ } else {155+ delete document.documentElement.dataset.themeId;156+ }157+ if (hasStoredTheme) {158+ document.documentElement.dataset.themeSelected = "true";159+ } else {160+ delete document.documentElement.dataset.themeSelected;161+ }@@ -26,0 +131,21 @@131+ : followSystem || preference.mode === "system"132+ ? prefersDark133+ ? "dark"134+ : "light"135+ : preference.id === "t3-chat-dark"136+ ? "dark"137+ : (preference.mode ?? "light");138+ const hasStoredTheme =139+ storedTheme === "light" ||140+ storedTheme === "dark" ||141+ storedTheme === "system" ||142+ isT3Chat ||143+ customTheme !== null;144+ const theme = hasStoredTheme && storedTheme ? storedTheme : "system";145+ const isDark = customTheme146+ ? customTheme.mode === "dark"147+ : isT3Chat148+ ? t3ChatMode === "dark"149+ : followSystem150+ ? prefersDark151+ : theme === "dark";@@ -26,0 +136,21 @@136+ ? "dark"137+ : (preference.mode ?? "light");138+ const hasStoredTheme =139+ storedTheme === "light" ||140+ storedTheme === "dark" ||141+ storedTheme === "system" ||142+ isT3Chat ||143+ customTheme !== null;144+ const theme = hasStoredTheme && storedTheme ? storedTheme : "system";145+ const isDark = customTheme146+ ? customTheme.mode === "dark"147+ : isT3Chat148+ ? t3ChatMode === "dark"149+ : followSystem150+ ? prefersDark151+ : theme === "dark";152+ if (isT3Chat || customTheme !== null) {153+ document.documentElement.dataset.themeId = isT3Chat ? "t3-chat" : customTheme.theme.id;154+ } else {155+ delete document.documentElement.dataset.themeId;156+ }
- apps/web/src/components/settings/SettingsPanels.tsx line 1175OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -950,0 +1155,21 @@1155+ open: boolean;1156+ onOpenChange: (open: boolean) => void;1157+ onCreated: (theme: ThemeDefinition) => void;1158+ initialAppearance: ThemeAppearance;1159+}) {1160+ const [name, setName] = useState("");1161+ const [modeSelection, setModeSelection] = useState<ThemeEditorModeSelection>("single");1162+ const [activeAppearance, setActiveAppearance] = useState<ThemeAppearance>(initialAppearance);1163+ const [isAdvanced, setIsAdvanced] = useState(false);1164+ const [colorsByAppearance, setColorsByAppearance] = useState<ThemeEditorColorsByAppearance>(() =>1165+ getThemeEditorColorsByAppearance(),1166+ );1167+ const [error, setError] = useState<string | null>(null);1168+ const previousOpenRef = useRef(false);1169+1170+ useEffect(() => {1171+ if (open && !previousOpenRef.current) {1172+ setName("");1173+ setModeSelection("single");1174+ setActiveAppearance(initialAppearance);1175+ setIsAdvanced(false);
- apps/web/src/components/settings/SettingsPanels.tsx line 1742OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -950,0 +1722,21 @@1722+ activeMode?: ThemeAppearance | null;1723+ onDownload?: () => void;1724+ onRemove?: () => void;1725+}) {1726+ return (1727+ <div1728+ className={cn(1729+ "cursor-pointer overflow-hidden rounded-xl border border-border/70 bg-card/60 outline-none transition-colors hover:bg-accent/10 focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",1730+ isActive && "bg-accent/30",1731+ )}1732+ aria-label={`${theme.label} theme${isActive ? ", currently active" : ""}`}1733+ aria-pressed={isActive}1734+ data-theme-library-card={theme.id}1735+ onClick={onUse}1736+ onKeyDown={(event) => {1737+ if (event.target !== event.currentTarget) return;1738+ if (event.key !== "Enter" && event.key !== " ") return;1739+ event.preventDefault();1740+ onUse();1741+ }}1742+ role="button"
- apps/web/src/components/settings/SettingsPanels.tsx lines 1119 to 1119OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -950,0 +1099,21 @@1099+ warningSurface: "Warning background",1100+ updateForeground: "Update text",1101+ updateSurface: "Update background",1102+ };1103+ const label = labels[role];1104+ if (label) return label;1105+ return role.replace(/([A-Z])/g, " $1").replace(/^./, (character) => character.toUpperCase());1106+}1107+1108+function ThemeColorField({1109+ role,1110+ value,1111+ onChange,1112+}: {1113+ role: ThemeColorRole;1114+ value: string;1115+ onChange: (value: string) => void;1116+}) {1117+ const label = getThemeRoleLabel(role);1118+ const isColorValue = /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(value);1119+ const pickerValue = /^#[0-9a-f]{6}$/i.test(value) ? value : "#000000";
- apps/web/src/components/settings/SettingsPanels.tsx line 1923OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -950,0 +1903,21 @@1903+ const handleFollowSystemChange = useCallback(1904+ (checked: boolean) => {1905+ setFollowSystem(checked);1906+ setTheme(1907+ checked1908+ ? (activeTheme?.id ?? "system")1909+ : activeTheme1910+ ? themePreferenceForMode(activeTheme, initialAppearance)1911+ : initialAppearance,1912+ );1913+ },1914+ [activeTheme, initialAppearance, setFollowSystem, setTheme],1915+ );1916+1917+ const handleRemoveTheme = useCallback((customTheme: ThemeDefinition) => {1918+ setThemeToRemove(customTheme);1919+ }, []);1920+1921+ const handleConfirmRemoveTheme = useCallback(() => {1922+ if (!themeToRemove) return;1923+ if (getThemeDefinition(theme)?.id === themeToRemove.id) setTheme("system");
- apps/web/src/components/settings/SettingsPanels.tsx line 1960OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -950,0 +1940,21 @@1940+ );1941+1942+ const handleEditedTheme = useCallback(1943+ (updatedTheme: ThemeDefinition) => {1944+ if (getThemeDefinition(theme)?.id === updatedTheme.id) {1945+ const selectedMode = followSystem ? null : getThemePreferenceMode(theme);1946+ const nextTheme =1947+ selectedMode && getThemeColorsForMode(updatedTheme, selectedMode)1948+ ? themePreferenceForMode(updatedTheme, selectedMode)1949+ : updatedTheme.id;1950+ setTheme(nextTheme);1951+ refreshTheme();1952+ }1953+ setThemeToEdit(null);1954+ toastManager.add(1955+ stackedThreadToast({1956+ type: "success",1957+ title: `${updatedTheme.label} saved`,1958+ description: "Your changes are now active.",1959+ }),1960+ );apps/web/src/components/settings/SettingsPanels.tsx line 1249OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -950,0 +1229,21 @@1229+ const handleSubmit = useCallback(() => {1230+ if (!name.trim()) {1231+ setError("Give your theme a name before saving it.");1232+ return;1233+ }1234+1235+ try {1236+ const baseAppearance =1237+ editingTheme && modeSelection === "both" ? editingTheme.appearance : activeAppearance;1238+ const variantAppearance = baseAppearance === "light" ? "dark" : "light";1239+ const variants =1240+ modeSelection === "both"1241+ ? { [variantAppearance]: colorsByAppearance[variantAppearance] }1242+ : undefined;1243+ const themeFile = {1244+ version: THEME_FILE_VERSION,1245+ ...(editingTheme ? { id: editingTheme.id } : {}),1246+ name,1247+ appearance: baseAppearance,1248+ colors: colorsByAppearance[baseAppearance],1249+ ...(variants ? { variants } : {}),
- apps/web/src/components/settings/SettingsPanels.tsx line 1608OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -950,0 +1588,21 @@1588+1589+ setSimpleColorsDirty(true);1590+ setColorsByAppearance((current) => ({1591+ light: getManagedEditorColors("light", current.light),1592+ dark: getManagedEditorColors("dark", current.dark),1593+ }));1594+ }, []);1595+1596+ const handleSubmit = useCallback(() => {1597+ if (!name.trim()) {1598+ setError("Give your theme a name before saving it.");1599+ return;1600+ }1601+1602+ try {1603+ const baseAppearance =1604+ editingTheme && getThemeModes(editingTheme).length > 11605+ ? editingTheme.appearance1606+ : activeAppearance;1607+ const variantAppearance = baseAppearance === "light" ? "dark" : "light";1608+ const colorsForSave =
- apps/web/src/components/settings/SettingsPanels.tsx line 1617OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -950,0 +1597,21 @@1597+ if (!name.trim()) {1598+ setError("Give your theme a name before saving it.");1599+ return;1600+ }1601+1602+ try {1603+ const baseAppearance =1604+ editingTheme && getThemeModes(editingTheme).length > 11605+ ? editingTheme.appearance1606+ : activeAppearance;1607+ const variantAppearance = baseAppearance === "light" ? "dark" : "light";1608+ const colorsForSave =1609+ !isAdvanced && (!isEditing || simpleColorsDirty)1610+ ? {1611+ light: getManagedEditorColors("light", colorsByAppearance.light),1612+ dark: getManagedEditorColors("dark", colorsByAppearance.dark),1613+ }1614+ : colorsByAppearance;1615+ const variants =1616+ modeSelection === "both"1617+ ? { [variantAppearance]: colorsForSave[variantAppearance] }
- apps/web/src/components/settings/SettingsPanels.tsx line 1615OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -950,0 +1595,21 @@1595+1596+ setSimpleColorsDirtyByAppearance((current) => ({1597+ ...current,1598+ [activeAppearance]: true,1599+ }));1600+ setColorsByAppearance((current) => ({1601+ ...current,1602+ [activeAppearance]: getManagedEditorColors(activeAppearance, current[activeAppearance]),1603+ }));1604+ },1605+ [activeAppearance],1606+ );1607+1608+ const handleSubmit = useCallback(() => {1609+ if (!name.trim()) {1610+ setError("Give your theme a name before saving it.");1611+ return;1612+ }1613+1614+ try {1615+ const baseAppearance =
- @@ -0,0 +686,21 @@686+export const T3_CHAT_THEME: ThemeDefinition = {687+ id: T3_CHAT_THEME_ID,688+ label: T3_CHAT_THEME_LABEL,689+ appearance: "light",690+ colors: T3_CHAT_LIGHT_COLORS,691+};692+693+/** Dark defaults are only used when creating a custom dark theme. */694+export function getDefaultThemeColors(appearance: ThemeAppearance): ThemeColors {695+ return appearance === "dark" ? DEFAULT_DARK_THEME_COLORS : T3_CHAT_THEME.colors;696+}697+698+export const T3_GROVE_THEME: ThemeDefinition = {699+ id: T3_GROVE_THEME_ID,700+ label: T3_GROVE_THEME_LABEL,701+ appearance: "light",702+ colors: createManagedThemeColors("light", "#f2faf4", "#218c5c"),703+ variants: {704+ dark: createManagedThemeColors("dark", "#102019", "#5ed58f"),705+ },706+};@@ -0,0 +685,21 @@685+686+export const T3_CHAT_THEME: ThemeDefinition = {687+ id: T3_CHAT_THEME_ID,688+ label: T3_CHAT_THEME_LABEL,689+ appearance: "light",690+ colors: T3_CHAT_LIGHT_COLORS,691+};692+693+/** Dark defaults are only used when creating a custom dark theme. */694+export function getDefaultThemeColors(appearance: ThemeAppearance): ThemeColors {695+ return appearance === "dark" ? DEFAULT_DARK_THEME_COLORS : T3_CHAT_THEME.colors;696+}697+698+export const T3_GROVE_THEME: ThemeDefinition = {699+ id: T3_GROVE_THEME_ID,700+ label: T3_GROVE_THEME_LABEL,701+ appearance: "light",702+ colors: createManagedThemeColors("light", "#f2faf4", "#218c5c"),703+ variants: {704+ dark: createManagedThemeColors("dark", "#102019", "#5ed58f"),705+ },apps/web/src/components/settings/SettingsPanels.tsx line 1631OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -950,0 +1611,21 @@1611+ return;1612+ }1613+1614+ try {1615+ const baseAppearance =1616+ editingTheme && getThemeModes(editingTheme).length > 11617+ ? editingTheme.appearance1618+ : activeAppearance;1619+ const variantAppearance = baseAppearance === "light" ? "dark" : "light";1620+ const colorsForSave = !isAdvanced1621+ ? {1622+ light:1623+ !isEditing || simpleColorsDirtyByAppearance.light1624+ ? getManagedEditorColors("light", colorsByAppearance.light)1625+ : colorsByAppearance.light,1626+ dark:1627+ !isEditing || simpleColorsDirtyByAppearance.dark1628+ ? getManagedEditorColors("dark", colorsByAppearance.dark)1629+ : colorsByAppearance.dark,1630+ }1631+ : colorsByAppearance;
- apps/web/src/components/settings/SettingsPanels.tsx lines 1613 to 1613OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -950,0 +1593,21 @@1593+1594+ setSimpleColorsDirtyByAppearance((current) => ({1595+ ...current,1596+ [activeAppearance]: true,1597+ }));1598+ setColorsByAppearance((current) => ({1599+ ...current,1600+ [activeAppearance]: getManagedEditorColors(activeAppearance, current[activeAppearance]),1601+ }));1602+ },1603+ [activeAppearance],1604+ );1605+1606+ const handleSubmit = useCallback(() => {1607+ if (!name.trim()) {1608+ setError("Give your theme a name before saving it.");1609+ return;1610+ }1611+1612+ try {1613+ const baseAppearance = editingTheme?.appearance ?? activeAppearance;apps/web/index.html lines 139 to 151OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -26,0 +131,21 @@131+ const customTheme = readCustomTheme(storedTheme, prefersDark, followSystem);132+ const isLegacyT3ChatDark = storedTheme === "t3-chat-dark";133+ const isT3Chat =134+ isLegacyT3ChatDark ||135+ (!preference.invalidMode &&136+ (preference.id === "t3-chat" || preference.id === "t3-chat-dark"));137+ const isT3Grove = !preference.invalidMode && preference.id === "t3-grove";138+ const isBuiltInTheme = isT3Chat || isT3Grove;139+ const builtInMode = isLegacyT3ChatDark140+ ? followSystem141+ ? prefersDark142+ ? "dark"143+ : "light"144+ : "dark"145+ : followSystem || preference.mode === "system"146+ ? prefersDark147+ ? "dark"148+ : "light"149+ : preference.id === "t3-chat-dark"150+ ? "dark"151+ : (preference.mode ?? "light");
- @@ -17,0 +34,21 @@34+ },35+ t3Chat: {36+ background: "#fffaff",37+ foreground: "#5c205f",38+ accent: "#c52d7b",39+ },40+ t3ChatDark: {41+ background: "#180f1b",42+ foreground: "#faeaf9",43+ accent: "#f06cab",44+ },45+ t3Grove: {46+ background: "#f4f8f5",47+ foreground: "#241523",48+ accent: "#1e7d52",49+ },50+ t3GroveDark: {51+ background: "#111f19",52+ foreground: "#fffaff",53+ accent: "#5dd58e",54+ },
- @@ -26,0 +146,21 @@146+ storedTheme === "dark" ||147+ storedTheme === "system" ||148+ (themeModes !== null && (explicitMode === null || themeModes.includes(explicitMode)));149+ const theme = isKnownTheme && storedTheme ? storedTheme : "system";150+ const storedFollowSystem = window.localStorage.getItem(THEME_FOLLOW_SYSTEM_STORAGE_KEY);151+ const followSystem =152+ storedFollowSystem === "true"153+ ? true154+ : storedFollowSystem === "false"155+ ? false156+ : theme === "system" || preference.mode === "system";157+ const isThemed = isKnownTheme && themeModes !== null;158+ const baseAppearance = customTheme ? customTheme.appearance : "light";159+ const systemMode = prefersDark ? "dark" : "light";160+ const themeMode = !isThemed161+ ? null162+ : followSystem || preference.mode === "system"163+ ? themeModes.includes(systemMode)164+ ? systemMode165+ : baseAppearance166+ : (explicitMode ?? baseAppearance);apps/web/src/components/settings/ThemeSettings.tsx line 321Resolvedby StiensWout(GitHub profile, opens in a new tab)@@ -0,0 +1425,21 @@1425+ checked1426+ ? (activeTheme?.id ?? "system")1427+ : activeTheme1428+ ? themePreferenceForMode(activeTheme, initialAppearance)1429+ : initialAppearance,1430+ );1431+ },1432+ [activeTheme, initialAppearance, setFollowSystem, setTheme],1433+ );1434+1435+ const handleRemoveTheme = useCallback((customTheme: ThemeDefinition) => {1436+ setThemeToRemove(customTheme);1437+ }, []);1438+1439+ const handleConfirmRemoveTheme = useCallback(() => {1440+ if (!themeToRemove) return;1441+ if (getThemeDefinition(theme)?.id === themeToRemove.id) {1442+ setTheme(followSystem ? "system" : initialAppearance);1443+ }1444+ removeCustomTheme(themeToRemove.id);1445+ setThemeToRemove(null);apps/web/src/components/settings/ThemeSettings.tsx line 1430OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -0,0 +1410,21 @@1410+ const [themeToEdit, setThemeToEdit] = useState<ThemeDefinition | null>(null);1411+ const [themeToRemove, setThemeToRemove] = useState<ThemeDefinition | null>(null);1412+ // Keep the last removal target so the dialog title stays populated while the1413+ // close animation plays after confirming.1414+ const lastThemeToRemoveRef = useRef<ThemeDefinition | null>(null);1415+ if (themeToRemove) lastThemeToRemoveRef.current = themeToRemove;1416+ const removeDialogTheme = themeToRemove ?? lastThemeToRemoveRef.current;1417+ const activeTheme = getThemeDefinition(theme);1418+ const standardThemes = getStandardThemeCards();1419+ const maintainerThemes = [T3_CHAT_THEME, T3_GROVE_THEME];1420+1421+ const handleFollowSystemChange = useCallback(1422+ (checked: boolean) => {1423+ setFollowSystem(checked);1424+ setTheme(1425+ checked1426+ ? (activeTheme?.id ?? "system")1427+ : activeTheme1428+ ? themePreferenceForMode(activeTheme, initialAppearance)1429+ : initialAppearance,1430+ );
- @@ -18 +51,21 @@51+ background: "#111f19",52+ foreground: "#fffaff",53+ accent: "#5dd58e",54+ },55+ };56+ // Built-in themes and the modes they can render. T3 Chat is light-only,57+ // so a dark OS must not flip its splash; the runtime resolves the same58+ // way via getThemeColorsForMode.59+ const BUILT_IN_THEME_MODES = {60+ "t3-chat": ["light"],61+ "t3-grove": ["light", "dark"],62+ };63+ const RESERVED_THEME_IDS = [64+ "system",65+ "light",66+ "dark",67+ "t3-chat",68+ "t3-grove",69+ "t3-chat-dark",70+ ];1871 const themeColorMeta = document.querySelector('meta[name="theme-color"]');
- apps/web/src/components/settings/ThemeSettings.tsx line 1430OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1410,21 @@1410+}) {1411+ const [isImportOpen, setIsImportOpen] = useState(false);1412+ const [isCreateOpen, setIsCreateOpen] = useState(false);1413+ const [themeToEdit, setThemeToEdit] = useState<ThemeDefinition | null>(null);1414+ const [themeToRemove, setThemeToRemove] = useState<ThemeDefinition | null>(null);1415+ // Keep the last removal target so the dialog title stays populated while the1416+ // close animation plays after confirming.1417+ const lastThemeToRemoveRef = useRef<ThemeDefinition | null>(null);1418+ if (themeToRemove) lastThemeToRemoveRef.current = themeToRemove;1419+ const removeDialogTheme = themeToRemove ?? lastThemeToRemoveRef.current;1420+ const activeTheme = getThemeDefinition(theme);1421+ const standardThemes = getStandardThemeCards();1422+ const maintainerThemes = [1423+ T3_CHAT_THEME,1424+ T3_GROVE_THEME,1425+ T3_OCEAN_THEME,1426+ T3_EMBER_THEME,1427+ T3_IRIS_THEME,1428+ ];1429+1430+ const handleFollowSystemChange = useCallback(@@ -18,0 +81,21 @@81+ };82+83+ const isHexColor = (value) =>84+ typeof value === "string" &&85+ /^#(?:[0-9a-f]{3}|[0-9a-f]{4}|[0-9a-f]{6}|[0-9a-f]{8})$/i.test(value);86+ const isThemePreferenceMode = (value) =>87+ value === "light" || value === "dark" || value === "system";88+ const isThemeAppearance = (value) => value === "light" || value === "dark";89+ const splitThemePreference = (preference) => {90+ const separatorIndex = preference.lastIndexOf(":");91+ if (separatorIndex <= 0) {92+ return { id: preference, mode: null, invalidMode: false };93+ }94+ const rawMode = preference.slice(separatorIndex + 1);95+ return {96+ id: preference.slice(0, separatorIndex),97+ mode: isThemePreferenceMode(rawMode) ? rawMode : null,98+ invalidMode: !isThemePreferenceMode(rawMode),99+ };100+ };101+ const findCustomTheme = (themeId) => {
- apps/web/src/components/settings/ThemeSettings.tsx line 1441OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +1421,21 @@1421+ const standardThemes = getStandardThemeCards();1422+ const maintainerThemes = [1423+ T3_CHAT_THEME,1424+ T3_GROVE_THEME,1425+ T3_OCEAN_THEME,1426+ T3_EMBER_THEME,1427+ T3_IRIS_THEME,1428+ ];1429+1430+ const handleFollowSystemChange = useCallback(1431+ (checked: boolean) => {1432+ // Keep the theme preference untouched when the follow-system write1433+ // fails, so the two stored values cannot drift apart.1434+ if (!setFollowSystem(checked)) return;1435+ setTheme(1436+ checked1437+ ? (activeTheme?.id ?? "system")1438+ : activeTheme1439+ ? themePreferenceForMode(activeTheme, initialAppearance)1440+ : initialAppearance,1441+ );@@ -27,4 +218,19 @@218+ } else {219+ delete document.documentElement.dataset.themeSelected;220+ }27221 document.documentElement.classList.toggle("dark", isDark);28- const chromeColor = isDark ? DARK_BACKGROUND : LIGHT_BACKGROUND;222+ const chromeColor = customSplash223+ ? customSplash.background224+ : builtInSplash225+ ? builtInSplash.background226+ : isDark227+ ? DARK_BACKGROUND228+ : LIGHT_BACKGROUND;29229 document.documentElement.style.backgroundColor = chromeColor;30- themeColorMeta?.setAttribute("content", chromeColor);230+ if (isKnownTheme && storedTheme !== null) {231+ const splashColors = customSplash ?? builtInSplash ?? fallbackSplash;232+ for (const [name, value] of Object.entries(splashColors)) {233+ document.documentElement.style.setProperty(`--boot-${name}`, value);234+ }235+ }236+ setThemeColor(chromeColor);
- apps/web/src/components/settings/ThemeSettings.tsx line 1473OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +1453,21 @@1453+ );1454+1455+ const handleFollowSystemChange = useCallback(1456+ (checked: boolean) => {1457+ const previousTheme = theme;1458+ const nextTheme = checked1459+ ? (activeTheme?.id ?? "system")1460+ : activeTheme1461+ ? themePreferenceForMode(activeTheme, initialAppearance)1462+ : initialAppearance;1463+1464+ // Write the theme first, then commit the follow-system flag. If the1465+ // second write fails, restore the original theme preference so the two1466+ // stored values cannot drift apart.1467+ if (!setTheme(nextTheme)) {1468+ notifyThemeSaveFailure();1469+ return;1470+ }1471+ if (setFollowSystem(checked)) return;1472+ setTheme(previousTheme);1473+ notifyThemeSaveFailure();
- apps/web/src/components/settings/ThemeSettings.tsx line 295Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +1469,21 @@1469+ return;1470+ }1471+ if (setTheme(nextTheme)) return;1472+ setFollowSystem(previousFollowSystem);1473+ notifyThemeSaveFailure();1474+ },1475+ [1476+ activeTheme,1477+ followSystem,1478+ initialAppearance,1479+ notifyThemeSaveFailure,1480+ setFollowSystem,1481+ setTheme,1482+ ],1483+ );1484+1485+ const handleRemoveTheme = useCallback((customTheme: ThemeDefinition) => {1486+ setThemeToRemove(customTheme);1487+ }, []);1488+1489+ const handleConfirmRemoveTheme = useCallback(() => {
- apps/web/src/components/settings/ThemeSettings.tsx line 319Resolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +1483,21 @@1483+ );1484+1485+ const handleRemoveTheme = useCallback((customTheme: ThemeDefinition) => {1486+ setThemeToRemove(customTheme);1487+ }, []);1488+1489+ const handleConfirmRemoveTheme = useCallback(() => {1490+ if (!themeToRemove) return;1491+ // Keep the theme installed if we cannot move the selection off it; the1492+ // dialog stays open so the user can retry or cancel.1493+ if (1494+ getThemeDefinition(theme)?.id === themeToRemove.id &&1495+ !persistTheme(followSystem ? "system" : initialAppearance)1496+ ) {1497+ return;1498+ }1499+ try {1500+ removeCustomTheme(themeToRemove.id);1501+ } catch {1502+ notifyThemeSaveFailure();1503+ return;
- apps/web/index.html lines 256 to 264OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -26,0 +244,21 @@244+ storedTheme === "light" ||245+ storedTheme === "dark" ||246+ storedTheme === "system" ||247+ (themeModes !== null && (explicitMode === null || themeModes.includes(explicitMode)));248+ const theme = isKnownTheme && storedTheme ? storedTheme : "system";249+ const isThemed = isKnownTheme && themeModes !== null;250+ const baseAppearance = customTheme ? customTheme.appearance : "light";251+ const systemMode = prefersDark ? "dark" : "light";252+ const storedAppearanceMode = window.localStorage.getItem(253+ THEME_APPEARANCE_MODE_STORAGE_KEY,254+ );255+ const storedFollowSystem = window.localStorage.getItem(THEME_FOLLOW_SYSTEM_STORAGE_KEY);256+ const appearanceMode = isThemePreferenceMode(storedAppearanceMode)257+ ? storedAppearanceMode258+ : storedFollowSystem === "true"259+ ? "system"260+ : storedFollowSystem === "false"261+ ? (explicitMode ?? baseAppearance)262+ : theme === "system" || preference.mode === "system"263+ ? "system"264+ : (explicitMode ?? baseAppearance);apps/web/src/components/settings/SettingsPanels.tsx line 682OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -690,4 +679,4 @@690679 );691680 if (!confirmed) return;692681693- setTheme("system");682+ const previousTheme = theme;
- apps/web/src/themePalette.ts lines 807 to 812OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +792,21 @@792+ const legacyMode = legacyThemeMode(theme);793+ if (legacyMode) return legacyMode;794+ return getThemeDefinition(theme)?.appearance ?? null;795+}796+797+function themeIdFromName(name: string): string {798+ const normalized = name799+ .trim()800+ .toLowerCase()801+ .replace(/[^a-z0-9]+/g, "-")802+ .replace(/^-+|-+$/g, "")803+ .slice(0, 48);804+ return normalized || "custom-theme";805+}806+807+export class ThemeLibraryStorageError extends Schema.TaggedErrorClass<ThemeLibraryStorageError>()(808+ "ThemeLibraryStorageError",809+ { cause: Schema.Defect() },810+) {811+ override get message(): string {812+ return `Could not save the theme library. ${this.cause instanceof Error ? this.cause.message : "Storage is unavailable."}`;
- apps/web/src/components/settings/ThemeColorPicker.tsx line 54Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +18,21 @@18+ warningForeground: "Warning text",19+ warningSurface: "Warning background",20+ updateForeground: "Update text",21+ updateSurface: "Update background",22+ };23+ const label = labels[role];24+ if (label) return label;25+ return role.replace(/([A-Z])/g, " $1").replace(/^./, (character) => character.toUpperCase());26+}27+28+type ThemeColorHsv = {29+ h: number;30+ s: number;31+ v: number;32+};33+34+function clampThemeColor(value: number, min = 0, max = 1) {35+ return Math.min(max, Math.max(min, value));36+}37+38+function normalizeThemePickerColor(value: string): string {apps/web/src/components/settings/ThemeImportDialog.tsx line 380Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +127,21 @@127+ const file = event.currentTarget.files?.[0];128+ event.currentTarget.value = "";129+ if (!file) return;130+131+ const requestId = ++importRequestRef.current;132+ setIsReading(true);133+ try {134+ const fileText = await file.text();135+ if (requestId !== importRequestRef.current) return;136+ setJson(fileText);137+ setFileName(file.name);138+ setError(null);139+ } catch {140+ if (requestId !== importRequestRef.current) return;141+ setError("Could not read that file. Paste the JSON below instead.");142+ } finally {143+ if (requestId === importRequestRef.current) setIsReading(false);144+ }145+ }, []);146+147+ const handleSubmit = useCallback(() => {
- apps/web/src/components/settings/ThemeEditorPanel.tsx line 237OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +217,21 @@217+ light: simpleColorsDirtyByAppearance.light218+ ? getManagedEditorColors("light", colorsByAppearance.light)219+ : colorsByAppearance.light,220+ dark: simpleColorsDirtyByAppearance.dark221+ ? getManagedEditorColors("dark", colorsByAppearance.dark)222+ : colorsByAppearance.dark,223+ }224+ : colorsByAppearance;225+ const variants =226+ modeSelection === "both"227+ ? { [variantAppearance]: colorsForSave[variantAppearance] }228+ : undefined;229+ const themeFile = {230+ version: THEME_FILE_VERSION,231+ ...(editingTheme ? { id: editingTheme.id } : {}),232+ name,233+ appearance: baseAppearance,234+ colors: colorsForSave[baseAppearance],235+ ...(variants ? { variants } : {}),236+ ...(isAdvanced ? {} : { managed: true }),237+ };
- apps/web/src/components/settings/ThemeSettings.tsx line 421OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +282,21 @@282+ (createdTheme: ThemeDefinition) => {283+ if (!persistTheme(createdTheme.id)) return false;284+ toastManager.add(285+ stackedThreadToast({286+ type: "success",287+ title: `${createdTheme.label} created`,288+ description: "It’s now active.",289+ }),290+ );291+ return true;292+ },293+ [persistTheme],294+ );295+296+ const handleEditedTheme = useCallback(297+ (updatedTheme: ThemeDefinition) => {298+ const wasActive = getThemeDefinition(theme)?.id === updatedTheme.id;299+ if (wasActive) {300+ if (!persistTheme(updatedTheme.id)) return false;301+ refreshTheme();302+ }apps/web/src/components/settings/ThemeEditorPanel.tsx line 229OutdatedResolvedby cursor[bot](GitHub profile, opens in a new tab)@@ -0,0 +209,21 @@209+210+ try {211+ const baseAppearance =212+ editingTheme && modeSelection === "both" ? editingTheme.appearance : activeAppearance;213+ const variantAppearance = baseAppearance === "light" ? "dark" : "light";214+ // Only regenerate palettes the user actually touched in guided mode, so215+ // untouched appearances save exactly what the editor displayed.216+ const colorsForSave = !isAdvanced217+ ? {218+ light: simpleColorsDirtyByAppearance.light219+ ? getManagedEditorColors("light", colorsByAppearance.light)220+ : colorsByAppearance.light,221+ dark: simpleColorsDirtyByAppearance.dark222+ ? getManagedEditorColors("dark", colorsByAppearance.dark)223+ : colorsByAppearance.dark,224+ }225+ : colorsByAppearance;226+ const variants =227+ modeSelection === "both"228+ ? { [variantAppearance]: colorsForSave[variantAppearance] }229+ : undefined;
- apps/web/src/components/DiffPanel.tsx line 145OutdatedResolvedby StiensWout(GitHub profile, opens in a new tab)@@ -120,11 +131,15 @@120- color-mix(in srgb, var(--background) 50%, var(--destructive)),121- color-mix(in srgb, var(--background) 70%, var(--destructive))131+ color-mix(in srgb, var(--code-background) 50%, var(--destructive)),132+ color-mix(in srgb, var(--code-background) 70%, var(--destructive))122133 );123134 --diffs-bg-deletion-number-override: light-dark(124- color-mix(in srgb, var(--background) 35%, var(--destructive)),125- color-mix(in srgb, var(--background) 60%, var(--destructive))135+ color-mix(in srgb, var(--code-background) 35%, var(--destructive)),136+ color-mix(in srgb, var(--code-background) 60%, var(--destructive))137+ );138+ --diffs-bg-deletion-hover-override: color-mix(139+ in srgb,140+ var(--code-background) 85%,141+ var(--destructive)126142 );127- --diffs-bg-deletion-hover-override: color-mix(in srgb, var(--background) 85%, var(--destructive));128143 --diffs-bg-deletion-emphasis-override: color-mix(129144 in srgb,130- var(--background) 80%,145+ var(--code-background) 80%,
Sign in to join this conversation.







Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro Plus
Run ID:
83260332-8257-44ef-ac0d-f35f58cb123eYou can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share