@diegopluna/narvi 0.3.3 → 0.3.5

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 (66) hide show
  1. package/dist/components/app-shell/AppShellMain.svelte +14 -2
  2. package/dist/components/app-shell/AppShellPanel.svelte +108 -12
  3. package/dist/components/app-shell/AppShellPanel.svelte.d.ts +11 -1
  4. package/dist/components/app-shell/AppShellSheet.svelte +11 -1
  5. package/dist/components/app-shell/context.d.ts +8 -0
  6. package/dist/components/app-shell/context.js +7 -0
  7. package/dist/components/avatar/AvatarRoot.svelte +20 -7
  8. package/dist/components/avatar/AvatarRoot.svelte.d.ts +10 -3
  9. package/dist/components/badge/Badge.svelte +13 -1
  10. package/dist/components/badge/Badge.svelte.d.ts +6 -0
  11. package/dist/components/button/Button.svelte +71 -32
  12. package/dist/components/button/Button.svelte.d.ts +13 -0
  13. package/dist/components/command/CommandDialog.svelte +24 -2
  14. package/dist/components/command/CommandDialog.svelte.d.ts +12 -0
  15. package/dist/components/command/CommandItem.svelte +15 -4
  16. package/dist/components/command/CommandItem.svelte.d.ts +20 -4
  17. package/dist/components/command/CommandRoot.svelte +57 -2
  18. package/dist/components/command/CommandRoot.svelte.d.ts +25 -1
  19. package/dist/components/composer/ComposerModelPicker.svelte +608 -53
  20. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +56 -1
  21. package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
  22. package/dist/components/composer/ComposerSubmit.svelte +12 -2
  23. package/dist/components/composer/ComposerSubmit.svelte.d.ts +6 -0
  24. package/dist/components/composer/index.d.ts +1 -1
  25. package/dist/components/input/Input.svelte.d.ts +1 -1
  26. package/dist/components/menu/MenuCheckboxItem.svelte +14 -5
  27. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +15 -4
  28. package/dist/components/menu/MenuItem.svelte +9 -3
  29. package/dist/components/menu/MenuItem.svelte.d.ts +11 -4
  30. package/dist/components/menu/MenuRadioItem.svelte +18 -9
  31. package/dist/components/menu/MenuRadioItem.svelte.d.ts +15 -4
  32. package/dist/components/menu/MenuSubTrigger.svelte +9 -3
  33. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +11 -4
  34. package/dist/components/questionnaire/Questionnaire.svelte +100 -9
  35. package/dist/components/questionnaire/Questionnaire.svelte.d.ts +11 -0
  36. package/dist/components/segmented/SegmentedControl.svelte +12 -1
  37. package/dist/components/segmented/SegmentedControl.svelte.d.ts +3 -1
  38. package/dist/components/select/Select.svelte +36 -5
  39. package/dist/components/select/Select.svelte.d.ts +12 -0
  40. package/dist/components/settings-row/SettingsRow.svelte +87 -37
  41. package/dist/components/settings-row/SettingsRow.svelte.d.ts +13 -0
  42. package/dist/components/slider/Slider.svelte.d.ts +2 -2
  43. package/dist/components/split-button/SplitButton.svelte +147 -0
  44. package/dist/components/split-button/SplitButton.svelte.d.ts +36 -0
  45. package/dist/components/tab-strip/TabStrip.svelte +410 -109
  46. package/dist/components/tab-strip/TabStrip.svelte.d.ts +51 -3
  47. package/dist/components/tab-strip/drag.svelte.d.ts +31 -0
  48. package/dist/components/tab-strip/drag.svelte.js +148 -0
  49. package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
  50. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +1 -1
  51. package/dist/index.d.ts +3 -1
  52. package/dist/index.js +1 -0
  53. package/dist/internal/ItemDescription.svelte +34 -0
  54. package/dist/internal/ItemDescription.svelte.d.ts +10 -0
  55. package/dist/internal/roving.d.ts +3 -1
  56. package/dist/internal/roving.js +6 -3
  57. package/dist/media.stylex.d.ts +6 -0
  58. package/dist/media.stylex.js +6 -0
  59. package/dist/vite.js +4 -0
  60. package/package.json +20 -1
  61. package/skills/building-ui/SKILL.md +48 -20
  62. package/skills/building-ui/references/components.md +43 -42
  63. package/skills/markdown/SKILL.md +1 -1
  64. package/skills/setup/SKILL.md +1 -1
  65. package/skills/styling/SKILL.md +11 -2
  66. 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;
