@proyecto-viviana/solidaria 0.2.1 → 0.2.3

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 (208) hide show
  1. package/dist/autocomplete/createAutocomplete.d.ts +2 -2
  2. package/dist/autocomplete/createAutocomplete.d.ts.map +1 -1
  3. package/dist/index.js +233 -234
  4. package/dist/index.js.map +2 -2
  5. package/dist/index.ssr.js +233 -234
  6. package/dist/index.ssr.js.map +2 -2
  7. package/dist/interactions/PressEvent.d.ts +13 -10
  8. package/dist/interactions/PressEvent.d.ts.map +1 -1
  9. package/dist/interactions/createPress.d.ts.map +1 -1
  10. package/dist/interactions/index.d.ts +1 -1
  11. package/dist/interactions/index.d.ts.map +1 -1
  12. package/dist/select/createHiddenSelect.d.ts.map +1 -1
  13. package/dist/toolbar/createToolbar.d.ts.map +1 -1
  14. package/dist/tooltip/createTooltipTrigger.d.ts.map +1 -1
  15. package/package.json +9 -7
  16. package/src/autocomplete/createAutocomplete.ts +341 -0
  17. package/src/autocomplete/index.ts +9 -0
  18. package/src/breadcrumbs/createBreadcrumbs.ts +196 -0
  19. package/src/breadcrumbs/index.ts +8 -0
  20. package/src/button/createButton.ts +142 -0
  21. package/src/button/createToggleButton.ts +101 -0
  22. package/src/button/index.ts +4 -0
  23. package/src/button/types.ts +78 -0
  24. package/src/calendar/createCalendar.ts +138 -0
  25. package/src/calendar/createCalendarCell.ts +187 -0
  26. package/src/calendar/createCalendarGrid.ts +140 -0
  27. package/src/calendar/createRangeCalendar.ts +136 -0
  28. package/src/calendar/createRangeCalendarCell.ts +186 -0
  29. package/src/calendar/index.ts +34 -0
  30. package/src/checkbox/createCheckbox.ts +135 -0
  31. package/src/checkbox/createCheckboxGroup.ts +137 -0
  32. package/src/checkbox/createCheckboxGroupItem.ts +117 -0
  33. package/src/checkbox/createCheckboxGroupState.ts +193 -0
  34. package/src/checkbox/index.ts +13 -0
  35. package/src/color/createColorArea.ts +314 -0
  36. package/src/color/createColorField.ts +137 -0
  37. package/src/color/createColorSlider.ts +197 -0
  38. package/src/color/createColorSwatch.ts +40 -0
  39. package/src/color/createColorWheel.ts +208 -0
  40. package/src/color/index.ts +24 -0
  41. package/src/color/types.ts +116 -0
  42. package/src/combobox/createComboBox.ts +647 -0
  43. package/src/combobox/index.ts +6 -0
  44. package/src/combobox/intl/en-US.json +7 -0
  45. package/src/combobox/intl/es-ES.json +7 -0
  46. package/src/combobox/intl/index.ts +23 -0
  47. package/src/datepicker/createDateField.ts +154 -0
  48. package/src/datepicker/createDatePicker.ts +206 -0
  49. package/src/datepicker/createDateSegment.ts +229 -0
  50. package/src/datepicker/createTimeField.ts +154 -0
  51. package/src/datepicker/index.ts +28 -0
  52. package/src/dialog/createDialog.ts +120 -0
  53. package/src/dialog/index.ts +2 -0
  54. package/src/dialog/types.ts +19 -0
  55. package/src/disclosure/createDisclosure.ts +131 -0
  56. package/src/disclosure/createDisclosureGroup.ts +62 -0
  57. package/src/disclosure/index.ts +11 -0
  58. package/src/dnd/createDrag.ts +209 -0
  59. package/src/dnd/createDraggableCollection.ts +63 -0
  60. package/src/dnd/createDraggableItem.ts +243 -0
  61. package/src/dnd/createDrop.ts +321 -0
  62. package/src/dnd/createDroppableCollection.ts +293 -0
  63. package/src/dnd/createDroppableItem.ts +213 -0
  64. package/src/dnd/index.ts +47 -0
  65. package/src/dnd/types.ts +89 -0
  66. package/src/dnd/utils.ts +294 -0
  67. package/src/focus/FocusScope.tsx +408 -0
  68. package/src/focus/createAutoFocus.ts +321 -0
  69. package/src/focus/createFocusRestore.ts +313 -0
  70. package/src/focus/createVirtualFocus.ts +396 -0
  71. package/src/focus/index.ts +35 -0
  72. package/src/form/createFormReset.ts +51 -0
  73. package/src/form/createFormValidation.ts +224 -0
  74. package/src/form/index.ts +11 -0
  75. package/src/grid/GridKeyboardDelegate.ts +429 -0
  76. package/src/grid/createGrid.ts +261 -0
  77. package/src/grid/createGridCell.ts +182 -0
  78. package/src/grid/createGridRow.ts +153 -0
  79. package/src/grid/index.ts +18 -0
  80. package/src/grid/types.ts +133 -0
  81. package/src/gridlist/createGridList.ts +185 -0
  82. package/src/gridlist/createGridListItem.ts +180 -0
  83. package/src/gridlist/createGridListSelectionCheckbox.ts +59 -0
  84. package/src/gridlist/index.ts +16 -0
  85. package/src/gridlist/types.ts +81 -0
  86. package/src/i18n/NumberFormatter.ts +266 -0
  87. package/src/i18n/createCollator.ts +79 -0
  88. package/src/i18n/createDateFormatter.ts +83 -0
  89. package/src/i18n/createFilter.ts +131 -0
  90. package/src/i18n/createNumberFormatter.ts +52 -0
  91. package/src/i18n/createStringFormatter.ts +87 -0
  92. package/src/i18n/index.ts +40 -0
  93. package/src/i18n/locale.tsx +188 -0
  94. package/src/i18n/utils.ts +99 -0
  95. package/src/index.ts +670 -0
  96. package/src/interactions/FocusableProvider.tsx +44 -0
  97. package/src/interactions/PressEvent.ts +126 -0
  98. package/src/interactions/createFocus.ts +163 -0
  99. package/src/interactions/createFocusRing.ts +89 -0
  100. package/src/interactions/createFocusWithin.ts +206 -0
  101. package/src/interactions/createFocusable.ts +168 -0
  102. package/src/interactions/createHover.ts +254 -0
  103. package/src/interactions/createInteractionModality.ts +424 -0
  104. package/src/interactions/createKeyboard.ts +82 -0
  105. package/src/interactions/createLongPress.ts +174 -0
  106. package/src/interactions/createMove.ts +289 -0
  107. package/src/interactions/createPress.ts +834 -0
  108. package/src/interactions/index.ts +78 -0
  109. package/src/label/createField.ts +145 -0
  110. package/src/label/createLabel.ts +117 -0
  111. package/src/label/createLabels.ts +50 -0
  112. package/src/label/index.ts +19 -0
  113. package/src/landmark/createLandmark.ts +377 -0
  114. package/src/landmark/index.ts +8 -0
  115. package/src/link/createLink.ts +182 -0
  116. package/src/link/index.ts +1 -0
  117. package/src/listbox/createListBox.ts +269 -0
  118. package/src/listbox/createOption.ts +151 -0
  119. package/src/listbox/index.ts +12 -0
  120. package/src/live-announcer/announce.ts +322 -0
  121. package/src/live-announcer/index.ts +9 -0
  122. package/src/menu/createMenu.ts +396 -0
  123. package/src/menu/createMenuItem.ts +149 -0
  124. package/src/menu/createMenuTrigger.ts +88 -0
  125. package/src/menu/index.ts +18 -0
  126. package/src/meter/createMeter.ts +75 -0
  127. package/src/meter/index.ts +1 -0
  128. package/src/numberfield/createNumberField.ts +268 -0
  129. package/src/numberfield/index.ts +5 -0
  130. package/src/overlays/ariaHideOutside.ts +219 -0
  131. package/src/overlays/createInteractOutside.ts +149 -0
  132. package/src/overlays/createModal.tsx +202 -0
  133. package/src/overlays/createOverlay.ts +155 -0
  134. package/src/overlays/createOverlayTrigger.ts +85 -0
  135. package/src/overlays/createPreventScroll.ts +266 -0
  136. package/src/overlays/index.ts +44 -0
  137. package/src/popover/calculatePosition.ts +766 -0
  138. package/src/popover/createOverlayPosition.ts +356 -0
  139. package/src/popover/createPopover.ts +170 -0
  140. package/src/popover/index.ts +24 -0
  141. package/src/progress/createProgressBar.ts +128 -0
  142. package/src/progress/index.ts +5 -0
  143. package/src/radio/createRadio.ts +287 -0
  144. package/src/radio/createRadioGroup.ts +189 -0
  145. package/src/radio/createRadioGroupState.ts +201 -0
  146. package/src/radio/index.ts +23 -0
  147. package/src/searchfield/createSearchField.ts +186 -0
  148. package/src/searchfield/index.ts +2 -0
  149. package/src/select/createHiddenSelect.tsx +236 -0
  150. package/src/select/createSelect.ts +395 -0
  151. package/src/select/index.ts +14 -0
  152. package/src/selection/createTypeSelect.ts +201 -0
  153. package/src/selection/index.ts +6 -0
  154. package/src/separator/createSeparator.ts +82 -0
  155. package/src/separator/index.ts +6 -0
  156. package/src/slider/createSlider.ts +349 -0
  157. package/src/slider/index.ts +2 -0
  158. package/src/ssr/index.tsx +370 -0
  159. package/src/switch/createSwitch.ts +70 -0
  160. package/src/switch/index.ts +1 -0
  161. package/src/table/createTable.ts +526 -0
  162. package/src/table/createTableCell.ts +147 -0
  163. package/src/table/createTableColumnHeader.ts +115 -0
  164. package/src/table/createTableHeaderRow.ts +40 -0
  165. package/src/table/createTableRow.ts +155 -0
  166. package/src/table/createTableRowGroup.ts +32 -0
  167. package/src/table/createTableSelectAllCheckbox.ts +73 -0
  168. package/src/table/createTableSelectionCheckbox.ts +59 -0
  169. package/src/table/index.ts +30 -0
  170. package/src/table/types.ts +165 -0
  171. package/src/tabs/createTabs.ts +472 -0
  172. package/src/tabs/index.ts +14 -0
  173. package/src/tag/createTag.ts +194 -0
  174. package/src/tag/createTagGroup.ts +154 -0
  175. package/src/tag/index.ts +12 -0
  176. package/src/textfield/createTextField.ts +198 -0
  177. package/src/textfield/index.ts +5 -0
  178. package/src/toast/createToast.ts +118 -0
  179. package/src/toast/createToastRegion.ts +100 -0
  180. package/src/toast/index.ts +11 -0
  181. package/src/toggle/createToggle.ts +223 -0
  182. package/src/toggle/createToggleState.ts +94 -0
  183. package/src/toggle/index.ts +7 -0
  184. package/src/toolbar/createToolbar.ts +369 -0
  185. package/src/toolbar/index.ts +6 -0
  186. package/src/tooltip/createTooltip.ts +79 -0
  187. package/src/tooltip/createTooltipTrigger.ts +222 -0
  188. package/src/tooltip/index.ts +6 -0
  189. package/src/tree/createTree.ts +246 -0
  190. package/src/tree/createTreeItem.ts +233 -0
  191. package/src/tree/createTreeSelectionCheckbox.ts +68 -0
  192. package/src/tree/index.ts +16 -0
  193. package/src/tree/types.ts +87 -0
  194. package/src/utils/createDescription.ts +137 -0
  195. package/src/utils/dom.ts +327 -0
  196. package/src/utils/env.ts +54 -0
  197. package/src/utils/events.ts +106 -0
  198. package/src/utils/filterDOMProps.ts +116 -0
  199. package/src/utils/focus.ts +151 -0
  200. package/src/utils/geometry.ts +115 -0
  201. package/src/utils/globalListeners.ts +142 -0
  202. package/src/utils/index.ts +80 -0
  203. package/src/utils/mergeProps.ts +52 -0
  204. package/src/utils/platform.ts +52 -0
  205. package/src/utils/reactivity.ts +36 -0
  206. package/src/utils/textSelection.ts +114 -0
  207. package/src/visually-hidden/createVisuallyHidden.ts +124 -0
  208. package/src/visually-hidden/index.ts +6 -0
