@designa8/vibedesign-linear-internal-v1-b737 0.0.1 → 0.2.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.
@@ -0,0 +1,498 @@
1
+ import * as React from "react";
2
+ import { Button } from "../Button";
3
+ import { Icon } from "../Icon";
4
+ import { IconButton } from "../IconButton";
5
+ import { Image } from "../Image";
6
+ import { Input } from "../Input";
7
+ import { Modal } from "../Modal";
8
+
9
+ export interface AgentQuestionOption {
10
+ id: string;
11
+ /** Overrides the auto A, B, C… letter shown in the option badge. */
12
+ letter?: string;
13
+ label: string;
14
+ }
15
+
16
+ export interface AgentQuestionAnswer {
17
+ questionId: string;
18
+ optionId: string;
19
+ /** Present only when the free-text row was the chosen answer. */
20
+ text?: string;
21
+ }
22
+
23
+ export interface AgentQuestionCardProps
24
+ extends Omit<React.HTMLAttributes<HTMLDivElement>, "onSubmit"> {
25
+ questionId: string;
26
+ question: string;
27
+ /** Shown before the question text, e.g. 1. */
28
+ questionNumber?: number;
29
+ options: AgentQuestionOption[];
30
+ /** Optional reference thumbnail; clicking it opens a large preview dialog. */
31
+ imageSrc?: string;
32
+ imageAlt?: string;
33
+ /** Label of the trailing free-text row. Pass `null` to remove the row. */
34
+ freeTextLabel?: string | null;
35
+ freeTextPlaceholder?: string;
36
+ /** Eyebrow label in the header. */
37
+ label?: string;
38
+ /** Muted hint beside the send action. */
39
+ hint?: string;
40
+ sendLabel?: string;
41
+ selectedOptionId?: string | null;
42
+ defaultSelectedOptionId?: string | null;
43
+ freeTextValue?: string;
44
+ defaultFreeTextValue?: string;
45
+ onAnswerChange?: (answer: { optionId: string | null; text: string }) => void;
46
+ onSubmit?: (answer: AgentQuestionAnswer) => void;
47
+ /** Called when the card collapses (close button or Escape). */
48
+ onClose?: () => void;
49
+ /** Called when the restore bar reopens the card. */
50
+ onReopen?: () => void;
51
+ collapsed?: boolean;
52
+ defaultCollapsed?: boolean;
53
+ onCollapsedChange?: (collapsed: boolean) => void;
54
+ submitting?: boolean;
55
+ /** Error line under the options; also marks the free-text row when it is chosen. */
56
+ errorMessage?: string;
57
+ /** Queue size shown in the restore bar. */
58
+ waitingCount?: number;
59
+ reopenLabel?: string;
60
+ }
61
+
62
+ /** Option id used when the free-text row is the selected answer. */
63
+ export const AGENT_QUESTION_FREE_TEXT_ID = "__other_free_text__";
64
+
65
+ const cn = (...parts: Array<string | false | null | undefined>) =>
66
+ parts.filter(Boolean).join(" ");
67
+
68
+ const letterFor = (option: AgentQuestionOption, index: number): string =>
69
+ option.letter ?? String.fromCharCode(65 + (index % 26));
70
+
71
+ const letterBadge = (selected: boolean): string =>
72
+ cn(
73
+ "flex h-lg w-lg shrink-0 items-center justify-center rounded-xs border text-caption transition-colors duration-150 ease-out",
74
+ selected
75
+ ? "border-primary bg-primary text-on-primary"
76
+ : "border-hairline-strong bg-canvas text-muted group-hover:border-primary group-hover:text-primary",
77
+ );
78
+
79
+ const PANEL =
80
+ "min-h-0 overflow-hidden transition duration-200 ease-out data-[state=open]:translate-y-0 data-[state=open]:opacity-100 data-[state=closed]:pointer-events-none data-[state=closed]:opacity-0";
81
+
82
+ /**
83
+ * The card that replaces the chat prompt while an agent waits on a choice.
84
+ * Options are a radiogroup (arrow keys move and select), the trailing row turns
85
+ * into an inline text field, and closing folds the card into a slim restore bar.
86
+ */
87
+ export const AgentQuestionCard = React.forwardRef<
88
+ HTMLDivElement,
89
+ AgentQuestionCardProps
90
+ >(
91
+ (
92
+ {
93
+ questionId,
94
+ question,
95
+ questionNumber,
96
+ options,
97
+ imageSrc,
98
+ imageAlt = "Reference image",
99
+ freeTextLabel = "Other…",
100
+ freeTextPlaceholder = "Type your answer",
101
+ label = "Questions",
102
+ hint = "Pick an option or write your own",
103
+ sendLabel = "Send",
104
+ selectedOptionId: selectedProp,
105
+ defaultSelectedOptionId = null,
106
+ freeTextValue: freeTextProp,
107
+ defaultFreeTextValue = "",
108
+ onAnswerChange,
109
+ onSubmit,
110
+ onClose,
111
+ onReopen,
112
+ collapsed: collapsedProp,
113
+ defaultCollapsed = false,
114
+ onCollapsedChange,
115
+ submitting = false,
116
+ errorMessage,
117
+ waitingCount = 1,
118
+ reopenLabel = "Answer",
119
+ className,
120
+ onKeyDown,
121
+ ...rest
122
+ },
123
+ ref,
124
+ ) => {
125
+ const reactId = React.useId();
126
+ const questionTextId = `aqc-question-${reactId}`;
127
+ const hintId = `aqc-hint-${reactId}`;
128
+ const freeTextInputId = `aqc-free-text-${reactId}`;
129
+
130
+ const [internalSelection, setInternalSelection] =
131
+ React.useState<string | null>(defaultSelectedOptionId);
132
+ const selected =
133
+ selectedProp !== undefined ? selectedProp ?? null : internalSelection;
134
+
135
+ const [internalText, setInternalText] = React.useState(defaultFreeTextValue);
136
+ const text = freeTextProp !== undefined ? freeTextProp : internalText;
137
+
138
+ const [imageOpen, setImageOpen] = React.useState(false);
139
+
140
+ const [internalCollapsed, setInternalCollapsed] =
141
+ React.useState(defaultCollapsed);
142
+ const collapsed =
143
+ collapsedProp !== undefined ? collapsedProp : internalCollapsed;
144
+
145
+ const setSelection = (next: string | null) => {
146
+ if (selectedProp === undefined) setInternalSelection(next);
147
+ onAnswerChange?.({ optionId: next, text });
148
+ };
149
+
150
+ const setText = (next: string) => {
151
+ if (freeTextProp === undefined) setInternalText(next);
152
+ onAnswerChange?.({ optionId: selected, text: next });
153
+ };
154
+
155
+ const collapse = (next: boolean) => {
156
+ if (collapsedProp === undefined) setInternalCollapsed(next);
157
+ onCollapsedChange?.(next);
158
+ if (next) onClose?.();
159
+ else onReopen?.();
160
+ };
161
+
162
+ const hasFreeText = freeTextLabel !== null;
163
+ const freeTextSelected =
164
+ hasFreeText && selected === AGENT_QUESTION_FREE_TEXT_ID;
165
+ const canSend =
166
+ !submitting &&
167
+ selected !== null &&
168
+ (!freeTextSelected || text.trim().length > 0);
169
+
170
+ const optionIds = [
171
+ ...options.map((option) => option.id),
172
+ ...(hasFreeText ? [AGENT_QUESTION_FREE_TEXT_ID] : []),
173
+ ];
174
+
175
+ const handleSubmit = () => {
176
+ if (!canSend || selected === null) return;
177
+ onSubmit?.({
178
+ questionId,
179
+ optionId: selected,
180
+ text: freeTextSelected ? text.trim() : undefined,
181
+ });
182
+ };
183
+
184
+ const rowRefs = React.useRef<Array<HTMLButtonElement | null>>([]);
185
+
186
+ const moveTo = (index: number) => {
187
+ const count = optionIds.length;
188
+ if (count === 0) return;
189
+ const wrapped = ((index % count) + count) % count;
190
+ rowRefs.current[wrapped]?.focus();
191
+ setSelection(optionIds[wrapped]);
192
+ };
193
+
194
+ const radioKeys =
195
+ (index: number) => (event: React.KeyboardEvent<HTMLButtonElement>) => {
196
+ if (event.key === "ArrowDown" || event.key === "ArrowRight") {
197
+ event.preventDefault();
198
+ moveTo(index + 1);
199
+ } else if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
200
+ event.preventDefault();
201
+ moveTo(index - 1);
202
+ }
203
+ };
204
+
205
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
206
+ onKeyDown?.(event);
207
+ if (event.key !== "Escape" || imageOpen || collapsed) return;
208
+ event.stopPropagation();
209
+ collapse(true);
210
+ };
211
+
212
+ const cardState = collapsed ? "closed" : "open";
213
+ const freeTextLetter = letterFor(
214
+ { id: AGENT_QUESTION_FREE_TEXT_ID, label: "" },
215
+ options.length,
216
+ );
217
+
218
+ const card = (
219
+ <div
220
+ role="group"
221
+ aria-labelledby={questionTextId}
222
+ aria-describedby={hintId}
223
+ aria-busy={submitting || undefined}
224
+ className="w-full rounded-xl border border-hairline bg-surface p-lg shadow-card"
225
+ >
226
+ <div className="mb-md flex items-center gap-sm">
227
+ <Icon name="message-circle" size={16} className="shrink-0 text-muted" />
228
+ <span className="min-w-0 flex-1 truncate text-body-sm text-muted">
229
+ {label}
230
+ </span>
231
+ <IconButton
232
+ icon="x"
233
+ variant="ghost"
234
+ size="md"
235
+ aria-label="Close question"
236
+ disabled={submitting}
237
+ onClick={() => collapse(true)}
238
+ className="text-muted-soft"
239
+ />
240
+ </div>
241
+
242
+ <div className="mb-md flex items-baseline gap-sm">
243
+ {questionNumber !== undefined && (
244
+ <span className="shrink-0 text-body-md text-muted">
245
+ {questionNumber}.
246
+ </span>
247
+ )}
248
+ <span id={questionTextId} className="min-w-0 flex-1 text-body-md text-ink">
249
+ {question}
250
+ </span>
251
+ </div>
252
+
253
+ {imageSrc && (
254
+ <div className="mb-md">
255
+ <Button
256
+ variant="media"
257
+ fullWidth
258
+ aria-haspopup="dialog"
259
+ aria-label={`View ${imageAlt}`}
260
+ onClick={() => setImageOpen(true)}
261
+ className="group block"
262
+ >
263
+ <div className="mx-auto w-2/3">
264
+ <Image
265
+ src={imageSrc}
266
+ alt={imageAlt}
267
+ ratio="wide"
268
+ fit="contain"
269
+ frameClassName="transition-colors duration-150 ease-out group-hover:border-hairline-strong"
270
+ />
271
+ </div>
272
+ </Button>
273
+ </div>
274
+ )}
275
+
276
+ <div
277
+ role="radiogroup"
278
+ aria-labelledby={questionTextId}
279
+ className="flex flex-col gap-xs"
280
+ >
281
+ {options.map((option, index) => {
282
+ const isSelected = selected === option.id;
283
+ return (
284
+ <Button
285
+ key={option.id}
286
+ ref={(node) => {
287
+ rowRefs.current[index] = node;
288
+ }}
289
+ variant="item"
290
+ size="md"
291
+ fullWidth
292
+ role="radio"
293
+ aria-checked={isSelected}
294
+ aria-label={option.label}
295
+ disabled={submitting}
296
+ leadingIcon={
297
+ <span aria-hidden="true" className={letterBadge(isSelected)}>
298
+ {letterFor(option, index)}
299
+ </span>
300
+ }
301
+ trailingIcon={
302
+ isSelected ? (
303
+ <Icon name="check" size={14} className="text-primary" />
304
+ ) : undefined
305
+ }
306
+ onClick={() => setSelection(option.id)}
307
+ onKeyDown={radioKeys(index)}
308
+ className="group"
309
+ >
310
+ {option.label}
311
+ </Button>
312
+ );
313
+ })}
314
+
315
+ {hasFreeText && (
316
+ <div
317
+ className={cn(
318
+ "flex w-full items-center gap-sm rounded-md border px-xs transition-colors duration-150 ease-out",
319
+ errorMessage && freeTextSelected
320
+ ? "border-semantic-error"
321
+ : freeTextSelected
322
+ ? "border-transparent bg-primary-soft"
323
+ : "border-transparent",
324
+ )}
325
+ >
326
+ {freeTextSelected ? (
327
+ <Button
328
+ ref={(node) => {
329
+ rowRefs.current[options.length] = node;
330
+ }}
331
+ variant="item"
332
+ size="md"
333
+ iconOnly
334
+ role="radio"
335
+ aria-checked
336
+ aria-label={freeTextLabel ?? undefined}
337
+ disabled={submitting}
338
+ onClick={() => {
339
+ requestAnimationFrame(() =>
340
+ document.getElementById(freeTextInputId)?.focus(),
341
+ );
342
+ }}
343
+ onKeyDown={radioKeys(options.length)}
344
+ className="group"
345
+ >
346
+ <span aria-hidden="true" className={letterBadge(true)}>
347
+ {freeTextLetter}
348
+ </span>
349
+ </Button>
350
+ ) : (
351
+ <Button
352
+ ref={(node) => {
353
+ rowRefs.current[options.length] = node;
354
+ }}
355
+ variant="item"
356
+ size="md"
357
+ fullWidth
358
+ role="radio"
359
+ aria-checked={false}
360
+ aria-label={freeTextLabel ?? undefined}
361
+ disabled={submitting}
362
+ leadingIcon={
363
+ <span aria-hidden="true" className={letterBadge(false)}>
364
+ {freeTextLetter}
365
+ </span>
366
+ }
367
+ onClick={() => {
368
+ setSelection(AGENT_QUESTION_FREE_TEXT_ID);
369
+ requestAnimationFrame(() =>
370
+ document.getElementById(freeTextInputId)?.focus(),
371
+ );
372
+ }}
373
+ onKeyDown={radioKeys(options.length)}
374
+ className="group text-muted"
375
+ >
376
+ {freeTextLabel}
377
+ </Button>
378
+ )}
379
+
380
+ {freeTextSelected && (
381
+ <>
382
+ <div className="min-w-0 flex-1">
383
+ <Input
384
+ id={freeTextInputId}
385
+ chrome="none"
386
+ value={text}
387
+ onChange={(event) => setText(event.target.value)}
388
+ onKeyDown={(event) => {
389
+ if (event.key === "Enter") {
390
+ event.preventDefault();
391
+ handleSubmit();
392
+ }
393
+ }}
394
+ placeholder={freeTextPlaceholder}
395
+ aria-label="Your answer"
396
+ disabled={submitting}
397
+ />
398
+ </div>
399
+ <Icon name="check" size={14} className="mr-xs shrink-0 text-primary" />
400
+ </>
401
+ )}
402
+ </div>
403
+ )}
404
+ </div>
405
+
406
+ <div role="status" aria-live="polite">
407
+ {errorMessage && (
408
+ <p className="mt-xs text-caption text-semantic-error">{errorMessage}</p>
409
+ )}
410
+ </div>
411
+
412
+ <div className="mt-md flex items-center justify-between gap-md border-t border-hairline-soft pt-md">
413
+ <span id={hintId} className="min-w-0 flex-1 text-caption text-muted">
414
+ {hint}
415
+ </span>
416
+ <Button
417
+ variant="primary"
418
+ size="lg"
419
+ disabled={!canSend}
420
+ loading={submitting}
421
+ loadingText="Sending…"
422
+ onClick={handleSubmit}
423
+ trailingIcon={<Icon name="arrow-up" size={16} />}
424
+ >
425
+ {sendLabel}
426
+ </Button>
427
+ </div>
428
+ </div>
429
+ );
430
+
431
+ return (
432
+ <div
433
+ ref={ref}
434
+ data-state={cardState}
435
+ className={cn("w-full", className)}
436
+ onKeyDown={handleKeyDown}
437
+ {...rest}
438
+ >
439
+ <div
440
+ className={cn(
441
+ "grid overflow-hidden transition-[grid-template-rows] duration-200 ease-out",
442
+ collapsed ? "grid-rows-[0fr]" : "grid-rows-[1fr]",
443
+ )}
444
+ >
445
+ <div
446
+ data-state={cardState}
447
+ className={cn(PANEL, "origin-bottom data-[state=closed]:-translate-y-2")}
448
+ >
449
+ {card}
450
+ </div>
451
+ </div>
452
+
453
+ <div
454
+ className={cn(
455
+ "grid overflow-hidden transition-[grid-template-rows] duration-200 ease-out",
456
+ collapsed ? "grid-rows-[1fr]" : "grid-rows-[0fr]",
457
+ )}
458
+ >
459
+ <div
460
+ data-state={collapsed ? "open" : "closed"}
461
+ className={cn(PANEL, "origin-bottom data-[state=closed]:translate-y-2")}
462
+ >
463
+ <div className="flex w-full items-center gap-md rounded-xl border border-hairline bg-surface px-md py-sm shadow-card">
464
+ <span className="flex h-lg w-lg shrink-0 items-center justify-center rounded-full bg-primary text-on-primary">
465
+ <Icon name="message-circle" size={14} />
466
+ </span>
467
+ <span className="min-w-0 flex-1 truncate text-body-sm text-ink">
468
+ {waitingCount === 1
469
+ ? "1 question waiting"
470
+ : `${waitingCount} questions waiting`}
471
+ </span>
472
+ <Button
473
+ variant="ghost"
474
+ size="sm"
475
+ onClick={() => collapse(false)}
476
+ className="text-primary"
477
+ >
478
+ {reopenLabel}
479
+ </Button>
480
+ </div>
481
+ </div>
482
+ </div>
483
+
484
+ {imageSrc && (
485
+ <Modal
486
+ open={imageOpen}
487
+ onOpenChange={setImageOpen}
488
+ title="Reference image"
489
+ size="lg"
490
+ >
491
+ <Image src={imageSrc} alt={imageAlt} ratio="wide" fit="contain" />
492
+ </Modal>
493
+ )}
494
+ </div>
495
+ );
496
+ },
497
+ );
498
+ AgentQuestionCard.displayName = "AgentQuestionCard";
@@ -0,0 +1,6 @@
1
+ export { AgentQuestionCard, AGENT_QUESTION_FREE_TEXT_ID } from "./AgentQuestionCard";
2
+ export type {
3
+ AgentQuestionCardProps,
4
+ AgentQuestionAnswer,
5
+ AgentQuestionOption,
6
+ } from "./AgentQuestionCard";
@@ -0,0 +1,109 @@
1
+ import * as React from "react";
2
+ import { AgentQuestionCard } from "./AgentQuestionCard";
3
+ import type { AgentQuestionAnswer, AgentQuestionOption } from "./AgentQuestionCard";
4
+
5
+ const OPTIONS: AgentQuestionOption[] = [
6
+ { id: "keep", label: "Keep the current layout and tighten spacing" },
7
+ { id: "rebuild", label: "Rebuild the canvas grid from scratch" },
8
+ { id: "defer", label: "Leave it as is for now" },
9
+ ];
10
+
11
+ const REFERENCE_IMAGE =
12
+ "https://images.unsplash.com/photo-1618005182384-a83a8bd57fbe?auto=format&fit=crop&w=720&q=70";
13
+
14
+ const Section = ({ title, children }: { title: string; children: React.ReactNode }) => (
15
+ <section className="space-y-sm">
16
+ <h2 className="text-caption text-muted">{title}</h2>
17
+ {children}
18
+ </section>
19
+ );
20
+
21
+ export default function Preview() {
22
+ const [selected, setSelected] = React.useState<string | null>("keep");
23
+ const [text, setText] = React.useState("");
24
+ const [collapsed, setCollapsed] = React.useState(false);
25
+ const [submitted, setSubmitted] = React.useState<AgentQuestionAnswer | null>(null);
26
+
27
+ const [errorSelected, setErrorSelected] = React.useState<string | null>("rebuild");
28
+ const [errorText, setErrorText] = React.useState("");
29
+ const [showError, setShowError] = React.useState(true);
30
+
31
+ return (
32
+ <div className="w-full max-w-3xl mx-auto p-lg space-y-lg">
33
+ <Section title="Live card — pick an option, choose Other…, or close it">
34
+ <AgentQuestionCard
35
+ questionId="q-layout"
36
+ questionNumber={1}
37
+ question="How should I handle the canvas layout for the new editor?"
38
+ options={OPTIONS}
39
+ imageSrc={REFERENCE_IMAGE}
40
+ imageAlt="Reference layout sketch"
41
+ selectedOptionId={selected}
42
+ freeTextValue={text}
43
+ hint={submitted ? "Answer sent" : "Pick an option or write your own"}
44
+ collapsed={collapsed}
45
+ onAnswerChange={(answer) => {
46
+ setSelected(answer.optionId);
47
+ setText(answer.text);
48
+ setSubmitted(null);
49
+ }}
50
+ onCollapsedChange={setCollapsed}
51
+ onSubmit={(answer) => setSubmitted(answer)}
52
+ />
53
+ <p className="text-caption text-muted">
54
+ {submitted
55
+ ? `Submitted ${submitted.optionId}${submitted.text ? ` — “${submitted.text}”` : ""}`
56
+ : "Nothing submitted yet."}
57
+ </p>
58
+ </Section>
59
+
60
+ <Section title="Error state — clear the free-text row to submit">
61
+ <AgentQuestionCard
62
+ questionId="q-tokens"
63
+ questionNumber={2}
64
+ question="Which token should the selected row use?"
65
+ options={[
66
+ { id: "primary-soft", label: "primary-soft tint with a trailing check" },
67
+ { id: "surface-soft", label: "surface-soft tint with no marker" },
68
+ ]}
69
+ selectedOptionId={errorSelected}
70
+ freeTextValue={errorText}
71
+ onAnswerChange={(answer) => {
72
+ setErrorSelected(answer.optionId);
73
+ setErrorText(answer.text);
74
+ setShowError(false);
75
+ }}
76
+ errorMessage={showError ? "A written answer can’t be empty — keep typing." : undefined}
77
+ onSubmit={() => setShowError(true)}
78
+ />
79
+ </Section>
80
+
81
+ <Section title="Submitting — spinner, Sending…, controls disabled">
82
+ <AgentQuestionCard
83
+ questionId="q-done"
84
+ questionNumber={3}
85
+ question="Should I apply the change to every breakpoint?"
86
+ options={[
87
+ { id: "all", label: "Yes, every breakpoint" },
88
+ { id: "desktop", label: "Desktop only for now" },
89
+ ]}
90
+ defaultSelectedOptionId="all"
91
+ submitting
92
+ waitingCount={3}
93
+ onSubmit={() => undefined}
94
+ />
95
+ </Section>
96
+
97
+ <Section title="Collapsed — restore bar with the waiting count">
98
+ <AgentQuestionCard
99
+ questionId="q-collapsed"
100
+ question="Ready for the next question?"
101
+ options={[{ id: "yes", label: "Yes, keep going" }]}
102
+ collapsed
103
+ waitingCount={2}
104
+ onSubmit={() => undefined}
105
+ />
106
+ </Section>
107
+ </div>
108
+ );
109
+ }
@@ -2,7 +2,19 @@ import * as React from "react";
2
2
  import { Icon } from "../Icon";
