@diegopluna/narvi 0.3.2 → 0.3.4

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 (133) hide show
  1. package/dist/components/activity/ActivityIcon.svelte +54 -0
  2. package/dist/components/activity/ActivityIcon.svelte.d.ts +24 -0
  3. package/dist/components/activity/ActivityStep.svelte +47 -13
  4. package/dist/components/activity/ActivityStep.svelte.d.ts +13 -4
  5. package/dist/components/activity/ActivityThought.svelte +24 -5
  6. package/dist/components/activity/ActivityThought.svelte.d.ts +12 -2
  7. package/dist/components/activity/index.d.ts +3 -1
  8. package/dist/components/activity/index.js +2 -1
  9. package/dist/components/app-shell/AppShellHeader.svelte +18 -4
  10. package/dist/components/app-shell/AppShellHeader.svelte.d.ts +5 -0
  11. package/dist/components/app-shell/AppShellMain.svelte +14 -2
  12. package/dist/components/app-shell/AppShellPanel.svelte +77 -12
  13. package/dist/components/app-shell/AppShellPanel.svelte.d.ts +11 -1
  14. package/dist/components/app-shell/AppShellSheet.svelte +11 -1
  15. package/dist/components/app-shell/context.d.ts +8 -0
  16. package/dist/components/app-shell/context.js +7 -0
  17. package/dist/components/approval/Approval.svelte +14 -1
  18. package/dist/components/approval/Approval.svelte.d.ts +5 -0
  19. package/dist/components/avatar/AvatarRoot.svelte +20 -7
  20. package/dist/components/avatar/AvatarRoot.svelte.d.ts +10 -3
  21. package/dist/components/badge/Badge.svelte +3 -1
  22. package/dist/components/badge/Badge.svelte.d.ts +1 -1
  23. package/dist/components/button/Button.svelte +28 -6
  24. package/dist/components/button/Button.svelte.d.ts +7 -0
  25. package/dist/components/composer/ComposerModelPicker.svelte +80 -13
  26. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +23 -6
  27. package/dist/components/composer/ComposerRoot.svelte +51 -12
  28. package/dist/components/composer/ComposerRoot.svelte.d.ts +16 -0
  29. package/dist/components/composer/ComposerSubmit.svelte +19 -5
  30. package/dist/components/composer/ComposerSubmit.svelte.d.ts +3 -1
  31. package/dist/components/composer/ComposerToggle.svelte +18 -4
  32. package/dist/components/composer/ComposerToggle.svelte.d.ts +2 -0
  33. package/dist/components/composer/ComposerTray.svelte +17 -3
  34. package/dist/components/composer/ComposerTray.svelte.d.ts +5 -0
  35. package/dist/components/composer/context.d.ts +4 -1
  36. package/dist/components/dialog/DialogContent.svelte +22 -12
  37. package/dist/components/dialog/DialogContent.svelte.d.ts +10 -0
  38. package/dist/components/divider/Divider.svelte +56 -14
  39. package/dist/components/divider/Divider.svelte.d.ts +13 -3
  40. package/dist/components/empty-state/EmptyState.svelte +12 -2
  41. package/dist/components/empty-state/EmptyState.svelte.d.ts +6 -0
  42. package/dist/components/heading/Heading.svelte +15 -0
  43. package/dist/components/heading/Heading.svelte.d.ts +6 -0
  44. package/dist/components/hover-card/HoverCardContent.svelte +18 -2
  45. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -0
  46. package/dist/components/input/Input.svelte +13 -3
  47. package/dist/components/input/Input.svelte.d.ts +10 -2
  48. package/dist/components/markdown/Markdown.svelte +22 -2
  49. package/dist/components/markdown/MarkdownDiagram.svelte +33 -2
  50. package/dist/components/markdown/MarkdownFile.svelte +56 -10
  51. package/dist/components/markdown/MarkdownMath.svelte +6 -0
  52. package/dist/components/markdown/MarkdownTable.svelte +3 -4
  53. package/dist/components/markdown/context.d.ts +6 -0
  54. package/dist/components/markdown/labels.d.ts +7 -0
  55. package/dist/components/markdown/labels.js +2 -0
  56. package/dist/components/menu/MenuCheckboxItem.svelte +44 -7
  57. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +12 -2
  58. package/dist/components/menu/MenuContent.svelte +10 -2
  59. package/dist/components/menu/MenuContent.svelte.d.ts +10 -0
  60. package/dist/components/menu/MenuItem.svelte +17 -2
  61. package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
  62. package/dist/components/menu/MenuSubContent.svelte +10 -2
  63. package/dist/components/menu/MenuSubContent.svelte.d.ts +10 -0
  64. package/dist/components/menu/MenuSubTrigger.svelte +19 -2
  65. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -0
  66. package/dist/components/message/MessageBubble.svelte +40 -0
  67. package/dist/components/message/MessageBubble.svelte.d.ts +12 -0
  68. package/dist/components/message/MessageContent.svelte +23 -14
  69. package/dist/components/message/MessageContent.svelte.d.ts +6 -0
  70. package/dist/components/message/MessageCopy.svelte +27 -15
  71. package/dist/components/message/MessageCopy.svelte.d.ts +9 -2
  72. package/dist/components/message/MessageRoot.svelte +20 -3
  73. package/dist/components/message/MessageRoot.svelte.d.ts +6 -0
  74. package/dist/components/message/context.d.ts +2 -0
  75. package/dist/components/message/index.d.ts +4 -1
  76. package/dist/components/message/index.js +3 -2
  77. package/dist/components/message/styles.d.ts +30 -0
  78. package/dist/components/message/styles.js +24 -0
  79. package/dist/components/notice/Notice.svelte +3 -3
  80. package/dist/components/popover/PopoverContent.svelte +27 -3
  81. package/dist/components/popover/PopoverContent.svelte.d.ts +18 -0
  82. package/dist/components/questionnaire/Questionnaire.svelte +103 -19
  83. package/dist/components/questionnaire/Questionnaire.svelte.d.ts +13 -1
  84. package/dist/components/queued-message/QueuedMessage.svelte +44 -6
  85. package/dist/components/queued-message/QueuedMessage.svelte.d.ts +12 -1
  86. package/dist/components/segmented/SegmentedControl.svelte +12 -1
  87. package/dist/components/segmented/SegmentedControl.svelte.d.ts +3 -1
  88. package/dist/components/select/Select.svelte +43 -6
  89. package/dist/components/select/Select.svelte.d.ts +14 -0
  90. package/dist/components/settings-row/SettingsRow.svelte +87 -37
  91. package/dist/components/settings-row/SettingsRow.svelte.d.ts +13 -0
  92. package/dist/components/split-button/SplitButton.svelte +137 -0
  93. package/dist/components/split-button/SplitButton.svelte.d.ts +29 -0
  94. package/dist/components/tab-strip/TabStrip.svelte +337 -93
  95. package/dist/components/tab-strip/TabStrip.svelte.d.ts +36 -1
  96. package/dist/components/tab-strip/drag.svelte.d.ts +31 -0
  97. package/dist/components/tab-strip/drag.svelte.js +148 -0
  98. package/dist/components/toast/Toaster.svelte +1 -1
  99. package/dist/components/toggle/Toggle.svelte +12 -2
  100. package/dist/components/toggle/Toggle.svelte.d.ts +11 -1
  101. package/dist/components/toggle-group/ToggleGroupItem.svelte +10 -1
  102. package/dist/components/toggle-group/ToggleGroupRoot.svelte +7 -1
  103. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +3 -1
  104. package/dist/components/toggle-group/context.d.ts +2 -1
  105. package/dist/components/tooltip/TooltipContent.svelte +13 -1
  106. package/dist/components/tooltip/TooltipContent.svelte.d.ts +10 -0
  107. package/dist/components/work-fold/WorkFold.svelte +13 -4
  108. package/dist/components/work-fold/WorkFold.svelte.d.ts +2 -1
  109. package/dist/focus-ring.d.ts +29 -0
  110. package/dist/focus-ring.js +42 -0
  111. package/dist/index.d.ts +8 -5
  112. package/dist/index.js +8 -2
  113. package/dist/internal/Collapse.svelte +15 -2
  114. package/dist/internal/Glyph.svelte +28 -0
  115. package/dist/internal/Glyph.svelte.d.ts +5 -0
  116. package/dist/internal/Tile.svelte +3 -2
  117. package/dist/internal/layer.d.ts +23 -0
  118. package/dist/internal/layer.js +19 -0
  119. package/dist/internal/toggle.d.ts +8 -1
  120. package/dist/internal/toggle.js +20 -2
  121. package/dist/markdown/file-paths.d.ts +7 -0
  122. package/dist/markdown/file-paths.js +29 -0
  123. package/dist/markdown/files.d.ts +22 -2
  124. package/dist/markdown/files.js +45 -14
  125. package/dist/tokens.stylex.d.ts +3 -0
  126. package/dist/tokens.stylex.js +5 -1
  127. package/package.json +1 -1
  128. package/skills/building-ui/SKILL.md +77 -5
  129. package/skills/building-ui/references/components.md +51 -50
  130. package/skills/markdown/SKILL.md +22 -6
  131. package/skills/setup/SKILL.md +1 -1
  132. package/skills/styling/SKILL.md +10 -3
  133. package/skills/theming/SKILL.md +11 -4
