@proyecto-viviana/solid-stately 0.2.4 → 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 (243) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +30 -283
  3. package/dist/autocomplete/createAutocompleteState.d.ts +3 -2
  4. package/dist/autocomplete/index.d.ts +1 -1
  5. package/dist/calendar/createCalendarState.d.ts +22 -7
  6. package/dist/calendar/createDateFieldState.d.ts +30 -7
  7. package/dist/calendar/createDatePickerState.d.ts +60 -0
  8. package/dist/calendar/createRangeCalendarState.d.ts +27 -8
  9. package/dist/calendar/createTimeFieldState.d.ts +34 -7
  10. package/dist/calendar/index.d.ts +7 -6
  11. package/dist/checkbox/createCheckboxGroupState.d.ts +12 -3
  12. package/dist/checkbox/index.d.ts +1 -1
  13. package/dist/collections/ListCollection.d.ts +1 -1
  14. package/dist/collections/createListState.d.ts +8 -8
  15. package/dist/collections/createMenuState.d.ts +7 -7
  16. package/dist/collections/createSelectionState.d.ts +5 -5
  17. package/dist/collections/index.d.ts +5 -5
  18. package/dist/collections/types.d.ts +23 -12
  19. package/dist/color/Color.d.ts +1 -1
  20. package/dist/color/createColorAreaState.d.ts +4 -2
  21. package/dist/color/createColorFieldState.d.ts +38 -12
  22. package/dist/color/createColorSliderState.d.ts +9 -2
  23. package/dist/color/createColorWheelState.d.ts +13 -2
  24. package/dist/color/getColorChannels.d.ts +20 -0
  25. package/dist/color/index.d.ts +6 -6
  26. package/dist/color/types.d.ts +4 -4
  27. package/dist/combobox/createComboBoxState.d.ts +27 -13
  28. package/dist/combobox/index.d.ts +1 -1
  29. package/dist/data/createAsyncList.d.ts +111 -0
  30. package/dist/data/createListData.d.ts +65 -0
  31. package/dist/data/createTreeData.d.ts +65 -0
  32. package/dist/data/index.d.ts +3 -0
  33. package/dist/datepicker/index.d.ts +8 -0
  34. package/dist/disclosure/createDisclosureState.d.ts +2 -2
  35. package/dist/disclosure/index.d.ts +1 -1
  36. package/dist/dnd/createDragState.d.ts +2 -2
  37. package/dist/dnd/createDraggableCollectionState.d.ts +2 -2
  38. package/dist/dnd/createDropState.d.ts +2 -2
  39. package/dist/dnd/createDroppableCollectionState.d.ts +3 -3
  40. package/dist/dnd/index.d.ts +5 -5
  41. package/dist/dnd/types.d.ts +16 -16
  42. package/dist/form/createFormValidationState.d.ts +3 -3
  43. package/dist/form/index.d.ts +1 -1
  44. package/dist/grid/createGridState.d.ts +2 -2
  45. package/dist/grid/index.d.ts +2 -2
  46. package/dist/grid/types.d.ts +17 -11
  47. package/dist/index.d.ts +31 -25
  48. package/dist/index.js +7990 -6264
  49. package/dist/index.js.map +1 -7
  50. package/dist/menu/index.d.ts +8 -0
  51. package/dist/numberfield/createNumberFieldState.d.ts +2 -2
  52. package/dist/numberfield/index.d.ts +1 -1
  53. package/dist/overlays/createOverlayTriggerState.d.ts +2 -2
  54. package/dist/overlays/index.d.ts +1 -1
  55. package/dist/radio/createRadioGroupState.d.ts +13 -4
  56. package/dist/radio/index.d.ts +1 -1
  57. package/dist/searchfield/createSearchFieldState.d.ts +2 -2
  58. package/dist/searchfield/index.d.ts +2 -2
  59. package/dist/select/createSelectState.d.ts +20 -3
  60. package/dist/select/index.d.ts +1 -1
  61. package/dist/selection/index.d.ts +11 -0
  62. package/dist/slider/createSliderState.d.ts +3 -3
  63. package/dist/slider/index.d.ts +2 -2
  64. package/dist/steplist/createStepListState.d.ts +48 -0
  65. package/dist/steplist/index.d.ts +1 -0
  66. package/dist/table/TableCollection.d.ts +3 -3
  67. package/dist/table/createTableColumnResizeState.d.ts +54 -0
  68. package/dist/table/createTableState.d.ts +2 -2
  69. package/dist/table/index.d.ts +5 -3
  70. package/dist/table/types.d.ts +10 -10
  71. package/dist/tabs/createTabListState.d.ts +5 -5
  72. package/dist/tabs/index.d.ts +1 -1
  73. package/dist/textfield/createTextFieldState.d.ts +2 -2
  74. package/dist/textfield/index.d.ts +1 -1
  75. package/dist/toast/createToastState.d.ts +15 -3
  76. package/dist/toast/index.d.ts +1 -1
  77. package/dist/toggle/createToggleGroupState.d.ts +45 -0
  78. package/dist/toggle/createToggleState.d.ts +2 -2
  79. package/dist/toggle/index.d.ts +2 -1
  80. package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
  81. package/dist/tooltip/index.d.ts +1 -1
  82. package/dist/tree/TreeCollection.d.ts +5 -4
  83. package/dist/tree/createTreeState.d.ts +2 -2
  84. package/dist/tree/index.d.ts +3 -3
  85. package/dist/tree/types.d.ts +19 -13
  86. package/dist/utils/index.d.ts +1 -1
  87. package/dist/utils/reactivity.d.ts +1 -1
  88. package/package.json +30 -30
  89. package/src/autocomplete/createAutocompleteState.d.ts +19 -17
  90. package/src/autocomplete/createAutocompleteState.ts +25 -32
  91. package/src/autocomplete/index.d.ts +6 -2
  92. package/src/autocomplete/index.ts +1 -1
  93. package/src/calendar/createCalendarState.d.ts +139 -117
  94. package/src/calendar/createCalendarState.ts +221 -74
  95. package/src/calendar/createDateFieldState.d.ts +130 -95
  96. package/src/calendar/createDateFieldState.ts +286 -151
  97. package/src/calendar/createDatePickerState.ts +347 -0
  98. package/src/calendar/createRangeCalendarState.d.ts +154 -129
  99. package/src/calendar/createRangeCalendarState.ts +293 -79
  100. package/src/calendar/createTimeFieldState.d.ts +81 -79
  101. package/src/calendar/createTimeFieldState.ts +187 -108
  102. package/src/calendar/index.d.ts +80 -7
  103. package/src/calendar/index.ts +21 -12
  104. package/src/checkbox/createCheckboxGroupState.d.ts +57 -55
  105. package/src/checkbox/createCheckboxGroupState.ts +57 -30
  106. package/src/checkbox/index.d.ts +6 -2
  107. package/src/checkbox/index.ts +1 -1
  108. package/src/collections/ListCollection.d.ts +25 -22
  109. package/src/collections/ListCollection.ts +152 -146
  110. package/src/collections/createListState.d.ts +73 -58
  111. package/src/collections/createListState.ts +267 -264
  112. package/src/collections/createMenuState.d.ts +36 -31
  113. package/src/collections/createMenuState.ts +112 -106
  114. package/src/collections/createSelectionState.d.ts +78 -65
  115. package/src/collections/createSelectionState.ts +340 -336
  116. package/src/collections/index.d.ts +38 -6
  117. package/src/collections/index.ts +41 -46
  118. package/src/collections/types.d.ts +101 -101
  119. package/src/collections/types.ts +181 -169
  120. package/src/color/Color.d.ts +20 -5
  121. package/src/color/Color.ts +1054 -951
  122. package/src/color/createColorAreaState.d.ts +67 -65
  123. package/src/color/createColorAreaState.ts +301 -293
  124. package/src/color/createColorFieldState.d.ts +46 -44
  125. package/src/color/createColorFieldState.ts +428 -292
  126. package/src/color/createColorSliderState.d.ts +58 -56
  127. package/src/color/createColorSliderState.ts +272 -241
  128. package/src/color/createColorWheelState.d.ts +42 -40
  129. package/src/color/createColorWheelState.ts +248 -211
  130. package/src/color/getColorChannels.ts +36 -0
  131. package/src/color/index.d.ts +36 -7
  132. package/src/color/index.ts +44 -47
  133. package/src/color/types.d.ts +68 -63
  134. package/src/color/types.ts +119 -127
  135. package/src/combobox/createComboBoxState.d.ts +107 -105
  136. package/src/combobox/createComboBoxState.ts +790 -703
  137. package/src/combobox/index.d.ts +10 -2
  138. package/src/combobox/index.ts +13 -13
  139. package/src/data/createAsyncList.ts +403 -0
  140. package/src/data/createListData.ts +298 -0
  141. package/src/data/createTreeData.ts +646 -0
  142. package/src/data/index.ts +25 -0
  143. package/src/datepicker/index.ts +32 -0
  144. package/src/disclosure/createDisclosureState.d.ts +47 -43
  145. package/src/disclosure/createDisclosureState.ts +9 -23
  146. package/src/disclosure/index.d.ts +10 -2
  147. package/src/disclosure/index.ts +1 -1
  148. package/src/dnd/createDragState.d.ts +51 -42
  149. package/src/dnd/createDragState.ts +151 -153
  150. package/src/dnd/createDraggableCollectionState.d.ts +52 -41
  151. package/src/dnd/createDraggableCollectionState.ts +158 -165
  152. package/src/dnd/createDropState.d.ts +64 -45
  153. package/src/dnd/createDropState.ts +202 -212
  154. package/src/dnd/createDroppableCollectionState.d.ts +88 -59
  155. package/src/dnd/createDroppableCollectionState.ts +354 -357
  156. package/src/dnd/index.d.ts +54 -6
  157. package/src/dnd/index.ts +63 -76
  158. package/src/dnd/types.d.ts +167 -156
  159. package/src/dnd/types.ts +316 -317
  160. package/src/form/createFormValidationState.d.ts +47 -45
  161. package/src/form/createFormValidationState.ts +356 -389
  162. package/src/form/index.d.ts +16 -2
  163. package/src/form/index.ts +15 -15
  164. package/src/grid/createGridState.d.ts +7 -4
  165. package/src/grid/createGridState.ts +44 -51
  166. package/src/grid/index.d.ts +3 -3
  167. package/src/grid/index.ts +2 -8
  168. package/src/grid/types.d.ts +136 -129
  169. package/src/grid/types.ts +24 -17
  170. package/src/index.d.ts +310 -26
  171. package/src/index.ts +87 -79
  172. package/src/menu/index.ts +17 -0
  173. package/src/numberfield/createNumberFieldState.d.ts +56 -54
  174. package/src/numberfield/createNumberFieldState.ts +422 -383
  175. package/src/numberfield/index.d.ts +6 -2
  176. package/src/numberfield/index.ts +5 -5
  177. package/src/overlays/createOverlayTriggerState.d.ts +22 -20
  178. package/src/overlays/createOverlayTriggerState.ts +66 -67
  179. package/src/overlays/index.d.ts +6 -2
  180. package/src/overlays/index.ts +5 -5
  181. package/src/radio/createRadioGroupState.d.ts +54 -52
  182. package/src/radio/createRadioGroupState.ts +66 -30
  183. package/src/radio/index.d.ts +7 -2
  184. package/src/radio/index.ts +1 -1
  185. package/src/searchfield/createSearchFieldState.d.ts +16 -14
  186. package/src/searchfield/createSearchFieldState.ts +56 -62
  187. package/src/searchfield/index.d.ts +3 -3
  188. package/src/searchfield/index.ts +2 -5
  189. package/src/select/createSelectState.d.ts +63 -61
  190. package/src/select/createSelectState.ts +290 -181
  191. package/src/select/index.d.ts +2 -2
  192. package/src/select/index.ts +1 -5
  193. package/src/selection/index.ts +27 -0
  194. package/src/slider/createSliderState.d.ts +60 -60
  195. package/src/slider/createSliderState.ts +233 -211
  196. package/src/slider/index.d.ts +3 -3
  197. package/src/slider/index.ts +2 -6
  198. package/src/ssr/index.d.ts +1 -1
  199. package/src/ssr/index.ts +2 -2
  200. package/src/steplist/createStepListState.ts +191 -0
  201. package/src/steplist/index.ts +5 -0
  202. package/src/table/TableCollection.d.ts +42 -40
  203. package/src/table/TableCollection.ts +61 -64
  204. package/src/table/createTableColumnResizeState.ts +242 -0
  205. package/src/table/createTableState.d.ts +7 -4
  206. package/src/table/createTableState.ts +10 -7
  207. package/src/table/index.d.ts +14 -4
  208. package/src/table/index.ts +10 -3
  209. package/src/table/types.d.ts +98 -92
  210. package/src/table/types.ts +17 -13
  211. package/src/tabs/createTabListState.d.ts +59 -57
  212. package/src/tabs/createTabListState.ts +58 -39
  213. package/src/tabs/index.d.ts +8 -2
  214. package/src/tabs/index.ts +1 -1
  215. package/src/textfield/createTextFieldState.d.ts +16 -14
  216. package/src/textfield/createTextFieldState.ts +7 -18
  217. package/src/textfield/index.d.ts +6 -2
  218. package/src/textfield/index.ts +1 -1
  219. package/src/toast/createToastState.d.ts +92 -81
  220. package/src/toast/createToastState.ts +56 -44
  221. package/src/toast/index.d.ts +12 -2
  222. package/src/toast/index.ts +1 -1
  223. package/src/toggle/createToggleGroupState.ts +117 -0
  224. package/src/toggle/createToggleState.d.ts +19 -19
  225. package/src/toggle/createToggleState.ts +2 -16
  226. package/src/toggle/index.d.ts +2 -2
  227. package/src/toggle/index.ts +6 -4
  228. package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
  229. package/src/tooltip/createTooltipTriggerState.ts +184 -183
  230. package/src/tooltip/index.d.ts +7 -2
  231. package/src/tooltip/index.ts +6 -6
  232. package/src/tree/TreeCollection.d.ts +26 -23
  233. package/src/tree/TreeCollection.ts +215 -175
  234. package/src/tree/createTreeState.d.ts +7 -4
  235. package/src/tree/createTreeState.ts +390 -392
  236. package/src/tree/index.d.ts +10 -4
  237. package/src/tree/index.ts +13 -13
  238. package/src/tree/types.d.ts +131 -126
  239. package/src/tree/types.ts +183 -174
  240. package/src/utils/index.d.ts +2 -2
  241. package/src/utils/index.ts +1 -1
  242. package/src/utils/reactivity.d.ts +2 -2
  243. package/src/utils/reactivity.ts +3 -3
