@diegopluna/narvi 0.4.1 → 0.5.1

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 (180) hide show
  1. package/README.md +3 -1
  2. package/dist/base.css +3 -0
  3. package/dist/components/app-shell/AppShellPanel.svelte +3 -2
  4. package/dist/components/button/Button.svelte +29 -17
  5. package/dist/components/checkbox/Checkbox.svelte +106 -54
  6. package/dist/components/checkbox/Checkbox.svelte.d.ts +22 -8
  7. package/dist/components/choice-cards/ChoiceCards.svelte +68 -39
  8. package/dist/components/choice-cards/ChoiceCards.svelte.d.ts +12 -8
  9. package/dist/components/collapsible/CollapsibleContent.svelte +71 -17
  10. package/dist/components/collapsible/CollapsibleContent.svelte.d.ts +14 -10
  11. package/dist/components/collapsible/CollapsibleRoot.svelte +13 -9
  12. package/dist/components/collapsible/CollapsibleRoot.svelte.d.ts +8 -9
  13. package/dist/components/collapsible/CollapsibleTrigger.svelte +24 -15
  14. package/dist/components/collapsible/CollapsibleTrigger.svelte.d.ts +10 -14
  15. package/dist/components/color-field/ColorField.svelte +13 -7
  16. package/dist/components/command/CommandDialog.svelte +30 -20
  17. package/dist/components/command/CommandDialog.svelte.d.ts +4 -3
  18. package/dist/components/command/CommandEmpty.svelte +11 -9
  19. package/dist/components/command/CommandEmpty.svelte.d.ts +6 -17
  20. package/dist/components/command/CommandGroup.svelte +32 -11
  21. package/dist/components/command/CommandGroup.svelte.d.ts +7 -11
  22. package/dist/components/command/CommandInput.svelte +25 -10
  23. package/dist/components/command/CommandInput.svelte.d.ts +8 -12
  24. package/dist/components/command/CommandItem.svelte +67 -29
  25. package/dist/components/command/CommandItem.svelte.d.ts +6 -32
  26. package/dist/components/command/CommandList.svelte +8 -10
  27. package/dist/components/command/CommandList.svelte.d.ts +6 -8
  28. package/dist/components/command/CommandRoot.svelte +247 -57
  29. package/dist/components/command/CommandRoot.svelte.d.ts +14 -28
  30. package/dist/components/command/CommandSeparator.svelte +18 -0
  31. package/dist/components/command/CommandSeparator.svelte.d.ts +7 -0
  32. package/dist/components/command/context.d.ts +27 -0
  33. package/dist/components/command/context.js +16 -0
  34. package/dist/components/command/index.d.ts +6 -4
  35. package/dist/components/command/index.js +5 -4
  36. package/dist/components/command/score.d.ts +27 -0
  37. package/dist/components/command/score.js +77 -0
  38. package/dist/components/command/styles.d.ts +32 -9
  39. package/dist/components/command/styles.js +42 -14
  40. package/dist/components/composer/ComposerModelPicker.svelte +350 -346
  41. package/dist/components/composer/ComposerModelPicker.svelte.d.ts +6 -3
  42. package/dist/components/composer/ComposerRoot.svelte.d.ts +1 -1
  43. package/dist/components/dialog/ConfirmDialog.svelte +73 -53
  44. package/dist/components/dialog/DialogClose.svelte +17 -0
  45. package/dist/components/dialog/DialogClose.svelte.d.ts +10 -0
  46. package/dist/components/dialog/DialogContent.svelte +35 -33
  47. package/dist/components/dialog/DialogContent.svelte.d.ts +6 -20
  48. package/dist/components/dialog/DialogDescription.svelte +9 -12
  49. package/dist/components/dialog/DialogDescription.svelte.d.ts +6 -8
  50. package/dist/components/dialog/DialogRoot.svelte +20 -0
  51. package/dist/components/dialog/DialogRoot.svelte.d.ts +7 -0
  52. package/dist/components/dialog/DialogTitle.svelte +12 -8
  53. package/dist/components/dialog/DialogTitle.svelte.d.ts +8 -8
  54. package/dist/components/dialog/DialogTrigger.svelte +17 -0
  55. package/dist/components/dialog/DialogTrigger.svelte.d.ts +10 -0
  56. package/dist/components/dialog/index.d.ts +6 -5
  57. package/dist/components/dialog/index.js +3 -6
  58. package/dist/components/dialog/styles.d.ts +1 -2
  59. package/dist/components/dialog/styles.js +11 -8
  60. package/dist/components/hover-card/HoverCardContent.svelte +35 -29
  61. package/dist/components/hover-card/HoverCardContent.svelte.d.ts +8 -12
  62. package/dist/components/hover-card/HoverCardRoot.svelte +7 -7
  63. package/dist/components/hover-card/HoverCardRoot.svelte.d.ts +5 -4
  64. package/dist/components/hover-card/HoverCardTrigger.svelte +18 -0
  65. package/dist/components/hover-card/HoverCardTrigger.svelte.d.ts +10 -0
  66. package/dist/components/hover-card/index.d.ts +2 -3
  67. package/dist/components/hover-card/index.js +1 -5
  68. package/dist/components/input/Input.svelte.d.ts +1 -1
  69. package/dist/components/markdown/MarkdownBlock.svelte +6 -3
  70. package/dist/components/markdown/MarkdownTable.svelte +15 -7
  71. package/dist/components/menu/ContextMenuContent.svelte +15 -15
  72. package/dist/components/menu/ContextMenuContent.svelte.d.ts +6 -9
  73. package/dist/components/menu/ContextMenuTrigger.svelte +14 -16
  74. package/dist/components/menu/ContextMenuTrigger.svelte.d.ts +8 -14
  75. package/dist/components/menu/MenuCheckboxItem.svelte +22 -11
  76. package/dist/components/menu/MenuCheckboxItem.svelte.d.ts +8 -22
  77. package/dist/components/menu/MenuContent.svelte +16 -18
  78. package/dist/components/menu/MenuContent.svelte.d.ts +6 -18
  79. package/dist/components/menu/MenuGroup.svelte +4 -4
  80. package/dist/components/menu/MenuGroup.svelte.d.ts +5 -4
  81. package/dist/components/menu/MenuItem.svelte +25 -12
  82. package/dist/components/menu/MenuItem.svelte.d.ts +6 -21
  83. package/dist/components/menu/MenuLabel.svelte +7 -11
  84. package/dist/components/menu/MenuLabel.svelte.d.ts +6 -8
  85. package/dist/components/menu/MenuRadioGroup.svelte +4 -4
  86. package/dist/components/menu/MenuRadioGroup.svelte.d.ts +5 -4
  87. package/dist/components/menu/MenuRadioItem.svelte +16 -14
  88. package/dist/components/menu/MenuRadioItem.svelte.d.ts +6 -19
  89. package/dist/components/menu/MenuSeparator.svelte +6 -10
  90. package/dist/components/menu/MenuSeparator.svelte.d.ts +6 -7
  91. package/dist/components/menu/MenuSubContent.svelte +22 -19
  92. package/dist/components/menu/MenuSubContent.svelte.d.ts +8 -15
  93. package/dist/components/menu/MenuSubTrigger.svelte +7 -11
  94. package/dist/components/menu/MenuSubTrigger.svelte.d.ts +6 -15
  95. package/dist/components/menu/MenuTrigger.svelte +17 -0
  96. package/dist/components/menu/MenuTrigger.svelte.d.ts +10 -0
  97. package/dist/components/menu/context-menu.d.ts +2 -2
  98. package/dist/components/menu/context-menu.js +3 -2
  99. package/dist/components/menu/group.js +1 -1
  100. package/dist/components/menu/index.d.ts +5 -4
  101. package/dist/components/menu/index.js +5 -5
  102. package/dist/components/menu/row.d.ts +20 -0
  103. package/dist/components/menu/row.js +12 -0
  104. package/dist/components/popover/PopoverClose.svelte +17 -0
  105. package/dist/components/popover/PopoverClose.svelte.d.ts +10 -0
  106. package/dist/components/popover/PopoverContent.svelte +30 -29
  107. package/dist/components/popover/PopoverContent.svelte.d.ts +6 -17
  108. package/dist/components/popover/PopoverTrigger.svelte +17 -0
  109. package/dist/components/popover/PopoverTrigger.svelte.d.ts +10 -0
  110. package/dist/components/popover/index.d.ts +6 -4
  111. package/dist/components/popover/index.js +6 -5
  112. package/dist/components/progress/Progress.svelte +16 -22
  113. package/dist/components/progress/Progress.svelte.d.ts +6 -5
  114. package/dist/components/reasoning/ReasoningRoot.svelte.d.ts +1 -1
  115. package/dist/components/resize-handle/ResizeHandle.svelte +80 -14
  116. package/dist/components/resize-handle/ResizeHandle.svelte.d.ts +15 -1
  117. package/dist/components/segmented/SegmentedControl.svelte +100 -91
  118. package/dist/components/segmented/SegmentedControl.svelte.d.ts +6 -4
  119. package/dist/components/select/Select.svelte +97 -59
  120. package/dist/components/select/Select.svelte.d.ts +3 -2
  121. package/dist/components/sheet/SheetContent.svelte +31 -38
  122. package/dist/components/sheet/SheetContent.svelte.d.ts +7 -22
  123. package/dist/components/sheet/index.d.ts +3 -5
  124. package/dist/components/sheet/index.js +3 -5
  125. package/dist/components/sheet/styles.js +26 -5
  126. package/dist/components/sidebar/SidebarItem.svelte +2 -3
  127. package/dist/components/slider/Slider.svelte +86 -65
  128. package/dist/components/slider/Slider.svelte.d.ts +9 -8
  129. package/dist/components/split-button/SplitButton.svelte +20 -3
  130. package/dist/components/split-button/SplitButton.svelte.d.ts +1 -1
  131. package/dist/components/switch/Switch.svelte +77 -49
  132. package/dist/components/switch/Switch.svelte.d.ts +15 -8
  133. package/dist/components/tab-strip/TabStrip.svelte +87 -68
  134. package/dist/components/tabs/Tabs.svelte +129 -99
  135. package/dist/components/tabs/Tabs.svelte.d.ts +6 -4
  136. package/dist/components/textarea/Textarea.svelte.d.ts +1 -1
  137. package/dist/components/toast/Toaster.svelte +132 -115
  138. package/dist/components/toast/Toaster.svelte.d.ts +5 -0
  139. package/dist/components/toast/toasts.svelte.d.ts +10 -23
  140. package/dist/components/toast/toasts.svelte.js +62 -40
  141. package/dist/components/toggle/Toggle.svelte +15 -9
  142. package/dist/components/toggle/Toggle.svelte.d.ts +8 -17
  143. package/dist/components/toggle-group/ToggleGroupItem.svelte +20 -9
  144. package/dist/components/toggle-group/ToggleGroupItem.svelte.d.ts +10 -10
  145. package/dist/components/toggle-group/ToggleGroupRoot.svelte +33 -18
  146. package/dist/components/toggle-group/ToggleGroupRoot.svelte.d.ts +4 -4
  147. package/dist/components/tool/ToolRoot.svelte.d.ts +1 -1
  148. package/dist/components/tooltip/TooltipContent.svelte +38 -28
  149. package/dist/components/tooltip/TooltipContent.svelte.d.ts +6 -15
  150. package/dist/components/tooltip/TooltipProvider.svelte +34 -10
  151. package/dist/components/tooltip/TooltipProvider.svelte.d.ts +18 -4
  152. package/dist/components/tooltip/TooltipRoot.svelte +52 -23
  153. package/dist/components/tooltip/TooltipRoot.svelte.d.ts +10 -10
  154. package/dist/components/tooltip/TooltipTrigger.svelte +14 -17
  155. package/dist/components/tooltip/TooltipTrigger.svelte.d.ts +10 -4
  156. package/dist/components/tooltip/index.d.ts +1 -1
  157. package/dist/components/tooltip/index.js +1 -1
  158. package/dist/components/work-fold/WorkFold.svelte +14 -5
  159. package/dist/index.d.ts +5 -5
  160. package/dist/index.js +1 -1
  161. package/dist/internal/TooltipScope.svelte +4 -4
  162. package/dist/internal/layer.d.ts +11 -9
  163. package/dist/internal/layer.js +21 -15
  164. package/dist/internal/loose.d.ts +30 -5
  165. package/dist/internal/loose.js +1 -1
  166. package/dist/internal/markers.stylex.d.ts +0 -4
  167. package/dist/internal/markers.stylex.js +0 -2
  168. package/dist/internal/toggle.d.ts +3 -0
  169. package/dist/internal/toggle.js +6 -2
  170. package/dist/internal/tooltip-trigger.d.ts +7 -6
  171. package/dist/internal/tooltip-trigger.js +9 -12
  172. package/dist/vite.d.ts +7 -1
  173. package/dist/vite.js +20 -5
  174. package/package.json +3 -2
  175. package/skills/building-ui/SKILL.md +22 -22
  176. package/skills/building-ui/references/components.md +30 -4
  177. package/skills/markdown/SKILL.md +1 -1
  178. package/skills/setup/SKILL.md +4 -8
  179. package/skills/styling/SKILL.md +1 -1
  180. package/skills/theming/SKILL.md +3 -7
