@widgetic/design-system 0.5.40 → 0.5.41

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.
Files changed (139) hide show
  1. package/README.md +73 -0
  2. package/dist/components/ContentRefreshOverlay.svelte +103 -0
  3. package/dist/components/ContentRefreshOverlay.svelte.d.ts +18 -0
  4. package/dist/components/chat/Composer.svelte +380 -19
  5. package/dist/components/chat/Composer.svelte.d.ts +88 -1
  6. package/dist/components/chat/PlanCard.svelte +218 -88
  7. package/dist/components/chat/PlanCard.svelte.d.ts +11 -0
  8. package/dist/components/chat/QuestionCard.svelte +180 -70
  9. package/dist/components/chat/QuestionCard.svelte.d.ts +28 -2
  10. package/dist/components/chat/QuestionCardSummary.svelte +96 -0
  11. package/dist/components/chat/QuestionCardSummary.svelte.d.ts +20 -0
  12. package/dist/components/chat/QueueCard.svelte +185 -0
  13. package/dist/components/chat/QueueCard.svelte.d.ts +40 -0
  14. package/dist/components/chat/composerLogic.d.ts +31 -0
  15. package/dist/components/chat/composerLogic.js +37 -0
  16. package/dist/components/chat/composerReferences.d.ts +28 -0
  17. package/dist/components/chat/composerReferences.js +23 -0
  18. package/dist/components/chat/index.d.ts +8 -3
  19. package/dist/components/chat/index.js +10 -2
  20. package/dist/components/chat/questionCardLogic.d.ts +40 -3
  21. package/dist/components/chat/questionCardLogic.js +54 -3
  22. package/dist/components/chat/queueCardLogic.d.ts +7 -0
  23. package/dist/components/chat/queueCardLogic.js +5 -0
  24. package/dist/components/creator/index.d.ts +1 -2
  25. package/dist/components/creator/index.js +2 -0
  26. package/dist/components/index.d.ts +8 -7
  27. package/dist/components/index.js +8 -6
  28. package/dist/components/modals/BaseModal.svelte +14 -4
  29. package/dist/components/navigation/breadcrumbSlideIn.d.ts +6 -2
  30. package/dist/components/navigation/breadcrumbSlideIn.js +6 -6
  31. package/dist/components/search-input/SearchInput.svelte +282 -14
  32. package/dist/components/search-input/SearchInput.svelte.d.ts +3 -0
  33. package/dist/components/search-input/index.d.ts +1 -0
  34. package/dist/components/search-input/index.js +1 -0
  35. package/dist/components/search-input/index2.d.ts +4 -0
  36. package/dist/components/search-input/recentSearches.d.ts +12 -0
  37. package/dist/components/search-input/recentSearches.js +124 -0
  38. package/dist/components/toast/ToasterModal.svelte +8 -3
  39. package/dist/components/toast/ToasterModal.svelte.d.ts +2 -0
  40. package/dist/components/ui/chip/chip.svelte +39 -1
  41. package/dist/components/ui/chip/chip.svelte.d.ts +8 -0
  42. package/dist/components/ui/chip/chipProgress.d.ts +14 -0
  43. package/dist/components/ui/chip/chipProgress.js +21 -0
  44. package/dist/components/ui/icon-button/icon-button.svelte +2 -0
  45. package/dist/components/ui/icon-button/icon-button.svelte.d.ts +5 -0
  46. package/dist/components/ui/number-controls/index.d.ts +2 -0
  47. package/dist/components/ui/number-controls/index.js +2 -0
  48. package/dist/components/ui/number-controls/number-controls.svelte +530 -0
  49. package/dist/components/ui/number-controls/number-controls.svelte.d.ts +46 -0
  50. package/dist/components/ui/number-controls/numberControlsSteps.d.ts +17 -0
  51. package/dist/components/ui/number-controls/numberControlsSteps.js +23 -0
  52. package/dist/components/ui/number-controls/numberControlsValueArea.d.ts +29 -0
  53. package/dist/components/ui/number-controls/numberControlsValueArea.js +51 -0
  54. package/dist/components/ui/text-flip/index.d.ts +1 -0
  55. package/dist/components/ui/text-flip/index.js +1 -0
  56. package/dist/components/ui/text-flip/text-flip.svelte +103 -0
  57. package/dist/components/ui/text-flip/text-flip.svelte.d.ts +15 -0
  58. package/dist/components/ui/text-flip/textFlipLogic.d.ts +49 -0
  59. package/dist/components/ui/text-flip/textFlipLogic.js +151 -0
  60. package/dist/inline-completion/completionAnswer.d.ts +11 -0
  61. package/dist/inline-completion/completionAnswer.js +49 -0
  62. package/dist/inline-completion/completionCache.d.ts +24 -0
  63. package/dist/inline-completion/completionCache.js +47 -0
  64. package/dist/inline-completion/completionController.d.ts +61 -0
  65. package/dist/inline-completion/completionController.js +280 -0
  66. package/dist/inline-completion/completionKeys.d.ts +21 -0
  67. package/dist/inline-completion/completionKeys.js +19 -0
  68. package/dist/inline-completion/completionText.d.ts +53 -0
  69. package/dist/inline-completion/completionText.js +79 -0
  70. package/dist/inline-completion/completionTypes.d.ts +71 -0
  71. package/dist/inline-completion/completionTypes.js +5 -0
  72. package/dist/inline-completion/gatewayCompletion.d.ts +37 -0
  73. package/dist/inline-completion/gatewayCompletion.js +77 -0
  74. package/dist/inline-completion/ghostTap.d.ts +19 -0
  75. package/dist/inline-completion/ghostTap.js +20 -0
  76. package/dist/inline-completion/hintMemory.d.ts +43 -0
  77. package/dist/inline-completion/hintMemory.js +90 -0
  78. package/dist/inline-completion/httpSource.d.ts +40 -0
  79. package/dist/inline-completion/httpSource.js +149 -0
  80. package/dist/inline-completion/index.d.ts +30 -0
  81. package/dist/inline-completion/index.js +20 -0
  82. package/dist/inline-completion/inlineCompletionAction.d.ts +54 -0
  83. package/dist/inline-completion/inlineCompletionAction.js +310 -0
  84. package/dist/inline-completion/outcomeReporter.d.ts +49 -0
  85. package/dist/inline-completion/outcomeReporter.js +139 -0
  86. package/dist/inline-completion/promiseLike.d.ts +9 -0
  87. package/dist/inline-completion/promiseLike.js +9 -0
  88. package/dist/prompt-references/ReferenceMenu.svelte +344 -0
  89. package/dist/prompt-references/ReferenceMenu.svelte.d.ts +26 -0
  90. package/dist/prompt-references/index.d.ts +27 -0
  91. package/dist/prompt-references/index.js +20 -0
  92. package/dist/prompt-references/neutralizingSource.d.ts +21 -0
  93. package/dist/prompt-references/neutralizingSource.js +29 -0
  94. package/dist/prompt-references/promptReferences.d.ts +28 -0
  95. package/dist/prompt-references/promptReferences.js +766 -0
  96. package/dist/prompt-references/referenceBadge.d.ts +61 -0
  97. package/dist/prompt-references/referenceBadge.js +82 -0
  98. package/dist/prompt-references/referenceBadgePainter.d.ts +31 -0
  99. package/dist/prompt-references/referenceBadgePainter.js +106 -0
  100. package/dist/prompt-references/referenceEditing.d.ts +60 -0
  101. package/dist/prompt-references/referenceEditing.js +135 -0
  102. package/dist/prompt-references/referenceLabels.d.ts +56 -0
  103. package/dist/prompt-references/referenceLabels.js +215 -0
  104. package/dist/prompt-references/referenceMeasure.d.ts +12 -0
  105. package/dist/prompt-references/referenceMeasure.js +63 -0
  106. package/dist/prompt-references/referenceMenuHost.svelte.d.ts +29 -0
  107. package/dist/prompt-references/referenceMenuHost.svelte.js +43 -0
  108. package/dist/prompt-references/referenceMenuKeys.d.ts +26 -0
  109. package/dist/prompt-references/referenceMenuKeys.js +49 -0
  110. package/dist/prompt-references/referenceMenuPlacement.d.ts +63 -0
  111. package/dist/prompt-references/referenceMenuPlacement.js +66 -0
  112. package/dist/prompt-references/referenceTokens.d.ts +175 -0
  113. package/dist/prompt-references/referenceTokens.js +332 -0
  114. package/dist/prompt-references/referenceTrigger.d.ts +52 -0
  115. package/dist/prompt-references/referenceTrigger.js +100 -0
  116. package/dist/prompt-references/referenceTypes.d.ts +38 -0
  117. package/dist/prompt-references/referenceTypes.js +4 -0
  118. package/dist/prompt-references/sentReferences.d.ts +50 -0
  119. package/dist/prompt-references/sentReferences.js +122 -0
  120. package/dist/styles/tokens.css +58 -0
  121. package/dist/textarea-overlay/index.d.ts +9 -0
  122. package/dist/textarea-overlay/index.js +7 -0
  123. package/dist/textarea-overlay/mirrorSegments.d.ts +31 -0
  124. package/dist/textarea-overlay/mirrorSegments.js +47 -0
  125. package/dist/textarea-overlay/mirrorSizing.d.ts +39 -0
  126. package/dist/textarea-overlay/mirrorSizing.js +40 -0
  127. package/dist/textarea-overlay/textareaOverlay.d.ts +25 -0
  128. package/dist/textarea-overlay/textareaOverlay.js +277 -0
  129. package/dist/utils/overlayMotion.d.ts +1 -0
  130. package/dist/utils/overlayMotion.js +3 -3
  131. package/dist/utils/reducedMotion.d.ts +9 -0
  132. package/dist/utils/reducedMotion.js +13 -0
  133. package/package.json +16 -1
  134. package/dist/components/ui/number-stepper/index.d.ts +0 -3
  135. package/dist/components/ui/number-stepper/index.js +0 -3
  136. package/dist/components/ui/number-stepper/number-stepper.svelte +0 -212
  137. package/dist/components/ui/number-stepper/number-stepper.svelte.d.ts +0 -24
  138. package/dist/components/ui/number-stepper/numberStepperSteps.d.ts +0 -26
  139. package/dist/components/ui/number-stepper/numberStepperSteps.js +0 -45
