@diegopluna/narvi 0.3.4 → 0.3.6

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 (63) hide show
  1. package/dist/components/app-shell/AppShellPanel.svelte +35 -4
  2. package/dist/components/badge/Badge.svelte +13 -1
  3. package/dist/components/badge/Badge.svelte.d.ts +6 -0
  4. package/dist/components/button/Button.svelte +80 -33
  5. package/dist/components/button/Button.svelte.d.ts +18 -0
  6. package/dist/components/command/CommandDialog.svelte +24 -2
  7. package/dist/components/command/CommandDialog.svelte.d.ts +12 -0
  8. package/dist/components/command/CommandItem.svelte +15 -4
  9. package/dist/components/command/CommandItem.svelte.d.ts +20 -4
  10. package/dist/components/command/CommandRoot.svelte +57 -2
  11. package/dist/components/command/CommandRoot.svelte.d.ts +25 -1
  12. package/dist/components/composer/ComposerModelPicker.svelte +608 -53
  13. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +56 -1
  14. package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
  15. package/dist/components/composer/ComposerSubmit.svelte +12 -2
  16. package/dist/components/composer/ComposerSubmit.svelte.d.ts +6 -0
  17. package/dist/components/composer/index.d.ts +1 -1
  18. package/dist/components/input/Input.svelte.d.ts +1 -1
  19. package/dist/components/menu/MenuCheckboxItem.svelte +14 -5
  20. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +15 -4
  21. package/dist/components/menu/MenuItem.svelte +9 -3
  22. package/dist/components/menu/MenuItem.svelte.d.ts +11 -4
  23. package/dist/components/menu/MenuRadioItem.svelte +18 -9
  24. package/dist/components/menu/MenuRadioItem.svelte.d.ts +15 -4
  25. package/dist/components/menu/MenuSubTrigger.svelte +9 -3
  26. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +11 -4
  27. package/dist/components/questionnaire/Questionnaire.svelte +100 -9
  28. package/dist/components/questionnaire/Questionnaire.svelte.d.ts +11 -0
  29. package/dist/components/queued-message/QueuedMessage.svelte +3 -2
  30. package/dist/components/rail/RailRoot.svelte +3 -3
  31. package/dist/components/segmented/SegmentedControl.svelte +2 -1
  32. package/dist/components/select/Select.svelte +11 -1
  33. package/dist/components/select/Select.svelte.d.ts +5 -0
  34. package/dist/components/settings-row/SettingsRow.svelte +3 -2
  35. package/dist/components/slider/Slider.svelte.d.ts +2 -2
  36. package/dist/components/split-button/SplitButton.svelte +14 -1
  37. package/dist/components/split-button/SplitButton.svelte.d.ts +7 -0
  38. package/dist/components/tab-strip/TabStrip.svelte +77 -20
  39. package/dist/components/tab-strip/TabStrip.svelte.d.ts +16 -3
  40. package/dist/components/tabs/Tabs.svelte +2 -1
  41. package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
  42. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +1 -1
  43. package/dist/components/tooltip/TooltipProvider.svelte +23 -0
  44. package/dist/components/tooltip/TooltipProvider.svelte.d.ts +8 -0
  45. package/dist/components/tooltip/index.d.ts +4 -5
  46. package/dist/components/tooltip/index.js +3 -5
  47. package/dist/index.d.ts +3 -3
  48. package/dist/internal/ItemDescription.svelte +34 -0
  49. package/dist/internal/ItemDescription.svelte.d.ts +10 -0
  50. package/dist/internal/TooltipScope.svelte +19 -0
  51. package/dist/internal/TooltipScope.svelte.d.ts +7 -0
  52. package/dist/internal/roving.d.ts +3 -1
  53. package/dist/internal/roving.js +6 -3
  54. package/dist/media.stylex.d.ts +6 -0
  55. package/dist/media.stylex.js +6 -0
  56. package/dist/vite.js +4 -0
  57. package/package.json +20 -1
  58. package/skills/building-ui/SKILL.md +45 -37
  59. package/skills/building-ui/references/components.md +42 -42
  60. package/skills/markdown/SKILL.md +1 -1
  61. package/skills/setup/SKILL.md +1 -1
  62. package/skills/styling/SKILL.md +11 -2
  63. package/skills/theming/SKILL.md +1 -1
@@ -1,12 +1,14 @@
1
1
  <!--
2
2
  The agent asks the person questions, one at a time. Keys 1 to 9 pick an
