@proyecto-viviana/solidaria-components 0.2.5 → 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 +39 -272
- package/dist/ActionBar.d.ts +79 -0
- package/dist/ActionBar.d.ts.map +1 -0
- package/dist/ActionGroup.d.ts +74 -0
- package/dist/ActionGroup.d.ts.map +1 -0
- package/dist/Alert.d.ts +70 -0
- package/dist/Alert.d.ts.map +1 -0
- package/dist/Autocomplete.d.ts +5 -5
- package/dist/Autocomplete.d.ts.map +1 -1
- package/dist/Breadcrumbs.d.ts +27 -8
- package/dist/Breadcrumbs.d.ts.map +1 -1
- package/dist/Button.d.ts +28 -5
- package/dist/Button.d.ts.map +1 -1
- package/dist/Calendar.d.ts +51 -7
- package/dist/Calendar.d.ts.map +1 -1
- package/dist/Checkbox.d.ts +33 -8
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Collection.d.ts +130 -0
- package/dist/Collection.d.ts.map +1 -0
- package/dist/Color.d.ts +210 -9
- package/dist/Color.d.ts.map +1 -1
- package/dist/ColorEditor.d.ts +42 -0
- package/dist/ColorEditor.d.ts.map +1 -0
- package/dist/ComboBox.d.ts +146 -16
- package/dist/ComboBox.d.ts.map +1 -1
- package/dist/ContextualHelpTrigger.d.ts +40 -0
- package/dist/ContextualHelpTrigger.d.ts.map +1 -0
- package/dist/DateField.d.ts +35 -8
- package/dist/DateField.d.ts.map +1 -1
- package/dist/DatePicker.d.ts +101 -5
- package/dist/DatePicker.d.ts.map +1 -1
- package/dist/DateRangePickerContext.d.ts +30 -0
- package/dist/DateRangePickerContext.d.ts.map +1 -0
- package/dist/Dialog.d.ts +5 -5
- package/dist/Dialog.d.ts.map +1 -1
- package/dist/Disclosure.d.ts +25 -5
- package/dist/Disclosure.d.ts.map +1 -1
- package/dist/DragAndDrop.d.ts +80 -0
- package/dist/DragAndDrop.d.ts.map +1 -0
- package/dist/DragPreview.d.ts +14 -0
- package/dist/DragPreview.d.ts.map +1 -0
- package/dist/DropZone.d.ts +27 -0
- package/dist/DropZone.d.ts.map +1 -0
- package/dist/FieldError.d.ts +27 -0
- package/dist/FieldError.d.ts.map +1 -0
- package/dist/FileTrigger.d.ts +26 -0
- package/dist/FileTrigger.d.ts.map +1 -0
- package/dist/Focusable.d.ts +27 -0
- package/dist/Focusable.d.ts.map +1 -0
- package/dist/Form.d.ts +41 -0
- package/dist/Form.d.ts.map +1 -0
- package/dist/GridList.d.ts +69 -10
- package/dist/GridList.d.ts.map +1 -1
- package/dist/HiddenDateInput.d.ts +26 -0
- package/dist/HiddenDateInput.d.ts.map +1 -0
- package/dist/HiddenTimeInput.d.ts +25 -0
- package/dist/HiddenTimeInput.d.ts.map +1 -0
- package/dist/Icon.d.ts +57 -0
- package/dist/Icon.d.ts.map +1 -0
- package/dist/Keyboard.d.ts +13 -0
- package/dist/Keyboard.d.ts.map +1 -0
- package/dist/Landmark.d.ts +3 -3
- package/dist/Landmark.d.ts.map +1 -1
- package/dist/Link.d.ts +10 -4
- package/dist/Link.d.ts.map +1 -1
- package/dist/ListBox.d.ts +73 -11
- package/dist/ListBox.d.ts.map +1 -1
- package/dist/ListDropTargetDelegate.d.ts +38 -0
- package/dist/ListDropTargetDelegate.d.ts.map +1 -0
- package/dist/Menu.d.ts +79 -10
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Meter.d.ts +4 -4
- package/dist/Meter.d.ts.map +1 -1
- package/dist/Modal.d.ts +6 -4
- package/dist/Modal.d.ts.map +1 -1
- package/dist/NumberField.d.ts +10 -12
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/Popover.d.ts +32 -7
- package/dist/Popover.d.ts.map +1 -1
- package/dist/Pressable.d.ts +27 -0
- package/dist/Pressable.d.ts.map +1 -0
- package/dist/ProgressBar.d.ts +6 -4
- package/dist/ProgressBar.d.ts.map +1 -1
- package/dist/RadioGroup.d.ts +43 -9
- package/dist/RadioGroup.d.ts.map +1 -1
- package/dist/RangeCalendar.d.ts +39 -7
- package/dist/RangeCalendar.d.ts.map +1 -1
- package/dist/RouterProvider.d.ts +75 -0
- package/dist/RouterProvider.d.ts.map +1 -0
- package/dist/SearchField.d.ts +23 -21
- package/dist/SearchField.d.ts.map +1 -1
- package/dist/Select.d.ts +48 -7
- package/dist/Select.d.ts.map +1 -1
- package/dist/SelectionIndicator.d.ts +30 -0
- package/dist/SelectionIndicator.d.ts.map +1 -0
- package/dist/Separator.d.ts +9 -3
- package/dist/Separator.d.ts.map +1 -1
- package/dist/SharedElementTransition.d.ts +41 -0
- package/dist/SharedElementTransition.d.ts.map +1 -0
- package/dist/Slider.d.ts +15 -8
- package/dist/Slider.d.ts.map +1 -1
- package/dist/StepList.d.ts +90 -0
- package/dist/StepList.d.ts.map +1 -0
- package/dist/Switch.d.ts +11 -5
- package/dist/Switch.d.ts.map +1 -1
- package/dist/Table.d.ts +222 -19
- package/dist/Table.d.ts.map +1 -1
- package/dist/Tabs.d.ts +47 -10
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/TagGroup.d.ts +22 -10
- package/dist/TagGroup.d.ts.map +1 -1
- package/dist/Text.d.ts +10 -0
- package/dist/Text.d.ts.map +1 -0
- package/dist/TextField.d.ts +19 -11
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TimeField.d.ts +32 -7
- package/dist/TimeField.d.ts.map +1 -1
- package/dist/Toast.d.ts +29 -14
- package/dist/Toast.d.ts.map +1 -1
- package/dist/ToggleButton.d.ts +36 -0
- package/dist/ToggleButton.d.ts.map +1 -0
- package/dist/ToggleButtonGroup.d.ts +33 -0
- package/dist/ToggleButtonGroup.d.ts.map +1 -0
- package/dist/Toolbar.d.ts +7 -3
- package/dist/Toolbar.d.ts.map +1 -1
- package/dist/Tooltip.d.ts +58 -7
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tree.d.ts +102 -11
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Virtualizer.d.ts +61 -0
- package/dist/Virtualizer.d.ts.map +1 -0
- package/dist/VirtualizerLayouts.d.ts +82 -0
- package/dist/VirtualizerLayouts.d.ts.map +1 -0
- package/dist/VisuallyHidden.d.ts +4 -2
- package/dist/VisuallyHidden.d.ts.map +1 -1
- package/dist/contexts.d.ts +6 -1
- package/dist/contexts.d.ts.map +1 -1
- package/dist/index.d.ts +73 -39
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23342 -10644
- package/dist/index.js.map +1 -7
- package/dist/index.jsx +18110 -0
- package/dist/index.jsx.map +1 -0
- package/dist/useDragAndDrop.d.ts +93 -0
- package/dist/useDragAndDrop.d.ts.map +1 -0
- package/dist/utils.d.ts +8 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/virtualizer/Layout.d.ts +79 -0
- package/dist/virtualizer/Layout.d.ts.map +1 -0
- package/package.json +33 -32
- package/src/ActionBar.tsx +251 -0
- package/src/ActionGroup.tsx +277 -0
- package/src/Alert.tsx +152 -0
- package/src/Autocomplete.tsx +39 -44
- package/src/Breadcrumbs.tsx +227 -72
- package/src/Button.tsx +315 -74
- package/src/Calendar.tsx +347 -141
- package/src/Checkbox.tsx +414 -123
- package/src/Collection.tsx +350 -0
- package/src/Color.tsx +1325 -284
- package/src/ColorEditor.tsx +213 -0
- package/src/ComboBox.tsx +644 -245
- package/src/ContextualHelpTrigger.tsx +195 -0
- package/src/DateField.tsx +274 -106
- package/src/DatePicker.tsx +892 -111
- package/src/DateRangePickerContext.tsx +44 -0
- package/src/Dialog.tsx +173 -104
- package/src/Disclosure.tsx +158 -105
- package/src/DragAndDrop.tsx +340 -0
- package/src/DragPreview.tsx +47 -0
- package/src/DropZone.tsx +233 -0
- package/src/FieldError.tsx +89 -0
- package/src/FileTrigger.tsx +83 -0
- package/src/Focusable.tsx +103 -0
- package/src/Form.tsx +140 -0
- package/src/GridList.tsx +542 -128
- package/src/HiddenDateInput.tsx +153 -0
- package/src/HiddenTimeInput.tsx +133 -0
- package/src/Icon.tsx +133 -0
- package/src/Keyboard.tsx +26 -0
- package/src/Landmark.tsx +37 -63
- package/src/Link.tsx +132 -69
- package/src/ListBox.tsx +656 -106
- package/src/ListDropTargetDelegate.ts +283 -0
- package/src/Menu.tsx +1234 -132
- package/src/Meter.tsx +44 -58
- package/src/Modal.tsx +262 -166
- package/src/NumberField.tsx +267 -151
- package/src/Popover.tsx +452 -343
- package/src/Pressable.tsx +108 -0
- package/src/ProgressBar.tsx +54 -59
- package/src/RadioGroup.tsx +533 -121
- package/src/RangeCalendar.tsx +249 -150
- package/src/RouterProvider.tsx +223 -0
- package/src/SearchField.tsx +460 -133
- package/src/Select.tsx +804 -233
- package/src/SelectionIndicator.tsx +108 -0
- package/src/Separator.tsx +47 -49
- package/src/SharedElementTransition.tsx +264 -0
- package/src/Slider.tsx +148 -98
- package/src/StepList.tsx +272 -0
- package/src/Switch.tsx +93 -46
- package/src/Table.tsx +1551 -225
- package/src/Tabs.tsx +377 -123
- package/src/TagGroup.tsx +233 -135
- package/src/Text.tsx +18 -0
- package/src/TextField.tsx +413 -86
- package/src/TimeField.tsx +232 -222
- package/src/Toast.tsx +306 -160
- package/src/ToggleButton.tsx +169 -0
- package/src/ToggleButtonGroup.tsx +141 -0
- package/src/Toolbar.tsx +61 -70
- package/src/Tooltip.tsx +473 -116
- package/src/Tree.tsx +1514 -175
- package/src/Virtualizer.tsx +730 -0
- package/src/VirtualizerLayouts.ts +280 -0
- package/src/VisuallyHidden.tsx +32 -38
- package/src/contexts.ts +29 -36
- package/src/index.ts +972 -620
- package/src/useDragAndDrop.ts +367 -0
- package/src/utils.tsx +69 -50
- package/src/virtualizer/Layout.ts +192 -0
- package/dist/index.ssr.js +0 -9785
- package/dist/index.ssr.js.map +0 -7
package/src/NumberField.tsx
CHANGED
|
@@ -5,24 +5,16 @@
|
|
|
5
5
|
* Port of react-aria-components/src/NumberField.tsx
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import {
|
|
9
|
-
type JSX,
|
|
10
|
-
createContext,
|
|
11
|
-
createMemo,
|
|
12
|
-
splitProps,
|
|
13
|
-
useContext,
|
|
14
|
-
} from 'solid-js';
|
|
8
|
+
import { type JSX, createContext, createMemo, splitProps, useContext } from "solid-js";
|
|
15
9
|
import {
|
|
16
10
|
createNumberField,
|
|
11
|
+
createButton,
|
|
17
12
|
createFocusRing,
|
|
18
13
|
createHover,
|
|
19
|
-
createPress,
|
|
20
14
|
type AriaNumberFieldProps,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
type NumberFieldState,
|
|
25
|
-
} from '@proyecto-viviana/solid-stately';
|
|
15
|
+
type AriaButtonProps,
|
|
16
|
+
} from "@proyecto-viviana/solidaria";
|
|
17
|
+
import { createNumberFieldState, type NumberFieldState } from "@proyecto-viviana/solid-stately";
|
|
26
18
|
import {
|
|
27
19
|
type RenderChildren,
|
|
28
20
|
type ClassNameOrFunction,
|
|
@@ -30,11 +22,7 @@ import {
|
|
|
30
22
|
type SlotProps,
|
|
31
23
|
useRenderProps,
|
|
32
24
|
filterDOMProps,
|
|
33
|
-
} from
|
|
34
|
-
|
|
35
|
-
// ============================================
|
|
36
|
-
// TYPES
|
|
37
|
-
// ============================================
|
|
25
|
+
} from "./utils";
|
|
38
26
|
|
|
39
27
|
export interface NumberFieldRenderProps {
|
|
40
28
|
/** Whether the number field is disabled. */
|
|
@@ -49,7 +37,7 @@ export interface NumberFieldRenderProps {
|
|
|
49
37
|
value: number;
|
|
50
38
|
}
|
|
51
39
|
|
|
52
|
-
export interface NumberFieldProps extends Omit<AriaNumberFieldProps,
|
|
40
|
+
export interface NumberFieldProps extends Omit<AriaNumberFieldProps, "label">, SlotProps {
|
|
53
41
|
/** The current value (controlled). */
|
|
54
42
|
value?: number;
|
|
55
43
|
/** The default value (uncontrolled). */
|
|
@@ -123,15 +111,11 @@ export interface NumberFieldDecrementButtonProps extends SlotProps {
|
|
|
123
111
|
style?: StyleOrFunction<NumberFieldButtonRenderProps>;
|
|
124
112
|
}
|
|
125
113
|
|
|
126
|
-
// ============================================
|
|
127
|
-
// CONTEXT
|
|
128
|
-
// ============================================
|
|
129
|
-
|
|
130
114
|
interface NumberFieldContextValue {
|
|
131
115
|
state: NumberFieldState;
|
|
132
116
|
inputProps: JSX.InputHTMLAttributes<HTMLInputElement>;
|
|
133
|
-
incrementButtonProps:
|
|
134
|
-
decrementButtonProps:
|
|
117
|
+
incrementButtonProps: AriaButtonProps;
|
|
118
|
+
decrementButtonProps: AriaButtonProps;
|
|
135
119
|
labelProps: JSX.HTMLAttributes<HTMLElement>;
|
|
136
120
|
groupProps: JSX.HTMLAttributes<HTMLElement>;
|
|
137
121
|
descriptionProps: JSX.HTMLAttributes<HTMLElement>;
|
|
@@ -140,13 +124,11 @@ interface NumberFieldContextValue {
|
|
|
140
124
|
isInvalid: boolean;
|
|
141
125
|
isRequired: boolean;
|
|
142
126
|
isReadOnly: boolean;
|
|
127
|
+
setInputRef: (el: HTMLInputElement) => void;
|
|
143
128
|
}
|
|
144
129
|
|
|
145
130
|
export const NumberFieldContext = createContext<NumberFieldContextValue | null>(null);
|
|
146
|
-
|
|
147
|
-
// ============================================
|
|
148
|
-
// COMPONENTS
|
|
149
|
-
// ============================================
|
|
131
|
+
export const NumberFieldStateContext = createContext<NumberFieldState | null>(null);
|
|
150
132
|
|
|
151
133
|
/**
|
|
152
134
|
* A number field allows a user to enter a number and increment/decrement the value.
|
|
@@ -154,12 +136,43 @@ export const NumberFieldContext = createContext<NumberFieldContextValue | null>(
|
|
|
154
136
|
export function NumberField(props: NumberFieldProps): JSX.Element {
|
|
155
137
|
const [local, stateProps, ariaProps, rest] = splitProps(
|
|
156
138
|
props,
|
|
157
|
-
[
|
|
158
|
-
[
|
|
159
|
-
|
|
139
|
+
["children", "class", "style", "slot"],
|
|
140
|
+
[
|
|
141
|
+
"value",
|
|
142
|
+
"defaultValue",
|
|
143
|
+
"onChange",
|
|
144
|
+
"minValue",
|
|
145
|
+
"maxValue",
|
|
146
|
+
"step",
|
|
147
|
+
"locale",
|
|
148
|
+
"formatOptions",
|
|
149
|
+
],
|
|
150
|
+
[
|
|
151
|
+
"label",
|
|
152
|
+
"aria-label",
|
|
153
|
+
"aria-labelledby",
|
|
154
|
+
"aria-describedby",
|
|
155
|
+
"isDisabled",
|
|
156
|
+
"isReadOnly",
|
|
157
|
+
"isRequired",
|
|
158
|
+
"isInvalid",
|
|
159
|
+
"description",
|
|
160
|
+
"errorMessage",
|
|
161
|
+
"id",
|
|
162
|
+
"autoFocus",
|
|
163
|
+
"name",
|
|
164
|
+
"form",
|
|
165
|
+
"onFocus",
|
|
166
|
+
"onBlur",
|
|
167
|
+
"onFocusChange",
|
|
168
|
+
"onKeyDown",
|
|
169
|
+
"onKeyUp",
|
|
170
|
+
"onPaste",
|
|
171
|
+
"onCopy",
|
|
172
|
+
"onCut",
|
|
173
|
+
],
|
|
160
174
|
);
|
|
161
175
|
|
|
162
|
-
// Create number field state
|
|
163
176
|
const state = createNumberFieldState({
|
|
164
177
|
get value() {
|
|
165
178
|
return stateProps.value;
|
|
@@ -193,21 +206,84 @@ export function NumberField(props: NumberFieldProps): JSX.Element {
|
|
|
193
206
|
},
|
|
194
207
|
});
|
|
195
208
|
|
|
196
|
-
// Ref for the input
|
|
197
209
|
let inputRef: HTMLInputElement | undefined;
|
|
210
|
+
const setInputRef = (el: HTMLInputElement) => {
|
|
211
|
+
inputRef = el;
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
const numberFieldAria = createNumberField(
|
|
215
|
+
{
|
|
216
|
+
get label() {
|
|
217
|
+
return ariaProps.label;
|
|
218
|
+
},
|
|
219
|
+
get "aria-label"() {
|
|
220
|
+
return ariaProps["aria-label"];
|
|
221
|
+
},
|
|
222
|
+
get "aria-labelledby"() {
|
|
223
|
+
return ariaProps["aria-labelledby"];
|
|
224
|
+
},
|
|
225
|
+
get "aria-describedby"() {
|
|
226
|
+
return ariaProps["aria-describedby"];
|
|
227
|
+
},
|
|
228
|
+
get isDisabled() {
|
|
229
|
+
return ariaProps.isDisabled;
|
|
230
|
+
},
|
|
231
|
+
get isReadOnly() {
|
|
232
|
+
return ariaProps.isReadOnly;
|
|
233
|
+
},
|
|
234
|
+
get isRequired() {
|
|
235
|
+
return ariaProps.isRequired;
|
|
236
|
+
},
|
|
237
|
+
get isInvalid() {
|
|
238
|
+
return ariaProps.isInvalid;
|
|
239
|
+
},
|
|
240
|
+
get description() {
|
|
241
|
+
return ariaProps.description;
|
|
242
|
+
},
|
|
243
|
+
get errorMessage() {
|
|
244
|
+
return ariaProps.errorMessage;
|
|
245
|
+
},
|
|
246
|
+
get id() {
|
|
247
|
+
return ariaProps.id;
|
|
248
|
+
},
|
|
249
|
+
get autoFocus() {
|
|
250
|
+
return ariaProps.autoFocus;
|
|
251
|
+
},
|
|
252
|
+
get name() {
|
|
253
|
+
return ariaProps.name;
|
|
254
|
+
},
|
|
255
|
+
get form() {
|
|
256
|
+
return ariaProps.form;
|
|
257
|
+
},
|
|
258
|
+
get onFocus() {
|
|
259
|
+
return ariaProps.onFocus;
|
|
260
|
+
},
|
|
261
|
+
get onBlur() {
|
|
262
|
+
return ariaProps.onBlur;
|
|
263
|
+
},
|
|
264
|
+
get onFocusChange() {
|
|
265
|
+
return ariaProps.onFocusChange;
|
|
266
|
+
},
|
|
267
|
+
get onKeyDown() {
|
|
268
|
+
return ariaProps.onKeyDown;
|
|
269
|
+
},
|
|
270
|
+
get onKeyUp() {
|
|
271
|
+
return ariaProps.onKeyUp;
|
|
272
|
+
},
|
|
273
|
+
get onPaste() {
|
|
274
|
+
return ariaProps.onPaste;
|
|
275
|
+
},
|
|
276
|
+
get onCopy() {
|
|
277
|
+
return ariaProps.onCopy;
|
|
278
|
+
},
|
|
279
|
+
get onCut() {
|
|
280
|
+
return ariaProps.onCut;
|
|
281
|
+
},
|
|
282
|
+
},
|
|
283
|
+
state,
|
|
284
|
+
() => inputRef ?? null,
|
|
285
|
+
);
|
|
198
286
|
|
|
199
|
-
// Create number field aria props
|
|
200
|
-
const {
|
|
201
|
-
labelProps,
|
|
202
|
-
groupProps,
|
|
203
|
-
inputProps,
|
|
204
|
-
incrementButtonProps,
|
|
205
|
-
decrementButtonProps,
|
|
206
|
-
descriptionProps,
|
|
207
|
-
errorMessageProps,
|
|
208
|
-
} = createNumberField(ariaProps, state, () => inputRef ?? null);
|
|
209
|
-
|
|
210
|
-
// Render props values
|
|
211
287
|
const renderValues = createMemo<NumberFieldRenderProps>(() => ({
|
|
212
288
|
isDisabled: ariaProps.isDisabled ?? false,
|
|
213
289
|
isInvalid: ariaProps.isInvalid ?? false,
|
|
@@ -216,65 +292,117 @@ export function NumberField(props: NumberFieldProps): JSX.Element {
|
|
|
216
292
|
value: state.numberValue(),
|
|
217
293
|
}));
|
|
218
294
|
|
|
219
|
-
// Resolve render props
|
|
220
295
|
const renderProps = useRenderProps(
|
|
221
296
|
{
|
|
222
297
|
children: props.children,
|
|
223
298
|
class: local.class,
|
|
224
299
|
style: local.style,
|
|
225
|
-
defaultClassName:
|
|
300
|
+
defaultClassName: "solidaria-NumberField",
|
|
226
301
|
},
|
|
227
|
-
renderValues
|
|
302
|
+
renderValues,
|
|
228
303
|
);
|
|
229
304
|
|
|
230
|
-
|
|
231
|
-
|
|
305
|
+
const childRenderValues: NumberFieldRenderProps = {
|
|
306
|
+
get isDisabled() {
|
|
307
|
+
return ariaProps.isDisabled ?? false;
|
|
308
|
+
},
|
|
309
|
+
get isInvalid() {
|
|
310
|
+
return ariaProps.isInvalid ?? false;
|
|
311
|
+
},
|
|
312
|
+
get isRequired() {
|
|
313
|
+
return ariaProps.isRequired ?? false;
|
|
314
|
+
},
|
|
315
|
+
get isReadOnly() {
|
|
316
|
+
return ariaProps.isReadOnly ?? false;
|
|
317
|
+
},
|
|
318
|
+
get value() {
|
|
319
|
+
return state.numberValue();
|
|
320
|
+
},
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
const fieldChildren = () => {
|
|
324
|
+
const children = local.children;
|
|
325
|
+
return typeof children === "function" ? children(childRenderValues) : children;
|
|
326
|
+
};
|
|
327
|
+
|
|
328
|
+
const domProps = createMemo(() =>
|
|
329
|
+
filterDOMProps(rest as Record<string, unknown>, { global: true }),
|
|
330
|
+
);
|
|
331
|
+
|
|
332
|
+
const contextValue: NumberFieldContextValue = {
|
|
333
|
+
state,
|
|
334
|
+
get inputProps() {
|
|
335
|
+
return numberFieldAria.inputProps;
|
|
336
|
+
},
|
|
337
|
+
get incrementButtonProps() {
|
|
338
|
+
return numberFieldAria.incrementButtonProps;
|
|
339
|
+
},
|
|
340
|
+
get decrementButtonProps() {
|
|
341
|
+
return numberFieldAria.decrementButtonProps;
|
|
342
|
+
},
|
|
343
|
+
get labelProps() {
|
|
344
|
+
return numberFieldAria.labelProps;
|
|
345
|
+
},
|
|
346
|
+
get groupProps() {
|
|
347
|
+
return numberFieldAria.groupProps;
|
|
348
|
+
},
|
|
349
|
+
get descriptionProps() {
|
|
350
|
+
return numberFieldAria.descriptionProps;
|
|
351
|
+
},
|
|
352
|
+
get errorMessageProps() {
|
|
353
|
+
return numberFieldAria.errorMessageProps;
|
|
354
|
+
},
|
|
355
|
+
get isDisabled() {
|
|
356
|
+
return ariaProps.isDisabled ?? false;
|
|
357
|
+
},
|
|
358
|
+
get isInvalid() {
|
|
359
|
+
return ariaProps.isInvalid ?? false;
|
|
360
|
+
},
|
|
361
|
+
get isRequired() {
|
|
362
|
+
return ariaProps.isRequired ?? false;
|
|
363
|
+
},
|
|
364
|
+
get isReadOnly() {
|
|
365
|
+
return ariaProps.isReadOnly ?? false;
|
|
366
|
+
},
|
|
367
|
+
setInputRef,
|
|
368
|
+
};
|
|
232
369
|
|
|
233
370
|
return (
|
|
234
|
-
<
|
|
235
|
-
value={
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
>
|
|
250
|
-
<div
|
|
251
|
-
{...domProps()}
|
|
252
|
-
class={renderProps.class()}
|
|
253
|
-
style={renderProps.style()}
|
|
254
|
-
data-disabled={ariaProps.isDisabled || undefined}
|
|
255
|
-
data-invalid={ariaProps.isInvalid || undefined}
|
|
256
|
-
data-required={ariaProps.isRequired || undefined}
|
|
257
|
-
data-readonly={ariaProps.isReadOnly || undefined}
|
|
258
|
-
>
|
|
259
|
-
{renderProps.renderChildren()}
|
|
260
|
-
</div>
|
|
261
|
-
</NumberFieldContext.Provider>
|
|
371
|
+
<NumberFieldStateContext.Provider value={state}>
|
|
372
|
+
<NumberFieldContext.Provider value={contextValue}>
|
|
373
|
+
<div
|
|
374
|
+
{...domProps()}
|
|
375
|
+
class={renderProps.class()}
|
|
376
|
+
style={renderProps.style()}
|
|
377
|
+
data-disabled={ariaProps.isDisabled || undefined}
|
|
378
|
+
data-invalid={ariaProps.isInvalid || undefined}
|
|
379
|
+
data-required={ariaProps.isRequired || undefined}
|
|
380
|
+
data-readonly={ariaProps.isReadOnly || undefined}
|
|
381
|
+
>
|
|
382
|
+
{fieldChildren()}
|
|
383
|
+
</div>
|
|
384
|
+
</NumberFieldContext.Provider>
|
|
385
|
+
</NumberFieldStateContext.Provider>
|
|
262
386
|
);
|
|
263
387
|
}
|
|
264
388
|
|
|
265
389
|
/**
|
|
266
390
|
* The label for a number field.
|
|
267
391
|
*/
|
|
268
|
-
export function NumberFieldLabel(props: {
|
|
392
|
+
export function NumberFieldLabel(props: {
|
|
393
|
+
children?: JSX.Element;
|
|
394
|
+
class?: string;
|
|
395
|
+
style?: JSX.CSSProperties;
|
|
396
|
+
}): JSX.Element {
|
|
269
397
|
const context = useContext(NumberFieldContext);
|
|
270
398
|
if (!context) {
|
|
271
|
-
throw new Error(
|
|
399
|
+
throw new Error("NumberFieldLabel must be used within a NumberField");
|
|
272
400
|
}
|
|
273
401
|
|
|
274
402
|
return (
|
|
275
403
|
<span
|
|
276
404
|
{...context.labelProps}
|
|
277
|
-
class={props.class ??
|
|
405
|
+
class={props.class ?? "solidaria-NumberField-label"}
|
|
278
406
|
style={props.style}
|
|
279
407
|
>
|
|
280
408
|
{props.children}
|
|
@@ -285,13 +413,13 @@ export function NumberFieldLabel(props: { children?: JSX.Element; class?: string
|
|
|
285
413
|
/**
|
|
286
414
|
* The input group for a number field (contains input and buttons).
|
|
287
415
|
*/
|
|
288
|
-
export function NumberFieldGroup(props:
|
|
416
|
+
export function NumberFieldGroup(props: JSX.HTMLAttributes<HTMLDivElement>): JSX.Element {
|
|
417
|
+
const [local, domProps] = splitProps(props, ["children", "class", "style"]);
|
|
289
418
|
const context = useContext(NumberFieldContext);
|
|
290
419
|
if (!context) {
|
|
291
|
-
throw new Error(
|
|
420
|
+
throw new Error("NumberFieldGroup must be used within a NumberField");
|
|
292
421
|
}
|
|
293
422
|
|
|
294
|
-
// Extract ref to avoid type issues
|
|
295
423
|
const cleanGroupProps = () => {
|
|
296
424
|
const { ref: _ref, ...rest } = context.groupProps as Record<string, unknown>;
|
|
297
425
|
return rest;
|
|
@@ -299,11 +427,12 @@ export function NumberFieldGroup(props: { children?: JSX.Element; class?: string
|
|
|
299
427
|
|
|
300
428
|
return (
|
|
301
429
|
<div
|
|
430
|
+
{...domProps}
|
|
302
431
|
{...cleanGroupProps()}
|
|
303
|
-
class={
|
|
304
|
-
style={
|
|
432
|
+
class={local.class ?? "solidaria-NumberField-group"}
|
|
433
|
+
style={local.style}
|
|
305
434
|
>
|
|
306
|
-
{
|
|
435
|
+
{local.children}
|
|
307
436
|
</div>
|
|
308
437
|
);
|
|
309
438
|
}
|
|
@@ -312,24 +441,21 @@ export function NumberFieldGroup(props: { children?: JSX.Element; class?: string
|
|
|
312
441
|
* The input element for a number field.
|
|
313
442
|
*/
|
|
314
443
|
export function NumberFieldInput(props: NumberFieldInputProps): JSX.Element {
|
|
315
|
-
const [local] = splitProps(props, [
|
|
444
|
+
const [local, domProps] = splitProps(props, ["class", "style", "slot"]);
|
|
316
445
|
|
|
317
446
|
const context = useContext(NumberFieldContext);
|
|
318
447
|
if (!context) {
|
|
319
|
-
throw new Error(
|
|
448
|
+
throw new Error("NumberFieldInput must be used within a NumberField");
|
|
320
449
|
}
|
|
321
450
|
|
|
322
|
-
// Create focus ring
|
|
323
451
|
const { isFocused, isFocusVisible, focusProps } = createFocusRing();
|
|
324
452
|
|
|
325
|
-
// Create hover
|
|
326
453
|
const { isHovered, hoverProps } = createHover({
|
|
327
454
|
get isDisabled() {
|
|
328
455
|
return context.isDisabled;
|
|
329
456
|
},
|
|
330
457
|
});
|
|
331
458
|
|
|
332
|
-
// Render props values
|
|
333
459
|
const renderValues = createMemo<NumberFieldInputRenderProps>(() => ({
|
|
334
460
|
isFocused: isFocused(),
|
|
335
461
|
isFocusVisible: isFocusVisible(),
|
|
@@ -338,19 +464,17 @@ export function NumberFieldInput(props: NumberFieldInputProps): JSX.Element {
|
|
|
338
464
|
isInvalid: context.isInvalid,
|
|
339
465
|
}));
|
|
340
466
|
|
|
341
|
-
// Resolve render props
|
|
342
467
|
const renderProps = useRenderProps(
|
|
343
468
|
{
|
|
344
469
|
class: local.class,
|
|
345
470
|
style: local.style,
|
|
346
|
-
defaultClassName:
|
|
471
|
+
defaultClassName: "solidaria-NumberField-input",
|
|
347
472
|
},
|
|
348
|
-
renderValues
|
|
473
|
+
renderValues,
|
|
349
474
|
);
|
|
350
475
|
|
|
351
|
-
// Remove ref from spread props
|
|
352
476
|
const cleanInputProps = () => {
|
|
353
|
-
const { ref: _ref, ...rest } = context.inputProps as Record<string, unknown>;
|
|
477
|
+
const { ref: _ref, onInput: _onInput, ...rest } = context.inputProps as Record<string, unknown>;
|
|
354
478
|
return rest;
|
|
355
479
|
};
|
|
356
480
|
const cleanFocusProps = () => {
|
|
@@ -361,12 +485,23 @@ export function NumberFieldInput(props: NumberFieldInputProps): JSX.Element {
|
|
|
361
485
|
const { ref: _ref, ...rest } = hoverProps as Record<string, unknown>;
|
|
362
486
|
return rest;
|
|
363
487
|
};
|
|
488
|
+
const handleInput: JSX.EventHandler<HTMLInputElement, InputEvent> = (event) => {
|
|
489
|
+
(
|
|
490
|
+
context.inputProps as unknown as { onInput?: JSX.EventHandler<HTMLInputElement, InputEvent> }
|
|
491
|
+
).onInput?.(event);
|
|
492
|
+
(domProps as unknown as { onInput?: JSX.EventHandler<HTMLInputElement, InputEvent> }).onInput?.(
|
|
493
|
+
event,
|
|
494
|
+
);
|
|
495
|
+
};
|
|
364
496
|
|
|
365
497
|
return (
|
|
366
498
|
<input
|
|
499
|
+
{...domProps}
|
|
500
|
+
ref={context.setInputRef}
|
|
367
501
|
{...cleanInputProps()}
|
|
368
502
|
{...cleanFocusProps()}
|
|
369
503
|
{...cleanHoverProps()}
|
|
504
|
+
onInput={handleInput}
|
|
370
505
|
class={renderProps.class()}
|
|
371
506
|
style={renderProps.style()}
|
|
372
507
|
data-focused={isFocused() || undefined}
|
|
@@ -382,57 +517,47 @@ export function NumberFieldInput(props: NumberFieldInputProps): JSX.Element {
|
|
|
382
517
|
* The increment button for a number field.
|
|
383
518
|
*/
|
|
384
519
|
export function NumberFieldIncrementButton(props: NumberFieldIncrementButtonProps): JSX.Element {
|
|
385
|
-
const [local] = splitProps(props, [
|
|
520
|
+
const [local, domProps] = splitProps(props, ["class", "style", "slot", "children"]);
|
|
386
521
|
|
|
387
522
|
const context = useContext(NumberFieldContext);
|
|
388
523
|
if (!context) {
|
|
389
|
-
throw new Error(
|
|
524
|
+
throw new Error("NumberFieldIncrementButton must be used within a NumberField");
|
|
390
525
|
}
|
|
391
526
|
|
|
392
|
-
|
|
393
|
-
|
|
527
|
+
const isDisabled = () => context.isDisabled || !context.state.canIncrement();
|
|
528
|
+
|
|
529
|
+
const buttonAria = createButton({
|
|
530
|
+
...(context.incrementButtonProps as Record<string, unknown>),
|
|
531
|
+
elementType: "div",
|
|
394
532
|
get isDisabled() {
|
|
395
|
-
return
|
|
396
|
-
},
|
|
397
|
-
onPress: () => {
|
|
398
|
-
context.state.increment();
|
|
533
|
+
return isDisabled();
|
|
399
534
|
},
|
|
400
535
|
});
|
|
401
536
|
|
|
402
|
-
// Create hover
|
|
403
537
|
const { isHovered, hoverProps } = createHover({
|
|
404
538
|
get isDisabled() {
|
|
405
539
|
return context.isDisabled || !context.state.canIncrement();
|
|
406
540
|
},
|
|
407
541
|
});
|
|
408
542
|
|
|
409
|
-
const isDisabled = () => context.isDisabled || !context.state.canIncrement();
|
|
410
|
-
|
|
411
|
-
// Render props values
|
|
412
543
|
const renderValues = createMemo<NumberFieldButtonRenderProps>(() => ({
|
|
413
|
-
isPressed: isPressed(),
|
|
544
|
+
isPressed: buttonAria.isPressed(),
|
|
414
545
|
isHovered: isHovered(),
|
|
415
546
|
isDisabled: isDisabled(),
|
|
416
547
|
}));
|
|
417
548
|
|
|
418
|
-
// Resolve render props
|
|
419
549
|
const renderProps = useRenderProps(
|
|
420
550
|
{
|
|
421
551
|
children: props.children,
|
|
422
552
|
class: local.class,
|
|
423
553
|
style: local.style,
|
|
424
|
-
defaultClassName:
|
|
554
|
+
defaultClassName: "solidaria-NumberField-increment",
|
|
425
555
|
},
|
|
426
|
-
renderValues
|
|
556
|
+
renderValues,
|
|
427
557
|
);
|
|
428
558
|
|
|
429
|
-
// Remove ref from spread props
|
|
430
559
|
const cleanButtonProps = () => {
|
|
431
|
-
const { ref: _ref, ...rest } =
|
|
432
|
-
return rest;
|
|
433
|
-
};
|
|
434
|
-
const cleanPressProps = () => {
|
|
435
|
-
const { ref: _ref, ...rest } = pressProps as Record<string, unknown>;
|
|
560
|
+
const { ref: _ref, ...rest } = buttonAria.buttonProps as Record<string, unknown>;
|
|
436
561
|
return rest;
|
|
437
562
|
};
|
|
438
563
|
const cleanHoverProps = () => {
|
|
@@ -441,18 +566,19 @@ export function NumberFieldIncrementButton(props: NumberFieldIncrementButtonProp
|
|
|
441
566
|
};
|
|
442
567
|
|
|
443
568
|
return (
|
|
444
|
-
<
|
|
569
|
+
<div
|
|
570
|
+
{...domProps}
|
|
445
571
|
{...cleanButtonProps()}
|
|
446
|
-
{...cleanPressProps()}
|
|
447
572
|
{...cleanHoverProps()}
|
|
573
|
+
aria-disabled={isDisabled() || undefined}
|
|
448
574
|
class={renderProps.class()}
|
|
449
575
|
style={renderProps.style()}
|
|
450
|
-
data-pressed={isPressed() || undefined}
|
|
576
|
+
data-pressed={buttonAria.isPressed() || undefined}
|
|
451
577
|
data-hovered={isHovered() || undefined}
|
|
452
578
|
data-disabled={isDisabled() || undefined}
|
|
453
579
|
>
|
|
454
580
|
{renderProps.renderChildren()}
|
|
455
|
-
</
|
|
581
|
+
</div>
|
|
456
582
|
);
|
|
457
583
|
}
|
|
458
584
|
|
|
@@ -460,57 +586,47 @@ export function NumberFieldIncrementButton(props: NumberFieldIncrementButtonProp
|
|
|
460
586
|
* The decrement button for a number field.
|
|
461
587
|
*/
|
|
462
588
|
export function NumberFieldDecrementButton(props: NumberFieldDecrementButtonProps): JSX.Element {
|
|
463
|
-
const [local] = splitProps(props, [
|
|
589
|
+
const [local, domProps] = splitProps(props, ["class", "style", "slot", "children"]);
|
|
464
590
|
|
|
465
591
|
const context = useContext(NumberFieldContext);
|
|
466
592
|
if (!context) {
|
|
467
|
-
throw new Error(
|
|
593
|
+
throw new Error("NumberFieldDecrementButton must be used within a NumberField");
|
|
468
594
|
}
|
|
469
595
|
|
|
470
|
-
|
|
471
|
-
|
|
596
|
+
const isDisabled = () => context.isDisabled || !context.state.canDecrement();
|
|
597
|
+
|
|
598
|
+
const buttonAria = createButton({
|
|
599
|
+
...(context.decrementButtonProps as Record<string, unknown>),
|
|
600
|
+
elementType: "div",
|
|
472
601
|
get isDisabled() {
|
|
473
|
-
return
|
|
474
|
-
},
|
|
475
|
-
onPress: () => {
|
|
476
|
-
context.state.decrement();
|
|
602
|
+
return isDisabled();
|
|
477
603
|
},
|
|
478
604
|
});
|
|
479
605
|
|
|
480
|
-
// Create hover
|
|
481
606
|
const { isHovered, hoverProps } = createHover({
|
|
482
607
|
get isDisabled() {
|
|
483
608
|
return context.isDisabled || !context.state.canDecrement();
|
|
484
609
|
},
|
|
485
610
|
});
|
|
486
611
|
|
|
487
|
-
const isDisabled = () => context.isDisabled || !context.state.canDecrement();
|
|
488
|
-
|
|
489
|
-
// Render props values
|
|
490
612
|
const renderValues = createMemo<NumberFieldButtonRenderProps>(() => ({
|
|
491
|
-
isPressed: isPressed(),
|
|
613
|
+
isPressed: buttonAria.isPressed(),
|
|
492
614
|
isHovered: isHovered(),
|
|
493
615
|
isDisabled: isDisabled(),
|
|
494
616
|
}));
|
|
495
617
|
|
|
496
|
-
// Resolve render props
|
|
497
618
|
const renderProps = useRenderProps(
|
|
498
619
|
{
|
|
499
620
|
children: props.children,
|
|
500
621
|
class: local.class,
|
|
501
622
|
style: local.style,
|
|
502
|
-
defaultClassName:
|
|
623
|
+
defaultClassName: "solidaria-NumberField-decrement",
|
|
503
624
|
},
|
|
504
|
-
renderValues
|
|
625
|
+
renderValues,
|
|
505
626
|
);
|
|
506
627
|
|
|
507
|
-
// Remove ref from spread props
|
|
508
628
|
const cleanButtonProps = () => {
|
|
509
|
-
const { ref: _ref, ...rest } =
|
|
510
|
-
return rest;
|
|
511
|
-
};
|
|
512
|
-
const cleanPressProps = () => {
|
|
513
|
-
const { ref: _ref, ...rest } = pressProps as Record<string, unknown>;
|
|
629
|
+
const { ref: _ref, ...rest } = buttonAria.buttonProps as Record<string, unknown>;
|
|
514
630
|
return rest;
|
|
515
631
|
};
|
|
516
632
|
const cleanHoverProps = () => {
|
|
@@ -519,22 +635,22 @@ export function NumberFieldDecrementButton(props: NumberFieldDecrementButtonProp
|
|
|
519
635
|
};
|
|
520
636
|
|
|
521
637
|
return (
|
|
522
|
-
<
|
|
638
|
+
<div
|
|
639
|
+
{...domProps}
|
|
523
640
|
{...cleanButtonProps()}
|
|
524
|
-
{...cleanPressProps()}
|
|
525
641
|
{...cleanHoverProps()}
|
|
642
|
+
aria-disabled={isDisabled() || undefined}
|
|
526
643
|
class={renderProps.class()}
|
|
527
644
|
style={renderProps.style()}
|
|
528
|
-
data-pressed={isPressed() || undefined}
|
|
645
|
+
data-pressed={buttonAria.isPressed() || undefined}
|
|
529
646
|
data-hovered={isHovered() || undefined}
|
|
530
647
|
data-disabled={isDisabled() || undefined}
|
|
531
648
|
>
|
|
532
649
|
{renderProps.renderChildren()}
|
|
533
|
-
</
|
|
650
|
+
</div>
|
|
534
651
|
);
|
|
535
652
|
}
|
|
536
653
|
|
|
537
|
-
// Attach sub-components
|
|
538
654
|
NumberField.Label = NumberFieldLabel;
|
|
539
655
|
NumberField.Group = NumberFieldGroup;
|
|
540
656
|
NumberField.Input = NumberFieldInput;
|