@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
@@ -6,66 +6,68 @@
6
6
  *
7
7
  * This is a 1:1 port of @react-stately/checkbox's useCheckboxGroupState.
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 CheckboxGroupProps {
12
- /** The current selected values (controlled). */
13
- value?: string[];
14
- /** The default selected values (uncontrolled). */
15
- defaultValue?: string[];
16
- /** Handler that is called when the value changes. */
17
- onChange?: (value: string[]) => void;
18
- /** Whether the checkbox group is disabled. */
19
- isDisabled?: boolean;
20
- /** Whether the checkbox group is read only. */
21
- isReadOnly?: boolean;
22
- /** Whether the checkbox group is required. */
23
- isRequired?: boolean;
24
- /** Whether the checkbox group is invalid. */
25
- isInvalid?: boolean;
26
- /** The name of the checkbox group, used when submitting an HTML form. */
27
- name?: string;
28
- /** The form to associate the checkbox group with. */
29
- form?: string;
30
- /** The label for the checkbox group. */
31
- label?: string;
32
- /** Handler that is called when the checkbox group receives focus. */
33
- onFocus?: (e: FocusEvent) => void;
34
- /** Handler that is called when the checkbox group loses focus. */
35
- onBlur?: (e: FocusEvent) => void;
36
- /** Handler that is called when the checkbox group's focus status changes. */
37
- onFocusChange?: (isFocused: boolean) => void;
12
+ /** The current selected values (controlled). */
13
+ value?: string[];
14
+ /** The default selected values (uncontrolled). */
15
+ defaultValue?: string[];
16
+ /** Handler that is called when the value changes. */
17
+ onChange?: (value: string[]) => void;
18
+ /** Whether the checkbox group is disabled. */
19
+ isDisabled?: boolean;
20
+ /** Whether the checkbox group is read only. */
21
+ isReadOnly?: boolean;
22
+ /** Whether the checkbox group is required. */
23
+ isRequired?: boolean;
24
+ /** Whether the checkbox group is invalid. */
25
+ isInvalid?: boolean;
26
+ /** The name of the checkbox group, used when submitting an HTML form. */
27
+ name?: string;
28
+ /** The form to associate the checkbox group with. */
29
+ form?: string;
30
+ /** The label for the checkbox group. */
31
+ label?: string;
32
+ /** Handler that is called when the checkbox group receives focus. */
33
+ onFocus?: (e: FocusEvent) => void;
34
+ /** Handler that is called when the checkbox group loses focus. */
35
+ onBlur?: (e: FocusEvent) => void;
36
+ /** Handler that is called when the checkbox group's focus status changes. */
37
+ onFocusChange?: (isFocused: boolean) => void;
38
38
  }
39
39
  export interface CheckboxGroupState {
40
- /** Current selected values. */
41
- readonly value: Accessor<readonly string[]>;
42
- /** Default selected values. */
43
- readonly defaultValue: readonly string[];
44
- /** Whether the checkbox group is disabled. */
45
- readonly isDisabled: boolean;
46
- /** Whether the checkbox group is read only. */
47
- readonly isReadOnly: boolean;
48
- /** Whether the checkbox group is invalid. */
49
- readonly isInvalid: boolean;
50
- /**
51
- * Whether the checkboxes in the group are required.
52
- * This changes to false once at least one item is selected.
53
- */
54
- readonly isRequired: Accessor<boolean>;
55
- /** Returns whether the given value is selected. */
56
- isSelected(value: string): boolean;
57
- /** Sets the selected values. */
58
- setValue(value: string[]): void;
59
- /** Adds a value to the set of selected values. */
60
- addValue(value: string): void;
61
- /** Removes a value from the set of selected values. */
62
- removeValue(value: string): void;
63
- /** Toggles a value in the set of selected values. */
64
- toggleValue(value: string): void;
40
+ /** Current selected values. */
41
+ readonly value: Accessor<readonly string[]>;
42
+ /** Default selected values. */
43
+ readonly defaultValue: readonly string[];
44
+ /** Whether the checkbox group is disabled. */
45
+ readonly isDisabled: boolean;
46
+ /** Whether the checkbox group is read only. */
47
+ readonly isReadOnly: boolean;
48
+ /** Whether the checkbox group is invalid. */
49
+ readonly isInvalid: boolean;
50
+ /**
51
+ * Whether the checkboxes in the group are required.
52
+ * This changes to false once at least one item is selected.
53
+ */
54
+ readonly isRequired: Accessor<boolean>;
55
+ /** Returns whether the given value is selected. */
56
+ isSelected(value: string): boolean;
57
+ /** Sets the selected values. */
58
+ setValue(value: string[]): void;
59
+ /** Adds a value to the set of selected values. */
60
+ addValue(value: string): void;
61
+ /** Removes a value from the set of selected values. */
62
+ removeValue(value: string): void;
63
+ /** Toggles a value in the set of selected values. */
64
+ toggleValue(value: string): void;
65
65
  }