3
- answer, Enter goes on, ⌘Enter sends them all once each is answered or
4
- skipped. Each question's prompt takes focus as it arrives, so it is read
5
- out. Once answered, it folds into what was said, a secret answer hidden.
3
+ answer, the up and down arrows move between the answers and the field for
4
+ one's own, the left and right arrows go back and on, Enter goes on, and
5
+ ⌘Enter sends them all once each is answered or skipped. Each question's
6
+ prompt takes focus as it arrives, so it is read out. Once answered, it folds
7
+ into what was said, a secret answer hidden.
6
8
  -->
7
9
  <script lang="ts" module>
8
10
  import * as stylex from '@stylexjs/stylex';
9
- import { tick } from 'svelte';
11
+ import { tick, type Snippet } from 'svelte';
10
12
  import { shared } from '../../internal/shared.js';
11
13
  import { attrs, type Sx } from '../../internal/sx.js';
12
14
  import { colors, font, radius, space } from '../../tokens.stylex.js';
@@ -53,6 +55,16 @@
53
55
  * pressed or changed.
54
56
  */
55
57
  busy?: boolean | undefined;
58
+ /**
59
+ * What the questions are about, at the start of the top row, with "Question 2 of 3" at
60
+ * its end: an icon and the agent's title for them, say.
61
+ */
62
+ heading?: Snippet | undefined;
63
+ /**
64
+ * Leaves out the card's fill, edge and padding, for questions put in a card of your own,
65
+ * such as the one an agent's turn shows what waits on the person in.
66
+ */
67
+ bare?: boolean | undefined;
56
68
  labels?:
57
69
  | Partial<
58
70
  Record<
@@ -95,7 +107,27 @@
95
107
  backgroundColor: colors.bgRaised,
96
108
  boxShadow: `inset 0 0 0 1px color-mix(in oklab, ${colors.accent} 35%, transparent)`
97
109
  },
110
+ // No card of its own: what holds it draws one
111
+ bare: { padding: 0, borderRadius: 0, backgroundColor: 'transparent', boxShadow: 'none' },
98
112
  head: { display: 'flex', flexDirection: 'column', gap: '0.5rem' },
113
+ // The heading at the start, the count at the end, on one line while they fit
114
+ headRow: {
115
+ display: 'flex',
116
+ flexWrap: 'wrap',
117
+ alignItems: 'center',
118
+ justifyContent: 'space-between',
119
+ columnGap: space.x3,
120
+ rowGap: '0.25rem',
121
+ minWidth: 0
122
+ },
123
+ heading: {
124
+ '--narvi-icon-size': '1rem',
125
+ display: 'flex',
126
+ alignItems: 'center',
127
+ gap: '0.5rem',
128
+ minWidth: 0,
129
+ fontWeight: font.weightMedium
130
+ },
99
131
  count: { color: colors.accent },
100
132
  prompt: {
101
133
  margin: 0,
@@ -183,6 +215,8 @@
183
215
  ondecline,
184
216
  answered,
185
217
  busy = false,
218
+ heading,
219
+ bare = false,
186
220
  labels,
187
221
  sx,
188
222
  class: className
@@ -194,6 +228,7 @@
194
228
  let answers = $state<QuestionnaireAnswers>({});
195
229
  let error = $state('');
196
230
  let prompt = $state<HTMLElement | null>(null);
231
+ let card = $state<HTMLElement | null>(null);
197
232
 
198
233
  const question = $derived(questions[index]);
199
234
  const answer = $derived(answers[question?.id] ?? { choices: [] });
@@ -252,8 +287,22 @@
252
287
  error = word.unanswered;
253
288
  }
254
289
 