@@ -19,3 +19,11 @@ export declare function setAppShellContext(context: AppShellContext): void;
19
19
  /** The surrounding AppShell, for building parts of your own. */
20
20
  export declare function getAppShellContext(): AppShellContext | undefined;
21
21
  export declare function useAppShell(part: string): AppShellContext;
22
+ /** @internal What the parts of one sheet tell each other. */
23
+ export type AppShellSheetContext = {
24
+ /** True while a panel in the sheet is maximized, over the page, which then steps out of view. */
25
+ readonly covered: boolean;
26
+ setCovered(covered: boolean): void;
27
+ };
28
+ export declare function setAppShellSheetContext(context: AppShellSheetContext): void;
29
+ export declare function getAppShellSheetContext(): AppShellSheetContext | undefined;
@@ -13,3 +13,10 @@ export function useAppShell(part) {
13
13
  throw new Error(`<AppShell.${part}> must be placed inside <AppShell.Root>.`);
14
14
  return context;
15
15
  }
16
+ const SHEET_KEY = Symbol('narvi.app-shell-sheet');
17
+ export function setAppShellSheetContext(context) {
18
+ setContext(SHEET_KEY, context);
19
+ }
20
+ export function getAppShellSheetContext() {
21
+ return getContext(SHEET_KEY);
22
+ }
@@ -63,6 +63,11 @@
63
63
  onchoose: (value: string) => void;
