Open History to see the last commit
1import type { CSSProperties } from "react";
2import { useState } from "react";
3import {
4 DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE,
5 DEFAULT_UNIFIED_SETTINGS,
6 type ChatWidth,
7 type EnvironmentIdentificationMode,
8 MAX_APPEARANCE_CONTRAST,
9 MAX_GLASS_OPACITY,
10 MAX_PANEL_ANIMATION_DURATION_MS,
11 MIN_APPEARANCE_CONTRAST,
12 MIN_GLASS_OPACITY,
13 MIN_PANEL_ANIMATION_DURATION_MS,
14} from "@t3tools/contracts/settings";
15import {
16 resolveEnvironmentIdentificationPillLabel,
17 useEnvironmentStageLabel,
18} from "../SidebarStageBackdrop";
19import { useCustomThemes } from "../../hooks/useCustomThemes";
20import { useTheme } from "../../hooks/useTheme";
21import { useScopedSettings, useUpdateScopedSettings } from "./useScopedSettings";
22import { Select, SelectItem, SelectPopup, SelectTrigger, SelectValue } from "../ui/select";
23import { Switch } from "../ui/switch";
24import { ThemeLibrary } from "./ThemeSettings";
25import {
26 SettingResetButton,
27 SettingsPageContainer,
28 SettingsRow,
29 SettingsSection,
30} from "./settingsLayout";
31import { searchableSetting } from "./settingsSearch";
32import { PanelAnimationsPreview } from "./PanelAnimationsPreview";
33import { TypographySection } from "./TypographySettings";
34
35const ENVIRONMENT_IDENTIFICATION_LABELS: Record<EnvironmentIdentificationMode, string> = {
36 artwork: "Artwork",
37 pill: "Version pill",
38 none: "None",
39};
40
41const CHAT_WIDTH_LABELS: Record<ChatWidth, string> = {
42 comfortable: "Comfortable",
43 wide: "Wide",
44 full: "Full",
45};
46
47export function AppearanceSettingsPanel() {
48 const {
49 appearanceMode,
50 refreshTheme,
51 resolvedTheme,
52 setAppearanceMode,
53 setTheme,
54 setThemeHalf,
55 theme,
56 themeHalves,
57 } = useTheme();
58 const customThemes = useCustomThemes();
59 const [isImportThemeOpen, setIsImportThemeOpen] = useState(false);
60 const settings = useScopedSettings();
61 const updateSettings = useUpdateScopedSettings();
62 const environmentStageLabel = useEnvironmentStageLabel();
63 const showEnvironmentIdentification =
64 resolveEnvironmentIdentificationPillLabel(environmentStageLabel) !== null;
65 const glassOpacityRatio =
66 (settings.glassOpacity - MIN_GLASS_OPACITY) / (MAX_GLASS_OPACITY - MIN_GLASS_OPACITY);
67 const glassOpacitySliderStyle = {
68 "--settings-slider-progress": `${glassOpacityRatio * 100}%`,
69 "--settings-slider-fill-offset": `${0.5 - glassOpacityRatio}rem`,
70 } as CSSProperties;
71 const appearanceContrastRatio =
72 (settings.appearanceContrast - MIN_APPEARANCE_CONTRAST) /
73 (MAX_APPEARANCE_CONTRAST - MIN_APPEARANCE_CONTRAST);
74 const appearanceContrastSliderStyle = {
75 "--settings-slider-progress": `${appearanceContrastRatio * 100}%`,
76 "--settings-slider-fill-offset": `${0.5 - appearanceContrastRatio}rem`,
77 } as CSSProperties;
78 const panelAnimationDurationRatio =
79 (settings.panelAnimationDurationMs - MIN_PANEL_ANIMATION_DURATION_MS) /
80 (MAX_PANEL_ANIMATION_DURATION_MS - MIN_PANEL_ANIMATION_DURATION_MS);
81 const panelAnimationDurationSliderStyle = {
82 "--settings-slider-progress": `${panelAnimationDurationRatio * 100}%`,
83 "--settings-slider-fill-offset": `${0.5 - panelAnimationDurationRatio}rem`,
84 } as CSSProperties;
85
86 return (
87 <SettingsPageContainer>
88 <SettingsSection id="appearance" title="Colors & themes" variant="plain" hideTitle>
89 <div id={searchableSetting("theme").id}>
90 <ThemeLibrary
91 appearanceMode={appearanceMode}
92 customThemes={customThemes}
93 initialAppearance={resolvedTheme}
94 refreshTheme={refreshTheme}
95 isImportOpen={isImportThemeOpen}
96 setAppearanceMode={setAppearanceMode}
97 setTheme={setTheme}
98 setThemeHalf={setThemeHalf}
99 theme={theme}
100 themeHalves={themeHalves}
101 onImportOpenChange={setIsImportThemeOpen}
102 />
103 </div>
104 </SettingsSection>
105
106 <SettingsSection id="appearance-interface" title="Interface">
107 <SettingsRow
108 {...searchableSetting("setting-appearance-contrast")}
109 description="Adjust the contrast of colors and borders across the interface."
110 resetAction={
111 settings.appearanceContrast !== DEFAULT_UNIFIED_SETTINGS.appearanceContrast ? (
112 <SettingResetButton
113 label="contrast"
114 onClick={() =>
115 updateSettings({
116 appearanceContrast: DEFAULT_UNIFIED_SETTINGS.appearanceContrast,
117 })
118 }
119 />
120 ) : null
121 }
122 control={
123 <div className="flex w-full items-center gap-3 sm:w-52">
124 <output
125 className="min-w-12 rounded-md bg-muted px-2 py-1 text-center font-mono text-xs font-medium tabular-nums text-foreground"
126 htmlFor="appearance-contrast"
127 >
128 {settings.appearanceContrast}%
129 </output>
130 <input
131 aria-label="Contrast"
132 className="settings-slider min-w-0 flex-1"
133 id="appearance-contrast"
134 max={MAX_APPEARANCE_CONTRAST}
135 min={MIN_APPEARANCE_CONTRAST}
136 onChange={(event) => {
137 const appearanceContrast = Number(event.currentTarget.value);
138 if (
139 Number.isInteger(appearanceContrast) &&
140 appearanceContrast >= MIN_APPEARANCE_CONTRAST &&
141 appearanceContrast <= MAX_APPEARANCE_CONTRAST
142 ) {
143 updateSettings({ appearanceContrast });
144 }
145 }}
146 step={5}
147 style={appearanceContrastSliderStyle}
148 type="range"
149 value={settings.appearanceContrast}
150 />
151 </div>
152 }
153 />
154
155 <SettingsRow
156 {...searchableSetting("setting-glass-opacity")}
157 description="Higher values make menus, dialogs, and the composer more solid."
158 resetAction={
159 settings.glassOpacity !== DEFAULT_UNIFIED_SETTINGS.glassOpacity ? (
160 <SettingResetButton
161 label="glass opacity"
162 onClick={() =>
163 updateSettings({ glassOpacity: DEFAULT_UNIFIED_SETTINGS.glassOpacity })
164 }
165 />
166 ) : null
167 }
168 control={
169 <div className="flex w-full items-center gap-3 sm:w-52">
170 <output
171 className="min-w-12 rounded-md bg-muted px-2 py-1 text-center font-mono text-xs font-medium tabular-nums text-foreground"
172 htmlFor="glass-opacity"
173 >
174 {settings.glassOpacity}%
175 </output>
176 <input
177 aria-label="Glass opacity"
178 className="settings-slider min-w-0 flex-1"
179 id="glass-opacity"
180 max={MAX_GLASS_OPACITY}
181 min={MIN_GLASS_OPACITY}
182 onChange={(event) => {
183 const glassOpacity = Number(event.currentTarget.value);
184 if (
185 Number.isInteger(glassOpacity) &&
186 glassOpacity >= MIN_GLASS_OPACITY &&
187 glassOpacity <= MAX_GLASS_OPACITY
188 ) {
189 updateSettings({ glassOpacity });
190 }
191 }}
192 step={5}
193 style={glassOpacitySliderStyle}
194 type="range"
195 value={settings.glassOpacity}
196 />
197 </div>
198 }
199 />
200
201 {showEnvironmentIdentification ? (
202 <SettingsRow
203 {...searchableSetting("environment-identification")}
204 description="Choose how Dev and Nightly environments are identified."
205 resetAction={
206 settings.environmentIdentificationMode !== DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE ? (
207 <SettingResetButton
208 label="environment identification"
209 onClick={() =>
210 updateSettings({
211 environmentIdentificationMode: DEFAULT_ENVIRONMENT_IDENTIFICATION_MODE,
212 })
213 }
214 />
215 ) : null
216 }
217 control={
218 <Select
219 value={settings.environmentIdentificationMode}
220 onValueChange={(value) => {
221 if (value === "artwork" || value === "pill" || value === "none") {
222 updateSettings({ environmentIdentificationMode: value });
223 }
224 }}
225 >
226 <SelectTrigger
227 size="sm"
228 className="w-full sm:w-40"
229 aria-label="Environment identification"
230 >
231 <SelectValue>
232 {ENVIRONMENT_IDENTIFICATION_LABELS[settings.environmentIdentificationMode]}
233 </SelectValue>
234 </SelectTrigger>
235 <SelectPopup align="end" alignItemWithTrigger={false}>
236 {Object.entries(ENVIRONMENT_IDENTIFICATION_LABELS).map(([value, label]) => (
237 <SelectItem hideIndicator key={value} value={value}>
238 {label}
239 </SelectItem>
240 ))}
241 </SelectPopup>
242 </Select>
243 }
244 />
245 ) : null}
246
247 <SettingsRow
248 {...searchableSetting("diff-color-scheme")}
249 description="Choose colors for additions and deletions, including change counts."
250 resetAction={
251 settings.diffColorScheme !== DEFAULT_UNIFIED_SETTINGS.diffColorScheme ? (
252 <SettingResetButton
253 label="diff colors"
254 onClick={() =>
255 updateSettings({ diffColorScheme: DEFAULT_UNIFIED_SETTINGS.diffColorScheme })
256 }
257 />
258 ) : null
259 }
260 control={
261 <div className="w-full sm:w-40">
262 <Select
263 value={settings.diffColorScheme}
264 onValueChange={(value) => {
265 if (value === "red-green" || value === "blue-orange")
266 updateSettings({ diffColorScheme: value });
267 }}
268 >
269 <SelectTrigger size="sm" className="w-full min-w-0" aria-label="Diff colors">
270 <span
271 aria-hidden="true"
272 className={
273 settings.diffColorScheme === "blue-orange"
274 ? "flex shrink-0 flex-row-reverse gap-1"
275 : "flex shrink-0 gap-1"
276 }
277 >
278 <span className="size-2 rounded-full bg-diff-deletion" />
279 <span className="size-2 rounded-full bg-diff-addition" />
280 </span>
281 <SelectValue>
282 {settings.diffColorScheme === "blue-orange" ? "Blue & orange" : "Red & green"}
283 </SelectValue>
284 </SelectTrigger>
285 <SelectPopup align="end" alignItemWithTrigger={false}>
286 <SelectItem value="red-green">Red & green (default)</SelectItem>
287 <SelectItem value="blue-orange">Blue & orange</SelectItem>
288 </SelectPopup>
289 </Select>
290 </div>
291 }
292 />
293
294 <SettingsRow
295 {...searchableSetting("composer-context")}
296 description="Keep branch and worktree controls below the composer after a thread starts."
297 resetAction={
298 settings.persistComposerContextStrip !==
299 DEFAULT_UNIFIED_SETTINGS.persistComposerContextStrip ? (
300 <SettingResetButton
301 label="composer context"
302 onClick={() =>
303 updateSettings({
304 persistComposerContextStrip:
305 DEFAULT_UNIFIED_SETTINGS.persistComposerContextStrip,
306 })
307 }
308 />
309 ) : null
310 }
311 control={
312 <Switch
313 checked={settings.persistComposerContextStrip}
314 onCheckedChange={(checked) =>
315 updateSettings({ persistComposerContextStrip: Boolean(checked) })
316 }
317 aria-label="Keep composer context visible in active threads"
318 />
319 }
320 />
321
322 <SettingsRow
323 {...searchableSetting("chat-width")}
324 description="Set how wide messages and the composer can grow on large screens."
325 resetAction={
326 settings.chatWidth !== DEFAULT_UNIFIED_SETTINGS.chatWidth ? (
327 <SettingResetButton
328 label="chat width"
329 onClick={() => updateSettings({ chatWidth: DEFAULT_UNIFIED_SETTINGS.chatWidth })}
330 />
331 ) : null
332 }
333 control={
334 <div className="w-full sm:w-40">
335 <Select
336 value={settings.chatWidth}
337 onValueChange={(value) => {
338 if (value === "comfortable" || value === "wide" || value === "full")
339 updateSettings({ chatWidth: value });
340 }}
341 >
342 <SelectTrigger size="sm" className="w-full min-w-0" aria-label="Chat width">
343 <SelectValue>{CHAT_WIDTH_LABELS[settings.chatWidth]}</SelectValue>
344 </SelectTrigger>
345 <SelectPopup align="end" alignItemWithTrigger={false}>
346 <SelectItem value="comfortable">Comfortable (default)</SelectItem>
347 <SelectItem value="wide">Wide</SelectItem>
348 <SelectItem value="full">Full</SelectItem>
349 </SelectPopup>
350 </Select>
351 </div>
352 }
353 />
354 <SettingsRow
355 {...searchableSetting("math-rendering")}
356 description="Typeset LaTeX math, such as $x^2$ or \[x^2\], in messages and Markdown previews. The composer keeps TeX source editable."
357 resetAction={
358 settings.mathRenderingEnabled !== DEFAULT_UNIFIED_SETTINGS.mathRenderingEnabled ? (
359 <SettingResetButton
360 label="math rendering"
361 onClick={() =>
362 updateSettings({
363 mathRenderingEnabled: DEFAULT_UNIFIED_SETTINGS.mathRenderingEnabled,
364 })
365 }
366 />
367 ) : null
368 }
369 control={
370 <Switch
371 checked={settings.mathRenderingEnabled}
372 onCheckedChange={(checked) =>
373 updateSettings({ mathRenderingEnabled: Boolean(checked) })
374 }
375 aria-label="Render math"
376 />
377 }
378 />
379 </SettingsSection>
380
381 <SettingsSection id="motion" title="Motion">
382 <SettingsRow
383 {...searchableSetting("panel-animations")}
384 description="Set how fast panels open and close."
385 control={
386 <div className="grid w-full grid-cols-[5rem_minmax(0,1fr)] items-center gap-3 sm:w-auto sm:grid-cols-[7rem_13rem] sm:gap-4">
387 <PanelAnimationsPreview durationMs={settings.panelAnimationDurationMs} />
388 <div className="flex w-full items-center gap-3">
389 <output
390 className="min-w-16 rounded-md bg-muted px-2 py-1 text-center font-mono text-xs font-medium tabular-nums text-foreground"
391 htmlFor="panel-animation-duration"
392 >
393 {settings.panelAnimationDurationMs} ms
394 </output>
395 <input
396 aria-label="Panel animation duration"
397 className="settings-slider min-w-0 flex-1"
398 id="panel-animation-duration"
399 max={MAX_PANEL_ANIMATION_DURATION_MS}
400 min={MIN_PANEL_ANIMATION_DURATION_MS}
401 onChange={(event) => {
402 const panelAnimationDurationMs = Number(event.currentTarget.value);
403 if (
404 Number.isInteger(panelAnimationDurationMs) &&
405 panelAnimationDurationMs >= MIN_PANEL_ANIMATION_DURATION_MS &&
406 panelAnimationDurationMs <= MAX_PANEL_ANIMATION_DURATION_MS
407 ) {
408 updateSettings({ panelAnimationDurationMs });
409 }
410 }}
411 step={25}
412 style={panelAnimationDurationSliderStyle}
413 type="range"
414 value={settings.panelAnimationDurationMs}
415 />
416 </div>
417 </div>
418 }
419 resetAction={
420 settings.panelAnimationDurationMs !==
421 DEFAULT_UNIFIED_SETTINGS.panelAnimationDurationMs ? (
422 <SettingResetButton
423 label="panel animations"
424 onClick={() =>
425 updateSettings({
426 panelAnimationDurationMs: DEFAULT_UNIFIED_SETTINGS.panelAnimationDurationMs,
427 })
428 }
429 />
430 ) : null
431 }
432 />
433 </SettingsSection>
434
435 <TypographySection />
436 </SettingsPageContainer>
437 );
438}