@diegopluna/narvi 0.4.1 → 0.5.0

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 (177) hide show
  1. package/README.md +3 -1
  2. package/dist/base.css +3 -0
  3. package/dist/components/button/Button.svelte +29 -17
  4. package/dist/components/checkbox/Checkbox.svelte +106 -54
  5. package/dist/components/checkbox/Checkbox.svelte.d.ts +22 -8
  6. package/dist/components/choice-cards/ChoiceCards.svelte +68 -39
  7. package/dist/components/choice-cards/ChoiceCards.svelte.d.ts +12 -8
  8. package/dist/components/collapsible/CollapsibleContent.svelte +71 -17
  9. package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +14 -10
  10. package/dist/components/collapsible/CollapsibleRoot.svelte +13 -9
  11. package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +8 -9
  12. package/dist/components/collapsible/CollapsibleTrigger.svelte +24 -15
  13. package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +10 -14
  14. package/dist/components/color-field/ColorField.svelte +13 -7
  15. package/dist/components/command/CommandDialog.svelte +30 -20
  16. package/dist/components/command/CommandDialog.svelte.d.ts +4 -3
  17. package/dist/components/command/CommandEmpty.svelte +11 -9
  18. package/dist/components/command/CommandEmpty.svelte.d.ts +6 -17
  19. package/dist/components/command/CommandGroup.svelte +32 -11
  20. package/dist/components/command/CommandGroup.svelte.d.ts +7 -11
  21. package/dist/components/command/CommandInput.svelte +25 -10
  22. package/dist/components/command/CommandInput.svelte.d.ts +8 -12
  23. package/dist/components/command/CommandItem.svelte +67 -29
  24. package/dist/components/command/CommandItem.svelte.d.ts +6 -32
  25. package/dist/components/command/CommandList.svelte +8 -10
  26. package/dist/components/command/CommandList.svelte.d.ts +6 -8
  27. package/dist/components/command/CommandRoot.svelte +247 -57
  28. package/dist/components/command/CommandRoot.svelte.d.ts +14 -28
  29. package/dist/components/command/CommandSeparator.svelte +18 -0
  30. package/dist/components/command/CommandSeparator.svelte.d.ts +7 -0
  31. package/dist/components/command/context.d.ts +27 -0
  32. package/dist/components/command/context.js +16 -0
  33. package/dist/components/command/index.d.ts +6 -4
  34. package/dist/components/command/index.js +5 -4
  35. package/dist/components/command/score.d.ts +27 -0
  36. package/dist/components/command/score.js +77 -0
  37. package/dist/components/command/styles.d.ts +32 -9
  38. package/dist/components/command/styles.js +42 -14
  39. package/dist/components/composer/ComposerModelPicker.svelte +350 -346
  40. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +6 -3
  41. package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
  42. package/dist/components/dialog/ConfirmDialog.svelte +73 -53
  43. package/dist/components/dialog/DialogClose.svelte +17 -0
  44. package/dist/components/dialog/DialogClose.svelte.d.ts +10 -0
  45. package/dist/components/dialog/DialogContent.svelte +35 -33
  46. package/dist/components/dialog/DialogContent.svelte.d.ts +6 -20
  47. package/dist/components/dialog/DialogDescription.svelte +9 -12
  48. package/dist/components/dialog/DialogDescription.svelte.d.ts +6 -8
  49. package/dist/components/dialog/DialogRoot.svelte +20 -0
  50. package/dist/components/dialog/DialogRoot.svelte.d.ts +7 -0
  51. package/dist/components/dialog/DialogTitle.svelte +12 -8
  52. package/dist/components/dialog/DialogTitle.svelte.d.ts +8 -8
  53. package/dist/components/dialog/DialogTrigger.svelte +17 -0
  54. package/dist/components/dialog/DialogTrigger.svelte.d.ts +10 -0
  55. package/dist/components/dialog/index.d.ts +6 -5
  56. package/dist/components/dialog/index.js +3 -6
  57. package/dist/components/dialog/styles.d.ts +1 -2
  58. package/dist/components/dialog/styles.js +11 -8
  59. package/dist/components/hover-card/HoverCardContent.svelte +35 -29
  60. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -12
  61. package/dist/components/hover-card/HoverCardRoot.svelte +7 -7
  62. package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -4
  63. package/dist/components/hover-card/HoverCardTrigger.svelte +18 -0
  64. package/dist/components/hover-card/HoverCardTrigger.svelte.d.ts +10 -0
  65. package/dist/components/hover-card/index.d.ts +2 -3
  66. package/dist/components/hover-card/index.js +1 -5
  67. package/dist/components/input/Input.svelte.d.ts +1 -1
  68. package/dist/components/markdown/MarkdownBlock.svelte +6 -3
  69. package/dist/components/markdown/MarkdownTable.svelte +15 -7
  70. package/dist/components/menu/ContextMenuContent.svelte +15 -15
  71. package/dist/components/menu/ContextMenuContent.svelte.d.ts +6 -9
  72. package/dist/components/menu/ContextMenuTrigger.svelte +14 -16
  73. package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +8 -14
  74. package/dist/components/menu/MenuCheckboxItem.svelte +22 -11
  75. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +8 -22
  76. package/dist/components/menu/MenuContent.svelte +16 -18
  77. package/dist/components/menu/MenuContent.svelte.d.ts +6 -18
  78. package/dist/components/menu/MenuGroup.svelte +4 -4
  79. package/dist/components/menu/MenuGroup.svelte.d.ts +5 -4
  80. package/dist/components/menu/MenuItem.svelte +25 -12
  81. package/dist/components/menu/MenuItem.svelte.d.ts +6 -21
  82. package/dist/components/menu/MenuLabel.svelte +7 -11
  83. package/dist/components/menu/MenuLabel.svelte.d.ts +6 -8
  84. package/dist/components/menu/MenuRadioGroup.svelte +4 -4
  85. package/dist/components/menu/MenuRadioGroup.svelte.d.ts +5 -4
  86. package/dist/components/menu/MenuRadioItem.svelte +16 -14
  87. package/dist/components/menu/MenuRadioItem.svelte.d.ts +6 -19
  88. package/dist/components/menu/MenuSeparator.svelte +6 -10
  89. package/dist/components/menu/MenuSeparator.svelte.d.ts +6 -7
  90. package/dist/components/menu/MenuSubContent.svelte +22 -19
  91. package/dist/components/menu/MenuSubContent.svelte.d.ts +8 -15
  92. package/dist/components/menu/MenuSubTrigger.svelte +7 -11
  93. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -15
  94. package/dist/components/menu/MenuTrigger.svelte +17 -0
  95. package/dist/components/menu/MenuTrigger.svelte.d.ts +10 -0
  96. package/dist/components/menu/context-menu.d.ts +2 -2
  97. package/dist/components/menu/context-menu.js +3 -2
  98. package/dist/components/menu/group.js +1 -1
  99. package/dist/components/menu/index.d.ts +5 -4
  100. package/dist/components/menu/index.js +5 -5
  101. package/dist/components/menu/row.d.ts +20 -0
  102. package/dist/components/menu/row.js +12 -0
  103. package/dist/components/popover/PopoverClose.svelte +17 -0
  104. package/dist/components/popover/PopoverClose.svelte.d.ts +10 -0
  105. package/dist/components/popover/PopoverContent.svelte +30 -29
  106. package/dist/components/popover/PopoverContent.svelte.d.ts +6 -17
  107. package/dist/components/popover/PopoverTrigger.svelte +17 -0
  108. package/dist/components/popover/PopoverTrigger.svelte.d.ts +10 -0
  109. package/dist/components/popover/index.d.ts +6 -4
  110. package/dist/components/popover/index.js +6 -5
  111. package/dist/components/progress/Progress.svelte +16 -22
  112. package/dist/components/progress/Progress.svelte.d.ts +6 -5
  113. package/dist/components/reasoning/ReasoningRoot.svelte.d.ts +1 -1
  114. package/dist/components/segmented/SegmentedControl.svelte +100 -91
  115. package/dist/components/segmented/SegmentedControl.svelte.d.ts +6 -4
  116. package/dist/components/select/Select.svelte +97 -59
  117. package/dist/components/select/Select.svelte.d.ts +3 -2
  118. package/dist/components/sheet/SheetContent.svelte +31 -38
  119. package/dist/components/sheet/SheetContent.svelte.d.ts +7 -22
  120. package/dist/components/sheet/index.d.ts +3 -5
  121. package/dist/components/sheet/index.js +3 -5
  122. package/dist/components/sheet/styles.js +26 -5
  123. package/dist/components/sidebar/SidebarItem.svelte +2 -3
  124. package/dist/components/slider/Slider.svelte +86 -65
  125. package/dist/components/slider/Slider.svelte.d.ts +9 -8
  126. package/dist/components/split-button/SplitButton.svelte +20 -3
  127. package/dist/components/split-button/SplitButton.svelte.d.ts +1 -1
  128. package/dist/components/switch/Switch.svelte +77 -49
  129. package/dist/components/switch/Switch.svelte.d.ts +15 -8
  130. package/dist/components/tab-strip/TabStrip.svelte +87 -68
  131. package/dist/components/tabs/Tabs.svelte +129 -99
  132. package/dist/components/tabs/Tabs.svelte.d.ts +6 -4
  133. package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
  134. package/dist/components/toast/Toaster.svelte +132 -115
  135. package/dist/components/toast/Toaster.svelte.d.ts +5 -0
  136. package/dist/components/toast/toasts.svelte.d.ts +10 -23
  137. package/dist/components/toast/toasts.svelte.js +62 -40
  138. package/dist/components/toggle/Toggle.svelte +15 -9
  139. package/dist/components/toggle/Toggle.svelte.d.ts +8 -17
  140. package/dist/components/toggle-group/ToggleGroupItem.svelte +20 -9
  141. package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +10 -10
  142. package/dist/components/toggle-group/ToggleGroupRoot.svelte +33 -18
  143. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +4 -4
  144. package/dist/components/tool/ToolRoot.svelte.d.ts +1 -1
  145. package/dist/components/tooltip/TooltipContent.svelte +38 -28
  146. package/dist/components/tooltip/TooltipContent.svelte.d.ts +6 -15
  147. package/dist/components/tooltip/TooltipProvider.svelte +34 -10
  148. package/dist/components/tooltip/TooltipProvider.svelte.d.ts +18 -4
  149. package/dist/components/tooltip/TooltipRoot.svelte +52 -23
  150. package/dist/components/tooltip/TooltipRoot.svelte.d.ts +10 -10
  151. package/dist/components/tooltip/TooltipTrigger.svelte +14 -17
  152. package/dist/components/tooltip/TooltipTrigger.svelte.d.ts +10 -4
  153. package/dist/components/tooltip/index.d.ts +1 -1
  154. package/dist/components/tooltip/index.js +1 -1
  155. package/dist/components/work-fold/WorkFold.svelte +14 -5
  156. package/dist/index.d.ts +5 -5
  157. package/dist/index.js +1 -1
  158. package/dist/internal/TooltipScope.svelte +4 -4
  159. package/dist/internal/layer.d.ts +11 -9
  160. package/dist/internal/layer.js +21 -15
  161. package/dist/internal/loose.d.ts +30 -5
  162. package/dist/internal/loose.js +1 -1
  163. package/dist/internal/markers.stylex.d.ts +0 -4
  164. package/dist/internal/markers.stylex.js +0 -2
  165. package/dist/internal/toggle.d.ts +3 -0
  166. package/dist/internal/toggle.js +6 -2
  167. package/dist/internal/tooltip-trigger.d.ts +7 -6
  168. package/dist/internal/tooltip-trigger.js +9 -12
  169. package/dist/vite.d.ts +7 -1
  170. package/dist/vite.js +20 -5
  171. package/package.json +3 -2
  172. package/skills/building-ui/SKILL.md +20 -20
  173. package/skills/building-ui/references/components.md +11 -4
  174. package/skills/markdown/SKILL.md +1 -1
  175. package/skills/setup/SKILL.md +4 -8
  176. package/skills/styling/SKILL.md +1 -1
  177. package/skills/theming/SKILL.md +3 -7