@@ -1,5 +1,11 @@
1
1
  <script lang="ts" module>
2
- import { Slider } from 'bits-ui';
2
+ import {
3
+ Slider as UiSlider,
4
+ SliderControl,
5
+ SliderIndicator,
6
+ SliderThumb,
7
+ SliderTrack
8
+ } from '@ui-sdk/svelte/slider';
3
9
  import * as stylex from '@stylexjs/stylex';
4
10
  import type { HTMLAttributes } from 'svelte/elements';
5
11
  import { attrs, type Sx } from '../../internal/sx.js';
@@ -7,7 +13,7 @@
7
13
  import { media } from '../../media.stylex.js';
8
14
 
9
15
  export type SliderProps<T extends number | number[] = number> = Omit<
10
- HTMLAttributes<HTMLSpanElement>,
16
+ HTMLAttributes<HTMLDivElement>,
11
17
  'children' | 'dir'
12
18
  > & {
13
19
  /**
@@ -21,10 +27,12 @@
21
27
  onValueCommit?: ((value: T) => void) | undefined;
22
28
  min?: number | undefined;
23
29
  max?: number | undefined;
24
- /** How far one step goes, or the values it may stop at. */
25
- step?: number | number[] | undefined;
30
+ /** How far one step goes, counted from `min`. */
31
+ step?: number | undefined;
26
32
  orientation?: 'horizontal' | 'vertical' | undefined;
27
- /** Set `rtl` in a right-to-left layout, so the slider runs from the right. */
33
+ /**
34
+ * `rtl` runs the slider from the right. Left out, it follows the page's direction.
35
+ */
28
36
  dir?: 'ltr' | 'rtl' | undefined;
29
37
  disabled?: boolean | undefined;
30
38
  /**
@@ -35,11 +43,13 @@
35
43
  /** Reads a value out in words, such as `0:42` for a playhead or `40%`. */
36
44
  format?: ((value: number) => string) | undefined;
37
45
  sx?: Sx | undefined;
38
- ref?: HTMLSpanElement | null | undefined;
46
+ ref?: HTMLElement | null | undefined;
39
47
  };