64
64
  /** Once there is one, the card folds into a line that says it. */
65
65
  answer?: ApprovalAnswer | undefined;
66
+ /**
67
+ * Set while the answer is on its way. The button pressed shows a spinner, the others
68
+ * wait, and the shortcuts do nothing, so the choice is not made twice.
69
+ */
70
+ busy?: boolean | undefined;
66
71
  /** What the folded line names after the answer, such as the command. */
67
72
  subject?: string | undefined;
68
73
  /** More detail inside the card. */
@@ -156,6 +161,7 @@
156
161
  choices,
157
162
  onchoose,
158
163
  answer,
164
+ busy = false,
159
165
  subject,
160
166
  children,
161
167
  sx,
@@ -166,10 +172,14 @@
166
172
  let card = $state<HTMLElement | null>(null);
167
173
  let line = $state<HTMLElement | null>(null);
168
174
  let keepFocus = false;
175
+ // The choice last made, which spins while the answer is on its way
176
+ let chosen = $state<string>();
169
177
 
170
178
  function choose(value: string) {
179
+ if (busy) return;
171
180
  // The buttons are about to go; focus follows to what replaces them
172
181
  keepFocus = !!card?.contains(document.activeElement);
182
+ chosen = value;
173
183
  onchoose(value);
174
184
  }
175
185
 
@@ -186,7 +196,7 @@
186
196
  });
187
197
 
188
198
  function onkeydown(event: KeyboardEvent) {
189
- if (answer || event.defaultPrevented || event.repeat || !card) return;
199
+ if (answer || busy || event.defaultPrevented || event.repeat || !card) return;
190
200
  // With several cards waiting, the first one on the page answers
191
201
  if (document.querySelector('[data-slot="approval"][data-shortcuts]') !== card) return;
192
202
  const mod = event.metaKey || event.ctrlKey;
@@ -241,6 +251,7 @@
241
251
  role="group"
242
252
  aria-labelledby="{uid}-title"
243
253
  data-slot="approval"
254
+ aria-busy={busy || undefined}
244
255
  data-shortcuts={choices.some((choice) => choice.shortcut) || undefined}
245
256
  {...attrs([styles.card, sx], className)}
246
257
  >
@@ -272,6 +283,8 @@
272
283
  .replace('enter', 'Enter')
273
284
  .replace('backspace', 'Backspace')
274
285
  : undefined}
286
+ loading={busy && chosen === choice.value}
287
+ disabled={busy && chosen !== choice.value}
275
288
  onclick={() => choose(choice.value)}
276
289
  >
277
290
  {choice.label}
