@widgetic/design-system 0.5.42 → 0.5.44

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 (31) hide show
  1. package/README.md +55 -3
  2. package/dist/components/chat/Composer.svelte +68 -17
  3. package/dist/components/chat/Composer.svelte.d.ts +22 -2
  4. package/dist/components/chat/ComposerNotice.svelte +56 -0
  5. package/dist/components/chat/ComposerNotice.svelte.d.ts +14 -0
  6. package/dist/components/chat/Message.svelte +50 -41
  7. package/dist/components/chat/MessageRatingActions.svelte +50 -3
  8. package/dist/components/chat/MessageRatingActions.svelte.d.ts +8 -0
  9. package/dist/components/chat/PlanCard.svelte +39 -8
  10. package/dist/components/chat/ScrollToBottom.svelte +13 -2
  11. package/dist/components/chat/ScrollToBottom.svelte.d.ts +1 -0
  12. package/dist/components/chat/composerLogic.d.ts +6 -0
  13. package/dist/components/chat/composerLogic.js +11 -0
  14. package/dist/components/chat/index.d.ts +1 -0
  15. package/dist/components/chat/index.js +2 -0
  16. package/dist/components/chat/planCardLogic.d.ts +24 -0
  17. package/dist/components/chat/planCardLogic.js +20 -0
  18. package/dist/components/index.d.ts +1 -1
  19. package/dist/components/index.js +1 -1
  20. package/dist/components/ui/dropdown-menu/dropdown-menu-sub-content.svelte +10 -0
  21. package/dist/inline-completion/hintMemory.js +1 -0
  22. package/dist/inline-completion/inlineCompletionAction.js +1 -0
  23. package/dist/prompt-references/ReferenceMenu.svelte +72 -72
  24. package/dist/prompt-references/ReferenceMenu.svelte.d.ts +2 -2
  25. package/dist/prompt-references/promptReferences.js +15 -2
  26. package/dist/prompt-references/referenceMenuPlacement.d.ts +2 -16
  27. package/dist/prompt-references/referenceMenuPlacement.js +2 -25
  28. package/dist/prompt-references/referenceTypes.d.ts +5 -0
  29. package/dist/styles/tokens.css +26 -1
  30. package/dist/textarea-overlay/textareaOverlay.js +4 -1
  31. package/package.json +1 -1
package/README.md CHANGED
@@ -380,10 +380,10 @@ The pieces are exported for a page that draws its own box: `createCompletionCont
380
380
 
381
381
  A person who attaches three pictures can say what happens with each: type `#` after a space and the attached files are listed with their thumbnails (as `@` lists the compositions of the workflows assistant); pick one and it stands in the sentence as a badge (thumbnail, name, an X): "Put **▣ #hero_banner** behind **▣ #logo**". The box stays the native textarea. Underneath, a badge is plain text, `#hero_banner`, between two runs of figure spaces that reserve room for the thumbnail and the X; a layer laid over the box (`textarea-overlay`) paints the badge there. So selection, undo, paste, input methods and the caret keep working natively, and what is sent is only text.
382
382
 
383
- - **The chat's `Composer`** takes a `references` prop (`ComposerReferences`): `{ items, messages: { hint, menuLabel, remove }, onHover?, triggerCharacter?, maxReferences?, log? }`. `onSend` then gets a second argument, `{ references }`: the attached files the text names, once each and in order (`{ id, label }`, `id` being the one the host gave the item). Without `references` the box is as it was: no menu, no badges, no listeners, and `onSend` gets the text alone. The text is what a person reads ("Put #hero_banner behind #logo"): the room of a badge is not sent, and is not counted by `maxLength`. While a file is attached the box says how to refer to it under the text (`messages.hint`, "Type # to reference an attached file"). The design system holds no English: the host passes all three words.
383
+ - **The chat's `Composer`** takes a `references` prop (`ComposerReferences`): `{ items, messages: { menuLabel, remove, hint? }, onHover?, triggerCharacter?, maxReferences?, log? }`. `onSend` then gets a second argument, `{ references }`: the attached files the text names, once each and in order (`{ id, label }`, `id` being the one the host gave the item). Without `references` the box is as it was: no menu, no badges, no listeners, and `onSend` gets the text alone. The text is what a person reads ("Put #hero_banner behind #logo"): the room of a badge is not sent, and is not counted by `maxLength`. The box draws no line of help for `#` under the text: a person who sees the box is not shown one. A host that wants a screen reader told how to refer to a file may pass the optional `messages.hint` (it is said while a file is attached, it is `sr-only`, and the box points to it); without it the box says nothing and points at nothing, as in the chat. The design system holds no English: the host passes the words (`menuLabel` and `remove`, and `hint` when it wants one).
384
384
  - **The files** are `items: ReferenceItem[]`, in tray order: `{ id, label, number, fileName, previewUrl?, sizeLabel? }`. `number` is the file's number in the tray (`#2` offers the second file), `previewUrl` any address a picture can be drawn from (without one the badge shows a file glyph). The host gives a file its `label` **once, when the file joins**, and keeps it: `assignReferenceLabel(fileName, { takenLabels, genericNumberFloor })`. A name that says something gives its label (`hero-banner-final.png` is `hero_banner_final`; a name taken gets `_2`), a name that says nothing (`IMG_4021.jpg`, `Screenshot 2026-11-17 at 7.55.01 AM.png`) is `Image_N`, with N above every generic number the draft has handed out so far (`genericLabelNumber` reads it back), so `#Image_2` typed for a file that has gone can never quietly mean the next one. A label is one to 24 letters, digits and underscores, in any script.