40
48
 
41
49
  const DISABLED = ':is([data-disabled])';
42
- const ACTIVE = ':is([data-active])';
50
+ const DRAGGING = ':is([data-dragging])';
51
+ // The thumb's range input, hidden inside it, is what takes focus
52
+ const FOCUSED = ':has(:focus-visible)';
43
53
 
44
54
  const styles = stylex.create({
45
55
  root: {
@@ -56,17 +66,31 @@
56
66
  cursor: { default: 'pointer', [DISABLED]: 'not-allowed' },
57
67
  opacity: { default: 1, [DISABLED]: 0.5 }
58
68
  },
59
- horizontal: { width: '100%', minWidth: '6rem', height: '1.5rem' },
69
+ // In a row beside a label or a value, it gives way down to its least width
70
+ horizontal: { flexShrink: 1, width: '100%', minWidth: '6rem', height: '1.5rem' },
60
71
  vertical: {
61
72
  flexDirection: 'column',
62
73
  width: '1.5rem',
63
74
  height: '100%',
64
75
  minHeight: '6rem'
65
76
  },
77
+ // Where presses land: the whole height of the slider around its thin track
78
+ control: { display: 'flex', flexGrow: 1, alignSelf: 'stretch', minWidth: 0 },
79
+ controlVertical: { flexDirection: 'column' },
80
+ // What ui-sdk places the thumbs along, in percent: as long as the track, as tall as the control.
81
+ // Inset by half a thumb, so a thumb at either end stays inside the slider's box.
82
+ rail: {
83
+ display: 'flex',
84
+ alignItems: 'center',
85
+ justifyContent: 'center',
86
+ flexGrow: 1,
87
+ alignSelf: 'stretch'
88
+ },
89
+ railHorizontal: { marginInline: '0.5rem' },
90
+ railVertical: { marginBlock: '0.5rem' },
66
91
  // A recess, like Progress's track
67
92
  track: {
68
93
  position: 'relative',
69
- flexGrow: 1,
70
94
  overflow: 'hidden',
71
95
  borderRadius: radius.pill,
72
96
  backgroundColor: colors.fillSunken,
@@ -75,9 +99,10 @@
75
99
  outlineColor: 'transparent',
76
100
  outlineOffset: '-1px'
77
101
  },
78
- trackHorizontal: { height: '0.25rem' },
79
- trackVertical: { width: '0.25rem' },
80
- // How far along: lit with the accent, as progress is
102
+ trackHorizontal: { width: '100%', height: '0.25rem' },
103
+ // Stretched to the rail, which has a height even where the slider's is not given
104
+ trackVertical: { width: '0.25rem', alignSelf: 'stretch' },
105
+ // How far along: lit with the accent, as progress is. ui-sdk places and sizes it.
81
106
  range: {
82
107
  backgroundColor: colors.accent,
83
108
  // Forced colours drop a background colour, not an image
@@ -87,11 +112,8 @@
87
112
  },
88
113
  forcedColorAdjust: 'none'
89
114
  },
90
- rangeHorizontal: { height: '100%' },
91
- rangeVertical: { width: '100%' },
92
- // Placed by bits-ui with `left` and `translate`, so a press grows it with `scale`
115
+ // Placed by ui-sdk with `inset` and `translate`, so a press grows it with `scale`
93
116
  thumb: {
94
- zIndex: 1,
95
117
  boxSizing: 'border-box',
96
118
  display: 'block',
97
119
  width: '1rem',
@@ -106,15 +128,15 @@
106
128
  }
107
129
  },