@@ -33,6 +33,11 @@ export type ApprovalProps = {
33
33
  onchoose: (value: string) => void;
34
34
  /** Once there is one, the card folds into a line that says it. */
35
35
  answer?: ApprovalAnswer | undefined;
36
+ /**
37
+ * Set while the answer is on its way. The button pressed shows a spinner, the others
38
+ * wait, and the shortcuts do nothing, so the choice is not made twice.
39
+ */
40
+ busy?: boolean | undefined;
36
41
  /** What the folded line names after the answer, such as the command. */
37
42
  subject?: string | undefined;
38
43
  /** More detail inside the card. */
@@ -6,14 +6,21 @@
6
6
  import { font, radius } from '../../tokens.stylex.js';
7
7
  import { setAvatarContext, type AvatarImageStatus } from './context.js';
8
8
 
9
- export type AvatarSize = 'sm' | 'md' | 'lg' | 'xl';
9
+ /** 20, 24, 28, 36 and 56px. */
10
+ export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
10
11
 
11
12
  export type AvatarRootProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
12
13
  /**
13
- * The person's name. It becomes the avatar's accessible name and picks the
14
- * colour behind the initials, so each person keeps theirs.
14
+ * The person's name. It picks the colour behind the initials, so each person keeps
15
+ * theirs, and is the avatar's accessible name unless `label` says otherwise.
15
16
  */
16
17
  name?: string | undefined;
18
+ /**
19
+ * The accessible name, in place of `name`: "Ada, the thread's owner". `null` where the
20
+ * name is written beside the avatar, so it is not read twice: the avatar is then hidden
21
+ * from assistive technology.
22
+ */
23
+ label?: string | null | undefined;
17
24
  size?: AvatarSize | undefined;
18
25
  sx?: Sx | undefined;
19
26
  ref?: HTMLSpanElement | null | undefined;
@@ -52,8 +59,10 @@
52
59
  });
53
60
 
54
61
  const sizes = stylex.create({
62
+ // Beside a line of meta text, as in a row of who is in a thread
63
+ xs: { width: '1.25rem', height: '1.25rem', fontSize: '0.5625rem' },
55
64
  sm: { width: '1.5rem', height: '1.5rem', fontSize: '0.625rem' },
56
- md: { width: '1.75rem', height: '1.75rem', fontSize: '0.6875rem' },
65
+ md: { width: '1.75rem', height: '1.75rem', fontSize: font.sizeMicro },
57
66
  lg: { width: '2.25rem', height: '2.25rem', fontSize: font.sizeMeta },
58
67
  xl: { width: '3.5rem', height: '3.5rem', fontSize: '1.125rem' }
59
68
  });
@@ -70,6 +79,7 @@
70
79
  <script lang="ts">
71
80
  let {
72
81
  name,
82
+ label,
73
83
  size = 'md',
74
84
  sx,
75
85
  class: className,
@@ -79,6 +89,7 @@
79
89
  }: AvatarRootProps = $props();
80
90
 
81
91
  let status = $state<AvatarImageStatus>('none');
92
+ const spoken = $derived(label === null ? undefined : (label ?? name) || undefined);
82
93
 
