The best way to control Claude Code, Codex and more from any computer or phone

main
tsx 221 lines 7.14 KB
Raw
1 import { useGT } from "gt-react";
2 import { MoonIcon, SunIcon } from "lucide-react";
3 import type { CSSProperties } from "react";
4 import {
5 STANDARD_THEME_PREVIEW_COLORS as SHARED_STANDARD_THEME_PREVIEW_COLORS,
6 THEME_PREVIEW_RENDER_SPECS,
7 } from "@t3tools/shared/themePreview";
8 import { cn } from "../../lib/utils";
9 import { Tooltip, TooltipPopup, TooltipTrigger } from "../ui/tooltip";
10 import {
11 getThemeColorsForMode,
12 getThemeModes,
13 type ThemeAppearance,
14 type ThemeDefinition,
15 } from "../../themePalette";
16
17 const THEME_PREVIEW_ROLES = [
18 "sidebar",
19 "canvas",
20 "surface",
21 "accentSurface",
22 "accent",
23 "messageSurface",
24 "messageAction",
25 ] as const;
26 type ThemePreviewRole = (typeof THEME_PREVIEW_ROLES)[number];
27 type ThemeCardPreview = {
28 mode: ThemeAppearance;
29 colors: Readonly<Record<ThemePreviewRole, string>>;
30 };
31 export type ThemeCardDefinition = {
32 id: string;
33 label: string;
34 previews: ReadonlyArray<ThemeCardPreview>;
35 };
36 export type ThemeMode = ThemeAppearance | "system";
37 export type ThemeCardPreviewColors = ThemeCardPreview["colors"];
38
39 const STANDARD_THEME_PREVIEW_COLORS: Record<
40 ThemeAppearance,
41 Readonly<Record<ThemePreviewRole, string>>
42 > = {
43 light: {
44 sidebar: "#fafafa",
45 surface: "#ffffff",
46 accentSurface: "#f4f4f5",
47 messageSurface: "#e4e4e7",
48 ...SHARED_STANDARD_THEME_PREVIEW_COLORS.light,
49 },
50 dark: {
51 sidebar: "#0f0f10",
52 surface: "#121212",
53 accentSurface: "#27272a",
54 messageSurface: "#27272a",
55 ...SHARED_STANDARD_THEME_PREVIEW_COLORS.dark,
56 },
57 };
58
59 export const STANDARD_THEME_CARDS: ReadonlyArray<ThemeCardDefinition> = [
60 {
61 id: "default",
62 label: "T3 Code",
63 previews: (["light", "dark"] as const).map((mode) => ({
64 mode,
65 colors: STANDARD_THEME_PREVIEW_COLORS[mode],
66 })),
67 },
68 ];
69
70 export function previewColorsOf(
71 card: ThemeCardDefinition,
72 mode: ThemeAppearance,
73 ): ThemeCardPreviewColors | null {
74 return card.previews.find((preview) => preview.mode === mode)?.colors ?? null;
75 }
76
77 export function getThemeCardDefinition(theme: ThemeDefinition): ThemeCardDefinition {
78 return {
79 id: theme.id,
80 label: theme.label,
81 previews: getThemeModes(theme).map((mode) => {
82 const colors = getThemeColorsForMode(theme, mode) ?? theme.colors;
83 return {
84 mode,
85 colors: {
86 sidebar: colors.sidebar,
87 canvas: colors.canvas,
88 surface: colors.surface,
89 accentSurface: colors.accentSurface,
90 accent: colors.accent,
91 messageSurface: colors.messageSurface,
92 messageAction: colors.messageAction,
93 },
94 };
95 }),
96 };
97 }
98
99 function getThemePreviewStyle(
100 colors: ThemeCardPreviewColors,
101 mode: ThemeAppearance,
102 ): CSSProperties {
103 const spec = THEME_PREVIEW_RENDER_SPECS[mode];
104 const modeBase = `color-mix(in oklab, ${colors.canvas} ${spec.baseWeight * 100}%, ${spec.baseTarget})`;
105 const accentPosition = `${spec.accent.center[0] * 100}% ${spec.accent.center[1] * 100}%`;
106 const actionPosition = `${spec.action.center[0] * 100}% ${spec.action.center[1] * 100}%`;
107 return {
108 backgroundColor: modeBase,
109 backgroundImage: [
110 `radial-gradient(circle at ${accentPosition} in oklab, ${colors.accent} 0%, color-mix(in oklab, ${colors.accent} ${spec.accent.middleOpacity * 100}%, transparent) ${spec.accent.middleOffset * 100}%, transparent ${spec.accent.endOffset * 100}%)`,
111 `radial-gradient(circle at ${actionPosition} in oklab, color-mix(in oklab, ${colors.messageAction} ${spec.action.startOpacity * 100}%, transparent) 0%, transparent ${spec.action.endOffset * 100}%)`,
112 ].join(", "),
113 };
114 }
115
116 function themePreviewEdgeShadow(mode: ThemeAppearance): string {
117 return mode === "dark"
118 ? "inset 0 0 0 1px rgb(255 255 255 / 0.14), 0 1px 2px rgb(0 0 0 / 0.18)"
119 : "inset 0 0 0 1px rgb(0 0 0 / 0.10), 0 1px 2px rgb(0 0 0 / 0.08)";
120 }
121
122 export function ThemePreviewCircle({
123 colors,
124 mode,
125 className,
126 }: {
127 colors: ThemeCardPreviewColors;
128 mode: ThemeAppearance;
129 className?: string;
130 }) {
131 return (
132 <span
133 aria-hidden
134 className={cn(
135 "relative block size-14 shrink-0 overflow-hidden rounded-full border-2 border-background",
136 className,
137 )}
138 style={{ boxShadow: themePreviewEdgeShadow(mode) }}
139 >
140 <span
141 className="absolute inset-0 rounded-full"
142 style={{
143 ...getThemePreviewStyle(colors, mode),
144 filter: `blur(${THEME_PREVIEW_RENDER_SPECS[mode].blurAt56Px}px)`,
145 transform: `scale(${THEME_PREVIEW_RENDER_SPECS[mode].scale})`,
146 }}
147 />
148 </span>
149 );
150 }
151
152 export function ThemePreviewCircles({
153 label,
154 activeModes,
155 onSelectMode,
156 previews,
157 }: {
158 label: string;
159 activeModes: ReadonlyArray<ThemeMode>;
160 onSelectMode: (mode: ThemeMode) => void;
161 previews: ThemeCardDefinition["previews"];
162 }) {
163 const gt = useGT();
164 return (
165 <div className="flex min-h-16 items-center justify-center gap-2.5 px-3 pt-3">
166 {previews.map((preview) => {
167 const mode = preview.mode;
168 const isPicked = activeModes.includes(mode);
169 return (
170 <Tooltip key={mode}>
171 <TooltipTrigger
172 render={
173 <button
174 aria-label={
175 mode === "light"
176 ? gt("Use {label} light mode", { label })
177 : gt("Use {label} dark mode", { label })
178 }
179 aria-pressed={isPicked}
180 className={cn(
181 "relative flex size-[68px] shrink-0 transform-gpu cursor-pointer items-center justify-center rounded-full p-1.5 outline-none transition-transform hover:scale-105 focus-visible:outline-2 focus-visible:outline-solid focus-visible:-outline-offset-5 focus-visible:outline-foreground/60",
182 isPicked && "hover:scale-100",
183 )}
184 onClick={(event) => {
185 event.stopPropagation();
186 onSelectMode(mode);
187 }}
188 type="button"
189 >
190 <ThemePreviewCircle colors={preview.colors} mode={mode} />
191 {isPicked ? (
192 <>
193 <span
194 aria-hidden
195 className="pointer-events-none absolute inset-0 rounded-full"
196 style={{ boxShadow: "inset 0 0 0 2px var(--ring)" }}
197 />
198 <span
199 aria-hidden
200 className="pointer-events-none absolute bottom-0.5 right-0.5 flex size-5 items-center justify-center rounded-full border border-border/70 bg-background text-foreground shadow-sm"
201 >
202 {mode === "light" ? (
203 <SunIcon className="size-3" />
204 ) : (
205 <MoonIcon className="size-3" />
206 )}
207 </span>
208 </>
209 ) : null}
210 </button>
211 }
212 />
213 <TooltipPopup>
214 {mode === "light" ? gt("Use for light mode only") : gt("Use for dark mode only")}
215 </TooltipPopup>
216 </Tooltip>
217 );
218 })}
219 </div>
220 );
221 }