108
130
  forcedColorAdjust: 'none',
109
- cursor: { default: 'grab', [ACTIVE]: 'grabbing', [DISABLED]: 'not-allowed' },
110
- scale: { default: null, [media.motion]: { default: 1, [ACTIVE]: 1.15 } },
131
+ cursor: { default: 'grab', [DRAGGING]: 'grabbing', [DISABLED]: 'not-allowed' },
132
+ scale: { default: null, [media.motion]: { default: 1, [DRAGGING]: 1.15 } },
111
133
  outlineStyle: 'solid',
112
- outlineWidth: { default: '1px', ':focus-visible': '2px' },
134
+ outlineWidth: { default: '1px', [FOCUSED]: '2px' },
113
135
  outlineColor: {
114
136
  default: 'transparent',
115
- ':focus-visible': { default: colors.focusRing, [media.forcedColors]: 'Highlight' }
137
+ [FOCUSED]: { default: colors.focusRing, [media.forcedColors]: 'Highlight' }
116
138
  },
117
- outlineOffset: { default: '-1px', ':focus-visible': '2px' },
139
+ outlineOffset: { default: '-1px', [FOCUSED]: '2px' },
118
140
  transitionProperty: { default: 'box-shadow', [media.motion]: 'scale, box-shadow' },
119
141
  transitionDuration: motion.fast,
120
142
  transitionTimingFunction: motion.easeOut,
@@ -138,7 +160,7 @@
138
160
  max = 100,
139
161
  step = 1,
140
162
  orientation = 'horizontal',
141
- dir = 'ltr',
163
+ dir,
142
164
  disabled = false,
143
165
  thumbLabels,
144
166
  format,
@@ -151,50 +173,49 @@
151
173
  }: SliderProps<T> = $props();
152
174
 
153
175
  const vertical = $derived(orientation === 'vertical');