83
94
  setAvatarContext({
84
95
  get status() {
@@ -93,11 +104,13 @@
93
104
  });
94
105
  </script>
95
106
 
96
- <!-- With a name, the whole avatar is one image with that name, and what is inside is not read out -->
107
+ <!-- With a name, the whole avatar is one image with that name, and what is inside is not read out.
108
+ With `label={null}` it is decoration, beside a name that is read already. -->
97
109
  <span
98
110
  bind:this={ref}
99
- role={name ? 'img' : undefined}
100
- aria-label={name}
111
+ role={spoken ? 'img' : undefined}
112
+ aria-label={spoken}
113
+ aria-hidden={label === null || undefined}
101
114
  data-slot="avatar"
102
115
  data-status={status}
103
116
  {...rest}
@@ -1,13 +1,20 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
3
  import { type Sx } from '../../internal/sx.js';
4
- export type AvatarSize = 'sm' | 'md' | 'lg' | 'xl';
4
+ /** 20, 24, 28, 36 and 56px. */
5
+ export type AvatarSize = 'xs' | 'sm' | 'md' | 'lg' | 'xl';
5
6
  export type AvatarRootProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
6
7
  /**
7
- * The person's name. It becomes the avatar's accessible name and picks the
8
- * colour behind the initials, so each person keeps theirs.
8
+ * The person's name. It picks the colour behind the initials, so each person keeps
9
+ * theirs, and is the avatar's accessible name unless `label` says otherwise.
9
10
  */
10
11
  name?: string | undefined;
12
+ /**
13
+ * The accessible name, in place of `name`: "Ada, the thread's owner". `null` where the
14
+ * name is written beside the avatar, so it is not read twice: the avatar is then hidden
15
+ * from assistive technology.
16
+ */
17
+ label?: string | null | undefined;
11
18
  size?: AvatarSize | undefined;
12
19
  sx?: Sx | undefined;
13
20
  ref?: HTMLSpanElement | null | undefined;
@@ -7,7 +7,7 @@
7
7
  import { colors, font, radius } from '../../tokens.stylex.js';
8
8
  import '../../internal/icons.css';
9
9
 
10
- export type BadgeTone = 'neutral' | 'accent' | 'success' | 'warning' | 'danger';
10
+ export type BadgeTone = 'neutral' | 'accent' | 'info' | 'success' | 'warning' | 'danger';
11
11
 
12
12
  export type BadgeProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
13
13
  /** Colour of the dot. The words stay in the text colour, so they are always readable. */
@@ -59,6 +59,7 @@
59
59
  const dots = stylex.create({
60
60
  neutral: { backgroundColor: colors.textSubtle },
61
61
  accent: { backgroundColor: colors.accent },
62
+ info: { backgroundColor: colors.info },
62
63
  success: { backgroundColor: colors.success },
63
64
  warning: { backgroundColor: colors.warning },
64
65
  danger: { backgroundColor: colors.danger }
@@ -68,6 +69,7 @@
68
69
  const words = stylex.create({
69
70
  neutral: {},
70
71
  accent: { color: colors.accent },
72
+ info: { color: colors.infoText },
71
73
  success: { color: colors.successText },
72
74
  warning: { color: colors.warningText },
73
75
  danger: { color: colors.dangerText }
@@ -2,7 +2,7 @@ import type { Snippet } from 'svelte';
2
2
  import type { HTMLAttributes } from 'svelte/elements';
3
3
  import { type Sx } from '../../internal/sx.js';
4
4
  import '../../internal/icons.css';
5
- export type BadgeTone = 'neutral' | 'accent' | 'success' | 'warning' | 'danger';
5
+ export type BadgeTone = 'neutral' | 'accent' | 'info' | 'success' | 'warning' | 'danger';
6
6
  export type BadgeProps = Omit<HTMLAttributes<HTMLSpanElement>, 'children'> & {
7
7
  /** Colour of the dot. The words stay in the text colour, so they are always readable. */
8
8
  tone?: BadgeTone | undefined;
@@ -44,6 +44,13 @@
44
44
  */
45
45
  loadingLabel?: string | undefined;
46
46
  disabled?: boolean | undefined;
47
+ /**
48
+ * Makes it a toggle button (`aria-pressed`), held in its open look while true: a
49
+ * toolbar's button that shows or hides something. `secondary` and `ghost` take the fill
50
+ * of what is chosen, `floating` its stronger edge, `bare` its full ink. For a toggle lit
51
+ * in the accent, use Toggle.
52
+ */
53
+ pressed?: boolean | undefined;
47
54
  /** Square button for a single icon. Give it an `aria-label`. */
48
55
  iconOnly?: boolean | undefined;
49
56
  /** Renders a link styled as a button. */
@@ -55,6 +62,12 @@
55
62
 
56
63
  // One key for every hover, so the catalog can show it without a pointer
57
64
  const HOVER = ':is(:hover, [data-preview~="hover"])';
65
+ // The trigger of a menu, a popover or a select while what it opened is showing. bits-ui
66
+ // marks it with `aria-expanded`, which a disclosure's trigger carries too: only a popup's
67
+ // (`aria-haspopup`) is held in its open look.
68
+ // A toggle button that is pressed holds the same look.
69
+ const OPEN =
70
+ ':is([aria-haspopup]:not([aria-haspopup="false"])[aria-expanded="true"], [aria-pressed="true"])';
58
71
 
59
72
  const styles = stylex.create({
60
73
  base: {
@@ -194,7 +207,8 @@
194
207
  color: colors.text,
195
208
  backgroundColor: {
196
209
  default: 'transparent',
197
- [HOVER]: { default: null, [media.hover]: colors.fillHover }
210
+ [HOVER]: { default: null, [media.hover]: colors.fillHover },
211
+ [OPEN]: colors.fillSelected
198
212
  },
199
213
  boxShadow: `inset 0 0 0 1px ${colors.borderStrong}`
200
214
  },
@@ -205,21 +219,25 @@
205
219
  [HOVER]: { default: null, [media.hover]: colors.focusHalo }
206
220
  }
207
221
  },
222
+ // Open, it holds the fill of what is chosen while its menu shows, a step past a hover
208
223
  ghost: {
209
224
  color: {
210
225
  default: colors.textMuted,
211
- [HOVER]: { default: null, [media.hover]: colors.text }
226
+ [HOVER]: { default: null, [media.hover]: colors.text },
227
+ [OPEN]: colors.text
212
228
  },
213
229
  backgroundColor: {
214
230
  default: 'transparent',
215
- [HOVER]: { default: null, [media.hover]: colors.fillHover }
231
+ [HOVER]: { default: null, [media.hover]: colors.fillHover },
232
+ [OPEN]: colors.fillSelected
216
233
  }
217
234
  },
218
235
  // No surface in any state: for a control on a shape that already frames it
219
236
  bare: {
220
237
  color: {
221
238
  default: colors.textMuted,
222
- [HOVER]: { default: null, [media.hover]: colors.text }
239
+ [HOVER]: { default: null, [media.hover]: colors.text },
240
+ [OPEN]: colors.text
223
241
  },
224
242
  backgroundColor: 'transparent'
225
243
  },
@@ -243,7 +261,8 @@
243
261
  floating: {
244
262
  color: {
245
263
  default: colors.textMuted,
246
- [HOVER]: { default: null, [media.hover]: colors.text }
264
+ [HOVER]: { default: null, [media.hover]: colors.text },
265
+ [OPEN]: colors.text
247
266
  },
248
267
  backgroundColor: colors.bgRaised,
249
268
  boxShadow: {
@@ -251,7 +270,8 @@
251
270
  [HOVER]: {
252
271
  default: null,
253
272
  [media.hover]: `inset 0 0 0 1px ${colors.borderStrong}, 0 6px 16px -6px ${colors.shadow}`
254
- }
273
+ },
274
+ [OPEN]: `inset 0 0 0 1px ${colors.borderStrong}, 0 6px 16px -6px ${colors.shadow}`
255
275
  }
256
276
  },
257
277
  // What cannot be undone, as a solid: the one press a dialog is asking for
@@ -433,6 +453,7 @@
433
453
  loading = false,
434
454
  loadingLabel,
435
455
  disabled = false,
456
+ pressed,
436
457
  iconOnly = false,
437
458
  href,
438
459
  type = 'button',
@@ -500,6 +521,7 @@
500
521
  data-icons
501
522
  {type}
502
523
  disabled={disabled || undefined}
524
+ aria-pressed={pressed}
503
525
  aria-disabled={loading ? true : undefined}
504
526
  aria-busy={loading ? true : undefined}
505
527
  {...rest}
@@ -24,6 +24,13 @@ export type ButtonProps = Omit<HTMLButtonAttributes & HTMLAnchorAttributes, 'chi
24
24
  */
25
25
  loadingLabel?: string | undefined;
26
26
  disabled?: boolean | undefined;
27
+ /**
28
+ * Makes it a toggle button (`aria-pressed`), held in its open look while true: a
29
+ * toolbar's button that shows or hides something. `secondary` and `ghost` take the fill
30
+ * of what is chosen, `floating` its stronger edge, `bare` its full ink. For a toggle lit
31
+ * in the accent, use Toggle.
32
+ */
33
+ pressed?: boolean | undefined;
27
34
  /** Square button for a single icon. Give it an `aria-label`. */
28
35
  iconOnly?: boolean | undefined;
29
36
  /** Renders a link styled as a button. */
@@ -20,18 +20,40 @@
20
20
  disabled?: boolean | undefined;
21
21
  };
22
22
 
23
- export type ComposerModelPickerProps = Omit<HTMLButtonAttributes, 'children' | 'value'> & {
23
+ type PickerBase = Omit<HTMLButtonAttributes, 'children' | 'value' | 'onchange'> & {
24
24
  models: ComposerModel[];
25
- /** The chosen model's value. Bindable. Defaults to the first model. */
26
- value?: string | undefined;
27
25
  /** What is being chosen. Names the list, and is read before the model on the button. */
28
26
  label?: string | undefined;
29
- /** Called when the person picks a model. */
30
- onchange?: ((value: string) => void) | undefined;
27
+ /** Whether the list is showing. Bindable. */
28
+ open?: boolean | undefined;
29
+ /** Called when the list opens or closes. */
30
+ onopenchange?: ((open: boolean) => void) | undefined;
31
31
  sx?: Sx | undefined;
32
32
  ref?: HTMLButtonElement | null | undefined;
33
33
  };
34
34
 
35
+ export type ComposerModelPickerProps = PickerBase &
36
+ (
37
+ | {
38
+ /** Lets several models be chosen, such as to run one prompt on each. */
39
+ multiple?: false | undefined;
40
+ /** The chosen model's value. Bindable. Defaults to the first model. */
41
+ value?: string | undefined;
42
+ /** Called when the person picks a model. */
43
+ onchange?: ((value: string) => void) | undefined;
44
+ placeholder?: undefined;
45
+ }
46
+ | {
47
+ multiple: true;
48
+ /** The chosen models' values, in the order of `models`. Bindable. */
49
+ value?: string[] | undefined;
50
+ /** Called with every chosen model's value when the person picks or drops one. */
51
+ onchange?: ((value: string[]) => void) | undefined;
52
+ /** What the button says while none is chosen. */
53
+ placeholder?: string | undefined;
54
+ }
55
+ );
56
+
35
57
  const GAP = 6;
36
58
  const MARGIN = 8;
37
59
 
@@ -76,6 +98,7 @@
76
98
  overflow: 'hidden',
77
99
  textOverflow: 'ellipsis'
78
100
  },
101
+ more: { flexShrink: 0, color: colors.textSubtle, fontVariantNumeric: 'tabular-nums' },
79
102
  selector: { display: 'grid', flexShrink: 0, opacity: 0.7 },
80
103
 
81
104
  // The list floats in the top layer, placed beside the button by script.
@@ -216,10 +239,16 @@
216
239
  </script>
217
240
 
218
241
  <script lang="ts">
242
+ import { untrack } from 'svelte';
243
+
219
244
  let {
220
245
  models,
221
246
  value = $bindable(),
222
247
  label = 'Model',
248
+ multiple = false,
249
+ placeholder = 'Choose models',
250
+ open = $bindable(false),
251
+ onopenchange,
223
252
  onchange,
224
253
  disabled,
225
254
  sx,
@@ -235,14 +264,26 @@
235
264
 
236
265
  let popover = $state<HTMLDivElement | null>(null);
237
266
  let list = $state<HTMLDivElement | null>(null);
238
- let open = $state(false);
239
267
  let active = $state<string>();
240
268
 
241
269
  const groups = $derived(groupModels(models));
242
270
  const enabled = $derived(models.filter((model) => !model.disabled));
243
- const selected = $derived(models.find((model) => model.value === value) ?? models[0]);
271
+ // The chosen models, in the list's order. One at most, and the first by default, unless several may be.
272
+ const chosen = $derived.by((): ComposerModel[] => {
273
+ if (multiple) {
274
+ const values = Array.isArray(value) ? value : [];
275
+ return models.filter((model) => values.includes(model.value));
276
+ }
277
+ const one = models.find((model) => model.value === value) ?? models[0];
278
+ return one ? [one] : [];
279
+ });
280
+ const selected = $derived(chosen[0]);
281
+ const isChosen = (model: ComposerModel) => chosen.includes(model);
244
282
  const optionId = (model: ComposerModel) => `${uid}-option-${models.indexOf(model)}`;
245
283
  const activeModel = $derived(models.find((model) => model.value === active));
284
+ const said = $derived(
285
+ chosen.length ? chosen.map((model) => model.label).join(', ') : multiple ? placeholder : ''
286
+ );
246
287
 
247
288
  function show() {
248
289
  active = selected && !selected.disabled ? selected.value : enabled[0]?.value;
@@ -260,8 +301,17 @@
260
301
 
261
302
  function choose(model: ComposerModel) {
262
303
  if (model.disabled) return;
304
+ if (multiple) {
305
+ // Several may be chosen: the list stays open to choose the next
306
+ const values = isChosen(model)
307
+ ? chosen.filter((m) => m !== model).map((m) => m.value)
308
+ : models.filter((m) => m === model || isChosen(m)).map((m) => m.value);
309
+ value = values;
310
+ (onchange as ((value: string[]) => void) | undefined)?.(values);
311
+ return;
312
+ }
263
313
  value = model.value;
264
- onchange?.(model.value);
314
+ (onchange as ((value: string) => void) | undefined)?.(model.value);
265
315
  hide();
266
316
  }
267
317
 
@@ -291,13 +341,28 @@
291
341
  }
292
342
 
293
343
  function ontoggle(event: ToggleEvent) {
294
- open = event.newState === 'open';
295
- if (!open && popover?.contains(document.activeElement)) {
344
+ const next = event.newState === 'open';
345
+ if (next !== open) {
346
+ open = next;
347
+ onopenchange?.(next);
348
+ }
349
+ if (!next && popover?.contains(document.activeElement)) {
296
350
  // Closed by Escape or a click outside while the list had focus
297
351
  ref?.focus();
298
352
  }
299
353
  }
300
354
 
355
+ // `open`, set from outside: the list follows it
356
+ $effect(() => {
357
+ const want = open;
358
+ if (!popover) return;
359
+ untrack(() => {
360
+ const shown = popover!.matches(':popover-open');
361
+ if (want && !shown) show();
362
+ else if (!want && shown) hide(popover!.contains(document.activeElement));
363
+ });
364
+ });
365
+
301
366
  $effect(() => {
302
367
  if (!open) return;
303
368
  const reposition = () => place();
@@ -392,7 +457,7 @@
392
457
  aria-haspopup="listbox"
393
458
  aria-expanded={open}
394
459
  aria-controls="{uid}-popover"
395
- aria-label="{label}: {selected?.label ?? ''}"
460
+ aria-label="{label}: {said}"
396
461
  disabled={disabled ?? composer?.disabled}
397
462
  data-slot="composer-model-picker"
398
463
  {...rest}
@@ -405,7 +470,8 @@
405
470
  }}
406
471
  onkeydown={onTriggerKeydown}
407
472
  >
408
- <span {...stylex.attrs(styles.triggerText)}>{selected?.label}</span>
473
+ <span {...stylex.attrs(styles.triggerText)}>{selected?.label ?? said}</span>
474
+ {#if chosen.length > 1}<span {...stylex.attrs(styles.more)}>+{chosen.length - 1}</span>{/if}
409
475
  <span {...stylex.attrs(styles.selector)}><Glyph name="selector" size={14} /></span>
410
476
  </button>
411
477
 
@@ -422,6 +488,7 @@
422
488
  role="listbox"
423
489
  tabindex="-1"
424
490
  aria-label={label}
491
+ aria-multiselectable={multiple || undefined}
425
492
  aria-activedescendant={activeModel ? optionId(activeModel) : undefined}
426
493
  {...stylex.attrs(styles.list)}
427
494
  onkeydown={onListKeydown}
@@ -436,7 +503,7 @@
436
503
  <div id="{uid}-group-{g}" {...stylex.attrs(styles.groupLabel)}>{group.name}</div>
437
504
  {/if}
438
505
  {#each group.models as model (model.value)}
439
- {@const isSelected = model.value === selected?.value}
506
+ {@const isSelected = isChosen(model)}
440
507
  <!-- The list handles the keyboard for every option; this click is for the pointer -->
441
508
  <div
442
509
  id={optionId(model)}
@@ -11,17 +11,34 @@ export type ComposerModel = {
11
11
  badge?: string | undefined;
12
12
  disabled?: boolean | undefined;
13
13
  };
14
- export type ComposerModelPickerProps = Omit<HTMLButtonAttributes, 'children' | 'value'> & {
14
+ type PickerBase = Omit<HTMLButtonAttributes, 'children' | 'value' | 'onchange'> & {
15
15
  models: ComposerModel[];
16
- /** The chosen model's value. Bindable. Defaults to the first model. */
17
- value?: string | undefined;
18
16
  /** What is being chosen. Names the list, and is read before the model on the button. */
19
17
  label?: string | undefined;
20
- /** Called when the person picks a model. */
21
- onchange?: ((value: string) => void) | undefined;
18
+ /** Whether the list is showing. Bindable. */
19
+ open?: boolean | undefined;
20
+ /** Called when the list opens or closes. */
21
+ onopenchange?: ((open: boolean) => void) | undefined;
22
22
  sx?: Sx | undefined;
23
23
  ref?: HTMLButtonElement | null | undefined;
24
24
  };
25
- declare const ComposerModelPicker: import("svelte").Component<ComposerModelPickerProps, {}, "value" | "ref">;
25
+ export type ComposerModelPickerProps = PickerBase & ({
26
+ /** Lets several models be chosen, such as to run one prompt on each. */
27
+ multiple?: false | undefined;
28
+ /** The chosen model's value. Bindable. Defaults to the first model. */
29
+ value?: string | undefined;
30
+ /** Called when the person picks a model. */
31
+ onchange?: ((value: string) => void) | undefined;
32
+ placeholder?: undefined;
33
+ } | {
34
+ multiple: true;
35
+ /** The chosen models' values, in the order of `models`. Bindable. */
36
+ value?: string[] | undefined;
37
+ /** Called with every chosen model's value when the person picks or drops one. */
38
+ onchange?: ((value: string[]) => void) | undefined;
39
+ /** What the button says while none is chosen. */
40
+ placeholder?: string | undefined;
41
+ });
42
+ declare const ComposerModelPicker: import("svelte").Component<ComposerModelPickerProps, {}, "value" | "ref" | "open">;
26
43
  type ComposerModelPicker = ReturnType<typeof ComposerModelPicker>;
27
44
  export default ComposerModelPicker;