@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
package/src/commit.tsx
ADDED
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import { Avatar, AvatarFallback } from "@elabs-ai/components-ui";
|
|
4
|
+
import { Button } from "@elabs-ai/components-ui";
|
|
5
|
+
import { Collapsible, CollapsibleContent, CollapsibleTrigger } from "@elabs-ai/components-ui";
|
|
6
|
+
import { useLocale } from "@elabs-ai/components-ui";
|
|
7
|
+
import { cn } from "@elabs-ai/components-ui/lib/cn";
|
|
8
|
+
import { CheckIcon, CopyIcon, FileIcon, GitCommitIcon, MinusIcon, PlusIcon } from "lucide-react";
|
|
9
|
+
import type { ComponentProps, HTMLAttributes } from "react";
|
|
10
|
+
import { useCallback, useEffect, useRef, useState } from "react";
|
|
11
|
+
|
|
12
|
+
export type CommitProps = ComponentProps<typeof Collapsible>;
|
|
13
|
+
|
|
14
|
+
export const Commit = ({ className, children, ...props }: CommitProps) => (
|
|
15
|
+
<Collapsible className={cn("rounded-lg border bg-background", className)} {...props}>
|
|
16
|
+
{children}
|
|
17
|
+
</Collapsible>
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
export type CommitHeaderProps = ComponentProps<typeof CollapsibleTrigger>;
|
|
21
|
+
|
|
22
|
+
export const CommitHeader = ({ className, children, ...props }: CommitHeaderProps) => (
|
|
23
|
+
<CollapsibleTrigger asChild {...props}>
|
|
24
|
+
<div
|
|
25
|
+
className={cn(
|
|
26
|
+
"group flex cursor-pointer items-center justify-between gap-4 p-3 text-start transition-colors hover:opacity-80",
|
|
27
|
+
className,
|
|
28
|
+
)}
|
|
29
|
+
>
|
|
30
|
+
{children}
|
|
31
|
+
</div>
|
|
32
|
+
</CollapsibleTrigger>
|
|
33
|
+
);
|
|
34
|
+
|
|
35
|
+
export type CommitHashProps = HTMLAttributes<HTMLSpanElement>;
|
|
36
|
+
|
|
37
|
+
export const CommitHash = ({ className, children, ...props }: CommitHashProps) => (
|
|
38
|
+
<span className={cn("font-mono text-xs", className)} {...props}>
|
|
39
|
+
<GitCommitIcon className="me-1 inline-block size-3" />
|
|
40
|
+
{children}
|
|
41
|
+
</span>
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
export type CommitMessageProps = HTMLAttributes<HTMLSpanElement>;
|
|
45
|
+
|
|
46
|
+
export const CommitMessage = ({ className, children, ...props }: CommitMessageProps) => (
|
|
47
|
+
<span className={cn("font-medium text-sm", className)} {...props}>
|
|
48
|
+
{children}
|
|
49
|
+
</span>
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
export type CommitMetadataProps = HTMLAttributes<HTMLDivElement>;
|
|
53
|
+
|
|
54
|
+
export const CommitMetadata = ({ className, children, ...props }: CommitMetadataProps) => (
|
|
55
|
+
<div
|
|
56
|
+
className={cn("flex items-center gap-2 text-muted-foreground text-xs", className)}
|
|
57
|
+
{...props}
|
|
58
|
+
>
|
|
59
|
+
{children}
|
|
60
|
+
</div>
|
|
61
|
+
);
|
|
62
|
+
|
|
63
|
+
export type CommitSeparatorProps = HTMLAttributes<HTMLSpanElement>;
|
|
64
|
+
|
|
65
|
+
export const CommitSeparator = ({ className, children, ...props }: CommitSeparatorProps) => (
|
|
66
|
+
<span className={className} {...props}>
|
|
67
|
+
{children ?? "•"}
|
|
68
|
+
</span>
|
|
69
|
+
);
|
|
70
|
+
|
|
71
|
+
export type CommitInfoProps = HTMLAttributes<HTMLDivElement>;
|
|
72
|
+
|
|
73
|
+
export const CommitInfo = ({ className, children, ...props }: CommitInfoProps) => (
|
|
74
|
+
<div className={cn("flex flex-1 flex-col", className)} {...props}>
|
|
75
|
+
{children}
|
|
76
|
+
</div>
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
export type CommitAuthorProps = HTMLAttributes<HTMLDivElement>;
|
|
80
|
+
|
|
81
|
+
export const CommitAuthor = ({ className, children, ...props }: CommitAuthorProps) => (
|
|
82
|
+
<div className={cn("flex items-center", className)} {...props}>
|
|
83
|
+
{children}
|
|
84
|
+
</div>
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
export type CommitAuthorAvatarProps = ComponentProps<typeof Avatar> & {
|
|
88
|
+
initials: string;
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
export const CommitAuthorAvatar = ({ initials, className, ...props }: CommitAuthorAvatarProps) => (
|
|
92
|
+
<Avatar className={cn("size-8", className)} {...props}>
|
|
93
|
+
<AvatarFallback className="text-xs">{initials}</AvatarFallback>
|
|
94
|
+
</Avatar>
|
|
95
|
+
);
|
|
96
|
+
|
|
97
|
+
export type CommitTimestampProps = HTMLAttributes<HTMLTimeElement> & {
|
|
98
|
+
date: Date;
|
|
99
|
+
};
|
|
100
|
+
|
|
101
|
+
const formatRelativeDate = (date: Date, locale: string) => {
|
|
102
|
+
const days = Math.round((date.getTime() - Date.now()) / (1000 * 60 * 60 * 24));
|
|
103
|
+
return new Intl.RelativeTimeFormat(locale, { numeric: "auto" }).format(days, "day");
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const CommitTimestamp = ({ date, className, children, ...props }: CommitTimestampProps) => {
|
|
107
|
+
const { locale } = useLocale();
|
|
108
|
+
const [formatted, setFormatted] = useState("");
|
|
109
|
+
|
|
110
|
+
const updateFormatted = useCallback(() => {
|
|
111
|
+
setFormatted(formatRelativeDate(date, locale));
|
|
112
|
+
}, [date, locale]);
|
|
113
|
+
|
|
114
|
+
useEffect(() => {
|
|
115
|
+
updateFormatted();
|
|
116
|
+
}, [updateFormatted]);
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<time className={cn("text-xs", className)} dateTime={date.toISOString()} {...props}>
|
|
120
|
+
{children ?? formatted}
|
|
121
|
+
</time>
|
|
122
|
+
);
|
|
123
|
+
};
|
|
124
|
+
|
|
125
|
+
export type CommitActionsProps = HTMLAttributes<HTMLDivElement>;
|
|
126
|
+
|
|
127
|
+
const handleActionsClick = (e: React.MouseEvent) => e.stopPropagation();
|
|
128
|
+
const handleActionsKeyDown = (e: React.KeyboardEvent) => e.stopPropagation();
|
|
129
|
+
|
|
130
|
+
export const CommitActions = ({ className, children, ...props }: CommitActionsProps) => (
|
|
131
|
+
<div
|
|
132
|
+
className={cn("flex items-center gap-1", className)}
|
|
133
|
+
onClick={handleActionsClick}
|
|
134
|
+
onKeyDown={handleActionsKeyDown}
|
|
135
|
+
role="group"
|
|
136
|
+
{...props}
|
|
137
|
+
>
|
|
138
|
+
{children}
|
|
139
|
+
</div>
|
|
140
|
+
);
|
|
141
|
+
|
|
142
|
+
export type CommitCopyButtonProps = ComponentProps<typeof Button> & {
|
|
143
|
+
hash: string;
|
|
144
|
+
onCopy?: () => void;
|
|
145
|
+
onError?: (error: Error) => void;
|
|
146
|
+
timeout?: number;
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export const CommitCopyButton = ({
|
|
150
|
+
hash,
|
|
151
|
+
onCopy,
|
|
152
|
+
onError,
|
|
153
|
+
timeout = 2000,
|
|
154
|
+
children,
|
|
155
|
+
className,
|
|
156
|
+
...props
|
|
157
|
+
}: CommitCopyButtonProps) => {
|
|
158
|
+
const [isCopied, setIsCopied] = useState(false);
|
|
159
|
+
const timeoutRef = useRef<number>(0);
|
|
160
|
+
|
|
161
|
+
const copyToClipboard = useCallback(async () => {
|
|
162
|
+
if (typeof window === "undefined" || !navigator?.clipboard?.writeText) {
|
|
163
|
+
onError?.(new Error("Clipboard API not available"));
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
try {
|
|
168
|
+
if (!isCopied) {
|
|
169
|
+
await navigator.clipboard.writeText(hash);
|
|
170
|
+
setIsCopied(true);
|
|
171
|
+
onCopy?.();
|
|
172
|
+
timeoutRef.current = window.setTimeout(() => setIsCopied(false), timeout);
|
|
173
|
+
}
|
|
174
|
+
} catch (error) {
|
|
175
|
+
onError?.(error as Error);
|
|
176
|
+
}
|
|
177
|
+
}, [hash, onCopy, onError, timeout, isCopied]);
|
|
178
|
+
|
|
179
|
+
useEffect(
|
|
180
|
+
() => () => {
|
|
181
|
+
window.clearTimeout(timeoutRef.current);
|
|
182
|
+
},
|
|
183
|
+
[],
|
|
184
|
+
);
|
|
185
|
+
|
|
186
|
+
const Icon = isCopied ? CheckIcon : CopyIcon;
|
|
187
|
+
|
|
188
|
+
return (
|
|
189
|
+
<Button
|
|
190
|
+
className={cn("size-7 shrink-0", className)}
|
|
191
|
+
onClick={copyToClipboard}
|
|
192
|
+
size="icon"
|
|
193
|
+
variant="ghost"
|
|
194
|
+
{...props}
|
|
195
|
+
>
|
|
196
|
+
{children ?? <Icon size={14} />}
|
|
197
|
+
</Button>
|
|
198
|
+
);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
export type CommitContentProps = ComponentProps<typeof CollapsibleContent>;
|
|
202
|
+
|
|
203
|
+
export const CommitContent = ({ className, children, ...props }: CommitContentProps) => (
|
|
204
|
+
<CollapsibleContent className={cn("border-t p-3", className)} {...props}>
|
|
205
|
+
{children}
|
|
206
|
+
</CollapsibleContent>
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
export type CommitFilesProps = HTMLAttributes<HTMLDivElement>;
|
|
210
|
+
|
|
211
|
+
export const CommitFiles = ({ className, children, ...props }: CommitFilesProps) => (
|
|
212
|
+
<div className={cn("space-y-1", className)} {...props}>
|
|
213
|
+
{children}
|
|
214
|
+
</div>
|
|
215
|
+
);
|
|
216
|
+
|
|
217
|
+
export type CommitFileProps = HTMLAttributes<HTMLDivElement>;
|
|
218
|
+
|
|
219
|
+
export const CommitFile = ({ className, children, ...props }: CommitFileProps) => (
|
|
220
|
+
<div
|
|
221
|
+
className={cn(
|
|
222
|
+
"flex items-center justify-between gap-2 rounded px-2 py-1 text-sm hover:bg-muted/50",
|
|
223
|
+
className,
|
|
224
|
+
)}
|
|
225
|
+
{...props}
|
|
226
|
+
>
|
|
227
|
+
{children}
|
|
228
|
+
</div>
|
|
229
|
+
);
|
|
230
|
+
|
|
231
|
+
export type CommitFileInfoProps = HTMLAttributes<HTMLDivElement>;
|
|
232
|
+
|
|
233
|
+
export const CommitFileInfo = ({ className, children, ...props }: CommitFileInfoProps) => (
|
|
234
|
+
<div className={cn("flex min-w-0 items-center gap-2", className)} {...props}>
|
|
235
|
+
{children}
|
|
236
|
+
</div>
|
|
237
|
+
);
|
|
238
|
+
|
|
239
|
+
const fileStatusStyles = {
|
|
240
|
+
added: "text-green-600 dark:text-green-400",
|
|
241
|
+
deleted: "text-red-600 dark:text-red-400",
|
|
242
|
+
modified: "text-yellow-600 dark:text-yellow-400",
|
|
243
|
+
renamed: "text-blue-600 dark:text-blue-400",
|
|
244
|
+
};
|
|
245
|
+
|
|
246
|
+
const fileStatusLabels = {
|
|
247
|
+
added: "A",
|
|
248
|
+
deleted: "D",
|
|
249
|
+
modified: "M",
|
|
250
|
+
renamed: "R",
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
export type CommitFileStatusProps = HTMLAttributes<HTMLSpanElement> & {
|
|
254
|
+
status: "added" | "modified" | "deleted" | "renamed";
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
export const CommitFileStatus = ({
|
|
258
|
+
status,
|
|
259
|
+
className,
|
|
260
|
+
children,
|
|
261
|
+
...props
|
|
262
|
+
}: CommitFileStatusProps) => (
|
|
263
|
+
<span
|
|
264
|
+
className={cn("font-medium font-mono text-xs", fileStatusStyles[status], className)}
|
|
265
|
+
{...props}
|
|
266
|
+
>
|
|
267
|
+
{children ?? fileStatusLabels[status]}
|
|
268
|
+
</span>
|
|
269
|
+
);
|
|
270
|
+
|
|
271
|
+
export type CommitFileIconProps = ComponentProps<typeof FileIcon>;
|
|
272
|
+
|
|
273
|
+
export const CommitFileIcon = ({ className, ...props }: CommitFileIconProps) => (
|
|
274
|
+
<FileIcon className={cn("size-3.5 shrink-0 text-muted-foreground", className)} {...props} />
|
|
275
|
+
);
|
|
276
|
+
|
|
277
|
+
export type CommitFilePathProps = HTMLAttributes<HTMLSpanElement>;
|
|
278
|
+
|
|
279
|
+
export const CommitFilePath = ({ className, children, ...props }: CommitFilePathProps) => (
|
|
280
|
+
<span className={cn("truncate font-mono text-xs", className)} {...props}>
|
|
281
|
+
{children}
|
|
282
|
+
</span>
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
export type CommitFileChangesProps = HTMLAttributes<HTMLDivElement>;
|
|
286
|
+
|
|
287
|
+
export const CommitFileChanges = ({ className, children, ...props }: CommitFileChangesProps) => (
|
|
288
|
+
<div className={cn("flex shrink-0 items-center gap-1 font-mono text-xs", className)} {...props}>
|
|
289
|
+
{children}
|
|
290
|
+
</div>
|
|
291
|
+
);
|
|
292
|
+
|
|
293
|
+
export type CommitFileAdditionsProps = HTMLAttributes<HTMLSpanElement> & {
|
|
294
|
+
count: number;
|
|
295
|
+
};
|
|
296
|
+
|
|
297
|
+
export const CommitFileAdditions = ({
|
|
298
|
+
count,
|
|
299
|
+
className,
|
|
300
|
+
children,
|
|
301
|
+
...props
|
|
302
|
+
}: CommitFileAdditionsProps) => {
|
|
303
|
+
if (count <= 0) {
|
|
304
|
+
return null;
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
return (
|
|
308
|
+
<span className={cn("text-green-600 dark:text-green-400", className)} {...props}>
|
|
309
|
+
{children ?? (
|
|
310
|
+
<>
|
|
311
|
+
<PlusIcon className="inline-block size-3" />
|
|
312
|
+
{count}
|
|
313
|
+
</>
|
|
314
|
+
)}
|
|
315
|
+
</span>
|
|
316
|
+
);
|
|
317
|
+
};
|
|
318
|
+
|
|
319
|
+
export type CommitFileDeletionsProps = HTMLAttributes<HTMLSpanElement> & {
|
|
320
|
+
count: number;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
export const CommitFileDeletions = ({
|
|
324
|
+
count,
|
|
325
|
+
className,
|
|
326
|
+
children,
|
|
327
|
+
...props
|
|
328
|
+
}: CommitFileDeletionsProps) => {
|
|
329
|
+
if (count <= 0) {
|
|
330
|
+
return null;
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return (
|
|
334
|
+
<span className={cn("text-red-600 dark:text-red-400", className)} {...props}>
|
|
335
|
+
{children ?? (
|
|
336
|
+
<>
|
|
337
|
+
<MinusIcon className="inline-block size-3" />
|
|
338
|
+
{count}
|
|
339
|
+
</>
|
|
340
|
+
)}
|
|
341
|
+
</span>
|
|
342
|
+
);
|
|
343
|
+
};
|
|
@@ -0,0 +1,188 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Composer — the standard brand-ui AI chat input.
|
|
3
|
+
*
|
|
4
|
+
* The canonical two-tone "double card": an outer `bg-card` frame with a muted
|
|
5
|
+
* status strip wrapping a recessed `PromptInput` well (sharp top, theme-rounded
|
|
6
|
+
* bottom), a model pill, voice, and a circular send. This is THE chat input —
|
|
7
|
+
* reach for `<Composer />` instead of hand-rolling a `PromptInput` footer, in a
|
|
8
|
+
* `ChatShell` footer or as a standalone empty-state composer. Semantic tokens
|
|
9
|
+
* only; theme-aware radii; reads in every theme.
|
|
10
|
+
*/
|
|
11
|
+
import type { Meta, StoryObj } from "@storybook/react-vite";
|
|
12
|
+
import { expect, fn, waitFor } from "storybook/test";
|
|
13
|
+
|
|
14
|
+
import { ChatGreeting } from "./chat-greeting";
|
|
15
|
+
import { Composer } from "./composer";
|
|
16
|
+
|
|
17
|
+
const SUGGESTIONS = ["Summary", "Code", "Design", "Research"];
|
|
18
|
+
|
|
19
|
+
const meta = {
|
|
20
|
+
title: "AI/Composer",
|
|
21
|
+
component: Composer,
|
|
22
|
+
parameters: {
|
|
23
|
+
layout: "padded",
|
|
24
|
+
docs: {
|
|
25
|
+
description: {
|
|
26
|
+
component:
|
|
27
|
+
"The standard brand-ui AI chat input: a rounded two-tone double card (outer bg-card frame + muted status strip around a recessed PromptInput well with a sharp top and theme-rounded bottom), a model pill, voice, and a circular send. Built on the real @elabs-ai/components-ai PromptInput. Use it as the chat input everywhere — a ChatShell footer or a standalone empty-state composer. Semantic tokens only; reads in all themes.",
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
},
|
|
31
|
+
args: {
|
|
32
|
+
onSubmit: () => undefined,
|
|
33
|
+
},
|
|
34
|
+
tags: ["autodocs"],
|
|
35
|
+
} satisfies Meta<typeof Composer>;
|
|
36
|
+
|
|
37
|
+
export default meta;
|
|
38
|
+
type Story = StoryObj<typeof meta>;
|
|
39
|
+
|
|
40
|
+
/** The standalone composer with its defaults. */
|
|
41
|
+
export const Default: Story = {
|
|
42
|
+
render: (args) => (
|
|
43
|
+
<div className="mx-auto max-w-2xl">
|
|
44
|
+
<Composer {...args} />
|
|
45
|
+
</div>
|
|
46
|
+
),
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* `tone="card"` (#254): the tinted-outer/distinct-inner "double card" — an
|
|
51
|
+
* outer `bg-surface-muted` frame around a `tone="card"` well, instead of
|
|
52
|
+
* Composer's default outer `bg-card` frame. Check both themes: the well
|
|
53
|
+
* is raised (lighter than the frame) on light themes, recessed (darker) on
|
|
54
|
+
* dark.
|
|
55
|
+
*/
|
|
56
|
+
export const DoubleCardToned: Story = {
|
|
57
|
+
args: { tone: "card" },
|
|
58
|
+
render: (args) => (
|
|
59
|
+
<div className="mx-auto max-w-2xl">
|
|
60
|
+
<Composer {...args} />
|
|
61
|
+
</div>
|
|
62
|
+
),
|
|
63
|
+
};
|
|
64
|
+
|
|
65
|
+
/** The empty/first-run chat state: a centered greeting + composer + suggestion chips. */
|
|
66
|
+
export const EmptyStateScene: Story = {
|
|
67
|
+
parameters: { layout: "fullscreen" },
|
|
68
|
+
render: (args) => (
|
|
69
|
+
<div className="grid min-h-[28rem] place-items-center bg-background px-4 py-10 text-foreground">
|
|
70
|
+
<div className="w-full max-w-2xl">
|
|
71
|
+
<ChatGreeting title="Good morning, Avery" subtitle="How can I" accent="assist you today?" />
|
|
72
|
+
<Composer {...args} suggestions={SUGGESTIONS} />
|
|
73
|
+
</div>
|
|
74
|
+
</div>
|
|
75
|
+
),
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
/** While the agent is generating: a status line + the streaming send (stop) state. */
|
|
79
|
+
export const Streaming: Story = {
|
|
80
|
+
args: { status: "Generating…", sendStatus: "streaming", onStop: () => undefined },
|
|
81
|
+
render: (args) => (
|
|
82
|
+
<div className="mx-auto max-w-2xl">
|
|
83
|
+
<Composer {...args} />
|
|
84
|
+
</div>
|
|
85
|
+
),
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
/**
|
|
89
|
+
* Running, but the user has already typed a follow-up (#351's P0 fix): the
|
|
90
|
+
* control flips back to the circular ArrowUp `sendIcon` — never the Stop
|
|
91
|
+
* square — and submits normally, letting the app decide what a mid-turn
|
|
92
|
+
* submit means. `sendIcon` (not `children`) is what survives the flip; see
|
|
93
|
+
* `Composer`'s own docblock.
|
|
94
|
+
*/
|
|
95
|
+
export const StreamingWithDraft: Story = {
|
|
96
|
+
args: { status: "Generating…", sendStatus: "streaming", onSubmit: fn(), onStop: fn() },
|
|
97
|
+
render: (args) => (
|
|
98
|
+
<div className="mx-auto max-w-2xl">
|
|
99
|
+
<Composer {...args} />
|
|
100
|
+
</div>
|
|
101
|
+
),
|
|
102
|
+
play: async ({ canvas, args, userEvent }) => {
|
|
103
|
+
await userEvent.type(
|
|
104
|
+
canvas.getByPlaceholderText("Ask me anything…"),
|
|
105
|
+
"What about the edge cases?",
|
|
106
|
+
);
|
|
107
|
+
|
|
108
|
+
const send = await canvas.findByRole("button", { name: "Submit" });
|
|
109
|
+
await expect(send).toHaveAttribute("data-action", "send");
|
|
110
|
+
await expect(send.querySelector("svg.lucide-arrow-up")).not.toBeNull();
|
|
111
|
+
|
|
112
|
+
await send.click();
|
|
113
|
+
await waitFor(() => expect(args.onSubmit).toHaveBeenCalledTimes(1));
|
|
114
|
+
await expect(args.onStop).not.toHaveBeenCalled();
|
|
115
|
+
},
|
|
116
|
+
};
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Every send-button state at once — the affordance grid.
|
|
120
|
+
*
|
|
121
|
+
* At rest the send is an ArrowUp and is **disabled** until there is text or an
|
|
122
|
+
* attachment (an enabled-looking button that refuses to send is an a11y lie).
|
|
123
|
+
* While generating it becomes the Stop square; on error, an X that stays
|
|
124
|
+
* clickable so the user can retry. Use this story to check the disabled circular
|
|
125
|
+
* send across both themes — the primary fill and the disabled opacity interact.
|
|
126
|
+
*/
|
|
127
|
+
export const SendStates: Story = {
|
|
128
|
+
render: (args) => (
|
|
129
|
+
<div className="mx-auto flex max-w-2xl flex-col gap-6">
|
|
130
|
+
{(
|
|
131
|
+
[
|
|
132
|
+
["ready", "Empty — send disabled until you type"],
|
|
133
|
+
["submitted", "Submitted — spinner"],
|
|
134
|
+
["streaming", "Generating — Stop"],
|
|
135
|
+
["error", "Failed — retry"],
|
|
136
|
+
] as const
|
|
137
|
+
).map(([sendStatus, label]) => (
|
|
138
|
+
<Composer
|
|
139
|
+
key={sendStatus}
|
|
140
|
+
{...args}
|
|
141
|
+
onStop={() => undefined}
|
|
142
|
+
sendStatus={sendStatus}
|
|
143
|
+
status={label}
|
|
144
|
+
/>
|
|
145
|
+
))}
|
|
146
|
+
</div>
|
|
147
|
+
),
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
/** Trimmed: no model pill, no voice — just attach + send. */
|
|
151
|
+
export const Minimal: Story = {
|
|
152
|
+
args: { model: null, showVoice: false, status: null },
|
|
153
|
+
render: (args) => (
|
|
154
|
+
<div className="mx-auto max-w-2xl">
|
|
155
|
+
<Composer {...args} />
|
|
156
|
+
</div>
|
|
157
|
+
),
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* A consumer-refused send: `submitProps.disabled` closes BOTH the click and the
|
|
162
|
+
* Enter route to submit.
|
|
163
|
+
*
|
|
164
|
+
* Why it matters: `PromptInput`'s submit handler calls `form.reset()` the moment
|
|
165
|
+
* it ACCEPTS a submit, so an app that refuses the send inside `onSubmit` — one
|
|
166
|
+
* doing async setup before the first message, say — finds the textarea already
|
|
167
|
+
* cleared and the user's question destroyed, with nothing to restore from.
|
|
168
|
+
* Disabling the control is what actually prevents that.
|
|
169
|
+
*
|
|
170
|
+
* Type into the field: the text stays, and nothing submits.
|
|
171
|
+
*
|
|
172
|
+
* Note `disabled` must be left UNSET (not `false`) when you have no opinion —
|
|
173
|
+
* `PromptInputSubmit` resolves `disabled ?? autoDisabled`, so a literal `false`
|
|
174
|
+
* opts out of the library's own empty-composer guard.
|
|
175
|
+
*/
|
|
176
|
+
export const RefusedSubmit: Story = {
|
|
177
|
+
args: {
|
|
178
|
+
model: null,
|
|
179
|
+
status: "Setting up the conversation…",
|
|
180
|
+
suggestions: undefined,
|
|
181
|
+
submitProps: { disabled: true, "aria-label": "Send (unavailable until setup completes)" },
|
|
182
|
+
},
|
|
183
|
+
render: (args) => (
|
|
184
|
+
<div className="mx-auto max-w-2xl">
|
|
185
|
+
<Composer {...args} />
|
|
186
|
+
</div>
|
|
187
|
+
),
|
|
188
|
+
};
|