@elabs-ai/components-ai 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +133 -0
- package/dist/_audio-player-media-chrome-KA5DY54G.js +81 -0
- package/dist/_audio-player-media-chrome-KA5DY54G.js.map +1 -0
- package/dist/_flow-boundary-D63PJ65S.js +186 -0
- package/dist/_flow-boundary-D63PJ65S.js.map +1 -0
- package/dist/_interactive-terminal-xterm-ATJ5EW3G.js +11 -0
- package/dist/_interactive-terminal-xterm-ATJ5EW3G.js.map +1 -0
- package/dist/_persona-rive-RFR2EUWP.js +164 -0
- package/dist/_persona-rive-RFR2EUWP.js.map +1 -0
- package/dist/index.d.ts +4079 -0
- package/dist/index.js +11770 -0
- package/dist/index.js.map +1 -0
- package/package.json +87 -0
- package/src/_audio-player-media-chrome.tsx +146 -0
- package/src/_chat-shell-rail.tsx +18 -0
- package/src/_code-block-theme.test.ts +134 -0
- package/src/_code-block-theme.ts +184 -0
- package/src/_flow-boundary.tsx +237 -0
- package/src/_flow-lazy.ts +34 -0
- package/src/_interactive-terminal-xterm.ts +32 -0
- package/src/_lazy-mermaid.test.ts +101 -0
- package/src/_lazy-mermaid.ts +117 -0
- package/src/_persona-rive.tsx +252 -0
- package/src/_streamdown-i18n.ts +119 -0
- package/src/agent-timeline.stories.tsx +66 -0
- package/src/agent-timeline.test.tsx +74 -0
- package/src/agent-timeline.tsx +106 -0
- package/src/agent.tsx +113 -0
- package/src/agentic-workspace.stories.tsx +1099 -0
- package/src/artifact.stories.tsx +62 -0
- package/src/artifact.test.tsx +112 -0
- package/src/artifact.tsx +167 -0
- package/src/asset-preview.stories.tsx +100 -0
- package/src/asset-preview.test.tsx +126 -0
- package/src/asset-preview.tsx +218 -0
- package/src/attachments.tsx +393 -0
- package/src/audio-player.stories.tsx +99 -0
- package/src/audio-player.tsx +170 -0
- package/src/blocks-ai-composer.stories.tsx +83 -0
- package/src/canvas.stories.tsx +142 -0
- package/src/canvas.tsx +29 -0
- package/src/chain-of-thought.tsx +193 -0
- package/src/chat-greeting.stories.tsx +96 -0
- package/src/chat-greeting.test.tsx +91 -0
- package/src/chat-greeting.tsx +91 -0
- package/src/chat-shell.stories.tsx +123 -0
- package/src/chat-shell.test.tsx +113 -0
- package/src/chat-shell.tsx +97 -0
- package/src/chat.stories.tsx +99 -0
- package/src/checkpoint.tsx +54 -0
- package/src/code-block.stories.tsx +81 -0
- package/src/code-block.test.tsx +191 -0
- package/src/code-block.tsx +673 -0
- package/src/commit.tsx +343 -0
- package/src/composer.stories.tsx +188 -0
- package/src/composer.test.tsx +182 -0
- package/src/composer.tsx +202 -0
- package/src/confirmation.stories.tsx +61 -0
- package/src/confirmation.test.tsx +136 -0
- package/src/confirmation.tsx +273 -0
- package/src/connection.tsx +23 -0
- package/src/context-panel.stories.tsx +137 -0
- package/src/context-panel.test.tsx +198 -0
- package/src/context-panel.tsx +609 -0
- package/src/context.stories.tsx +16 -0
- package/src/context.tsx +363 -0
- package/src/controls.tsx +20 -0
- package/src/conversation.stories.tsx +26 -0
- package/src/conversation.test.tsx +123 -0
- package/src/conversation.tsx +143 -0
- package/src/dark-theme-variant.test.ts +47 -0
- package/src/edge.tsx +33 -0
- package/src/environment-variables.tsx +304 -0
- package/src/file-tree.stories.tsx +55 -0
- package/src/file-tree.test.tsx +101 -0
- package/src/file-tree.tsx +390 -0
- package/src/gallery.stories.tsx +182 -0
- package/src/gallery.test.tsx +150 -0
- package/src/gallery.tsx +737 -0
- package/src/grouped-parts.stories.tsx +104 -0
- package/src/grouped-parts.test.tsx +167 -0
- package/src/grouped-parts.tsx +247 -0
- package/src/image.stories.tsx +67 -0
- package/src/image.test.tsx +105 -0
- package/src/image.tsx +115 -0
- package/src/index.ts +93 -0
- package/src/inline-citation.stories.tsx +91 -0
- package/src/inline-citation.test.tsx +96 -0
- package/src/inline-citation.tsx +314 -0
- package/src/interactive-terminal.stories.tsx +165 -0
- package/src/interactive-terminal.test.tsx +448 -0
- package/src/interactive-terminal.tsx +444 -0
- package/src/jsx-preview.stories.tsx +265 -0
- package/src/jsx-preview.test.tsx +75 -0
- package/src/jsx-preview.tsx +409 -0
- package/src/markdown-view.stories.tsx +57 -0
- package/src/markdown-view.test.tsx +36 -0
- package/src/markdown-view.tsx +113 -0
- package/src/message-edit.stories.tsx +150 -0
- package/src/message-edit.test.tsx +115 -0
- package/src/message-edit.tsx +336 -0
- package/src/message-feedback.stories.tsx +53 -0
- package/src/message-feedback.test.tsx +62 -0
- package/src/message-feedback.tsx +117 -0
- package/src/message-form-spec.ts +349 -0
- package/src/message-form.stories.tsx +182 -0
- package/src/message-form.test.tsx +227 -0
- package/src/message-form.tsx +845 -0
- package/src/message-table-spec.ts +281 -0
- package/src/message-table.stories.tsx +176 -0
- package/src/message-table.test.tsx +144 -0
- package/src/message-table.tsx +366 -0
- package/src/message.stories.tsx +262 -0
- package/src/message.test.tsx +508 -0
- package/src/message.tsx +619 -0
- package/src/mic-selector.tsx +339 -0
- package/src/microcopy.test.tsx +123 -0
- package/src/model-selector.stories.tsx +73 -0
- package/src/model-selector.test.tsx +55 -0
- package/src/model-selector.tsx +225 -0
- package/src/motion-config.tsx +49 -0
- package/src/node.tsx +71 -0
- package/src/open-in-chat.tsx +340 -0
- package/src/package-info.tsx +205 -0
- package/src/panel.tsx +20 -0
- package/src/part-groups.ts +258 -0
- package/src/persona-sources.ts +59 -0
- package/src/persona.stories.tsx +111 -0
- package/src/persona.test.tsx +67 -0
- package/src/persona.tsx +148 -0
- package/src/plan.tsx +135 -0
- package/src/prompt-input.stories.tsx +261 -0
- package/src/prompt-input.test.tsx +392 -0
- package/src/prompt-input.tsx +1668 -0
- package/src/queue.tsx +237 -0
- package/src/reasoning.stories.tsx +81 -0
- package/src/reasoning.test.tsx +50 -0
- package/src/reasoning.tsx +229 -0
- package/src/sandbox.stories.tsx +62 -0
- package/src/sandbox.test.tsx +42 -0
- package/src/sandbox.tsx +149 -0
- package/src/schema-display.tsx +412 -0
- package/src/selection-toolbar.stories.tsx +86 -0
- package/src/selection-toolbar.test.tsx +89 -0
- package/src/selection-toolbar.tsx +192 -0
- package/src/shimmer.stories.tsx +10 -0
- package/src/shimmer.tsx +81 -0
- package/src/snippet.stories.tsx +19 -0
- package/src/snippet.test.tsx +116 -0
- package/src/snippet.tsx +138 -0
- package/src/sources.stories.tsx +34 -0
- package/src/sources.test.tsx +129 -0
- package/src/sources.tsx +93 -0
- package/src/speech-input.tsx +312 -0
- package/src/stack-trace.tsx +479 -0
- package/src/streamdown-i18n.test.tsx +163 -0
- package/src/suggestion.stories.tsx +75 -0
- package/src/suggestion.test.tsx +72 -0
- package/src/suggestion.tsx +120 -0
- package/src/task.stories.tsx +22 -0
- package/src/task.test.tsx +36 -0
- package/src/task.tsx +89 -0
- package/src/templates-ai-assistant.stories.tsx +142 -0
- package/src/terminal.tsx +244 -0
- package/src/test-results.stories.tsx +177 -0
- package/src/test-results.test.tsx +241 -0
- package/src/test-results.tsx +408 -0
- package/src/tool-result-card.stories.tsx +143 -0
- package/src/tool-result-card.test.tsx +72 -0
- package/src/tool-result-card.tsx +86 -0
- package/src/tool.stories.tsx +60 -0
- package/src/tool.test.tsx +63 -0
- package/src/tool.tsx +235 -0
- package/src/toolbar.tsx +44 -0
- package/src/transcription.tsx +118 -0
- package/src/voice-selector.tsx +469 -0
- package/src/web-preview.stories.tsx +67 -0
- package/src/web-preview.test.tsx +117 -0
- package/src/web-preview.tsx +283 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { useControllableState } from "@radix-ui/react-use-controllable-state";
|
|
4
|
+
import { Button } from "@elabs-ai/components-ui";
|
|
5
|
+
import {
|
|
6
|
+
Command,
|
|
7
|
+
CommandDialog,
|
|
8
|
+
CommandEmpty,
|
|
9
|
+
CommandGroup,
|
|
10
|
+
CommandInput,
|
|
11
|
+
CommandItem,
|
|
12
|
+
CommandList,
|
|
13
|
+
CommandSeparator,
|
|
14
|
+
CommandShortcut,
|
|
15
|
+
} from "@elabs-ai/components-ui";
|
|
16
|
+
import { Dialog, DialogContent, DialogTitle, DialogTrigger } from "@elabs-ai/components-ui";
|
|
17
|
+
import { Spinner } from "@elabs-ai/components-ui";
|
|
18
|
+
import { cn } from "@elabs-ai/components-ui/lib/cn";
|
|
19
|
+
import { useLocale } from "@elabs-ai/components-ui";
|
|
20
|
+
import {
|
|
21
|
+
CircleSmallIcon,
|
|
22
|
+
MarsIcon,
|
|
23
|
+
MarsStrokeIcon,
|
|
24
|
+
NonBinaryIcon,
|
|
25
|
+
PauseIcon,
|
|
26
|
+
PlayIcon,
|
|
27
|
+
TransgenderIcon,
|
|
28
|
+
VenusAndMarsIcon,
|
|
29
|
+
VenusIcon,
|
|
30
|
+
} from "lucide-react";
|
|
31
|
+
import type { ComponentProps, ReactNode } from "react";
|
|
32
|
+
import { createContext, useCallback, useContext, useMemo } from "react";
|
|
33
|
+
|
|
34
|
+
interface VoiceSelectorContextValue {
|
|
35
|
+
value: string | undefined;
|
|
36
|
+
setValue: (value: string | undefined) => void;
|
|
37
|
+
open: boolean;
|
|
38
|
+
setOpen: (open: boolean) => void;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
const VoiceSelectorContext = createContext<VoiceSelectorContextValue | null>(null);
|
|
42
|
+
|
|
43
|
+
export const useVoiceSelector = () => {
|
|
44
|
+
const context = useContext(VoiceSelectorContext);
|
|
45
|
+
if (!context) {
|
|
46
|
+
throw new Error("VoiceSelector components must be used within VoiceSelector");
|
|
47
|
+
}
|
|
48
|
+
return context;
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
export type VoiceSelectorProps = ComponentProps<typeof Dialog> & {
|
|
52
|
+
value?: string;
|
|
53
|
+
defaultValue?: string;
|
|
54
|
+
onValueChange?: (value: string | undefined) => void;
|
|
55
|
+
};
|
|
56
|
+
|
|
57
|
+
export const VoiceSelector = ({
|
|
58
|
+
value: valueProp,
|
|
59
|
+
defaultValue,
|
|
60
|
+
onValueChange,
|
|
61
|
+
open: openProp,
|
|
62
|
+
defaultOpen = false,
|
|
63
|
+
onOpenChange,
|
|
64
|
+
children,
|
|
65
|
+
...props
|
|
66
|
+
}: VoiceSelectorProps) => {
|
|
67
|
+
const [value, setValue] = useControllableState({
|
|
68
|
+
defaultProp: defaultValue,
|
|
69
|
+
onChange: onValueChange,
|
|
70
|
+
prop: valueProp,
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
const [open, setOpen] = useControllableState({
|
|
74
|
+
defaultProp: defaultOpen,
|
|
75
|
+
onChange: onOpenChange,
|
|
76
|
+
prop: openProp,
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
const voiceSelectorContext = useMemo(
|
|
80
|
+
() => ({ open, setOpen, setValue, value }),
|
|
81
|
+
[value, setValue, open, setOpen],
|
|
82
|
+
);
|
|
83
|
+
|
|
84
|
+
return (
|
|
85
|
+
<VoiceSelectorContext.Provider value={voiceSelectorContext}>
|
|
86
|
+
<Dialog onOpenChange={setOpen} open={open} {...props}>
|
|
87
|
+
{children}
|
|
88
|
+
</Dialog>
|
|
89
|
+
</VoiceSelectorContext.Provider>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export type VoiceSelectorTriggerProps = ComponentProps<typeof DialogTrigger>;
|
|
94
|
+
|
|
95
|
+
export const VoiceSelectorTrigger = (props: VoiceSelectorTriggerProps) => (
|
|
96
|
+
<DialogTrigger {...props} />
|
|
97
|
+
);
|
|
98
|
+
|
|
99
|
+
export type VoiceSelectorContentProps = ComponentProps<typeof DialogContent> & {
|
|
100
|
+
title?: ReactNode;
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
export const VoiceSelectorContent = ({
|
|
104
|
+
className,
|
|
105
|
+
children,
|
|
106
|
+
title = "Voice Selector",
|
|
107
|
+
...props
|
|
108
|
+
}: VoiceSelectorContentProps) => (
|
|
109
|
+
<DialogContent aria-describedby={undefined} className={cn("p-0", className)} {...props}>
|
|
110
|
+
<DialogTitle className="sr-only">{title}</DialogTitle>
|
|
111
|
+
<Command className="**:data-[slot=command-input-wrapper]:h-auto">{children}</Command>
|
|
112
|
+
</DialogContent>
|
|
113
|
+
);
|
|
114
|
+
|
|
115
|
+
export type VoiceSelectorDialogProps = ComponentProps<typeof CommandDialog>;
|
|
116
|
+
|
|
117
|
+
export const VoiceSelectorDialog = (props: VoiceSelectorDialogProps) => (
|
|
118
|
+
<CommandDialog {...props} />
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
export type VoiceSelectorInputProps = ComponentProps<typeof CommandInput>;
|
|
122
|
+
|
|
123
|
+
export const VoiceSelectorInput = ({ className, ...props }: VoiceSelectorInputProps) => (
|
|
124
|
+
<CommandInput className={cn("h-auto py-3.5", className)} {...props} />
|
|
125
|
+
);
|
|
126
|
+
|
|
127
|
+
export type VoiceSelectorListProps = ComponentProps<typeof CommandList>;
|
|
128
|
+
|
|
129
|
+
export const VoiceSelectorList = (props: VoiceSelectorListProps) => <CommandList {...props} />;
|
|
130
|
+
|
|
131
|
+
export type VoiceSelectorEmptyProps = ComponentProps<typeof CommandEmpty>;
|
|
132
|
+
|
|
133
|
+
export const VoiceSelectorEmpty = (props: VoiceSelectorEmptyProps) => <CommandEmpty {...props} />;
|
|
134
|
+
|
|
135
|
+
export type VoiceSelectorGroupProps = ComponentProps<typeof CommandGroup>;
|
|
136
|
+
|
|
137
|
+
export const VoiceSelectorGroup = (props: VoiceSelectorGroupProps) => <CommandGroup {...props} />;
|
|
138
|
+
|
|
139
|
+
export type VoiceSelectorItemProps = ComponentProps<typeof CommandItem>;
|
|
140
|
+
|
|
141
|
+
export const VoiceSelectorItem = ({ className, ...props }: VoiceSelectorItemProps) => (
|
|
142
|
+
<CommandItem className={cn("px-4 py-2", className)} {...props} />
|
|
143
|
+
);
|
|
144
|
+
|
|
145
|
+
export type VoiceSelectorShortcutProps = ComponentProps<typeof CommandShortcut>;
|
|
146
|
+
|
|
147
|
+
export const VoiceSelectorShortcut = (props: VoiceSelectorShortcutProps) => (
|
|
148
|
+
<CommandShortcut {...props} />
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
export type VoiceSelectorSeparatorProps = ComponentProps<typeof CommandSeparator>;
|
|
152
|
+
|
|
153
|
+
export const VoiceSelectorSeparator = (props: VoiceSelectorSeparatorProps) => (
|
|
154
|
+
<CommandSeparator {...props} />
|
|
155
|
+
);
|
|
156
|
+
|
|
157
|
+
export type VoiceSelectorGenderProps = ComponentProps<"span"> & {
|
|
158
|
+
value?: "male" | "female" | "transgender" | "androgyne" | "non-binary" | "intersex";
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
export const VoiceSelectorGender = ({
|
|
162
|
+
className,
|
|
163
|
+
value,
|
|
164
|
+
children,
|
|
165
|
+
...props
|
|
166
|
+
}: VoiceSelectorGenderProps) => {
|
|
167
|
+
let icon: ReactNode | null = null;
|
|
168
|
+
|
|
169
|
+
switch (value) {
|
|
170
|
+
case "male": {
|
|
171
|
+
icon = <MarsIcon className="size-4" />;
|
|
172
|
+
break;
|
|
173
|
+
}
|
|
174
|
+
case "female": {
|
|
175
|
+
icon = <VenusIcon className="size-4" />;
|
|
176
|
+
break;
|
|
177
|
+
}
|
|
178
|
+
case "transgender": {
|
|
179
|
+
icon = <TransgenderIcon className="size-4" />;
|
|
180
|
+
break;
|
|
181
|
+
}
|
|
182
|
+
case "androgyne": {
|
|
183
|
+
icon = <MarsStrokeIcon className="size-4" />;
|
|
184
|
+
break;
|
|
185
|
+
}
|
|
186
|
+
case "non-binary": {
|
|
187
|
+
icon = <NonBinaryIcon className="size-4" />;
|
|
188
|
+
break;
|
|
189
|
+
}
|
|
190
|
+
case "intersex": {
|
|
191
|
+
icon = <VenusAndMarsIcon className="size-4" />;
|
|
192
|
+
break;
|
|
193
|
+
}
|
|
194
|
+
default: {
|
|
195
|
+
icon = <CircleSmallIcon className="size-4" />;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
return (
|
|
200
|
+
<span className={cn("text-muted-foreground text-xs", className)} {...props}>
|
|
201
|
+
{children ?? icon}
|
|
202
|
+
</span>
|
|
203
|
+
);
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
export type VoiceSelectorAccentProps = ComponentProps<"span"> & {
|
|
207
|
+
value?:
|
|
208
|
+
| "american"
|
|
209
|
+
| "british"
|
|
210
|
+
| "australian"
|
|
211
|
+
| "canadian"
|
|
212
|
+
| "irish"
|
|
213
|
+
| "scottish"
|
|
214
|
+
| "indian"
|
|
215
|
+
| "south-african"
|
|
216
|
+
| "new-zealand"
|
|
217
|
+
| "spanish"
|
|
218
|
+
| "french"
|
|
219
|
+
| "german"
|
|
220
|
+
| "italian"
|
|
221
|
+
| "portuguese"
|
|
222
|
+
| "brazilian"
|
|
223
|
+
| "mexican"
|
|
224
|
+
| "argentinian"
|
|
225
|
+
| "japanese"
|
|
226
|
+
| "chinese"
|
|
227
|
+
| "korean"
|
|
228
|
+
| "russian"
|
|
229
|
+
| "arabic"
|
|
230
|
+
| "dutch"
|
|
231
|
+
| "swedish"
|
|
232
|
+
| "norwegian"
|
|
233
|
+
| "danish"
|
|
234
|
+
| "finnish"
|
|
235
|
+
| "polish"
|
|
236
|
+
| "turkish"
|
|
237
|
+
| "greek"
|
|
238
|
+
| string;
|
|
239
|
+
};
|
|
240
|
+
|
|
241
|
+
export const VoiceSelectorAccent = ({
|
|
242
|
+
className,
|
|
243
|
+
value,
|
|
244
|
+
children,
|
|
245
|
+
...props
|
|
246
|
+
}: VoiceSelectorAccentProps) => {
|
|
247
|
+
let emoji: string | null = null;
|
|
248
|
+
|
|
249
|
+
switch (value) {
|
|
250
|
+
case "american": {
|
|
251
|
+
emoji = "🇺🇸";
|
|
252
|
+
break;
|
|
253
|
+
}
|
|
254
|
+
case "british": {
|
|
255
|
+
emoji = "🇬🇧";
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
case "australian": {
|
|
259
|
+
emoji = "🇦🇺";
|
|
260
|
+
break;
|
|
261
|
+
}
|
|
262
|
+
case "canadian": {
|
|
263
|
+
emoji = "🇨🇦";
|
|
264
|
+
break;
|
|
265
|
+
}
|
|
266
|
+
case "irish": {
|
|
267
|
+
emoji = "🇮🇪";
|
|
268
|
+
break;
|
|
269
|
+
}
|
|
270
|
+
case "scottish": {
|
|
271
|
+
emoji = "🏴";
|
|
272
|
+
break;
|
|
273
|
+
}
|
|
274
|
+
case "indian": {
|
|
275
|
+
emoji = "🇮🇳";
|
|
276
|
+
break;
|
|
277
|
+
}
|
|
278
|
+
case "south-african": {
|
|
279
|
+
emoji = "🇿🇦";
|
|
280
|
+
break;
|
|
281
|
+
}
|
|
282
|
+
case "new-zealand": {
|
|
283
|
+
emoji = "🇳🇿";
|
|
284
|
+
break;
|
|
285
|
+
}
|
|
286
|
+
case "spanish": {
|
|
287
|
+
emoji = "🇪🇸";
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
case "french": {
|
|
291
|
+
emoji = "🇫🇷";
|
|
292
|
+
break;
|
|
293
|
+
}
|
|
294
|
+
case "german": {
|
|
295
|
+
emoji = "🇩🇪";
|
|
296
|
+
break;
|
|
297
|
+
}
|
|
298
|
+
case "italian": {
|
|
299
|
+
emoji = "🇮🇹";
|
|
300
|
+
break;
|
|
301
|
+
}
|
|
302
|
+
case "portuguese": {
|
|
303
|
+
emoji = "🇵🇹";
|
|
304
|
+
break;
|
|
305
|
+
}
|
|
306
|
+
case "brazilian": {
|
|
307
|
+
emoji = "🇧🇷";
|
|
308
|
+
break;
|
|
309
|
+
}
|
|
310
|
+
case "mexican": {
|
|
311
|
+
emoji = "🇲🇽";
|
|
312
|
+
break;
|
|
313
|
+
}
|
|
314
|
+
case "argentinian": {
|
|
315
|
+
emoji = "🇦🇷";
|
|
316
|
+
break;
|
|
317
|
+
}
|
|
318
|
+
case "japanese": {
|
|
319
|
+
emoji = "🇯🇵";
|
|
320
|
+
break;
|
|
321
|
+
}
|
|
322
|
+
case "chinese": {
|
|
323
|
+
emoji = "🇨🇳";
|
|
324
|
+
break;
|
|
325
|
+
}
|
|
326
|
+
case "korean": {
|
|
327
|
+
emoji = "🇰🇷";
|
|
328
|
+
break;
|
|
329
|
+
}
|
|
330
|
+
case "russian": {
|
|
331
|
+
emoji = "🇷🇺";
|
|
332
|
+
break;
|
|
333
|
+
}
|
|
334
|
+
case "arabic": {
|
|
335
|
+
emoji = "🇸🇦";
|
|
336
|
+
break;
|
|
337
|
+
}
|
|
338
|
+
case "dutch": {
|
|
339
|
+
emoji = "🇳🇱";
|
|
340
|
+
break;
|
|
341
|
+
}
|
|
342
|
+
case "swedish": {
|
|
343
|
+
emoji = "🇸🇪";
|
|
344
|
+
break;
|
|
345
|
+
}
|
|
346
|
+
case "norwegian": {
|
|
347
|
+
emoji = "🇳🇴";
|
|
348
|
+
break;
|
|
349
|
+
}
|
|
350
|
+
case "danish": {
|
|
351
|
+
emoji = "🇩🇰";
|
|
352
|
+
break;
|
|
353
|
+
}
|
|
354
|
+
case "finnish": {
|
|
355
|
+
emoji = "🇫🇮";
|
|
356
|
+
break;
|
|
357
|
+
}
|
|
358
|
+
case "polish": {
|
|
359
|
+
emoji = "🇵🇱";
|
|
360
|
+
break;
|
|
361
|
+
}
|
|
362
|
+
case "turkish": {
|
|
363
|
+
emoji = "🇹🇷";
|
|
364
|
+
break;
|
|
365
|
+
}
|
|
366
|
+
case "greek": {
|
|
367
|
+
emoji = "🇬🇷";
|
|
368
|
+
break;
|
|
369
|
+
}
|
|
370
|
+
default: {
|
|
371
|
+
emoji = null;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
|
|
375
|
+
return (
|
|
376
|
+
<span className={cn("text-muted-foreground text-xs", className)} {...props}>
|
|
377
|
+
{children ?? emoji}
|
|
378
|
+
</span>
|
|
379
|
+
);
|
|
380
|
+
};
|
|
381
|
+
|
|
382
|
+
export type VoiceSelectorAgeProps = ComponentProps<"span">;
|
|
383
|
+
|
|
384
|
+
export const VoiceSelectorAge = ({ className, ...props }: VoiceSelectorAgeProps) => (
|
|
385
|
+
<span className={cn("text-muted-foreground text-xs tabular-nums", className)} {...props} />
|
|
386
|
+
);
|
|
387
|
+
|
|
388
|
+
export type VoiceSelectorNameProps = ComponentProps<"span">;
|
|
389
|
+
|
|
390
|
+
export const VoiceSelectorName = ({ className, ...props }: VoiceSelectorNameProps) => (
|
|
391
|
+
<span className={cn("flex-1 truncate text-start font-medium", className)} {...props} />
|
|
392
|
+
);
|
|
393
|
+
|
|
394
|
+
export type VoiceSelectorDescriptionProps = ComponentProps<"span">;
|
|
395
|
+
|
|
396
|
+
export const VoiceSelectorDescription = ({
|
|
397
|
+
className,
|
|
398
|
+
...props
|
|
399
|
+
}: VoiceSelectorDescriptionProps) => (
|
|
400
|
+
<span className={cn("text-muted-foreground text-xs", className)} {...props} />
|
|
401
|
+
);
|
|
402
|
+
|
|
403
|
+
export type VoiceSelectorAttributesProps = ComponentProps<"div">;
|
|
404
|
+
|
|
405
|
+
export const VoiceSelectorAttributes = ({
|
|
406
|
+
className,
|
|
407
|
+
children,
|
|
408
|
+
...props
|
|
409
|
+
}: VoiceSelectorAttributesProps) => (
|
|
410
|
+
<div className={cn("flex items-center text-xs", className)} {...props}>
|
|
411
|
+
{children}
|
|
412
|
+
</div>
|
|
413
|
+
);
|
|
414
|
+
|
|
415
|
+
export type VoiceSelectorBulletProps = ComponentProps<"span">;
|
|
416
|
+
|
|
417
|
+
export const VoiceSelectorBullet = ({ className, ...props }: VoiceSelectorBulletProps) => (
|
|
418
|
+
<span aria-hidden="true" className={cn("select-none text-border", className)} {...props}>
|
|
419
|
+
•
|
|
420
|
+
</span>
|
|
421
|
+
);
|
|
422
|
+
|
|
423
|
+
export type VoiceSelectorPreviewProps = Omit<ComponentProps<"button">, "children"> & {
|
|
424
|
+
playing?: boolean;
|
|
425
|
+
loading?: boolean;
|
|
426
|
+
onPlay?: () => void;
|
|
427
|
+
};
|
|
428
|
+
|
|
429
|
+
export const VoiceSelectorPreview = ({
|
|
430
|
+
className,
|
|
431
|
+
playing,
|
|
432
|
+
loading,
|
|
433
|
+
onPlay,
|
|
434
|
+
onClick,
|
|
435
|
+
...props
|
|
436
|
+
}: VoiceSelectorPreviewProps) => {
|
|
437
|
+
const { t } = useLocale();
|
|
438
|
+
const handleClick = useCallback(
|
|
439
|
+
(event: React.MouseEvent<HTMLButtonElement>) => {
|
|
440
|
+
event.stopPropagation();
|
|
441
|
+
onClick?.(event);
|
|
442
|
+
onPlay?.();
|
|
443
|
+
},
|
|
444
|
+
[onClick, onPlay],
|
|
445
|
+
);
|
|
446
|
+
|
|
447
|
+
let icon = <PlayIcon className="size-3" />;
|
|
448
|
+
|
|
449
|
+
if (loading) {
|
|
450
|
+
icon = <Spinner className="size-3" />;
|
|
451
|
+
} else if (playing) {
|
|
452
|
+
icon = <PauseIcon className="size-3" />;
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
return (
|
|
456
|
+
<Button
|
|
457
|
+
aria-label={playing ? t("ai.voiceSelector.pausePreview") : t("ai.voiceSelector.playPreview")}
|
|
458
|
+
className={cn("size-6", className)}
|
|
459
|
+
disabled={loading}
|
|
460
|
+
onClick={handleClick}
|
|
461
|
+
size="icon-sm"
|
|
462
|
+
type="button"
|
|
463
|
+
variant="outline"
|
|
464
|
+
{...props}
|
|
465
|
+
>
|
|
466
|
+
{icon}
|
|
467
|
+
</Button>
|
|
468
|
+
);
|
|
469
|
+
};
|
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
2
|
+
import {
|
|
3
|
+
WebPreview,
|
|
4
|
+
WebPreviewBody,
|
|
5
|
+
WebPreviewNavigation,
|
|
6
|
+
WebPreviewNavigationButton,
|
|
7
|
+
WebPreviewUrl,
|
|
8
|
+
} from "./web-preview";
|
|
9
|
+
import { RotateCwIcon } from "lucide-react";
|
|
10
|
+
|
|
11
|
+
const meta = {
|
|
12
|
+
title: "AI/WebPreview",
|
|
13
|
+
component: WebPreview,
|
|
14
|
+
parameters: { layout: "padded" },
|
|
15
|
+
} satisfies Meta<typeof WebPreview>;
|
|
16
|
+
export default meta;
|
|
17
|
+
type Story = StoryObj<typeof meta>;
|
|
18
|
+
|
|
19
|
+
export const Default: Story = {
|
|
20
|
+
render: () => (
|
|
21
|
+
<WebPreview className="h-96" defaultUrl="about:blank">
|
|
22
|
+
<WebPreviewNavigation>
|
|
23
|
+
<WebPreviewNavigationButton tooltip="Reload">
|
|
24
|
+
<RotateCwIcon className="size-4" />
|
|
25
|
+
</WebPreviewNavigationButton>
|
|
26
|
+
<WebPreviewUrl />
|
|
27
|
+
</WebPreviewNavigation>
|
|
28
|
+
<WebPreviewBody />
|
|
29
|
+
</WebPreview>
|
|
30
|
+
),
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// LOADING — the preview target hasn't finished loading yet (loading-states.md
|
|
34
|
+
// `loading`). `WebPreviewBody` renders a layout-shaped skeleton filling the
|
|
35
|
+
// iframe box while the navigation bar keeps rendering as passed.
|
|
36
|
+
export const Loading: Story = {
|
|
37
|
+
render: () => (
|
|
38
|
+
<WebPreview className="h-96" defaultUrl="about:blank">
|
|
39
|
+
<WebPreviewNavigation>
|
|
40
|
+
<WebPreviewNavigationButton disabled tooltip="Reload">
|
|
41
|
+
<RotateCwIcon className="size-4" />
|
|
42
|
+
</WebPreviewNavigationButton>
|
|
43
|
+
<WebPreviewUrl />
|
|
44
|
+
</WebPreviewNavigation>
|
|
45
|
+
<WebPreviewBody loading />
|
|
46
|
+
</WebPreview>
|
|
47
|
+
),
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
// A caller-supplied placeholder node overrides the default Skeleton (the
|
|
51
|
+
// pre-existing escape hatch, kept alongside the boolean signal).
|
|
52
|
+
export const CustomLoadingNode: Story = {
|
|
53
|
+
render: () => (
|
|
54
|
+
<WebPreview className="h-96" defaultUrl="about:blank">
|
|
55
|
+
<WebPreviewNavigation>
|
|
56
|
+
<WebPreviewUrl />
|
|
57
|
+
</WebPreviewNavigation>
|
|
58
|
+
<WebPreviewBody
|
|
59
|
+
loading={
|
|
60
|
+
<div className="absolute inset-0 flex items-center justify-center bg-card text-body text-muted-foreground">
|
|
61
|
+
Booting sandbox…
|
|
62
|
+
</div>
|
|
63
|
+
}
|
|
64
|
+
/>
|
|
65
|
+
</WebPreview>
|
|
66
|
+
),
|
|
67
|
+
};
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
import { describe, expect, it } from "vitest";
|
|
2
|
+
import { render, screen } from "@testing-library/react";
|
|
3
|
+
import {
|
|
4
|
+
WebPreview,
|
|
5
|
+
WebPreviewBody,
|
|
6
|
+
WebPreviewNavigation,
|
|
7
|
+
WebPreviewNavigationButton,
|
|
8
|
+
WebPreviewUrl,
|
|
9
|
+
} from "./web-preview";
|
|
10
|
+
|
|
11
|
+
describe("WebPreview", () => {
|
|
12
|
+
it("renders the navigation bar and the iframe body", () => {
|
|
13
|
+
const { container, getByDisplayValue } = render(
|
|
14
|
+
<WebPreview defaultUrl="about:blank">
|
|
15
|
+
<WebPreviewNavigation>
|
|
16
|
+
<WebPreviewUrl />
|
|
17
|
+
</WebPreviewNavigation>
|
|
18
|
+
<WebPreviewBody />
|
|
19
|
+
</WebPreview>,
|
|
20
|
+
);
|
|
21
|
+
expect(container.querySelector("iframe")).not.toBeNull();
|
|
22
|
+
expect(getByDisplayValue("about:blank")).toBeInTheDocument();
|
|
23
|
+
});
|
|
24
|
+
});
|
|
25
|
+
|
|
26
|
+
describe("WebPreviewBody loading (#269, loading-states.md)", () => {
|
|
27
|
+
it("renders nothing extra by default", () => {
|
|
28
|
+
const { container } = render(
|
|
29
|
+
<WebPreview>
|
|
30
|
+
<WebPreviewBody />
|
|
31
|
+
</WebPreview>,
|
|
32
|
+
);
|
|
33
|
+
expect(container.querySelector(".animate-pulse")).toBeNull();
|
|
34
|
+
expect(container.querySelector('[role="status"]')).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
|
|
37
|
+
it("renders a layout-shaped skeleton filling the iframe box when loading is true", () => {
|
|
38
|
+
const { container } = render(
|
|
39
|
+
<WebPreview>
|
|
40
|
+
<WebPreviewBody loading />
|
|
41
|
+
</WebPreview>,
|
|
42
|
+
);
|
|
43
|
+
expect(container.querySelectorAll(".animate-pulse").length).toBeGreaterThan(0);
|
|
44
|
+
const statuses = container.querySelectorAll('[role="status"]');
|
|
45
|
+
expect(statuses).toHaveLength(1);
|
|
46
|
+
expect(statuses[0]).toHaveAttribute("aria-live", "polite");
|
|
47
|
+
// The iframe itself keeps rendering underneath the placeholder.
|
|
48
|
+
expect(container.querySelector("iframe")).not.toBeNull();
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("renders a caller-supplied placeholder node instead of the default skeleton", () => {
|
|
52
|
+
const { container, getByText } = render(
|
|
53
|
+
<WebPreview>
|
|
54
|
+
<WebPreviewBody loading={<div>Booting sandbox…</div>} />
|
|
55
|
+
</WebPreview>,
|
|
56
|
+
);
|
|
57
|
+
expect(getByText("Booting sandbox…")).toBeInTheDocument();
|
|
58
|
+
expect(container.querySelector(".animate-pulse")).toBeNull();
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// #386 — `WebPreviewNavigationButton` is icon-only. Its `tooltip` only becomes
|
|
63
|
+
// an `aria-describedby` while the Radix tooltip is OPEN, so at rest the button
|
|
64
|
+
// had no accessible name at all and axe's `button-name` reds every story that
|
|
65
|
+
// mounts one. The tooltip text is the name (the `MessageAction` precedent in
|
|
66
|
+
// message.tsx), and an explicit `aria-label` still wins.
|
|
67
|
+
describe("WebPreviewNavigationButton accessible name (#386)", () => {
|
|
68
|
+
it("names an icon-only navigation button from its tooltip", () => {
|
|
69
|
+
render(
|
|
70
|
+
<WebPreview>
|
|
71
|
+
<WebPreviewNavigation>
|
|
72
|
+
<WebPreviewNavigationButton tooltip="Reload">
|
|
73
|
+
<svg aria-hidden="true" />
|
|
74
|
+
</WebPreviewNavigationButton>
|
|
75
|
+
</WebPreviewNavigation>
|
|
76
|
+
</WebPreview>,
|
|
77
|
+
);
|
|
78
|
+
expect(screen.getByRole("button", { name: "Reload" })).toBeInTheDocument();
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
it("still names a disabled navigation button", () => {
|
|
82
|
+
render(
|
|
83
|
+
<WebPreview>
|
|
84
|
+
<WebPreviewNavigation>
|
|
85
|
+
<WebPreviewNavigationButton disabled tooltip="Reload">
|
|
86
|
+
<svg aria-hidden="true" />
|
|
87
|
+
</WebPreviewNavigationButton>
|
|
88
|
+
</WebPreviewNavigation>
|
|
89
|
+
</WebPreview>,
|
|
90
|
+
);
|
|
91
|
+
expect(screen.getByRole("button", { name: "Reload" })).toBeDisabled();
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
it("lets an explicit aria-label override the tooltip-derived name", () => {
|
|
95
|
+
render(
|
|
96
|
+
<WebPreview>
|
|
97
|
+
<WebPreviewNavigation>
|
|
98
|
+
<WebPreviewNavigationButton aria-label="Reload preview" tooltip="Reload">
|
|
99
|
+
<svg aria-hidden="true" />
|
|
100
|
+
</WebPreviewNavigationButton>
|
|
101
|
+
</WebPreviewNavigation>
|
|
102
|
+
</WebPreview>,
|
|
103
|
+
);
|
|
104
|
+
expect(screen.getByRole("button", { name: "Reload preview" })).toBeInTheDocument();
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it("keeps a text-labelled navigation button's own content as its name", () => {
|
|
108
|
+
render(
|
|
109
|
+
<WebPreview>
|
|
110
|
+
<WebPreviewNavigation>
|
|
111
|
+
<WebPreviewNavigationButton>Back</WebPreviewNavigationButton>
|
|
112
|
+
</WebPreviewNavigation>
|
|
113
|
+
</WebPreview>,
|
|
114
|
+
);
|
|
115
|
+
expect(screen.getByRole("button", { name: "Back" })).toBeInTheDocument();
|
|
116
|
+
});
|
|
117
|
+
});
|