@proyecto-viviana/solid-stately 0.2.7 → 0.3.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 (242) hide show
  1. package/README.md +30 -283
  2. package/dist/autocomplete/createAutocompleteState.d.ts +2 -2
  3. package/dist/autocomplete/index.d.ts +1 -1
  4. package/dist/calendar/createCalendarState.d.ts +22 -7
  5. package/dist/calendar/createDateFieldState.d.ts +30 -7
  6. package/dist/calendar/createDatePickerState.d.ts +60 -0
  7. package/dist/calendar/createRangeCalendarState.d.ts +27 -8
  8. package/dist/calendar/createTimeFieldState.d.ts +34 -7
  9. package/dist/calendar/index.d.ts +7 -6
  10. package/dist/checkbox/createCheckboxGroupState.d.ts +6 -6
  11. package/dist/checkbox/index.d.ts +1 -1
  12. package/dist/collections/ListCollection.d.ts +1 -1
  13. package/dist/collections/createListState.d.ts +8 -8
  14. package/dist/collections/createMenuState.d.ts +7 -7
  15. package/dist/collections/createSelectionState.d.ts +5 -5
  16. package/dist/collections/index.d.ts +5 -5
  17. package/dist/collections/types.d.ts +12 -12
  18. package/dist/color/Color.d.ts +1 -1
  19. package/dist/color/createColorAreaState.d.ts +4 -2
  20. package/dist/color/createColorFieldState.d.ts +38 -12
  21. package/dist/color/createColorSliderState.d.ts +9 -2
  22. package/dist/color/createColorWheelState.d.ts +13 -2
  23. package/dist/color/getColorChannels.d.ts +1 -1
  24. package/dist/color/index.d.ts +6 -6
  25. package/dist/color/types.d.ts +4 -4
  26. package/dist/combobox/createComboBoxState.d.ts +27 -13
  27. package/dist/combobox/index.d.ts +1 -1
  28. package/dist/data/createAsyncList.d.ts +4 -4
  29. package/dist/data/createListData.d.ts +2 -2
  30. package/dist/data/createTreeData.d.ts +6 -2
  31. package/dist/data/index.d.ts +3 -3
  32. package/dist/datepicker/index.d.ts +2 -4
  33. package/dist/disclosure/createDisclosureState.d.ts +2 -2
  34. package/dist/disclosure/index.d.ts +1 -1
  35. package/dist/dnd/createDragState.d.ts +2 -2
  36. package/dist/dnd/createDraggableCollectionState.d.ts +2 -2
  37. package/dist/dnd/createDropState.d.ts +2 -2
  38. package/dist/dnd/createDroppableCollectionState.d.ts +3 -3
  39. package/dist/dnd/index.d.ts +5 -5
  40. package/dist/dnd/types.d.ts +16 -16
  41. package/dist/form/createFormValidationState.d.ts +3 -3
  42. package/dist/form/index.d.ts +1 -1
  43. package/dist/grid/createGridState.d.ts +2 -2
  44. package/dist/grid/index.d.ts +2 -2
  45. package/dist/grid/types.d.ts +13 -11
  46. package/dist/index.d.ts +31 -30
  47. package/dist/index.js +7924 -7238
  48. package/dist/index.js.map +1 -1
  49. package/dist/menu/index.d.ts +2 -2
  50. package/dist/numberfield/createNumberFieldState.d.ts +2 -2
  51. package/dist/numberfield/index.d.ts +1 -1
  52. package/dist/overlays/createOverlayTriggerState.d.ts +2 -2
  53. package/dist/overlays/index.d.ts +1 -1
  54. package/dist/radio/createRadioGroupState.d.ts +7 -7
  55. package/dist/radio/index.d.ts +1 -1
  56. package/dist/searchfield/createSearchFieldState.d.ts +2 -2
  57. package/dist/searchfield/index.d.ts +2 -2
  58. package/dist/select/createSelectState.d.ts +8 -8
  59. package/dist/select/index.d.ts +1 -1
  60. package/dist/selection/index.d.ts +5 -5
  61. package/dist/slider/createSliderState.d.ts +3 -3
  62. package/dist/slider/index.d.ts +2 -2
  63. package/dist/steplist/createStepListState.d.ts +48 -0
  64. package/dist/steplist/index.d.ts +1 -0
  65. package/dist/table/TableCollection.d.ts +3 -3
  66. package/dist/table/createTableColumnResizeState.d.ts +54 -0
  67. package/dist/table/createTableState.d.ts +2 -2
  68. package/dist/table/index.d.ts +5 -3
  69. package/dist/table/types.d.ts +10 -10
  70. package/dist/tabs/createTabListState.d.ts +5 -5
  71. package/dist/tabs/index.d.ts +1 -1
  72. package/dist/textfield/createTextFieldState.d.ts +2 -2
  73. package/dist/textfield/index.d.ts +1 -1
  74. package/dist/toast/createToastState.d.ts +8 -2
  75. package/dist/toast/index.d.ts +1 -1
  76. package/dist/toggle/createToggleGroupState.d.ts +4 -4
  77. package/dist/toggle/createToggleState.d.ts +2 -2
  78. package/dist/toggle/index.d.ts +2 -2
  79. package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
  80. package/dist/tooltip/index.d.ts +1 -1
  81. package/dist/tree/TreeCollection.d.ts +2 -2
  82. package/dist/tree/createTreeState.d.ts +2 -2
  83. package/dist/tree/index.d.ts +3 -3
  84. package/dist/tree/types.d.ts +19 -13
  85. package/dist/utils/index.d.ts +1 -1
  86. package/dist/utils/reactivity.d.ts +1 -1
  87. package/package.json +29 -30
  88. package/src/autocomplete/createAutocompleteState.d.ts +19 -17
  89. package/src/autocomplete/createAutocompleteState.ts +24 -30
  90. package/src/autocomplete/index.d.ts +6 -2
  91. package/src/autocomplete/index.ts +1 -1
  92. package/src/calendar/createCalendarState.d.ts +139 -117
  93. package/src/calendar/createCalendarState.ts +221 -74
  94. package/src/calendar/createDateFieldState.d.ts +130 -95
  95. package/src/calendar/createDateFieldState.ts +263 -151
  96. package/src/calendar/createDatePickerState.ts +347 -0
  97. package/src/calendar/createRangeCalendarState.d.ts +154 -129
  98. package/src/calendar/createRangeCalendarState.ts +293 -79
  99. package/src/calendar/createTimeFieldState.d.ts +81 -79
  100. package/src/calendar/createTimeFieldState.ts +187 -108
  101. package/src/calendar/index.d.ts +80 -7
  102. package/src/calendar/index.ts +21 -12
  103. package/src/checkbox/createCheckboxGroupState.d.ts +57 -55
  104. package/src/checkbox/createCheckboxGroupState.ts +20 -29
  105. package/src/checkbox/index.d.ts +6 -2
  106. package/src/checkbox/index.ts +1 -1
  107. package/src/collections/ListCollection.d.ts +25 -22
  108. package/src/collections/ListCollection.ts +6 -6
  109. package/src/collections/createListState.d.ts +73 -58
  110. package/src/collections/createListState.ts +19 -18
  111. package/src/collections/createMenuState.d.ts +36 -31
  112. package/src/collections/createMenuState.ts +18 -12
  113. package/src/collections/createSelectionState.d.ts +78 -65
  114. package/src/collections/createSelectionState.ts +36 -32
  115. package/src/collections/index.d.ts +38 -6
  116. package/src/collections/index.ts +5 -10
  117. package/src/collections/types.d.ts +101 -101
  118. package/src/collections/types.ts +12 -12
  119. package/src/color/Color.d.ts +20 -5
  120. package/src/color/Color.ts +357 -254
  121. package/src/color/createColorAreaState.d.ts +67 -65
  122. package/src/color/createColorAreaState.ts +21 -13
  123. package/src/color/createColorFieldState.d.ts +46 -44
  124. package/src/color/createColorFieldState.ts +285 -149
  125. package/src/color/createColorSliderState.d.ts +58 -56
  126. package/src/color/createColorSliderState.ts +45 -14
  127. package/src/color/createColorWheelState.d.ts +42 -40
  128. package/src/color/createColorWheelState.ts +101 -64
  129. package/src/color/getColorChannels.ts +7 -5
  130. package/src/color/index.d.ts +36 -7
  131. package/src/color/index.ts +6 -9
  132. package/src/color/types.d.ts +68 -63
  133. package/src/color/types.ts +11 -19
  134. package/src/combobox/createComboBoxState.d.ts +107 -105
  135. package/src/combobox/createComboBoxState.ts +176 -89
  136. package/src/combobox/index.d.ts +10 -2
  137. package/src/combobox/index.ts +1 -1
  138. package/src/data/createAsyncList.ts +89 -63
  139. package/src/data/createListData.ts +67 -67
  140. package/src/data/createTreeData.ts +304 -91
  141. package/src/data/index.ts +3 -3
  142. package/src/datepicker/index.ts +6 -10
  143. package/src/disclosure/createDisclosureState.d.ts +47 -43
  144. package/src/disclosure/createDisclosureState.ts +7 -21
  145. package/src/disclosure/index.d.ts +10 -2
  146. package/src/disclosure/index.ts +1 -1
  147. package/src/dnd/createDragState.d.ts +51 -42
  148. package/src/dnd/createDragState.ts +12 -14
  149. package/src/dnd/createDraggableCollectionState.d.ts +52 -41
  150. package/src/dnd/createDraggableCollectionState.ts +14 -21
  151. package/src/dnd/createDropState.d.ts +64 -45
  152. package/src/dnd/createDropState.ts +22 -32
  153. package/src/dnd/createDroppableCollectionState.d.ts +88 -59
  154. package/src/dnd/createDroppableCollectionState.ts +40 -43
  155. package/src/dnd/index.d.ts +54 -6
  156. package/src/dnd/index.ts +5 -18
  157. package/src/dnd/types.d.ts +167 -156
  158. package/src/dnd/types.ts +20 -21
  159. package/src/form/createFormValidationState.d.ts +47 -45
  160. package/src/form/createFormValidationState.ts +30 -63
  161. package/src/form/index.d.ts +16 -2
  162. package/src/form/index.ts +1 -1
  163. package/src/grid/createGridState.d.ts +7 -4
  164. package/src/grid/createGridState.ts +44 -51
  165. package/src/grid/index.d.ts +3 -3
  166. package/src/grid/index.ts +2 -8
  167. package/src/grid/types.d.ts +136 -129
  168. package/src/grid/types.ts +20 -18
  169. package/src/index.d.ts +310 -26
  170. package/src/index.ts +48 -89
  171. package/src/menu/index.ts +2 -4
  172. package/src/numberfield/createNumberFieldState.d.ts +56 -54
  173. package/src/numberfield/createNumberFieldState.ts +26 -31
  174. package/src/numberfield/index.d.ts +6 -2
  175. package/src/numberfield/index.ts +1 -1
  176. package/src/overlays/createOverlayTriggerState.d.ts +22 -20
  177. package/src/overlays/createOverlayTriggerState.ts +3 -4
  178. package/src/overlays/index.d.ts +6 -2
  179. package/src/overlays/index.ts +1 -1
  180. package/src/radio/createRadioGroupState.d.ts +54 -52
  181. package/src/radio/createRadioGroupState.ts +27 -29
  182. package/src/radio/index.d.ts +7 -2
  183. package/src/radio/index.ts +1 -1
  184. package/src/searchfield/createSearchFieldState.d.ts +16 -14
  185. package/src/searchfield/createSearchFieldState.ts +5 -11
  186. package/src/searchfield/index.d.ts +3 -3
  187. package/src/searchfield/index.ts +2 -5
  188. package/src/select/createSelectState.d.ts +63 -61
  189. package/src/select/createSelectState.ts +27 -27
  190. package/src/select/index.d.ts +2 -2
  191. package/src/select/index.ts +1 -5
  192. package/src/selection/index.ts +6 -7
  193. package/src/slider/createSliderState.d.ts +60 -60
  194. package/src/slider/createSliderState.ts +55 -33
  195. package/src/slider/index.d.ts +3 -3
  196. package/src/slider/index.ts +2 -6
  197. package/src/ssr/index.d.ts +1 -1
  198. package/src/ssr/index.ts +2 -2
  199. package/src/steplist/createStepListState.ts +191 -0
  200. package/src/steplist/index.ts +5 -0
  201. package/src/table/TableCollection.d.ts +42 -40
  202. package/src/table/TableCollection.ts +61 -64
  203. package/src/table/createTableColumnResizeState.ts +242 -0
  204. package/src/table/createTableState.d.ts +7 -4
  205. package/src/table/createTableState.ts +10 -7
  206. package/src/table/index.d.ts +14 -4
  207. package/src/table/index.ts +10 -3
  208. package/src/table/types.d.ts +98 -92
  209. package/src/table/types.ts +17 -13
  210. package/src/tabs/createTabListState.d.ts +59 -57
  211. package/src/tabs/createTabListState.ts +24 -31
  212. package/src/tabs/index.d.ts +8 -2
  213. package/src/tabs/index.ts +1 -1
  214. package/src/textfield/createTextFieldState.d.ts +16 -14
  215. package/src/textfield/createTextFieldState.ts +7 -18
  216. package/src/textfield/index.d.ts +6 -2
  217. package/src/textfield/index.ts +1 -1
  218. package/src/toast/createToastState.d.ts +92 -86
  219. package/src/toast/createToastState.ts +48 -43
  220. package/src/toast/index.d.ts +12 -2
  221. package/src/toast/index.ts +1 -1
  222. package/src/toggle/createToggleGroupState.ts +11 -21
  223. package/src/toggle/createToggleState.d.ts +19 -19
  224. package/src/toggle/createToggleState.ts +2 -16
  225. package/src/toggle/index.d.ts +2 -2
  226. package/src/toggle/index.ts +2 -6
  227. package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
  228. package/src/tooltip/createTooltipTriggerState.ts +12 -11
  229. package/src/tooltip/index.d.ts +7 -2
  230. package/src/tooltip/index.ts +1 -1
  231. package/src/tree/TreeCollection.d.ts +26 -23
  232. package/src/tree/TreeCollection.ts +29 -22
  233. package/src/tree/createTreeState.d.ts +7 -4
  234. package/src/tree/createTreeState.ts +39 -41
  235. package/src/tree/index.d.ts +10 -4
  236. package/src/tree/index.ts +3 -3
  237. package/src/tree/types.d.ts +131 -126
  238. package/src/tree/types.ts +22 -13
  239. package/src/utils/index.d.ts +2 -2
  240. package/src/utils/index.ts +1 -1
  241. package/src/utils/reactivity.d.ts +2 -2
  242. package/src/utils/reactivity.ts +3 -3