66
66
  /**
67
67
  * Provides state management for a checkbox group component.
68
68
  * Provides a name for the group, and manages selection and focus state.
69
69
  */
70
- export declare function createCheckboxGroupState(props?: MaybeAccessor<CheckboxGroupProps>): CheckboxGroupState;
71
- //# sourceMappingURL=createCheckboxGroupState.d.ts.map
70
+ export declare function createCheckboxGroupState(
71
+ props?: MaybeAccessor<CheckboxGroupProps>,
72
+ ): CheckboxGroupState;
73
+ //# sourceMappingURL=createCheckboxGroupState.d.ts.map
@@ -7,18 +7,14 @@
7
7
  * This is a 1:1 port of @react-stately/checkbox's useCheckboxGroupState.
8
8
  */
9
9
 
10
- import { createSignal, Accessor } from 'solid-js';
11
- import { type MaybeAccessor, access } from '../utils';
10
+ import { createMemo, createSignal, Accessor } from "solid-js";
11
+ import { type MaybeAccessor, access } from "../utils";
12
12
  import {
13
13
  createFormValidationState,
14
14
  type FormValidationState,
15
15
  type ValidationFunction,
16
16
  type ValidationResult,
17
- } from '../form';
18
-
19
- // ============================================
20
- // TYPES
21
- // ============================================
17
+ } from "../form";
22
18
 