@@ -23,7 +23,10 @@
23
23
  disabled?: boolean | undefined;
24
24
  };
25
25
 
26
- export type SegmentedControlProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
26
+ export type SegmentedControlProps = Omit<
27
+ HTMLAttributes<HTMLDivElement>,
28
+ 'children' | 'onchange'
29
+ > & {
27
30
  /** The choices, in order. Two to five read best. */
28
31
  options: SegmentedOption[];
29
32
  /** The selected option's value. Bindable. */
@@ -31,6 +34,8 @@
31
34
  /** Form field name. Generated when omitted. */
32
35
  name?: string | undefined;
33
36
  disabled?: boolean | undefined;
37
+ /** Called when the person picks an option, with its value: not when `value` is set. */
38
+ onchange?: ((value: string) => void) | undefined;
34
39
  sx?: Sx | undefined;
35
40
  };
36
41
 
@@ -139,6 +144,7 @@
139
144
  value = $bindable(),
140
145
  name,
141
146
  disabled = false,
147
+ onchange,
142
148
  sx,
143
149
  class: className,
144
150
  ...rest
@@ -181,6 +187,11 @@
181
187
  name={name ?? uid}
182
188
  value={option.value}
183
189
  bind:group={value}
190
+ onchange={() => {
191
+ // The binding may not have run yet: the value is set before the callback reads it
192
+ value = option.value;
193
+ onchange?.(option.value);
194
+ }}
184
195
  disabled={off}
185
196
  aria-describedby={titleId}
186
197
  {...stylex.attrs(styles.input, segmentedInputMarker)}
@@ -14,7 +14,7 @@ export type SegmentedOption = {
14
14
  icon?: IconComponent | undefined;
15
15
  disabled?: boolean | undefined;
16
16
  };
17
- export type SegmentedControlProps = Omit<HTMLAttributes<HTMLDivElement>, 'children'> & {
17
+ export type SegmentedControlProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onchange'> & {
18
18
  /** The choices, in order. Two to five read best. */
19
19
  options: SegmentedOption[];
20
20
  /** The selected option's value. Bindable. */
@@ -22,6 +22,8 @@ export type SegmentedControlProps = Omit<HTMLAttributes<HTMLDivElement>, 'childr
22
22
  /** Form field name. Generated when omitted. */
23
23
  name?: string | undefined;
24
24
  disabled?: boolean | undefined;
25
+ /** Called when the person picks an option, with its value: not when `value` is set. */
26
+ onchange?: ((value: string) => void) | undefined;
25
27
  sx?: Sx | undefined;
26
28
  };
27
29
  declare const SegmentedControl: import("svelte").Component<SegmentedControlProps, {}, "value">;
@@ -11,7 +11,7 @@
11
11
  import { control, type ControlSize } from '../../internal/control.js';
12
12
  import { layer } from '../../internal/layer.js';
13
13
  import { attrs, type Sx } from '../../internal/sx.js';
14
- import { colors } from '../../tokens.stylex.js';
14
+ import { colors, font } from '../../tokens.stylex.js';
15
15
  import { getFieldContext } from '../field/context.js';
16
16
 