385
385
  - **When a file leaves** the tray, `removeTokensOfLabel(text, label)` takes its badges out of the text (each with one adjacent space; a `#label` the person typed by hand stays: it is their own word). A text restored from a draft goes through `unbadgeTokensWithoutFiles(text, labels)`: a badge whose file is not there any more is plain `#label` again. Both are exported from `components/chat` as well, where the chat imports them.
386
- - **`#` opens the menu** after the start of the text, a blank, an opening bracket or a quote, or a badge. It does not open in `a#b`, after a hyphen, in a hex colour (`#fff`) or a link. The menu is a list of the files whose label, file name or tray number matches what follows the `#` (`#2`, `#her`), with a picture of the highlighted one beside it; Up and Down move, **Enter** or **Tab** choose, **Esc** closes, a click chooses, and a key with a modifier is left to the box. It is drawn in the top layer, so no panel of the page clips it, and it opens upwards when there is no room below. While it is open the ghost text of the same box is off, and Enter does not send.
386
+ - **`#` opens the menu** after the start of the text, a blank, an opening bracket or a quote, or a badge. It does not open in `a#b`, after a hyphen, in a hex colour (`#fff`) or a link. The menu is a list of the files whose label, file name or tray number matches what follows the `#` (`#2`, `#her`): each row is the file's small picture, its name (two lines at most; the whole name and the size show in the row's `title`) and its tray number, and no larger card opens beside the list (the picture is the preview; a larger one shows only over a badge the pointer is on); Up and Down move, **Enter** or **Tab** choose, **Esc** closes, a click chooses, and a key with a modifier is left to the box. It is drawn in the top layer, so no panel of the page clips it, and it opens upwards when there is no room below. While it is open the ghost text of the same box is off, and Enter does not send.
387
387
  - **Editing around a badge**: the caret never rests inside one (arrows jump over it, a click next to it snaps), Backspace or Delete next to one takes the whole badge, the X takes it out, pasted text loses any figure space it carries, and Undo brings back the `#he` that was typed (the edit goes through the browser's own edit command). A badge that would not fit where the text puts its characters (the box wraps differently from the layer, for instance at a fractional width) is **not drawn**: the plain `#label` shows until the text or the width changes, and it is logged once.
388
388
  - **A badge is a file**: a pointer on a badge, or the keys on a menu row, tell the host (`onHover({ label, source })`) so its tray rings the same file. A change to the tray (a file removed, a name changed) repaints the badges on the spot.
389
389
  - **What a suggestion service sees**: with `references`, the ghost text of the box asks its source with every reference (a badge, and a hand-typed `#label` that names an attached file) as the neutral word `#file`: `neutralizeReferences(text, { knownLabels })`. A person's file names never reach a service through a suggestion. A text that cannot be made neutral asks nothing.
@@ -409,13 +409,65 @@ A person who attaches three pictures can say what happens with each: type `#` af
409
409
 
410
410
  <Composer
411
411
  bind:value
412
- references={{ items, messages: { hint: 'Type # to reference an attached file', menuLabel: 'Attached files', remove: 'Remove {name}' } }}
412
+ references={{ items, messages: { menuLabel: 'Attached files', remove: 'Remove {name}' } }}
413
413
  onSend={(text, options) => send(text, options?.references ?? [])}
414
414
  />
415
415
  ```
416
416
 
417
417
  To see it work run `npm run dev` and open `/showcase/prompt-references` (a tray of made-up files and five boxes: a wide one, a narrow one, one with ghost text, a right-to-left one) or the "With file references" composer on `/showcase/chat`. In a right-to-left box the badge reads as the bidirectional algorithm reads it: `label#`.
418
418
 
419
+ ### Previewing a suggestion in the box (`Composer` `previewText`)
420
+
421
+ A chat that offers ideas (follow-ups under the last reply, starter cards in an empty chat) can show an idea in the box while the pointer rests on it, the way Figma's chat does, instead of a tooltip. The page gives the `Composer` the idea's words in `previewText` when the pointer (or the keyboard) enters the idea, and `null` when it leaves.
422
+
423
+ - **What the box does**: it shows the words greyed, in place of what is typed. What was typed is not touched (the textarea keeps its focus, caret and text, and it is back the moment the preview ends), the send control is greyed, Enter sends nothing while the preview shows, and the grey suggestion after the caret is gone with it. The box grows to the taller of the two texts, up to the same limit as the textarea. A blank or non-text `previewText` is no preview.
424
+ - **What the page does**: it sets `previewText` on enter and focus of the idea, clears it on leave and blur, on a click (the idea then goes into the text for real), and when the idea is taken out of the page (a removed pill never sends a leave). Putting the idea into the text (a click: "after what is already there") is the page's own rule, it is not the box's.
425
+
426
+ ```svelte
427
+ <Composer bind:value previewText={hoveredIdea?.request ?? null} onSend={send} />
428
+ ```
429
+
430
+ To see it run `npm run dev`, open `/showcase/chat` and hover the three ideas under the "With a suggestion previewed" box.
431
+
432
+ ### A box that is off until something changes (`Composer` `disabledLook`)
433
+
434
+ A `disabled` `Composer` fades the whole box to half (`disabledLook="faded"`, the default), the look of a box that is off for a moment. A chat that stays off until something outside it changes (the workspace ran out of AI credits and a notice above the box says so, as in Figma) uses `disabledLook="muted"`: the box keeps its words and takes the grey `bg-muted` ground, the text turns `text-muted-foreground`, and the send, attach and model controls are off as before. The prop does nothing for a box that is not `disabled`.
435
+
436
+ ```svelte
437
+ <Composer bind:value disabled={outOfCredits} disabledLook="muted" onSend={send} />
438
+ ```
439
+
440
+ To see it open `/showcase/chat` and look at the "Disabled, muted" box.
441
+
442
+ ### A notice above the box (`ComposerNotice`)
443
+
444
+ `ComposerNotice` is the tinted, rounded block a chat keeps right above its `Composer` for as long as something is true (the workspace is out of AI credits, as in Figma's own chat): the words, and under them one small filled button (`actionLabel` and `onAction`; no button when either is missing). It is a `role="status"` region on the `brand-subtle` ground (the design system has no blue info token), as wide as the box, and the words wrap inside it. It holds no English: the page gives the words as the children and the label of the button.
445
+
446
+ ```svelte
447
+ <ComposerNotice actionLabel="Manage credits" onAction={openBilling}>
448
+ You're out of AI credits in Design Team. Credits reset Nov 26.
449
+ </ComposerNotice>
450
+ <Composer bind:value disabled disabledLook="muted" />
451
+ ```
452
+
453
+ It does not go away by itself: the page removes it when it is no longer true (`@widgetic/chat` keeps the credits one across reloads and drops it when the reset day comes). Open `/showcase/chat` for the three states ("Composer notice").
454
+
455
+ ### The arrow to the newest message (`ScrollToBottom` `visible`)
456
+
457
+ `ScrollToBottom` stays in the page the whole time and is only moved and faded: it **slides up from the bottom edge while it fades in** when `visible` becomes true, and **slides back down while it fades out** when it becomes false. The list around it never changes size when it comes or goes, a change of mind half way (the person scrolls back down while it is still arriving) turns it around from where it is, and while it is away it is out of the tab order and the accessibility tree (`inert`). People who ask for less motion get no slide and no fade. The page decides `visible` (the person is away from the end of the list) and what `onScroll` does (`@widgetic/chat` glides the list to its end with an ease, it does not jump).
458
+
459
+ ```svelte
460
+ <ScrollToBottom visible={isAwayFromEnd} label="Scroll to latest messages" onScroll={glideToEnd} />
461
+ ```
462
+
463
+ ### An "i" at the end of the message actions (`MessageRatingActions` `onDetails`)
464
+
465
+ The row under an assistant message (copy, regenerate, thumbs) draws a small **"i" at its far end** when the page gives `onDetails`: it is for support and not for the person's own use, which is why it sits away from the buttons that act on the message. Pressing it calls `onDetails`; what it opens (a card with a Support ID, `SupportIdDialog` of `@widgetic/chat`) is the page's. The name of the button is `messages.details` ("Copy debug details"). Without `onDetails` no "i" is drawn, and like the rest of the row it is drawn only when the row has something else to show (words to copy, or a version to rate).
466
+
467
+ ```svelte
468
+ <MessageRatingActions copyText={words} onCopy={copy} onDetails={supportId ? openSupportCard : undefined} messages={{ details: 'Copy debug details' }} />
469
+ ```
470
+
419
471
  ## Troubleshooting
420
472
 
421
473
  ### File Case Sensitivity Issues (macOS/Windows Teams)
@@ -46,8 +46,13 @@
46
46
 
47
47
  /** The words the box says about files a message may refer to. The design system holds no English: the host passes them. */
48
48
  export type ComposerReferenceMessages = {
49
- /** The line under the box while a file is attached: how to refer to it ("Type # to reference an attached file"). */
50
- hint: string;
49
+ /**
50
+ * Optional. What a screen reader is told about the box while a file is attached: how to refer to it. Nothing is drawn for it:
51
+ * a person who sees the box is not shown a line of help under the text. Left out (or empty), nothing is said and nothing is
52
+ * drawn for it at all, and the box does not point at a hint: the chat leaves it out, since a person who has attached a file
53
+ * needs no line of help for it.
54
+ */
55
+ hint?: string;
51
56
  /** What a screen reader calls the list of files the `#` menu opens ("Attached files"). */
52
57
  menuLabel: string;
53
58
  /** What the X of a badge is called, with `{name}` for the file's name ("Remove {name}"). */
@@ -111,6 +116,13 @@
111
116
  placeholder?: string;
112
117
  busy?: boolean;
113
118
  disabled?: boolean;
119
+ /**
120
+ * How a `disabled` box looks. `faded` (the default): the whole box fades to half, the look of a box that is off for a moment.
121
+ * `muted`: the box keeps its words and takes the grey ground of Figma's locked composer, for a chat that is off until
122
+ * something outside it changes (the workspace is out of AI credits) and says why in a notice above the box. It does nothing
123
+ * for a box that is not `disabled`.
124
+ */
125
+ disabledLook?: 'faded' | 'muted';
114
126
  maxLength?: number;
115
127
  allowEmpty?: boolean;
116
128
  assistantLabel?: string;
@@ -147,6 +159,14 @@
147
159
  * becomes a badge (picture, name, X) inside the text. Without it the box is as it was: no menu, no badges, no listeners.
148
160
  */
149
161
  references?: ComposerReferences;
162
+ /**
163
+ * Words to show in the box, greyed, in place of what is typed, while the pointer (or the keyboard) rests on a suggestion
164
+ * elsewhere on the page (Figma's chat does this for its follow-ups): the page sets it when the suggestion is entered and sets
165
+ * it back to `null` when it is left. Only a preview: what was typed is not touched (it is back the moment the preview ends),
166
+ * the send control is greyed and nothing is sent while it shows, and the grey suggestion after the caret is gone with it.
167
+ * Without it (or with `null`, or blank words) the box is as it was.
168
+ */
169
+ previewText?: string | null;
150
170
  /** Bounce + white tooltip on the send control (publish-before-send nudge). */
151
171
  sendAttention?: {
152
172
  bounce: boolean;
@@ -176,6 +196,7 @@
176
196
  composerPrimaryAction,
177
197
  enterKeyAction,
178
198
  isQueueableText,
199
+ previewTextOf,
179
200
  shouldSendOnKeyDown
180
201
  } from './composerLogic.js';
181
202
  import { selectedModelLabel, shouldShowComposerModelMenu } from './composerModelMenuLogic.js';
@@ -215,6 +236,7 @@
215
236
  placeholder = 'Type your message…',
216
237
  busy = $bindable(false),
217
238
  disabled = false,
239
+ disabledLook = 'faded',
218
240
  maxLength,
219
241
  allowEmpty = false,
220
242
  assistantLabel = 'Assistant',
@@ -232,11 +254,16 @@
232
254
  attachments,
233
255
  completion,
234
256
  references,
257
+ previewText = null,
235
258
  sendAttention,
236
259
  ...restProps
237
260
  }: ComposerProps = $props();
238
261
 
239
262
  const messages = $derived({ ...defaultMessages, ...messagesProp });
263
+ // The words shown in place of the typed text while the page previews a suggestion (null: nothing is previewed)
264
+ const preview = $derived(previewTextOf(previewText));
265
+ // A disabled box that keeps its words on a grey ground (Figma's locked composer) instead of fading to half
266
+ const mutedWhenDisabled = $derived(disabledLook === 'muted');
240
267
  const modelMenuVisible = $derived(shouldShowComposerModelMenu(models));
241
268
  const modelMenuLabel = $derived(selectedModelLabel(models, selectedModelId, assistantLabel));
242
269
  let modelMenuOpen = $state(false);
@@ -249,8 +276,9 @@
249
276
  const referencesOn = $derived(references !== undefined);
250
277
  const sendableValue = $derived(messageText(value, referencesOn));
251
278
  const referenceHintId = nextReferenceHintId();
279
+ // A hint is said only when the host gave one (the message is optional): without it the box points at nothing.
252
280
  const referenceHintShown = $derived(
253
- references !== undefined && references.items.length > 0 && references.messages.hint !== ''
281
+ references !== undefined && references.items.length > 0 && (references.messages.hint ?? '') !== ''
254
282
  );
255
283
  // Whether the `#` menu is open: the grey suggestion of the same box goes while it is.
256
284
  let referenceMenuOpen = $state(false);
@@ -304,11 +332,12 @@
304
332
 
305
333
  // What the ghost-text action is told. `value` is there so a text the page changes by itself (the box clears after a send) is
306
334
  // noticed and the suggestion goes with it. The ghost stays while the assistant builds (`busy`), and goes while the box is
307
- // disabled and while the `#` menu is open (one popup at a time, and the menu owns the keys).
335
+ // disabled and while the `#` menu is open (one popup at a time, and the menu owns the keys). It also goes while a suggestion of the
336
+ // page is previewed in the box (the typed text is hidden then), and is asked for again when the preview ends.
308
337
  const completionParams = $derived<InlineCompletionParams>({
309
338
  source: completionSource,
310
339
  value,
311
- disabled: disabled || referenceMenuOpen,
340
+ disabled: disabled || referenceMenuOpen || preview !== null,
312
341
  // Written here, in this file, so the class is found where the design system's styles are built.
313
342
  ghostClass: 'text-muted-foreground',
314
343
  debounceMs: completion?.debounceMs,
@@ -410,6 +439,8 @@
410
439
  * Enter on an empty text while an agent works does nothing (Stop is a button).
411
440
  */
412
441
  function handleSend(source: 'control' | 'enter' = 'control') {
442
+ // What the box shows is a preview of something else, not the message: nothing is sent (nor queued, nor saved) until it ends
443
+ if (preview !== null) return;
413
444
  const action = source === 'enter' ? enterKeyAction(primaryAction, onQueue != null) : primaryAction;
414
445
  if (action === 'none') return;
415
446
  if (action === 'stop') {
@@ -475,7 +506,9 @@
475
506
  bind:this={ref}
476
507
  class={cn(
477
508
  'max-w-content rounded-card border-input bg-background flex w-full flex-col gap-2 border p-[11px]',
478
- disabled && 'pointer-events-none opacity-50',
509
+ disabled && 'pointer-events-none',
510
+ disabled && !mutedWhenDisabled && 'opacity-50',
511
+ disabled && mutedWhenDisabled && 'bg-muted',
479
512
  className
480
513
  )}
481
514
  {...restProps}
@@ -494,12 +527,19 @@
494
527
  <div class="flex flex-wrap gap-1.5 overflow-hidden">{@render attachments()}</div>
495
528
  {/if}
496
529
 
497
- <!-- Positioned, so the layer the suggestion is painted on (a sibling of the textarea) is measured against this box. -->
498
- <div class="relative min-h-12 w-full px-1 pt-1">
530
+ <!-- Positioned, so the layer the suggestion is painted on (a sibling of the textarea) is measured against this box. While a
531
+ suggestion of the page is previewed, the box is a grid of one cell where the textarea and the preview lie one over the other, so
532
+ the box grows to the taller of the two. -->
533
+ <div class="relative min-h-12 w-full px-1 pt-1" class:grid={preview !== null}>
499
534
  <textarea
500
535
  bind:this={textareaRef}
501
536
  bind:value
502
- class="text-body text-foreground placeholder:text-muted-foreground block w-full resize-none overflow-y-auto border-0 bg-transparent outline-hidden focus-visible:outline-hidden disabled:cursor-not-allowed"
537
+ class={cn(
538
+ 'text-body placeholder:text-muted-foreground block w-full resize-none overflow-y-auto border-0 bg-transparent outline-hidden focus-visible:outline-hidden disabled:cursor-not-allowed',
539
+ disabled && mutedWhenDisabled ? 'text-muted-foreground' : 'text-foreground'
540
+ )}
541
+ class:col-start-1={preview !== null}
542
+ class:row-start-1={preview !== null}
503
543
  style="min-height: 2.75rem; max-height: 7.5rem;"
504
544
  {placeholder}
505
545
  {disabled}
@@ -516,16 +556,21 @@
516
556
  isComposing = false;
517
557
  }}
518
558
  ></textarea>
559
+ {#if preview !== null}
560
+ <!-- The words of the suggestion the page is previewing, greyed, over the text (which stays where it was: the textarea keeps
561
+ its focus, its caret and its text, and none of it is changed). Opaque, so the badges and the grey suggestion under it
562
+ do not show through. Not read out and not pointed at: it is gone when the pointer leaves the suggestion. -->
563
+ <div
564
+ class="text-body text-muted-foreground bg-background pointer-events-none z-10 col-start-1 row-start-1 max-h-[7.5rem] overflow-hidden whitespace-pre-wrap [overflow-wrap:anywhere]"
565
+ aria-hidden="true"
566
+ data-testid="composer-preview">{preview}</div>
567
+ {/if}
519
568
  {#if overLimit}
520
569
  <p class="text-caption text-destructive mt-1" role="status">{messages.characterLimit}</p>
521
570
  {/if}
522
571
  {#if referenceHintShown && references}
523
- <!-- How to refer to an attached file: shown while a file is attached, so the way in is not a secret. -->
524
- <p
525
- id={referenceHintId}
526
- class="text-caption text-muted-foreground mt-1"
527
- data-testid="composer-reference-hint"
528
- >
572
+ <!-- How to refer to an attached file, said to a screen reader only (the box points at it): a person who sees the box is not shown a line of help for it. -->
573
+ <p id={referenceHintId} class="sr-only" data-testid="composer-reference-hint">
529
574
  {references.messages.hint}
530
575
  </p>
531
576
  {/if}
@@ -596,9 +641,15 @@
596
641
  variant={primaryAction === 'stop' ? 'inverse' : 'primary'}
597
642
  data-testid="composer-send"
598
643
  data-action={primaryAction}
599
- class={sendAttention?.bounce ? 'wc-composer-send-bounce' : undefined}
644
+ class={cn(
645
+ // Enabled and disabled are two looks the control fades between, very quickly. A fade that is under way turns
646
+ // around by itself when the look changes back (see `press-feedback-fade`), so a text that is typed, erased and
647
+ // typed again never leaves the control half way or makes it jump.
648
+ 'press-feedback-fade',
649
+ sendAttention?.bounce && 'wc-composer-send-bounce'
650
+ )}
600
651
  label={primaryLabel}
601
- disabled={!sendEnabled}
652
+ disabled={!sendEnabled || preview !== null}
602
653
  onclick={() => handleSend('control')}
603
654
  >
604
655
  {#if primaryAction === 'stop'}
@@ -30,8 +30,13 @@ export type ComposerCompletion = {
30
30
  };
31
31
  /** The words the box says about files a message may refer to. The design system holds no English: the host passes them. */
32
32
  export type ComposerReferenceMessages = {
33
- /** The line under the box while a file is attached: how to refer to it ("Type # to reference an attached file"). */
34
- hint: string;
33
+ /**
34
+ * Optional. What a screen reader is told about the box while a file is attached: how to refer to it. Nothing is drawn for it:
35
+ * a person who sees the box is not shown a line of help under the text. Left out (or empty), nothing is said and nothing is
36
+ * drawn for it at all, and the box does not point at a hint: the chat leaves it out, since a person who has attached a file
37
+ * needs no line of help for it.
38
+ */
39
+ hint?: string;
35
40
  /** What a screen reader calls the list of files the `#` menu opens ("Attached files"). */
36
41
  menuLabel: string;
37
42
  /** What the X of a badge is called, with `{name}` for the file's name ("Remove {name}"). */
@@ -82,6 +87,13 @@ export type ComposerProps = HTMLAttributes<HTMLDivElement> & {
82
87
  placeholder?: string;
83
88
  busy?: boolean;
84
89
  disabled?: boolean;
90
+ /**
91
+ * How a `disabled` box looks. `faded` (the default): the whole box fades to half, the look of a box that is off for a moment.
92
+ * `muted`: the box keeps its words and takes the grey ground of Figma's locked composer, for a chat that is off until
93
+ * something outside it changes (the workspace is out of AI credits) and says why in a notice above the box. It does nothing
94
+ * for a box that is not `disabled`.
95
+ */
96
+ disabledLook?: 'faded' | 'muted';
85
97
  maxLength?: number;
86
98
  allowEmpty?: boolean;
87
99
  assistantLabel?: string;
@@ -118,6 +130,14 @@ export type ComposerProps = HTMLAttributes<HTMLDivElement> & {
118
130
  * becomes a badge (picture, name, X) inside the text. Without it the box is as it was: no menu, no badges, no listeners.
119
131
  */
120
132
  references?: ComposerReferences;
133
+ /**
134
+ * Words to show in the box, greyed, in place of what is typed, while the pointer (or the keyboard) rests on a suggestion
135
+ * elsewhere on the page (Figma's chat does this for its follow-ups): the page sets it when the suggestion is entered and sets
136
+ * it back to `null` when it is left. Only a preview: what was typed is not touched (it is back the moment the preview ends),
137
+ * the send control is greyed and nothing is sent while it shows, and the grey suggestion after the caret is gone with it.
138
+ * Without it (or with `null`, or blank words) the box is as it was.
139
+ */
140
+ previewText?: string | null;
121
141
  /** Bounce + white tooltip on the send control (publish-before-send nudge). */
122
142
  sendAttention?: {
123
143
  bounce: boolean;
@@ -0,0 +1,56 @@
1
+ <!--
2
+ Figma: none yet (code only). Drawn from the banner Figma's own AI chat puts above its message box when the workspace is out of
3
+ AI credits (seen on 21 Nov 2026): a tinted, rounded block as wide as the message box, the sentence in the body size, and one
4
+ small filled button under it, at the start of the line. `Banner` (shell) is the page-wide row with an icon; this is the stacked
5
+ notice of a chat, which sits right above the `Composer` and stays for as long as it is true.
6
+ 12px of padding on every side and 8px between the words and the button, the radius of `Banner`, the `brand-subtle` ground (the
7
+ design system has no blue "info" token; its light surface is the sage tint).
8
+ -->
9
+ <script lang="ts" module>
10
+ import type { Snippet } from 'svelte';
11
+ import type { HTMLAttributes } from 'svelte/elements';
12
+
13
+ export type ComposerNoticeProps = HTMLAttributes<HTMLDivElement> & {
14
+ ref?: HTMLDivElement | null;
15
+ class?: string;
16
+ /** The words of the notice (plain text: a sentence or two). The design system holds no English: the page gives them. */
17
+ children: Snippet;
18
+ /** The label of the button under the words. No button when it is empty or when there is no `onAction`. */
19
+ actionLabel?: string;
20
+ onAction?: () => void;
21
+ };
22
+ </script>
23
+
24
+ <script lang="ts">
25
+ import { cn } from '../../utils.js';
26
+ import { Button } from '../ui/button/index.js';
27
+
28
+ let {
29
+ ref = $bindable(null),
30
+ class: className,
31
+ children,
32
+ actionLabel = '',
33
+ onAction,
34
+ ...restProps
35
+ }: ComposerNoticeProps = $props();
36
+
37
+ /** Whether the notice has a button (a label and a handler). */
38
+ const hasAction = $derived(Boolean(actionLabel) && typeof onAction === 'function');
39
+ </script>
40
+
41
+ <!-- A status region: a screen reader says the words when the notice appears, and they stay in the reading order above the box. -->
42
+ <div
43
+ bind:this={ref}
44
+ role="status"
45
+ data-testid="composer-notice"
46
+ class={cn(
47
+ 'max-w-content bg-brand-subtle text-body text-foreground flex w-full flex-col items-start gap-2 rounded-xl p-3',
48
+ className
49
+ )}
50
+ {...restProps}
51
+ >
52
+ <div class="min-w-0 [overflow-wrap:anywhere]" data-testid="composer-notice-text">{@render children()}</div>
53
+ {#if hasAction}
54
+ <Button data-testid="composer-notice-action" size="sm" onclick={onAction}>{actionLabel}</Button>
55
+ {/if}
56
+ </div>
@@ -0,0 +1,14 @@
1
+ import type { Snippet } from 'svelte';
2
+ import type { HTMLAttributes } from 'svelte/elements';
3
+ export type ComposerNoticeProps = HTMLAttributes<HTMLDivElement> & {
4
+ ref?: HTMLDivElement | null;
5
+ class?: string;
6
+ /** The words of the notice (plain text: a sentence or two). The design system holds no English: the page gives them. */
7
+ children: Snippet;
8
+ /** The label of the button under the words. No button when it is empty or when there is no `onAction`. */
9
+ actionLabel?: string;
10
+ onAction?: () => void;
11
+ };
12
+ declare const ComposerNotice: import("svelte").Component<ComposerNoticeProps, {}, "ref">;
13
+ type ComposerNotice = ReturnType<typeof ComposerNotice>;
14
+ export default ComposerNotice;
@@ -67,6 +67,11 @@
67
67
 
68
68
  const messages = $derived({ ...defaultMessages, ...messagesProp });
69
69
  const isUser = $derived(role === 'user');
70
+ // The row of actions under a message is drawn only when there is an action to put in it. A row with nothing in it still took its
71
+ // 32 px (and the 4 px gap above it): the space between a message and the next one grew by 36 px for no reason, and the chat had to
72
+ // hide the empty row with a rule of its own. Where there are actions the row keeps its place while hidden, so showing it never moves anything.
73
+ const hasUserActions = $derived(Boolean(onRestoreCheckpoint || onCopy || actions));
74
+ const hasAssistantActions = $derived(Boolean(onCopy || onRegenerate || actions));
70
75
  </script>
71
76
 
72
77
  <div
@@ -89,27 +94,29 @@
89
94
  {@render children()}
90
95
  {/if}
91
96
  </div>
92
- <div
93
- class={cn(
94
- 'duration-fast flex min-h-8 items-center gap-1 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 motion-reduce:transition-none',
95
- showActions && 'opacity-100'
96
- )}
97
- >
98
- {#if onRestoreCheckpoint}
99
- <Button variant="ghost" size="sm" onclick={onRestoreCheckpoint}>
100
- <IconRestore class="size-4 stroke-2" aria-hidden="true" />
101
- {messages.restoreCheckpoint}
102
- </Button>
103
- {/if}
104
- {#if onCopy}
105
- <IconButton variant="ghost" label={messages.copy} onclick={onCopy}>
106
- <IconCopy class="size-4 stroke-2" aria-hidden="true" />
107
- </IconButton>
108
- {/if}
109
- {#if actions}
110
- {@render actions()}
111
- {/if}
112
- </div>
97
+ {#if hasUserActions}
98
+ <div
99
+ class={cn(
100
+ 'duration-fast flex min-h-8 items-center gap-1 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 motion-reduce:transition-none',
101
+ showActions && 'opacity-100'
102
+ )}
103
+ >
104
+ {#if onRestoreCheckpoint}
105
+ <Button variant="ghost" size="sm" onclick={onRestoreCheckpoint}>
106
+ <IconRestore class="size-4 stroke-2" aria-hidden="true" />
107
+ {messages.restoreCheckpoint}
108
+ </Button>
109
+ {/if}
110
+ {#if onCopy}
111
+ <IconButton variant="ghost" label={messages.copy} onclick={onCopy}>
112
+ <IconCopy class="size-4 stroke-2" aria-hidden="true" />
113
+ </IconButton>
114
+ {/if}
115
+ {#if actions}
116
+ {@render actions()}
117
+ {/if}
118
+ </div>
119
+ {/if}
113
120
  {:else}
114
121
  <div
115
122
  class={cn('text-body text-foreground w-full', error && 'text-destructive')}
@@ -134,25 +141,27 @@
134
141
  </span>
135
142
  {/if}
136
143
  </div>
137
- <div
138
- class={cn(
139
- 'duration-fast flex min-h-8 items-center gap-1 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 motion-reduce:transition-none',
140
- showActions && 'opacity-100'
141
- )}
142
- >
143
- {#if onCopy}
144
- <IconButton variant="ghost" label={messages.copy} onclick={onCopy}>
145
- <IconCopy class="size-4 stroke-2" aria-hidden="true" />
146
- </IconButton>
147
- {/if}
148
- {#if onRegenerate}
149
- <IconButton variant="ghost" label={messages.regenerate} onclick={onRegenerate}>
150
- <IconRefresh class="size-4 stroke-2" aria-hidden="true" />
151
- </IconButton>
152
- {/if}
153
- {#if actions}
154
- {@render actions()}
155
- {/if}
156
- </div>
144
+ {#if hasAssistantActions}
145
+ <div
146
+ class={cn(
147
+ 'duration-fast flex min-h-8 items-center gap-1 opacity-0 transition-opacity group-focus-within:opacity-100 group-hover:opacity-100 motion-reduce:transition-none',
148
+ showActions && 'opacity-100'
149
+ )}
150
+ >
151
+ {#if onCopy}
152
+ <IconButton variant="ghost" label={messages.copy} onclick={onCopy}>
153
+ <IconCopy class="size-4 stroke-2" aria-hidden="true" />
154
+ </IconButton>
155
+ {/if}
156
+ {#if onRegenerate}
157
+ <IconButton variant="ghost" label={messages.regenerate} onclick={onRegenerate}>
158
+ <IconRefresh class="size-4 stroke-2" aria-hidden="true" />
159
+ </IconButton>
160
+ {/if}
161
+ {#if actions}
162
+ {@render actions()}
163
+ {/if}
164
+ </div>
165
+ {/if}
157
166
  {/if}
158
167
  </div>
@@ -1,5 +1,7 @@
1
1
  <!--
2
2
  Figma: Message actions row (copy, regenerate, thumbs) on assistant turns.
3
+ The "i" button at the far end of the row (`onDetails`) has no frame of its own in our Figma file: it follows the row Figma's own
4
+ assistant draws (copy, thumbs, then an "i" that opens "Copy debug details"), so that a person can hand support the id of the chat.
3
5
  -->
4
6
  <script lang="ts" module>
5
7
  import type { HTMLAttributes } from 'svelte/elements';
@@ -13,6 +15,8 @@
13
15
  rateGroup: string;
14
16
  rateUp: string;
15
17
  rateDown: string;
18
+ /** The name of the "i" button at the far end of the row (its tooltip and what a screen reader says). */
19
+ details: string;
16
20
  };
17
21
 
18
22
  export type MessageRatingActionsProps = HTMLAttributes<HTMLDivElement> & {
@@ -26,6 +30,12 @@
26
30
  onCopy?: () => void | Promise<void>;
27
31
  onRegenerate?: () => void;
28
32
  onRate?: (messageId: string, pressed: VersionThumb) => void;
33
+ /**
34
+ * Draws an "i" button at the far end of the row (away from the buttons that act on the message: it is for support, not for the
35
+ * person's own use). Pressing it calls this; what it opens (the page's dialog with a Support ID) is the page's. Without it no
36
+ * "i" is drawn. Like the rest of the row it is drawn only when the row has something else to show.
37
+ */
38
+ onDetails?: () => void;
29
39
  };
30
40
  </script>
31
41
 
@@ -35,8 +45,10 @@
35
45
  import IconThumbDown from '@tabler/icons-svelte/icons/thumb-down';
36
46
  import IconThumbUp from '@tabler/icons-svelte/icons/thumb-up';
37
47
  import IconCheck from '@tabler/icons-svelte/icons/check';
48
+ import IconInfoCircle from '@tabler/icons-svelte/icons/info-circle';
38
49
  import { cn } from '../../utils.js';
39
50
  import { IconButton } from '../ui/icon-button/index.js';
51
+ import HintTooltip from '../tooltip/HintTooltip.svelte';
40
52
  import {
41
53
  shouldRenderMessageRatingBar,
42
54
  shouldShowCopyAction,
@@ -51,7 +63,8 @@
51
63
  regenerate: 'Regenerate response',
52
64
  rateGroup: 'Rate this version',
53
65
  rateUp: 'Good result',
54
- rateDown: 'Poor result'
66
+ rateDown: 'Poor result',
67
+ details: 'Copy debug details'
55
68
  };
56
69
 
57
70
  let {
@@ -65,9 +78,18 @@
65
78
  onCopy,
66
79
  onRegenerate,
67
80
  onRate,
81
+ onDetails,
68
82
  ...restProps
69
83
  }: MessageRatingActionsProps = $props();
70
84
 
85
+ /**
86
+ * The row is not what the eyes should go to, so its buttons rest in the placeholder grey (`text-muted-foreground`, the colour of the
87
+ * placeholder in the composer) and take the full text colour under the pointer and under the keyboard focus (the ghost button's own
88
+ * hover). A thumb that was pressed keeps the full colour, so a vote that was given stays easy to see.
89
+ */
90
+ const quietButtonClass = 'text-muted-foreground';
91
+ const quietThumbClass = 'text-muted-foreground aria-pressed:text-foreground';
92
+
71
93
  const messages = $derived({ ...defaultMessages, ...messagesProp });
72
94
  const visible = $derived(
73
95
  shouldRenderMessageRatingBar({ copyText, canRegenerate, ratedMessageId })
@@ -108,7 +130,7 @@
108
130
  {...restProps}
109
131
  >
110
132
  {#if shouldShowCopyAction(copyText) && onCopy}
111
- <IconButton variant="ghost" label={copied ? messages.copied : messages.copy} onclick={handleCopy}>
133
+ <IconButton variant="ghost" class={quietButtonClass} label={copied ? messages.copied : messages.copy} onclick={handleCopy}>
112
134
  {#if copied}
113
135
  <IconCheck class="size-4 stroke-2" aria-hidden="true" />
114
136
  {:else}
@@ -118,7 +140,7 @@
118
140
  {/if}
119
141
 
120
142
  {#if shouldShowRegenerateAction(canRegenerate) && onRegenerate}
121
- <IconButton variant="ghost" label={messages.regenerate} onclick={onRegenerate}>
143
+ <IconButton variant="ghost" class={quietButtonClass} label={messages.regenerate} onclick={onRegenerate}>
122
144
  <IconRefresh class="size-4 stroke-2" aria-hidden="true" />
123
145
  </IconButton>
124
146
  {/if}
@@ -127,6 +149,7 @@
127
149
  <span class="inline-flex items-center gap-0.5" role="group" aria-label={messages.rateGroup}>
128
150
  <IconButton
129
151
  variant="ghost"
152
+ class={quietThumbClass}
130
153
  label={messages.rateUp}
131
154
  aria-pressed={thumbIsPressed(rating, 'up')}
132
155
  onclick={() => onRate(ratedMessageId, 'up')}
@@ -139,6 +162,7 @@
139
162
  </IconButton>
140
163
  <IconButton
141
164
  variant="ghost"
165
+ class={quietThumbClass}
142
166
  label={messages.rateDown}
143
167
  aria-pressed={thumbIsPressed(rating, 'down')}
144
168
  onclick={() => onRate(ratedMessageId, 'down')}
@@ -152,6 +176,29 @@
152
176
  </span>
153
177
  {/if}
154
178
 
179
+ {#if onDetails}
180
+ <!-- Pushed to the far end of the row (`ms-auto` is the end side in both directions): the other buttons are for the message, this
181
+ one is for support, and nothing on it says so but its tooltip, so it has one (the white hint, above the button). -->
182
+ <span class="ms-auto inline-flex items-center">
183
+ <HintTooltip content={messages.details} side="top" align="end" sideOffset={8}>
184
+ {#snippet trigger({ props })}
185
+ <IconButton
186
+ {...props}
187
+ variant="ghost"
188
+ class={quietButtonClass}
189
+ label={messages.details}
190
+ onclick={(event: MouseEvent) => {
191
+ (props.onclick as ((event: MouseEvent) => void) | undefined)?.(event);
192
+ onDetails?.();
193
+ }}
194
+ >
195
+ <IconInfoCircle class="size-4 stroke-2" aria-hidden="true" />
196
+ </IconButton>
197
+ {/snippet}
198
+ </HintTooltip>
199
+ </span>
200
+ {/if}
201
+
155
202
  <span class="sr-only" aria-live="polite">{copied ? messages.copied : ''}</span>
156
203
  </div>
157
204
  {/if}