3
3
  import type { IconProps } from "../Icon";
4
4
 
5
- export type BadgeTone = "neutral" | "primary" | "success" | "warning" | "error" | "info";
5
+ /**
6
+ * `on-primary` keeps a count legible when the badge sits on a solid primary
7
+ * fill (e.g. the active segment of a segmented control): it inverts to
8
+ * `on-primary` text over a translucent `on-primary` tint.
9
+ */
10
+ export type BadgeTone =
11
+ | "neutral"
12
+ | "primary"
13
+ | "success"
14
+ | "warning"
15
+ | "error"
16
+ | "info"
17
+ | "on-primary";
6
18
  export type BadgeSize = "sm" | "md" | "lg";
7
19
 
8
20
  export interface BadgeProps extends React.HTMLAttributes<HTMLSpanElement> {
@@ -19,6 +31,7 @@ const TONE: Record<BadgeTone, string> = {
19
31
  warning: "bg-semantic-warning-soft text-semantic-warning",
20
32
  error: "bg-semantic-error-soft text-semantic-error",
21
33
  info: "bg-semantic-info-soft text-semantic-info",
34
+ "on-primary": "bg-on-primary/20 text-on-primary",
22
35
  };
23
36
 
24
37
  const SIZE: Record<BadgeSize, string> = {