@@ -1,8 +1,11 @@
1
1
  <script lang="ts" module>
2
2
  import type { IconComponent } from '../../internal/icon.js';
3
- import { segmentedInputMarker } from '../../internal/markers.stylex.js';
3
+ import type { Loose, PartProps } from '../../internal/loose.js';
4
+ import {
5
+ SegmentedControl as UiSegmentedControl,
6
+ SegmentedControlItem
7
+ } from '@ui-sdk/svelte/segmented-control';
4
8
  import * as stylex from '@stylexjs/stylex';
5
- import type { HTMLAttributes } from 'svelte/elements';
6
9
  import { attrs, type Sx } from '../../internal/sx.js';
7
10
  import { colors, density, font, motion, radius } from '../../tokens.stylex.js';
8
11
  import { media } from '../../media.stylex.js';
@@ -24,21 +27,34 @@
24
27
  disabled?: boolean | undefined;
25
28
  };
26
29
 
27
- export type SegmentedControlProps = Omit<
28
- HTMLAttributes<HTMLDivElement>,
29
- 'children' | 'onchange'
30
- > & {
31
- /** The choices, in order. Two to five read best. */
32
- options: SegmentedOption[];
33
- /** The selected option's value. Bindable. */
34
- value?: string | undefined;
35
- /** Form field name. Generated when omitted. */
36
- name?: string | undefined;
37
- disabled?: boolean | undefined;
38
- /** Called when the person picks an option, with its value: not when `value` is set. */
39
- onchange?: ((value: string) => void) | undefined;
40
- sx?: Sx | undefined;
41
- };
30
+ export interface SegmentedControlProps extends Loose<
31
+ Omit<
32
+ PartProps<typeof UiSegmentedControl>,
33
+ | 'children'
34
+ | 'render'
35
+ | 'value'
36
+ | 'defaultValue'
37
+ | 'onValueChange'
38
+ | 'onchange'
39
+ | 'orientation'
40
+ | 'controller'
41
+ | 'debug'
42
+ > & {
43
+ /** The choices, in order. Two to five read best. */
44
+ options: SegmentedOption[];
45
+ /** The selected option's value. Bindable. */
46
+ value?: string | undefined;
47
+ /** Form field name. Without one, the choice is not submitted with a form. */
48
+ name?: string | undefined;
49
+ disabled?: boolean | undefined;
50
+ /** Called when the person picks an option, with its value: not when `value` is set. */
51
+ onchange?: ((value: string) => void) | undefined;
52
+ sx?: Sx | undefined;
53
+ }
54
+ > {}
55
+
56
+ const CHECKED = ':is([data-checked])';
57
+ const DISABLED = ':is([data-disabled])';
42
58
 
