@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
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export {
|
|
2
|
+
createNumberFieldState,
|
|
3
|
+
type NumberFieldStateProps,
|
|
4
|
+
type NumberFieldState,
|
|
5
|
+
} from "./createNumberFieldState";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
package/src/numberfield/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
createNumberFieldState,
|
|
3
|
-
type NumberFieldStateProps,
|
|
4
|
-
type NumberFieldState,
|
|
5
|
-
} from
|
|
1
|
+
export {
|
|
2
|
+
createNumberFieldState,
|
|
3
|
+
type NumberFieldStateProps,
|
|
4
|
+
type NumberFieldState,
|
|
5
|
+
} from "./createNumberFieldState";
|
|
@@ -2,31 +2,33 @@
|
|
|
2
2
|
* Manages state for an overlay trigger.
|
|
3
3
|
* Based on @react-stately/overlays useOverlayTriggerState.
|
|
4
4
|
*/
|
|
5
|
-
import { type Accessor } from
|
|
6
|
-
import { type MaybeAccessor } from
|
|
5
|
+
import { type Accessor } from "solid-js";
|
|
6
|
+
import { type MaybeAccessor } from "../utils";
|
|
7
7
|
export interface OverlayTriggerProps {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
/** Whether the overlay is open by default (uncontrolled). */
|
|
9
|
+
defaultOpen?: boolean;
|
|
10
|
+
/** Whether the overlay is open (controlled). */
|
|
11
|
+
isOpen?: boolean;
|
|
12
|
+
/** Handler that is called when the overlay's open state changes. */
|
|
13
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
14
14
|
}
|
|
15
15
|
export interface OverlayTriggerState {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
16
|
+
/** Whether the overlay is currently open. */
|
|
17
|
+
readonly isOpen: Accessor<boolean>;
|
|
18
|
+
/** Sets whether the overlay is open. */
|
|
19
|
+
setOpen(isOpen: boolean): void;
|
|
20
|
+
/** Opens the overlay. */
|
|
21
|
+
open(): void;
|
|
22
|
+
/** Closes the overlay. */
|
|
23
|
+
close(): void;
|
|
24
|
+
/** Toggles the overlay's visibility. */
|
|
25
|
+
toggle(): void;
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
28
|
* Manages state for an overlay trigger. Tracks whether the overlay is open, and provides
|
|
29
29
|
* methods to toggle this state.
|
|
30
30
|
*/
|
|
31
|
-
export declare function createOverlayTriggerState(
|
|
32
|
-
|
|
31
|
+
export declare function createOverlayTriggerState(
|
|
32
|
+
props?: MaybeAccessor<OverlayTriggerProps>,
|
|
33
|
+
): OverlayTriggerState;
|
|
34
|
+
//# sourceMappingURL=createOverlayTriggerState.d.ts.map
|
|
@@ -1,67 +1,66 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Manages state for an overlay trigger.
|
|
3
|
-
* Based on @react-stately/overlays useOverlayTriggerState.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { createSignal, type Accessor } from
|
|
7
|
-
import { access, type MaybeAccessor } from
|
|
8
|
-
|
|
9
|
-
export interface OverlayTriggerProps {
|
|
10
|
-
/** Whether the overlay is open by default (uncontrolled). */
|
|
11
|
-
defaultOpen?: boolean;
|
|
12
|
-
/** Whether the overlay is open (controlled). */
|
|
13
|
-
isOpen?: boolean;
|
|
14
|
-
/** Handler that is called when the overlay's open state changes. */
|
|
15
|
-
onOpenChange?: (isOpen: boolean) => void;
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
export interface OverlayTriggerState {
|
|
19
|
-
/** Whether the overlay is currently open. */
|
|
20
|
-
readonly isOpen: Accessor<boolean>;
|
|
21
|
-
/** Sets whether the overlay is open. */
|
|
22
|
-
setOpen(isOpen: boolean): void;
|
|
23
|
-
/** Opens the overlay. */
|
|
24
|
-
open(): void;
|
|
25
|
-
/** Closes the overlay. */
|
|
26
|
-
close(): void;
|
|
27
|
-
/** Toggles the overlay's visibility. */
|
|
28
|
-
toggle(): void;
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Manages state for an overlay trigger. Tracks whether the overlay is open, and provides
|
|
33
|
-
* methods to toggle this state.
|
|
34
|
-
*/
|
|
35
|
-
export function createOverlayTriggerState(
|
|
36
|
-
props: MaybeAccessor<OverlayTriggerProps> = {}
|
|
37
|
-
): OverlayTriggerState {
|
|
38
|
-
const propsAccessor = () => access(props);
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const
|
|
57
|
-
const
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
1
|
+
/**
|
|
2
|
+
* Manages state for an overlay trigger.
|
|
3
|
+
* Based on @react-stately/overlays useOverlayTriggerState.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { createSignal, type Accessor } from "solid-js";
|
|
7
|
+
import { access, type MaybeAccessor } from "../utils";
|
|
8
|
+
|
|
9
|
+
export interface OverlayTriggerProps {
|
|
10
|
+
/** Whether the overlay is open by default (uncontrolled). */
|
|
11
|
+
defaultOpen?: boolean;
|
|
12
|
+
/** Whether the overlay is open (controlled). */
|
|
13
|
+
isOpen?: boolean;
|
|
14
|
+
/** Handler that is called when the overlay's open state changes. */
|
|
15
|
+
onOpenChange?: (isOpen: boolean) => void;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export interface OverlayTriggerState {
|
|
19
|
+
/** Whether the overlay is currently open. */
|
|
20
|
+
readonly isOpen: Accessor<boolean>;
|
|
21
|
+
/** Sets whether the overlay is open. */
|
|
22
|
+
setOpen(isOpen: boolean): void;
|
|
23
|
+
/** Opens the overlay. */
|
|
24
|
+
open(): void;
|
|
25
|
+
/** Closes the overlay. */
|
|
26
|
+
close(): void;
|
|
27
|
+
/** Toggles the overlay's visibility. */
|
|
28
|
+
toggle(): void;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/**
|
|
32
|
+
* Manages state for an overlay trigger. Tracks whether the overlay is open, and provides
|
|
33
|
+
* methods to toggle this state.
|
|
34
|
+
*/
|
|
35
|
+
export function createOverlayTriggerState(
|
|
36
|
+
props: MaybeAccessor<OverlayTriggerProps> = {},
|
|
37
|
+
): OverlayTriggerState {
|
|
38
|
+
const propsAccessor = () => access(props);
|
|
39
|
+
|
|
40
|
+
const [internalOpen, setInternalOpen] = createSignal(propsAccessor().defaultOpen ?? false);
|
|
41
|
+
|
|
42
|
+
const isOpen: Accessor<boolean> = () => {
|
|
43
|
+
const p = propsAccessor();
|
|
44
|
+
return p.isOpen !== undefined ? p.isOpen : internalOpen();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
const setOpen = (open: boolean) => {
|
|
48
|
+
const p = propsAccessor();
|
|
49
|
+
if (p.isOpen === undefined) {
|
|
50
|
+
setInternalOpen(open);
|
|
51
|
+
}
|
|
52
|
+
p.onOpenChange?.(open);
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
const open = () => setOpen(true);
|
|
56
|
+
const close = () => setOpen(false);
|
|
57
|
+
const toggle = () => setOpen(!isOpen());
|
|
58
|
+
|
|
59
|
+
return {
|
|
60
|
+
isOpen,
|
|
61
|
+
setOpen,
|
|
62
|
+
open,
|
|
63
|
+
close,
|
|
64
|
+
toggle,
|
|
65
|
+
};
|
|
66
|
+
}
|
package/src/overlays/index.d.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export {
|
|
2
|
+
createOverlayTriggerState,
|
|
3
|
+
type OverlayTriggerProps,
|
|
4
|
+
type OverlayTriggerState,
|
|
5
|
+
} from "./createOverlayTriggerState";
|
|
6
|
+
//# sourceMappingURL=index.d.ts.map
|
package/src/overlays/index.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export {
|
|
2
|
-
createOverlayTriggerState,
|
|
3
|
-
type OverlayTriggerProps,
|
|
4
|
-
type OverlayTriggerState,
|
|
5
|
-
} from
|
|
1
|
+
export {
|
|
2
|
+
createOverlayTriggerState,
|
|
3
|
+
type OverlayTriggerProps,
|
|
4
|
+
type OverlayTriggerState,
|
|
5
|
+
} from "./createOverlayTriggerState";
|
|
@@ -6,59 +6,59 @@
|
|
|
6
6
|
*
|
|
7
7
|
* This is a 1:1 port of @react-stately/radio's useRadioGroupState.
|
|
8
8
|
*/
|
|
9
|
-
import { Accessor } from
|
|
10
|
-
import { type MaybeAccessor } from
|
|
9
|
+
import { Accessor } from "solid-js";
|
|
10
|
+
import { type MaybeAccessor } from "../utils";
|
|
11
11
|
export interface RadioGroupProps {
|
|
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
|
-
|
|
38
|
-
|
|
39
|
-
|
|
12
|
+
/** The current selected value (controlled). */
|
|
13
|
+
value?: string | null;
|
|
14
|
+
/** The default selected value (uncontrolled). */
|
|
15
|
+
defaultValue?: string | null;
|
|
16
|
+
/** Handler that is called when the value changes. */
|
|
17
|
+
onChange?: (value: string) => void;
|
|
18
|
+
/** Whether the radio group is disabled. */
|
|
19
|
+
isDisabled?: boolean;
|
|
20
|
+
/** Whether the radio group is read only. */
|
|
21
|
+
isReadOnly?: boolean;
|
|
22
|
+
/** Whether the radio group is required. */
|
|
23
|
+
isRequired?: boolean;
|
|
24
|
+
/** Whether the radio group is invalid. */
|
|
25
|
+
isInvalid?: boolean;
|
|
26
|
+
/** The name of the radio group, used when submitting an HTML form. */
|
|
27
|
+
name?: string;
|
|
28
|
+
/** The form to associate the radio group with. */
|
|
29
|
+
form?: string;
|
|
30
|
+
/** The label for the radio group. */
|
|
31
|
+
label?: string;
|
|
32
|
+
/** Orientation of the radio group. */
|
|
33
|
+
orientation?: "horizontal" | "vertical";
|
|
34
|
+
/** Handler that is called when the radio group receives focus. */
|
|
35
|
+
onFocus?: (e: FocusEvent) => void;
|
|
36
|
+
/** Handler that is called when the radio group loses focus. */
|
|
37
|
+
onBlur?: (e: FocusEvent) => void;
|
|
38
|
+
/** Handler that is called when the radio group's focus status changes. */
|
|
39
|
+
onFocusChange?: (isFocused: boolean) => void;
|
|
40
40
|
}
|
|
41
41
|
export interface RadioGroupState {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
42
|
+
/** The name for the group, used for native form submission. */
|
|
43
|
+
readonly name: string;
|
|
44
|
+
/** Whether the radio group is disabled. */
|
|
45
|
+
readonly isDisabled: boolean;
|
|
46
|
+
/** Whether the radio group is read only. */
|
|
47
|
+
readonly isReadOnly: boolean;
|
|
48
|
+
/** Whether the radio group is required. */
|
|
49
|
+
readonly isRequired: boolean;
|
|
50
|
+
/** Whether the radio group is invalid. */
|
|
51
|
+
readonly isInvalid: boolean;
|
|
52
|
+
/** The currently selected value. */
|
|
53
|
+
readonly selectedValue: Accessor<string | null>;
|
|
54
|
+
/** The default selected value. */
|
|
55
|
+
readonly defaultSelectedValue: string | null;
|
|
56
|
+
/** Sets the selected value. */
|
|
57
|
+
setSelectedValue(value: string | null): void;
|
|
58
|
+
/** The value of the last focused radio. */
|
|
59
|
+
readonly lastFocusedValue: Accessor<string | null>;
|
|
60
|
+
/** Sets the last focused value. */
|
|
61
|
+
setLastFocusedValue(value: string | null): void;
|
|
62
62
|
}
|
|
63
63
|
/**
|
|
64
64
|
* Internal WeakMap to store sync version accessors for each radio group state.
|
|
@@ -73,5 +73,7 @@ export declare const radioGroupSyncVersion: WeakMap<RadioGroupState, Accessor<nu
|
|
|
73
73
|
* Provides state management for a radio group component.
|
|
74
74
|
* Provides a name for the group, and manages selection and focus state.
|
|
75
75
|
*/
|
|
76
|
-
export declare function createRadioGroupState(
|
|
77
|
-
|
|
76
|
+
export declare function createRadioGroupState(
|
|
77
|
+
props?: MaybeAccessor<RadioGroupProps>,
|
|
78
|
+
): RadioGroupState;
|
|
79
|
+
//# sourceMappingURL=createRadioGroupState.d.ts.map
|
|
@@ -7,13 +7,15 @@
|
|
|
7
7
|
* This is a 1:1 port of @react-stately/radio's useRadioGroupState.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import { createSignal, Accessor, untrack } from
|
|
11
|
-
import { type MaybeAccessor, access } from
|
|
12
|
-
import { createId } from
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
import { createMemo, createSignal, Accessor, untrack } from "solid-js";
|
|
11
|
+
import { type MaybeAccessor, access } from "../utils";
|
|
12
|
+
import { createId } from "../ssr";
|
|
13
|
+
import {
|
|
14
|
+
createFormValidationState,
|
|
15
|
+
type FormValidationState,
|
|
16
|
+
type ValidationFunction,
|
|
17
|
+
type ValidationResult,
|
|
18
|
+
} from "../form";
|
|
17
19
|
|
|
18
20
|
export interface RadioGroupProps {
|
|
19
21
|
/** The current selected value (controlled). */
|
|
@@ -37,16 +39,29 @@ export interface RadioGroupProps {
|
|
|
37
39
|
/** The label for the radio group. */
|
|
38
40
|
label?: string;
|
|
39
41
|
/** Orientation of the radio group. */
|
|
40
|
-
orientation?:
|
|
42
|
+
orientation?: "horizontal" | "vertical";
|
|
41
43
|
/** Handler that is called when the radio group receives focus. */
|
|
42
44
|
onFocus?: (e: FocusEvent) => void;
|
|
43
45
|
/** Handler that is called when the radio group loses focus. */
|
|
44
46
|
onBlur?: (e: FocusEvent) => void;
|
|
45
47
|
/** Handler that is called when the radio group's focus status changes. */
|
|
46
48
|
onFocusChange?: (isFocused: boolean) => void;
|
|
49
|
+
/** Backward-compatible controlled validation state. */
|
|
50
|
+
validationState?: "valid" | "invalid";
|
|
51
|
+
/** Custom validation function. */
|
|
52
|
+
validate?: ValidationFunction<string | null>;
|
|
53
|
+
/** Validation behavior for the radio group. */
|
|
54
|
+
validationBehavior?: "aria" | "native";
|
|
47
55
|
}
|
|
48
56
|
|
|
49
|
-
export interface RadioGroupState
|
|
57
|
+
export interface RadioGroupState extends Pick<
|
|
58
|
+
FormValidationState,
|
|
59
|
+
| "realtimeValidation"
|
|
60
|
+
| "displayValidation"
|
|
61
|
+
| "updateValidation"
|
|
62
|
+
| "resetValidation"
|
|
63
|
+
| "commitValidation"
|
|
64
|
+
> {
|
|
50
65
|
/** The name for the group, used for native form submission. */
|
|
51
66
|
readonly name: string;
|
|
52
67
|
|
|
@@ -76,11 +91,10 @@ export interface RadioGroupState {
|
|
|
76
91
|
|
|
77
92
|
/** Sets the last focused value. */
|
|
78
93
|
setLastFocusedValue(value: string | null): void;
|
|
79
|
-
}
|
|
80
94
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
95
|
+
/** Current display validation result for the group. */
|
|
96
|
+
readonly displayValidation: Accessor<ValidationResult>;
|
|
97
|
+
}
|
|
84
98
|
|
|
85
99
|
/**
|
|
86
100
|
* Internal WeakMap to store sync version accessors for each radio group state.
|
|
@@ -92,17 +106,11 @@ export interface RadioGroupState {
|
|
|
92
106
|
*/
|
|
93
107
|
export const radioGroupSyncVersion: WeakMap<RadioGroupState, Accessor<number>> = new WeakMap();
|
|
94
108
|
|
|
95
|
-
// ============================================
|
|
96
|
-
// IMPLEMENTATION
|
|
97
|
-
// ============================================
|
|
98
|
-
|
|
99
109
|
/**
|
|
100
110
|
* Provides state management for a radio group component.
|
|
101
111
|
* Provides a name for the group, and manages selection and focus state.
|
|
102
112
|
*/
|
|
103
|
-
export function createRadioGroupState(
|
|
104
|
-
props: MaybeAccessor<RadioGroupProps> = {}
|
|
105
|
-
): RadioGroupState {
|
|
113
|
+
export function createRadioGroupState(props: MaybeAccessor<RadioGroupProps> = {}): RadioGroupState {
|
|
106
114
|
const getProps = () => access(props);
|
|
107
115
|
|
|
108
116
|
// Get initial props using untrack to avoid setting up dependencies
|
|
@@ -116,7 +124,7 @@ export function createRadioGroupState(
|
|
|
116
124
|
// Create internal signal for uncontrolled mode
|
|
117
125
|
// Initialize with defaultValue only (not value, which is for controlled mode)
|
|
118
126
|
const [internalValue, setInternalValue] = createSignal<string | null>(
|
|
119
|
-
initialProps.defaultValue ?? null
|
|
127
|
+
initialProps.defaultValue ?? null,
|
|
120
128
|
);
|
|
121
129
|
const [lastFocusedValue, setLastFocusedValueInternal] = createSignal<string | null>(null);
|
|
122
130
|
|
|
@@ -125,24 +133,45 @@ export function createRadioGroupState(
|
|
|
125
133
|
// from our reactive state (e.g., clicking a radio unchecks siblings in the DOM)
|
|
126
134
|
const [syncVersion, setSyncVersion] = createSignal(0);
|
|
127
135
|
|
|
136
|
+
const controlledValue = createMemo<string | null | undefined>(() => {
|
|
137
|
+
const value = getProps().value;
|
|
138
|
+
return value === undefined ? undefined : (value ?? null);
|
|
139
|
+
});
|
|
140
|
+
|
|
128
141
|
// Determine if controlled - must be reactive to handle dynamic props
|
|
129
|
-
const isControlled = () =>
|
|
142
|
+
const isControlled = () => controlledValue() !== undefined;
|
|
130
143
|
|
|
131
144
|
// Get current value - reactive for both controlled and uncontrolled modes
|
|
132
145
|
const selectedValue: Accessor<string | null> = () => {
|
|
133
|
-
const p = getProps();
|
|
134
146
|
// In controlled mode, always read from props.value reactively
|
|
135
147
|
// In uncontrolled mode, read from internal signal
|
|
136
|
-
|
|
137
|
-
|
|
148
|
+
const value = controlledValue();
|
|
149
|
+
if (value !== undefined) {
|
|
150
|
+
return value;
|
|
138
151
|
}
|
|
139
152
|
return internalValue();
|
|
140
153
|
};
|
|
141
154
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
155
|
+
const validation = createFormValidationState<string | null>({
|
|
156
|
+
get value() {
|
|
157
|
+
return selectedValue();
|
|
158
|
+
},
|
|
159
|
+
get isInvalid() {
|
|
160
|
+
return getProps().isInvalid;
|
|
161
|
+
},
|
|
162
|
+
get validationState() {
|
|
163
|
+
return getProps().validationState;
|
|
164
|
+
},
|
|
165
|
+
get validate() {
|
|
166
|
+
return getProps().validate;
|
|
167
|
+
},
|
|
168
|
+
get validationBehavior() {
|
|
169
|
+
return getProps().validationBehavior ?? "native";
|
|
170
|
+
},
|
|
171
|
+
get name() {
|
|
172
|
+
return getProps().name;
|
|
173
|
+
},
|
|
174
|
+
});
|
|
146
175
|
|
|
147
176
|
// Set value
|
|
148
177
|
function setSelectedValue(value: string | null): void {
|
|
@@ -165,6 +194,8 @@ export function createRadioGroupState(
|
|
|
165
194
|
if (value != null) {
|
|
166
195
|
p.onChange?.(value);
|
|
167
196
|
}
|
|
197
|
+
|
|
198
|
+
validation.commitValidation();
|
|
168
199
|
}
|
|
169
200
|
|
|
170
201
|
// Set last focused value
|
|
@@ -179,6 +210,11 @@ export function createRadioGroupState(
|
|
|
179
210
|
setSelectedValue,
|
|
180
211
|
lastFocusedValue,
|
|
181
212
|
setLastFocusedValue,
|
|
213
|
+
realtimeValidation: validation.realtimeValidation,
|
|
214
|
+
displayValidation: validation.displayValidation,
|
|
215
|
+
updateValidation: validation.updateValidation,
|
|
216
|
+
resetValidation: validation.resetValidation,
|
|
217
|
+
commitValidation: validation.commitValidation,
|
|
182
218
|
get isDisabled() {
|
|
183
219
|
return getProps().isDisabled ?? false;
|
|
184
220
|
},
|
|
@@ -189,7 +225,7 @@ export function createRadioGroupState(
|
|
|
189
225
|
return getProps().isRequired ?? false;
|
|
190
226
|
},
|
|
191
227
|
get isInvalid() {
|
|
192
|
-
return
|
|
228
|
+
return validation.displayValidation().isInvalid;
|
|
193
229
|
},
|
|
194
230
|
};
|
|
195
231
|
|
package/src/radio/index.d.ts
CHANGED
|
@@ -1,2 +1,7 @@
|
|
|
1
|
-
export {
|
|
2
|
-
|
|
1
|
+
export {
|
|
2
|
+
createRadioGroupState,
|
|
3
|
+
radioGroupSyncVersion,
|
|
4
|
+
type RadioGroupProps,
|
|
5
|
+
type RadioGroupState,
|
|
6
|
+
} from "./createRadioGroupState";
|
|
7
|
+
//# sourceMappingURL=index.d.ts.map
|
package/src/radio/index.ts
CHANGED
|
@@ -2,24 +2,26 @@
|
|
|
2
2
|
* Creates state for a search field component.
|
|
3
3
|
* Based on @react-stately/searchfield useSearchFieldState.
|
|
4
4
|
*/
|
|
5
|
-
import { type Accessor } from
|
|
6
|
-
import { type MaybeAccessor } from
|
|
5
|
+
import { type Accessor } from "solid-js";
|
|
6
|
+
import { type MaybeAccessor } from "../utils";
|
|
7
7
|
export interface SearchFieldStateProps {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
8
|
+
/** The current value (controlled). */
|
|
9
|
+
value?: string;
|
|
10
|
+
/** The default value (uncontrolled). */
|
|
11
|
+
defaultValue?: string;
|
|
12
|
+
/** Handler that is called when the value changes. */
|
|
13
|
+
onChange?: (value: string) => void;
|
|
14
14
|
}
|
|
15
15
|
export interface SearchFieldState {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
/** The current value of the search field. */
|
|
17
|
+
value: Accessor<string>;
|
|
18
|
+
/** Sets the value of the search field. */
|
|
19
|
+
setValue: (value: string) => void;
|
|
20
20
|
}
|
|
21
21
|
/**
|
|
22
22
|
* Provides state management for a search field.
|
|
23
23
|
*/
|
|
24
|
-
export declare function createSearchFieldState(
|
|
25
|
-
|
|
24
|
+
export declare function createSearchFieldState(
|
|
25
|
+
props: MaybeAccessor<SearchFieldStateProps>,
|
|
26
|
+
): SearchFieldState;
|
|
27
|
+
//# sourceMappingURL=createSearchFieldState.d.ts.map
|