@@ -0,0 +1,349 @@
1
+ /**
2
+ * Provides the behavior and accessibility implementation for a slider component.
3
+ * A slider allows users to select a value from a range.
4
+ * Based on @react-aria/slider useSlider.
5
+ */
6
+
7
+ import { type JSX, onCleanup, onMount } from 'solid-js';
8
+ import { createLabel } from '../label/createLabel';
9
+ import { createFocusRing } from '../interactions/createFocusRing';
10
+ import { filterDOMProps } from '../utils/filterDOMProps';
11
+ import { mergeProps } from '../utils/mergeProps';
12
+ import { createId } from '../ssr';
13
+ import { access, type MaybeAccessor } from '../utils/reactivity';
14
+ import type { SliderState, SliderOrientation } from '@proyecto-viviana/solid-stately';
15
+
16
+ export interface AriaSliderProps {
17
+ /** An ID for the slider. */
18
+ id?: string;
19
+ /** Whether the slider is disabled. */
20
+ isDisabled?: boolean;
21
+ /** The label for the slider. */
22
+ label?: JSX.Element;
23
+ /** An accessible label for the slider when no visible label is provided. */
24
+ 'aria-label'?: string;
25
+ /** The ID of an element that labels the slider. */
26
+ 'aria-labelledby'?: string;
27
+ /** The ID of an element that describes the slider. */
28
+ 'aria-describedby'?: string;
29
+ /** The orientation of the slider. */
30
+ orientation?: SliderOrientation;
31
+ }
32
+
33
+ export interface SliderAria {
34
+ /** Props for the label element. */
35
+ labelProps: JSX.HTMLAttributes<HTMLElement>;
36
+ /** Props for the root group element. */
37
+ groupProps: JSX.HTMLAttributes<HTMLElement>;
38
+ /** Props for the track element. */
39
+ trackProps: JSX.HTMLAttributes<HTMLElement>;
40
+ /** Props for the thumb element. */
41
+ thumbProps: JSX.HTMLAttributes<HTMLElement>;
42
+ /** Props for the hidden input element. */
43
+ inputProps: JSX.InputHTMLAttributes<HTMLInputElement>;
44
+ /** Props for the output element (showing current value). */
45
+ outputProps: JSX.HTMLAttributes<HTMLElement>;
46
+ }
47
+
48
+ /**
49
+ * Provides the behavior and accessibility implementation for a slider.
50
+ */
51
+ export function createSlider(
52
+ props: MaybeAccessor<AriaSliderProps>,
53
+ state: SliderState,
54
+ trackRef?: () => HTMLElement | null
55
+ ): SliderAria {
56
+ const getProps = () => access(props);
57
+ const id = createId(getProps().id);
58
+
59
+ // Generate IDs for associated elements
60
+ const inputId = `${id}-input`;
61
+ const outputId = `${id}-output`;
62
+
63
+ // Filter DOM props
64
+ const domProps = () =>
65
+ filterDOMProps(getProps() as unknown as Record<string, unknown>, { labelable: true });
66
+
67
+ // Label handling
68
+ const { labelProps, fieldProps } = createLabel({
69
+ get id() {
70
+ return inputId;
71
+ },
72
+ get label() {
73
+ return getProps().label;
74
+ },
75
+ get 'aria-label'() {
76
+ return getProps()['aria-label'];
77
+ },
78
+ get 'aria-labelledby'() {
79
+ return getProps()['aria-labelledby'];
80
+ },
81
+ labelElementType: 'span',
82
+ });
83
+
84
+ // Focus ring for keyboard focus styling
85
+ const { isFocusVisible, focusProps } = createFocusRing({
86
+ within: true,
87
+ });
88
+
89
+ // Track pointer state for drag handling
90
+ let currentPointerId: number | null = null;
91
+
92
+ // Calculate position from pointer event
93
+ const getPositionFromPointer = (clientX: number, clientY: number): number => {
94
+ const track = trackRef?.();
95
+ if (!track) return 0;
96
+
97
+ const rect = track.getBoundingClientRect();
98
+ const isVertical = state.orientation === 'vertical';
99
+
100
+ let position: number;
101
+ if (isVertical) {
102
+ position = (rect.bottom - clientY) / rect.height;
103
+ } else {
104
+ position = (clientX - rect.left) / rect.width;
105
+ }
106
+
107
+ return Math.max(0, Math.min(1, position));
108
+ };
109
+
110
+ // Handle pointer down on track
111
+ const onTrackPointerDown = (e: PointerEvent) => {
112
+ if (state.isDisabled || e.button !== 0) return;
113
+
114
+ e.preventDefault();
115
+ currentPointerId = e.pointerId;
116
+
117
+ const track = trackRef?.();
118
+ if (track) {
119
+ track.setPointerCapture(e.pointerId);
120
+ }
121
+
122
+ const percent = getPositionFromPointer(e.clientX, e.clientY);
123
+ state.setValuePercent(percent);
124
+ state.setDragging(true);
125
+ };
126
+
127
+ // Handle pointer move for dragging
128
+ const onTrackPointerMove = (e: PointerEvent) => {
129
+ if (!state.isDragging() || e.pointerId !== currentPointerId) return;
130
+
131
+ const percent = getPositionFromPointer(e.clientX, e.clientY);
132
+ state.setValuePercent(percent);
133
+ };
134
+
135
+ // Handle pointer up to end drag
136
+ const onTrackPointerUp = (e: PointerEvent) => {
137
+ if (e.pointerId !== currentPointerId) return;
138
+
139
+ const track = trackRef?.();
140
+ if (track) {
141
+ track.releasePointerCapture(e.pointerId);
142
+ }
143
+
144
+ currentPointerId = null;
145
+ state.setDragging(false);
146
+ };
147
+
148
+ // Keyboard navigation for thumb
149
+ const onThumbKeyDown = (e: KeyboardEvent) => {
150
+ if (state.isDisabled) return;
151
+
152
+ const isVertical = state.orientation === 'vertical';
153
+
154
+ switch (e.key) {
155
+ case 'ArrowRight':
156
+ case 'ArrowUp':
157
+ e.preventDefault();
158
+ if ((e.key === 'ArrowRight' && !isVertical) || (e.key === 'ArrowUp' && isVertical)) {
159
+ state.increment();
160
+ } else {
161
+ state.decrement();
162
+ }
163
+ break;
164
+ case 'ArrowLeft':
165
+ case 'ArrowDown':
166
+ e.preventDefault();
167
+ if ((e.key === 'ArrowLeft' && !isVertical) || (e.key === 'ArrowDown' && isVertical)) {
168
+ state.decrement();
169
+ } else {
170
+ state.increment();
171
+ }
172
+ break;
173
+ case 'PageUp':
174
+ e.preventDefault();
175
+ state.increment(state.pageStep / state.step);
176
+ break;
177
+ case 'PageDown':
178
+ e.preventDefault();
179
+ state.decrement(state.pageStep / state.step);
180
+ break;
181
+ case 'Home':
182
+ e.preventDefault();
183
+ state.setValue(state.minValue);
184
+ break;
185
+ case 'End':
186
+ e.preventDefault();
187
+ state.setValue(state.maxValue);
188
+ break;
189
+ }
190
+ };
191
+
192
+ // Handle focus events
193
+ const onFocus = () => {
194
+ state.setFocused(true);
195
+ };
196
+
197
+ const onBlur = () => {
198
+ state.setFocused(false);
199
+ };
200
+
201
+ // Handle pointer down on thumb (for direct thumb dragging)
202
+ const onThumbPointerDown = (e: PointerEvent) => {
203
+ if (state.isDisabled || e.button !== 0) return;
204
+
205
+ e.preventDefault();
206
+ e.stopPropagation(); // Prevent track from also handling
207
+ currentPointerId = e.pointerId;
208
+
209
+ // Capture pointer on document for smooth dragging
210
+ document.body.setPointerCapture(e.pointerId);
211
+ state.setDragging(true);
212
+ };
213
+
214
+ // Global pointer move handler for thumb dragging
215
+ const onDocumentPointerMove = (e: PointerEvent) => {
216
+ if (!state.isDragging() || e.pointerId !== currentPointerId) return;
217
+
218
+ const percent = getPositionFromPointer(e.clientX, e.clientY);
219
+ state.setValuePercent(percent);
220
+ };
221
+
222
+ // Global pointer up handler
223
+ const onDocumentPointerUp = (e: PointerEvent) => {
224
+ if (e.pointerId !== currentPointerId) return;
225
+
226
+ try {
227
+ document.body.releasePointerCapture(e.pointerId);
228
+ } catch {
229
+ // Ignore if capture was already released
230
+ }
231
+
232
+ currentPointerId = null;
233
+ state.setDragging(false);
234
+ };
235
+
236
+ // Set up global listeners on mount (client-side only)
237
+ onMount(() => {
238
+ if (typeof document === 'undefined') return;
239
+
240
+ document.addEventListener('pointermove', onDocumentPointerMove);
241
+ document.addEventListener('pointerup', onDocumentPointerUp);
242
+ document.addEventListener('pointercancel', onDocumentPointerUp);
243
+
244
+ // Cleanup when component unmounts
245
+ onCleanup(() => {
246
+ document.removeEventListener('pointermove', onDocumentPointerMove);
247
+ document.removeEventListener('pointerup', onDocumentPointerUp);
248
+ document.removeEventListener('pointercancel', onDocumentPointerUp);
249
+ });
250
+ });
251
+
252
+ return {
253
+ get labelProps() {
254
+ return labelProps as JSX.HTMLAttributes<HTMLElement>;
255
+ },
256
+ get groupProps() {
257
+ return mergeProps(
258
+ domProps(),
259
+ fieldProps as Record<string, unknown>,
260
+ {
261
+ role: 'group',
262
+ 'data-disabled': state.isDisabled || undefined,
263
+ 'data-orientation': state.orientation,
264
+ } as Record<string, unknown>
265
+ ) as JSX.HTMLAttributes<HTMLElement>;
266
+ },
267
+ get trackProps() {
268
+ return {
269
+ onPointerDown: onTrackPointerDown,
270
+ onPointerMove: onTrackPointerMove,
271
+ onPointerUp: onTrackPointerUp,
272
+ onPointerCancel: onTrackPointerUp,
273
+ style: {
274
+ position: 'relative',
275
+ 'touch-action': 'none',
276
+ },
277
+ 'data-disabled': state.isDisabled || undefined,
278
+ 'data-orientation': state.orientation,
279
+ 'data-dragging': state.isDragging() || undefined,
280
+ } as JSX.HTMLAttributes<HTMLElement>;
281
+ },
282
+ get thumbProps() {
283
+ const percent = state.getValuePercent();
284
+ const isVertical = state.orientation === 'vertical';
285
+
286
+ return mergeProps(
287
+ focusProps as Record<string, unknown>,
288
+ {
289
+ role: 'slider',
290
+ tabIndex: state.isDisabled ? undefined : 0,
291
+ 'aria-valuemin': state.minValue,
292
+ 'aria-valuemax': state.maxValue,
293
+ 'aria-valuenow': state.value(),
294
+ 'aria-valuetext': state.getFormattedValue(),
295
+ 'aria-orientation': state.orientation,
296
+ 'aria-disabled': state.isDisabled || undefined,
297
+ 'aria-labelledby': (labelProps as { id?: string }).id,
298
+ onPointerDown: onThumbPointerDown,
299
+ onKeyDown: onThumbKeyDown,
300
+ onFocus,
301
+ onBlur,
302
+ style: {
303
+ position: 'absolute',
304
+ [isVertical ? 'bottom' : 'left']: `${percent * 100}%`,
305
+ transform: isVertical ? 'translateY(50%)' : 'translateX(-50%)',
306
+ },
307
+ 'data-disabled': state.isDisabled || undefined,
308
+ 'data-dragging': state.isDragging() || undefined,
309
+ 'data-focus-visible': isFocusVisible() || undefined,
310
+ } as Record<string, unknown>
311
+ ) as JSX.HTMLAttributes<HTMLElement>;
312
+ },
313
+ get inputProps() {
314
+ return {
315
+ type: 'range',
316
+ id: inputId,
317
+ min: state.minValue,
318
+ max: state.maxValue,
319
+ step: state.step,
320
+ value: state.value(),
321
+ disabled: state.isDisabled,
322
+ 'aria-hidden': true,
323
+ tabIndex: -1,
324
+ style: {
325
+ position: 'absolute',
326
+ width: '1px',
327
+ height: '1px',
328
+ padding: '0',
329
+ margin: '-1px',
330
+ overflow: 'hidden',
331
+ clip: 'rect(0, 0, 0, 0)',
332
+ 'white-space': 'nowrap',
333
+ border: '0',
334
+ },
335
+ onChange: (e: Event) => {
336
+ const target = e.target as HTMLInputElement;
337
+ state.setValue(parseFloat(target.value));
338
+ },
339
+ } as JSX.InputHTMLAttributes<HTMLInputElement>;
340
+ },
341
+ get outputProps() {
342
+ return {
343
+ id: outputId,
344
+ 'for': inputId,
345
+ 'aria-live': 'off',
346
+ } as JSX.HTMLAttributes<HTMLElement>;
347
+ },
348
+ };
349
+ }
@@ -0,0 +1,2 @@
1
+ export { createSlider } from './createSlider';
2
+ export type { AriaSliderProps, SliderAria } from './createSlider';
@@ -0,0 +1,370 @@
1
+ /**
2
+ * SSR utilities for Solidaria
3
+ *
4
+ * SolidJS has built-in SSR support with `isServer` and `createUniqueId()`.
5
+ * These utilities provide a consistent API matching React-Aria's patterns
6
+ * with additional features for hydration management.
7
+ */
8
+
9
+ import {
10
+ type Accessor,
11
+ type JSX,
12
+ type ParentProps,
13
+ createContext,
14
+ createEffect,
15
+ createMemo,
16
+ createSignal,
17
+ onCleanup,
18
+ onMount,
19
+ useContext,
20
+ createUniqueId,
21
+ } from 'solid-js';
22
+ import { isServer } from 'solid-js/web';
23
+
24
+ // ============================================
25
+ // TYPES
26
+ // ============================================
27
+
28
+ export interface SSRProviderProps extends ParentProps {}
29
+
30
+ export interface SSRContextValue {
31
+ /** Whether currently rendering on the server. */
32
+ isSSR: boolean;
33
+ /** Prefix for generated IDs, allowing nested providers. */
34
+ prefix: string;
35
+ }
36
+
37
+ // ============================================
38
+ // CONTEXT
39
+ // ============================================
40
+
41
+ const SSRContext = createContext<SSRContextValue>({
42
+ isSSR: isServer,
43
+ prefix: '',
44
+ });
45
+
46
+ // ============================================
47
+ // BASIC UTILITIES
48
+ // ============================================
49
+
50
+ /**
51
+ * Returns whether the component is currently being server side rendered.
52
+ * Can be used to delay browser-specific rendering until after hydration.
53
+ *
54
+ * Note: This returns a static boolean. For reactive hydration detection,
55
+ * use `createHydrationState()`.
56
+ */
57
+ export function createIsSSR(): boolean {
58
+ return isServer;
59
+ }
60
+
61
+ /**
62
+ * Check if we can use DOM APIs.
63
+ * This is useful for code that needs to run only in the browser.
64
+ */
65
+ export const canUseDOM = !isServer;
66
+
67
+ /**
68
+ * Generate a unique ID that is stable across server and client.
69
+ * Uses SolidJS's built-in createUniqueId which handles SSR correctly.
70
+ *
71
+ * @param defaultId - Optional default ID to use instead of generating one.
72
+ *
73
+ * @example
74
+ * ```tsx
75
+ * function TextField(props) {
76
+ * const inputId = createId(props.id);
77
+ * return (
78
+ * <>
79
+ * <label for={inputId}>{props.label}</label>
80
+ * <input id={inputId} />
81
+ * </>
82
+ * );
83
+ * }
84
+ * ```
85
+ */
86
+ export function createId(defaultId?: string): string {
87
+ if (defaultId) {
88
+ return defaultId;
89
+ }
90
+ const ctx = useContext(SSRContext);
91
+ const uniqueId = createUniqueId();
92
+ return ctx.prefix ? `solidaria-${ctx.prefix}-${uniqueId}` : `solidaria-${uniqueId}`;
93
+ }
94
+
95
+ // ============================================
96
+ // SSR PROVIDER
97
+ // ============================================
98
+
99
+ /**
100
+ * Provides SSR context to the component tree.
101
+ *
102
+ * While SolidJS handles most SSR scenarios automatically, this provider
103
+ * can be useful for:
104
+ * - Nested ID prefixes to avoid collisions in micro-frontends
105
+ * - Explicit hydration boundary markers
106
+ * - Testing SSR behavior
107
+ *
108
+ * @example
109
+ * ```tsx
110
+ * // Root of your app
111
+ * <SSRProvider>
112
+ * <App />
113
+ * </SSRProvider>
114
+ *
115
+ * // With custom prefix for micro-frontend
116
+ * <SSRProvider prefix="widget">
117
+ * <Widget />
118
+ * </SSRProvider>
119
+ * ```
120
+ */
121
+ export function SSRProvider(props: SSRProviderProps & { prefix?: string }): JSX.Element {
122
+ const parentContext = useContext(SSRContext);
123
+
124
+ const value = createMemo<SSRContextValue>(() => ({
125
+ isSSR: isServer,
126
+ prefix: props.prefix
127
+ ? parentContext.prefix
128
+ ? `${parentContext.prefix}-${props.prefix}`
129
+ : props.prefix
130
+ : parentContext.prefix,
131
+ }));
132
+
133
+ return (
134
+ <SSRContext.Provider value={value()}>
135
+ {props.children}
136
+ </SSRContext.Provider>
137
+ );
138
+ }
139
+
140
+ // ============================================
141
+ // HYDRATION STATE
142
+ // ============================================
143
+
144
+ /**
145
+ * Tracks whether the component is currently hydrating.
146
+ *
147
+ * During server-side rendering, this returns `true`. After hydration
148
+ * completes on the client, it switches to `false`. This is useful for
149
+ * components that need to show different content during hydration.
150
+ *
151
+ * @example
152
+ * ```tsx
153
+ * function ClientOnlyComponent() {
154
+ * const isHydrating = createHydrationState();
155
+ *
156
+ * return (
157
+ * <Show when={!isHydrating()} fallback={<LoadingPlaceholder />}>
158
+ * <InteractiveWidget />
159
+ * </Show>
160
+ * );
161
+ * }
162
+ * ```
163
+ */
164
+ export function createHydrationState(): Accessor<boolean> {
165
+ // On the server, always return true
166
+ if (isServer) {
167
+ return () => true;
168
+ }
169
+
170
+ // On the client, track hydration state
171
+ const [isHydrating, setIsHydrating] = createSignal(true);
172
+
173
+ onMount(() => {
174
+ setIsHydrating(false);
175
+ });
176
+
177
+ return isHydrating;
178
+ }
179
+
180
+ /**
181
+ * Hook that returns `true` during SSR and initial hydration.
182
+ * Use this to delay browser-specific code until hydration is complete.
183
+ *
184
+ * Unlike `createIsSSR()` which is static, this updates reactively
185
+ * after hydration completes.
186
+ *
187
+ * @example
188
+ * ```tsx
189
+ * function BrowserOnlyFeature() {
190
+ * const isSSR = useIsSSR();
191
+ *
192
+ * createEffect(() => {
193
+ * if (!isSSR()) {
194
+ * // Safe to access browser APIs here
195
+ * window.localStorage.getItem('key');
196
+ * }
197
+ * });
198
+ *
199
+ * return <Show when={!isSSR()}>...</Show>;
200
+ * }
201
+ * ```
202
+ */
203
+ export function useIsSSR(): Accessor<boolean> {
204
+ return createHydrationState();
205
+ }
206
+
207
+ // ============================================
208
+ // SAFE BROWSER EFFECTS
209
+ // ============================================
210
+
211
+ /**
212
+ * Creates an effect that only runs on the client after hydration.
213
+ * This is a convenience wrapper that ensures browser-specific code
214
+ * doesn't run during SSR.
215
+ *
216
+ * @param fn - The effect function to run
217
+ *
218
+ * @example
219
+ * ```tsx
220
+ * function Analytics() {
221
+ * createBrowserEffect(() => {
222
+ * // Safe to access window, document, localStorage, etc.
223
+ * window.analytics.track('page_view');
224
+ * });
225
+ *
226
+ * return null;
227
+ * }
228
+ * ```
229
+ */
230
+ export function createBrowserEffect(fn: () => void | (() => void)): void {
231
+ if (isServer) {
232
+ return;
233
+ }
234
+
235
+ createEffect(() => {
236
+ const cleanup = fn();
237
+ if (typeof cleanup === 'function') {
238
+ onCleanup(cleanup);
239
+ }
240
+ });
241
+ }
242
+
243
+ /**
244
+ * Creates a value that is computed only on the client.
245
+ * On the server, returns the fallback value.
246
+ *
247
+ * @param fn - Function to compute the value on the client
248
+ * @param fallback - Value to return during SSR
249
+ *
250
+ * @example
251
+ * ```tsx
252
+ * function WindowSize() {
253
+ * const width = createBrowserValue(
254
+ * () => window.innerWidth,
255
+ * 0
256
+ * );
257
+ *
258
+ * return <span>Width: {width()}</span>;
259
+ * }
260
+ * ```
261
+ */
262
+ export function createBrowserValue<T>(
263
+ fn: () => T,
264
+ fallback: T
265
+ ): Accessor<T> {
266
+ if (isServer) {
267
+ return () => fallback;
268
+ }
269
+
270
+ const [value, setValue] = createSignal<T>(fallback);
271
+
272
+ onMount(() => {
273
+ setValue(() => fn());
274
+ });
275
+
276
+ return value;
277
+ }
278
+
279
+ // ============================================
280
+ // WINDOW/DOCUMENT SAFE ACCESS
281
+ // ============================================
282
+
283
+ /**
284
+ * Returns the window object if available, or undefined during SSR.
285
+ * Useful for accessing browser globals safely.
286
+ *
287
+ * @example
288
+ * ```tsx
289
+ * const win = getWindow();
290
+ * if (win) {
291
+ * win.addEventListener('resize', handler);
292
+ * }
293
+ * ```
294
+ */
295
+ export function getWindow(): Window | undefined {
296
+ if (typeof window !== 'undefined') {
297
+ return window;
298
+ }
299
+ return undefined;
300
+ }
301
+
302
+ /**
303
+ * Returns the document object if available, or undefined during SSR.
304
+ * Useful for accessing document safely.
305
+ *
306
+ * @example
307
+ * ```tsx
308
+ * const doc = getDocument();
309
+ * if (doc) {
310
+ * doc.addEventListener('keydown', handler);
311
+ * }
312
+ * ```
313
+ */
314
+ export function getDocument(): Document | undefined {
315
+ if (typeof document !== 'undefined') {
316
+ return document;
317
+ }
318
+ return undefined;
319
+ }
320
+
321
+ /**
322
+ * Returns the owner document of an element, with SSR safety.
323
+ *
324
+ * @param el - The element to get the owner document from
325
+ */
326
+ export function getOwnerDocument(el: Element | null | undefined): Document | undefined {
327
+ return el?.ownerDocument ?? getDocument();
328
+ }
329
+
330
+ /**
331
+ * Returns the owner window of an element, with SSR safety.
332
+ *
333
+ * @param el - The element to get the owner window from
334
+ */
335
+ export function getOwnerWindow(el: Element | null | undefined): Window | undefined {
336
+ return getOwnerDocument(el)?.defaultView ?? getWindow();
337
+ }
338
+
339
+ // ============================================
340
+ // PORTAL HELPERS
341
+ // ============================================
342
+
343
+ /**
344
+ * Gets the appropriate container for portals, with SSR safety.
345
+ * Returns the specified container, or document.body on the client,
346
+ * or undefined during SSR.
347
+ *
348
+ * @param container - Optional custom container element
349
+ *
350
+ * @example
351
+ * ```tsx
352
+ * function Modal(props) {
353
+ * const container = getPortalContainer(props.container);
354
+ *
355
+ * return (
356
+ * <Show when={container}>
357
+ * <Portal mount={container}>
358
+ * {props.children}
359
+ * </Portal>
360
+ * </Show>
361
+ * );
362
+ * }
363
+ * ```
364
+ */
365
+ export function getPortalContainer(container?: Element): Element | undefined {
366
+ if (container) {
367
+ return container;
368
+ }
369
+ return getDocument()?.body;
370
+ }