@@ -1,21 +1,37 @@
1
1
  <!--
2
- Figma: Question Card (component set 68:26, page Question Card)
2
+ Figma: Question Card (component 68:26, page Question Card); the arrows of the pager are Pager Arrow (component set 1985:76).
3
+ The card: a small title over the question, the options and a footer. At the start of the footer the pager (an arrow, the step
4
+ such as "1 of 4", an arrow; only with more than one question), at the end Skip (Ghost, optional) and Next / Submit (Primary).
5
+ The arrows step back and forth between the questions without answering, and what is picked stays when the person leaves a
6
+ question and comes back. Next / Submit is on once the question on show has a pick, unless `nextSkips` is set: then it is
7
+ always on, and with nothing picked it leaves that question skipped (the agent decides it), the way Cursor's question card works.
8
+ Each question says on its own (`multiple`) whether one option or several can be picked: one is a radio group, several a group
9
+ of checkboxes with a hint under the question. A question with no options shows a hint in their place (it is answered in the
10
+ message box, or left to the agent with Next).
3
11
  -->
4
12
  <script lang="ts">
5
13
  import type { HTMLAttributes } from 'svelte/elements';
14
+ import IconChevronLeft from '@tabler/icons-svelte/icons/chevron-left';
15
+ import IconChevronRight from '@tabler/icons-svelte/icons/chevron-right';
6
16
  import { Button } from '../ui/button';
