@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.
- package/LICENSE +21 -0
- package/README.md +30 -283
- package/dist/autocomplete/createAutocompleteState.d.ts +3 -2
- package/dist/autocomplete/index.d.ts +1 -1
- package/dist/calendar/createCalendarState.d.ts +22 -7
- package/dist/calendar/createDateFieldState.d.ts +30 -7
- package/dist/calendar/createDatePickerState.d.ts +60 -0
- package/dist/calendar/createRangeCalendarState.d.ts +27 -8
- package/dist/calendar/createTimeFieldState.d.ts +34 -7
- package/dist/calendar/index.d.ts +7 -6
- package/dist/checkbox/createCheckboxGroupState.d.ts +12 -3
- package/dist/checkbox/index.d.ts +1 -1
- package/dist/collections/ListCollection.d.ts +1 -1
- package/dist/collections/createListState.d.ts +8 -8
- package/dist/collections/createMenuState.d.ts +7 -7
- package/dist/collections/createSelectionState.d.ts +5 -5
- package/dist/collections/index.d.ts +5 -5
- package/dist/collections/types.d.ts +23 -12
- package/dist/color/Color.d.ts +1 -1
- package/dist/color/createColorAreaState.d.ts +4 -2
- package/dist/color/createColorFieldState.d.ts +38 -12
- package/dist/color/createColorSliderState.d.ts +9 -2
- package/dist/color/createColorWheelState.d.ts +13 -2
- package/dist/color/getColorChannels.d.ts +20 -0
- package/dist/color/index.d.ts +6 -6
- package/dist/color/types.d.ts +4 -4
- package/dist/combobox/createComboBoxState.d.ts +27 -13
- package/dist/combobox/index.d.ts +1 -1
- package/dist/data/createAsyncList.d.ts +111 -0
- package/dist/data/createListData.d.ts +65 -0
- package/dist/data/createTreeData.d.ts +65 -0
- package/dist/data/index.d.ts +3 -0
- package/dist/datepicker/index.d.ts +8 -0
- package/dist/disclosure/createDisclosureState.d.ts +2 -2
- package/dist/disclosure/index.d.ts +1 -1
- package/dist/dnd/createDragState.d.ts +2 -2
- package/dist/dnd/createDraggableCollectionState.d.ts +2 -2
- package/dist/dnd/createDropState.d.ts +2 -2
- package/dist/dnd/createDroppableCollectionState.d.ts +3 -3
- package/dist/dnd/index.d.ts +5 -5
- package/dist/dnd/types.d.ts +16 -16
- package/dist/form/createFormValidationState.d.ts +3 -3
- package/dist/form/index.d.ts +1 -1
- package/dist/grid/createGridState.d.ts +2 -2
- package/dist/grid/index.d.ts +2 -2
- package/dist/grid/types.d.ts +17 -11
- package/dist/index.d.ts +31 -25
- package/dist/index.js +7990 -6264
- package/dist/index.js.map +1 -7
- package/dist/menu/index.d.ts +8 -0
- package/dist/numberfield/createNumberFieldState.d.ts +2 -2
- package/dist/numberfield/index.d.ts +1 -1
- package/dist/overlays/createOverlayTriggerState.d.ts +2 -2
- package/dist/overlays/index.d.ts +1 -1
- package/dist/radio/createRadioGroupState.d.ts +13 -4
- package/dist/radio/index.d.ts +1 -1
- package/dist/searchfield/createSearchFieldState.d.ts +2 -2
- package/dist/searchfield/index.d.ts +2 -2
- package/dist/select/createSelectState.d.ts +20 -3
- package/dist/select/index.d.ts +1 -1
- package/dist/selection/index.d.ts +11 -0
- package/dist/slider/createSliderState.d.ts +3 -3
- package/dist/slider/index.d.ts +2 -2
- package/dist/steplist/createStepListState.d.ts +48 -0
- package/dist/steplist/index.d.ts +1 -0
- package/dist/table/TableCollection.d.ts +3 -3
- package/dist/table/createTableColumnResizeState.d.ts +54 -0
- package/dist/table/createTableState.d.ts +2 -2
- package/dist/table/index.d.ts +5 -3
- package/dist/table/types.d.ts +10 -10
- package/dist/tabs/createTabListState.d.ts +5 -5
- package/dist/tabs/index.d.ts +1 -1
- package/dist/textfield/createTextFieldState.d.ts +2 -2
- package/dist/textfield/index.d.ts +1 -1
- package/dist/toast/createToastState.d.ts +15 -3
- package/dist/toast/index.d.ts +1 -1
- package/dist/toggle/createToggleGroupState.d.ts +45 -0
- package/dist/toggle/createToggleState.d.ts +2 -2
- package/dist/toggle/index.d.ts +2 -1
- package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
- package/dist/tooltip/index.d.ts +1 -1
- package/dist/tree/TreeCollection.d.ts +5 -4
- package/dist/tree/createTreeState.d.ts +2 -2
- package/dist/tree/index.d.ts +3 -3
- package/dist/tree/types.d.ts +19 -13
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/reactivity.d.ts +1 -1
- package/package.json +30 -30
- package/src/autocomplete/createAutocompleteState.d.ts +19 -17
- package/src/autocomplete/createAutocompleteState.ts +25 -32
- package/src/autocomplete/index.d.ts +6 -2
- package/src/autocomplete/index.ts +1 -1
- package/src/calendar/createCalendarState.d.ts +139 -117
- package/src/calendar/createCalendarState.ts +221 -74
- package/src/calendar/createDateFieldState.d.ts +130 -95
- package/src/calendar/createDateFieldState.ts +286 -151
- package/src/calendar/createDatePickerState.ts +347 -0
- package/src/calendar/createRangeCalendarState.d.ts +154 -129
- package/src/calendar/createRangeCalendarState.ts +293 -79
- package/src/calendar/createTimeFieldState.d.ts +81 -79
- package/src/calendar/createTimeFieldState.ts +187 -108
- package/src/calendar/index.d.ts +80 -7
- package/src/calendar/index.ts +21 -12
- package/src/checkbox/createCheckboxGroupState.d.ts +57 -55
- package/src/checkbox/createCheckboxGroupState.ts +57 -30
- package/src/checkbox/index.d.ts +6 -2
- package/src/checkbox/index.ts +1 -1
- package/src/collections/ListCollection.d.ts +25 -22
- package/src/collections/ListCollection.ts +152 -146
- package/src/collections/createListState.d.ts +73 -58
- package/src/collections/createListState.ts +267 -264
- package/src/collections/createMenuState.d.ts +36 -31
- package/src/collections/createMenuState.ts +112 -106
- package/src/collections/createSelectionState.d.ts +78 -65
- package/src/collections/createSelectionState.ts +340 -336
- package/src/collections/index.d.ts +38 -6
- package/src/collections/index.ts +41 -46
- package/src/collections/types.d.ts +101 -101
- package/src/collections/types.ts +181 -169
- package/src/color/Color.d.ts +20 -5
- package/src/color/Color.ts +1054 -951
- package/src/color/createColorAreaState.d.ts +67 -65
- package/src/color/createColorAreaState.ts +301 -293
- package/src/color/createColorFieldState.d.ts +46 -44
- package/src/color/createColorFieldState.ts +428 -292
- package/src/color/createColorSliderState.d.ts +58 -56
- package/src/color/createColorSliderState.ts +272 -241
- package/src/color/createColorWheelState.d.ts +42 -40
- package/src/color/createColorWheelState.ts +248 -211
- package/src/color/getColorChannels.ts +36 -0
- package/src/color/index.d.ts +36 -7
- package/src/color/index.ts +44 -47
- package/src/color/types.d.ts +68 -63
- package/src/color/types.ts +119 -127
- package/src/combobox/createComboBoxState.d.ts +107 -105
- package/src/combobox/createComboBoxState.ts +790 -703
- package/src/combobox/index.d.ts +10 -2
- package/src/combobox/index.ts +13 -13
- package/src/data/createAsyncList.ts +403 -0
- package/src/data/createListData.ts +298 -0
- package/src/data/createTreeData.ts +646 -0
- package/src/data/index.ts +25 -0
- package/src/datepicker/index.ts +32 -0
- package/src/disclosure/createDisclosureState.d.ts +47 -43
- package/src/disclosure/createDisclosureState.ts +9 -23
- package/src/disclosure/index.d.ts +10 -2
- package/src/disclosure/index.ts +1 -1
- package/src/dnd/createDragState.d.ts +51 -42
- package/src/dnd/createDragState.ts +151 -153
- package/src/dnd/createDraggableCollectionState.d.ts +52 -41
- package/src/dnd/createDraggableCollectionState.ts +158 -165
- package/src/dnd/createDropState.d.ts +64 -45
- package/src/dnd/createDropState.ts +202 -212
- package/src/dnd/createDroppableCollectionState.d.ts +88 -59
- package/src/dnd/createDroppableCollectionState.ts +354 -357
- package/src/dnd/index.d.ts +54 -6
- package/src/dnd/index.ts +63 -76
- package/src/dnd/types.d.ts +167 -156
- package/src/dnd/types.ts +316 -317
- package/src/form/createFormValidationState.d.ts +47 -45
- package/src/form/createFormValidationState.ts +356 -389
- package/src/form/index.d.ts +16 -2
- package/src/form/index.ts +15 -15
- package/src/grid/createGridState.d.ts +7 -4
- package/src/grid/createGridState.ts +44 -51
- package/src/grid/index.d.ts +3 -3
- package/src/grid/index.ts +2 -8
- package/src/grid/types.d.ts +136 -129
- package/src/grid/types.ts +24 -17
- package/src/index.d.ts +310 -26
- package/src/index.ts +87 -79
- package/src/menu/index.ts +17 -0
- package/src/numberfield/createNumberFieldState.d.ts +56 -54
- package/src/numberfield/createNumberFieldState.ts +422 -383
- package/src/numberfield/index.d.ts +6 -2
- package/src/numberfield/index.ts +5 -5
- package/src/overlays/createOverlayTriggerState.d.ts +22 -20
- package/src/overlays/createOverlayTriggerState.ts +66 -67
- package/src/overlays/index.d.ts +6 -2
- package/src/overlays/index.ts +5 -5
- package/src/radio/createRadioGroupState.d.ts +54 -52
- package/src/radio/createRadioGroupState.ts +66 -30
- package/src/radio/index.d.ts +7 -2
- package/src/radio/index.ts +1 -1
- package/src/searchfield/createSearchFieldState.d.ts +16 -14
- package/src/searchfield/createSearchFieldState.ts +56 -62
- package/src/searchfield/index.d.ts +3 -3
- package/src/searchfield/index.ts +2 -5
- package/src/select/createSelectState.d.ts +63 -61
- package/src/select/createSelectState.ts +290 -181
- package/src/select/index.d.ts +2 -2
- package/src/select/index.ts +1 -5
- package/src/selection/index.ts +27 -0
- package/src/slider/createSliderState.d.ts +60 -60
- package/src/slider/createSliderState.ts +233 -211
- package/src/slider/index.d.ts +3 -3
- package/src/slider/index.ts +2 -6
- package/src/ssr/index.d.ts +1 -1
- package/src/ssr/index.ts +2 -2
- package/src/steplist/createStepListState.ts +191 -0
- package/src/steplist/index.ts +5 -0
- package/src/table/TableCollection.d.ts +42 -40
- package/src/table/TableCollection.ts +61 -64
- package/src/table/createTableColumnResizeState.ts +242 -0
- package/src/table/createTableState.d.ts +7 -4
- package/src/table/createTableState.ts +10 -7
- package/src/table/index.d.ts +14 -4
- package/src/table/index.ts +10 -3
- package/src/table/types.d.ts +98 -92
- package/src/table/types.ts +17 -13
- package/src/tabs/createTabListState.d.ts +59 -57
- package/src/tabs/createTabListState.ts +58 -39
- package/src/tabs/index.d.ts +8 -2
- package/src/tabs/index.ts +1 -1
- package/src/textfield/createTextFieldState.d.ts +16 -14
- package/src/textfield/createTextFieldState.ts +7 -18
- package/src/textfield/index.d.ts +6 -2
- package/src/textfield/index.ts +1 -1
- package/src/toast/createToastState.d.ts +92 -81
- package/src/toast/createToastState.ts +56 -44
- package/src/toast/index.d.ts +12 -2
- package/src/toast/index.ts +1 -1
- package/src/toggle/createToggleGroupState.ts +117 -0
- package/src/toggle/createToggleState.d.ts +19 -19
- package/src/toggle/createToggleState.ts +2 -16
- package/src/toggle/index.d.ts +2 -2
- package/src/toggle/index.ts +6 -4
- package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
- package/src/tooltip/createTooltipTriggerState.ts +184 -183
- package/src/tooltip/index.d.ts +7 -2
- package/src/tooltip/index.ts +6 -6
- package/src/tree/TreeCollection.d.ts +26 -23
- package/src/tree/TreeCollection.ts +215 -175
- package/src/tree/createTreeState.d.ts +7 -4
- package/src/tree/createTreeState.ts +390 -392
- package/src/tree/index.d.ts +10 -4
- package/src/tree/index.ts +13 -13
- package/src/tree/types.d.ts +131 -126
- package/src/tree/types.ts +183 -174
- package/src/utils/index.d.ts +2 -2
- package/src/utils/index.ts +1 -1
- package/src/utils/reactivity.d.ts +2 -2
- 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
|
|
10
|
-
import { type MaybeAccessor } from
|
|
9
|
+
import { Accessor } from "solid-js";
|
|
10
|
+
import { type MaybeAccessor } from "../utils";
|
|
11
11
|
export interface CheckboxGroupProps {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
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
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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(
|
|
71
|
-
|
|
70
|
+
export declare function createCheckboxGroupState(
|
|
71
|
+
props?: MaybeAccessor<CheckboxGroupProps>,
|
|
72
|
+
): CheckboxGroupState;
|
|
73
|
+
//# sourceMappingURL=createCheckboxGroupState.d.ts.map
|
|
@@ -7,12 +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
|
|
11
|
-
import { type MaybeAccessor, access } from
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
10
|
+
import { createMemo, createSignal, Accessor } from "solid-js";
|
|
11
|
+
import { type MaybeAccessor, access } from "../utils";
|
|
12
|
+
import {
|
|
13
|
+
createFormValidationState,
|
|
14
|
+
type FormValidationState,
|
|
15
|
+
type ValidationFunction,
|
|
16
|
+
type ValidationResult,
|
|
17
|
+
} from "../form";
|
|
16
18
|
|
|
17
19
|
export interface CheckboxGroupProps {
|
|
18
20
|
/** The current selected values (controlled). */
|
|
@@ -41,9 +43,22 @@ export interface CheckboxGroupProps {
|
|
|
41
43
|
onBlur?: (e: FocusEvent) => void;
|
|
42
44
|
/** Handler that is called when the checkbox group's focus status changes. */
|
|
43
45
|
onFocusChange?: (isFocused: boolean) => void;
|
|
46
|
+
/** Backward-compatible controlled validation state. */
|
|
47
|
+
validationState?: "valid" | "invalid";
|
|
48
|
+
/** Custom validation function. */
|
|
49
|
+
validate?: ValidationFunction<readonly string[]>;
|
|
50
|
+
/** Validation behavior for the checkbox group. */
|
|
51
|
+
validationBehavior?: "aria" | "native";
|
|
44
52
|
}
|
|
45
53
|
|
|
46
|
-
export interface CheckboxGroupState
|
|
54
|
+
export interface CheckboxGroupState extends Pick<
|
|
55
|
+
FormValidationState,
|
|
56
|
+
| "realtimeValidation"
|
|
57
|
+
| "displayValidation"
|
|
58
|
+
| "updateValidation"
|
|
59
|
+
| "resetValidation"
|
|
60
|
+
| "commitValidation"
|
|
61
|
+
> {
|
|
47
62
|
/** Current selected values. */
|
|
48
63
|
readonly value: Accessor<readonly string[]>;
|
|
49
64
|
/** Default selected values. */
|
|
@@ -69,49 +84,60 @@ export interface CheckboxGroupState {
|
|
|
69
84
|
removeValue(value: string): void;
|
|
70
85
|
/** Toggles a value in the set of selected values. */
|
|
71
86
|
toggleValue(value: string): void;
|
|
72
|
-
}
|
|
73
87
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
88
|
+
/** Current display validation result for the group. */
|
|
89
|
+
readonly displayValidation: Accessor<ValidationResult>;
|
|
90
|
+
}
|
|
77
91
|
|
|
78
92
|
/**
|
|
79
93
|
* Provides state management for a checkbox group component.
|
|
80
94
|
* Provides a name for the group, and manages selection and focus state.
|
|
81
95
|
*/
|
|
82
96
|
export function createCheckboxGroupState(
|
|
83
|
-
props: MaybeAccessor<CheckboxGroupProps> = {}
|
|
97
|
+
props: MaybeAccessor<CheckboxGroupProps> = {},
|
|
84
98
|
): CheckboxGroupState {
|
|
85
99
|
const getProps = () => access(props);
|
|
86
100
|
|
|
87
|
-
// Get initial values
|
|
88
101
|
const initialProps = getProps();
|
|
89
102
|
const initialValue = initialProps.value ?? initialProps.defaultValue ?? [];
|
|
90
103
|
|
|
91
|
-
// Create internal signal for uncontrolled mode
|
|
92
104
|
const [internalValue, setInternalValue] = createSignal<readonly string[]>(initialValue);
|
|
93
105
|
|
|
94
|
-
|
|
95
|
-
|
|
106
|
+
const controlledValue = createMemo<readonly string[] | undefined>(() => getProps().value);
|
|
107
|
+
|
|
108
|
+
const isControlled = () => controlledValue() !== undefined;
|
|
96
109
|
|
|
97
|
-
// Get current value
|
|
98
110
|
const value: Accessor<readonly string[]> = () => {
|
|
99
|
-
const
|
|
100
|
-
return
|
|
111
|
+
const controlled = controlledValue();
|
|
112
|
+
return controlled !== undefined ? controlled : internalValue();
|
|
101
113
|
};
|
|
102
114
|
|
|
103
|
-
// Check if required (true if isRequired and no items selected)
|
|
104
115
|
const isRequired: Accessor<boolean> = () => {
|
|
105
116
|
const p = getProps();
|
|
106
117
|
return !!p.isRequired && value().length === 0;
|
|
107
118
|
};
|
|
108
119
|
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
120
|
+
const validation = createFormValidationState<readonly string[]>({
|
|
121
|
+
get value() {
|
|
122
|
+
return value();
|
|
123
|
+
},
|
|
124
|
+
get isInvalid() {
|
|
125
|
+
return getProps().isInvalid;
|
|
126
|
+
},
|
|
127
|
+
get validationState() {
|
|
128
|
+
return getProps().validationState;
|
|
129
|
+
},
|
|
130
|
+
get validate() {
|
|
131
|
+
return getProps().validate;
|
|
132
|
+
},
|
|
133
|
+
get validationBehavior() {
|
|
134
|
+
return getProps().validationBehavior ?? "native";
|
|
135
|
+
},
|
|
136
|
+
get name() {
|
|
137
|
+
return getProps().name;
|
|
138
|
+
},
|
|
139
|
+
});
|
|
113
140
|
|
|
114
|
-
// Set value
|
|
115
141
|
function setValue(newValue: string[]): void {
|
|
116
142
|
const p = getProps();
|
|
117
143
|
if (p.isReadOnly || p.isDisabled) {
|
|
@@ -125,12 +151,10 @@ export function createCheckboxGroupState(
|
|
|
125
151
|
p.onChange?.(newValue);
|
|
126
152
|
}
|
|
127
153
|
|
|
128
|
-
// Check if value is selected
|
|
129
154
|
function isSelected(checkValue: string): boolean {
|
|
130
155
|
return value().includes(checkValue);
|
|
131
156
|
}
|
|
132
157
|
|
|
133
|
-
// Add value
|
|
134
158
|
function addValue(addVal: string): void {
|
|
135
159
|
const p = getProps();
|
|
136
160
|
if (p.isReadOnly || p.isDisabled) {
|
|
@@ -143,7 +167,6 @@ export function createCheckboxGroupState(
|
|
|
143
167
|
}
|
|
144
168
|
}
|
|
145
169
|
|
|
146
|
-
// Remove value
|
|
147
170
|
function removeValue(removeVal: string): void {
|
|
148
171
|
const p = getProps();
|
|
149
172
|
if (p.isReadOnly || p.isDisabled) {
|
|
@@ -156,7 +179,6 @@ export function createCheckboxGroupState(
|
|
|
156
179
|
}
|
|
157
180
|
}
|
|
158
181
|
|
|
159
|
-
// Toggle value
|
|
160
182
|
function toggleValue(toggleVal: string): void {
|
|
161
183
|
const p = getProps();
|
|
162
184
|
if (p.isReadOnly || p.isDisabled) {
|
|
@@ -181,7 +203,7 @@ export function createCheckboxGroupState(
|
|
|
181
203
|
return getProps().isReadOnly ?? false;
|
|
182
204
|
},
|
|
183
205
|
get isInvalid() {
|
|
184
|
-
return
|
|
206
|
+
return validation.displayValidation().isInvalid;
|
|
185
207
|
},
|
|
186
208
|
isRequired,
|
|
187
209
|
isSelected,
|
|
@@ -189,5 +211,10 @@ export function createCheckboxGroupState(
|
|
|
189
211
|
addValue,
|
|
190
212
|
removeValue,
|
|
191
213
|
toggleValue,
|
|
214
|
+
realtimeValidation: validation.realtimeValidation,
|
|
215
|
+
displayValidation: validation.displayValidation,
|
|
216
|
+
updateValidation: validation.updateValidation,
|
|
217
|
+
resetValidation: validation.resetValidation,
|
|
218
|
+
commitValidation: validation.commitValidation,
|
|
192
219
|
};
|
|
193
220
|
}
|
package/src/checkbox/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export {
|
|
2
|
+
createCheckboxGroupState,
|
|
3
|
+
type CheckboxGroupProps,
|
|
4
|
+
type CheckboxGroupState,
|
|
5
|
+
} from "./createCheckboxGroupState";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
package/src/checkbox/index.ts
CHANGED
|
@@ -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
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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>(
|
|
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
|
-
}
|
|
37
|
-
|
|
38
|
+
},
|
|
39
|
+
): ListCollection<T>;
|
|
40
|
+
//# sourceMappingURL=ListCollection.d.ts.map
|
|
@@ -1,146 +1,152 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* A simple list collection implementation.
|
|
3
|
-
* Provides a Collection interface over an array of nodes.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import type { Collection, CollectionNode, Key } from
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* A basic implementation of Collection for list-based components.
|
|
10
|
-
*/
|
|
11
|
-
export class ListCollection<T = unknown> implements Collection<T> {
|
|
12
|
-
private nodes: CollectionNode<T>[];
|
|
13
|
-
private keyMap: Map<Key, CollectionNode<T>>;
|
|
14
|
-
|
|
15
|
-
constructor(nodes: CollectionNode<T>[]) {
|
|
16
|
-
this.nodes = nodes;
|
|
17
|
-
this.keyMap = new Map();
|
|
18
|
-
|
|
19
|
-
// Build key map for O(1) lookups
|
|
20
|
-
const addToMap = (node: CollectionNode<T>) => {
|
|
21
|
-
this.keyMap.set(node.key, node);
|
|
22
|
-
if (node.childNodes) {
|
|
23
|
-
for (const child of node.childNodes) {
|
|
24
|
-
addToMap(child);
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
for (const node of nodes) {
|
|
30
|
-
addToMap(node);
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
get size(): number {
|
|
35
|
-
return this.keyMap.size;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
*[Symbol.iterator](): Iterator<CollectionNode<T>> {
|
|
39
|
-
yield* this.nodes;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
*getKeys(): Iterable<Key> {
|
|
43
|
-
for (const node of this.keyMap.values()) {
|
|
44
|
-
yield node.key;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
getItem(key: Key): CollectionNode<T> | null {
|
|
49
|
-
return this.keyMap.get(key) ?? null;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
at(index: number): CollectionNode<T> | null {
|
|
53
|
-
// Flatten all items for indexing
|
|
54
|
-
const items = this.getAllItems();
|
|
55
|
-
return items[index] ?? null;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
getKeyBefore(key: Key): Key | null {
|
|
59
|
-
const items = this.getAllItems();
|
|
60
|
-
const index = items.findIndex((item) => item.key === key);
|
|
61
|
-
if (index <= 0) return null;
|
|
62
|
-
return items[index - 1].key;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
getKeyAfter(key: Key): Key | null {
|
|
66
|
-
const items = this.getAllItems();
|
|
67
|
-
const index = items.findIndex((item) => item.key === key);
|
|
68
|
-
if (index < 0 || index >= items.length - 1) return null;
|
|
69
|
-
return items[index + 1].key;
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
getFirstKey(): Key | null {
|
|
73
|
-
const items = this.getAllItems();
|
|
74
|
-
return items[0]?.key ?? null;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
getLastKey(): Key | null {
|
|
78
|
-
const items = this.getAllItems();
|
|
79
|
-
return items[items.length - 1]?.key ?? null;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
*getChildren(key: Key): Iterable<CollectionNode<T>> {
|
|
83
|
-
const node = this.getItem(key);
|
|
84
|
-
if (node?.childNodes) {
|
|
85
|
-
yield* node.childNodes;
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
getTextValue(key: Key): string {
|
|
90
|
-
return this.getItem(key)?.textValue ??
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
/**
|
|
94
|
-
* Get all items (excluding sections, including items within sections).
|
|
95
|
-
*/
|
|
96
|
-
private getAllItems(): CollectionNode<T>[] {
|
|
97
|
-
const items: CollectionNode<T>[] = [];
|
|
98
|
-
|
|
99
|
-
const addItems = (nodes: CollectionNode<T>[]) => {
|
|
100
|
-
for (const node of nodes) {
|
|
101
|
-
if (node.type ===
|
|
102
|
-
items.push(node);
|
|
103
|
-
} else if (node.type ===
|
|
104
|
-
addItems(node.childNodes);
|
|
105
|
-
}
|
|
106
|
-
}
|
|
107
|
-
};
|
|
108
|
-
|
|
109
|
-
addItems(this.nodes);
|
|
110
|
-
return items;
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
/**
|
|
115
|
-
* Create a collection from an array of items.
|
|
116
|
-
*/
|
|
117
|
-
export function createListCollection<T>(
|
|
118
|
-
items: T[],
|
|
119
|
-
options: {
|
|
120
|
-
getKey?: (item: T, index: number) => Key;
|
|
121
|
-
getTextValue?: (item: T) => string;
|
|
122
|
-
getDisabled?: (item: T) => boolean;
|
|
123
|
-
} = {}
|
|
124
|
-
): ListCollection<T> {
|
|
125
|
-
const {
|
|
126
|
-
getKey = (item: T, index: number) =>
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
1
|
+
/**
|
|
2
|
+
* A simple list collection implementation.
|
|
3
|
+
* Provides a Collection interface over an array of nodes.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import type { Collection, CollectionItemLike, CollectionNode, Key } from "./types";
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* A basic implementation of Collection for list-based components.
|
|
10
|
+
*/
|
|
11
|
+
export class ListCollection<T = unknown> implements Collection<T> {
|
|
12
|
+
private nodes: CollectionNode<T>[];
|
|
13
|
+
private keyMap: Map<Key, CollectionNode<T>>;
|
|
14
|
+
|
|
15
|
+
constructor(nodes: CollectionNode<T>[]) {
|
|
16
|
+
this.nodes = nodes;
|
|
17
|
+
this.keyMap = new Map();
|
|
18
|
+
|
|
19
|
+
// Build key map for O(1) lookups
|
|
20
|
+
const addToMap = (node: CollectionNode<T>) => {
|
|
21
|
+
this.keyMap.set(node.key, node);
|
|
22
|
+
if (node.childNodes) {
|
|
23
|
+
for (const child of node.childNodes) {
|
|
24
|
+
addToMap(child);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
for (const node of nodes) {
|
|
30
|
+
addToMap(node);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
get size(): number {
|
|
35
|
+
return this.keyMap.size;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
*[Symbol.iterator](): Iterator<CollectionNode<T>> {
|
|
39
|
+
yield* this.nodes;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
*getKeys(): Iterable<Key> {
|
|
43
|
+
for (const node of this.keyMap.values()) {
|
|
44
|
+
yield node.key;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
getItem(key: Key): CollectionNode<T> | null {
|
|
49
|
+
return this.keyMap.get(key) ?? null;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
at(index: number): CollectionNode<T> | null {
|
|
53
|
+
// Flatten all items for indexing
|
|
54
|
+
const items = this.getAllItems();
|
|
55
|
+
return items[index] ?? null;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
getKeyBefore(key: Key): Key | null {
|
|
59
|
+
const items = this.getAllItems();
|
|
60
|
+
const index = items.findIndex((item) => item.key === key);
|
|
61
|
+
if (index <= 0) return null;
|
|
62
|
+
return items[index - 1].key;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
getKeyAfter(key: Key): Key | null {
|
|
66
|
+
const items = this.getAllItems();
|
|
67
|
+
const index = items.findIndex((item) => item.key === key);
|
|
68
|
+
if (index < 0 || index >= items.length - 1) return null;
|
|
69
|
+
return items[index + 1].key;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
getFirstKey(): Key | null {
|
|
73
|
+
const items = this.getAllItems();
|
|
74
|
+
return items[0]?.key ?? null;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
getLastKey(): Key | null {
|
|
78
|
+
const items = this.getAllItems();
|
|
79
|
+
return items[items.length - 1]?.key ?? null;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
*getChildren(key: Key): Iterable<CollectionNode<T>> {
|
|
83
|
+
const node = this.getItem(key);
|
|
84
|
+
if (node?.childNodes) {
|
|
85
|
+
yield* node.childNodes;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
getTextValue(key: Key): string {
|
|
90
|
+
return this.getItem(key)?.textValue ?? "";
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Get all items (excluding sections, including items within sections).
|
|
95
|
+
*/
|
|
96
|
+
private getAllItems(): CollectionNode<T>[] {
|
|
97
|
+
const items: CollectionNode<T>[] = [];
|
|
98
|
+
|
|
99
|
+
const addItems = (nodes: CollectionNode<T>[]) => {
|
|
100
|
+
for (const node of nodes) {
|
|
101
|
+
if (node.type === "item") {
|
|
102
|
+
items.push(node);
|
|
103
|
+
} else if (node.type === "section" && node.childNodes) {
|
|
104
|
+
addItems(node.childNodes);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
addItems(this.nodes);
|
|
110
|
+
return items;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/**
|
|
115
|
+
* Create a collection from an array of items.
|
|
116
|
+
*/
|
|
117
|
+
export function createListCollection<T>(
|
|
118
|
+
items: T[],
|
|
119
|
+
options: {
|
|
120
|
+
getKey?: (item: T, index: number) => Key;
|
|
121
|
+
getTextValue?: (item: T) => string;
|
|
122
|
+
getDisabled?: (item: T) => boolean;
|
|
123
|
+
} = {},
|
|
124
|
+
): ListCollection<T> {
|
|
125
|
+
const {
|
|
126
|
+
getKey = (item: T, index: number) => {
|
|
127
|
+
const o = item as CollectionItemLike;
|
|
128
|
+
return o.key ?? o.id ?? index;
|
|
129
|
+
},
|
|
130
|
+
getTextValue = (item: T) => {
|
|
131
|
+
const o = item as CollectionItemLike;
|
|
132
|
+
return o.textValue ?? o.label ?? String(item);
|
|
133
|
+
},
|
|
134
|
+
getDisabled = (item: T) => (item as CollectionItemLike).isDisabled ?? false,
|
|
135
|
+
} = options;
|
|
136
|
+
|
|
137
|
+
const nodes: CollectionNode<T>[] = items.map((item, index) => ({
|
|
138
|
+
type: "item" as const,
|
|
139
|
+
key: getKey(item, index),
|
|
140
|
+
value: item,
|
|
141
|
+
textValue: getTextValue(item),
|
|
142
|
+
rendered: null!, // Will be set by component
|
|
143
|
+
level: 0,
|
|
144
|
+
index,
|
|
145
|
+
parentKey: null,
|
|
146
|
+
hasChildNodes: false,
|
|
147
|
+
childNodes: [],
|
|
148
|
+
isDisabled: getDisabled(item),
|
|
149
|
+
}));
|
|
150
|
+
|
|
151
|
+
return new ListCollection(nodes);
|
|
152
|
+
}
|