@@ -3,18 +3,19 @@
3
3
  * Based on @react-stately/tabs.
4
4
  */
5
5
 
6
- import { createSignal, type Accessor } from 'solid-js';
7
- import { access, type MaybeAccessor } from '../utils';
8
- import { ListCollection } from '../collections/ListCollection';
6
+ import { createComputed, createMemo, createSignal, type Accessor } from "solid-js";
7
+ import { access, type MaybeAccessor } from "../utils";
8
+ import { ListCollection } from "../collections/ListCollection";
9
9
  import type {
10
10
  Collection,
11
+ CollectionItemLike,
11
12
  CollectionNode,
12
13
  Key,
13
14
  FocusStrategy,
14
- } from '../collections/types';
15
+ } from "../collections/types";
15
16
 
16
- export type KeyboardActivation = 'automatic' | 'manual';
17
- export type TabOrientation = 'horizontal' | 'vertical';
17
+ export type KeyboardActivation = "automatic" | "manual";
18
+ export type TabOrientation = "horizontal" | "vertical";
18
19
 
19
20
  export interface TabListStateProps<T = unknown> {
20
21
  /** The items in the tab list. */
@@ -76,27 +77,26 @@ export interface TabListState<T = unknown> {
76
77
  * Creates state for a tab list component.
77
78
  */
78
79
  export function createTabListState<T = unknown>(
79
- props: MaybeAccessor<TabListStateProps<T>>
80
+ props: MaybeAccessor<TabListStateProps<T>>,
80
81
  ): TabListState<T> {
81
82
  const getProps = () => access(props);
82
83
 
83
- // Build collection from items
84
- const collection: Accessor<Collection<T>> = () => {
84
+ const collection: Accessor<Collection<T>> = createMemo(() => {
85
85
  const p = getProps();
86
86
  const items = p.items ?? [];
87
87
 
88
88
  const nodes: CollectionNode<T>[] = items.map((item, index) => {
89
- const key = p.getKey?.(item) ?? (item as any).key ?? (item as any).id ?? index;
90
- const textValue =
91
- p.getTextValue?.(item) ?? (item as any).textValue ?? (item as any).label ?? String(item);
92
- const isDisabled = p.getDisabled?.(item) ?? (item as any).isDisabled ?? false;
89
+ const o = item as CollectionItemLike;
90
+ const key = p.getKey?.(item) ?? o.key ?? o.id ?? index;
91
+ const textValue = p.getTextValue?.(item) ?? o.textValue ?? o.label ?? String(item);
92
+ const isDisabled = p.getDisabled?.(item) ?? o.isDisabled ?? false;
93
93
 
94
94
  return {
95
- type: 'item' as const,
95
+ type: "item" as const,
96
96
  key,
97
97
  value: item,
98
98
  textValue,
99
- rendered: null as any,
99
+ rendered: null!,
100
100
  level: 0,
101
101
  index,
102
102
  parentKey: null,
@@ -107,10 +107,10 @@ export function createTabListState<T = unknown>(
107
107
  });
108
108
 
109
109
  return new ListCollection(nodes);
110
- };
110
+ });
111
111
 
112
- // Compute disabled keys
113
- const disabledKeys: Accessor<Set<Key>> = () => {
112
+ // Compute disabled keys (memoized to avoid rebuilding Set per access)
113
+ const disabledKeys: Accessor<Set<Key>> = createMemo(() => {
114
114
  const p = getProps();
115
115
  const result = new Set<Key>(p.disabledKeys ?? []);
116
116
 
@@ -122,9 +122,8 @@ export function createTabListState<T = unknown>(
122
122
  }
123
123
 
124
124
  return result;
125
- };
125
+ });
126
126
 
127
- // Check if a key is disabled
128
127
  const isKeyDisabled = (key: Key): boolean => {
129
128
  const p = getProps();
130
129
  if (p.isDisabled) return true;
@@ -142,30 +141,24 @@ export function createTabListState<T = unknown>(
142
141
  return null;
143
142
  };
144
143
 
145
- // Get initial selected key
146
144
  const getInitialSelectedKey = (): Key | null => {
147
145
  const p = getProps();
148
146
 
149
- // If controlled, use that value
150
147
  if (p.selectedKey !== undefined) {
151
148
  return p.selectedKey;
152
149
  }
153
150
 
154
- // If default provided and not disabled, use it
155
151
  if (p.defaultSelectedKey !== undefined && !isKeyDisabled(p.defaultSelectedKey)) {
156
152
  return p.defaultSelectedKey;
157
153
  }
158
154
 
159
- // Otherwise, select first non-disabled
160
155
  return findFirstNonDisabledKey();
161
156
  };
162
157
 
163
- // Selection state
164
158
  const [selectedKeyInternal, setSelectedKeyInternal] = createSignal<Key | null>(
165
- getInitialSelectedKey()
159
+ getInitialSelectedKey(),
166
160
  );
167
161
 
168
- // Compute actual selected key (controlled vs uncontrolled)
169
162
  const selectedKey: Accessor<Key | null> = () => {
170
163
  const p = getProps();
171
164
  if (p.selectedKey !== undefined) {
@@ -175,38 +168,30 @@ export function createTabListState<T = unknown>(
175
168
  };
176
169
 
177
170
  const setSelectedKey = (key: Key) => {
178
- // Don't select disabled keys
179
171
  if (isKeyDisabled(key)) return;
172
+ if (selectedKey() === key) return;
180
173
 
181
174
  const p = getProps();
182
- // For uncontrolled mode, update internal state
183
175
  if (p.selectedKey === undefined) {
184
176
  setSelectedKeyInternal(key);
185
177
  }
186
178
 
187
- // Always call onChange
188
179
  p.onSelectionChange?.(key);
189
180
  };
190
181
 
191
- // Get selected item
192
182
  const selectedItem: Accessor<CollectionNode<T> | null> = () => {
193
183
  const key = selectedKey();
194
184
  if (key === null) return null;
195
185
  return collection().getItem(key);
196
186
  };
197
187
 
198
- // Is disabled accessor
199
188
  const isDisabled: Accessor<boolean> = () => getProps().isDisabled ?? false;
200
189
 
201
- // Keyboard activation accessor
202
190
  const keyboardActivation: Accessor<KeyboardActivation> = () =>
203
- getProps().keyboardActivation ?? 'automatic';
191
+ getProps().keyboardActivation ?? "automatic";
204
192
 
205
- // Orientation accessor
206
- const orientation: Accessor<TabOrientation> = () =>
207
- getProps().orientation ?? 'horizontal';
193
+ const orientation: Accessor<TabOrientation> = () => getProps().orientation ?? "horizontal";
208
194
 
209
- // Focus state
210
195
  const [isFocused, setIsFocused] = createSignal(false);
211
196
  const [focusedKey, setFocusedKeyInternal] = createSignal<Key | null>(null);
212
197
  const [childFocusStrategy, setChildFocusStrategy] = createSignal<FocusStrategy | null>(null);
@@ -216,11 +201,45 @@ export function createTabListState<T = unknown>(
216
201
  setChildFocusStrategy(childStrategy ?? null);
217
202
 
218
203
  // In automatic mode, selecting follows focus
219
- if (keyboardActivation() === 'automatic' && key !== null && !isKeyDisabled(key)) {
204
+ if (
205
+ keyboardActivation() === "automatic" &&
206
+ key !== null &&
207
+ key !== selectedKey() &&
208
+ !isKeyDisabled(key)
209
+ ) {
220
210
  setSelectedKey(key);
221
211
  }
222
212
  };
223
213
 
214
+ // Keep uncontrolled selection valid as items/disabled keys change.
215
+ createComputed(() => {
216
+ const p = getProps();
217
+ if (p.selectedKey !== undefined) return;
218
+
219
+ const coll = collection();
220
+ const current = selectedKeyInternal();
221
+ const currentExists = current !== null && coll.getItem(current) !== null;
222
+ const currentEnabled = current !== null && !isKeyDisabled(current);
223
+
224
+ if (currentExists && currentEnabled) return;
225
+
226
+ if (
227
+ p.defaultSelectedKey !== undefined &&
228
+ coll.getItem(p.defaultSelectedKey) !== null &&
229
+ !isKeyDisabled(p.defaultSelectedKey)
230
+ ) {
231
+ if (p.defaultSelectedKey !== current) {
232
+ setSelectedKeyInternal(p.defaultSelectedKey);
233
+ }
234
+ return;
235
+ }
236
+
237
+ const nextKey = findFirstNonDisabledKey();
238
+ if (nextKey !== current) {
239
+ setSelectedKeyInternal(nextKey);
240
+ }
241
+ });
242
+
224
243
  return {
225
244
  collection,
226
245
  selectedKey,
@@ -1,2 +1,8 @@
1
- export { createTabListState, type TabListStateProps, type TabListState, type KeyboardActivation, type TabOrientation, } from './createTabListState';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export {
2
+ createTabListState,
3
+ type TabListStateProps,
4
+ type TabListState,
5
+ type KeyboardActivation,
6
+ type TabOrientation,
7
+ } from "./createTabListState";
8
+ //# sourceMappingURL=index.d.ts.map
package/src/tabs/index.ts CHANGED
@@ -4,4 +4,4 @@ export {
4
4
  type TabListState,
5
5
  type KeyboardActivation,
6
6
  type TabOrientation,
7
- } from './createTabListState';
7
+ } from "./createTabListState";
@@ -6,25 +6,27 @@
6
6
  * This is a port of @react-stately/utils's useControlledState pattern
7
7
  * as used by @react-aria/textfield.
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 TextFieldStateOptions {
12
- /** The current value (controlled). */
13
- value?: string;
14
- /** The default value (uncontrolled). */
15
- defaultValue?: string;
16
- /** Handler that is called when the value changes. */
17
- onChange?: (value: string) => void;
12
+ /** The current value (controlled). */
13
+ value?: string;
14
+ /** The default value (uncontrolled). */
15
+ defaultValue?: string;
16
+ /** Handler that is called when the value changes. */
17
+ onChange?: (value: string) => void;
18
18
  }
19
19
  export interface TextFieldState {
20
- /** The current value of the text field. */
21
- readonly value: Accessor<string>;
22
- /** Sets the value of the text field. */
23
- setValue(value: string): void;
20
+ /** The current value of the text field. */
21
+ readonly value: Accessor<string>;
22
+ /** Sets the value of the text field. */
23
+ setValue(value: string): void;
24
24
  }
25
25
  /**
26
26
  * Provides state management for text input components.
27
27
  * Supports both controlled and uncontrolled modes.
28
28
  */
29
- export declare function createTextFieldState(props?: MaybeAccessor<TextFieldStateOptions>): TextFieldState;
30
- //# sourceMappingURL=createTextFieldState.d.ts.map
29
+ export declare function createTextFieldState(
30
+ props?: MaybeAccessor<TextFieldStateOptions>,
31
+ ): TextFieldState;
32
+ //# sourceMappingURL=createTextFieldState.d.ts.map
@@ -7,12 +7,8 @@
7
7
  * as used by @react-aria/textfield.
8
8
  */
9
9
 
10
- import { createSignal, Accessor } from 'solid-js';
11
- import { type MaybeAccessor, access } from '../utils';
12
-
13
- // ============================================
14
- // TYPES
15
- // ============================================
10
+ import { createSignal, Accessor } from "solid-js";
11
+ import { type MaybeAccessor, access } from "../utils";
16
12
 
17
13
  export interface TextFieldStateOptions {
18
14
  /** The current value (controlled). */
@@ -30,34 +26,27 @@ export interface TextFieldState {
30
26
  setValue(value: string): void;
31
27
  }
32
28
 
33
- // ============================================
34
- // IMPLEMENTATION
35
- // ============================================
36
-
37
29
  /**
38
30
  * Provides state management for text input components.
39
31
  * Supports both controlled and uncontrolled modes.
40
32
  */
41
- export function createTextFieldState(props: MaybeAccessor<TextFieldStateOptions> = {}): TextFieldState {
33
+ export function createTextFieldState(
34
+ props: MaybeAccessor<TextFieldStateOptions> = {},
35
+ ): TextFieldState {
42
36
  const getProps = () => access(props);
43
37
 
44
- // Get initial value
45
38
  const initialProps = getProps();
46
- const initialValue = initialProps.value ?? initialProps.defaultValue ?? '';
39
+ const initialValue = initialProps.value ?? initialProps.defaultValue ?? "";
47
40
 
48
- // Create internal signal for uncontrolled mode
49
41
  const [internalValue, setInternalValue] = createSignal(initialValue);
50
42
 
51
- // Determine if controlled
52
43
  const isControlled = () => getProps().value !== undefined;
53
44
 
54
- // Get current value
55
45
  const value: Accessor<string> = () => {
56
46
  const p = getProps();
57
- return isControlled() ? (p.value ?? '') : internalValue();
47
+ return isControlled() ? (p.value ?? "") : internalValue();
58
48
  };
59
49
 
60
- // Update value
61
50
  function setValue(newValue: string): void {
62
51
  const p = getProps();
63
52
 
@@ -1,2 +1,6 @@
1
- export { createTextFieldState, type TextFieldStateOptions, type TextFieldState, } from './createTextFieldState';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export {
2
+ createTextFieldState,
3
+ type TextFieldStateOptions,
4
+ type TextFieldState,
5
+ } from "./createTextFieldState";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -2,4 +2,4 @@ export {
2
2
  createTextFieldState,
3
3
  type TextFieldStateOptions,
4
4
  type TextFieldState,
5
- } from './createTextFieldState';
5
+ } from "./createTextFieldState";
@@ -2,66 +2,73 @@
2
2
  * Toast state management for SolidJS
3
3
  * Based on @react-stately/toast useToastState
4
4
  */
5
- import { type Accessor } from 'solid-js';
5
+ import { type Accessor } from "solid-js";
6
6
  export interface ToastOptions {
7
- /** A timeout to automatically close the toast, in milliseconds. */
8
- timeout?: number;
9
- /** The priority of the toast relative to other toasts. */
10
- priority?: number;
11
- /** Handler called when the toast is closed. */
12
- onClose?: () => void;
7
+ /** A timeout to automatically close the toast, in milliseconds. */
8
+ timeout?: number;
9
+ /** The priority of the toast relative to other toasts. */
10
+ priority?: number;
11
+ /** Handler called when the toast is closed. */
12
+ onClose?: () => void;
13
13
  }
14
14
  export interface QueuedToast<T> {
15
- /** The content of the toast. */
16
- content: T;
17
- /** A unique key for the toast. */
18
- key: string;
19
- /** The timer for the toast. */
20
- timer: Timer | null;
21
- /** Whether the toast should be animated. */
22
- animation?: 'entering' | 'exiting' | 'queued';
23
- /** The priority of the toast. */
24
- priority: number;
25
- /** Handler called when the toast is closed. */
26
- onClose?: () => void;
27
- /** The timeout for the toast. */
28
- timeout?: number;
15
+ /** The content of the toast. */
16
+ content: T;
17
+ /** A unique key for the toast. */
18
+ key: string;
19
+ /** The timer for the toast. */
20
+ timer: Timer | null;
21
+ /** Whether the toast should be animated. */
22
+ animation?: "entering" | "exiting" | "queued";
23
+ /** The priority of the toast. */
24
+ priority: number;
25
+ /** Handler called when the toast is closed. */
26
+ onClose?: () => void;
27
+ /** The timeout for the toast. */
28
+ timeout?: number;
29
29
  }
30
30
  export interface ToastQueueOptions {
31
- /** The maximum number of toasts to display at once. */
32
- maxVisibleToasts?: number;
33
- /** Whether toasts should stack (true) or queue (false). */
34
- hasExitAnimation?: boolean;
31
+ /** The maximum number of toasts to display at once. */
32
+ maxVisibleToasts?: number;
33
+ /** Whether toasts should stack (true) or queue (false). */
34
+ hasExitAnimation?: boolean;
35
35
  }
36
36
  export interface ToastStateProps<T> {
37
- /** The toast queue to use. */
38
- queue: ToastQueue<T>;
37
+ /** The toast queue to use. */
38
+ queue: ToastQueue<T>;
39
39
  }
40
40
  export interface ToastState<T> {
41
- /** The currently visible toasts. */
42
- visibleToasts: Accessor<QueuedToast<T>[]>;
43
- /** Adds a toast to the queue. */
44
- add: (content: T, options?: ToastOptions) => string;
45
- /** Closes a toast by key. */
46
- close: (key: string) => void;
47
- /** Pauses all toast timers. */
48
- pauseAll: () => void;
49
- /** Resumes all toast timers. */
50
- resumeAll: () => void;
41
+ /** The currently visible toasts. */
42
+ visibleToasts: Accessor<QueuedToast<T>[]>;
43
+ /** Adds a toast to the queue. */
44
+ add: (content: T, options?: ToastOptions) => string;
45
+ /** Closes a toast by key. Starts exit animation if hasExitAnimation is enabled. */
46
+ close: (key: string) => void;
47
+ /**
48
+ * Removes a toast after exit animation completes.
49
+ * Call this from the component layer when the CSS exit animation finishes.
50
+ */
51
+ remove: (key: string) => void;
52
+ /** Clears all queued and visible toasts. */
53
+ clear: () => void;
54
+ /** Pauses all toast timers. */
55
+ pauseAll: () => void;
56
+ /** Resumes all toast timers. */
57
+ resumeAll: () => void;
51
58
  }
52
59
  /**
53
60
  * A Timer that supports pause and resume.
54
61
  */
55
62
  export declare class Timer {
56
- private timerId;
57
- private startTime;
58
- private remaining;
59
- private callback;
60
- constructor(callback: () => void, delay: number);
61
- pause(): void;
62
- resume(): void;
63
- reset(delay: number): void;
64
- cancel(): void;
63
+ private timerId;
64
+ private startTime;
65
+ private remaining;
66
+ private callback;
67
+ constructor(callback: () => void, delay: number);
68
+ pause(): void;
69
+ resume(): void;
70
+ reset(delay: number): void;
71
+ cancel(): void;
65
72
  }
66
73
  type SubscribeCallback<T> = (toasts: QueuedToast<T>[]) => void;
67
74
  /**
@@ -69,38 +76,42 @@ type SubscribeCallback<T> = (toasts: QueuedToast<T>[]) => void;
69
76
  * Can be created once and shared across the app (singleton pattern).
70
77
  */
71
78
  export declare class ToastQueue<T> {
72
- private queue;
73
- private subscriptions;
74
- private maxVisibleToasts;
75
- private hasExitAnimation;
76
- private keyCounter;
77
- constructor(options?: ToastQueueOptions);
78
- /**
79
- * Subscribe to queue changes.
80
- */
81
- subscribe(callback: SubscribeCallback<T>): () => void;
82
- /**
83
- * Add a toast to the queue.
84
- */
85
- add(content: T, options?: ToastOptions): string;
86
- /**
87
- * Close a toast by key.
88
- */
89
- close(key: string): void;
90
- /**
91
- * Remove a toast after exit animation completes.
92
- */
93
- remove(key: string): void;
94
- /**
95
- * Pause all toast timers.
96
- */
97
- pauseAll(): void;
98
- /**
99
- * Resume all toast timers.
100
- */
101
- resumeAll(): void;
102
- private updateVisibility;
103
- private notify;
79
+ private queue;
80
+ private subscriptions;
81
+ private maxVisibleToasts;
82
+ private hasExitAnimation;
83
+ private keyCounter;
84
+ constructor(options?: ToastQueueOptions);
85
+ /**
86
+ * Subscribe to queue changes.
87
+ */
88
+ subscribe(callback: SubscribeCallback<T>): () => void;
89
+ /**
90
+ * Add a toast to the queue.
91
+ */
92
+ add(content: T, options?: ToastOptions): string;
93
+ /**
94
+ * Close a toast by key.
95
+ */
96
+ close(key: string): void;
97
+ /**
98
+ * Remove a toast after exit animation completes.
99
+ */
100
+ remove(key: string): void;
101
+ /**
102
+ * Clear all queued and visible toasts.
103
+ */
104
+ clear(): void;
105
+ /**
106
+ * Pause all toast timers.
107
+ */
108
+ pauseAll(): void;
109
+ /**
110
+ * Resume all toast timers.
111
+ */
112
+ resumeAll(): void;
113
+ private updateVisibility;
114
+ private notify;
104
115
  }
105
116
  /**
106
117
  * Creates reactive toast state from a ToastQueue.
@@ -112,7 +123,7 @@ export declare function createToastState<T>(props: ToastStateProps<T>): ToastSta
112
123
  * Use this if you don't need a global queue.
113
124
  */
114
125
  export declare function createToastQueue<T>(options?: ToastQueueOptions): ToastState<T> & {
115
- queue: ToastQueue<T>;
126
+ queue: ToastQueue<T>;
116
127
  };
117
- export {};
118
- //# sourceMappingURL=createToastState.d.ts.map
128
+
129
+ //# sourceMappingURL=createToastState.d.ts.map