43
59
  /** A length at the window's density (`density` in the tokens). */
44
60
  const d = (rem: string) => `calc(${rem} * ${density.factor})`;
@@ -49,7 +65,9 @@
49
65
  position: 'relative',
50
66
  display: 'inline-grid',
51
67
  gridAutoFlow: 'column',
52
- gridAutoColumns: '1fr',
68
+ // Equal columns even when a label is too long for its share, so the thumb, which steps by
69
+ // one column, stays under the chosen option; the label is cut short instead
70
+ gridAutoColumns: 'minmax(0, 1fr)',
53
71
  boxSizing: 'border-box',
54
72
  padding: '0.1875rem',
55
73
  borderRadius: `calc(${radius.item} + 0.1875rem)`,
@@ -88,56 +106,50 @@
88
106
  transitionTimingFunction: motion.easeInOut
89
107
  },
90
108
  thumbHidden: { opacity: 0 },
91
- option: {
109
+ // Each option is a button with the radio role; ui-sdk keeps a hidden native radio beside it
110
+ // for forms, out of the layout
111
+ item: {
112
+ '--narvi-icon-size': '0.875rem',
92
113
  position: 'relative',
93
114
  zIndex: 1,
94
- display: 'grid',
95
- cursor: 'pointer',
96
- WebkitTapHighlightColor: 'transparent'
97
- },
98
- optionDisabled: { cursor: 'not-allowed', opacity: 0.5 },
99
- // The radio itself is invisible and covers its option, so it takes the click and the focus
100
- input: {
101
- position: 'absolute',
102
- inset: 0,
103
- width: '100%',
104
- height: '100%',
105
- margin: 0,
106
- opacity: 0,
107
- appearance: 'none',
108
- cursor: 'inherit'
109
- },
110
- text: {
111
- '--narvi-icon-size': '0.875rem',
112
115
  display: 'flex',
113
116
  alignItems: 'center',
114
117
  justifyContent: 'center',
115
118
  gap: '0.375rem',
116
119
  minHeight: d('1.75rem'),
120
+ margin: 0,
121
+ paddingBlock: 0,
117
122
  paddingInline: d('0.75rem'),
123
+ borderWidth: 0,
118
124
  borderRadius: radius.item,
125
+ backgroundColor: 'transparent',
119
126
  color: {
120
127
  default: colors.textMuted,
121
128
  ':hover': { default: null, [media.hover]: colors.text },
122
- [stylex.when.siblingBefore(':checked', segmentedInputMarker)]: colors.text
129
+ [CHECKED]: colors.text
123
130
  },
131
+ fontFamily: 'inherit',
124
132
  fontSize: font.sizeBody,
125
- fontWeight: {
126
- default: font.weightMedium,
127
- [stylex.when.siblingBefore(':checked', segmentedInputMarker)]: font.weightSemibold
128
- },
133
+ fontWeight: { default: font.weightMedium, [CHECKED]: font.weightSemibold },
129
134
  lineHeight: 1,
130
135
  whiteSpace: 'nowrap',
136
+ cursor: { default: 'pointer', [DISABLED]: 'not-allowed' },
137
+ opacity: { default: 1, [DISABLED]: 0.5 },
138
+ WebkitTapHighlightColor: 'transparent',
131
139
  outlineStyle: 'solid',
132
140
  outlineWidth: '2px',
133
141
  outlineOffset: '1px',
134
- outlineColor: {
135
- default: 'transparent',
136
- [stylex.when.siblingBefore(':focus-visible', segmentedInputMarker)]: colors.focusRing
137
- },
142
+ outlineColor: { default: 'transparent', ':focus-visible': colors.focusRing },
138
143
  transitionProperty: 'color',
139
144
  transitionDuration: motion.base,
140
145
  transitionTimingFunction: 'ease'
146
+ },
147
+ // The line box is taller than the item's 1, so a cut label keeps its accents and descenders
148
+ label: {
149
+ minWidth: 0,
150
+ overflow: 'hidden',
151
+ textOverflow: 'ellipsis',
152
+ lineHeight: font.leadingSnug
141
153
  }
142
154
  });