290
+ // The up and down arrows go through the answers as they are shown: each choice, then the
291
+ // field for one's own. On a radio, arriving picks it, as a radio group's own arrows do.
292
+ function moveAnswer(from: HTMLElement, step: number) {
293
+ const all = [...(card?.querySelectorAll<HTMLElement>('[data-answer]') ?? [])];
294
+ const at = all.indexOf(from);
295
+ if (at === -1 || all.length < 2) return false;
296
+ const to = all[(at + step + all.length) % all.length];
297
+ to.focus();
298
+ if (to instanceof HTMLInputElement && to.type === 'radio' && to.dataset.answer) {
299
+ pick(to.dataset.answer);
300
+ }
301
+ return true;
302
+ }
303
+
255
304
  function onkeydown(event: KeyboardEvent) {
256
- if (event.isComposing) return;
305
+ if (event.isComposing || event.defaultPrevented) return;
257
306
  if (busy) {
258
307
  if (event.key === 'Enter') event.preventDefault();
259
308
  return;
@@ -263,6 +312,33 @@
263
312
  const field =
264
313
  target instanceof HTMLInputElement && target.type !== 'radio' && target.type !== 'checkbox';
265
314
  const typing = target instanceof HTMLTextAreaElement || field;
315
+ const radio = target instanceof HTMLInputElement && target.type === 'radio';
316
+ const plain = !event.metaKey && !event.ctrlKey && !event.altKey && !event.shiftKey;
317
+ if (
318
+ plain &&
319
+ (event.key === 'ArrowDown' || event.key === 'ArrowUp') &&
320
+ target instanceof HTMLElement &&
321
+ target.hasAttribute('data-answer') &&
322
+ // In a field with words in it, the arrows move through the words
323
+ !(typing && (target as HTMLInputElement | HTMLTextAreaElement).value)
324
+ ) {
325
+ if (moveAnswer(target, event.key === 'ArrowDown' ? 1 : -1)) event.preventDefault();
326
+ return;
327
+ }
328
+ // Left and right go back and on, except where they move through words or a radio group.
329
+ // On goes only past a question answered or skipped; right to left, the two trade places.
330
+ if (plain && !typing && !radio && (event.key === 'ArrowLeft' || event.key === 'ArrowRight')) {
331
+ const rtl = !!card && getComputedStyle(card).direction === 'rtl';
332
+ const back = (event.key === 'ArrowLeft') !== rtl;
333
+ if (back && index > 0) {
334
+ event.preventDefault();
335
+ go(index - 1);
336
+ } else if (!back && !last && given(answers[question.id])) {
337
+ event.preventDefault();
338
+ go(index + 1);
339
+ }
340
+ return;
341
+ }
266
342
  if (event.key === 'Enter' && (event.metaKey || event.ctrlKey)) {
267
343
  event.preventDefault();
268
344
  sendAll();
@@ -307,13 +383,25 @@
307
383
  aria-labelledby="{uid}-prompt"
308
384
  data-slot="questionnaire"
309
385
  aria-busy={busy || undefined}
310
- {...attrs([styles.card, sx], className)}
386
+ bind:this={card}
387
+ {...attrs([styles.card, bare && styles.bare, sx], className)}
311
388
  {onkeydown}
312
389
  >
313
390
  <div {...stylex.attrs(styles.head)}>
314
- <span {...stylex.attrs(shared.eyebrow, styles.count)}
315
- >Question {index + 1} of {questions.length}</span
316
- >
391
+ {#if heading}
392
+ <div {...stylex.attrs(styles.headRow)}>
393
+ <div data-icons {...stylex.attrs(styles.heading)}>{@render heading()}</div>
394
+ {#if questions.length > 1}
395
+ <span {...stylex.attrs(shared.eyebrow, styles.count)}
396
+ >Question {index + 1} of {questions.length}</span
397
+ >
398
+ {/if}
399
+ </div>
400
+ {:else}
401
+ <span {...stylex.attrs(shared.eyebrow, styles.count)}
402
+ >Question {index + 1} of {questions.length}</span
403
+ >
404
+ {/if}
317
405
  {#if questions.length > 1}
318
406
  <Progress
319
407
  value={index + 1}
@@ -342,6 +430,7 @@
342
430
  type={question.multiple ? 'checkbox' : 'radio'}
343
431
  name="{uid}-{question.id}"
344
432
  checked={answer.choices.includes(choice.label)}
433
+ data-answer={choice.label}
345
434
  onchange={() => pick(choice.label)}
346
435
  {...stylex.attrs(styles.input, question.multiple && styles.box)}
347
436
  />
@@ -367,6 +456,7 @@
367
456
  aria-label={typeof question.other === 'string' ? question.other : 'Your answer'}
368
457
  aria-describedby={question.description ? `${uid}-about` : undefined}
369
458
  placeholder={typeof question.other === 'string' ? question.other : 'Your answer'}
459
+ data-answer=""
370
460
  value={answer.other ?? ''}
371
461
  oninput={(event) => set({ ...answer, skipped: false, other: event.currentTarget.value })}
372
462
  />
@@ -378,6 +468,7 @@
378
468
  rows={2}
379
469
  aria-label={typeof question.other === 'string' ? question.other : 'Your answer'}
380
470
  placeholder={typeof question.other === 'string' ? question.other : 'Your answer'}
471
+ data-answer=""
381
472
  value={answer.other ?? ''}
382
473
  oninput={(event) => set({ ...answer, skipped: false, other: event.currentTarget.value })}
383
474
  />
@@ -1,3 +1,4 @@
1
+ import { type Snippet } from 'svelte';
1
2
  import { type Sx } from '../../internal/sx.js';
2
3
  export type Question = {
3
4
  id: string;
@@ -36,6 +37,16 @@ export type QuestionnaireProps = {
36
37
  * pressed or changed.
37
38
  */
38
39
  busy?: boolean | undefined;
40
+ /**
41
+ * What the questions are about, at the start of the top row, with "Question 2 of 3" at
42
+ * its end: an icon and the agent's title for them, say.
43
+ */
44
+ heading?: Snippet | undefined;
45
+ /**
46
+ * Leaves out the card's fill, edge and padding, for questions put in a card of your own,
47
+ * such as the one an agent's turn shows what waits on the person in.
48
+ */
49
+ bare?: boolean | undefined;
39
50
  labels?: Partial<Record<'next' | 'back' | 'skip' | 'send' | 'decline' | 'required' | 'unanswered' | 'skipped' | 'hidden', string>> | undefined;
40
51
  sx?: Sx | undefined;
41
52
  class?: string | undefined;
@@ -12,6 +12,7 @@
12
12
  import Button from '../button/Button.svelte';
13
13
  import { text, type MessageTextSize } from '../message/styles.js';
14
14
  import * as Tooltip from '../tooltip/index.js';
15
+ import TooltipScope from '../../internal/TooltipScope.svelte';
15
16
 
16
17
  export type QueuedMessageStatus = 'queued' | 'editing' | 'unsent';
17
18
 
@@ -151,7 +152,7 @@
151
152
  {...stylex.attrs(styles.status, status === 'unsent' && styles.unsent)}
152
153
  >{statusText ?? STATUS[status]}</span
153
154
  >
154
- <Tooltip.Provider delayDuration={400}>
155
+ <TooltipScope>
155
156
  {#each actions as [key, handler, icon, fallback] (key)}
156
157
  {@const label = labels?.[key] ?? fallback}
157
158
  <Tooltip.Root>
@@ -173,6 +174,6 @@
173
174
  <Tooltip.Content>{label}</Tooltip.Content>
174
175
  </Tooltip.Root>
175
176
  {/each}
176
- </Tooltip.Provider>
177
+ </TooltipScope>
177
178
  </div>
178
179
  </div>
@@ -11,7 +11,7 @@
11
11
  import type { HTMLAttributes } from 'svelte/elements';
12
12
  import { roving } from '../../internal/roving.js';
13
13
  import { attrs, type Sx } from '../../internal/sx.js';
14
- import * as Tooltip from '../tooltip/index.js';
14
+ import TooltipScope from '../../internal/TooltipScope.svelte';
15
15
 
16
16
  export type RailRootProps = Omit<HTMLAttributes<HTMLElement>, 'children'> & {
17
17
  /** Names it for assistive technology: "Workspaces". */
@@ -54,7 +54,7 @@
54
54
  {...attrs([styles.rail, sx], className)}
55
55
  {@attach roving({ selector: '[data-rail-item]' })}
56
56
  >
57
- <Tooltip.Provider delayDuration={400}>
57
+ <TooltipScope>
58
58
  {@render children?.()}
59
- </Tooltip.Provider>
59
+ </TooltipScope>
60
60
  </nav>
@@ -9,6 +9,7 @@
9
9
  import '../../internal/icons.css';
10
10
  import { groupTrigger } from '../../internal/tooltip-trigger.js';
11
11
  import * as Tooltip from '../tooltip/index.js';
12
+ import TooltipScope from '../../internal/TooltipScope.svelte';
12
13
 
13
14
  export type SegmentedOption = {
14
15
  value: string;
@@ -217,7 +218,7 @@
217
218
  {/each}
218
219
  {/snippet}
219
220
  {#if titled}
220
- <Tooltip.Provider delayDuration={400}>{@render segments()}</Tooltip.Provider>
221
+ <TooltipScope>{@render segments()}</TooltipScope>
221
222
  {:else}
222
223
  {@render segments()}
223
224
  {/if}
@@ -40,6 +40,11 @@
40
40
  value?: string | undefined;
41
41
  /** Shown while nothing is chosen. */
42
42
  placeholder?: string | undefined;
43
+ /**
44
+ * Words on the trigger before the chosen option, muted, that say what it sets: "Text size"
45
+ * before "Default". They are part of its name, so it needs no `aria-label`.
46
+ */
47
+ prefix?: string | undefined;
43
48
  /**
44
49
  * Draws each option's icon, in the list and on the trigger, in place of `option.icon`:
45
50
  * for an icon that takes props, such as a provider's mark in its colours, or a dot.
@@ -77,6 +82,7 @@
77
82
  whiteSpace: 'nowrap'
78
83
  },
79
84
  placeholder: { color: colors.textSubtle },
85
+ prefix: { flexShrink: 0, color: colors.textMuted },
80
86
  // The chosen option's icon, on the trigger
81
87
  icon: {
82
88
  '--narvi-icon-size': '1rem',
@@ -113,6 +119,7 @@
113
119
  options,
114
120
  value = $bindable(),
115
121
  placeholder = 'Choose…',
122
+ prefix,
116
123
  optionIcon,
117
124
  size = 'md',
118
125
  align = 'start',
@@ -142,7 +149,7 @@
142
149
  >
143
150
  <Select.Trigger
144
151
  id={id ?? field?.id}
145
- aria-label={label}
152
+ aria-label={label ?? (prefix ? `${prefix} ${selected?.label ?? placeholder}` : undefined)}
146
153
  aria-describedby={describedBy ?? field?.describedBy}
147
154
  data-slot="select"
148
155
  {...attrs([control.base, control[size], styles.trigger, sx], className)}
@@ -154,6 +161,7 @@
154
161
  {:else if selected?.icon}
155
162
  <span data-icons {...stylex.attrs(styles.icon)}><selected.icon aria-hidden="true" /></span>
156
163
  {/if}
164
+ {#if prefix}<span {...stylex.attrs(styles.prefix)}>{prefix}</span>{/if}
157
165
  <span {...stylex.attrs(styles.value, !selected && styles.placeholder)}>
158
166
  {selected?.label ?? placeholder}
159
167
  </span>
@@ -163,6 +171,8 @@
163
171
  <Select.Content {align} sideOffset={6} collisionPadding={8} {...stylex.attrs(layer.surface)}>
164
172
  <Select.Viewport>
165
173
  {#each groups as group, index (index)}
174
+ <!-- A hairline between groups, as a menu draws between its parts -->
175
+ {#if index > 0}<div aria-hidden="true" {...stylex.attrs(layer.separator)}></div>{/if}
166
176
  <Select.Group>
167
177
  {#if group.name}
168
178
  <Select.GroupHeading {...stylex.attrs(layer.heading)}
@@ -28,6 +28,11 @@ export type SelectProps = {
28
28
  value?: string | undefined;
29
29
  /** Shown while nothing is chosen. */
30
30
  placeholder?: string | undefined;
31
+ /**
32
+ * Words on the trigger before the chosen option, muted, that say what it sets: "Text size"
33
+ * before "Default". They are part of its name, so it needs no `aria-label`.
34
+ */
35
+ prefix?: string | undefined;
31
36
  /**
32
37
  * Draws each option's icon, in the list and on the trigger, in place of `option.icon`:
33
38
  * for an icon that takes props, such as a provider's mark in its colours, or a dot.
@@ -15,6 +15,7 @@
15
15
  import { media } from '../../media.stylex.js';
16
16
  import { typography } from '../../typography.js';
17
17
  import * as Tooltip from '../tooltip/index.js';
18
+ import TooltipScope from '../../internal/TooltipScope.svelte';
18
19
  import { getSettingsGroupContext } from '../settings-group/context.js';
19
20
  import '../../internal/icons.css';
20
21
 
@@ -222,7 +223,7 @@
222
223
  <span id={control.labelId} {...stylex.attrs(...labelStyles)}>{label}</span>
223
224
  {/if}
224
225
  {#if about}
225
- <Tooltip.Provider delayDuration={400}>
226
+ <TooltipScope>
226
227
  <Tooltip.Root>
227
228
  <Tooltip.Trigger>
228
229
  {#snippet child({ props })}
@@ -238,7 +239,7 @@
238
239
  </Tooltip.Trigger>
239
240
  <Tooltip.Content side="top">{about}</Tooltip.Content>
240
241
  </Tooltip.Root>
241
- </Tooltip.Provider>
242
+ </TooltipScope>
242
243
  {/if}
243
244
  </span>
244
245
  {#if description}
@@ -32,7 +32,7 @@ export type SliderProps<T extends number | number[] = number> = Omit<HTMLAttribu
32
32
  declare function $$render<T extends number | number[] = number>(): {
33
33
  props: SliderProps<T>;
34
34
  exports: {};
35
- bindings: "value" | "ref";
35
+ bindings: "ref" | "value";
36
36
  slots: {};
37
37
  events: {};
38
38
  };
@@ -40,7 +40,7 @@ declare class __sveltets_Render<T extends number | number[] = number> {
40
40
  props(): ReturnType<typeof $$render<T>>['props'];
41
41
  events(): ReturnType<typeof $$render<T>>['events'];
42
42
  slots(): ReturnType<typeof $$render<T>>['slots'];
43
- bindings(): "value" | "ref";
43
+ bindings(): "ref" | "value";
44
44
  exports(): {};
45
45
  }
46
46
  interface $$IsomorphicComponent {
@@ -33,6 +33,13 @@
33
33
  menuWidth?: string | undefined;
34
34
  /** Whether the menu is open. Bindable. */
35
35
  open?: boolean | undefined;
36
+ /** Called as the menu opens or closes: to fetch what it lists as it opens, say. */
37
+ onopenchange?: ((open: boolean) => void) | undefined;
38
+ /**
39
+ * A tooltip on the button that opens the menu, as `tooltip` is on the main one: words, or a
40
+ * snippet with a shortcut. It opens on the side `tooltipSide` names, as the main one's does.
41
+ */
42
+ menuTooltip?: string | Snippet | undefined;
36
43
  /** On the group, which holds both halves. */
37
44
  sx?: Sx | undefined;
38
45
  /** The main button's label, and its icon if it has one. */
@@ -79,6 +86,9 @@
79
86
  align = 'end',
80
87
  menuWidth,
81
88
  open = $bindable(false),
89
+ onopenchange,
90
+ menuTooltip,
91
+ tooltipSide,
82
92
  disabled = false,
83
93
  loading = false,
84
94
  sx,
@@ -104,12 +114,13 @@
104
114
  {size}
105
115
  {disabled}
106
116
  {loading}
117
+ {tooltipSide}
107
118
  sx={[styles.half, menu && styles.main]}
108
119
  >
109
120
  {@render children?.()}
110
121
  </Button>
111
122
  {#if menu}
112
- <Menu.Root bind:open>
123
+ <Menu.Root bind:open onOpenChange={onopenchange}>
113
124
  <Menu.Trigger disabled={disabled || loading}>
114
125
  {#snippet child({ props })}
115
126
  <Button
@@ -118,6 +129,8 @@
118
129
  {size}
119
130
  disabled={disabled || loading}
120
131
  aria-label={menuLabel}
132
+ tooltip={menuTooltip}
133
+ {tooltipSide}
121
134
  sx={[
122
135
  styles.half,
123
136
  styles.more,
@@ -19,6 +19,13 @@ export type SplitButtonProps = Omit<ButtonProps, 'variant' | 'iconOnly' | 'href'
19
19
  menuWidth?: string | undefined;
20
20
  /** Whether the menu is open. Bindable. */
21
21
  open?: boolean | undefined;
22
+ /** Called as the menu opens or closes: to fetch what it lists as it opens, say. */
23
+ onopenchange?: ((open: boolean) => void) | undefined;
24
+ /**
25
+ * A tooltip on the button that opens the menu, as `tooltip` is on the main one: words, or a
26
+ * snippet with a shortcut. It opens on the side `tooltipSide` names, as the main one's does.
27
+ */
28
+ menuTooltip?: string | Snippet | undefined;
22
29
  /** On the group, which holds both halves. */
23
30
  sx?: Sx | undefined;
24
31
  /** The main button's label, and its icon if it has one. */
@@ -22,6 +22,7 @@
22
22
  import { tabStripTabMarker } from '../../internal/markers.stylex.js';
23
23
  import { roving } from '../../internal/roving.js';
24
24
  import * as ContextMenu from '../menu/context-menu.js';
25
+ import * as Menu from '../menu/index.js';
25
26
  import { TabDragging, tabOffset } from './drag.svelte.js';
26
27
  import { attrs, type Sx } from '../../internal/sx.js';
27
28
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
@@ -42,18 +43,33 @@
42
43
  renamable?: boolean | undefined;
43
44
  };
44
45
 
45
- export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclose'> & {
46
+ export type TabStripProps = Omit<
47
+ HTMLAttributes<HTMLDivElement>,
48
+ 'children' | 'onclose' | 'onchange'
49
+ > & {
46
50
  tabs: TabStripTab[];
47
51
  /** The id of the open tab. Bindable. */
48
52
  value?: string | undefined;
53
+ /** Called as a tab is opened: clicked, or reached with the arrow keys. */
54
+ onchange?: ((id: string) => void) | undefined;
55
+ /**
56
+ * `automatic` opens the tab the arrow keys reach, as a browser's tabs do; `manual` only moves
57
+ * the focus, and Enter or Space opens it, for tabs slow to show.
58
+ */
59
+ activation?: 'automatic' | 'manual' | undefined;
49
60
  /** Names the strip: "Open threads". */
50
61
  label: string;
51
62
  /** The id of the panel the tabs show. */
52
63
  controls?: string | undefined;
53
64
  /** Called to close a tab. Without it the tabs cannot be closed. */
54
65
  onclose?: ((id: string) => void) | undefined;
55
- /** Called to add one. Without it there is no button to add. */
66
+ /** Called to add one. Without it, or `addMenu`, there is no button to add. */
56
67
  onadd?: (() => void) | undefined;
68
+ /**
69
+ * What can be added, as Menu parts: the button to add opens them, in place of calling
70
+ * `onadd`. For a strip that opens several kinds of tab: a file, a page, a terminal.
71
+ */
72
+ addMenu?: Snippet | undefined;
57
73
  addLabel?: string | undefined;
58
74
  /** The name of a tab's close button. */
59
75
  closeLabel?: ((tab: TabStripTab) => string) | undefined;
@@ -77,7 +93,8 @@
77
93
  onmove?: ((id: string, index: number) => void) | undefined;
78
94
  /**
79
95
  * Called with a tab's new name, as Enter is pressed. Without it the tabs cannot be
80
- * renamed. Renaming starts on a double-click, on F2, or as `renaming` is set.
96
+ * renamed. Renaming starts on a double-click, on F2, or as `renaming` is set. A name
97
+ * cleared is passed as `''`, for the tab to take back a name of its own.
81
98
  */
82
99
  onrename?: ((id: string, label: string) => void) | undefined;
83
100
  /** The id of the tab being renamed. Bindable: set it from a menu's Rename. */
@@ -354,7 +371,10 @@
354
371
  controls,
355
372
  onclose,
356
373
  onadd,
374
+ addMenu,
357
375
  addLabel = 'New tab',
376
+ onchange,
377
+ activation = 'automatic',
358
378
  closeLabel = (tab) => `Close ${tab.label}`,
359
379
  leading,
360
380
  trailing,
@@ -432,8 +452,9 @@
432
452
  function endRename(tab: TabStripTab, name: string | null, refocus: boolean) {
433
453
  if (renaming !== tab.id) return;
434
454
  renaming = undefined;
455
+ // Cleared, the name goes as '': the app gives the tab back a name of its own
435
456
  const next = name?.trim();
436
- if (next) onrename?.(tab.id, next);
457
+ if (next !== undefined && next !== tab.label) onrename?.(tab.id, next);
437
458
  if (refocus) tick().then(() => tabButton(tab.id)?.focus());
438
459
  }
439
460
 
@@ -443,6 +464,24 @@
443
464
  input.select();
444
465
  };
445
466
 
467
+ function open(tab: TabStripTab) {
468
+ if (value === tab.id) return;
469
+ value = tab.id;
470
+ onchange?.(tab.id);
471
+ }
472
+
473
+ // The arrow keys, Home and End move the focus to a tab; with automatic activation, the tab
474
+ // they reach opens. A tab focused any other way, such as as its menu closes, stays as it is.
475
+ let arrowed = false;
476
+ function onListKeydownCapture(event: KeyboardEvent) {
477
+ if (event.altKey || event.metaKey || event.ctrlKey || event.shiftKey) return;
478
+ if (!['ArrowLeft', 'ArrowRight', 'Home', 'End'].includes(event.key)) return;
479
+ if (!(event.target instanceof HTMLElement) || event.target.getAttribute('role') !== 'tab')
480
+ return;
481
+ arrowed = true;
482
+ setTimeout(() => (arrowed = false));
483
+ }
484
+
446
485
  function moveByKey(tab: TabStripTab, event: KeyboardEvent) {
447
486
  if (!onmove || !event.altKey || !event.shiftKey) return false;
448
487
  if (event.key !== 'ArrowLeft' && event.key !== 'ArrowRight') return false;
@@ -514,7 +553,10 @@
514
553
  onclose && !leading && !trailing && styles.closable,
515
554
  trailing && styles.buttonBeforeTrailing
516
555
  )}
517
- onclick={() => (value = tab.id)}
556
+ onclick={() => open(tab)}
557
+ onfocus={() => {
558
+ if (arrowed && activation === 'automatic') open(tab);
559
+ }}
518
560
  ondblclick={() => startRename(tab)}
519
561
  onauxclick={(event) => {
520
562
  // The middle button closes, as it does in a browser
@@ -621,7 +663,8 @@
621
663
  aria-label={label}
622
664
  aria-orientation="horizontal"
623
665
  {...stylex.attrs(styles.list)}
624
- {@attach roving({ selector: '[role="tab"]', orientation: 'horizontal' })}
666
+ {@attach roving({ selector: '[role="tab"]', orientation: 'horizontal', wrap: true })}
667
+ onkeydowncapture={onListKeydownCapture}
625
668
  >
626
669
  {#each tabs as tab, index (tab.id)}
627
670
  {#if menu}
@@ -645,21 +688,35 @@
645
688
  {/if}
646
689
  {/each}
647
690
  </div>
648
- {#if onadd}
691
+ {#snippet plus()}
692
+ <svg
693
+ data-glyph=""
694
+ width="14"
695
+ height="14"
696
+ viewBox="0 0 16 16"
697
+ fill="none"
698
+ stroke="currentColor"
699
+ stroke-width="1.5"
700
+ stroke-linecap="round"
701
+ aria-hidden="true"
702
+ >
703
+ <path d="M8 3.5v9M3.5 8h9" />
704
+ </svg>
705
+ {/snippet}
706
+ {#if addMenu}
707
+ <Menu.Root>
708
+ <Menu.Trigger>
709
+ {#snippet child({ props })}
710
+ <button type="button" aria-label={addLabel} {...props} {...stylex.attrs(styles.add)}>
711
+ {@render plus()}
712
+ </button>
713
+ {/snippet}
714
+ </Menu.Trigger>
715
+ <Menu.Content align="end">{@render addMenu()}</Menu.Content>
716
+ </Menu.Root>
717
+ {:else if onadd}
649
718
  <button type="button" aria-label={addLabel} {...stylex.attrs(styles.add)} onclick={onadd}>
650
- <svg
651
- data-glyph=""
652
- width="14"
653
- height="14"
654
- viewBox="0 0 16 16"
655
- fill="none"
656
- stroke="currentColor"
657
- stroke-width="1.5"
658
- stroke-linecap="round"
659
- aria-hidden="true"
660
- >
661
- <path d="M8 3.5v9M3.5 8h9" />
662
- </svg>
719
+ {@render plus()}
663
720
  </button>
664
721
  {/if}
665
722
  </div>
@@ -15,18 +15,30 @@ export type TabStripTab = {
15
15
  /** With `onrename`, whether this tab can be renamed. Defaults to true. */
16
16
  renamable?: boolean | undefined;
17
17
  };
18
- export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclose'> & {
18
+ export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onclose' | 'onchange'> & {
19
19
  tabs: TabStripTab[];
20
20
  /** The id of the open tab. Bindable. */
21
21
  value?: string | undefined;
22
+ /** Called as a tab is opened: clicked, or reached with the arrow keys. */
23
+ onchange?: ((id: string) => void) | undefined;
24
+ /**
25
+ * `automatic` opens the tab the arrow keys reach, as a browser's tabs do; `manual` only moves
26
+ * the focus, and Enter or Space opens it, for tabs slow to show.
27
+ */
28
+ activation?: 'automatic' | 'manual' | undefined;
22
29
  /** Names the strip: "Open threads". */
23
30
  label: string;
24
31
  /** The id of the panel the tabs show. */
25
32
  controls?: string | undefined;
26
33
  /** Called to close a tab. Without it the tabs cannot be closed. */
27
34
  onclose?: ((id: string) => void) | undefined;
28
- /** Called to add one. Without it there is no button to add. */
35
+ /** Called to add one. Without it, or `addMenu`, there is no button to add. */
29
36
  onadd?: (() => void) | undefined;
37
+ /**
38
+ * What can be added, as Menu parts: the button to add opens them, in place of calling
39
+ * `onadd`. For a strip that opens several kinds of tab: a file, a page, a terminal.
40
+ */
41
+ addMenu?: Snippet | undefined;
30
42
  addLabel?: string | undefined;
31
43
  /** The name of a tab's close button. */
32
44
  closeLabel?: ((tab: TabStripTab) => string) | undefined;
@@ -50,7 +62,8 @@ export type TabStripProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'o
50
62
  onmove?: ((id: string, index: number) => void) | undefined;
51
63
  /**
52
64
  * Called with a tab's new name, as Enter is pressed. Without it the tabs cannot be
53
- * renamed. Renaming starts on a double-click, on F2, or as `renaming` is set.
65
+ * renamed. Renaming starts on a double-click, on F2, or as `renaming` is set. A name
66
+ * cleared is passed as `''`, for the tab to take back a name of its own.
54
67
  */
55
68
  onrename?: ((id: string, label: string) => void) | undefined;
56
69
  /** The id of the tab being renamed. Bindable: set it from a menu's Rename. */