7
17
  import { cn } from '../../utils.js';
8
18
  import OptionRow from './OptionRow.svelte';
9
19
  import {
10
- canSubmitQuestion,
20
+ canAdvanceQuestion,
21
+ canStepBack,
22
+ canStepForward,
23
+ collectQuestionSelections,
11
24
  formatQuestionStep,
12
- isFirstQuestion,
13
25
  isLastQuestion,
14
26
  moveFocusedIndex,
15
27
  optionItemRole,
16
28
  primaryQuestionLabel,
29
+ questionCardTitle,
17
30
  selectionRole,
18
- toggleOption
31
+ showsQuestionPager,
32
+ stepQuestionIndex,
33
+ toggleOption,
34
+ type QuestionStepDirection
19
35
  } from './questionCardLogic.js';
20
36
 
21
37
  export type QuestionOption = {
@@ -27,39 +43,70 @@
27
43
  export type QuestionItem = {
28
44
  question: string;
29
45
  options: QuestionOption[];
46
+ /** Several options can be picked for this question (checkboxes); left out, one option (a radio group). */
30
47
  multiple?: boolean;
31
48
  };
32
49
 
33
50
  export type QuestionCardMessages = {
51
+ /** The small title on top of a card with one question. */
52
+ title: string;
53
+ /** The small title on top of a card with a few questions. */
54
+ titleMany: string;
55
+ /** The step between the arrows of the pager, `{current}` and `{total}` filled in. */
34
56
  step: string;
57
+ /** The label of the arrow that goes back to the question before. */
35
58
  back: string;
59
+ /** The label of the arrow that goes on to the question after. */
60
+ forward: string;
36
61
  next: string;
37
62
  submit: string;
38
63
  skip: string;
64
+ /** The hint under a question that takes several picks. */
65
+ multipleHint: string;
66
+ /** The hint in place of the options of a question that has none: it is answered in the message box, or skipped. */
67
+ noOptionsHint: string;
39
68
  };
40
69
 
41
70
  const defaultMessages: QuestionCardMessages = {
42
- step: 'Question {current} of {total}',
43
- back: 'Back',
71
+ title: 'Question',
72
+ titleMany: 'Questions',
73
+ step: '{current} of {total}',
74
+ back: 'Previous question',
75
+ forward: 'Next question',
44
76
  next: 'Next',
45
77
  submit: 'Submit',
46
- skip: 'Skip'
78
+ skip: 'Skip',
79
+ multipleHint: 'Select all that apply',
80
+ noOptionsHint: 'Write your answer in the message box, or skip this question.'
47
81
  };
48
82
 
49
83
  type Props = HTMLAttributes<HTMLDivElement> & {
50
84
  ref?: HTMLDivElement | null;
51
85
  class?: string;
52
- /** Overrides the formatted step line when set. */
86
+ /** Overrides the step between the arrows of the pager when set. */
53
87
  step?: string;
54
88
  question: string;
55
89
  options: QuestionOption[];
56
90
  /** Multi-question flow; when set, `question` / `options` on the root are ignored. */
57
91
  questions?: QuestionItem[];
92
+ /** Several picks for the single question of the root (`question` / `options`); a question of `questions` has its own. */
58
93
  multiple?: boolean;
94
+ /**
95
+ * Next / Submit works with nothing picked: that question is left skipped (its picks are empty in `onNext` and `onSubmit`),
96
+ * and a pick that was made can be taken off by pressing it again. Off by default: Next then waits for a pick.
97
+ */
98
+ nextSkips?: boolean;
99
+ /** Skip shows (Ghost, before Next) when this is not false and `onSkip` is set. */
59
100
  showSkip?: boolean;
60
101
  messages?: Partial<QuestionCardMessages>;
61
- onSubmit?: (selectedIds: string[]) => void;
102
+ /**
103
+ * The last question was answered. `selectedIds` are the picks of that question, `allSelectedIds` the picks of every
104
+ * question in order (the ones the person stepped over with the arrows have none).
105
+ */
106
+ onSubmit?: (selectedIds: string[], allSelectedIds: string[][]) => void;
107
+ /** The person left a question to go on (Next or the arrow). `selectedIds` is empty when the arrow was used before a pick. */
62
108
  onNext?: (selectedIds: string[], questionIndex: number) => void;
109
+ /** The person left a question to go back (the arrow). */
63
110
  onBack?: (questionIndex: number) => void;
64
111
  onSkip?: () => void;
65
112
  };
@@ -72,7 +119,8 @@
72
119
  options,
73
120
  questions,
74
121
  multiple = false,
75
- showSkip = false,
122
+ nextSkips = false,
123
+ showSkip = true,
76
124
  messages: messagesProp,
77
125
  onSubmit,
78
126
  onNext,
@@ -97,10 +145,15 @@
97
145
  const activeOptions = $derived(activeItem?.options ?? options);
98
146
  const activeMultiple = $derived(activeItem?.multiple ?? multiple);
99
147
 
148
+ const titleLabel = $derived(
149
+ questionCardTitle(questionTotal, messages.title, messages.titleMany)
150
+ );
100
151
  const stepLabel = $derived(
101
152
  step ?? formatQuestionStep(messages.step, currentIndex + 1, questionTotal)
102
153
  );
103
- const onFirst = $derived(isFirstQuestion(currentIndex));
154
+ const pagerShown = $derived(showsQuestionPager(questionTotal));
155
+ const backEnabled = $derived(canStepBack(currentIndex));
156
+ const forwardEnabled = $derived(canStepForward(currentIndex, questionTotal));
104
157
  const onLast = $derived(isLastQuestion(currentIndex, questionTotal));
105
158
  const primaryLabel = $derived(
106
159
  primaryQuestionLabel(onLast && questionTotal > 1, messages.next, messages.submit)
@@ -108,7 +161,7 @@
108
161
 
109
162
  const groupRole = $derived(selectionRole(activeMultiple));
110
163
  const itemRole = $derived(optionItemRole(activeMultiple));
111
- const submitEnabled = $derived(canSubmitQuestion(selectedIds));
164
+ const submitEnabled = $derived(canAdvanceQuestion(selectedIds, nextSkips));
112
165
 
113
166
  function isSelected(id: string): boolean {
114
167
  return selectedIds.includes(id);
@@ -124,7 +177,7 @@
124
177
  }
125
178
 
126
179
  function selectOption(id: string) {
127
- selectedIds = toggleOption(selectedIds, id, activeMultiple);
180
+ selectedIds = toggleOption(selectedIds, id, activeMultiple, nextSkips);
128
181
  }
129
182
 
130
183
  function handleOptionKeydown(event: KeyboardEvent, index: number, id: string) {
@@ -156,37 +209,39 @@
156
209
  el?.focus();
157
210
  }
158
211
 
212
+ /**
213
+ * Goes to the question before or after the one on show (an arrow of the pager, or Next). The pick of the question
214
+ * that is left is kept, so that it is there when the person comes back to it.
215
+ */
216
+ function stepToQuestion(direction: QuestionStepDirection) {
217
+ const targetIndex = stepQuestionIndex(currentIndex, direction, questionTotal);
218
+ if (targetIndex === currentIndex) return;
219
+ persistSelection();
220
+ try {
221
+ if (direction === 'forward') onNext?.([...selectedIds], currentIndex);
222
+ else onBack?.(currentIndex);
223
+ } catch (error) {
224
+ console.error(error);
225
+ }
226
+ currentIndex = targetIndex;
227
+ loadSelectionForIndex(currentIndex);
228
+ }
229
+
159
230
  function handlePrimary() {
160
231
  if (!submitEnabled) return;
161
232
  if (onLast) {
162
233
  if (!onSubmit) return;
163
234
  try {
164
- onSubmit([...selectedIds]);
235
+ onSubmit(
236
+ [...selectedIds],
237
+ collectQuestionSelections(questionTotal, selectionsByIndex, currentIndex, selectedIds)
238
+ );
165
239
  } catch (error) {
166
240
  console.error(error);
167
241
  }
168
242
  return;
169
243
  }
170
- persistSelection();
171
- try {
172
- onNext?.([...selectedIds], currentIndex);
173
- } catch (error) {
174
- console.error(error);
175
- }
176
- currentIndex += 1;
177
- loadSelectionForIndex(currentIndex);
178
- }
179
-
180
- function handleBack() {
181
- if (onFirst) return;
182
- persistSelection();
183
- try {
184
- onBack?.(currentIndex);
185
- } catch (error) {
186
- console.error(error);
187
- }
188
- currentIndex -= 1;
189
- loadSelectionForIndex(currentIndex);
244
+ stepToQuestion('forward');
190
245
  }
191
246
 
192
247
  function handleSkip() {
@@ -214,51 +269,106 @@
214
269
  {...restProps}
215
270
  >
216
271
  <header class="flex min-w-0 flex-col gap-0.5">
217
- <p class="text-caption-medium text-muted-foreground">{stepLabel}</p>
272
+ <p class="text-caption-medium text-muted-foreground">{titleLabel}</p>
218
273
  <p class="text-body-medium text-foreground">{activeQuestion}</p>
274
+ {#if activeMultiple}
275
+ <!-- A question that takes several picks says so, under the question: the rows look the same, the hint tells them apart -->
276
+ <p class="text-caption text-muted-foreground" data-testid="question-card-multiple-hint">
277
+ {messages.multipleHint}
278
+ </p>
279
+ {/if}
219
280
  </header>
220
281
 
221
- <div
222
- class="flex flex-col gap-1"
223
- role={groupRole}
224
- aria-label={activeQuestion}
225
- onkeydown={handleGroupKeydown}
226
- >
227
- {#each activeOptions as option, index (option.id)}
228
- {@const selected = isSelected(option.id)}
229
- <div class="flex flex-col gap-0.5">
230
- <OptionRow
231
- label={option.label}
232
- {selected}
233
- selectionMode={itemRole === 'checkbox' ? 'checkbox' : 'radio'}
234
- data-option-index={index}
235
- tabindex={index === focusedIndex ? 0 : -1}
236
- onSelect={() => {
237
- focusedIndex = index;
238
- selectOption(option.id);
239
- }}
240
- onkeydown={(event) => handleOptionKeydown(event, index, option.id)}
241
- />
242
- {#if option.description}
243
- <p class="text-caption text-muted-foreground ps-3">{option.description}</p>
244
- {/if}
245
- </div>
246
- {/each}
247
- </div>
282
+ {#if activeOptions.length === 0}
283
+ <!-- A question with no options is answered in the message box (which skips the card) or left to the agent with Next -->
284
+ <p class="text-caption text-muted-foreground" data-testid="question-card-no-options-hint">
285
+ {messages.noOptionsHint}
286
+ </p>
287
+ {:else}
288
+ <div
289
+ class="flex flex-col gap-1"
290
+ role={groupRole}
291
+ aria-label={activeQuestion}
292
+ onkeydown={handleGroupKeydown}
293
+ >
294
+ {#each activeOptions as option, index (option.id)}
295
+ {@const selected = isSelected(option.id)}
296
+ <div class="flex flex-col gap-0.5">
297
+ <OptionRow
298
+ label={option.label}
299
+ {selected}
300
+ selectionMode={itemRole === 'checkbox' ? 'checkbox' : 'radio'}
301
+ data-option-index={index}
302
+ tabindex={index === focusedIndex ? 0 : -1}
303
+ onSelect={() => {
304
+ focusedIndex = index;
305
+ selectOption(option.id);
306
+ }}
307
+ onkeydown={(event) => handleOptionKeydown(event, index, option.id)}
308
+ />
309
+ {#if option.description}
310
+ <p class="text-caption text-muted-foreground ps-3">{option.description}</p>
311
+ {/if}
312
+ </div>
313
+ {/each}
314
+ </div>
315
+ {/if}
248
316
 
249
317
  <footer class="flex min-w-0 items-center gap-2">
318
+ {#if pagerShown}
319
+ <!-- The pager: the step sits between the arrows; the arrows turn the other way in right to left -->
320
+ <div class="flex shrink-0 items-center" data-testid="question-card-pager">
321
+ <Button
322
+ variant="ghost"
323
+ size="icon-sm"
324
+ disabled={!backEnabled}
325
+ aria-label={messages.back}
326
+ title={messages.back}
327
+ data-testid="question-card-back"
328
+ onclick={() => stepToQuestion('back')}
329
+ >
330
+ <IconChevronLeft aria-hidden="true" class="rtl:-scale-x-100" />
331
+ </Button>
332
+ <span
333
+ class="text-caption text-muted-foreground min-w-8 text-center tabular-nums"
334
+ aria-live="polite"
335
+ >
336
+ {stepLabel}
337
+ </span>
338
+ <Button
339
+ variant="ghost"
340
+ size="icon-sm"
341
+ disabled={!forwardEnabled}
342
+ aria-label={messages.forward}
343
+ title={messages.forward}
344
+ data-testid="question-card-forward"
345
+ onclick={() => stepToQuestion('forward')}
346
+ >
347
+ <IconChevronRight aria-hidden="true" class="rtl:-scale-x-100" />
348
+ </Button>
349
+ </div>
350
+ {/if}
351
+ <span class="min-w-0 flex-1" aria-hidden="true"></span>
250
352
  {#if showSkip && onSkip}
251
- <Button variant="ghost" size="sm" class="shrink-0" onclick={handleSkip}>
353
+ <Button
354
+ variant="ghost"
355
+ size="sm"
356
+ class="shrink-0"
357
+ data-testid="question-card-skip"
358
+ onclick={handleSkip}
359
+ >
252
360
  {messages.skip}
253
361
  </Button>
254
362
  {/if}
255
- {#if !onFirst}
256
- <Button variant="ghost" size="sm" class="shrink-0" onclick={handleBack}>
257
- {messages.back}
258
- </Button>
259
- {/if}
260
- <span class="min-w-0 flex-1" aria-hidden="true"></span>
261
- <Button variant="default" size="sm" disabled={!submitEnabled} onclick={handlePrimary}>
363
+ <!-- Secondary, not the filled main button: a card sits next to the screen's own main call to action (Publish, Create,
364
+ Send), and a screen has one. -->
365
+ <Button
366
+ variant="secondary"
367
+ size="sm"
368
+ disabled={!submitEnabled}
369
+ data-testid="question-card-primary"
370
+ onclick={handlePrimary}
371
+ >
262
372
  {primaryLabel}
263
373
  </Button>
264
374
  </footer>
@@ -7,29 +7,55 @@ export type QuestionOption = {
7
7
  export type QuestionItem = {
8
8
  question: string;
9
9
  options: QuestionOption[];
10
+ /** Several options can be picked for this question (checkboxes); left out, one option (a radio group). */
10
11
  multiple?: boolean;
11
12
  };
12
13
  export type QuestionCardMessages = {
14
+ /** The small title on top of a card with one question. */
15
+ title: string;
16
+ /** The small title on top of a card with a few questions. */
17
+ titleMany: string;
18
+ /** The step between the arrows of the pager, `{current}` and `{total}` filled in. */
13
19
  step: string;
20
+ /** The label of the arrow that goes back to the question before. */
14
21
  back: string;
22
+ /** The label of the arrow that goes on to the question after. */
23
+ forward: string;
15
24
  next: string;
16
25
  submit: string;
17
26
  skip: string;
27
+ /** The hint under a question that takes several picks. */
28
+ multipleHint: string;
29
+ /** The hint in place of the options of a question that has none: it is answered in the message box, or skipped. */
30
+ noOptionsHint: string;
18
31
  };
19
32
  type Props = HTMLAttributes<HTMLDivElement> & {
20
33
  ref?: HTMLDivElement | null;
21
34
  class?: string;
22
- /** Overrides the formatted step line when set. */
35
+ /** Overrides the step between the arrows of the pager when set. */
23
36
  step?: string;
24
37
  question: string;
25
38
  options: QuestionOption[];
26
39
  /** Multi-question flow; when set, `question` / `options` on the root are ignored. */
27
40
  questions?: QuestionItem[];
41
+ /** Several picks for the single question of the root (`question` / `options`); a question of `questions` has its own. */
28
42
  multiple?: boolean;
43
+ /**
44
+ * Next / Submit works with nothing picked: that question is left skipped (its picks are empty in `onNext` and `onSubmit`),
45
+ * and a pick that was made can be taken off by pressing it again. Off by default: Next then waits for a pick.
46
+ */
47
+ nextSkips?: boolean;
48
+ /** Skip shows (Ghost, before Next) when this is not false and `onSkip` is set. */
29
49
  showSkip?: boolean;
30
50
  messages?: Partial<QuestionCardMessages>;
31
- onSubmit?: (selectedIds: string[]) => void;
51
+ /**
52
+ * The last question was answered. `selectedIds` are the picks of that question, `allSelectedIds` the picks of every
53
+ * question in order (the ones the person stepped over with the arrows have none).
54
+ */
55
+ onSubmit?: (selectedIds: string[], allSelectedIds: string[][]) => void;
56
+ /** The person left a question to go on (Next or the arrow). `selectedIds` is empty when the arrow was used before a pick. */
32
57
  onNext?: (selectedIds: string[], questionIndex: number) => void;
58
+ /** The person left a question to go back (the arrow). */
33
59
  onBack?: (questionIndex: number) => void;
34
60
  onSkip?: () => void;
35
61
  };
@@ -0,0 +1,96 @@
1
+ <!--
2
+ The Question Card once it is closed: what the person answered, question by question. A question with picks shows them (a check
3
+ before each); a question with none shows "Skipped" in a muted voice, so a person who left a question to the agent (Next with
4
+ nothing picked, Skip, or a message typed in the chat instead of the card) sees that it was left. It has the frame, the small
5
+ title and the type of the Question Card (Figma: Question Card, component 68:26), without options and without a footer.
6
+ -->
7
+ <script lang="ts">
8
+ import type { HTMLAttributes } from 'svelte/elements';
9
+ import IconCheck from '@tabler/icons-svelte/icons/check';
10
+ import { cn } from '../../utils.js';
11
+ import {
12
+ areAllQuestionsSkipped,
13
+ isQuestionSkipped,
14
+ questionCardTitle,
15
+ type QuestionSummaryItem
16
+ } from './questionCardLogic.js';
17
+
18
+ export type QuestionCardSummaryMessages = {
19
+ /** The small title on top of a summary with one question. */
20
+ title: string;
21
+ /** The small title on top of a summary with a few questions. */
22
+ titleMany: string;
23
+ /** What stands for the answer of a question that was skipped. */
24
+ skipped: string;
25
+ };
26
+
27
+ const defaultMessages: QuestionCardSummaryMessages = {
28
+ title: 'Question',
29
+ titleMany: 'Questions',
30
+ skipped: 'Skipped'
31
+ };
32
+
33
+ type Props = HTMLAttributes<HTMLDivElement> & {
34
+ ref?: HTMLDivElement | null;
35
+ class?: string;
36
+ /** The questions in the order they were asked, each with the labels of what was picked (none: skipped). */
37
+ items: QuestionSummaryItem[];
38
+ messages?: Partial<QuestionCardSummaryMessages>;
39
+ };
40
+
41
+ let {
42
+ ref = $bindable(null),
43
+ class: className,
44
+ items,
45
+ messages: messagesProp,
46
+ ...restProps
47
+ }: Props = $props();
48
+
49
+ const messages = $derived({ ...defaultMessages, ...messagesProp });
50
+ const titleLabel = $derived(questionCardTitle(items.length, messages.title, messages.titleMany));
51
+ const everythingSkipped = $derived(areAllQuestionsSkipped(items));
52
+ </script>
53
+
54
+ <div
55
+ bind:this={ref}
56
+ role="group"
57
+ aria-label={titleLabel}
58
+ data-testid="question-card-summary"
59
+ data-all-skipped={everythingSkipped ? 'true' : 'false'}
60
+ class={cn(
61
+ 'rounded-card border-border bg-background flex w-full max-w-full flex-col gap-3 border p-4',
62
+ className
63
+ )}
64
+ {...restProps}
65
+ >
66
+ <p class="text-caption-medium text-muted-foreground">{titleLabel}</p>
67
+
68
+ <ol class="flex min-w-0 flex-col gap-3">
69
+ {#each items as item, index (index)}
70
+ {@const skipped = isQuestionSkipped(item.answers)}
71
+ <li
72
+ class="flex min-w-0 flex-col gap-1"
73
+ data-testid="question-card-summary-item"
74
+ data-skipped={skipped ? 'true' : 'false'}
75
+ >
76
+ <p class="text-body-medium text-foreground">{item.question}</p>
77
+ {#if skipped}
78
+ <p class="text-body text-muted-foreground" data-testid="question-card-summary-skipped">
79
+ {messages.skipped}
80
+ </p>
81
+ {:else}
82
+ <ul class="flex min-w-0 flex-col gap-0.5">
83
+ {#each item.answers as answer, answerIndex (answerIndex)}
84
+ <li class="text-body text-foreground flex min-w-0 items-start gap-2">
85
+ <span class="flex h-6 shrink-0 items-center" aria-hidden="true">
86
+ <IconCheck class="size-4 stroke-2" />
87
+ </span>
88
+ <span class="min-w-0 break-words">{answer}</span>
89
+ </li>
90
+ {/each}
91
+ </ul>
92
+ {/if}
93
+ </li>
94
+ {/each}
95
+ </ol>
96
+ </div>
@@ -0,0 +1,20 @@
1
+ import type { HTMLAttributes } from 'svelte/elements';
2
+ import { type QuestionSummaryItem } from './questionCardLogic.js';
3
+ export type QuestionCardSummaryMessages = {
4
+ /** The small title on top of a summary with one question. */
5
+ title: string;
6
+ /** The small title on top of a summary with a few questions. */
7
+ titleMany: string;
8
+ /** What stands for the answer of a question that was skipped. */
9
+ skipped: string;
10
+ };
11
+ type Props = HTMLAttributes<HTMLDivElement> & {
12
+ ref?: HTMLDivElement | null;
13
+ class?: string;
14
+ /** The questions in the order they were asked, each with the labels of what was picked (none: skipped). */
15
+ items: QuestionSummaryItem[];
16
+ messages?: Partial<QuestionCardSummaryMessages>;
17
+ };
18
+ declare const QuestionCardSummary: import("svelte").Component<Props, {}, "ref">;
19
+ type QuestionCardSummary = ReturnType<typeof QuestionCardSummary>;
20
+ export default QuestionCardSummary;