23
19
  export interface CheckboxGroupProps {
24
20
  /** The current selected values (controlled). */
@@ -48,14 +44,21 @@ export interface CheckboxGroupProps {
48
44
  /** Handler that is called when the checkbox group's focus status changes. */
49
45
  onFocusChange?: (isFocused: boolean) => void;
50
46
  /** Backward-compatible controlled validation state. */
51
- validationState?: 'valid' | 'invalid';
47
+ validationState?: "valid" | "invalid";
52
48
  /** Custom validation function. */
53
49
  validate?: ValidationFunction<readonly string[]>;
54
50
  /** Validation behavior for the checkbox group. */
55
- validationBehavior?: 'aria' | 'native';
51
+ validationBehavior?: "aria" | "native";
56
52
  }
57
53
 
58
- export interface CheckboxGroupState extends Pick<FormValidationState, 'realtimeValidation' | 'displayValidation' | 'updateValidation' | 'resetValidation' | 'commitValidation'> {
54
+ export interface CheckboxGroupState extends Pick<
55
+ FormValidationState,
56
+ | "realtimeValidation"
57
+ | "displayValidation"
58
+ | "updateValidation"
59
+ | "resetValidation"
60
+ | "commitValidation"
61
+ > {
59
62
  /** Current selected values. */
60
63
  readonly value: Accessor<readonly string[]>;
61
64
  /** Default selected values. */
@@ -86,36 +89,29 @@ export interface CheckboxGroupState extends Pick<FormValidationState, 'realtimeV
86
89
  readonly displayValidation: Accessor<ValidationResult>;
87
90
  }
88
91
 
89
- // ============================================
90
- // IMPLEMENTATION
91
- // ============================================
92
-
93
92
  /**
94
93
  * Provides state management for a checkbox group component.
95
94
  * Provides a name for the group, and manages selection and focus state.
96
95
  */
97
96
  export function createCheckboxGroupState(
98
- props: MaybeAccessor<CheckboxGroupProps> = {}
97
+ props: MaybeAccessor<CheckboxGroupProps> = {},
99
98
  ): CheckboxGroupState {
100
99
  const getProps = () => access(props);
101
100
 
102
- // Get initial values
103
101
  const initialProps = getProps();
104
102
  const initialValue = initialProps.value ?? initialProps.defaultValue ?? [];
105
103
 
106
- // Create internal signal for uncontrolled mode
107
104
  const [internalValue, setInternalValue] = createSignal<readonly string[]>(initialValue);
108
105
 
109
- // Determine if controlled
110
- const isControlled = () => getProps().value !== undefined;
106
+ const controlledValue = createMemo<readonly string[] | undefined>(() => getProps().value);
107
+
108
+ const isControlled = () => controlledValue() !== undefined;
111
109
 
112
- // Get current value
113
110
  const value: Accessor<readonly string[]> = () => {
114
- const p = getProps();
115
- return isControlled() ? (p.value ?? []) : internalValue();
111
+ const controlled = controlledValue();
112
+ return controlled !== undefined ? controlled : internalValue();
116
113
  };
117
114
 
118
- // Check if required (true if isRequired and no items selected)
119
115
  const isRequired: Accessor<boolean> = () => {
120
116
  const p = getProps();
121
117
  return !!p.isRequired && value().length === 0;
@@ -135,14 +131,13 @@ export function createCheckboxGroupState(
135
131
  return getProps().validate;
136
132
  },
137
133
  get validationBehavior() {
138
- return getProps().validationBehavior ?? 'aria';
134
+ return getProps().validationBehavior ?? "native";
139
135
  },
140
136
  get name() {
141
137
  return getProps().name;
142
138
  },
143
139
  });
144
140
 
145
- // Set value
146
141
  function setValue(newValue: string[]): void {
147
142
  const p = getProps();
148
143
  if (p.isReadOnly || p.isDisabled) {
@@ -156,12 +151,10 @@ export function createCheckboxGroupState(
156
151
  p.onChange?.(newValue);
157
152
  }
158
153
 
159
- // Check if value is selected
160
154
  function isSelected(checkValue: string): boolean {
161
155
  return value().includes(checkValue);
162
156
  }
163
157
 
164
- // Add value
165
158
  function addValue(addVal: string): void {
166
159
  const p = getProps();
167
160
  if (p.isReadOnly || p.isDisabled) {
@@ -174,7 +167,6 @@ export function createCheckboxGroupState(
174
167
  }
175
168
  }
176
169
 
177
- // Remove value
178
170
  function removeValue(removeVal: string): void {
179
171
  const p = getProps();
180
172
  if (p.isReadOnly || p.isDisabled) {
@@ -187,7 +179,6 @@ export function createCheckboxGroupState(
187
179
  }
188
180
  }
189
181
 
190
- // Toggle value
191
182
  function toggleValue(toggleVal: string): void {
192
183
  const p = getProps();
193
184
  if (p.isReadOnly || p.isDisabled) {
@@ -1,2 +1,6 @@
1
- export { createCheckboxGroupState, type CheckboxGroupProps, type CheckboxGroupState, } from './createCheckboxGroupState';
2
- //# sourceMappingURL=index.d.ts.map
1
+ export {
2
+ createCheckboxGroupState,
3
+ type CheckboxGroupProps,
4
+ type CheckboxGroupState,
5
+ } from "./createCheckboxGroupState";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -2,4 +2,4 @@ export {
2
2
  createCheckboxGroupState,
3
3
  type CheckboxGroupProps,
4
4
  type CheckboxGroupState,
5
- } from './createCheckboxGroupState';
5
+ } from "./createCheckboxGroupState";
@@ -2,36 +2,39 @@
2
2
  * A simple list collection implementation.
3
3
  * Provides a Collection interface over an array of nodes.
4
4
  */
5
- import type { Collection, CollectionNode, Key } from './types';
5
+ import type { Collection, CollectionNode, Key } from "./types";
6
6
  /**
7
7
  * A basic implementation of Collection for list-based components.
8
8
  */
9
9
  export declare class ListCollection<T = unknown> implements Collection<T> {
10
- private nodes;
11
- private keyMap;
12
- constructor(nodes: CollectionNode<T>[]);
13
- get size(): number;
14
- [Symbol.iterator](): Iterator<CollectionNode<T>>;
15
- getKeys(): Iterable<Key>;
16
- getItem(key: Key): CollectionNode<T> | null;
17
- at(index: number): CollectionNode<T> | null;
18
- getKeyBefore(key: Key): Key | null;
19
- getKeyAfter(key: Key): Key | null;
20
- getFirstKey(): Key | null;
21
- getLastKey(): Key | null;
22
- getChildren(key: Key): Iterable<CollectionNode<T>>;
23
- getTextValue(key: Key): string;
24
- /**
25
- * Get all items (excluding sections, including items within sections).
26
- */
27
- private getAllItems;
10
+ private nodes;
11
+ private keyMap;
12
+ constructor(nodes: CollectionNode<T>[]);
13
+ get size(): number;
14
+ [Symbol.iterator](): Iterator<CollectionNode<T>>;
15
+ getKeys(): Iterable<Key>;
16
+ getItem(key: Key): CollectionNode<T> | null;
17
+ at(index: number): CollectionNode<T> | null;
18
+ getKeyBefore(key: Key): Key | null;
19
+ getKeyAfter(key: Key): Key | null;
20
+ getFirstKey(): Key | null;
21
+ getLastKey(): Key | null;
22
+ getChildren(key: Key): Iterable<CollectionNode<T>>;
23
+ getTextValue(key: Key): string;
24
+ /**
25
+ * Get all items (excluding sections, including items within sections).
26
+ */
27
+ private getAllItems;
28
28
  }
29
29
  /**
30
30
  * Create a collection from an array of items.
31
31
  */
32
- export declare function createListCollection<T>(items: T[], options?: {
32
+ export declare function createListCollection<T>(
33
+ items: T[],
34
+ options?: {
33
35
  getKey?: (item: T, index: number) => Key;
34
36
  getTextValue?: (item: T) => string;
35
37
  getDisabled?: (item: T) => boolean;
36
- }): ListCollection<T>;
37
- //# sourceMappingURL=ListCollection.d.ts.map
38
+ },
39
+ ): ListCollection<T>;
40
+ //# sourceMappingURL=ListCollection.d.ts.map
@@ -3,7 +3,7 @@
3
3
  * Provides a Collection interface over an array of nodes.
4
4
  */
5
5
 
6
- import type { Collection, CollectionItemLike, CollectionNode, Key } from './types';
6
+ import type { Collection, CollectionItemLike, CollectionNode, Key } from "./types";
7
7
 
8
8
  /**
9
9
  * A basic implementation of Collection for list-based components.
@@ -87,7 +87,7 @@ export class ListCollection<T = unknown> implements Collection<T> {
87
87
  }
88
88
 
89
89
  getTextValue(key: Key): string {
90
- return this.getItem(key)?.textValue ?? '';
90
+ return this.getItem(key)?.textValue ?? "";
91
91
  }
92
92
 
93
93
  /**
@@ -98,9 +98,9 @@ export class ListCollection<T = unknown> implements Collection<T> {
98
98
 
99
99
  const addItems = (nodes: CollectionNode<T>[]) => {
100
100
  for (const node of nodes) {
101
- if (node.type === 'item') {
101
+ if (node.type === "item") {
102
102
  items.push(node);
103
- } else if (node.type === 'section' && node.childNodes) {
103
+ } else if (node.type === "section" && node.childNodes) {
104
104
  addItems(node.childNodes);
105
105
  }
106
106
  }
@@ -120,7 +120,7 @@ export function createListCollection<T>(
120
120
  getKey?: (item: T, index: number) => Key;
121
121
  getTextValue?: (item: T) => string;
122
122
  getDisabled?: (item: T) => boolean;
123
- } = {}
123
+ } = {},
124
124
  ): ListCollection<T> {
125
125
  const {
126
126
  getKey = (item: T, index: number) => {
@@ -135,7 +135,7 @@ export function createListCollection<T>(
135
135
  } = options;
136
136
 
137
137
  const nodes: CollectionNode<T>[] = items.map((item, index) => ({
138
- type: 'item' as const,
138
+ type: "item" as const,
139
139
  key: getKey(item, index),
140
140
  value: item,
141
141
  textValue: getTextValue(item),
@@ -3,77 +3,92 @@
3
3
  * Combines collection and selection state.
4
4
  * Based on @react-stately/list.
5
5
  */
6
- import { type Accessor } from 'solid-js';
7
- import { type MaybeAccessor } from '../utils';
8
- import { type SelectionState } from './createSelectionState';
9
- import type { Collection, CollectionNode, DisabledBehavior, FocusStrategy, Key, SelectionBehavior, SelectionMode } from './types';
6
+ import { type Accessor } from "solid-js";
7
+ import { type MaybeAccessor } from "../utils";
8
+ import { type SelectionState } from "./createSelectionState";
9
+ import type {
10
+ Collection,
11
+ CollectionNode,
12
+ DisabledBehavior,
13
+ FocusStrategy,
14
+ Key,
15
+ SelectionBehavior,
16
+ SelectionMode,
17
+ } from "./types";
10
18
  export interface ListStateProps<T = unknown> {
11
- /** The items in the list (for dynamic rendering). */
12
- items?: T[];
13
- /** Function to get a key from an item. */
14
- getKey?: (item: T) => Key;
15
- /** Function to get text value from an item. */
16
- getTextValue?: (item: T) => string;
17
- /** Function to check if an item is disabled. */
18
- getDisabled?: (item: T) => boolean;
19
- /** Keys of disabled items. */
20
- disabledKeys?: Iterable<Key>;
21
- /** How disabled keys behave. */
22
- disabledBehavior?: DisabledBehavior;
23
- /** The selection mode. */
24
- selectionMode?: SelectionMode;
25
- /** How selection behaves on interaction. */
26
- selectionBehavior?: SelectionBehavior;
27
- /** Whether empty selection is disallowed. */
28
- disallowEmptySelection?: boolean;
29
- /** Currently selected keys (controlled). */
30
- selectedKeys?: 'all' | Iterable<Key>;
31
- /** Default selected keys (uncontrolled). */
32
- defaultSelectedKeys?: 'all' | Iterable<Key>;
33
- /** Handler for selection changes. */
34
- onSelectionChange?: (keys: 'all' | Set<Key>) => void;
35
- /** Whether to allow duplicate selection events. */
36
- allowDuplicateSelectionEvents?: boolean;
19
+ /** The items in the list (for dynamic rendering). */
20
+ items?: T[];
21
+ /** Function to get a key from an item. */
22
+ getKey?: (item: T) => Key;
23
+ /** Function to get text value from an item. */
24
+ getTextValue?: (item: T) => string;
25
+ /** Function to check if an item is disabled. */
26
+ getDisabled?: (item: T) => boolean;
27
+ /** Keys of disabled items. */
28
+ disabledKeys?: Iterable<Key>;
29
+ /** How disabled keys behave. */
30
+ disabledBehavior?: DisabledBehavior;
31
+ /** The selection mode. */
32
+ selectionMode?: SelectionMode;
33
+ /** How selection behaves on interaction. */
34
+ selectionBehavior?: SelectionBehavior;
35
+ /** Whether empty selection is disallowed. */
36
+ disallowEmptySelection?: boolean;
37
+ /** Currently selected keys (controlled). */
38
+ selectedKeys?: "all" | Iterable<Key>;
39
+ /** Default selected keys (uncontrolled). */
40
+ defaultSelectedKeys?: "all" | Iterable<Key>;
41
+ /** Handler for selection changes. */
42
+ onSelectionChange?: (keys: "all" | Set<Key>) => void;
43
+ /** Whether to allow duplicate selection events. */
44
+ allowDuplicateSelectionEvents?: boolean;
37
45
  }
38
46
  export interface ListState<T = unknown> extends SelectionState {
39
- /** The collection of items. */
40
- readonly collection: Accessor<Collection<T>>;
41
- /** Whether the collection is focused. */
42
- readonly isFocused: Accessor<boolean>;
43
- /** Set the focused state. */
44
- setFocused(isFocused: boolean): void;
45
- /** The currently focused key. */
46
- readonly focusedKey: Accessor<Key | null>;
47
- /** Set the focused key. */
48
- setFocusedKey(key: Key | null, childStrategy?: FocusStrategy): void;
49
- /** The child focus strategy. */
50
- readonly childFocusStrategy: Accessor<FocusStrategy | null>;
47
+ /** The collection of items. */
48
+ readonly collection: Accessor<Collection<T>>;
49
+ /** Whether the collection is focused. */
50
+ readonly isFocused: Accessor<boolean>;
51
+ /** Set the focused state. */
52
+ setFocused(isFocused: boolean): void;
53
+ /** The currently focused key. */
54
+ readonly focusedKey: Accessor<Key | null>;
55
+ /** Set the focused key. */
56
+ setFocusedKey(key: Key | null, childStrategy?: FocusStrategy): void;
57
+ /** The child focus strategy. */
58
+ readonly childFocusStrategy: Accessor<FocusStrategy | null>;
51
59
  }
52
60
  /**
53
61
  * Creates state for a list component with selection.
54
62
  */
55
- export declare function createListState<T = unknown>(props: MaybeAccessor<ListStateProps<T>>): ListState<T>;
63
+ export declare function createListState<T = unknown>(
64
+ props: MaybeAccessor<ListStateProps<T>>,
65
+ ): ListState<T>;
56
66
  /**
57
67
  * Props for single selection list state.
58
68
  */
59
- export interface SingleSelectListStateProps<T = unknown> extends Omit<ListStateProps<T>, 'selectionMode' | 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange'> {
60
- /** The currently selected key (controlled). */
61
- selectedKey?: Key | null;
62
- /** The default selected key (uncontrolled). */
63
- defaultSelectedKey?: Key;
64
- /** Handler for selection changes. */
65
- onSelectionChange?: (key: Key | null) => void;
69
+ export interface SingleSelectListStateProps<T = unknown> extends Omit<
70
+ ListStateProps<T>,
71
+ "selectionMode" | "selectedKeys" | "defaultSelectedKeys" | "onSelectionChange"
72
+ > {
73
+ /** The currently selected key (controlled). */
74
+ selectedKey?: Key | null;
75
+ /** The default selected key (uncontrolled). */
76
+ defaultSelectedKey?: Key;
77
+ /** Handler for selection changes. */
78
+ onSelectionChange?: (key: Key | null) => void;
66
79
  }
67
80
  export interface SingleSelectListState<T = unknown> extends ListState<T> {
68
- /** The currently selected key. */
69
- readonly selectedKey: Accessor<Key | null>;
70
- /** Set the selected key. */
71
- setSelectedKey(key: Key | null): void;
72
- /** The currently selected item. */
73
- readonly selectedItem: Accessor<CollectionNode<T> | null>;
81
+ /** The currently selected key. */
82
+ readonly selectedKey: Accessor<Key | null>;
83
+ /** Set the selected key. */
84
+ setSelectedKey(key: Key | null): void;
85
+ /** The currently selected item. */
86
+ readonly selectedItem: Accessor<CollectionNode<T> | null>;
74
87
  }
75
88
  /**
76
89
  * Creates state for a single-select list component.
77
90
  */
78
- export declare function createSingleSelectListState<T = unknown>(props: MaybeAccessor<SingleSelectListStateProps<T>>): SingleSelectListState<T>;
79
- //# sourceMappingURL=createListState.d.ts.map
91
+ export declare function createSingleSelectListState<T = unknown>(
92
+ props: MaybeAccessor<SingleSelectListStateProps<T>>,
93
+ ): SingleSelectListState<T>;
94
+ //# sourceMappingURL=createListState.d.ts.map
@@ -4,10 +4,10 @@
4
4
  * Based on @react-stately/list.
5
5
  */
6
6
 
7
- import { createSignal, createMemo, type Accessor } from 'solid-js';
8
- import { access, type MaybeAccessor } from '../utils';
9
- import { ListCollection } from './ListCollection';
10
- import { createSelectionState, type SelectionState } from './createSelectionState';
7
+ import { createSignal, createMemo, type Accessor } from "solid-js";
8
+ import { access, type MaybeAccessor } from "../utils";
9
+ import { ListCollection } from "./ListCollection";
10
+ import { createSelectionState, type SelectionState } from "./createSelectionState";
11
11
  import type {
12
12
  Collection,
13
13
  CollectionItemLike,
@@ -17,7 +17,7 @@ import type {
17
17
  Key,
18
18
  SelectionBehavior,
19
19
  SelectionMode,
20
- } from './types';
20
+ } from "./types";
21
21
 
22
22
  export interface ListStateProps<T = unknown> {
23
23
  /** The items in the list (for dynamic rendering). */
@@ -39,11 +39,11 @@ export interface ListStateProps<T = unknown> {
39
39
  /** Whether empty selection is disallowed. */
40
40
  disallowEmptySelection?: boolean;
41
41
  /** Currently selected keys (controlled). */
42
- selectedKeys?: 'all' | Iterable<Key>;
42
+ selectedKeys?: "all" | Iterable<Key>;
43
43
  /** Default selected keys (uncontrolled). */
44
- defaultSelectedKeys?: 'all' | Iterable<Key>;
44
+ defaultSelectedKeys?: "all" | Iterable<Key>;
45
45
  /** Handler for selection changes. */
46
- onSelectionChange?: (keys: 'all' | Set<Key>) => void;
46
+ onSelectionChange?: (keys: "all" | Set<Key>) => void;
47
47
  /** Whether to allow duplicate selection events. */
48
48
  allowDuplicateSelectionEvents?: boolean;
49
49
  }
@@ -67,7 +67,7 @@ export interface ListState<T = unknown> extends SelectionState {
67
67
  * Creates state for a list component with selection.
68
68
  */
69
69
  export function createListState<T = unknown>(
70
- props: MaybeAccessor<ListStateProps<T>>
70
+ props: MaybeAccessor<ListStateProps<T>>,
71
71
  ): ListState<T> {
72
72
  const getProps = () => access(props);
73
73
 
@@ -79,12 +79,11 @@ export function createListState<T = unknown>(
79
79
  const nodes: CollectionNode<T>[] = items.map((item, index) => {
80
80
  const o = item as CollectionItemLike;
81
81
  const key = p.getKey?.(item) ?? o.key ?? o.id ?? index;
82
- const textValue =
83
- p.getTextValue?.(item) ?? o.textValue ?? o.label ?? String(item);
82
+ const textValue = p.getTextValue?.(item) ?? o.textValue ?? o.label ?? String(item);
84
83
  const isDisabled = p.getDisabled?.(item) ?? o.isDisabled ?? false;
85
84
 
86
85
  return {
87
- type: 'item' as const,
86
+ type: "item" as const,
88
87
  key,
89
88
  value: item,
90
89
  textValue,
@@ -172,8 +171,10 @@ export function createListState<T = unknown>(
172
171
  /**
173
172
  * Props for single selection list state.
174
173
  */
175
- export interface SingleSelectListStateProps<T = unknown>
176
- extends Omit<ListStateProps<T>, 'selectionMode' | 'selectedKeys' | 'defaultSelectedKeys' | 'onSelectionChange'> {
174
+ export interface SingleSelectListStateProps<T = unknown> extends Omit<
175
+ ListStateProps<T>,
176
+ "selectionMode" | "selectedKeys" | "defaultSelectedKeys" | "onSelectionChange"
177
+ > {
177
178
  /** The currently selected key (controlled). */
178
179
  selectedKey?: Key | null;
179
180
  /** The default selected key (uncontrolled). */
@@ -195,7 +196,7 @@ export interface SingleSelectListState<T = unknown> extends ListState<T> {
195
196
  * Creates state for a single-select list component.
196
197
  */
197
198
  export function createSingleSelectListState<T = unknown>(
198
- props: MaybeAccessor<SingleSelectListStateProps<T>>
199
+ props: MaybeAccessor<SingleSelectListStateProps<T>>,
199
200
  ): SingleSelectListState<T> {
200
201
  const getProps = () => access(props);
201
202
 
@@ -219,7 +220,7 @@ export function createSingleSelectListState<T = unknown>(
219
220
  get disabledBehavior() {
220
221
  return getProps().disabledBehavior;
221
222
  },
222
- selectionMode: 'single',
223
+ selectionMode: "single",
223
224
  disallowEmptySelection: true,
224
225
  allowDuplicateSelectionEvents: true,
225
226
  get selectedKeys() {
@@ -231,7 +232,7 @@ export function createSingleSelectListState<T = unknown>(
231
232
  return key != null ? [key] : undefined;
232
233
  },
233
234
  onSelectionChange(keys) {
234
- if (keys === 'all') return;
235
+ if (keys === "all") return;
235
236
  const key = keys.values().next().value ?? null;
236
237
  getProps().onSelectionChange?.(key);
237
238
  },
@@ -239,7 +240,7 @@ export function createSingleSelectListState<T = unknown>(
239
240
 
240
241
  const selectedKey: Accessor<Key | null> = () => {
241
242
  const keys = listState.selectedKeys();
242
- if (keys === 'all') return null;
243
+ if (keys === "all") return null;
243
244
  return keys.values().next().value ?? null;
244
245
  };
245
246