17
17
  export type SelectOption = {
@@ -22,6 +22,13 @@
22
22
  * component such as a Lucide icon, which is sized to fit.
23
23
  */
24
24
  icon?: IconComponent | undefined;
25
+ /**
26
+ * More about the option, at the end of its row in the list and muted: a commit's short
27
+ * hash, a device's size, a count. It is not shown on the trigger.
28
+ */
29
+ detail?: string | undefined;
30
+ /** Sets `detail` in monospace, for code such as a hash. */
31
+ detailMono?: boolean | undefined;
25
32
  /** Options with the same group are listed together under its name. */
26
33
  group?: string | undefined;
27
34
  disabled?: boolean | undefined;
@@ -33,6 +40,11 @@
33
40
  value?: string | undefined;
34
41
  /** Shown while nothing is chosen. */
35
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;
36
48
  /**
37
49
  * Draws each option's icon, in the list and on the trigger, in place of `option.icon`:
38
50
  * for an icon that takes props, such as a provider's mark in its colours, or a dot.
@@ -70,6 +82,7 @@
70
82
  whiteSpace: 'nowrap'
71
83
  },
72
84
  placeholder: { color: colors.textSubtle },
85
+ prefix: { flexShrink: 0, color: colors.textMuted },
73
86
  // The chosen option's icon, on the trigger
74
87
  icon: {
75
88
  '--narvi-icon-size': '1rem',
@@ -79,9 +92,16 @@
79
92
  color: colors.textMuted
80
93
  },
81
94
  selector: { display: 'grid', flexShrink: 0, color: colors.textSubtle },
82
- check: { display: 'grid', marginInlineStart: 'auto', color: colors.accent }
95
+ check: { display: 'grid', marginInlineStart: 'auto', color: colors.accent },
96
+ // Where options have details, every row keeps the check's room, so the details line up
97
+ unchecked: { visibility: 'hidden' },
98
+ mono: { fontFamily: font.mono }
83
99
  });
84
100
 
101
+ // Made here: the item's `selected` comes through a snippet's argument, which StyleX cannot read
102
+ const check = stylex.attrs(styles.check);
103
+ const checkHidden = stylex.attrs(styles.check, styles.unchecked);
104
+
85
105
  type Group = { name: string | undefined; options: SelectOption[] };
86
106
  function grouped(options: SelectOption[]): Group[] {
87
107
  const groups: Group[] = [];
@@ -99,6 +119,7 @@
99
119
  options,
100
120
  value = $bindable(),
101
121
  placeholder = 'Choose…',
122
+ prefix,
102
123
  optionIcon,
103
124
  size = 'md',
104
125
  align = 'start',
@@ -115,6 +136,7 @@
115
136
  const field = getFieldContext();
116
137
  const selected = $derived(options.find((option) => option.value === value));
117
138
  const groups = $derived(grouped(options));
139
+ const detailed = $derived(options.some((option) => option.detail));
118
140
  </script>
119
141
 
120
142
  <Select.Root
@@ -127,7 +149,7 @@
127
149
  >
128
150
  <Select.Trigger
129
151
  id={id ?? field?.id}
130
- aria-label={label}
152
+ aria-label={label ?? (prefix ? `${prefix} ${selected?.label ?? placeholder}` : undefined)}
131
153
  aria-describedby={describedBy ?? field?.describedBy}
132
154
  data-slot="select"
133
155
  {...attrs([control.base, control[size], styles.trigger, sx], className)}
@@ -139,6 +161,7 @@
139
161
  {:else if selected?.icon}
140
162
  <span data-icons {...stylex.attrs(styles.icon)}><selected.icon aria-hidden="true" /></span>
141
163
  {/if}
164
+ {#if prefix}<span {...stylex.attrs(styles.prefix)}>{prefix}</span>{/if}
142
165
  <span {...stylex.attrs(styles.value, !selected && styles.placeholder)}>
143
166
  {selected?.label ?? placeholder}
144
167
  </span>
@@ -148,6 +171,8 @@
148
171
  <Select.Content {align} sideOffset={6} collisionPadding={8} {...stylex.attrs(layer.surface)}>
149
172
  <Select.Viewport>
150
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}
151
176
  <Select.Group>
152
177
  {#if group.name}
153
178
  <Select.GroupHeading {...stylex.attrs(layer.heading)}
@@ -172,8 +197,14 @@
172
197
  >
173
198
  {/if}
174
199
  <span {...stylex.attrs(layer.label)}>{option.label}</span>
175
- {#if selected}
176
- <span {...stylex.attrs(styles.check)}><Glyph name="check" stroke={1.75} /></span
200
+ {#if option.detail}
201
+ <span {...stylex.attrs(layer.trailing, option.detailMono && styles.mono)}
202
+ >{option.detail}</span
203
+ >
204
+ {/if}
205
+ {#if selected || detailed}
206
+ <span aria-hidden={!selected || undefined} {...selected ? check : checkHidden}
207
+ ><Glyph name="check" stroke={1.75} /></span
177
208
  >
178
209
  {/if}
179
210
  {/snippet}
@@ -11,6 +11,13 @@ export type SelectOption = {
11
11
  * component such as a Lucide icon, which is sized to fit.
12
12
  */
13
13
  icon?: IconComponent | undefined;
14
+ /**
15
+ * More about the option, at the end of its row in the list and muted: a commit's short
16
+ * hash, a device's size, a count. It is not shown on the trigger.
17
+ */
18
+ detail?: string | undefined;
19
+ /** Sets `detail` in monospace, for code such as a hash. */
20
+ detailMono?: boolean | undefined;
14
21
  /** Options with the same group are listed together under its name. */
15
22
  group?: string | undefined;
16
23
  disabled?: boolean | undefined;
@@ -21,6 +28,11 @@ export type SelectProps = {
21
28
  value?: string | undefined;
22
29
  /** Shown while nothing is chosen. */
23
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;
24
36
  /**
25
37
  * Draws each option's icon, in the list and on the trigger, in place of `option.icon`:
26
38
  * for an icon that takes props, such as a provider's mark in its colours, or a dot.
@@ -11,11 +11,12 @@
11
11
  import Glyph from '../../internal/Glyph.svelte';
12
12
  import { shared } from '../../internal/shared.js';
13
13
  import { attrs, type Sx } from '../../internal/sx.js';
14
- import { colors, motion, radius, space } from '../../tokens.stylex.js';
14
+ import { colors, font, motion, radius, space } from '../../tokens.stylex.js';
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
18
  import { getSettingsGroupContext } from '../settings-group/context.js';
19
+ import '../../internal/icons.css';
19
20
 
20
21
  export type SettingsRowControl = {
21
22
  /** For the control's `id`, which the label's `for` names: `controlId` when it is set. */
@@ -28,6 +29,18 @@
28
29
 
29
30
  export type SettingsRowProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'title'> & {
30
31
  label: string;
32
+ /**
33
+ * Before the label and the description: a provider's mark, an icon of what the row is,
34
+ * an Avatar. Decoration: the label names the row.
35
+ */
36
+ leading?: Snippet | undefined;
37
+ /** Sets the label in the muted ink: for something switched off, or not to be had here. */
38
+ dimmed?: boolean | undefined;
39
+ /**
40
+ * Sets the label in monospace, for a name that is code: an environment variable, a
41
+ * header, a tool, a path.
42
+ */
43
+ mono?: boolean | undefined;
31
44
  /**
32
45
  * What the setting does, in a sentence or two, behind an info mark beside the label. It
33
46
  * opens on a hover, or as the mark takes the focus.
@@ -88,9 +101,27 @@
88
101
  text: { display: 'flex', flexDirection: 'column', gap: '0.125rem', minWidth: 0 },
89
102
  // Beside the control, the text takes the room and wraps the control under it below 14rem
90
103
  textInline: { flexGrow: 1, flexShrink: 1, flexBasis: '14rem' },
104
+ // The leading mark and the text beside it
105
+ lead: { display: 'flex', alignItems: 'center', gap: space.x3, minWidth: 0 },
106
+ leading: {
107
+ '--narvi-icon-size': '1rem',
108
+ display: 'grid',
109
+ placeItems: 'center',
110
+ flexShrink: 0,
111
+ color: colors.textMuted
112
+ },
113
+ leadText: { flexGrow: 1 },
91
114
  // Room for the info mark's focus ring beside the label
92
115
  title: { display: 'flex', alignItems: 'center', gap: '0.375rem', minWidth: 0 },
93
116
  label: { color: colors.text },
117
+ dimmed: { color: colors.textMuted },
118
+ // Mono runs wider than the text's face: a step down, and no heavier than the text
119
+ mono: {
120
+ fontFamily: font.mono,
121
+ fontSize: font.sizeMeta,
122
+ fontWeight: font.weightRegular,
123
+ overflowWrap: 'anywhere'
124
+ },
94
125
  about: {
95
126
  position: 'relative',
96
127
  display: 'inline-grid',
@@ -127,6 +158,9 @@
127
158
  <script lang="ts">
128
159
  let {
129
160
  label,
161
+ leading,
162
+ dimmed = false,
163
+ mono = false,
130
164
  about,
131
165
  description,
132
166
  stacked = false,
@@ -149,6 +183,12 @@
149
183
  .filter(Boolean)
150
184
  .join(' ') || undefined
151
185
  );
186
+ const labelStyles = $derived([
187
+ typography.label,
188
+ styles.label,
189
+ dimmed && styles.dimmed,
190
+ mono && styles.mono
191
+ ]);
152
192
  const control = $derived({
153
193
  id: controlId ?? `${uid}-control`,
154
194
  labelId: `${uid}-label`,
@@ -171,43 +211,53 @@
171
211
  className
172
212
  )}
173
213
  >
174
- <div {...stylex.attrs(styles.text, !stacked && styles.textInline)}>
175
- <span {...stylex.attrs(styles.title)}>
176
- {#if labelFor && children}
177
- <label
178
- id={control.labelId}
179
- for={control.id}
180
- {...stylex.attrs(typography.label, styles.label)}>{label}</label
181
- >
182
- {:else}
183
- <span id={control.labelId} {...stylex.attrs(typography.label, styles.label)}>{label}</span>
184
- {/if}
185
- {#if about}
186
- <Tooltip.Provider delayDuration={400}>
187
- <Tooltip.Root>
188
- <Tooltip.Trigger>
189
- {#snippet child({ props })}
190
- <button
191
- {...props}
192
- type="button"
193
- aria-label="About {label}"
194
- {...stylex.attrs(styles.about, shared.focusable)}
195
- >
196
- <Glyph name="info" size={14} />
197
- </button>
198
- {/snippet}
199
- </Tooltip.Trigger>
200
- <Tooltip.Content side="top">{about}</Tooltip.Content>
201
- </Tooltip.Root>
202
- </Tooltip.Provider>
214
+ {#snippet text(sx: Sx | false)}
215
+ <div {...stylex.attrs(styles.text, sx)}>
216
+ <span {...stylex.attrs(styles.title)}>
217
+ {#if labelFor && children}
218
+ <label id={control.labelId} for={control.id} {...stylex.attrs(...labelStyles)}
219
+ >{label}</label
220
+ >
221
+ {:else}
222
+ <span id={control.labelId} {...stylex.attrs(...labelStyles)}>{label}</span>
223
+ {/if}
224
+ {#if about}
225
+ <Tooltip.Provider delayDuration={400}>
226
+ <Tooltip.Root>
227
+ <Tooltip.Trigger>
228
+ {#snippet child({ props })}
229
+ <button
230
+ {...props}
231
+ type="button"
232
+ aria-label="About {label}"
233
+ {...stylex.attrs(styles.about, shared.focusable)}
234
+ >
235
+ <Glyph name="info" size={14} />
236
+ </button>
237
+ {/snippet}
238
+ </Tooltip.Trigger>
239
+ <Tooltip.Content side="top">{about}</Tooltip.Content>
240
+ </Tooltip.Root>
241
+ </Tooltip.Provider>
242
+ {/if}
243
+ </span>
244
+ {#if description}
245
+ <div id="{uid}-description" {...stylex.attrs(typography.meta, styles.description)}>
246
+ {#if typeof description === 'string'}{description}{:else}{@render description()}{/if}
247
+ </div>
203
248
  {/if}
204
- </span>
205
- {#if description}
206
- <div id="{uid}-description" {...stylex.attrs(typography.meta, styles.description)}>
207
- {#if typeof description === 'string'}{description}{:else}{@render description()}{/if}
208
- </div>
209
- {/if}
210
- </div>
249
+ </div>
250
+ {/snippet}
251
+ {#if leading}
252
+ <div {...stylex.attrs(styles.lead, !stacked && styles.textInline)}>
253
+ <span data-icons aria-hidden="true" {...stylex.attrs(styles.leading)}
254
+ >{@render leading()}</span
255
+ >
256
+ {@render text(styles.leadText)}
257
+ </div>
258
+ {:else}
259
+ {@render text(!stacked && styles.textInline)}
260
+ {/if}
211
261
  {#if children}
212
262
  <div {...stylex.attrs(styles.control, stacked ? styles.full : styles.controlInline)}>
213
263
  {@render children(control)}
@@ -1,6 +1,7 @@
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
+ import '../../internal/icons.css';
4
5
  export type SettingsRowControl = {
5
6
  /** For the control's `id`, which the label's `for` names: `controlId` when it is set. */
6
7
  id: string;
@@ -11,6 +12,18 @@ export type SettingsRowControl = {
11
12
  };
12
13
  export type SettingsRowProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'title'> & {
13
14
  label: string;
15
+ /**
16
+ * Before the label and the description: a provider's mark, an icon of what the row is,
17
+ * an Avatar. Decoration: the label names the row.
18
+ */
19
+ leading?: Snippet | undefined;
20
+ /** Sets the label in the muted ink: for something switched off, or not to be had here. */
21
+ dimmed?: boolean | undefined;
22
+ /**
23
+ * Sets the label in monospace, for a name that is code: an environment variable, a
24
+ * header, a tool, a path.
25
+ */
26
+ mono?: boolean | undefined;
14
27
  /**
15
28
  * What the setting does, in a sentence or two, behind an info mark beside the label. It
16
29
  * opens on a hover, or as the mark takes the focus.
@@ -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 {