@@ -3,8 +3,8 @@
3
3
  * Based on @react-stately/numberfield useNumberFieldState.
4
4
  */
5
5
 
6
- import { createSignal, createMemo, type Accessor } from 'solid-js';
7
- import { access, type MaybeAccessor } from '../utils';
6
+ import { createSignal, createMemo, type Accessor } from "solid-js";
7
+ import { access, type MaybeAccessor } from "../utils";
8
8
 
9
9
  export interface NumberFieldStateProps {
10
10
  /** The current value (controlled). */
@@ -65,15 +65,11 @@ export interface NumberFieldState {
65
65
  /**
66
66
  * Handles decimal operations to avoid floating point errors.
67
67
  */
68
- function handleDecimalOperation(
69
- operator: '+' | '-',
70
- value1: number,
71
- value2: number
72
- ): number {
68
+ function handleDecimalOperation(operator: "+" | "-", value1: number, value2: number): number {
73
69
  // Find the number of decimal places
74
70
  const getDecimals = (n: number) => {
75
71
  const str = String(n);
76
- const idx = str.indexOf('.');
72
+ const idx = str.indexOf(".");
77
73
  return idx === -1 ? 0 : str.length - idx - 1;
78
74
  };
79
75
 
@@ -83,7 +79,7 @@ function handleDecimalOperation(
83
79
  const int1 = Math.round(value1 * multiplier);
84
80
  const int2 = Math.round(value2 * multiplier);
85
81
 
86
- const result = operator === '+' ? int1 + int2 : int1 - int2;
82
+ const result = operator === "+" ? int1 + int2 : int1 - int2;
87
83
  return result / multiplier;
88
84
  }
89
85
 
@@ -104,7 +100,7 @@ function snapToStep(value: number, step: number, min?: number): number {
104
100
  const base = min ?? 0;
105
101
  const diff = value - base;
106
102
  const steps = Math.round(diff / step);
107
- return handleDecimalOperation('+', base, steps * step);
103
+ return handleDecimalOperation("+", base, steps * step);
108
104
  }
109
105
 
110
106
  function isValidStep(step: number | undefined): step is number {
@@ -115,12 +111,12 @@ function isValidStep(step: number | undefined): step is number {
115
111
  * Creates state for a number field.
116
112
  */
117
113
  export function createNumberFieldState(
118
- props: MaybeAccessor<NumberFieldStateProps>
114
+ props: MaybeAccessor<NumberFieldStateProps>,
119
115
  ): NumberFieldState {
120
116
  const getProps = () => access(props);
121
117
 
122
118
  // Get locale and formatter
123
- const locale = () => getProps().locale ?? 'en-US';
119
+ const locale = () => getProps().locale ?? "en-US";
124
120
  const formatOptions = () => getProps().formatOptions ?? {};
125
121
 
126
122
  // Create number formatter
@@ -130,7 +126,7 @@ export function createNumberFieldState(
130
126
 
131
127
  // Create number parser (simplified - real implementation would be more robust)
132
128
  const parseNumber = (value: string): number => {
133
- if (!value || value === '' || value === '-') return NaN;
129
+ if (!value || value === "" || value === "-") return NaN;
134
130
 
135
131
  // Handle locale-specific decimal separators
136
132
  const opts = formatOptions();
@@ -139,17 +135,17 @@ export function createNumberFieldState(
139
135
 
140
136
  // Normalize the input
141
137
  let normalized = value;
142
- if (decimalSeparator !== '.') {
143
- normalized = normalized.replace(decimalSeparator, '.');
138
+ if (decimalSeparator !== ".") {
139
+ normalized = normalized.replace(decimalSeparator, ".");
144
140
  }
145
141
 
146
142
  // Remove grouping separators and currency symbols
147
- normalized = normalized.replace(/[^\d.\-]/g, '');
143
+ normalized = normalized.replace(/[^\d.-]/g, "");
148
144
 
149
145
  const parsed = parseFloat(normalized);
150
146
  if (isNaN(parsed)) return parsed;
151
147
 
152
- if (opts.style === 'percent') {
148
+ if (opts.style === "percent") {
153
149
  return parsed / 100;
154
150
  }
155
151
 
@@ -158,7 +154,7 @@ export function createNumberFieldState(
158
154
 
159
155
  // Format a number to string
160
156
  const formatNumber = (value: number): string => {
161
- if (isNaN(value)) return '';
157
+ if (isNaN(value)) return "";
162
158
  return formatter().format(value);
163
159
  };
164
160
 
@@ -169,12 +165,12 @@ export function createNumberFieldState(
169
165
  const p = getProps();
170
166
  if (hasCustomStep()) return p.step as number;
171
167
  // Default step for percent is 0.01
172
- if (p.formatOptions?.style === 'percent') return 0.01;
168
+ if (p.formatOptions?.style === "percent") return 0.01;
173
169
  return 1;
174
170
  });
175
171
 
176
172
  // Internal signals
177
- const [inputValue, setInputValueInternal] = createSignal<string>('');
173
+ const [inputValue, setInputValueInternal] = createSignal<string>("");
178
174
  const [numberValue, setNumberValue] = createSignal<number>(NaN);
179
175
 
180
176
  const applyConstraints = (value: number): number => {
@@ -242,7 +238,7 @@ export function createNumberFieldState(
242
238
 
243
239
  // Validate partial input
244
240
  const validate = (value: string): boolean => {
245
- if (value === '' || value === '-') return true;
241
+ if (value === "" || value === "-") return true;
246
242
 
247
243
  // Allow partial decimal input like "1."
248
244
  const opts = formatOptions();
@@ -251,7 +247,7 @@ export function createNumberFieldState(
251
247
 
252
248
  // Check if it's a valid partial number
253
249
  const pattern = new RegExp(
254
- `^-?\\d*${decimalSeparator === '.' ? '\\.' : decimalSeparator}?\\d*$`
250
+ `^-?\\d*${decimalSeparator === "." ? "\\." : decimalSeparator}?\\d*$`,
255
251
  );
256
252
  return pattern.test(value);
257
253
  };
@@ -266,14 +262,13 @@ export function createNumberFieldState(
266
262
  // Commit the current input value
267
263
  const commit = () => {
268
264
  ensureInitialized();
269
- syncControlledValue();
270
265
  const p = getProps();
271
266
  const input = inputValue();
272
267
 
273
- if (input === '' || input === '-') {
268
+ if (input === "" || input === "-") {
274
269
  // Clear value
275
270
  setNumberValue(NaN);
276
- setInputValueInternal(p.value === undefined ? '' : formatNumber(actualNumberValue()));
271
+ setInputValueInternal(p.value === undefined ? "" : formatNumber(actualNumberValue()));
277
272
  p.onChange?.(NaN);
278
273
  return;
279
274
  }
@@ -308,7 +303,7 @@ export function createNumberFieldState(
308
303
  if (p.maxValue == null) return true;
309
304
  return (
310
305
  snapToStep(current, step(), p.minValue) > current ||
311
- handleDecimalOperation('+', current, step()) <= p.maxValue
306
+ handleDecimalOperation("+", current, step()) <= p.maxValue
312
307
  );
313
308
  });
314
309
 
@@ -324,11 +319,11 @@ export function createNumberFieldState(
324
319
  if (p.minValue == null) return true;
325
320
  return (
326
321
  snapToStep(current, step(), p.minValue) < current ||
327
- handleDecimalOperation('-', current, step()) >= p.minValue
322
+ handleDecimalOperation("-", current, step()) >= p.minValue
328
323
  );
329
324
  });
330
325
 
331
- const safeNextStep = (operation: '+' | '-', minOrMaxValue: number = 0): number => {
326
+ const safeNextStep = (operation: "+" | "-", minOrMaxValue: number = 0): number => {
332
327
  const p = getProps();
333
328
  const parsed = parsedInputValue();
334
329
 
@@ -338,7 +333,7 @@ export function createNumberFieldState(
338
333
  }
339
334
 
340
335
  const snapped = snapToStep(parsed, step(), p.minValue);
341
- if ((operation === '+' && snapped > parsed) || (operation === '-' && snapped < parsed)) {
336
+ if ((operation === "+" && snapped > parsed) || (operation === "-" && snapped < parsed)) {
342
337
  return clamp(snapped, p.minValue, p.maxValue);
343
338
  }
344
339
 
@@ -353,7 +348,7 @@ export function createNumberFieldState(
353
348
  const p = getProps();
354
349
  if (p.isDisabled || p.isReadOnly) return;
355
350
 
356
- const current = safeNextStep('+', p.minValue);
351
+ const current = safeNextStep("+", p.minValue);
357
352
  setNumberValue(current);
358
353
  setInputValueInternal(formatNumber(current));
359
354
  p.onChange?.(current);
@@ -366,7 +361,7 @@ export function createNumberFieldState(
366
361
  const p = getProps();
367
362
  if (p.isDisabled || p.isReadOnly) return;
368
363
 
369
- const current = safeNextStep('-', p.maxValue);
364
+ const current = safeNextStep("-", p.maxValue);
370
365
  setNumberValue(current);
371
366
  setInputValueInternal(formatNumber(current));
372
367
  p.onChange?.(current);
@@ -1,2 +1,6 @@
1
- export { createNumberFieldState, type NumberFieldStateProps, type NumberFieldState, } from './createNumberFieldState';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export {
2
+ createNumberFieldState,
3
+ type NumberFieldStateProps,
4
+ type NumberFieldState,
5
+ } from "./createNumberFieldState";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -2,4 +2,4 @@ export {
2
2
  createNumberFieldState,
3
3
  type NumberFieldStateProps,
4
4
  type NumberFieldState,
5
- } from './createNumberFieldState';
5
+ } from "./createNumberFieldState";
@@ -2,31 +2,33 @@
2
2
  * Manages state for an overlay trigger.
3
3
  * Based on @react-stately/overlays useOverlayTriggerState.
4
4
  */
5
- import { type Accessor } from 'solid-js';
6
- import { type MaybeAccessor } from '../utils';
5
+ import { type Accessor } from "solid-js";
6
+ import { type MaybeAccessor } from "../utils";
7
7
  export interface OverlayTriggerProps {
8
- /** Whether the overlay is open by default (uncontrolled). */
9
- defaultOpen?: boolean;
10
- /** Whether the overlay is open (controlled). */
11
- isOpen?: boolean;
12
- /** Handler that is called when the overlay's open state changes. */
13
- onOpenChange?: (isOpen: boolean) => void;
8
+ /** Whether the overlay is open by default (uncontrolled). */
9
+ defaultOpen?: boolean;
10
+ /** Whether the overlay is open (controlled). */
11
+ isOpen?: boolean;
12
+ /** Handler that is called when the overlay's open state changes. */
13
+ onOpenChange?: (isOpen: boolean) => void;
14
14
  }
15
15
  export interface OverlayTriggerState {
16
- /** Whether the overlay is currently open. */
17
- readonly isOpen: Accessor<boolean>;
18
- /** Sets whether the overlay is open. */
19
- setOpen(isOpen: boolean): void;
20
- /** Opens the overlay. */
21
- open(): void;
22
- /** Closes the overlay. */
23
- close(): void;
24
- /** Toggles the overlay's visibility. */
25
- toggle(): void;
16
+ /** Whether the overlay is currently open. */
17
+ readonly isOpen: Accessor<boolean>;
18
+ /** Sets whether the overlay is open. */
19
+ setOpen(isOpen: boolean): void;
20
+ /** Opens the overlay. */
21
+ open(): void;
22
+ /** Closes the overlay. */
23
+ close(): void;
24
+ /** Toggles the overlay's visibility. */
25
+ toggle(): void;
26
26
  }
27
27
  /**
28
28
  * Manages state for an overlay trigger. Tracks whether the overlay is open, and provides
29
29
  * methods to toggle this state.
30
30
  */
31
- export declare function createOverlayTriggerState(props?: MaybeAccessor<OverlayTriggerProps>): OverlayTriggerState;
32
- //# sourceMappingURL=createOverlayTriggerState.d.ts.map
31
+ export declare function createOverlayTriggerState(
32
+ props?: MaybeAccessor<OverlayTriggerProps>,
33
+ ): OverlayTriggerState;
34
+ //# sourceMappingURL=createOverlayTriggerState.d.ts.map
@@ -3,8 +3,8 @@
3
3
  * Based on @react-stately/overlays useOverlayTriggerState.
4
4
  */
5
5
 
6
- import { createSignal, type Accessor } from 'solid-js';
7
- import { access, type MaybeAccessor } from '../utils';
6
+ import { createSignal, type Accessor } from "solid-js";
7
+ import { access, type MaybeAccessor } from "../utils";
8
8
 
9
9
  export interface OverlayTriggerProps {
10
10
  /** Whether the overlay is open by default (uncontrolled). */
@@ -33,11 +33,10 @@ export interface OverlayTriggerState {
33
33
  * methods to toggle this state.
34
34
  */
35
35
  export function createOverlayTriggerState(
36
- props: MaybeAccessor<OverlayTriggerProps> = {}
36
+ props: MaybeAccessor<OverlayTriggerProps> = {},
37
37
  ): OverlayTriggerState {
38
38
  const propsAccessor = () => access(props);
39
39
 
40
- // Use controlled state if isOpen is provided, otherwise use internal state
41
40
  const [internalOpen, setInternalOpen] = createSignal(propsAccessor().defaultOpen ?? false);
42
41
 
43
42
  const isOpen: Accessor<boolean> = () => {
@@ -1,2 +1,6 @@
1
- export { createOverlayTriggerState, type OverlayTriggerProps, type OverlayTriggerState, } from './createOverlayTriggerState';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export {
2
+ createOverlayTriggerState,
3
+ type OverlayTriggerProps,
4
+ type OverlayTriggerState,
5
+ } from "./createOverlayTriggerState";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -2,4 +2,4 @@ export {
2
2
  createOverlayTriggerState,
3
3
  type OverlayTriggerProps,
4
4
  type OverlayTriggerState,
5
- } from './createOverlayTriggerState';
5
+ } from "./createOverlayTriggerState";
@@ -6,59 +6,59 @@
6
6
  *
7
7
  * This is a 1:1 port of @react-stately/radio's useRadioGroupState.
8
8
  */
9
- import { Accessor } from 'solid-js';
10
- import { type MaybeAccessor } from '../utils';
9
+ import { Accessor } from "solid-js";
10
+ import { type MaybeAccessor } from "../utils";
11
11
  export interface RadioGroupProps {
12
- /** The current selected value (controlled). */
13
- value?: string | null;
14
- /** The default selected value (uncontrolled). */
15
- defaultValue?: string | null;
16
- /** Handler that is called when the value changes. */
17
- onChange?: (value: string) => void;
18
- /** Whether the radio group is disabled. */
19
- isDisabled?: boolean;
20
- /** Whether the radio group is read only. */
21
- isReadOnly?: boolean;
22
- /** Whether the radio group is required. */
23
- isRequired?: boolean;
24
- /** Whether the radio group is invalid. */
25
- isInvalid?: boolean;
26
- /** The name of the radio group, used when submitting an HTML form. */
27
- name?: string;
28
- /** The form to associate the radio group with. */
29
- form?: string;
30
- /** The label for the radio group. */
31
- label?: string;
32
- /** Orientation of the radio group. */
33
- orientation?: 'horizontal' | 'vertical';
34
- /** Handler that is called when the radio group receives focus. */
35
- onFocus?: (e: FocusEvent) => void;
36
- /** Handler that is called when the radio group loses focus. */
37
- onBlur?: (e: FocusEvent) => void;
38
- /** Handler that is called when the radio group's focus status changes. */
39
- onFocusChange?: (isFocused: boolean) => void;
12
+ /** The current selected value (controlled). */
13
+ value?: string | null;
14
+ /** The default selected value (uncontrolled). */
15
+ defaultValue?: string | null;
16
+ /** Handler that is called when the value changes. */
17
+ onChange?: (value: string) => void;
18
+ /** Whether the radio group is disabled. */
19
+ isDisabled?: boolean;
20
+ /** Whether the radio group is read only. */
21
+ isReadOnly?: boolean;
22
+ /** Whether the radio group is required. */
23
+ isRequired?: boolean;
24
+ /** Whether the radio group is invalid. */
25
+ isInvalid?: boolean;
26
+ /** The name of the radio group, used when submitting an HTML form. */
27
+ name?: string;
28
+ /** The form to associate the radio group with. */
29
+ form?: string;
30
+ /** The label for the radio group. */
31
+ label?: string;
32
+ /** Orientation of the radio group. */
33
+ orientation?: "horizontal" | "vertical";
34
+ /** Handler that is called when the radio group receives focus. */
35
+ onFocus?: (e: FocusEvent) => void;
36
+ /** Handler that is called when the radio group loses focus. */
37
+ onBlur?: (e: FocusEvent) => void;
38
+ /** Handler that is called when the radio group's focus status changes. */
39
+ onFocusChange?: (isFocused: boolean) => void;
40
40
  }
41
41
  export interface RadioGroupState {
42
- /** The name for the group, used for native form submission. */
43
- readonly name: string;
44
- /** Whether the radio group is disabled. */
45
- readonly isDisabled: boolean;
46
- /** Whether the radio group is read only. */
47
- readonly isReadOnly: boolean;
48
- /** Whether the radio group is required. */
49
- readonly isRequired: boolean;
50
- /** Whether the radio group is invalid. */
51
- readonly isInvalid: boolean;
52
- /** The currently selected value. */
53
- readonly selectedValue: Accessor<string | null>;
54
- /** The default selected value. */
55
- readonly defaultSelectedValue: string | null;
56
- /** Sets the selected value. */
57
- setSelectedValue(value: string | null): void;
58
- /** The value of the last focused radio. */
59
- readonly lastFocusedValue: Accessor<string | null>;
60
- /** Sets the last focused value. */
61
- setLastFocusedValue(value: string | null): void;
42
+ /** The name for the group, used for native form submission. */
43
+ readonly name: string;
44
+ /** Whether the radio group is disabled. */
45
+ readonly isDisabled: boolean;
46
+ /** Whether the radio group is read only. */
47
+ readonly isReadOnly: boolean;
48
+ /** Whether the radio group is required. */
49
+ readonly isRequired: boolean;
50
+ /** Whether the radio group is invalid. */
51
+ readonly isInvalid: boolean;
52
+ /** The currently selected value. */
53
+ readonly selectedValue: Accessor<string | null>;
54
+ /** The default selected value. */
55
+ readonly defaultSelectedValue: string | null;
56
+ /** Sets the selected value. */
57
+ setSelectedValue(value: string | null): void;
58
+ /** The value of the last focused radio. */
59
+ readonly lastFocusedValue: Accessor<string | null>;
60
+ /** Sets the last focused value. */
61
+ setLastFocusedValue(value: string | null): void;
62
62
  }
63
63
  /**
64
64
  * Internal WeakMap to store sync version accessors for each radio group state.
@@ -73,5 +73,7 @@ export declare const radioGroupSyncVersion: WeakMap<RadioGroupState, Accessor<nu
73
73
  * Provides state management for a radio group component.
74
74
  * Provides a name for the group, and manages selection and focus state.
75
75
  */
76
- export declare function createRadioGroupState(props?: MaybeAccessor<RadioGroupProps>): RadioGroupState;
77
- //# sourceMappingURL=createRadioGroupState.d.ts.map
76
+ export declare function createRadioGroupState(
77
+ props?: MaybeAccessor<RadioGroupProps>,
78
+ ): RadioGroupState;
79
+ //# sourceMappingURL=createRadioGroupState.d.ts.map
@@ -7,19 +7,15 @@
7
7
  * This is a 1:1 port of @react-stately/radio's useRadioGroupState.
8
8
  */
9
9
 
10
- import { createSignal, Accessor, untrack } from 'solid-js';
11
- import { type MaybeAccessor, access } from '../utils';
12
- import { createId } from '../ssr';
10
+ import { createMemo, createSignal, Accessor, untrack } from "solid-js";
11
+ import { type MaybeAccessor, access } from "../utils";
12
+ import { createId } from "../ssr";
13
13
  import {
14
14
  createFormValidationState,
15
15
  type FormValidationState,
16
16
  type ValidationFunction,
17
17
  type ValidationResult,
18
- } from '../form';
19
-
20
- // ============================================
21
- // TYPES
22
- // ============================================
18
+ } from "../form";
23
19
 
24
20
  export interface RadioGroupProps {
25
21
  /** The current selected value (controlled). */
@@ -43,7 +39,7 @@ export interface RadioGroupProps {
43
39
  /** The label for the radio group. */
44
40
  label?: string;
45
41
  /** Orientation of the radio group. */
46
- orientation?: 'horizontal' | 'vertical';
42
+ orientation?: "horizontal" | "vertical";
47
43
  /** Handler that is called when the radio group receives focus. */
48
44
  onFocus?: (e: FocusEvent) => void;
49
45
  /** Handler that is called when the radio group loses focus. */
@@ -51,14 +47,21 @@ export interface RadioGroupProps {
51
47
  /** Handler that is called when the radio group's focus status changes. */
52
48
  onFocusChange?: (isFocused: boolean) => void;
53
49
  /** Backward-compatible controlled validation state. */
54
- validationState?: 'valid' | 'invalid';
50
+ validationState?: "valid" | "invalid";
55
51
  /** Custom validation function. */
56
52
  validate?: ValidationFunction<string | null>;
57
53
  /** Validation behavior for the radio group. */
58
- validationBehavior?: 'aria' | 'native';
54
+ validationBehavior?: "aria" | "native";
59
55
  }
60
56
 
61
- export interface RadioGroupState extends Pick<FormValidationState, 'realtimeValidation' | 'displayValidation' | 'updateValidation' | 'resetValidation' | 'commitValidation'> {
57
+ export interface RadioGroupState extends Pick<
58
+ FormValidationState,
59
+ | "realtimeValidation"
60
+ | "displayValidation"
61
+ | "updateValidation"
62
+ | "resetValidation"
63
+ | "commitValidation"
64
+ > {
62
65
  /** The name for the group, used for native form submission. */
63
66
  readonly name: string;
64
67
 
@@ -93,10 +96,6 @@ export interface RadioGroupState extends Pick<FormValidationState, 'realtimeVali
93
96
  readonly displayValidation: Accessor<ValidationResult>;
94
97
  }
95
98
 
96
- // ============================================
97
- // INTERNAL: SolidJS-specific sync mechanism
98
- // ============================================
99
-
100
99
  /**
101
100
  * Internal WeakMap to store sync version accessors for each radio group state.
102
101
  * This is used by createRadio to trigger DOM sync when native radio behavior
@@ -107,17 +106,11 @@ export interface RadioGroupState extends Pick<FormValidationState, 'realtimeVali
107
106
  */
108
107
  export const radioGroupSyncVersion: WeakMap<RadioGroupState, Accessor<number>> = new WeakMap();
109
108
 
110
- // ============================================
111
- // IMPLEMENTATION
112
- // ============================================
113
-
114
109
  /**
115
110
  * Provides state management for a radio group component.
116
111
  * Provides a name for the group, and manages selection and focus state.
117
112
  */
118
- export function createRadioGroupState(
119
- props: MaybeAccessor<RadioGroupProps> = {}
120
- ): RadioGroupState {
113
+ export function createRadioGroupState(props: MaybeAccessor<RadioGroupProps> = {}): RadioGroupState {
121
114
  const getProps = () => access(props);
122
115
 
123
116
  // Get initial props using untrack to avoid setting up dependencies
@@ -131,7 +124,7 @@ export function createRadioGroupState(
131
124
  // Create internal signal for uncontrolled mode
132
125
  // Initialize with defaultValue only (not value, which is for controlled mode)
133
126
  const [internalValue, setInternalValue] = createSignal<string | null>(
134
- initialProps.defaultValue ?? null
127
+ initialProps.defaultValue ?? null,
135
128
  );
136
129
  const [lastFocusedValue, setLastFocusedValueInternal] = createSignal<string | null>(null);
137
130
 
@@ -140,16 +133,21 @@ export function createRadioGroupState(
140
133
  // from our reactive state (e.g., clicking a radio unchecks siblings in the DOM)
141
134
  const [syncVersion, setSyncVersion] = createSignal(0);
142
135
 
136
+ const controlledValue = createMemo<string | null | undefined>(() => {
137
+ const value = getProps().value;
138
+ return value === undefined ? undefined : (value ?? null);
139
+ });
140
+
143
141
  // Determine if controlled - must be reactive to handle dynamic props
144
- const isControlled = () => getProps().value !== undefined;
142
+ const isControlled = () => controlledValue() !== undefined;
145
143
 
146
144
  // Get current value - reactive for both controlled and uncontrolled modes
147
145
  const selectedValue: Accessor<string | null> = () => {
148
- const p = getProps();
149
146
  // In controlled mode, always read from props.value reactively
150
147
  // In uncontrolled mode, read from internal signal
151
- if (p.value !== undefined) {
152
- return p.value ?? null;
148
+ const value = controlledValue();
149
+ if (value !== undefined) {
150
+ return value;
153
151
  }
154
152
  return internalValue();
155
153
  };
@@ -168,7 +166,7 @@ export function createRadioGroupState(
168
166
  return getProps().validate;
169
167
  },
170
168
  get validationBehavior() {
171
- return getProps().validationBehavior ?? 'aria';
169
+ return getProps().validationBehavior ?? "native";
172
170
  },
173
171
  get name() {
174
172
  return getProps().name;
@@ -1,2 +1,7 @@
1
- export { createRadioGroupState, radioGroupSyncVersion, type RadioGroupProps, type RadioGroupState, } from './createRadioGroupState';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export {
2
+ createRadioGroupState,
3
+ radioGroupSyncVersion,
4
+ type RadioGroupProps,
5
+ type RadioGroupState,
6
+ } from "./createRadioGroupState";
7
+ //# sourceMappingURL=index.d.ts.map
@@ -3,4 +3,4 @@ export {
3
3
  radioGroupSyncVersion,
4
4
  type RadioGroupProps,
5
5
  type RadioGroupState,
6
- } from './createRadioGroupState';
6
+ } from "./createRadioGroupState";
@@ -2,24 +2,26 @@
2
2
  * Creates state for a search field component.
3
3
  * Based on @react-stately/searchfield useSearchFieldState.
4
4
  */
5
- import { type Accessor } from 'solid-js';
6
- import { type MaybeAccessor } from '../utils';
5
+ import { type Accessor } from "solid-js";
6
+ import { type MaybeAccessor } from "../utils";
7
7
  export interface SearchFieldStateProps {
8
- /** The current value (controlled). */
9
- value?: string;
10
- /** The default value (uncontrolled). */
11
- defaultValue?: string;
12
- /** Handler that is called when the value changes. */
13
- onChange?: (value: string) => void;
8
+ /** The current value (controlled). */
9
+ value?: string;
10
+ /** The default value (uncontrolled). */
11
+ defaultValue?: string;
12
+ /** Handler that is called when the value changes. */
13
+ onChange?: (value: string) => void;
14
14
  }
15
15
  export interface SearchFieldState {
16
- /** The current value of the search field. */
17
- value: Accessor<string>;
18
- /** Sets the value of the search field. */
19
- setValue: (value: string) => void;
16
+ /** The current value of the search field. */
17
+ value: Accessor<string>;
18
+ /** Sets the value of the search field. */
19
+ setValue: (value: string) => void;
20
20
  }
21
21
  /**
22
22
  * Provides state management for a search field.
23
23
  */
24
- export declare function createSearchFieldState(props: MaybeAccessor<SearchFieldStateProps>): SearchFieldState;
25
- //# sourceMappingURL=createSearchFieldState.d.ts.map
24
+ export declare function createSearchFieldState(
25
+ props: MaybeAccessor<SearchFieldStateProps>,
26
+ ): SearchFieldState;
27
+ //# sourceMappingURL=createSearchFieldState.d.ts.map