143
155
  </script>
@@ -154,7 +166,6 @@
154
166
  ...rest
155
167
  }: SegmentedControlProps = $props();
156
168
 
157
- const uid = $props.id();
158
169
  const index = $derived(options.findIndex((option) => option.value === value));
159
170
 
160
171
  // The thumb slides only for a choice made with a pointer. Arrow keys move the
@@ -166,11 +177,48 @@
166
177
  const titled = $derived(options.some((option) => option.title));
167
178
  </script>
168
179
 
169
- <div
170
- role="radiogroup"
180
+ {#snippet segments()}
181
+ {#each options as option (option.value)}
182
+ <!-- A title is the tooltip's, which describes the option whether open or not -->
183
+ {#snippet item(props: Record<string, unknown>)}
184
+ <SegmentedControlItem
185
+ {...props}
186
+ value={option.value}
187
+ disabled={option.disabled}
188
+ data-icons
189
+ {...stylex.attrs(styles.item)}
190
+ >
191
+ {#if option.icon}<option.icon aria-hidden="true" />{/if}<span
192
+ {...stylex.attrs(styles.label)}>{option.label}</span
193
+ >
194
+ </SegmentedControlItem>
195
+ {/snippet}
196
+ {#if option.title}
197
+ <Tooltip.Root>
198
+ <Tooltip.Trigger disabled={disabled || option.disabled}>
199
+ {#snippet child({ props })}{@render item(groupTrigger(props))}{/snippet}
200
+ </Tooltip.Trigger>
201
+ <Tooltip.Content side="top">{option.title}</Tooltip.Content>
202
+ </Tooltip.Root>
203
+ {:else}
204
+ {@render item({})}
205
+ {/if}
206
+ {/each}
207
+ {/snippet}
208
+
209
+ <!-- A radio group from ui-sdk: one tab stop, the arrow keys move and check, disabled options are
210
+ skipped. Its own sliding indicator is left out: the thumb below moves by index, over equal columns. -->
211
+ <UiSegmentedControl
171
212
  {...rest}
213
+ bind:value={() => value ?? null, (next) => (value = next ?? undefined)}
214
+ {name}
215
+ {disabled}
216
+ onValueChange={(next) => {
217
+ // Set before the callback reads it, as a binding would be only after
218
+ value = next ?? undefined;
219
+ if (next !== null) onchange?.(next);
220
+ }}
172
221
  {...attrs([styles.root, sx], className)}
173
- style:--narvi-seg-count={options.length}
174
222
  onpointerdowncapture={() => (slides = index >= 0)}
175
223
  onkeydowncapture={() => (slides = false)}
176
224
  >
@@ -178,51 +226,12 @@
178
226
  <span
179
227
  aria-hidden="true"
180
228
  {...stylex.attrs(styles.thumb, slides && styles.thumbSlides, index < 0 && styles.thumbHidden)}
229
+ style:--narvi-seg-count={options.length}
181
230
  style:--narvi-seg-index={Math.max(index, 0)}
182
231
  ></span>
183
- {#snippet segments()}
184
- {#each options as option, at (option.value)}
185
- {@const off = disabled || option.disabled}
186
- {@const titleId = option.title ? `${uid}-title-${at}` : undefined}
187
- {#snippet radio(props: Record<string, unknown>)}
188
- <input
189
- {...props}
190
- type="radio"
191
- name={name ?? uid}
192
- value={option.value}
193
- bind:group={value}
194
- onchange={() => {
195
- // The binding may not have run yet: the value is set before the callback reads it
196
- value = option.value;
197
- onchange?.(option.value);
198
- }}
199
- disabled={off}
200
- aria-describedby={titleId}
201
- {...stylex.attrs(styles.input, segmentedInputMarker)}
202
- />
203
- {/snippet}
204
- <label {...stylex.attrs(styles.option, off && styles.optionDisabled)}>
205
- {#if option.title}
206
- <Tooltip.Root>
207
- <Tooltip.Trigger disabled={off}>
208
- {#snippet child({ props })}{@render radio(groupTrigger(props))}{/snippet}
209
- </Tooltip.Trigger>
210
- <Tooltip.Content side="top">{option.title}</Tooltip.Content>
211
- </Tooltip.Root>
212
- {:else}
213
- {@render radio({})}
214
- {/if}
215
- <span data-icons {...stylex.attrs(styles.text)}>
216
- {#if option.icon}<option.icon aria-hidden="true" />{/if}{option.label}
217
- </span>
218
- <!-- Always there to describe the radio, which the tooltip does only while open -->
219
- {#if option.title}<span id={titleId} hidden>{option.title}</span>{/if}
220
- </label>
221
- {/each}
222
- {/snippet}
223
232
  {#if titled}
224
233
  <TooltipScope>{@render segments()}</TooltipScope>
225
234
  {:else}
226
235
  {@render segments()}
227
236
  {/if}
228
- </div>
237
+ </UiSegmentedControl>
@@ -1,5 +1,6 @@
1
1
  import type { IconComponent } from '../../internal/icon.js';
2
- import type { HTMLAttributes } from 'svelte/elements';
2
+ import type { Loose, PartProps } from '../../internal/loose.js';
3
+ import { SegmentedControl as UiSegmentedControl } from '@ui-sdk/svelte/segmented-control';
3
4
  import { type Sx } from '../../internal/sx.js';
4
5
  import '../../internal/icons.css';
5
6
  export type SegmentedOption = {
@@ -14,18 +15,19 @@ export type SegmentedOption = {
14
15
  icon?: IconComponent | undefined;
15
16
  disabled?: boolean | undefined;
16
17
  };
17
- export type SegmentedControlProps = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onchange'> & {
18
+ export interface SegmentedControlProps extends Loose<Omit<PartProps<typeof UiSegmentedControl>, 'children' | 'render' | 'value' | 'defaultValue' | 'onValueChange' | 'onchange' | 'orientation' | 'controller' | 'debug'> & {
18
19
  /** The choices, in order. Two to five read best. */
19
20
  options: SegmentedOption[];
20
21
  /** The selected option's value. Bindable. */
21
22
  value?: string | undefined;
22
- /** Form field name. Generated when omitted. */
23
+ /** Form field name. Without one, the choice is not submitted with a form. */
23
24
  name?: string | undefined;
24
25
  disabled?: boolean | undefined;
25
26
  /** Called when the person picks an option, with its value: not when `value` is set. */
26
27
  onchange?: ((value: string) => void) | undefined;
27
28
  sx?: Sx | undefined;
28
- };
29
+ }> {
30
+ }
29
31
  declare const SegmentedControl: import("svelte").Component<SegmentedControlProps, {}, "value">;
30
32
  type SegmentedControl = ReturnType<typeof SegmentedControl>;
31
33
  export default SegmentedControl;
@@ -4,7 +4,15 @@
4
4
  -->
5
5
  <script lang="ts" module>
6
6
  import type { IconComponent } from '../../internal/icon.js';
7
- import { Select } from 'bits-ui';
7
+ import {
8
+ Select as UiSelect,
9
+ SelectContent,
10
+ SelectGroup,
11
+ SelectGroupLabel,
12
+ SelectItem,
13
+ SelectTrigger,
14
+ type ListData
15
+ } from '@ui-sdk/svelte/select';
8
16
  import * as stylex from '@stylexjs/stylex';
9
17
  import type { Snippet } from 'svelte';
10
18
  import Glyph from '../../internal/Glyph.svelte';
@@ -38,6 +46,8 @@
38
46
  options: SelectOption[];
39
47
  /** The chosen value. Bindable. */
40
48
  value?: string | undefined;
49
+ /** Whether the list is open. Bindable. */
50
+ open?: boolean | undefined;
41
51
  /** Shown while nothing is chosen. */
42
52
  placeholder?: string | undefined;
43
53
  /**
@@ -82,7 +92,15 @@
82
92
  whiteSpace: 'nowrap'
83
93
  },
84
94
  placeholder: { color: colors.textSubtle },
85
- prefix: { flexShrink: 0, color: colors.textMuted },
95
+ // Never more than half the trigger, so a long prefix leaves the value room to be read
96
+ prefix: {
97
+ flexShrink: 0,
98
+ maxWidth: '50%',
99
+ overflow: 'hidden',
100
+ textOverflow: 'ellipsis',
101
+ whiteSpace: 'nowrap',
102
+ color: colors.textMuted
103
+ },
86
104
  // The chosen option's icon, on the trigger
87
105
  icon: {
88
106
  '--narvi-icon-size': '1rem',
@@ -95,6 +113,16 @@
95
113
  check: { display: 'grid', marginInlineStart: 'auto', color: colors.accent },
96
114
  // Where options have details, every row keeps the check's room, so the details line up
97
115
  unchecked: { visibility: 'hidden' },
116
+ // A detail never takes more than half the row, so a long one leaves the label room to be
117
+ // read; it is cut short instead
118
+ detail: {
119
+ display: 'block',
120
+ boxSizing: 'border-box',
121
+ maxWidth: '50%',
122
+ overflow: 'hidden',
123
+ textOverflow: 'ellipsis',
124
+ whiteSpace: 'nowrap'
125
+ },
98
126
  mono: { fontFamily: font.mono }
99
127
  });
100
128
 
@@ -112,12 +140,21 @@
112
140
  }
113
141
  return groups;
114
142
  }
143
+
144
+ // The options as ui-sdk's data, so the trigger can find them by typing before the list opens
145
+ function listed(groups: Group[]): ListData {
146
+ return groups.flatMap((group): ListData => {
147
+ const items = group.options.map(({ value, label, disabled }) => ({ value, label, disabled }));
148
+ return group.name ? [{ type: 'group' as const, label: group.name, items }] : items;
149
+ });
150
+ }
115
151
  </script>
116
152
 
117
153
  <script lang="ts">
118
154
  let {
119
155
  options,
120
156
  value = $bindable(),
157
+ open = $bindable(false),
121
158
  placeholder = 'Choose…',
122
159
  prefix,
123
160
  optionIcon,
@@ -139,19 +176,20 @@
139
176
  const detailed = $derived(options.some((option) => option.detail));
140
177
  </script>
141
178
 
142
- <Select.Root
143
- type="single"
144
- bind:value={() => value ?? '', (next) => (value = next || undefined)}
145
- onValueChange={(next) => onchange?.(next)}
146
- items={options}
179
+ <UiSelect
180
+ items={listed(groups)}
181
+ bind:value={() => value ?? null, (next) => (value = next ?? undefined)}
182
+ bind:open={() => open && options.length > 0, (next) => (open = next && options.length > 0)}
183
+ onValueChange={(next) => {
184
+ if (next !== null) onchange?.(next);
185
+ }}
147
186
  {name}
148
187
  disabled={disabled ?? field?.disabled}
149
188
  >
150
- <Select.Trigger
189
+ <SelectTrigger
151
190
  id={id ?? field?.id}
152
191
  aria-label={label ?? (prefix ? `${prefix} ${selected?.label ?? placeholder}` : undefined)}
153
192
  aria-describedby={describedBy ?? field?.describedBy}
154
- data-slot="select"
155
193
  {...attrs([control.base, control[size], styles.trigger, sx], className)}
156
194
  >
157
195
  {#if selected && optionIcon}
@@ -166,53 +204,53 @@
166
204
  {selected?.label ?? placeholder}
167
205
  </span>
168
206
  <span {...stylex.attrs(styles.selector)}><Glyph name="selector" size={14} /></span>
169
- </Select.Trigger>
170
- <Select.Portal>
171
- <Select.Content {align} sideOffset={6} collisionPadding={8} {...stylex.attrs(layer.surface)}>
172
- <Select.Viewport>
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}
176
- <Select.Group>
177
- {#if group.name}
178
- <Select.GroupHeading {...stylex.attrs(layer.heading)}
179
- >{group.name}</Select.GroupHeading
180
- >
181
- {/if}
182
- {#each group.options as option (option.value)}
183
- <Select.Item
184
- value={option.value}
185
- label={option.label}
186
- disabled={option.disabled}
187
- {...stylex.attrs(layer.item)}
188
- >
189
- {#snippet children({ selected })}
190
- {#if optionIcon}
191
- <span data-icons aria-hidden="true" {...stylex.attrs(layer.icon)}
192
- >{@render optionIcon(option)}</span
193
- >
194
- {:else if option.icon}
195
- <span data-icons {...stylex.attrs(layer.icon)}
196
- ><option.icon aria-hidden="true" /></span
197
- >
198
- {/if}
199
- <span {...stylex.attrs(layer.label)}>{option.label}</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
208
- >
209
- {/if}
210
- {/snippet}
211
- </Select.Item>
212
- {/each}
213
- </Select.Group>
214
- {/each}
215
- </Select.Viewport>
216
- </Select.Content>
217
- </Select.Portal>
218
- </Select.Root>
207
+ </SelectTrigger>
208
+ <!-- In place, in the top layer: ui-sdk needs no portal. The list scrolls in the surface. With
209
+ no options it stays shut, rather than open as an empty sliver. -->
210
+ <SelectContent {align} sideOffset={6} collisionPadding={8} {...stylex.attrs(layer.surface)}>
211
+ {#each groups as group, index (index)}
212
+ <!-- A hairline between groups, as a menu draws between its parts -->
213
+ {#if index > 0}<div aria-hidden="true" {...stylex.attrs(layer.separator)}></div>{/if}
214
+ {#if group.name}
215
+ <SelectGroup>
216
+ <SelectGroupLabel {...stylex.attrs(layer.heading)}>{group.name}</SelectGroupLabel>
217
+ {@render items(group.options)}
218
+ </SelectGroup>
219
+ {:else}
220
+ {@render items(group.options)}
221
+ {/if}
222
+ {/each}
223
+ </SelectContent>
224
+ </UiSelect>
225
+
226
+ {#snippet items(options: SelectOption[])}
227
+ {#each options as option (option.value)}
228
+ <SelectItem
229
+ value={option.value}
230
+ label={option.label}
231
+ disabled={option.disabled}
232
+ {...stylex.attrs(layer.item)}
233
+ >
234
+ {#snippet children({ selected })}
235
+ {#if optionIcon}
236
+ <span data-icons aria-hidden="true" {...stylex.attrs(layer.icon)}
237
+ >{@render optionIcon(option)}</span
238
+ >
239
+ {:else if option.icon}
240
+ <span data-icons {...stylex.attrs(layer.icon)}><option.icon aria-hidden="true" /></span>
241
+ {/if}
242
+ <span {...stylex.attrs(layer.label)}>{option.label}</span>
243
+ {#if option.detail}
244
+ <span {...stylex.attrs(layer.trailing, styles.detail, option.detailMono && styles.mono)}
245
+ >{option.detail}</span
246
+ >
247
+ {/if}
248
+ {#if selected || detailed}
249
+ <span aria-hidden={!selected || undefined} {...selected ? check : checkHidden}
250
+ ><Glyph name="check" stroke={1.75} /></span
251
+ >
252
+ {/if}
253
+ {/snippet}
254
+ </SelectItem>
255
+ {/each}
256
+ {/snippet}
@@ -1,5 +1,4 @@
1
1
  import type { IconComponent } from '../../internal/icon.js';
2
- import { Select } from 'bits-ui';
3
2
  import type { Snippet } from 'svelte';
4
3
  import { type ControlSize } from '../../internal/control.js';
5
4
  import { type Sx } from '../../internal/sx.js';
@@ -26,6 +25,8 @@ export type SelectProps = {
26
25
  options: SelectOption[];
27
26
  /** The chosen value. Bindable. */
28
27
  value?: string | undefined;
28
+ /** Whether the list is open. Bindable. */
29
+ open?: boolean | undefined;
29
30
  /** Shown while nothing is chosen. */
30
31
  placeholder?: string | undefined;
31
32
  /**
@@ -53,6 +54,6 @@ export type SelectProps = {
53
54
  sx?: Sx | undefined;
54
55
  class?: string | undefined;
55
56
  };
56
- declare const Select: import("svelte").Component<SelectProps, {}, "value">;
57
+ declare const Select: import("svelte").Component<SelectProps, {}, "open" | "value">;
57
58
  type Select = ReturnType<typeof Select>;
58
59
  export default Select;
@@ -1,6 +1,6 @@
1
1
  <script lang="ts" module>
2
- import type { Loose } from '../../internal/loose.js';
3
- import { Dialog } from 'bits-ui';
2
+ import type { Loose, PartProps } from '../../internal/loose.js';
3
+ import { DialogBackdrop, DialogClose, DialogContent } from '@ui-sdk/svelte/dialog';
4
4
  import * as stylex from '@stylexjs/stylex';
5
5
  import type { Snippet } from 'svelte';
6
6
  import Glyph from '../../internal/Glyph.svelte';
@@ -13,8 +13,8 @@
13
13
 
14
14
  export type SheetSize = 'sm' | 'md' | 'lg' | 'xl' | '2xl';
15
15
 
16
- export type SheetContentProps = Loose<
17
- Omit<Dialog.ContentProps, 'children' | 'child'> & {
16
+ export interface SheetContentProps extends Loose<
17
+ Omit<PartProps<typeof DialogContent>, 'children' | 'render'> & {
18
18
  /** The edge it slides in from. `start` and `end` follow the writing direction. */
19
19
  side?: SheetSide | undefined;
20
20
  /** How wide a sheet along the start or end is: 20, 26, 36, 44 or 56rem. */
@@ -24,14 +24,14 @@
24
24
  /**
25
25
  * What takes the focus as it opens: `sheet`, the sheet itself, so a list or a rail in
26
26
  * it shows no focus ring until the keys move into it; or `first`, its first control,
27
- * for a sheet that holds a form.
27
+ * for a sheet that holds a form. `initialFocus` names anything else and wins over it.
28
28
  */
29
29
  focusOnOpen?: 'sheet' | 'first' | undefined;
30
30
  sx?: Sx | undefined;
31
31
  /** A Sheet.Header, a Sheet.Body and a Sheet.Footer. */
32
32
  children?: Snippet | undefined;
33
33
  }
34
- >;
34
+ > {}
35
35
  </script>
36
36
 
37
37
  <script lang="ts">
@@ -40,8 +40,7 @@
40
40
  size = 'md',
41
41
  closeLabel = 'Close',
42
42
  focusOnOpen = 'sheet',
43
- onOpenAutoFocus,
44
- ref = $bindable(null),
43
+ initialFocus,
45
44
  sx,
46
45
  class: className,
47
46
  children,
@@ -51,33 +50,27 @@
51
50
  const across = $derived(side === 'start' || side === 'end');
52
51
  </script>
53
52
 
54
- <Dialog.Portal>
55
- <Dialog.Overlay data-slot="sheet-overlay" {...stylex.attrs(dialog.overlay)} />
56
- <Dialog.Content
57
- bind:ref
58
- data-slot="sheet"
59
- data-side={side}
60
- tabindex={-1}
61
- onOpenAutoFocus={(event) => {
62
- onOpenAutoFocus?.(event);
63
- if (event.defaultPrevented || focusOnOpen === 'first') return;
64
- event.preventDefault();
65
- ref?.focus({ preventScroll: true });
66
- }}
67
- {...rest}
68
- {...attrs([dialog.content, sheet.sheet, across && sheet[size], sheet[side], sx], className)}
69
- >
70
- {@render children?.()}
71
- {#if closeLabel}
72
- <span {...stylex.attrs(dialog.close)}>
73
- <Dialog.Close>
74
- {#snippet child({ props })}
75
- <Button {...props} variant="ghost" size="sm" iconOnly aria-label={closeLabel}>
76
- <Glyph name="close" />
77
- </Button>
78
- {/snippet}
79
- </Dialog.Close>
80
- </span>
81
- {/if}
82
- </Dialog.Content>
83
- </Dialog.Portal>
53
+ <!--
54
+ A dialog along an edge, on ui-sdk's Dialog rather than its Drawer: a drawer moves itself, by
55
+ drag and snap points, where a sheet slides in on Narvi's own transition and stays put.
56
+ -->
57
+ <DialogBackdrop {...stylex.attrs(dialog.overlay)} />
58
+ <DialogContent
59
+ data-side={side}
60
+ initialFocus={initialFocus ?? (focusOnOpen === 'first' ? 'auto' : 'content')}
61
+ {...rest}
62
+ {...attrs([dialog.content, sheet.sheet, across && sheet[size], sheet[side], sx], className)}
63
+ >
64
+ {@render children?.()}
65
+ {#if closeLabel}
66
+ <span {...stylex.attrs(dialog.close)}>
67
+ <DialogClose>
68
+ {#snippet render({ props })}
69
+ <Button {...props} variant="ghost" size="sm" iconOnly aria-label={closeLabel}>
70
+ <Glyph name="close" />
71
+ </Button>
72
+ {/snippet}
73
+ </DialogClose>
74
+ </span>
75
+ {/if}
76
+ </DialogContent>