@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.
- package/README.md +30 -283
- package/dist/autocomplete/createAutocompleteState.d.ts +2 -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 +6 -6
- 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 +12 -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 +1 -1
- 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 +4 -4
- package/dist/data/createListData.d.ts +2 -2
- package/dist/data/createTreeData.d.ts +6 -2
- package/dist/data/index.d.ts +3 -3
- package/dist/datepicker/index.d.ts +2 -4
- 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 +13 -11
- package/dist/index.d.ts +31 -30
- package/dist/index.js +7924 -7238
- package/dist/index.js.map +1 -1
- package/dist/menu/index.d.ts +2 -2
- 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 +7 -7
- 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 +8 -8
- package/dist/select/index.d.ts +1 -1
- package/dist/selection/index.d.ts +5 -5
- 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 +8 -2
- package/dist/toast/index.d.ts +1 -1
- package/dist/toggle/createToggleGroupState.d.ts +4 -4
- package/dist/toggle/createToggleState.d.ts +2 -2
- package/dist/toggle/index.d.ts +2 -2
- package/dist/tooltip/createTooltipTriggerState.d.ts +2 -2
- package/dist/tooltip/index.d.ts +1 -1
- package/dist/tree/TreeCollection.d.ts +2 -2
- 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 +29 -30
- package/src/autocomplete/createAutocompleteState.d.ts +19 -17
- package/src/autocomplete/createAutocompleteState.ts +24 -30
- 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 +263 -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 +20 -29
- 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 +6 -6
- package/src/collections/createListState.d.ts +73 -58
- package/src/collections/createListState.ts +19 -18
- package/src/collections/createMenuState.d.ts +36 -31
- package/src/collections/createMenuState.ts +18 -12
- package/src/collections/createSelectionState.d.ts +78 -65
- package/src/collections/createSelectionState.ts +36 -32
- package/src/collections/index.d.ts +38 -6
- package/src/collections/index.ts +5 -10
- package/src/collections/types.d.ts +101 -101
- package/src/collections/types.ts +12 -12
- package/src/color/Color.d.ts +20 -5
- package/src/color/Color.ts +357 -254
- package/src/color/createColorAreaState.d.ts +67 -65
- package/src/color/createColorAreaState.ts +21 -13
- package/src/color/createColorFieldState.d.ts +46 -44
- package/src/color/createColorFieldState.ts +285 -149
- package/src/color/createColorSliderState.d.ts +58 -56
- package/src/color/createColorSliderState.ts +45 -14
- package/src/color/createColorWheelState.d.ts +42 -40
- package/src/color/createColorWheelState.ts +101 -64
- package/src/color/getColorChannels.ts +7 -5
- package/src/color/index.d.ts +36 -7
- package/src/color/index.ts +6 -9
- package/src/color/types.d.ts +68 -63
- package/src/color/types.ts +11 -19
- package/src/combobox/createComboBoxState.d.ts +107 -105
- package/src/combobox/createComboBoxState.ts +176 -89
- package/src/combobox/index.d.ts +10 -2
- package/src/combobox/index.ts +1 -1
- package/src/data/createAsyncList.ts +89 -63
- package/src/data/createListData.ts +67 -67
- package/src/data/createTreeData.ts +304 -91
- package/src/data/index.ts +3 -3
- package/src/datepicker/index.ts +6 -10
- package/src/disclosure/createDisclosureState.d.ts +47 -43
- package/src/disclosure/createDisclosureState.ts +7 -21
- 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 +12 -14
- package/src/dnd/createDraggableCollectionState.d.ts +52 -41
- package/src/dnd/createDraggableCollectionState.ts +14 -21
- package/src/dnd/createDropState.d.ts +64 -45
- package/src/dnd/createDropState.ts +22 -32
- package/src/dnd/createDroppableCollectionState.d.ts +88 -59
- package/src/dnd/createDroppableCollectionState.ts +40 -43
- package/src/dnd/index.d.ts +54 -6
- package/src/dnd/index.ts +5 -18
- package/src/dnd/types.d.ts +167 -156
- package/src/dnd/types.ts +20 -21
- package/src/form/createFormValidationState.d.ts +47 -45
- package/src/form/createFormValidationState.ts +30 -63
- package/src/form/index.d.ts +16 -2
- package/src/form/index.ts +1 -1
- 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 +20 -18
- package/src/index.d.ts +310 -26
- package/src/index.ts +48 -89
- package/src/menu/index.ts +2 -4
- package/src/numberfield/createNumberFieldState.d.ts +56 -54
- package/src/numberfield/createNumberFieldState.ts +26 -31
- package/src/numberfield/index.d.ts +6 -2
- package/src/numberfield/index.ts +1 -1
- package/src/overlays/createOverlayTriggerState.d.ts +22 -20
- package/src/overlays/createOverlayTriggerState.ts +3 -4
- package/src/overlays/index.d.ts +6 -2
- package/src/overlays/index.ts +1 -1
- package/src/radio/createRadioGroupState.d.ts +54 -52
- package/src/radio/createRadioGroupState.ts +27 -29
- 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 +5 -11
- 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 +27 -27
- package/src/select/index.d.ts +2 -2
- package/src/select/index.ts +1 -5
- package/src/selection/index.ts +6 -7
- package/src/slider/createSliderState.d.ts +60 -60
- package/src/slider/createSliderState.ts +55 -33
- 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 +24 -31
- 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 -86
- package/src/toast/createToastState.ts +48 -43
- package/src/toast/index.d.ts +12 -2
- package/src/toast/index.ts +1 -1
- package/src/toggle/createToggleGroupState.ts +11 -21
- 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 +2 -6
- package/src/tooltip/createTooltipTriggerState.d.ts +17 -17
- package/src/tooltip/createTooltipTriggerState.ts +12 -11
- package/src/tooltip/index.d.ts +7 -2
- package/src/tooltip/index.ts +1 -1
- package/src/tree/TreeCollection.d.ts +26 -23
- package/src/tree/TreeCollection.ts +29 -22
- package/src/tree/createTreeState.d.ts +7 -4
- package/src/tree/createTreeState.ts +39 -41
- package/src/tree/index.d.ts +10 -4
- package/src/tree/index.ts +3 -3
- package/src/tree/types.d.ts +131 -126
- package/src/tree/types.ts +22 -13
- 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,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
|
|
11
|
-
import { type MaybeAccessor, access } from
|
|
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
|
|
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?:
|
|
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?:
|
|
51
|
+
validationBehavior?: "aria" | "native";
|
|
56
52
|
}
|
|
57
53
|
|
|
58
|
-
export interface CheckboxGroupState extends Pick<
|
|
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
|
-
|
|
110
|
-
|
|
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
|
|
115
|
-
return
|
|
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 ??
|
|
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) {
|
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
|
|
@@ -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
|
|
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 ===
|
|
101
|
+
if (node.type === "item") {
|
|
102
102
|
items.push(node);
|
|
103
|
-
} else if (node.type ===
|
|
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:
|
|
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
|
|
7
|
-
import { type MaybeAccessor } from
|
|
8
|
-
import { type SelectionState } from
|
|
9
|
-
import type {
|
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
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>(
|
|
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<
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
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
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
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>(
|
|
79
|
-
|
|
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
|
|
8
|
-
import { access, type MaybeAccessor } from
|
|
9
|
-
import { ListCollection } from
|
|
10
|
-
import { createSelectionState, type SelectionState } from
|
|
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
|
|
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?:
|
|
42
|
+
selectedKeys?: "all" | Iterable<Key>;
|
|
43
43
|
/** Default selected keys (uncontrolled). */
|
|
44
|
-
defaultSelectedKeys?:
|
|
44
|
+
defaultSelectedKeys?: "all" | Iterable<Key>;
|
|
45
45
|
/** Handler for selection changes. */
|
|
46
|
-
onSelectionChange?: (keys:
|
|
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:
|
|
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
|
-
|
|
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:
|
|
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 ===
|
|
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 ===
|
|
243
|
+
if (keys === "all") return null;
|
|
243
244
|
return keys.values().next().value ?? null;
|
|
244
245
|
};
|
|
245
246
|
|