154
-
155
- // bits-ui types a single and a multiple slider apart; which one this is
156
- // follows from the value it is given
157
- const root = $derived({
158
- type: Array.isArray(value) ? 'multiple' : 'single',
159
- value,
160
- onValueChange: (next: number | number[]) => {
161
- value = next as T;
162
- onValueChange?.(next as T);
163
- },
164
- onValueCommit: (next: number | number[]) => onValueCommit?.(next as T),
165
- min,
166
- max,
167
- step,
168
- orientation,
169
- dir,
170
- disabled
171
- } as Slider.RootProps);
172
-
173
- const valueAt = (index: number) =>
174
- Array.isArray(value) ? (value[index] ?? min) : ((value as number | undefined) ?? min);
176
+ // One thumb for a number, one for each value of an array
177
+ const thumbs = $derived(Array.isArray(value) ? value.length : 1);
178
+ // A thumb of its own name leaves the slider's to the group around the thumbs
179
+ const named = $derived(!!thumbLabels?.length);
175
180
  </script>
176
181
 
177
- <Slider.Root
178
- bind:ref
179
- data-slot="slider"
180
- {...root}
181
- {...rest as Record<string, unknown>}
182
+ <UiSlider
183
+ bind:value={() => value as number | number[] | undefined, (next) => (value = next as T)}
184
+ onValueChange={(next) => onValueChange?.(next as T)}
185
+ onValueCommit={(next) => onValueCommit?.(next as T)}
186
+ {min}
187
+ {max}
188
+ {step}
189
+ {orientation}
190
+ {disabled}
191
+ {format}
192
+ {dir}
193
+ aria-label={named ? ariaLabel : undefined}
194
+ aria-labelledby={named ? ariaLabelledby : undefined}
195
+ {...rest}
182
196
  {...attrs([styles.root, vertical ? styles.vertical : styles.horizontal, sx], className)}
197
+ {@attach (element: HTMLElement) => {
198
+ ref = element;
199
+ return () => (ref = null);
200
+ }}
183
201
  >
