@proyecto-viviana/solid-stately 0.2.7 → 0.4.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/IncompleteDate.d.ts +61 -0
- package/dist/calendar/createCalendarState.d.ts +41 -16
- package/dist/calendar/createDateFieldState.d.ts +39 -9
- package/dist/calendar/createDatePickerState.d.ts +60 -0
- package/dist/calendar/createRangeCalendarState.d.ts +37 -10
- 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 +11 -8
- package/dist/collections/createMenuState.d.ts +7 -7
- package/dist/collections/createSelectionState.d.ts +22 -10
- package/dist/collections/getChildNodes.d.ts +11 -0
- package/dist/collections/index.d.ts +6 -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 +34 -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 +19 -17
- 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 +27 -11
- package/dist/index.d.ts +31 -30
- package/dist/index.js +9077 -7246
- 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 +14 -8
- package/dist/select/index.d.ts +1 -1
- package/dist/selection/Selection.d.ts +16 -0
- package/dist/selection/SelectionManager.d.ts +110 -0
- package/dist/selection/createMultipleSelectionState.d.ts +59 -0
- package/dist/selection/index.d.ts +6 -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 +33 -3
- package/dist/table/createTableColumnResizeState.d.ts +54 -0
- package/dist/table/createTableState.d.ts +2 -2
- package/dist/table/createTreeGridState.d.ts +15 -0
- package/dist/table/index.d.ts +6 -3
- package/dist/table/types.d.ts +68 -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 +24 -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 +27 -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/IncompleteDate.ts +430 -0
- package/src/calendar/createCalendarState.d.ts +139 -117
- package/src/calendar/createCalendarState.ts +308 -94
- package/src/calendar/createDateFieldState.d.ts +130 -95
- package/src/calendar/createDateFieldState.ts +447 -334
- package/src/calendar/createDatePickerState.ts +347 -0
- package/src/calendar/createRangeCalendarState.d.ts +154 -129
- package/src/calendar/createRangeCalendarState.ts +411 -85
- 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 +23 -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 +67 -35
- package/src/collections/createMenuState.d.ts +36 -31
- package/src/collections/createMenuState.ts +21 -12
- package/src/collections/createSelectionState.d.ts +78 -65
- package/src/collections/createSelectionState.ts +66 -52
- package/src/collections/getChildNodes.ts +98 -0
- package/src/collections/index.d.ts +38 -6
- package/src/collections/index.ts +14 -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 +184 -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 +55 -6
- package/src/dnd/index.ts +6 -18
- package/src/dnd/types.d.ts +170 -157
- package/src/dnd/types.ts +24 -22
- 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 +78 -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 +34 -18
- package/src/index.d.ts +311 -26
- package/src/index.ts +59 -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 +42 -29
- package/src/select/index.d.ts +2 -2
- package/src/select/index.ts +1 -5
- package/src/selection/Selection.ts +28 -0
- package/src/selection/SelectionManager.ts +526 -0
- package/src/selection/createMultipleSelectionState.ts +247 -0
- package/src/selection/index.ts +12 -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 +266 -99
- package/src/table/createTableColumnResizeState.ts +242 -0
- package/src/table/createTableState.d.ts +7 -4
- package/src/table/createTableState.ts +30 -7
- package/src/table/createTreeGridState.ts +146 -0
- package/src/table/index.d.ts +14 -4
- package/src/table/index.ts +13 -3
- package/src/table/types.d.ts +98 -92
- package/src/table/types.ts +83 -13
- package/src/tabs/createTabListState.d.ts +59 -57
- package/src/tabs/createTabListState.ts +34 -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 -86
- package/src/toast/createToastState.ts +90 -52
- package/src/toast/index.d.ts +12 -2
- package/src/toast/index.ts +2 -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 +70 -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 +30 -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
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Based on @react-stately/numberfield useNumberFieldState.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { createSignal, createMemo, type Accessor } from
|
|
7
|
-
import { access, type MaybeAccessor } from
|
|
6
|
+
import { createSignal, createMemo, type Accessor } from "solid-js";
|
|
7
|
+
import { access, type MaybeAccessor } from "../utils";
|
|
8
8
|
|
|
9
9
|
export interface NumberFieldStateProps {
|
|
10
10
|
/** The current value (controlled). */
|
|
@@ -65,15 +65,11 @@ export interface NumberFieldState {
|
|
|
65
65
|
/**
|
|
66
66
|
* Handles decimal operations to avoid floating point errors.
|
|
67
67
|
*/
|
|
68
|
-
function handleDecimalOperation(
|
|
69
|
-
operator: '+' | '-',
|
|
70
|
-
value1: number,
|
|
71
|
-
value2: number
|
|
72
|
-
): number {
|
|
68
|
+
function handleDecimalOperation(operator: "+" | "-", value1: number, value2: number): number {
|
|
73
69
|
// Find the number of decimal places
|
|
74
70
|
const getDecimals = (n: number) => {
|
|
75
71
|
const str = String(n);
|
|
76
|
-
const idx = str.indexOf(
|
|
72
|
+
const idx = str.indexOf(".");
|
|
77
73
|
return idx === -1 ? 0 : str.length - idx - 1;
|
|
78
74
|
};
|
|
79
75
|
|
|
@@ -83,7 +79,7 @@ function handleDecimalOperation(
|
|
|
83
79
|
const int1 = Math.round(value1 * multiplier);
|
|
84
80
|
const int2 = Math.round(value2 * multiplier);
|
|
85
81
|
|
|
86
|
-
const result = operator ===
|
|
82
|
+
const result = operator === "+" ? int1 + int2 : int1 - int2;
|
|
87
83
|
return result / multiplier;
|
|
88
84
|
}
|
|
89
85
|
|
|
@@ -104,7 +100,7 @@ function snapToStep(value: number, step: number, min?: number): number {
|
|
|
104
100
|
const base = min ?? 0;
|
|
105
101
|
const diff = value - base;
|
|
106
102
|
const steps = Math.round(diff / step);
|
|
107
|
-
return handleDecimalOperation(
|
|
103
|
+
return handleDecimalOperation("+", base, steps * step);
|
|
108
104
|
}
|
|
109
105
|
|
|
110
106
|
function isValidStep(step: number | undefined): step is number {
|
|
@@ -115,12 +111,12 @@ function isValidStep(step: number | undefined): step is number {
|
|
|
115
111
|
* Creates state for a number field.
|
|
116
112
|
*/
|
|
117
113
|
export function createNumberFieldState(
|
|
118
|
-
props: MaybeAccessor<NumberFieldStateProps
|
|
114
|
+
props: MaybeAccessor<NumberFieldStateProps>,
|
|
119
115
|
): NumberFieldState {
|
|
120
116
|
const getProps = () => access(props);
|
|
121
117
|
|
|
122
118
|
// Get locale and formatter
|
|
123
|
-
const locale = () => getProps().locale ??
|
|
119
|
+
const locale = () => getProps().locale ?? "en-US";
|
|
124
120
|
const formatOptions = () => getProps().formatOptions ?? {};
|
|
125
121
|
|
|
126
122
|
// Create number formatter
|
|
@@ -130,7 +126,7 @@ export function createNumberFieldState(
|
|
|
130
126
|
|
|
131
127
|
// Create number parser (simplified - real implementation would be more robust)
|
|
132
128
|
const parseNumber = (value: string): number => {
|
|
133
|
-
if (!value || value ===
|
|
129
|
+
if (!value || value === "" || value === "-") return NaN;
|
|
134
130
|
|
|
135
131
|
// Handle locale-specific decimal separators
|
|
136
132
|
const opts = formatOptions();
|
|
@@ -139,17 +135,17 @@ export function createNumberFieldState(
|
|
|
139
135
|
|
|
140
136
|
// Normalize the input
|
|
141
137
|
let normalized = value;
|
|
142
|
-
if (decimalSeparator !==
|
|
143
|
-
normalized = normalized.replace(decimalSeparator,
|
|
138
|
+
if (decimalSeparator !== ".") {
|
|
139
|
+
normalized = normalized.replace(decimalSeparator, ".");
|
|
144
140
|
}
|
|
145
141
|
|
|
146
142
|
// Remove grouping separators and currency symbols
|
|
147
|
-
normalized = normalized.replace(/[^\d
|
|
143
|
+
normalized = normalized.replace(/[^\d.-]/g, "");
|
|
148
144
|
|
|
149
145
|
const parsed = parseFloat(normalized);
|
|
150
146
|
if (isNaN(parsed)) return parsed;
|
|
151
147
|
|
|
152
|
-
if (opts.style ===
|
|
148
|
+
if (opts.style === "percent") {
|
|
153
149
|
return parsed / 100;
|
|
154
150
|
}
|
|
155
151
|
|
|
@@ -158,7 +154,7 @@ export function createNumberFieldState(
|
|
|
158
154
|
|
|
159
155
|
// Format a number to string
|
|
160
156
|
const formatNumber = (value: number): string => {
|
|
161
|
-
if (isNaN(value)) return
|
|
157
|
+
if (isNaN(value)) return "";
|
|
162
158
|
return formatter().format(value);
|
|
163
159
|
};
|
|
164
160
|
|
|
@@ -169,12 +165,12 @@ export function createNumberFieldState(
|
|
|
169
165
|
const p = getProps();
|
|
170
166
|
if (hasCustomStep()) return p.step as number;
|
|
171
167
|
// Default step for percent is 0.01
|
|
172
|
-
if (p.formatOptions?.style ===
|
|
168
|
+
if (p.formatOptions?.style === "percent") return 0.01;
|
|
173
169
|
return 1;
|
|
174
170
|
});
|
|
175
171
|
|
|
176
172
|
// Internal signals
|
|
177
|
-
const [inputValue, setInputValueInternal] = createSignal<string>(
|
|
173
|
+
const [inputValue, setInputValueInternal] = createSignal<string>("");
|
|
178
174
|
const [numberValue, setNumberValue] = createSignal<number>(NaN);
|
|
179
175
|
|
|
180
176
|
const applyConstraints = (value: number): number => {
|
|
@@ -242,7 +238,7 @@ export function createNumberFieldState(
|
|
|
242
238
|
|
|
243
239
|
// Validate partial input
|
|
244
240
|
const validate = (value: string): boolean => {
|
|
245
|
-
if (value ===
|
|
241
|
+
if (value === "" || value === "-") return true;
|
|
246
242
|
|
|
247
243
|
// Allow partial decimal input like "1."
|
|
248
244
|
const opts = formatOptions();
|
|
@@ -251,7 +247,7 @@ export function createNumberFieldState(
|
|
|
251
247
|
|
|
252
248
|
// Check if it's a valid partial number
|
|
253
249
|
const pattern = new RegExp(
|
|
254
|
-
`^-?\\d*${decimalSeparator ===
|
|
250
|
+
`^-?\\d*${decimalSeparator === "." ? "\\." : decimalSeparator}?\\d*$`,
|
|
255
251
|
);
|
|
256
252
|
return pattern.test(value);
|
|
257
253
|
};
|
|
@@ -266,14 +262,13 @@ export function createNumberFieldState(
|
|
|
266
262
|
// Commit the current input value
|
|
267
263
|
const commit = () => {
|
|
268
264
|
ensureInitialized();
|
|
269
|
-
syncControlledValue();
|
|
270
265
|
const p = getProps();
|
|
271
266
|
const input = inputValue();
|
|
272
267
|
|
|
273
|
-
if (input ===
|
|
268
|
+
if (input === "" || input === "-") {
|
|
274
269
|
// Clear value
|
|
275
270
|
setNumberValue(NaN);
|
|
276
|
-
setInputValueInternal(p.value === undefined ?
|
|
271
|
+
setInputValueInternal(p.value === undefined ? "" : formatNumber(actualNumberValue()));
|
|
277
272
|
p.onChange?.(NaN);
|
|
278
273
|
return;
|
|
279
274
|
}
|
|
@@ -308,7 +303,7 @@ export function createNumberFieldState(
|
|
|
308
303
|
if (p.maxValue == null) return true;
|
|
309
304
|
return (
|
|
310
305
|
snapToStep(current, step(), p.minValue) > current ||
|
|
311
|
-
handleDecimalOperation(
|
|
306
|
+
handleDecimalOperation("+", current, step()) <= p.maxValue
|
|
312
307
|
);
|
|
313
308
|
});
|
|
314
309
|
|
|
@@ -324,11 +319,11 @@ export function createNumberFieldState(
|
|
|
324
319
|
if (p.minValue == null) return true;
|
|
325
320
|
return (
|
|
326
321
|
snapToStep(current, step(), p.minValue) < current ||
|
|
327
|
-
handleDecimalOperation(
|
|
322
|
+
handleDecimalOperation("-", current, step()) >= p.minValue
|
|
328
323
|
);
|
|
329
324
|
});
|
|
330
325
|
|
|
331
|
-
const safeNextStep = (operation:
|
|
326
|
+
const safeNextStep = (operation: "+" | "-", minOrMaxValue: number = 0): number => {
|
|
332
327
|
const p = getProps();
|
|
333
328
|
const parsed = parsedInputValue();
|
|
334
329
|
|
|
@@ -338,7 +333,7 @@ export function createNumberFieldState(
|
|
|
338
333
|
}
|
|
339
334
|
|
|
340
335
|
const snapped = snapToStep(parsed, step(), p.minValue);
|
|
341
|
-
if ((operation ===
|
|
336
|
+
if ((operation === "+" && snapped > parsed) || (operation === "-" && snapped < parsed)) {
|
|
342
337
|
return clamp(snapped, p.minValue, p.maxValue);
|
|
343
338
|
}
|
|
344
339
|
|
|
@@ -353,7 +348,7 @@ export function createNumberFieldState(
|
|
|
353
348
|
const p = getProps();
|
|
354
349
|
if (p.isDisabled || p.isReadOnly) return;
|
|
355
350
|
|
|
356
|
-
const current = safeNextStep(
|
|
351
|
+
const current = safeNextStep("+", p.minValue);
|
|
357
352
|
setNumberValue(current);
|
|
358
353
|
setInputValueInternal(formatNumber(current));
|
|
359
354
|
p.onChange?.(current);
|
|
@@ -366,7 +361,7 @@ export function createNumberFieldState(
|
|
|
366
361
|
const p = getProps();
|
|
367
362
|
if (p.isDisabled || p.isReadOnly) return;
|
|
368
363
|
|
|
369
|
-
const current = safeNextStep(
|
|
364
|
+
const current = safeNextStep("-", p.maxValue);
|
|
370
365
|
setNumberValue(current);
|
|
371
366
|
setInputValueInternal(formatNumber(current));
|
|
372
367
|
p.onChange?.(current);
|
|
@@ -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
|
@@ -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
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
* Based on @react-stately/overlays useOverlayTriggerState.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { createSignal, type Accessor } from
|
|
7
|
-
import { access, type MaybeAccessor } from
|
|
6
|
+
import { createSignal, type Accessor } from "solid-js";
|
|
7
|
+
import { access, type MaybeAccessor } from "../utils";
|
|
8
8
|
|
|
9
9
|
export interface OverlayTriggerProps {
|
|
10
10
|
/** Whether the overlay is open by default (uncontrolled). */
|
|
@@ -33,11 +33,10 @@ export interface OverlayTriggerState {
|
|
|
33
33
|
* methods to toggle this state.
|
|
34
34
|
*/
|
|
35
35
|
export function createOverlayTriggerState(
|
|
36
|
-
props: MaybeAccessor<OverlayTriggerProps> = {}
|
|
36
|
+
props: MaybeAccessor<OverlayTriggerProps> = {},
|
|
37
37
|
): OverlayTriggerState {
|
|
38
38
|
const propsAccessor = () => access(props);
|
|
39
39
|
|
|
40
|
-
// Use controlled state if isOpen is provided, otherwise use internal state
|
|
41
40
|
const [internalOpen, setInternalOpen] = createSignal(propsAccessor().defaultOpen ?? false);
|
|
42
41
|
|
|
43
42
|
const isOpen: Accessor<boolean> = () => {
|
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
|
@@ -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,19 +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
|
|
10
|
+
import { createMemo, createSignal, Accessor, untrack } from "solid-js";
|
|
11
|
+
import { type MaybeAccessor, access } from "../utils";
|
|
12
|
+
import { createId } from "../ssr";
|
|
13
13
|
import {
|
|
14
14
|
createFormValidationState,
|
|
15
15
|
type FormValidationState,
|
|
16
16
|
type ValidationFunction,
|
|
17
17
|
type ValidationResult,
|
|
18
|
-
} from
|
|
19
|
-
|
|
20
|
-
// ============================================
|
|
21
|
-
// TYPES
|
|
22
|
-
// ============================================
|
|
18
|
+
} from "../form";
|
|
23
19
|
|
|
24
20
|
export interface RadioGroupProps {
|
|
25
21
|
/** The current selected value (controlled). */
|
|
@@ -43,7 +39,7 @@ export interface RadioGroupProps {
|
|
|
43
39
|
/** The label for the radio group. */
|
|
44
40
|
label?: string;
|
|
45
41
|
/** Orientation of the radio group. */
|
|
46
|
-
orientation?:
|
|
42
|
+
orientation?: "horizontal" | "vertical";
|
|
47
43
|
/** Handler that is called when the radio group receives focus. */
|
|
48
44
|
onFocus?: (e: FocusEvent) => void;
|
|
49
45
|
/** Handler that is called when the radio group loses focus. */
|
|
@@ -51,14 +47,21 @@ export interface RadioGroupProps {
|
|
|
51
47
|
/** Handler that is called when the radio group's focus status changes. */
|
|
52
48
|
onFocusChange?: (isFocused: boolean) => void;
|
|
53
49
|
/** Backward-compatible controlled validation state. */
|
|
54
|
-
validationState?:
|
|
50
|
+
validationState?: "valid" | "invalid";
|
|
55
51
|
/** Custom validation function. */
|
|
56
52
|
validate?: ValidationFunction<string | null>;
|
|
57
53
|
/** Validation behavior for the radio group. */
|
|
58
|
-
validationBehavior?:
|
|
54
|
+
validationBehavior?: "aria" | "native";
|
|
59
55
|
}
|
|
60
56
|
|
|
61
|
-
export interface RadioGroupState extends Pick<
|
|
57
|
+
export interface RadioGroupState extends Pick<
|
|
58
|
+
FormValidationState,
|
|
59
|
+
| "realtimeValidation"
|
|
60
|
+
| "displayValidation"
|
|
61
|
+
| "updateValidation"
|
|
62
|
+
| "resetValidation"
|
|
63
|
+
| "commitValidation"
|
|
64
|
+
> {
|
|
62
65
|
/** The name for the group, used for native form submission. */
|
|
63
66
|
readonly name: string;
|
|
64
67
|
|
|
@@ -93,10 +96,6 @@ export interface RadioGroupState extends Pick<FormValidationState, 'realtimeVali
|
|
|
93
96
|
readonly displayValidation: Accessor<ValidationResult>;
|
|
94
97
|
}
|
|
95
98
|
|
|
96
|
-
// ============================================
|
|
97
|
-
// INTERNAL: SolidJS-specific sync mechanism
|
|
98
|
-
// ============================================
|
|
99
|
-
|
|
100
99
|
/**
|
|
101
100
|
* Internal WeakMap to store sync version accessors for each radio group state.
|
|
102
101
|
* This is used by createRadio to trigger DOM sync when native radio behavior
|
|
@@ -107,17 +106,11 @@ export interface RadioGroupState extends Pick<FormValidationState, 'realtimeVali
|
|
|
107
106
|
*/
|
|
108
107
|
export const radioGroupSyncVersion: WeakMap<RadioGroupState, Accessor<number>> = new WeakMap();
|
|
109
108
|
|
|
110
|
-
// ============================================
|
|
111
|
-
// IMPLEMENTATION
|
|
112
|
-
// ============================================
|
|
113
|
-
|
|
114
109
|
/**
|
|
115
110
|
* Provides state management for a radio group component.
|
|
116
111
|
* Provides a name for the group, and manages selection and focus state.
|
|
117
112
|
*/
|
|
118
|
-
export function createRadioGroupState(
|
|
119
|
-
props: MaybeAccessor<RadioGroupProps> = {}
|
|
120
|
-
): RadioGroupState {
|
|
113
|
+
export function createRadioGroupState(props: MaybeAccessor<RadioGroupProps> = {}): RadioGroupState {
|
|
121
114
|
const getProps = () => access(props);
|
|
122
115
|
|
|
123
116
|
// Get initial props using untrack to avoid setting up dependencies
|
|
@@ -131,7 +124,7 @@ export function createRadioGroupState(
|
|
|
131
124
|
// Create internal signal for uncontrolled mode
|
|
132
125
|
// Initialize with defaultValue only (not value, which is for controlled mode)
|
|
133
126
|
const [internalValue, setInternalValue] = createSignal<string | null>(
|
|
134
|
-
initialProps.defaultValue ?? null
|
|
127
|
+
initialProps.defaultValue ?? null,
|
|
135
128
|
);
|
|
136
129
|
const [lastFocusedValue, setLastFocusedValueInternal] = createSignal<string | null>(null);
|
|
137
130
|
|
|
@@ -140,16 +133,21 @@ export function createRadioGroupState(
|
|
|
140
133
|
// from our reactive state (e.g., clicking a radio unchecks siblings in the DOM)
|
|
141
134
|
const [syncVersion, setSyncVersion] = createSignal(0);
|
|
142
135
|
|
|
136
|
+
const controlledValue = createMemo<string | null | undefined>(() => {
|
|
137
|
+
const value = getProps().value;
|
|
138
|
+
return value === undefined ? undefined : (value ?? null);
|
|
139
|
+
});
|
|
140
|
+
|
|
143
141
|
// Determine if controlled - must be reactive to handle dynamic props
|
|
144
|
-
const isControlled = () =>
|
|
142
|
+
const isControlled = () => controlledValue() !== undefined;
|
|
145
143
|
|
|
146
144
|
// Get current value - reactive for both controlled and uncontrolled modes
|
|
147
145
|
const selectedValue: Accessor<string | null> = () => {
|
|
148
|
-
const p = getProps();
|
|
149
146
|
// In controlled mode, always read from props.value reactively
|
|
150
147
|
// In uncontrolled mode, read from internal signal
|
|
151
|
-
|
|
152
|
-
|
|
148
|
+
const value = controlledValue();
|
|
149
|
+
if (value !== undefined) {
|
|
150
|
+
return value;
|
|
153
151
|
}
|
|
154
152
|
return internalValue();
|
|
155
153
|
};
|
|
@@ -168,7 +166,7 @@ export function createRadioGroupState(
|
|
|
168
166
|
return getProps().validate;
|
|
169
167
|
},
|
|
170
168
|
get validationBehavior() {
|
|
171
|
-
return getProps().validationBehavior ??
|
|
169
|
+
return getProps().validationBehavior ?? "native";
|
|
172
170
|
},
|
|
173
171
|
get name() {
|
|
174
172
|
return getProps().name;
|
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
|