@devries-cameron20 / t3code Mirror · read-only
Fork 0

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

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 21, 04:45 UTC

main
tsx 214 lines 6.3 KB
Raw
1 import type { DesktopPreviewColorScheme } from "@t3tools/contracts";
2 import { msg, T, useGT, useMessages, Var } from "gt-react";
3 import { Minus, MoreVertical, Plus as PlusIcon, RotateCcw } from "lucide-react";
4
5 import { Button } from "~/components/ui/button";
6 import {
7 Menu,
8 MenuItem,
9 MenuPopup,
10 MenuShortcut,
11 MenuRadioGroup,
12 MenuRadioItem,
13 MenuGroup,
14 MenuGroupLabel,
15 MenuSeparator,
16 MenuSub,
17 MenuSubPopup,
18 MenuSubTrigger,
19 MenuTrigger,
20 } from "~/components/ui/menu";
21 import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
22
23 const COLOR_SCHEME_OPTIONS: ReadonlyArray<{
24 value: DesktopPreviewColorScheme;
25 label: string;
26 }> = [
27 { value: "system", label: msg("System", { $context: "color scheme" }) },
28 { value: "light", label: msg("Light", { $context: "color scheme" }) },
29 { value: "dark", label: msg("Dark", { $context: "color scheme" }) },
30 ];
31
32 export interface PreviewMoreMenuActions {
33 readonly hardReload: () => void;
34 readonly setColorScheme: (colorScheme: DesktopPreviewColorScheme) => void;
35 readonly zoomIn: () => void;
36 readonly zoomOut: () => void;
37 readonly resetZoom: () => void;
38 readonly clearCookies: () => void;
39 readonly clearCache: () => void;
40 readonly openDevTools?: () => void;
41 readonly toggleNativePictureInPicture?: () => void;
42 readonly find?: () => void;
43 }
44
45 interface Props {
46 enabled: boolean;
47 actions: PreviewMoreMenuActions;
48 zoomFactor: number;
49 colorScheme: DesktopPreviewColorScheme;
50 deviceToolbarVisible: boolean;
51 onToggleDeviceToolbar: () => void;
52 nativePictureInPicture: boolean;
53 profileName: string | undefined;
54 findShortcutLabel?: string | null;
55 move?: { readonly label: string; readonly onMove: () => void };
56 }
57
58 const MenuTriggerButton = () => {
59 const gt = useGT();
60 return (
61 <Tooltip>
62 <TooltipTrigger
63 render={
64 <MenuTrigger
65 render={
66 <Button
67 variant="ghost"
68 size="icon-xs"
69 type="button"
70 aria-label={gt("Preview menu")}
71 />
72 }
73 />
74 }
75 >
76 <MoreVertical />
77 </TooltipTrigger>
78 <TooltipPopup>
79 <T context="more actions menu">More</T>
80 </TooltipPopup>
81 </Tooltip>
82 );
83 };
84
85 export function PreviewMoreMenu({
86 enabled,
87 actions,
88 zoomFactor,
89 colorScheme,
90 deviceToolbarVisible,
91 onToggleDeviceToolbar,
92 nativePictureInPicture,
93 profileName,
94 findShortcutLabel,
95 move,
96 }: Props) {
97 const gt = useGT();
98 const m = useMessages();
99 const zoomLabel = `${Math.round(zoomFactor * 100)}%`;
100 const disabled = !enabled;
101 return (
102 <Menu>
103 <MenuTriggerButton />
104 <MenuPopup align="end" sideOffset={6}>
105 {actions.find ? (
106 <MenuItem onClick={actions.find} disabled={disabled}>
107 <T>Find on page</T>
108 {findShortcutLabel ? <MenuShortcut>{findShortcutLabel}</MenuShortcut> : null}
109 </MenuItem>
110 ) : null}
111 <MenuItem onClick={actions.hardReload} disabled={disabled}>
112 <T>Hard reload</T>
113 </MenuItem>
114 {actions.openDevTools ? (
115 <MenuItem onClick={actions.openDevTools} disabled={disabled}>
116 <T>Open DevTools</T>
117 </MenuItem>
118 ) : null}
119 {actions.toggleNativePictureInPicture ? (
120 <MenuItem onClick={actions.toggleNativePictureInPicture} disabled={disabled}>
121 {nativePictureInPicture
122 ? gt("Close separate preview window")
123 : gt("Open separate preview window")}
124 </MenuItem>
125 ) : null}
126 {move ? <MenuItem onClick={move.onMove}>{move.label}</MenuItem> : null}
127 <MenuItem onClick={onToggleDeviceToolbar} disabled={disabled}>
128 {deviceToolbarVisible ? gt("Hide device toolbar") : gt("Show device toolbar")}
129 </MenuItem>
130 <MenuSub>
131 <MenuSubTrigger disabled={disabled}>
132 <T>Appearance</T>
133 </MenuSubTrigger>
134 <MenuSubPopup>
135 <MenuRadioGroup
136 value={colorScheme}
137 onValueChange={(value) => actions.setColorScheme(value as DesktopPreviewColorScheme)}
138 >
139 {COLOR_SCHEME_OPTIONS.map((option) => (
140 <MenuRadioItem key={option.value} value={option.value}>
141 {m(option.label)}
142 </MenuRadioItem>
143 ))}
144 </MenuRadioGroup>
145 </MenuSubPopup>
146 </MenuSub>
147 <MenuSeparator />
148 <MenuItem
149 closeOnClick={false}
150 onClick={(event: React.MouseEvent) => event.preventDefault()}
151 className="justify-between"
152 disabled={disabled}
153 >
154 <span>
155 <T>Zoom</T>
156 </span>
157 <span className="flex items-center gap-1">
158 <Button
159 variant="outline"
160 size="icon-xs"
161 type="button"
162 onClick={actions.zoomOut}
163 aria-label={gt("Zoom out")}
164 disabled={disabled}
165 >
166 <Minus />
167 </Button>
168 <span className="min-w-12 text-center text-xs tabular-nums text-muted-foreground">
169 {zoomLabel}
170 </span>
171 <Button
172 variant="outline"
173 size="icon-xs"
174 type="button"
175 onClick={actions.zoomIn}
176 aria-label={gt("Zoom in")}
177 disabled={disabled}
178 >
179 <PlusIcon />
180 </Button>
181 <Button
182 variant="ghost"
183 size="icon-xs"
184 type="button"
185 onClick={actions.resetZoom}
186 aria-label={gt("Reset zoom")}
187 disabled={disabled}
188 >
189 <RotateCcw />
190 </Button>
191 </span>
192 </MenuItem>
193 <MenuSeparator />
194 <MenuGroup>
195 {profileName ? (
196 <MenuGroupLabel className="max-w-64">
197 <span className="block truncate">
198 <T>
199 Profile: <Var>{profileName}</Var>
200 </T>
201 </span>
202 </MenuGroupLabel>
203 ) : null}
204 <MenuItem onClick={actions.clearCookies}>
205 <T>Clear cookies</T>
206 </MenuItem>
207 <MenuItem onClick={actions.clearCache}>
208 <T>Clear cache</T>
209 </MenuItem>
210 </MenuGroup>
211 </MenuPopup>
212 </Menu>
213 );
214 }