184
- {#snippet children({ thumbItems })}
185
- <span {...stylex.attrs(styles.track, vertical ? styles.trackVertical : styles.trackHorizontal)}>
186
- <Slider.Range
187
- {...stylex.attrs(styles.range, vertical ? styles.rangeVertical : styles.rangeHorizontal)}
188
- />
189
- </span>
190
- {#each thumbItems as thumb (thumb.index)}
191
- <Slider.Thumb
192
- index={thumb.index}
193
- aria-label={thumbLabels?.[thumb.index] ?? ariaLabel}
194
- aria-labelledby={thumbLabels?.[thumb.index] ? undefined : ariaLabelledby}
195
- aria-valuetext={format?.(valueAt(thumb.index))}
196
- {...stylex.attrs(styles.thumb)}
197
- />
198
- {/each}
199
- {/snippet}
200
- </Slider.Root>
202
+ <SliderControl {...stylex.attrs(styles.control, vertical && styles.controlVertical)}>
203
+ <SliderTrack
204
+ {...stylex.attrs(styles.rail, vertical ? styles.railVertical : styles.railHorizontal)}
205
+ >
206
+ <span
207
+ {...stylex.attrs(styles.track, vertical ? styles.trackVertical : styles.trackHorizontal)}
208
+ >
209
+ <SliderIndicator {...stylex.attrs(styles.range)} />
210
+ </span>
211
+ {#each { length: thumbs }, index (index)}
212
+ <SliderThumb
213
+ {index}
214
+ aria-label={thumbLabels?.[index] ?? ariaLabel}
215
+ aria-labelledby={thumbLabels?.[index] ? undefined : ariaLabelledby}
216
+ {...stylex.attrs(styles.thumb)}
217
+ />
218
+ {/each}
219
+ </SliderTrack>
220
+ </SliderControl>
221
+ </UiSlider>
@@ -1,7 +1,6 @@
1
- import { Slider } from 'bits-ui';
2
1
  import type { HTMLAttributes } from 'svelte/elements';
3
2
  import { type Sx } from '../../internal/sx.js';
4
- export type SliderProps<T extends number | number[] = number> = Omit<HTMLAttributes<HTMLSpanElement>, 'children' | 'dir'> & {
3
+ export type SliderProps<T extends number | number[] = number> = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'dir'> & {
5
4
  /**
6
5
  * Where the thumb stands. Bindable. A number gives one thumb; an array gives
7
6
  * one thumb for each of its values, such as a range's two ends.
@@ -13,10 +12,12 @@ export type SliderProps<T extends number | number[] = number> = Omit<HTMLAttribu
13
12
  onValueCommit?: ((value: T) => void) | undefined;
14
13
  min?: number | undefined;
15
14
  max?: number | undefined;
16
- /** How far one step goes, or the values it may stop at. */
17
- step?: number | number[] | undefined;
15
+ /** How far one step goes, counted from `min`. */
16
+ step?: number | undefined;
18
17
  orientation?: 'horizontal' | 'vertical' | undefined;
19
- /** Set `rtl` in a right-to-left layout, so the slider runs from the right. */
18
+ /**
19
+ * `rtl` runs the slider from the right. Left out, it follows the page's direction.
20
+ */
20
21
  dir?: 'ltr' | 'rtl' | undefined;
21
22
  disabled?: boolean | undefined;
22
23
  /**
@@ -27,12 +28,12 @@ export type SliderProps<T extends number | number[] = number> = Omit<HTMLAttribu
27
28
  /** Reads a value out in words, such as `0:42` for a playhead or `40%`. */
28
29
  format?: ((value: number) => string) | undefined;
29
30
  sx?: Sx | undefined;
30
- ref?: HTMLSpanElement | null | undefined;
31
+ ref?: HTMLElement | null | undefined;
31
32
  };
32
33
  declare function $$render<T extends number | number[] = number>(): {
33
34
  props: SliderProps<T>;
34
35
  exports: {};
35
- bindings: "ref" | "value";
36
+ bindings: "value" | "ref";
36
37
  slots: {};
37
38
  events: {};
38
39
  };
@@ -40,7 +41,7 @@ declare class __sveltets_Render<T extends number | number[] = number> {
40
41
  props(): ReturnType<typeof $$render<T>>['props'];
41
42
  events(): ReturnType<typeof $$render<T>>['events'];
42
43
  slots(): ReturnType<typeof $$render<T>>['slots'];
43
- bindings(): "ref" | "value";
44
+ bindings(): "value" | "ref";
44
45
  exports(): {};
45
46
  }
46
47
  interface $$IsomorphicComponent {
@@ -74,8 +74,21 @@
74
74
  display: 'inline-flex',
75
75
  alignItems: 'stretch',
76
76
  flexShrink: 0,
77
+ // Never wider than what holds it: a long label is cut short at the main button's end,
78
+ // and the button that opens the menu stays whole
79
+ maxWidth: '100%',
77
80
  verticalAlign: 'middle'
78
81
  },
82
+ mainFits: { flexShrink: 1, minWidth: 0 },
83
+ // The label and its icon in a row, as the button lays them out, cut at the side only, so
84
+ // accents and descenders keep their room
85
+ label: {
86
+ display: 'inline-flex',
87
+ alignItems: 'center',
88
+ gap: 'inherit',
89
+ minWidth: 0,
90
+ overflowX: 'clip'
91
+ },
79
92
  // The focused half is drawn over its neighbour, so its ring is whole
80
93
  half: { zIndex: { default: null, ':focus-visible': 1 } },
81
94
  main: { borderStartEndRadius: 0, borderEndEndRadius: 0 },
@@ -138,6 +151,9 @@
138
151
  ...rest
139
152
  }: SplitButtonProps = $props();
140
153
 
154
+ // The menu lines up with the pair, not with its chevron alone, as `align` says
155
+ let pair = $state<HTMLElement | null>(null);
156
+
141
157
  const glyph = { micro: 10, xs: 12, sm: 12, md: 14, lg: 16 } as const;
142
158
  const divider = {
143
159
  primary: styles.morePrimary,
@@ -151,6 +167,7 @@
151
167
  aria-label={label}
152
168
  data-slot="split-button"
153
169
  {...attrs([styles.group, sx], className)}
170
+ bind:this={pair}
154
171
  >
155
172
  <Button
156
173
  bind:ref
@@ -161,9 +178,9 @@
161
178
  disabled={disabled || mainDisabled}
162
179
  {loading}
163
180
  {tooltipSide}
164
- sx={[styles.half, menu && styles.main, mainSx]}
181
+ sx={[styles.half, styles.mainFits, menu && styles.main, mainSx]}
165
182
  >
166
- {@render children?.()}
183
+ <span {...stylex.attrs(styles.label)}>{@render children?.()}</span>
167
184
  </Button>
168
185
  {#if menu}
169
186
  <Menu.Root bind:open onOpenChange={onopenchange}>
@@ -184,7 +201,7 @@
184
201
  </Button>
185
202
  {/snippet}
186
203
  </Menu.Trigger>
187
- <Menu.Content {align} width={menuWidth} minWidth={menuMinWidth}>
204
+ <Menu.Content {align} anchor={pair} width={menuWidth} minWidth={menuMinWidth}>
188
205
  {@render menu()}
189
206
  </Menu.Content>
190
207
  </Menu.Root>
@@ -48,6 +48,6 @@ export type SplitButtonProps = Omit<ButtonProps, 'variant' | 'iconOnly' | 'href'
48
48
  /** The main button's label, and its icon if it has one. */
49
49
  children?: Snippet | undefined;
50
50
  };
51
- declare const SplitButton: import("svelte").Component<SplitButtonProps, {}, "ref" | "open">;
51
+ declare const SplitButton: import("svelte").Component<SplitButtonProps, {}, "open" | "ref">;
52
52
  type SplitButton = ReturnType<typeof SplitButton>;
53
53
  export default SplitButton;
@@ -1,24 +1,38 @@
1
1
  <script lang="ts" module>
2
+ import { Switch as UiSwitch } from '@ui-sdk/svelte/switch';
2
3
  import * as stylex from '@stylexjs/stylex';
3
4
  import type { Snippet } from 'svelte';
4
- import type { ChangeEventHandler, HTMLInputAttributes } from 'svelte/elements';
5
+ import type { ChangeEventHandler } from 'svelte/elements';
6
+ import type { Loose, PartProps } from '../../internal/loose.js';
5
7
  import { attrs, type Sx } from '../../internal/sx.js';
6
8
  import { colors, font, motion, radius } from '../../tokens.stylex.js';
7
9
  import { media } from '../../media.stylex.js';
10
+ import { getFieldContext } from '../field/context.js';
8
11
 
9
- export type SwitchProps = Omit<HTMLInputAttributes, 'type' | 'role' | 'children'> & {
10
- checked?: boolean | undefined;
11
- /** Called with the new value when the person turns it on or off. */
12
- onCheckedChange?: ((checked: boolean) => void) | undefined;
13
- disabled?: boolean | undefined;
14
- /** A second, quieter line under the label. */
15
- description?: string | undefined;
16
- /** Applied to the outermost element: the label when there is one, else the input. */
17
- sx?: Sx | undefined;
18
- ref?: HTMLInputElement | null | undefined;
19
- /** Label content. Without it, give the switch an `aria-label`. */
20
- children?: Snippet | undefined;
21
- };
12
+ export interface SwitchProps extends Loose<
13
+ Omit<
14
+ PartProps<typeof UiSwitch>,
15
+ 'children' | 'render' | 'checked' | 'defaultChecked' | 'onchange'
16
+ > & {
17
+ /** Whether it is on. Bindable. */
18
+ checked?: boolean | undefined;
19
+ /**
20
+ * The native change event, from the form input underneath: `event.currentTarget.checked`
21
+ * is the new value. It follows `onCheckedChange`.
22
+ */
23
+ onchange?: ChangeEventHandler<HTMLInputElement> | undefined;
24
+ /** A second, quieter line under the label. */
25
+ description?: string | undefined;
26
+ /** Applied to the outermost element: the label when there is one, else the switch. */
27
+ sx?: Sx | undefined;
28
+ /** The switch's button. Bindable. */
29
+ ref?: HTMLButtonElement | null | undefined;
30
+ /** Label content. Without it, give the switch an `aria-label`. */
31
+ children?: Snippet | undefined;
32
+ }
33
+ > {}
34
+
35
+ const ON = ':is([data-checked])';
22
36
 
23
37
  const styles = stylex.create({
24
38
  root: {
@@ -32,6 +46,8 @@
32
46
  cursor: 'pointer',
33
47
  WebkitTapHighlightColor: 'transparent'
34
48
  },
49
+ // A label with no break in it, such as a URL, wraps rather than running out of the box
50
+ text: { minWidth: 0, overflowWrap: 'anywhere' },
35
51
  rootDisabled: {
36
52
  color: colors.textSubtle,
37
53
  cursor: 'not-allowed'
@@ -42,24 +58,26 @@
42
58
  fontSize: font.sizeCaption,
43
59
  lineHeight: font.leadingSnug
44
60
  },
45
- input: {
61
+ control: {
46
62
  position: 'relative',
63
+ display: 'inline-block',
47
64
  flexShrink: 0,
48
65
  boxSizing: 'border-box',
49
66
  width: '2rem',
50
67
  height: '1.125rem',
51
68
  margin: 0,
52
69
  marginBlock: '1px',
70
+ padding: 0,
53
71
  borderWidth: 0,
54
72
  borderRadius: radius.pill,
55
73
  backgroundColor: {
56
74
  default: colors.borderControl,
57
75
  ':hover': { default: null, [media.hover]: colors.borderControlHover },
58
- [media.forcedColors]: { default: 'Canvas', ':checked': 'Highlight' }
76
+ [media.forcedColors]: { default: 'Canvas', [ON]: 'Highlight' }
59
77
  },
60
78
  backgroundImage: {
61
79
  default: 'none',
62
- ':checked': `linear-gradient(${colors.accent}, ${colors.accent})`,
80
+ [ON]: `linear-gradient(${colors.accent}, ${colors.accent})`,
63
81
  [media.forcedColors]: 'none'
64
82
  },
65
83
  forcedColorAdjust: 'none',
@@ -88,20 +106,20 @@
88
106
  height: '0.875rem',
89
107
  translate: {
90
108
  default: '0 0',
91
- ':checked': { default: '14px 0', ':dir(rtl)': '-14px 0' }
109
+ [ON]: { default: '14px 0', ':dir(rtl)': '-14px 0' }
92
110
  },
93
111
  // While pressed, the thumb stretches towards where it is about to go
94
112
  scale: { default: null, ':active': { default: null, [media.motion]: '1.2 1' } },
95
113
  transformOrigin: {
96
114
  default: 'left center',
97
115
  ':dir(rtl)': 'right center',
98
- ':checked': { default: 'right center', ':dir(rtl)': 'left center' }
116
+ [ON]: { default: 'right center', ':dir(rtl)': 'left center' }
99
117
  },
100
118
  borderRadius: radius.pill,
101
119
  backgroundColor: {
102
120
  default: colors.thumb,
103
- ':checked': colors.onAccent,
104
- [media.forcedColors]: { default: 'ButtonText', ':checked': 'HighlightText' }
121
+ [ON]: colors.onAccent,
122
+ [media.forcedColors]: { default: 'ButtonText', [ON]: 'HighlightText' }
105
123
  },
106
124
  transitionProperty: {
107
125
  default: 'background-color',
@@ -127,9 +145,12 @@
127
145
  <script lang="ts">
128
146
  let {
129
147
  checked = $bindable(false),
130
- onCheckedChange,
131
148
  onchange,
132
- disabled = false,
149
+ disabled,
150
+ required,
151
+ id,
152
+ 'aria-describedby': describedBy,
153
+ 'aria-invalid': ariaInvalid,
133
154
  description,
134
155
  sx,
135
156
  class: className,
@@ -138,25 +159,41 @@
138
159
  ...rest
139
160
  }: SwitchProps = $props();
140
161
 
141
- const changed: ChangeEventHandler<HTMLInputElement> = (event) => {
142
- onchange?.(event);
143
- onCheckedChange?.(event.currentTarget.checked);
144
- };
162
+ const field = getFieldContext();
163
+ const isDisabled = $derived(disabled ?? field?.disabled ?? false);
164
+
165
+ // ui-sdk's switch is a button, and the native change event fires on the form input it keeps
166
+ // beside it, so `onchange` is heard there, where `currentTarget.checked` is the new value.
167
+ $effect(() => {
168
+ const input = ref?.nextElementSibling;
169
+ if (!onchange || !(input instanceof HTMLInputElement)) return;
170
+ const listener = onchange as unknown as EventListener;
171
+ input.addEventListener('change', listener);
172
+ return () => input.removeEventListener('change', listener);
173
+ });
145
174
  </script>
146
175
 
176
+ {#snippet control(own: (Sx | false)[], className?: SwitchProps['class'])}
177
+ <UiSwitch
178
+ bind:checked
179
+ id={id ?? field?.id}
180
+ disabled={isDisabled}
181
+ required={required ?? field?.required}
182
+ aria-invalid={ariaInvalid ?? (field?.invalid || undefined)}
183
+ aria-describedby={describedBy ?? field?.describedBy}
184
+ {...rest}
185
+ {...attrs([styles.control, ...own], className)}
186
+ {@attach (element: HTMLButtonElement) => {
187
+ ref = element;
188
+ return () => (ref = null);
189
+ }}
190
+ />
191
+ {/snippet}
192
+
147
193
  {#if children}
148
- <label {...attrs([styles.root, disabled && styles.rootDisabled, sx], className)}>
149
- <input
150
- bind:this={ref}
151
- bind:checked
152
- type="checkbox"
153
- role="switch"
154
- {disabled}
155
- {...rest}
156
- onchange={changed}
157
- {...stylex.attrs(styles.input)}
158
- />
159
- <span>
194
+ <label {...attrs([styles.root, isDisabled && styles.rootDisabled, sx], className)}>
195
+ {@render control([])}
196
+ <span {...stylex.attrs(styles.text)}>
160
197
  {@render children()}
161
198
  {#if description}
162
199
  <span {...stylex.attrs(styles.description)}>{description}</span>
@@ -164,14 +201,5 @@
164
201
  </span>
165
202
  </label>
166
203
  {:else}
167
- <input
168
- bind:this={ref}
169
- bind:checked
170
- type="checkbox"
171
- role="switch"
172
- {disabled}
173
- {...rest}
174
- onchange={changed}
175
- {...attrs([styles.input, styles.standalone, sx], className)}
176
- />
204
+ {@render control([styles.standalone, sx], className)}
177
205
  {/if}
@@ -1,19 +1,26 @@
1
+ import { Switch as UiSwitch } from '@ui-sdk/svelte/switch';
1
2
  import type { Snippet } from 'svelte';
2
- import type { HTMLInputAttributes } from 'svelte/elements';
3
+ import type { ChangeEventHandler } from 'svelte/elements';
4
+ import type { Loose, PartProps } from '../../internal/loose.js';
3
5
  import { type Sx } from '../../internal/sx.js';
4
- export type SwitchProps = Omit<HTMLInputAttributes, 'type' | 'role' | 'children'> & {
6
+ export interface SwitchProps extends Loose<Omit<PartProps<typeof UiSwitch>, 'children' | 'render' | 'checked' | 'defaultChecked' | 'onchange'> & {
7
+ /** Whether it is on. Bindable. */
5
8
  checked?: boolean | undefined;
6
- /** Called with the new value when the person turns it on or off. */
7
- onCheckedChange?: ((checked: boolean) => void) | undefined;
8
- disabled?: boolean | undefined;
9
+ /**
10
+ * The native change event, from the form input underneath: `event.currentTarget.checked`
11
+ * is the new value. It follows `onCheckedChange`.
12
+ */
13
+ onchange?: ChangeEventHandler<HTMLInputElement> | undefined;
9
14
  /** A second, quieter line under the label. */
10
15
  description?: string | undefined;
11
- /** Applied to the outermost element: the label when there is one, else the input. */
16
+ /** Applied to the outermost element: the label when there is one, else the switch. */
12
17
  sx?: Sx | undefined;
13
- ref?: HTMLInputElement | null | undefined;
18
+ /** The switch's button. Bindable. */
19
+ ref?: HTMLButtonElement | null | undefined;
14
20
  /** Label content. Without it, give the switch an `aria-label`. */
15
21
  children?: Snippet | undefined;
16
- };
22
+ }> {
23
+ }
17
24
  declare const Switch: import("svelte").Component<SwitchProps, {}, "ref" | "checked">;
18
25
  type Switch = ReturnType<typeof Switch>;
19
26
  export default Switch;