@designa8/vibedesign-v6 1.6.7
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/README.md +66 -0
- package/dist/fonts/inter/Inter-Italic[opsz,wght].ttf +0 -0
- package/dist/fonts/inter/Inter[opsz,wght].ttf +0 -0
- package/dist/index.cjs +3231 -0
- package/dist/index.js +3201 -0
- package/dist/styles.css +1810 -0
- package/package.json +109 -0
- package/src/atoms/AppLayout/AppLayout.tsx +537 -0
- package/src/atoms/AppLayout/index.ts +2 -0
- package/src/atoms/AppLayout/preview.tsx +75 -0
- package/src/atoms/AppSidebar/AppSidebar.tsx +399 -0
- package/src/atoms/AppSidebar/index.ts +2 -0
- package/src/atoms/AppSidebar/preview.tsx +214 -0
- package/src/atoms/AuthScreen/AuthScreen.tsx +226 -0
- package/src/atoms/AuthScreen/index.ts +2 -0
- package/src/atoms/AuthScreen/preview.tsx +10 -0
- package/src/atoms/Button/Button.tsx +71 -0
- package/src/atoms/Button/index.ts +2 -0
- package/src/atoms/Button/preview.tsx +71 -0
- package/src/atoms/ChatScreen/ChatScreen.tsx +629 -0
- package/src/atoms/ChatScreen/index.ts +2 -0
- package/src/atoms/ChatScreen/preview.tsx +239 -0
- package/src/atoms/Chip/Chip.tsx +121 -0
- package/src/atoms/Chip/index.ts +2 -0
- package/src/atoms/Chip/preview.tsx +99 -0
- package/src/atoms/FilterTabBar/FilterTabBar.tsx +95 -0
- package/src/atoms/FilterTabBar/index.ts +2 -0
- package/src/atoms/FilterTabBar/preview.tsx +92 -0
- package/src/atoms/Input/Input.tsx +139 -0
- package/src/atoms/Input/index.ts +2 -0
- package/src/atoms/Input/preview.tsx +97 -0
- package/src/atoms/Modal/Modal.tsx +144 -0
- package/src/atoms/Modal/index.ts +2 -0
- package/src/atoms/Modal/preview.tsx +111 -0
- package/src/atoms/NavItem/NavItem.tsx +316 -0
- package/src/atoms/NavItem/index.ts +2 -0
- package/src/atoms/NavItem/preview.tsx +125 -0
- package/src/atoms/PromptInputBar/PromptInputBar.tsx +626 -0
- package/src/atoms/PromptInputBar/index.ts +2 -0
- package/src/atoms/PromptInputBar/preview.tsx +85 -0
- package/src/atoms/TopNavbar/TopNavbar.tsx +400 -0
- package/src/atoms/TopNavbar/index.ts +2 -0
- package/src/atoms/TopNavbar/preview.tsx +117 -0
- package/src/atoms/UpgradeCard/UpgradeCard.tsx +65 -0
- package/src/atoms/UpgradeCard/index.ts +2 -0
- package/src/atoms/UpgradeCard/preview.tsx +25 -0
- package/src/atoms/WorkspaceMenu/WorkspaceMenu.tsx +216 -0
- package/src/atoms/WorkspaceMenu/index.ts +2 -0
- package/src/atoms/WorkspaceMenu/preview.tsx +44 -0
- package/src/index.ts +16 -0
- package/src/tokens.css +165 -0
|
@@ -0,0 +1,629 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { PromptInputBar, PromptMode, PromptInputBarModel } from "../PromptInputBar";
|
|
3
|
+
import { Button } from "../Button";
|
|
4
|
+
|
|
5
|
+
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
6
|
+
|
|
7
|
+
export type MessageRole = "user" | "ai";
|
|
8
|
+
|
|
9
|
+
export interface PlanTask {
|
|
10
|
+
id: string;
|
|
11
|
+
label: string;
|
|
12
|
+
/** pending = not yet started; in_progress = actively running; done = completed; failed = error */
|
|
13
|
+
status?: "pending" | "in_progress" | "done" | "failed";
|
|
14
|
+
/** Friendly tool label shown inline when status is in_progress */
|
|
15
|
+
currentTool?: string;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface PlanCard {
|
|
19
|
+
title: string;
|
|
20
|
+
tasks: PlanTask[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export interface ChatMessage {
|
|
24
|
+
id: string;
|
|
25
|
+
role: MessageRole;
|
|
26
|
+
content: string;
|
|
27
|
+
/** Initials shown in the user avatar — falls back to "U" */
|
|
28
|
+
userInitials?: string;
|
|
29
|
+
/** AI is still generating — show a live-activity row at the top of the bubble */
|
|
30
|
+
inFlight?: boolean;
|
|
31
|
+
/** Label for the current tool being invoked, e.g. "Writing atom" */
|
|
32
|
+
currentToolLabel?: string;
|
|
33
|
+
plan?: PlanCard;
|
|
34
|
+
/**
|
|
35
|
+
* Optional text rendered in a separate <p> AFTER the plan card.
|
|
36
|
+
* If not provided, nothing additional renders after the plan card.
|
|
37
|
+
*/
|
|
38
|
+
postContent?: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export interface ChatScreenProps {
|
|
42
|
+
/** Initial messages to render (used only when children is not provided).
|
|
43
|
+
* When explicitly set to [] (empty array), the empty state is shown instead of demo messages. */
|
|
44
|
+
messages?: ChatMessage[];
|
|
45
|
+
/** Placeholder for the prompt bar */
|
|
46
|
+
placeholder?: string;
|
|
47
|
+
/** Called when the user sends a new prompt */
|
|
48
|
+
onSend?: (value: string) => void;
|
|
49
|
+
/**
|
|
50
|
+
* When provided, renders directly inside a flex-1 flex flex-col min-h-0 div
|
|
51
|
+
* WITHOUT the default px-lg py-xl padding or max-w-2xl mx-auto container.
|
|
52
|
+
* Children control their own layout entirely, including scrolling.
|
|
53
|
+
*/
|
|
54
|
+
children?: React.ReactNode;
|
|
55
|
+
/**
|
|
56
|
+
* When provided, renders instead of the default PromptInputBar footer section.
|
|
57
|
+
* The entire border-t footer area is replaced by this node.
|
|
58
|
+
*/
|
|
59
|
+
renderFooter?: React.ReactNode;
|
|
60
|
+
/** Available AI models to surface in the PromptInputBar model selector */
|
|
61
|
+
models?: PromptInputBarModel[];
|
|
62
|
+
/** Currently selected model id */
|
|
63
|
+
selectedModelId?: string;
|
|
64
|
+
/** Called when the user selects a different model */
|
|
65
|
+
onModelChange?: (modelId: string) => void;
|
|
66
|
+
className?: string;
|
|
67
|
+
|
|
68
|
+
// ── Empty-state props ──────────────────────────────────────────────────────
|
|
69
|
+
/** Title shown in the built-in empty state. Default: "Start the conversation" */
|
|
70
|
+
emptyTitle?: string;
|
|
71
|
+
/** Description shown in the built-in empty state. */
|
|
72
|
+
emptyDescription?: string;
|
|
73
|
+
/**
|
|
74
|
+
* When provided, fully replaces the built-in empty state content.
|
|
75
|
+
* Still centered in the thread area when messages is an empty array.
|
|
76
|
+
*/
|
|
77
|
+
emptyState?: React.ReactNode;
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
// ─── Empty-state illustration ─────────────────────────────────────────────────
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Soft blob + chat bubble + sparkles.
|
|
84
|
+
* All geometry uses explicit SVG width/height attributes and inline styles
|
|
85
|
+
* so it renders correctly in consumer apps that may not include Tailwind
|
|
86
|
+
* numeric spacing utilities (w-28, size-2.5, h-1.5, opacity-15, etc.).
|
|
87
|
+
* Token-only color classes: text-primary, bg-primary, text-on-primary.
|
|
88
|
+
*/
|
|
89
|
+
const ChatEmptyIllustration: React.FC = () => (
|
|
90
|
+
// 112px container — stable width regardless of Tailwind spacing scale.
|
|
91
|
+
<div
|
|
92
|
+
className="relative flex-shrink-0"
|
|
93
|
+
aria-hidden="true"
|
|
94
|
+
style={{ width: 112 }}
|
|
95
|
+
>
|
|
96
|
+
{/* Organic blob background — explicit dimensions + inline opacity */}
|
|
97
|
+
<svg
|
|
98
|
+
viewBox="0 0 160 140"
|
|
99
|
+
width="112"
|
|
100
|
+
height="98"
|
|
101
|
+
className="text-primary"
|
|
102
|
+
fill="currentColor"
|
|
103
|
+
style={{ opacity: 0.15, display: "block" }}
|
|
104
|
+
>
|
|
105
|
+
<path d="M78 8c28-6 52 10 58 34 6 24-6 44-4 62 2 16-14 30-36 32-26 2-48-8-62-28-12-18-22-42-10-58C36 30 52 14 78 8z" />
|
|
106
|
+
</svg>
|
|
107
|
+
|
|
108
|
+
{/* Chat bubble circle — 64×64 via inline style */}
|
|
109
|
+
<div className="absolute inset-0 flex items-center justify-center">
|
|
110
|
+
<div
|
|
111
|
+
className="relative flex items-center justify-center rounded-full bg-primary shadow-sm"
|
|
112
|
+
style={{ width: 64, height: 64 }}
|
|
113
|
+
>
|
|
114
|
+
{/* Message lines — height/width via inline styles, not h-1.5 / w-2/3 */}
|
|
115
|
+
<div className="flex flex-col" style={{ width: 32, gap: 6 }}>
|
|
116
|
+
<span
|
|
117
|
+
className="rounded-full bg-on-primary"
|
|
118
|
+
style={{ height: 6, width: "100%" }}
|
|
119
|
+
/>
|
|
120
|
+
<span
|
|
121
|
+
className="rounded-full bg-on-primary"
|
|
122
|
+
style={{ height: 6, width: "66%" }}
|
|
123
|
+
/>
|
|
124
|
+
</div>
|
|
125
|
+
{/* Tail triangle — 12×12 via inline style, no h-3/w-3 */}
|
|
126
|
+
<span
|
|
127
|
+
className="absolute bg-primary"
|
|
128
|
+
style={{
|
|
129
|
+
width: 12,
|
|
130
|
+
height: 12,
|
|
131
|
+
bottom: -2,
|
|
132
|
+
right: 8,
|
|
133
|
+
transform: "rotate(45deg)",
|
|
134
|
+
borderRadius: 2,
|
|
135
|
+
}}
|
|
136
|
+
/>
|
|
137
|
+
</div>
|
|
138
|
+
</div>
|
|
139
|
+
|
|
140
|
+
{/* Sparkle accents — explicit width/height attrs; positions via inline style */}
|
|
141
|
+
<svg
|
|
142
|
+
viewBox="0 0 24 24"
|
|
143
|
+
width="12"
|
|
144
|
+
height="12"
|
|
145
|
+
className="absolute text-primary"
|
|
146
|
+
fill="currentColor"
|
|
147
|
+
aria-hidden="true"
|
|
148
|
+
style={{ left: 8, top: 16 }}
|
|
149
|
+
>
|
|
150
|
+
<path d="M12 0l1.5 8.5L22 12l-8.5 1.5L12 22l-1.5-8.5L2 12l8.5-1.5L12 0z" />
|
|
151
|
+
</svg>
|
|
152
|
+
<svg
|
|
153
|
+
viewBox="0 0 24 24"
|
|
154
|
+
width="10"
|
|
155
|
+
height="10"
|
|
156
|
+
className="absolute text-primary"
|
|
157
|
+
fill="currentColor"
|
|
158
|
+
aria-hidden="true"
|
|
159
|
+
style={{ right: 12, top: 32 }}
|
|
160
|
+
>
|
|
161
|
+
<path d="M12 0l1.5 8.5L22 12l-8.5 1.5L12 22l-1.5-8.5L2 12l8.5-1.5L12 0z" />
|
|
162
|
+
</svg>
|
|
163
|
+
<svg
|
|
164
|
+
viewBox="0 0 24 24"
|
|
165
|
+
width="8"
|
|
166
|
+
height="8"
|
|
167
|
+
className="absolute text-primary"
|
|
168
|
+
fill="currentColor"
|
|
169
|
+
aria-hidden="true"
|
|
170
|
+
style={{ left: 24, bottom: 24 }}
|
|
171
|
+
>
|
|
172
|
+
<path d="M12 0l1.5 8.5L22 12l-8.5 1.5L12 22l-1.5-8.5L2 12l8.5-1.5L12 0z" />
|
|
173
|
+
</svg>
|
|
174
|
+
<svg
|
|
175
|
+
viewBox="0 0 24 24"
|
|
176
|
+
width="14"
|
|
177
|
+
height="14"
|
|
178
|
+
className="absolute text-primary"
|
|
179
|
+
fill="currentColor"
|
|
180
|
+
aria-hidden="true"
|
|
181
|
+
style={{ right: 8, bottom: 32 }}
|
|
182
|
+
>
|
|
183
|
+
<path d="M12 0l1.5 8.5L22 12l-8.5 1.5L12 22l-1.5-8.5L2 12l8.5-1.5L12 0z" />
|
|
184
|
+
</svg>
|
|
185
|
+
</div>
|
|
186
|
+
);
|
|
187
|
+
|
|
188
|
+
/** Default empty-state content: illustration on the left, text block on the right. */
|
|
189
|
+
const ChatEmptyStateContent: React.FC<{ title: string; description: string }> = ({
|
|
190
|
+
title,
|
|
191
|
+
description,
|
|
192
|
+
}) => (
|
|
193
|
+
// Use inline gap so the layout is robust when gap-lg is absent in the consumer theme.
|
|
194
|
+
<div className="flex items-center px-lg" style={{ gap: 24 }}>
|
|
195
|
+
<ChatEmptyIllustration />
|
|
196
|
+
<div className="flex min-w-0 flex-col gap-xs">
|
|
197
|
+
<h2 className="text-heading-sm font-weight-heading-sm text-ink">{title}</h2>
|
|
198
|
+
<p className="text-body-sm text-muted" style={{ maxWidth: "24rem" }}>{description}</p>
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
// ─── Sub-components ───────────────────────────────────────────────────────────
|
|
204
|
+
|
|
205
|
+
/** Chevron icon — rotates when expanded */
|
|
206
|
+
const ChevronIcon: React.FC<{ expanded: boolean }> = ({ expanded }) => (
|
|
207
|
+
<svg
|
|
208
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
209
|
+
viewBox="0 0 24 24"
|
|
210
|
+
fill="none"
|
|
211
|
+
stroke="currentColor"
|
|
212
|
+
strokeWidth="2"
|
|
213
|
+
strokeLinecap="round"
|
|
214
|
+
strokeLinejoin="round"
|
|
215
|
+
className="size-4 text-muted flex-shrink-0 transition-transform duration-200"
|
|
216
|
+
style={{ transform: expanded ? "rotate(180deg)" : "rotate(0deg)" }}
|
|
217
|
+
aria-hidden="true"
|
|
218
|
+
>
|
|
219
|
+
<polyline points="6 9 12 15 18 9" />
|
|
220
|
+
</svg>
|
|
221
|
+
);
|
|
222
|
+
|
|
223
|
+
/** Numbered plan card — progressive reveal: only shows tasks that are not pending */
|
|
224
|
+
const PlanCardBlock: React.FC<{ plan: PlanCard }> = ({ plan }) => {
|
|
225
|
+
const [titleExpanded, setTitleExpanded] = React.useState(false);
|
|
226
|
+
const titleRef = React.useRef<HTMLSpanElement>(null);
|
|
227
|
+
const [isOverflowing, setIsOverflowing] = React.useState(false);
|
|
228
|
+
|
|
229
|
+
// Detect whether the title text actually overflows 2 lines
|
|
230
|
+
React.useEffect(() => {
|
|
231
|
+
const el = titleRef.current;
|
|
232
|
+
if (!el) return;
|
|
233
|
+
const check = () => {
|
|
234
|
+
if (el) {
|
|
235
|
+
setIsOverflowing(el.scrollHeight > el.clientHeight + 2);
|
|
236
|
+
}
|
|
237
|
+
};
|
|
238
|
+
check();
|
|
239
|
+
// Re-check on resize
|
|
240
|
+
const ro = new ResizeObserver(check);
|
|
241
|
+
ro.observe(el);
|
|
242
|
+
return () => ro.disconnect();
|
|
243
|
+
}, [plan.title]);
|
|
244
|
+
|
|
245
|
+
// Determine whether at least one task has been promoted beyond pending
|
|
246
|
+
const hasActivity = plan.tasks.some(
|
|
247
|
+
(t) => t.status === "in_progress" || t.status === "done" || t.status === "failed",
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
// Only show tasks that are not pending (progressive reveal)
|
|
251
|
+
const visibleTasks = plan.tasks.filter(
|
|
252
|
+
(t) => t.status === "in_progress" || t.status === "done" || t.status === "failed",
|
|
253
|
+
);
|
|
254
|
+
|
|
255
|
+
return (
|
|
256
|
+
<div className="mt-md rounded-xl border border-hairline bg-canvas shadow-sm overflow-hidden">
|
|
257
|
+
{/* Header */}
|
|
258
|
+
<div className="flex items-start gap-sm px-lg py-md border-b border-hairline-soft">
|
|
259
|
+
{/* Numbered-list icon */}
|
|
260
|
+
<svg
|
|
261
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
262
|
+
viewBox="0 0 24 24"
|
|
263
|
+
fill="none"
|
|
264
|
+
stroke="currentColor"
|
|
265
|
+
strokeWidth="2"
|
|
266
|
+
strokeLinecap="round"
|
|
267
|
+
strokeLinejoin="round"
|
|
268
|
+
className="size-4 text-primary flex-shrink-0 mt-xs"
|
|
269
|
+
aria-hidden="true"
|
|
270
|
+
>
|
|
271
|
+
<line x1="8" y1="6" x2="21" y2="6" />
|
|
272
|
+
<line x1="8" y1="12" x2="21" y2="12" />
|
|
273
|
+
<line x1="8" y1="18" x2="21" y2="18" />
|
|
274
|
+
<line x1="3" y1="6" x2="3.01" y2="6" />
|
|
275
|
+
<line x1="3" y1="12" x2="3.01" y2="12" />
|
|
276
|
+
<line x1="3" y1="18" x2="3.01" y2="18" />
|
|
277
|
+
</svg>
|
|
278
|
+
|
|
279
|
+
{/* Title + chevron */}
|
|
280
|
+
<div className="flex-1 min-w-0 flex items-start gap-xs">
|
|
281
|
+
<span
|
|
282
|
+
ref={titleRef}
|
|
283
|
+
className="text-body-sm font-weight-heading-sm text-primary flex-1 min-w-0"
|
|
284
|
+
style={
|
|
285
|
+
titleExpanded
|
|
286
|
+
? undefined
|
|
287
|
+
: {
|
|
288
|
+
display: "-webkit-box",
|
|
289
|
+
WebkitLineClamp: 2,
|
|
290
|
+
WebkitBoxOrient: "vertical",
|
|
291
|
+
overflow: "hidden",
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
>
|
|
295
|
+
{plan.title}
|
|
296
|
+
</span>
|
|
297
|
+
|
|
298
|
+
{/* Chevron toggle — only visible when title overflows */}
|
|
299
|
+
{isOverflowing && (
|
|
300
|
+
<Button
|
|
301
|
+
variant="ghost"
|
|
302
|
+
size="sm"
|
|
303
|
+
type="button"
|
|
304
|
+
onClick={() => setTitleExpanded((prev) => !prev)}
|
|
305
|
+
aria-label={titleExpanded ? "Collapse plan title" : "Expand plan title"}
|
|
306
|
+
className="flex-shrink-0 !p-xxs !rounded-xs"
|
|
307
|
+
>
|
|
308
|
+
<ChevronIcon expanded={titleExpanded} />
|
|
309
|
+
</Button>
|
|
310
|
+
)}
|
|
311
|
+
</div>
|
|
312
|
+
</div>
|
|
313
|
+
|
|
314
|
+
{/* Tasks — only render if at least one is promoted */}
|
|
315
|
+
{hasActivity && visibleTasks.length > 0 && (
|
|
316
|
+
<ol className="flex flex-col divide-y divide-hairline-soft">
|
|
317
|
+
{visibleTasks.map((task) => (
|
|
318
|
+
<li
|
|
319
|
+
key={task.id}
|
|
320
|
+
className="flex items-center gap-md px-lg py-md"
|
|
321
|
+
>
|
|
322
|
+
{/* Status indicator */}
|
|
323
|
+
{task.status === "in_progress" && (
|
|
324
|
+
<span
|
|
325
|
+
className="flex-shrink-0 size-3 rounded-full bg-primary animate-pulse"
|
|
326
|
+
aria-label="In progress"
|
|
327
|
+
/>
|
|
328
|
+
)}
|
|
329
|
+
{task.status === "done" && (
|
|
330
|
+
<span className="flex-shrink-0" aria-label="Done">
|
|
331
|
+
<svg
|
|
332
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
333
|
+
viewBox="0 0 24 24"
|
|
334
|
+
fill="none"
|
|
335
|
+
stroke="currentColor"
|
|
336
|
+
strokeWidth="2.5"
|
|
337
|
+
strokeLinecap="round"
|
|
338
|
+
strokeLinejoin="round"
|
|
339
|
+
className="size-4 text-semantic-success"
|
|
340
|
+
aria-hidden="true"
|
|
341
|
+
>
|
|
342
|
+
<polyline points="20 6 9 17 4 12" />
|
|
343
|
+
</svg>
|
|
344
|
+
</span>
|
|
345
|
+
)}
|
|
346
|
+
{task.status === "failed" && (
|
|
347
|
+
<span className="flex-shrink-0" aria-label="Failed">
|
|
348
|
+
<svg
|
|
349
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
350
|
+
viewBox="0 0 24 24"
|
|
351
|
+
fill="none"
|
|
352
|
+
stroke="currentColor"
|
|
353
|
+
strokeWidth="2.5"
|
|
354
|
+
strokeLinecap="round"
|
|
355
|
+
strokeLinejoin="round"
|
|
356
|
+
className="size-4 text-semantic-error"
|
|
357
|
+
aria-hidden="true"
|
|
358
|
+
>
|
|
359
|
+
<line x1="18" y1="6" x2="6" y2="18" />
|
|
360
|
+
<line x1="6" y1="6" x2="18" y2="18" />
|
|
361
|
+
</svg>
|
|
362
|
+
</span>
|
|
363
|
+
)}
|
|
364
|
+
|
|
365
|
+
{/* Label */}
|
|
366
|
+
<span
|
|
367
|
+
className={[
|
|
368
|
+
"text-body-sm",
|
|
369
|
+
task.status === "in_progress"
|
|
370
|
+
? "font-weight-heading-sm text-ink"
|
|
371
|
+
: task.status === "done"
|
|
372
|
+
? "line-through text-muted"
|
|
373
|
+
: task.status === "failed"
|
|
374
|
+
? "text-semantic-error"
|
|
375
|
+
: "text-ink",
|
|
376
|
+
]
|
|
377
|
+
.filter(Boolean)
|
|
378
|
+
.join(" ")}
|
|
379
|
+
>
|
|
380
|
+
{task.label}
|
|
381
|
+
</span>
|
|
382
|
+
|
|
383
|
+
{/* currentTool inline hint for in_progress */}
|
|
384
|
+
{task.status === "in_progress" && task.currentTool && (
|
|
385
|
+
<span className="ml-auto text-caption text-muted flex-shrink-0">
|
|
386
|
+
{task.currentTool}
|
|
387
|
+
</span>
|
|
388
|
+
)}
|
|
389
|
+
</li>
|
|
390
|
+
))}
|
|
391
|
+
</ol>
|
|
392
|
+
)}
|
|
393
|
+
</div>
|
|
394
|
+
);
|
|
395
|
+
};
|
|
396
|
+
|
|
397
|
+
/** AI avatar — small violet circle with "AI" text */
|
|
398
|
+
const AIAvatar: React.FC = () => (
|
|
399
|
+
<span
|
|
400
|
+
aria-hidden="true"
|
|
401
|
+
className="flex-shrink-0 flex items-center justify-center size-8 rounded-full bg-primary text-on-primary text-caption font-weight-heading-sm select-none mt-1"
|
|
402
|
+
>
|
|
403
|
+
AI
|
|
404
|
+
</span>
|
|
405
|
+
);
|
|
406
|
+
|
|
407
|
+
/** User avatar — slightly larger muted circle with user initials */
|
|
408
|
+
const UserAvatar: React.FC<{ initials?: string }> = ({ initials = "U" }) => (
|
|
409
|
+
<span
|
|
410
|
+
aria-hidden="true"
|
|
411
|
+
className="flex-shrink-0 flex items-center justify-center size-8 rounded-full bg-surface-strong text-muted text-caption font-weight-heading-sm select-none"
|
|
412
|
+
>
|
|
413
|
+
{initials}
|
|
414
|
+
</span>
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
/** Spinning circle icon for the live-activity row */
|
|
418
|
+
const SpinnerIcon: React.FC = () => (
|
|
419
|
+
<svg
|
|
420
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
421
|
+
viewBox="0 0 24 24"
|
|
422
|
+
fill="none"
|
|
423
|
+
stroke="currentColor"
|
|
424
|
+
strokeWidth="2.5"
|
|
425
|
+
strokeLinecap="round"
|
|
426
|
+
strokeLinejoin="round"
|
|
427
|
+
className="size-4 text-primary animate-spin flex-shrink-0"
|
|
428
|
+
aria-hidden="true"
|
|
429
|
+
>
|
|
430
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
|
|
431
|
+
</svg>
|
|
432
|
+
);
|
|
433
|
+
|
|
434
|
+
/** AI message bubble — left-aligned, avatar pinned to top of row */
|
|
435
|
+
const AiMessage: React.FC<{ message: ChatMessage }> = ({ message }) => (
|
|
436
|
+
<div className="flex items-start gap-md w-full">
|
|
437
|
+
<AIAvatar />
|
|
438
|
+
<div className="flex-1 min-w-0">
|
|
439
|
+
{message.inFlight && (
|
|
440
|
+
<div className="flex items-center gap-xs mb-sm min-h-8" role="status" aria-live="polite">
|
|
441
|
+
<SpinnerIcon />
|
|
442
|
+
<span className="text-body-sm text-primary">
|
|
443
|
+
{message.currentToolLabel ?? "Working…"}
|
|
444
|
+
</span>
|
|
445
|
+
</div>
|
|
446
|
+
)}
|
|
447
|
+
{/* Body text: body-sm (14px) */}
|
|
448
|
+
<p className="text-body-sm text-body leading-relaxed">{message.content}</p>
|
|
449
|
+
{message.plan && <PlanCardBlock plan={message.plan} />}
|
|
450
|
+
{message.postContent && (
|
|
451
|
+
<p className="text-body-sm text-body leading-relaxed mt-md">{message.postContent}</p>
|
|
452
|
+
)}
|
|
453
|
+
</div>
|
|
454
|
+
</div>
|
|
455
|
+
);
|
|
456
|
+
|
|
457
|
+
/** User message bubble — right-aligned with primary-disabled background */
|
|
458
|
+
const UserMessage: React.FC<{ message: ChatMessage }> = ({ message }) => (
|
|
459
|
+
<div className="flex items-start gap-md w-full justify-end">
|
|
460
|
+
<div className="max-w-[80%] bg-primary-disabled rounded-xl px-lg py-md">
|
|
461
|
+
{/* Body text: body-sm (14px) */}
|
|
462
|
+
<p className="text-body-sm text-ink">{message.content}</p>
|
|
463
|
+
</div>
|
|
464
|
+
<UserAvatar initials={message.userInitials ?? "U"} />
|
|
465
|
+
</div>
|
|
466
|
+
);
|
|
467
|
+
|
|
468
|
+
// ─── Main Component ───────────────────────────────────────────────────────────
|
|
469
|
+
|
|
470
|
+
const DEFAULT_EMPTY_TITLE = "Start the conversation";
|
|
471
|
+
const DEFAULT_EMPTY_DESCRIPTION =
|
|
472
|
+
"Ask about atoms, tokens, components, or anything in your design system.";
|
|
473
|
+
|
|
474
|
+
export const ChatScreen = React.forwardRef<HTMLDivElement, ChatScreenProps>(
|
|
475
|
+
(
|
|
476
|
+
{
|
|
477
|
+
messages: initialMessages,
|
|
478
|
+
placeholder = "Ask Lovable...",
|
|
479
|
+
onSend,
|
|
480
|
+
children,
|
|
481
|
+
renderFooter,
|
|
482
|
+
models,
|
|
483
|
+
selectedModelId,
|
|
484
|
+
onModelChange,
|
|
485
|
+
className,
|
|
486
|
+
emptyTitle = DEFAULT_EMPTY_TITLE,
|
|
487
|
+
emptyDescription = DEFAULT_EMPTY_DESCRIPTION,
|
|
488
|
+
emptyState,
|
|
489
|
+
},
|
|
490
|
+
ref,
|
|
491
|
+
) => {
|
|
492
|
+
const defaultMessages: ChatMessage[] = [
|
|
493
|
+
{
|
|
494
|
+
id: "1",
|
|
495
|
+
role: "user",
|
|
496
|
+
content: "Build a `PromptInputBar` Molecule that reproduces the Lovable-style prompt bar with placeholder and the bottom toolbar.",
|
|
497
|
+
userInitials: "DU",
|
|
498
|
+
},
|
|
499
|
+
{
|
|
500
|
+
id: "2",
|
|
501
|
+
role: "ai",
|
|
502
|
+
content:
|
|
503
|
+
"I'll build the `PromptInputBar` Molecule to match the Lovable-style prompt bar. It will include a soft surface background, large rounded container, textarea with placeholder, and the bottom toolbar with `+`, `Visual edits`, `Build` mode dropdown, mic, and send buttons.\n\nHere's my plan for building this component:",
|
|
504
|
+
plan: {
|
|
505
|
+
title: "Plan: Build the PromptInputBar Molecule with all toolbar controls, placeholder text, and mode-switching behaviour for the Lovable editor canvas",
|
|
506
|
+
tasks: [
|
|
507
|
+
{ id: "p1", label: "Create the PromptInputBar structure and styling", status: "done" },
|
|
508
|
+
{ id: "p2", label: "Add textarea with placeholder", status: "done" },
|
|
509
|
+
{ id: "p3", label: "Build bottom toolbar with all button elements", status: "done" },
|
|
510
|
+
{ id: "p4", label: "Add interactions and states" },
|
|
511
|
+
{ id: "p5", label: "Create stories and tests" },
|
|
512
|
+
],
|
|
513
|
+
},
|
|
514
|
+
postContent: "The plan above outlines all the steps. Let me start building the component now.",
|
|
515
|
+
},
|
|
516
|
+
{
|
|
517
|
+
id: "3",
|
|
518
|
+
role: "ai",
|
|
519
|
+
content: "Let me start building the `PromptInputBar` Molecule.",
|
|
520
|
+
},
|
|
521
|
+
];
|
|
522
|
+
|
|
523
|
+
const [messages, setMessages] = React.useState<ChatMessage[]>(
|
|
524
|
+
initialMessages !== undefined ? initialMessages : defaultMessages,
|
|
525
|
+
);
|
|
526
|
+
const [mode, setMode] = React.useState<PromptMode>("Build");
|
|
527
|
+
const threadRef = React.useRef<HTMLDivElement>(null);
|
|
528
|
+
const lastMessageCountRef = React.useRef(messages.length);
|
|
529
|
+
|
|
530
|
+
React.useEffect(() => {
|
|
531
|
+
if (initialMessages !== undefined) {
|
|
532
|
+
setMessages(initialMessages);
|
|
533
|
+
}
|
|
534
|
+
}, [initialMessages]);
|
|
535
|
+
|
|
536
|
+
React.useLayoutEffect(() => {
|
|
537
|
+
const thread = threadRef.current;
|
|
538
|
+
if (!thread) return;
|
|
539
|
+
|
|
540
|
+
const previousCount = lastMessageCountRef.current;
|
|
541
|
+
const currentCount = messages.length;
|
|
542
|
+
const didGrow = currentCount > previousCount;
|
|
543
|
+
|
|
544
|
+
if (previousCount === currentCount) {
|
|
545
|
+
thread.scrollTop = thread.scrollHeight;
|
|
546
|
+
} else if (didGrow) {
|
|
547
|
+
thread.scrollTop = thread.scrollHeight;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
lastMessageCountRef.current = currentCount;
|
|
551
|
+
}, [messages]);
|
|
552
|
+
|
|
553
|
+
const handleSend = (value: string) => {
|
|
554
|
+
if (!children) {
|
|
555
|
+
const newMsg: ChatMessage = {
|
|
556
|
+
id: String(Date.now()),
|
|
557
|
+
role: "user",
|
|
558
|
+
content: value,
|
|
559
|
+
};
|
|
560
|
+
setMessages((prev) => [...prev, newMsg]);
|
|
561
|
+
}
|
|
562
|
+
onSend?.(value);
|
|
563
|
+
};
|
|
564
|
+
|
|
565
|
+
const showEmptyState =
|
|
566
|
+
children === undefined &&
|
|
567
|
+
initialMessages !== undefined &&
|
|
568
|
+
initialMessages.length === 0;
|
|
569
|
+
|
|
570
|
+
return (
|
|
571
|
+
<div
|
|
572
|
+
ref={ref}
|
|
573
|
+
className={[
|
|
574
|
+
"w-full flex flex-col bg-surface-soft",
|
|
575
|
+
className,
|
|
576
|
+
]
|
|
577
|
+
.filter(Boolean)
|
|
578
|
+
.join(" ")}
|
|
579
|
+
style={{ height: "100%" }}
|
|
580
|
+
>
|
|
581
|
+
{children !== undefined ? (
|
|
582
|
+
<div className="flex-1 flex flex-col min-h-0">
|
|
583
|
+
{children}
|
|
584
|
+
</div>
|
|
585
|
+
) : showEmptyState ? (
|
|
586
|
+
<div className="flex-1 flex items-center justify-center overflow-y-auto px-lg py-xl">
|
|
587
|
+
{emptyState !== undefined ? (
|
|
588
|
+
emptyState
|
|
589
|
+
) : (
|
|
590
|
+
<ChatEmptyStateContent title={emptyTitle} description={emptyDescription} />
|
|
591
|
+
)}
|
|
592
|
+
</div>
|
|
593
|
+
) : (
|
|
594
|
+
<div ref={threadRef} className="flex-1 overflow-y-auto px-lg py-xl">
|
|
595
|
+
<div className="w-full max-w-2xl mx-auto flex flex-col gap-xl">
|
|
596
|
+
{messages.map((msg) =>
|
|
597
|
+
msg.role === "user" ? (
|
|
598
|
+
<UserMessage key={msg.id} message={msg} />
|
|
599
|
+
) : (
|
|
600
|
+
<AiMessage key={msg.id} message={msg} />
|
|
601
|
+
),
|
|
602
|
+
)}
|
|
603
|
+
</div>
|
|
604
|
+
</div>
|
|
605
|
+
)}
|
|
606
|
+
|
|
607
|
+
{renderFooter !== undefined ? (
|
|
608
|
+
renderFooter
|
|
609
|
+
) : (
|
|
610
|
+
<div className="w-full px-lg pb-lg pt-sm border-t border-hairline-soft bg-canvas">
|
|
611
|
+
<div className="w-full max-w-2xl mx-auto">
|
|
612
|
+
<PromptInputBar
|
|
613
|
+
placeholder={placeholder}
|
|
614
|
+
mode={mode}
|
|
615
|
+
onModeChange={setMode}
|
|
616
|
+
onSend={handleSend}
|
|
617
|
+
models={models}
|
|
618
|
+
selectedModelId={selectedModelId}
|
|
619
|
+
onModelChange={onModelChange}
|
|
620
|
+
/>
|
|
621
|
+
</div>
|
|
622
|
+
</div>
|
|
623
|
+
)}
|
|
624
|
+
</div>
|
|
625
|
+
);
|
|
626
|
+
},
|
|
627
|
+
);
|
|
628
|
+
|
|
629
|
+
ChatScreen.displayName = "ChatScreen";
|