@designa8/vibedesign-v6 1.20.20 → 2.1.2
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 +1 -1
- package/dist/fonts/plusjakartasans/PlusJakartaSans-Italic[wght].ttf +0 -0
- package/dist/fonts/plusjakartasans/PlusJakartaSans[wght].ttf +0 -0
- package/dist/index.cjs +12027 -4942
- package/dist/index.js +12089 -5004
- package/dist/styles.css +1393 -97
- package/package.json +116 -1
- package/src/atoms/AgentQuestionCard/AgentQuestionCard.tsx +567 -0
- package/src/atoms/AgentQuestionCard/index.ts +6 -0
- package/src/atoms/AgentQuestionCard/preview.tsx +199 -0
- package/src/atoms/AppLayout/AppLayout.tsx +85 -22
- package/src/atoms/AppLayout/preview.tsx +4 -0
- package/src/atoms/AppSidebar/AppSidebar.tsx +224 -138
- package/src/atoms/AppSidebar/index.ts +1 -1
- package/src/atoms/AppSidebar/preview.tsx +61 -8
- package/src/atoms/AppSidebarMobile/AppSidebarMobile.tsx +242 -173
- package/src/atoms/AppSidebarMobile/preview.tsx +59 -89
- package/src/atoms/AuthLogin/AuthLogin.tsx +86 -49
- package/src/atoms/AuthLogin/preview.tsx +16 -0
- package/src/atoms/AuthSignUp/AuthSignUp.tsx +206 -126
- package/src/atoms/AuthSignUp/preview.tsx +10 -0
- package/src/atoms/BottomSheet/BottomSheet.tsx +199 -0
- package/src/atoms/BottomSheet/index.ts +2 -0
- package/src/atoms/BottomSheet/preview.tsx +50 -0
- package/src/atoms/Button/Button.tsx +19 -3
- package/src/atoms/Button/preview.tsx +2 -1
- package/src/atoms/ChatHistorySidebar/ChatHistorySidebar.tsx +160 -84
- package/src/atoms/ChatHistorySidebar/preview.tsx +81 -42
- package/src/atoms/ChatScreen/ChatScreen.tsx +298 -33
- package/src/atoms/ChatScreen/preview.tsx +54 -90
- package/src/atoms/Chip/Chip.tsx +81 -33
- package/src/atoms/Chip/preview.tsx +39 -21
- package/src/atoms/CodeEditor/CodeEditor.tsx +10 -4
- package/src/atoms/ComponentActionsSheet/ComponentActionsSheet.tsx +165 -0
- package/src/atoms/ComponentActionsSheet/index.ts +7 -0
- package/src/atoms/ComponentActionsSheet/preview.tsx +67 -0
- package/src/atoms/ComponentCard/ComponentCard.tsx +17 -35
- package/src/atoms/ComponentCard/preview.tsx +9 -9
- package/src/atoms/DesignSystemLoader/DesignSystemLoader.tsx +153 -0
- package/src/atoms/DesignSystemLoader/index.ts +2 -0
- package/src/atoms/DesignSystemLoader/preview.tsx +19 -0
- package/src/atoms/DesignSystemShowcase/DesignSystemShowcase.tsx +410 -0
- package/src/atoms/DesignSystemShowcase/index.ts +6 -0
- package/src/atoms/DesignSystemShowcase/preview.tsx +22 -0
- package/src/atoms/DesignTokensPanel/DesignTokensPanel.data.ts +254 -0
- package/src/atoms/DesignTokensPanel/DesignTokensPanel.tsx +946 -0
- package/src/atoms/DesignTokensPanel/index.ts +9 -0
- package/src/atoms/DesignTokensPanel/preview.tsx +39 -0
- package/src/atoms/ExpandableMessage/ExpandableMessage.tsx +239 -0
- package/src/atoms/ExpandableMessage/fix-link-note.txt +3 -0
- package/src/atoms/ExpandableMessage/index.ts +2 -0
- package/src/atoms/ExpandableMessage/markdown.tsx +310 -0
- package/src/atoms/ExpandableMessage/preview.tsx +83 -0
- package/src/atoms/ExportDesignMdModal/ExportDesignMdModal.tsx +6 -1
- package/src/atoms/FilterTabBar/FilterTabBar.tsx +2 -2
- package/src/atoms/FontCombobox/FontCombobox.tsx +655 -0
- package/src/atoms/FontCombobox/index.ts +6 -0
- package/src/atoms/FontCombobox/preview.tsx +111 -0
- package/src/atoms/HomePageTemplate/HomePageTemplate.tsx +894 -96
- package/src/atoms/HomePageTemplate/preview.tsx +4 -0
- package/src/atoms/Icon/Icon.tsx +17 -11
- package/src/atoms/Icon/icons.data.ts +34 -0
- package/src/atoms/Input/Input.tsx +37 -21
- package/src/atoms/LandingHero/LandingHero.tsx +545 -0
- package/src/atoms/LandingHero/index.ts +6 -0
- package/src/atoms/LandingHero/preview.tsx +88 -0
- package/src/atoms/MarketingFooter/MarketingFooter.tsx +215 -0
- package/src/atoms/MarketingFooter/index.ts +7 -0
- package/src/atoms/MarketingFooter/preview.tsx +28 -0
- package/src/atoms/MarketingNavbar/MarketingNavbar.tsx +451 -0
- package/src/atoms/MarketingNavbar/index.ts +7 -0
- package/src/atoms/MarketingNavbar/preview.tsx +109 -0
- package/src/atoms/Menu/Menu.tsx +1 -1
- package/src/atoms/MobileActionsDrawer/MobileActionsDrawer.tsx +548 -0
- package/src/atoms/MobileActionsDrawer/index.ts +9 -0
- package/src/atoms/MobileActionsDrawer/preview.tsx +109 -0
- package/src/atoms/Modal/Modal.tsx +77 -28
- package/src/atoms/PreviewDock/PreviewDock.tsx +119 -0
- package/src/atoms/PreviewDock/index.ts +2 -0
- package/src/atoms/PreviewDock/preview.tsx +30 -0
- package/src/atoms/PreviewToolbar/PreviewToolbar.tsx +47 -30
- package/src/atoms/PricingCard/PricingCard.tsx +15 -4
- package/src/atoms/PricingPageTemplate/PricingPageTemplate.tsx +109 -89
- package/src/atoms/ProjectSettingsModal/ProjectSettingsModal.tsx +314 -0
- package/src/atoms/ProjectSettingsModal/index.ts +2 -0
- package/src/atoms/ProjectSettingsModal/preview.tsx +130 -0
- package/src/atoms/ProjectSettingsModal/switch.snippet.txt +8 -0
- package/src/atoms/PromptInputBar/PromptInputBar.tsx +750 -302
- package/src/atoms/PromptInputBar/preview.tsx +64 -64
- package/src/atoms/SettingsPageTemplate/SettingsPageTemplate.tsx +272 -0
- package/src/atoms/SettingsPageTemplate/index.ts +2 -0
- package/src/atoms/SettingsPageTemplate/preview.tsx +29 -0
- package/src/atoms/SidebarUpgradeBanner/SidebarUpgradeBanner.tsx +178 -0
- package/src/atoms/SidebarUpgradeBanner/index.ts +2 -0
- package/src/atoms/SidebarUpgradeBanner/preview.tsx +47 -0
- package/src/atoms/SkeletonChip/SkeletonChip.tsx +198 -0
- package/src/atoms/SkeletonChip/index.ts +2 -0
- package/src/atoms/SkeletonChip/preview.tsx +44 -0
- package/src/atoms/TemplateHeader/TemplateHeader.tsx +129 -0
- package/src/atoms/TemplateHeader/index.ts +2 -0
- package/src/atoms/TemplateHeader/preview.tsx +39 -0
- package/src/atoms/TemplateHero/TemplateHero.tsx +286 -0
- package/src/atoms/TemplateHero/index.ts +2 -0
- package/src/atoms/TemplateHero/preview.tsx +32 -0
- package/src/atoms/TemplateSummary/TemplateSummary.tsx +85 -0
- package/src/atoms/TemplateSummary/index.ts +2 -0
- package/src/atoms/TemplateSummary/preview.tsx +10 -0
- package/src/atoms/Toast/Toast.tsx +178 -0
- package/src/atoms/Toast/index.ts +2 -0
- package/src/atoms/Toast/preview.tsx +100 -0
- package/src/atoms/TopNavbar/TopNavbar.tsx +145 -67
- package/src/atoms/TopNavbar/preview.tsx +13 -7
- package/src/atoms/TopupModal/TopupModal.tsx +94 -0
- package/src/atoms/TopupModal/index.ts +2 -0
- package/src/atoms/TopupModal/preview.tsx +22 -0
- package/src/atoms/UpgradeCard/UpgradeCard.tsx +124 -43
- package/src/atoms/UpgradeCard/index.ts +1 -1
- package/src/atoms/UpgradeCard/preview.tsx +7 -14
- package/src/atoms/UpgradeModal/UpgradeModal.tsx +192 -0
- package/src/atoms/UpgradeModal/index.ts +2 -0
- package/src/atoms/UpgradeModal/preview.tsx +41 -0
- package/src/index.ts +23 -0
- package/src/tokens.css +45 -7
- package/dist/fonts/inter/Inter-Italic[opsz,wght].ttf +0 -0
- package/dist/fonts/inter/Inter[opsz,wght].ttf +0 -0
|
@@ -0,0 +1,567 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { Icon } from "../Icon";
|
|
3
|
+
import { Input } from "../Input";
|
|
4
|
+
import { Modal } from "../Modal";
|
|
5
|
+
|
|
6
|
+
// ─── Types ────────────────────────────────────────────────────────────────────
|
|
7
|
+
|
|
8
|
+
export interface AgentQuestionOption {
|
|
9
|
+
/** Stable id returned on submit */
|
|
10
|
+
id: string;
|
|
11
|
+
/** Letter badge shown leading the row — falls back to A, B, C… by index */
|
|
12
|
+
letter?: string;
|
|
13
|
+
/** Option label */
|
|
14
|
+
label: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface AgentQuestionAnswer {
|
|
18
|
+
/** Id of the question that was answered */
|
|
19
|
+
questionId: string;
|
|
20
|
+
/** Id of the chosen option — the free-text option's id when text was typed */
|
|
21
|
+
optionId: string;
|
|
22
|
+
/** The typed free text, only present when the free-text option was used */
|
|
23
|
+
text?: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface AgentQuestionCardProps
|
|
27
|
+
extends Omit<React.HTMLAttributes<HTMLDivElement>, "onSubmit"> {
|
|
28
|
+
/** Stable id for this question, echoed back in the answer payload */
|
|
29
|
+
questionId: string;
|
|
30
|
+
/** The question the agent is asking */
|
|
31
|
+
question: string;
|
|
32
|
+
/** 1-based index shown before the question text — hidden when omitted */
|
|
33
|
+
questionNumber?: number;
|
|
34
|
+
/** Selectable options */
|
|
35
|
+
options: AgentQuestionOption[];
|
|
36
|
+
/**
|
|
37
|
+
* Optional reference image (e.g. a generated mockup) shown between the
|
|
38
|
+
* question text and the option list. Clicking it opens a large view.
|
|
39
|
+
*/
|
|
40
|
+
imageSrc?: string;
|
|
41
|
+
/** Alt text for the reference image. Default: "Reference image" */
|
|
42
|
+
imageAlt?: string;
|
|
43
|
+
/**
|
|
44
|
+
* Label for the free-text escape hatch appended after the options.
|
|
45
|
+
* Pass `null` to remove the free-text row entirely.
|
|
46
|
+
*/
|
|
47
|
+
freeTextLabel?: string | null;
|
|
48
|
+
/** Placeholder inside the free-text field */
|
|
49
|
+
freeTextPlaceholder?: string;
|
|
50
|
+
/** Eyebrow label in the header. Default: "Questions" */
|
|
51
|
+
label?: string;
|
|
52
|
+
/** Hint shown in the footer's start slot. Default: "Pick an option or write your own" */
|
|
53
|
+
hint?: string;
|
|
54
|
+
/** Label on the submit action. Default: "Send" */
|
|
55
|
+
sendLabel?: string;
|
|
56
|
+
/** Controlled selected option id */
|
|
57
|
+
selectedOptionId?: string | null;
|
|
58
|
+
/** Initial selected option id when uncontrolled */
|
|
59
|
+
defaultSelectedOptionId?: string | null;
|
|
60
|
+
/** Controlled free-text value */
|
|
61
|
+
freeTextValue?: string;
|
|
62
|
+
/** Initial free-text value when uncontrolled */
|
|
63
|
+
defaultFreeTextValue?: string;
|
|
64
|
+
/** Called whenever the selection or free text changes */
|
|
65
|
+
onAnswerChange?: (answer: { optionId: string | null; text: string }) => void;
|
|
66
|
+
/** Called with the composed answer when the send action fires */
|
|
67
|
+
onSubmit?: (answer: AgentQuestionAnswer) => void;
|
|
68
|
+
/** Called when the card is collapsed with the close (X) action */
|
|
69
|
+
onClose?: () => void;
|
|
70
|
+
/** Called when the collapsed restore bar's action reopens the card */
|
|
71
|
+
onReopen?: () => void;
|
|
72
|
+
/** Render the card collapsed as the slim restore bar. Omit to let it manage itself. */
|
|
73
|
+
collapsed?: boolean;
|
|
74
|
+
/** Initial collapsed state when uncontrolled. Default: false */
|
|
75
|
+
defaultCollapsed?: boolean;
|
|
76
|
+
/** Called whenever the card collapses or reopens */
|
|
77
|
+
onCollapsedChange?: (collapsed: boolean) => void;
|
|
78
|
+
/** Submitting in progress — disables every control and swaps the label for a spinner */
|
|
79
|
+
submitting?: boolean;
|
|
80
|
+
/** Validation / submit error message shown under the options */
|
|
81
|
+
errorMessage?: string;
|
|
82
|
+
/** Number of questions still waiting — shown on the restore bar. Default: 1 */
|
|
83
|
+
waitingCount?: number;
|
|
84
|
+
/** Label of the restore bar's action. Default: "Answer" */
|
|
85
|
+
reopenLabel?: string;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// ─── Constants / helpers ──────────────────────────────────────────────────────
|
|
89
|
+
|
|
90
|
+
/** Sentinel option id for the free-text answer. */
|
|
91
|
+
export const AGENT_QUESTION_FREE_TEXT_ID = "__other_free_text__";
|
|
92
|
+
|
|
93
|
+
const letterFor = (option: AgentQuestionOption, index: number): string =>
|
|
94
|
+
option.letter ?? String.fromCharCode(65 + (index % 26));
|
|
95
|
+
|
|
96
|
+
const letterBadgeClasses = (selected: boolean): string =>
|
|
97
|
+
[
|
|
98
|
+
"flex size-6 flex-shrink-0 items-center justify-center rounded-xs border text-caption",
|
|
99
|
+
"transition-colors duration-150 ease-out",
|
|
100
|
+
selected
|
|
101
|
+
? "border-primary bg-primary text-on-primary"
|
|
102
|
+
: "border-hairline-strong bg-canvas text-muted group-hover:border-primary group-hover:text-primary",
|
|
103
|
+
].join(" ");
|
|
104
|
+
|
|
105
|
+
// ─── Restore bar ──────────────────────────────────────────────────────────────
|
|
106
|
+
|
|
107
|
+
const RestoreBar: React.FC<{
|
|
108
|
+
waitingCount: number;
|
|
109
|
+
reopenLabel: string;
|
|
110
|
+
onReopen: () => void;
|
|
111
|
+
}> = ({ waitingCount, reopenLabel, onReopen }) => (
|
|
112
|
+
<div className="flex w-full items-center gap-md rounded-xl border border-hairline bg-surface px-md py-sm shadow-card">
|
|
113
|
+
<span className="flex size-6 flex-shrink-0 items-center justify-center rounded-full bg-primary text-on-primary">
|
|
114
|
+
<Icon name="help-question-circle" size={14} />
|
|
115
|
+
</span>
|
|
116
|
+
<span className="min-w-0 flex-1 truncate text-body-sm text-ink">
|
|
117
|
+
{waitingCount === 1 ? "1 question waiting" : `${waitingCount} questions waiting`}
|
|
118
|
+
</span>
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
onClick={onReopen}
|
|
122
|
+
className="cursor-pointer rounded-xs px-xs py-xxs text-body-sm text-primary-text underline-offset-2 transition duration-150 ease-out hover:text-primary-active hover:underline active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue"
|
|
123
|
+
>
|
|
124
|
+
{reopenLabel}
|
|
125
|
+
</button>
|
|
126
|
+
</div>
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
// ─── Component ────────────────────────────────────────────────────────────────
|
|
130
|
+
|
|
131
|
+
export const AgentQuestionCard = React.forwardRef<HTMLDivElement, AgentQuestionCardProps>(
|
|
132
|
+
(
|
|
133
|
+
{
|
|
134
|
+
questionId,
|
|
135
|
+
question,
|
|
136
|
+
questionNumber,
|
|
137
|
+
options,
|
|
138
|
+
imageSrc,
|
|
139
|
+
imageAlt = "Reference image",
|
|
140
|
+
freeTextLabel = "Other…",
|
|
141
|
+
freeTextPlaceholder = "Type your answer",
|
|
142
|
+
label = "Questions",
|
|
143
|
+
hint = "Pick an option or write your own",
|
|
144
|
+
sendLabel = "Send",
|
|
145
|
+
selectedOptionId: selectedProp,
|
|
146
|
+
defaultSelectedOptionId = null,
|
|
147
|
+
freeTextValue: freeTextProp,
|
|
148
|
+
defaultFreeTextValue = "",
|
|
149
|
+
onAnswerChange,
|
|
150
|
+
onSubmit,
|
|
151
|
+
onClose,
|
|
152
|
+
onReopen,
|
|
153
|
+
collapsed: collapsedProp,
|
|
154
|
+
defaultCollapsed = false,
|
|
155
|
+
onCollapsedChange,
|
|
156
|
+
submitting = false,
|
|
157
|
+
errorMessage,
|
|
158
|
+
waitingCount = 1,
|
|
159
|
+
reopenLabel = "Answer",
|
|
160
|
+
className,
|
|
161
|
+
...rest
|
|
162
|
+
},
|
|
163
|
+
ref,
|
|
164
|
+
) => {
|
|
165
|
+
const reactId = React.useId();
|
|
166
|
+
const questionTextId = `aqc-question-${reactId}`;
|
|
167
|
+
const hintId = `aqc-hint-${reactId}`;
|
|
168
|
+
const freeTextInputId = `aqc-free-text-${reactId}`;
|
|
169
|
+
|
|
170
|
+
// ── selection + free text ──────────────────────────────────────────────
|
|
171
|
+
const isSelectionControlled = selectedProp !== undefined;
|
|
172
|
+
const [internalSelection, setInternalSelection] = React.useState<string | null>(
|
|
173
|
+
defaultSelectedOptionId,
|
|
174
|
+
);
|
|
175
|
+
const selected = isSelectionControlled ? selectedProp ?? null : internalSelection;
|
|
176
|
+
|
|
177
|
+
const isTextControlled = freeTextProp !== undefined;
|
|
178
|
+
const [internalText, setInternalText] = React.useState(defaultFreeTextValue);
|
|
179
|
+
const text = isTextControlled ? freeTextProp : internalText;
|
|
180
|
+
|
|
181
|
+
const [localError, setLocalError] = React.useState<string | null>(null);
|
|
182
|
+
|
|
183
|
+
const setSelection = (next: string | null) => {
|
|
184
|
+
if (!isSelectionControlled) setInternalSelection(next);
|
|
185
|
+
setLocalError(null);
|
|
186
|
+
onAnswerChange?.({ optionId: next, text });
|
|
187
|
+
};
|
|
188
|
+
|
|
189
|
+
const setText = (next: string) => {
|
|
190
|
+
if (!isTextControlled) setInternalText(next);
|
|
191
|
+
setLocalError(null);
|
|
192
|
+
onAnswerChange?.({ optionId: selected, text: next });
|
|
193
|
+
};
|
|
194
|
+
|
|
195
|
+
// ── image viewer ───────────────────────────────────────────────────────
|
|
196
|
+
const [imageOpen, setImageOpen] = React.useState(false);
|
|
197
|
+
|
|
198
|
+
// ── collapsed ──────────────────────────────────────────────────────────
|
|
199
|
+
const isCollapsedControlled = collapsedProp !== undefined;
|
|
200
|
+
const [internalCollapsed, setInternalCollapsed] = React.useState(defaultCollapsed);
|
|
201
|
+
const collapsed = isCollapsedControlled ? collapsedProp : internalCollapsed;
|
|
202
|
+
|
|
203
|
+
const collapse = (next: boolean) => {
|
|
204
|
+
if (!isCollapsedControlled) setInternalCollapsed(next);
|
|
205
|
+
onCollapsedChange?.(next);
|
|
206
|
+
if (next) onClose?.();
|
|
207
|
+
else onReopen?.();
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
// ── derived ────────────────────────────────────────────────────────────
|
|
211
|
+
const hasFreeText = freeTextLabel !== null;
|
|
212
|
+
const freeTextSelected = hasFreeText && selected === AGENT_QUESTION_FREE_TEXT_ID;
|
|
213
|
+
const answeredFreeText = text.trim().length > 0;
|
|
214
|
+
const canSend =
|
|
215
|
+
!submitting && selected !== null && (!freeTextSelected || answeredFreeText);
|
|
216
|
+
const shownError = errorMessage ?? localError;
|
|
217
|
+
|
|
218
|
+
const optionIds: string[] = [
|
|
219
|
+
...options.map((o) => o.id),
|
|
220
|
+
...(hasFreeText ? [AGENT_QUESTION_FREE_TEXT_ID] : []),
|
|
221
|
+
];
|
|
222
|
+
|
|
223
|
+
const handleSubmit = () => {
|
|
224
|
+
if (!canSend || selected === null) return;
|
|
225
|
+
onSubmit?.({
|
|
226
|
+
questionId,
|
|
227
|
+
optionId: selected,
|
|
228
|
+
text: freeTextSelected ? text.trim() : undefined,
|
|
229
|
+
});
|
|
230
|
+
};
|
|
231
|
+
|
|
232
|
+
// ── keyboard: arrow keys move + select within the radio group ──────────
|
|
233
|
+
const rowRefs = React.useRef<Array<HTMLButtonElement | null>>([]);
|
|
234
|
+
|
|
235
|
+
const moveTo = (index: number) => {
|
|
236
|
+
const count = optionIds.length;
|
|
237
|
+
const wrapped = ((index % count) + count) % count;
|
|
238
|
+
rowRefs.current[wrapped]?.focus();
|
|
239
|
+
setSelection(optionIds[wrapped]);
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
const handleRadioKeyDown =
|
|
243
|
+
(index: number) => (event: React.KeyboardEvent<HTMLButtonElement>) => {
|
|
244
|
+
if (event.key === "ArrowDown" || event.key === "ArrowRight") {
|
|
245
|
+
event.preventDefault();
|
|
246
|
+
moveTo(index + 1);
|
|
247
|
+
} else if (event.key === "ArrowUp" || event.key === "ArrowLeft") {
|
|
248
|
+
event.preventDefault();
|
|
249
|
+
moveTo(index - 1);
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
|
|
253
|
+
const handleCardKeyDown = (event: React.KeyboardEvent<HTMLDivElement>) => {
|
|
254
|
+
if (event.key !== "Escape") return;
|
|
255
|
+
// While the reference image is open, Escape belongs to the viewer only —
|
|
256
|
+
// it must not also collapse the card.
|
|
257
|
+
if (imageOpen) return;
|
|
258
|
+
if (!collapsed) {
|
|
259
|
+
event.stopPropagation();
|
|
260
|
+
collapse(true);
|
|
261
|
+
}
|
|
262
|
+
};
|
|
263
|
+
|
|
264
|
+
// ── card ───────────────────────────────────────────────────────────────
|
|
265
|
+
const card = (
|
|
266
|
+
<div
|
|
267
|
+
role="group"
|
|
268
|
+
aria-labelledby={questionTextId}
|
|
269
|
+
aria-describedby={hintId}
|
|
270
|
+
aria-busy={submitting ? "true" : undefined}
|
|
271
|
+
onKeyDown={handleCardKeyDown}
|
|
272
|
+
className="w-full rounded-xl border border-hairline bg-surface p-lg shadow-card"
|
|
273
|
+
>
|
|
274
|
+
{/* Header */}
|
|
275
|
+
<div className="mb-md flex items-center gap-sm">
|
|
276
|
+
<span className="flex flex-shrink-0 items-center justify-center text-muted">
|
|
277
|
+
<Icon name="help-question-circle" size={16} />
|
|
278
|
+
</span>
|
|
279
|
+
<span className="min-w-0 flex-1 truncate text-body-sm text-muted">{label}</span>
|
|
280
|
+
<button
|
|
281
|
+
type="button"
|
|
282
|
+
onClick={() => collapse(true)}
|
|
283
|
+
disabled={submitting}
|
|
284
|
+
aria-label="Close question"
|
|
285
|
+
className="flex size-8 flex-shrink-0 cursor-pointer items-center justify-center rounded-xs text-muted-soft transition duration-150 ease-out hover:bg-surface-soft hover:text-ink active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue disabled:cursor-not-allowed disabled:opacity-[var(--opacity-disabled)]"
|
|
286
|
+
>
|
|
287
|
+
<Icon name="close" size={16} />
|
|
288
|
+
</button>
|
|
289
|
+
</div>
|
|
290
|
+
|
|
291
|
+
{/* Question */}
|
|
292
|
+
<div className="mb-md flex items-baseline gap-sm">
|
|
293
|
+
{questionNumber !== undefined && (
|
|
294
|
+
<span className="flex-shrink-0 text-body-md text-muted">{questionNumber}.</span>
|
|
295
|
+
)}
|
|
296
|
+
<span id={questionTextId} className="min-w-0 flex-1 text-body-md text-ink">
|
|
297
|
+
{question}
|
|
298
|
+
</span>
|
|
299
|
+
</div>
|
|
300
|
+
|
|
301
|
+
{/* Reference image — thumbnail only; answers stay below it */}
|
|
302
|
+
{imageSrc && (
|
|
303
|
+
<div className="mb-md">
|
|
304
|
+
<button
|
|
305
|
+
type="button"
|
|
306
|
+
onClick={() => setImageOpen(true)}
|
|
307
|
+
aria-label={`View ${imageAlt}`}
|
|
308
|
+
aria-haspopup="dialog"
|
|
309
|
+
className="w-full cursor-pointer overflow-hidden rounded-lg border border-hairline bg-surface-soft transition duration-150 ease-out hover:border-hairline-strong active:scale-[0.98] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue"
|
|
310
|
+
>
|
|
311
|
+
<img
|
|
312
|
+
src={imageSrc}
|
|
313
|
+
alt={imageAlt}
|
|
314
|
+
className="max-h-44 w-full object-contain object-center"
|
|
315
|
+
/>
|
|
316
|
+
</button>
|
|
317
|
+
</div>
|
|
318
|
+
)}
|
|
319
|
+
|
|
320
|
+
{/* Options */}
|
|
321
|
+
<div role="radiogroup" aria-labelledby={questionTextId} className="flex flex-col gap-xs">
|
|
322
|
+
{options.map((option, index) => {
|
|
323
|
+
const isSelected = selected === option.id;
|
|
324
|
+
return (
|
|
325
|
+
<div
|
|
326
|
+
key={option.id}
|
|
327
|
+
className={[
|
|
328
|
+
"flex w-full items-center gap-md rounded-md px-sm py-sm transition-colors duration-150 ease-out",
|
|
329
|
+
isSelected ? "bg-primary-soft" : "",
|
|
330
|
+
]
|
|
331
|
+
.filter(Boolean)
|
|
332
|
+
.join(" ")}
|
|
333
|
+
>
|
|
334
|
+
<button
|
|
335
|
+
ref={(node) => {
|
|
336
|
+
rowRefs.current[index] = node;
|
|
337
|
+
}}
|
|
338
|
+
type="button"
|
|
339
|
+
role="radio"
|
|
340
|
+
aria-checked={isSelected}
|
|
341
|
+
aria-label={option.label}
|
|
342
|
+
disabled={submitting}
|
|
343
|
+
onClick={() => setSelection(option.id)}
|
|
344
|
+
onKeyDown={handleRadioKeyDown(index)}
|
|
345
|
+
className={[
|
|
346
|
+
"group flex min-w-0 flex-1 cursor-pointer items-center gap-md rounded-sm text-left",
|
|
347
|
+
"transition duration-150 ease-out active:scale-[0.99]",
|
|
348
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue",
|
|
349
|
+
"disabled:cursor-not-allowed disabled:opacity-[var(--opacity-disabled)]",
|
|
350
|
+
].join(" ")}
|
|
351
|
+
>
|
|
352
|
+
<span aria-hidden="true" className={letterBadgeClasses(isSelected)}>
|
|
353
|
+
{letterFor(option, index)}
|
|
354
|
+
</span>
|
|
355
|
+
<span className="min-w-0 flex-1 text-body-md text-ink">{option.label}</span>
|
|
356
|
+
</button>
|
|
357
|
+
|
|
358
|
+
{isSelected && (
|
|
359
|
+
<span
|
|
360
|
+
aria-hidden="true"
|
|
361
|
+
className="flex flex-shrink-0 items-center pr-xs text-primary"
|
|
362
|
+
>
|
|
363
|
+
<Icon name="check-checkmark" size={14} />
|
|
364
|
+
</span>
|
|
365
|
+
)}
|
|
366
|
+
</div>
|
|
367
|
+
);
|
|
368
|
+
})}
|
|
369
|
+
|
|
370
|
+
{hasFreeText && (
|
|
371
|
+
<div
|
|
372
|
+
className={[
|
|
373
|
+
"flex w-full items-center gap-md rounded-md border px-sm py-sm transition-colors duration-150 ease-out",
|
|
374
|
+
shownError && freeTextSelected
|
|
375
|
+
? "border-semantic-error"
|
|
376
|
+
: freeTextSelected
|
|
377
|
+
? "border-transparent bg-primary-soft"
|
|
378
|
+
: "border-transparent",
|
|
379
|
+
].join(" ")}
|
|
380
|
+
>
|
|
381
|
+
<button
|
|
382
|
+
ref={(node) => {
|
|
383
|
+
rowRefs.current[options.length] = node;
|
|
384
|
+
}}
|
|
385
|
+
type="button"
|
|
386
|
+
role="radio"
|
|
387
|
+
aria-checked={freeTextSelected}
|
|
388
|
+
aria-label={freeTextLabel}
|
|
389
|
+
disabled={submitting}
|
|
390
|
+
onClick={() => {
|
|
391
|
+
setSelection(AGENT_QUESTION_FREE_TEXT_ID);
|
|
392
|
+
requestAnimationFrame(() => {
|
|
393
|
+
document.getElementById(freeTextInputId)?.focus();
|
|
394
|
+
});
|
|
395
|
+
}}
|
|
396
|
+
onKeyDown={handleRadioKeyDown(options.length)}
|
|
397
|
+
className={[
|
|
398
|
+
"group flex min-w-0 cursor-pointer items-center gap-md rounded-sm text-left",
|
|
399
|
+
freeTextSelected ? "" : "flex-1",
|
|
400
|
+
"transition duration-150 ease-out active:scale-[0.99]",
|
|
401
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue",
|
|
402
|
+
"disabled:cursor-not-allowed disabled:opacity-[var(--opacity-disabled)]",
|
|
403
|
+
].join(" ")}
|
|
404
|
+
>
|
|
405
|
+
<span
|
|
406
|
+
aria-hidden="true"
|
|
407
|
+
className={letterBadgeClasses(freeTextSelected)}
|
|
408
|
+
>
|
|
409
|
+
{letterFor(
|
|
410
|
+
{ id: AGENT_QUESTION_FREE_TEXT_ID, label: freeTextLabel },
|
|
411
|
+
options.length,
|
|
412
|
+
)}
|
|
413
|
+
</span>
|
|
414
|
+
{!freeTextSelected && (
|
|
415
|
+
<span className="min-w-0 flex-1 text-body-md text-muted">{freeTextLabel}</span>
|
|
416
|
+
)}
|
|
417
|
+
</button>
|
|
418
|
+
|
|
419
|
+
{freeTextSelected && (
|
|
420
|
+
<div className="min-w-0 flex-1">
|
|
421
|
+
<Input
|
|
422
|
+
id={freeTextInputId}
|
|
423
|
+
unstyled
|
|
424
|
+
fullWidth
|
|
425
|
+
value={text}
|
|
426
|
+
onChange={(event) => setText(event.target.value)}
|
|
427
|
+
onKeyDown={(event) => {
|
|
428
|
+
if (event.key === "Enter") {
|
|
429
|
+
event.preventDefault();
|
|
430
|
+
handleSubmit();
|
|
431
|
+
}
|
|
432
|
+
}}
|
|
433
|
+
placeholder={freeTextPlaceholder}
|
|
434
|
+
aria-label="Your answer"
|
|
435
|
+
disabled={submitting}
|
|
436
|
+
className="text-body-md text-ink placeholder:text-muted-soft"
|
|
437
|
+
/>
|
|
438
|
+
</div>
|
|
439
|
+
)}
|
|
440
|
+
|
|
441
|
+
{freeTextSelected && (
|
|
442
|
+
<span
|
|
443
|
+
aria-hidden="true"
|
|
444
|
+
className="flex flex-shrink-0 items-center pr-xs text-primary"
|
|
445
|
+
>
|
|
446
|
+
<Icon name="check-checkmark" size={14} />
|
|
447
|
+
</span>
|
|
448
|
+
)}
|
|
449
|
+
</div>
|
|
450
|
+
)}
|
|
451
|
+
</div>
|
|
452
|
+
|
|
453
|
+
{/* Announcement + error */}
|
|
454
|
+
<div role="status" aria-live="polite">
|
|
455
|
+
{shownError && (
|
|
456
|
+
<p className="mt-xs text-caption text-semantic-error">{shownError}</p>
|
|
457
|
+
)}
|
|
458
|
+
</div>
|
|
459
|
+
|
|
460
|
+
{/* Footer */}
|
|
461
|
+
<div className="mt-md flex items-center justify-between gap-md border-t border-hairline-soft pt-md">
|
|
462
|
+
<span id={hintId} className="min-w-0 flex-1 text-caption text-muted">
|
|
463
|
+
{hint}
|
|
464
|
+
</span>
|
|
465
|
+
<button
|
|
466
|
+
type="button"
|
|
467
|
+
onClick={handleSubmit}
|
|
468
|
+
disabled={!canSend}
|
|
469
|
+
className={[
|
|
470
|
+
"inline-flex flex-shrink-0 items-center gap-sm rounded-xl px-lg py-sm text-body-md",
|
|
471
|
+
"transition duration-150 ease-out",
|
|
472
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-focus-blue",
|
|
473
|
+
canSend
|
|
474
|
+
? "cursor-pointer bg-primary text-on-primary hover:bg-primary-hover active:scale-[0.98]"
|
|
475
|
+
: "cursor-not-allowed bg-primary-disabled text-on-primary",
|
|
476
|
+
].join(" ")}
|
|
477
|
+
>
|
|
478
|
+
{submitting ? (
|
|
479
|
+
<>
|
|
480
|
+
<Icon name="loading-spinner" size={16} className="animate-spin" />
|
|
481
|
+
<span>Sending…</span>
|
|
482
|
+
</>
|
|
483
|
+
) : (
|
|
484
|
+
<>
|
|
485
|
+
<span>{sendLabel}</span>
|
|
486
|
+
<Icon name="arrow-up-send" size={16} />
|
|
487
|
+
</>
|
|
488
|
+
)}
|
|
489
|
+
</button>
|
|
490
|
+
</div>
|
|
491
|
+
</div>
|
|
492
|
+
);
|
|
493
|
+
|
|
494
|
+
return (
|
|
495
|
+
<div
|
|
496
|
+
ref={ref}
|
|
497
|
+
data-state={collapsed ? "closed" : "open"}
|
|
498
|
+
className={["w-full", className].filter(Boolean).join(" ")}
|
|
499
|
+
{...rest}
|
|
500
|
+
>
|
|
501
|
+
{/* Card — stays mounted; the grid row collapses so no gap is left behind */}
|
|
502
|
+
<div
|
|
503
|
+
data-state={collapsed ? "closed" : "open"}
|
|
504
|
+
className={[
|
|
505
|
+
"grid grid-rows-[1fr] transition-[grid-template-rows] duration-200 ease-out",
|
|
506
|
+
"data-[state=closed]:grid-rows-[0fr]",
|
|
507
|
+
].join(" ")}
|
|
508
|
+
>
|
|
509
|
+
<div
|
|
510
|
+
data-state={collapsed ? "closed" : "open"}
|
|
511
|
+
className={[
|
|
512
|
+
"min-h-0 origin-bottom transition duration-200 ease-out",
|
|
513
|
+
"data-[state=open]:translate-y-0 data-[state=open]:opacity-100",
|
|
514
|
+
"data-[state=closed]:overflow-hidden data-[state=closed]:pointer-events-none",
|
|
515
|
+
"data-[state=closed]:translate-y-2 data-[state=closed]:opacity-0",
|
|
516
|
+
].join(" ")}
|
|
517
|
+
>
|
|
518
|
+
{card}
|
|
519
|
+
</div>
|
|
520
|
+
</div>
|
|
521
|
+
|
|
522
|
+
{/* Restore bar — takes the card's place once collapsed */}
|
|
523
|
+
<div
|
|
524
|
+
data-state={collapsed ? "open" : "closed"}
|
|
525
|
+
className={[
|
|
526
|
+
"grid grid-rows-[0fr] transition-[grid-template-rows] duration-200 ease-out",
|
|
527
|
+
"data-[state=open]:grid-rows-[1fr]",
|
|
528
|
+
].join(" ")}
|
|
529
|
+
>
|
|
530
|
+
<div
|
|
531
|
+
data-state={collapsed ? "open" : "closed"}
|
|
532
|
+
className={[
|
|
533
|
+
"min-h-0 origin-bottom transition duration-200 ease-out",
|
|
534
|
+
"data-[state=open]:translate-y-0 data-[state=open]:opacity-100",
|
|
535
|
+
"data-[state=closed]:overflow-hidden data-[state=closed]:pointer-events-none",
|
|
536
|
+
"data-[state=closed]:-translate-y-1 data-[state=closed]:opacity-0",
|
|
537
|
+
].join(" ")}
|
|
538
|
+
>
|
|
539
|
+
<RestoreBar
|
|
540
|
+
waitingCount={waitingCount}
|
|
541
|
+
reopenLabel={reopenLabel}
|
|
542
|
+
onReopen={() => collapse(false)}
|
|
543
|
+
/>
|
|
544
|
+
</div>
|
|
545
|
+
</div>
|
|
546
|
+
|
|
547
|
+
{/* Reference image viewer — viewing only, never answers or collapses */}
|
|
548
|
+
{imageSrc && (
|
|
549
|
+
<Modal
|
|
550
|
+
isOpen={imageOpen}
|
|
551
|
+
onClose={() => setImageOpen(false)}
|
|
552
|
+
title="Reference image"
|
|
553
|
+
size="full"
|
|
554
|
+
>
|
|
555
|
+
<img
|
|
556
|
+
src={imageSrc}
|
|
557
|
+
alt={imageAlt}
|
|
558
|
+
className="h-full w-full object-contain object-center"
|
|
559
|
+
/>
|
|
560
|
+
</Modal>
|
|
561
|
+
)}
|
|
562
|
+
</div>
|
|
563
|
+
);
|
|
564
|
+
},
|
|
565
|
+
);
|
|
566
|
+
|
|
567
|
+
AgentQuestionCard.displayName = "AgentQuestionCard";
|