@proyecto-viviana/solidaria-components 0.2.9 → 0.3.1
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 +39 -272
- package/dist/ActionBar.d.ts +21 -13
- package/dist/ActionBar.d.ts.map +1 -1
- package/dist/ActionGroup.d.ts +8 -8
- package/dist/ActionGroup.d.ts.map +1 -1
- package/dist/Alert.d.ts +5 -5
- package/dist/Alert.d.ts.map +1 -1
- package/dist/Autocomplete.d.ts +5 -5
- package/dist/Autocomplete.d.ts.map +1 -1
- package/dist/Breadcrumbs.d.ts +18 -7
- package/dist/Breadcrumbs.d.ts.map +1 -1
- package/dist/Button.d.ts +24 -5
- package/dist/Button.d.ts.map +1 -1
- package/dist/Calendar.d.ts +38 -7
- package/dist/Calendar.d.ts.map +1 -1
- package/dist/Checkbox.d.ts +32 -7
- package/dist/Checkbox.d.ts.map +1 -1
- package/dist/Collection.d.ts +19 -14
- package/dist/Collection.d.ts.map +1 -1
- package/dist/Color.d.ts +103 -14
- package/dist/Color.d.ts.map +1 -1
- package/dist/ColorEditor.d.ts +6 -6
- package/dist/ColorEditor.d.ts.map +1 -1
- package/dist/ComboBox.d.ts +85 -19
- package/dist/ComboBox.d.ts.map +1 -1
- package/dist/ContextualHelpTrigger.d.ts +2 -2
- package/dist/ContextualHelpTrigger.d.ts.map +1 -1
- package/dist/DateField.d.ts +8 -6
- package/dist/DateField.d.ts.map +1 -1
- package/dist/DatePicker.d.ts +53 -22
- 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 +23 -5
- package/dist/Disclosure.d.ts.map +1 -1
- package/dist/DragAndDrop.d.ts +6 -6
- package/dist/DragAndDrop.d.ts.map +1 -1
- package/dist/DragPreview.d.ts +2 -2
- package/dist/DragPreview.d.ts.map +1 -1
- package/dist/DropZone.d.ts +4 -4
- package/dist/DropZone.d.ts.map +1 -1
- package/dist/FieldError.d.ts +9 -5
- package/dist/FieldError.d.ts.map +1 -1
- package/dist/FileTrigger.d.ts +3 -3
- package/dist/FileTrigger.d.ts.map +1 -1
- package/dist/Focusable.d.ts +2 -2
- package/dist/Focusable.d.ts.map +1 -1
- package/dist/Form.d.ts +18 -4
- package/dist/Form.d.ts.map +1 -1
- package/dist/GridList.d.ts +32 -12
- 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 +5 -5
- package/dist/Icon.d.ts.map +1 -1
- package/dist/Keyboard.d.ts +1 -1
- 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 +32 -12
- package/dist/ListBox.d.ts.map +1 -1
- package/dist/ListDropTargetDelegate.d.ts +6 -6
- package/dist/ListDropTargetDelegate.d.ts.map +1 -1
- package/dist/Menu.d.ts +65 -14
- package/dist/Menu.d.ts.map +1 -1
- package/dist/Meter.d.ts +3 -3
- package/dist/Meter.d.ts.map +1 -1
- package/dist/Modal.d.ts +5 -5
- package/dist/Modal.d.ts.map +1 -1
- package/dist/NumberField.d.ts +8 -12
- package/dist/NumberField.d.ts.map +1 -1
- package/dist/Popover.d.ts +28 -5
- package/dist/Popover.d.ts.map +1 -1
- package/dist/Pressable.d.ts +2 -2
- package/dist/Pressable.d.ts.map +1 -1
- package/dist/ProgressBar.d.ts +5 -3
- 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 +34 -7
- package/dist/RangeCalendar.d.ts.map +1 -1
- package/dist/RouterProvider.d.ts +2 -2
- package/dist/RouterProvider.d.ts.map +1 -1
- package/dist/SearchField.d.ts +23 -20
- package/dist/SearchField.d.ts.map +1 -1
- package/dist/Select.d.ts +41 -11
- package/dist/Select.d.ts.map +1 -1
- package/dist/SelectionIndicator.d.ts +3 -3
- package/dist/SelectionIndicator.d.ts.map +1 -1
- package/dist/Separator.d.ts +9 -3
- package/dist/Separator.d.ts.map +1 -1
- package/dist/SharedElementTransition.d.ts +6 -4
- package/dist/SharedElementTransition.d.ts.map +1 -1
- package/dist/Slider.d.ts +12 -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 +187 -23
- package/dist/Table.d.ts.map +1 -1
- package/dist/Tabs.d.ts +45 -9
- package/dist/Tabs.d.ts.map +1 -1
- package/dist/TagGroup.d.ts +12 -10
- package/dist/TagGroup.d.ts.map +1 -1
- package/dist/Text.d.ts +2 -2
- package/dist/TextField.d.ts +15 -11
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TimeField.d.ts +6 -6
- 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 +11 -5
- package/dist/ToggleButton.d.ts.map +1 -1
- package/dist/ToggleButtonGroup.d.ts +7 -7
- package/dist/ToggleButtonGroup.d.ts.map +1 -1
- package/dist/Toolbar.d.ts +7 -3
- package/dist/Toolbar.d.ts.map +1 -1
- package/dist/Tooltip.d.ts +50 -8
- package/dist/Tooltip.d.ts.map +1 -1
- package/dist/Tree.d.ts +66 -17
- package/dist/Tree.d.ts.map +1 -1
- package/dist/Virtualizer.d.ts +12 -12
- package/dist/Virtualizer.d.ts.map +1 -1
- package/dist/VirtualizerLayouts.d.ts +2 -2
- package/dist/VirtualizerLayouts.d.ts.map +1 -1
- package/dist/VisuallyHidden.d.ts +1 -1
- package/dist/VisuallyHidden.d.ts.map +1 -1
- package/dist/contexts.d.ts +5 -1
- package/dist/contexts.d.ts.map +1 -1
- package/dist/index.d.ts +73 -71
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +23253 -18564
- package/dist/index.js.map +1 -1
- package/dist/index.jsx +18116 -0
- package/dist/index.jsx.map +1 -0
- package/dist/useDragAndDrop.d.ts +13 -13
- package/dist/useDragAndDrop.d.ts.map +1 -1
- package/dist/utils.d.ts +2 -2
- package/dist/utils.d.ts.map +1 -1
- package/dist/virtualizer/Layout.d.ts +1 -1
- package/dist/virtualizer/Layout.d.ts.map +1 -1
- package/package.json +31 -32
- package/src/ActionBar.tsx +75 -72
- package/src/ActionGroup.tsx +53 -61
- package/src/Alert.tsx +17 -42
- package/src/Autocomplete.tsx +39 -44
- package/src/Breadcrumbs.tsx +149 -80
- package/src/Button.tsx +267 -70
- package/src/Calendar.tsx +218 -138
- package/src/Checkbox.tsx +413 -121
- package/src/Collection.tsx +67 -58
- package/src/Color.tsx +803 -380
- package/src/ColorEditor.tsx +131 -149
- package/src/ComboBox.tsx +414 -249
- package/src/ContextualHelpTrigger.tsx +86 -74
- package/src/DateField.tsx +185 -91
- package/src/DatePicker.tsx +524 -213
- package/src/DateRangePickerContext.tsx +44 -0
- package/src/Dialog.tsx +156 -118
- package/src/Disclosure.tsx +127 -80
- package/src/DragAndDrop.tsx +60 -54
- package/src/DragPreview.tsx +13 -11
- package/src/DropZone.tsx +42 -22
- package/src/FieldError.tsx +45 -23
- package/src/FileTrigger.tsx +19 -19
- package/src/Focusable.tsx +21 -24
- package/src/Form.tsx +71 -16
- package/src/GridList.tsx +273 -197
- package/src/HiddenDateInput.tsx +153 -0
- package/src/HiddenTimeInput.tsx +133 -0
- package/src/Icon.tsx +22 -43
- package/src/Keyboard.tsx +3 -3
- package/src/Landmark.tsx +37 -63
- package/src/Link.tsx +125 -75
- package/src/ListBox.tsx +332 -233
- package/src/ListDropTargetDelegate.ts +81 -80
- package/src/Menu.tsx +1023 -274
- package/src/Meter.tsx +38 -56
- package/src/Modal.tsx +251 -176
- package/src/NumberField.tsx +139 -143
- package/src/Popover.tsx +396 -234
- package/src/Pressable.tsx +21 -21
- package/src/ProgressBar.tsx +48 -57
- package/src/RadioGroup.tsx +524 -122
- package/src/RangeCalendar.tsx +157 -90
- package/src/RouterProvider.tsx +30 -47
- package/src/SearchField.tsx +362 -143
- package/src/Select.tsx +656 -233
- package/src/SelectionIndicator.tsx +18 -15
- package/src/Separator.tsx +47 -49
- package/src/SharedElementTransition.tsx +103 -97
- package/src/Slider.tsx +138 -98
- package/src/StepList.tsx +272 -0
- package/src/Switch.tsx +93 -46
- package/src/Table.tsx +1308 -342
- package/src/Tabs.tsx +324 -103
- package/src/TagGroup.tsx +139 -126
- package/src/Text.tsx +3 -3
- package/src/TextField.tsx +389 -79
- package/src/TimeField.tsx +136 -76
- package/src/Toast.tsx +216 -158
- package/src/ToggleButton.tsx +47 -37
- package/src/ToggleButtonGroup.tsx +39 -34
- package/src/Toolbar.tsx +54 -69
- package/src/Tooltip.tsx +387 -119
- package/src/Tree.tsx +651 -368
- package/src/Virtualizer.tsx +208 -180
- package/src/VirtualizerLayouts.ts +45 -30
- package/src/VisuallyHidden.tsx +19 -19
- package/src/contexts.ts +29 -37
- package/src/index.ts +110 -195
- package/src/useDragAndDrop.ts +87 -71
- package/src/utils.tsx +49 -60
- package/src/virtualizer/Layout.ts +14 -22
- package/dist/index.ssr.js +0 -16996
- package/dist/index.ssr.js.map +0 -1
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>;
|
|
@@ -146,45 +130,49 @@ interface NumberFieldContextValue {
|
|
|
146
130
|
export const NumberFieldContext = createContext<NumberFieldContextValue | null>(null);
|
|
147
131
|
export const NumberFieldStateContext = createContext<NumberFieldState | null>(null);
|
|
148
132
|
|
|
149
|
-
// ============================================
|
|
150
|
-
// COMPONENTS
|
|
151
|
-
// ============================================
|
|
152
|
-
|
|
153
133
|
/**
|
|
154
134
|
* A number field allows a user to enter a number and increment/decrement the value.
|
|
155
135
|
*/
|
|
156
136
|
export function NumberField(props: NumberFieldProps): JSX.Element {
|
|
157
137
|
const [local, stateProps, ariaProps, rest] = splitProps(
|
|
158
138
|
props,
|
|
159
|
-
[
|
|
160
|
-
[
|
|
139
|
+
["children", "class", "style", "slot"],
|
|
140
|
+
[
|
|
141
|
+
"value",
|
|
142
|
+
"defaultValue",
|
|
143
|
+
"onChange",
|
|
144
|
+
"minValue",
|
|
145
|
+
"maxValue",
|
|
146
|
+
"step",
|
|
147
|
+
"locale",
|
|
148
|
+
"formatOptions",
|
|
149
|
+
],
|
|
161
150
|
[
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
]
|
|
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
|
+
],
|
|
185
174
|
);
|
|
186
175
|
|
|
187
|
-
// Create number field state
|
|
188
176
|
const state = createNumberFieldState({
|
|
189
177
|
get value() {
|
|
190
178
|
return stateProps.value;
|
|
@@ -218,26 +206,24 @@ export function NumberField(props: NumberFieldProps): JSX.Element {
|
|
|
218
206
|
},
|
|
219
207
|
});
|
|
220
208
|
|
|
221
|
-
// Ref for the input
|
|
222
209
|
let inputRef: HTMLInputElement | undefined;
|
|
223
210
|
const setInputRef = (el: HTMLInputElement) => {
|
|
224
211
|
inputRef = el;
|
|
225
212
|
};
|
|
226
213
|
|
|
227
|
-
// Create number field aria props
|
|
228
214
|
const numberFieldAria = createNumberField(
|
|
229
215
|
{
|
|
230
216
|
get label() {
|
|
231
217
|
return ariaProps.label;
|
|
232
218
|
},
|
|
233
|
-
get
|
|
234
|
-
return ariaProps[
|
|
219
|
+
get "aria-label"() {
|
|
220
|
+
return ariaProps["aria-label"];
|
|
235
221
|
},
|
|
236
|
-
get
|
|
237
|
-
return ariaProps[
|
|
222
|
+
get "aria-labelledby"() {
|
|
223
|
+
return ariaProps["aria-labelledby"];
|
|
238
224
|
},
|
|
239
|
-
get
|
|
240
|
-
return ariaProps[
|
|
225
|
+
get "aria-describedby"() {
|
|
226
|
+
return ariaProps["aria-describedby"];
|
|
241
227
|
},
|
|
242
228
|
get isDisabled() {
|
|
243
229
|
return ariaProps.isDisabled;
|
|
@@ -295,10 +281,9 @@ export function NumberField(props: NumberFieldProps): JSX.Element {
|
|
|
295
281
|
},
|
|
296
282
|
},
|
|
297
283
|
state,
|
|
298
|
-
() => inputRef ?? null
|
|
284
|
+
() => inputRef ?? null,
|
|
299
285
|
);
|
|
300
286
|
|
|
301
|
-
// Render props values
|
|
302
287
|
const renderValues = createMemo<NumberFieldRenderProps>(() => ({
|
|
303
288
|
isDisabled: ariaProps.isDisabled ?? false,
|
|
304
289
|
isInvalid: ariaProps.isInvalid ?? false,
|
|
@@ -307,19 +292,42 @@ export function NumberField(props: NumberFieldProps): JSX.Element {
|
|
|
307
292
|
value: state.numberValue(),
|
|
308
293
|
}));
|
|
309
294
|
|
|
310
|
-
// Resolve render props
|
|
311
295
|
const renderProps = useRenderProps(
|
|
312
296
|
{
|
|
313
297
|
children: props.children,
|
|
314
298
|
class: local.class,
|
|
315
299
|
style: local.style,
|
|
316
|
-
defaultClassName:
|
|
300
|
+
defaultClassName: "solidaria-NumberField",
|
|
317
301
|
},
|
|
318
|
-
renderValues
|
|
302
|
+
renderValues,
|
|
319
303
|
);
|
|
320
304
|
|
|
321
|
-
|
|
322
|
-
|
|
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
|
+
);
|
|
323
331
|
|
|
324
332
|
const contextValue: NumberFieldContextValue = {
|
|
325
333
|
state,
|
|
@@ -371,7 +379,7 @@ export function NumberField(props: NumberFieldProps): JSX.Element {
|
|
|
371
379
|
data-required={ariaProps.isRequired || undefined}
|
|
372
380
|
data-readonly={ariaProps.isReadOnly || undefined}
|
|
373
381
|
>
|
|
374
|
-
{
|
|
382
|
+
{fieldChildren()}
|
|
375
383
|
</div>
|
|
376
384
|
</NumberFieldContext.Provider>
|
|
377
385
|
</NumberFieldStateContext.Provider>
|
|
@@ -381,16 +389,20 @@ export function NumberField(props: NumberFieldProps): JSX.Element {
|
|
|
381
389
|
/**
|
|
382
390
|
* The label for a number field.
|
|
383
391
|
*/
|
|
384
|
-
export function NumberFieldLabel(props: {
|
|
392
|
+
export function NumberFieldLabel(props: {
|
|
393
|
+
children?: JSX.Element;
|
|
394
|
+
class?: string;
|
|
395
|
+
style?: JSX.CSSProperties;
|
|
396
|
+
}): JSX.Element {
|
|
385
397
|
const context = useContext(NumberFieldContext);
|
|
386
398
|
if (!context) {
|
|
387
|
-
throw new Error(
|
|
399
|
+
throw new Error("NumberFieldLabel must be used within a NumberField");
|
|
388
400
|
}
|
|
389
401
|
|
|
390
402
|
return (
|
|
391
403
|
<span
|
|
392
404
|
{...context.labelProps}
|
|
393
|
-
class={props.class ??
|
|
405
|
+
class={props.class ?? "solidaria-NumberField-label"}
|
|
394
406
|
style={props.style}
|
|
395
407
|
>
|
|
396
408
|
{props.children}
|
|
@@ -401,13 +413,13 @@ export function NumberFieldLabel(props: { children?: JSX.Element; class?: string
|
|
|
401
413
|
/**
|
|
402
414
|
* The input group for a number field (contains input and buttons).
|
|
403
415
|
*/
|
|
404
|
-
export function NumberFieldGroup(props:
|
|
416
|
+
export function NumberFieldGroup(props: JSX.HTMLAttributes<HTMLDivElement>): JSX.Element {
|
|
417
|
+
const [local, domProps] = splitProps(props, ["children", "class", "style"]);
|
|
405
418
|
const context = useContext(NumberFieldContext);
|
|
406
419
|
if (!context) {
|
|
407
|
-
throw new Error(
|
|
420
|
+
throw new Error("NumberFieldGroup must be used within a NumberField");
|
|
408
421
|
}
|
|
409
422
|
|
|
410
|
-
// Extract ref to avoid type issues
|
|
411
423
|
const cleanGroupProps = () => {
|
|
412
424
|
const { ref: _ref, ...rest } = context.groupProps as Record<string, unknown>;
|
|
413
425
|
return rest;
|
|
@@ -415,11 +427,12 @@ export function NumberFieldGroup(props: { children?: JSX.Element; class?: string
|
|
|
415
427
|
|
|
416
428
|
return (
|
|
417
429
|
<div
|
|
430
|
+
{...domProps}
|
|
418
431
|
{...cleanGroupProps()}
|
|
419
|
-
class={
|
|
420
|
-
style={
|
|
432
|
+
class={local.class ?? "solidaria-NumberField-group"}
|
|
433
|
+
style={local.style}
|
|
421
434
|
>
|
|
422
|
-
{
|
|
435
|
+
{local.children}
|
|
423
436
|
</div>
|
|
424
437
|
);
|
|
425
438
|
}
|
|
@@ -428,24 +441,21 @@ export function NumberFieldGroup(props: { children?: JSX.Element; class?: string
|
|
|
428
441
|
* The input element for a number field.
|
|
429
442
|
*/
|
|
430
443
|
export function NumberFieldInput(props: NumberFieldInputProps): JSX.Element {
|
|
431
|
-
const [local, domProps] = splitProps(props, [
|
|
444
|
+
const [local, domProps] = splitProps(props, ["class", "style", "slot"]);
|
|
432
445
|
|
|
433
446
|
const context = useContext(NumberFieldContext);
|
|
434
447
|
if (!context) {
|
|
435
|
-
throw new Error(
|
|
448
|
+
throw new Error("NumberFieldInput must be used within a NumberField");
|
|
436
449
|
}
|
|
437
450
|
|
|
438
|
-
// Create focus ring
|
|
439
451
|
const { isFocused, isFocusVisible, focusProps } = createFocusRing();
|
|
440
452
|
|
|
441
|
-
// Create hover
|
|
442
453
|
const { isHovered, hoverProps } = createHover({
|
|
443
454
|
get isDisabled() {
|
|
444
455
|
return context.isDisabled;
|
|
445
456
|
},
|
|
446
457
|
});
|
|
447
458
|
|
|
448
|
-
// Render props values
|
|
449
459
|
const renderValues = createMemo<NumberFieldInputRenderProps>(() => ({
|
|
450
460
|
isFocused: isFocused(),
|
|
451
461
|
isFocusVisible: isFocusVisible(),
|
|
@@ -454,19 +464,17 @@ export function NumberFieldInput(props: NumberFieldInputProps): JSX.Element {
|
|
|
454
464
|
isInvalid: context.isInvalid,
|
|
455
465
|
}));
|
|
456
466
|
|
|
457
|
-
// Resolve render props
|
|
458
467
|
const renderProps = useRenderProps(
|
|
459
468
|
{
|
|
460
469
|
class: local.class,
|
|
461
470
|
style: local.style,
|
|
462
|
-
defaultClassName:
|
|
471
|
+
defaultClassName: "solidaria-NumberField-input",
|
|
463
472
|
},
|
|
464
|
-
renderValues
|
|
473
|
+
renderValues,
|
|
465
474
|
);
|
|
466
475
|
|
|
467
|
-
// Remove ref from spread props
|
|
468
476
|
const cleanInputProps = () => {
|
|
469
|
-
const { ref: _ref, ...rest } = context.inputProps as Record<string, unknown>;
|
|
477
|
+
const { ref: _ref, onInput: _onInput, ...rest } = context.inputProps as Record<string, unknown>;
|
|
470
478
|
return rest;
|
|
471
479
|
};
|
|
472
480
|
const cleanFocusProps = () => {
|
|
@@ -477,6 +485,14 @@ export function NumberFieldInput(props: NumberFieldInputProps): JSX.Element {
|
|
|
477
485
|
const { ref: _ref, ...rest } = hoverProps as Record<string, unknown>;
|
|
478
486
|
return rest;
|
|
479
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
|
+
};
|
|
480
496
|
|
|
481
497
|
return (
|
|
482
498
|
<input
|
|
@@ -485,6 +501,7 @@ export function NumberFieldInput(props: NumberFieldInputProps): JSX.Element {
|
|
|
485
501
|
{...cleanInputProps()}
|
|
486
502
|
{...cleanFocusProps()}
|
|
487
503
|
{...cleanHoverProps()}
|
|
504
|
+
onInput={handleInput}
|
|
488
505
|
class={renderProps.class()}
|
|
489
506
|
style={renderProps.style()}
|
|
490
507
|
data-focused={isFocused() || undefined}
|
|
@@ -500,57 +517,47 @@ export function NumberFieldInput(props: NumberFieldInputProps): JSX.Element {
|
|
|
500
517
|
* The increment button for a number field.
|
|
501
518
|
*/
|
|
502
519
|
export function NumberFieldIncrementButton(props: NumberFieldIncrementButtonProps): JSX.Element {
|
|
503
|
-
const [local, domProps] = splitProps(props, [
|
|
520
|
+
const [local, domProps] = splitProps(props, ["class", "style", "slot", "children"]);
|
|
504
521
|
|
|
505
522
|
const context = useContext(NumberFieldContext);
|
|
506
523
|
if (!context) {
|
|
507
|
-
throw new Error(
|
|
524
|
+
throw new Error("NumberFieldIncrementButton must be used within a NumberField");
|
|
508
525
|
}
|
|
509
526
|
|
|
510
|
-
|
|
511
|
-
|
|
527
|
+
const isDisabled = () => context.isDisabled || !context.state.canIncrement();
|
|
528
|
+
|
|
529
|
+
const buttonAria = createButton({
|
|
530
|
+
...(context.incrementButtonProps as Record<string, unknown>),
|
|
531
|
+
elementType: "div",
|
|
512
532
|
get isDisabled() {
|
|
513
|
-
return
|
|
514
|
-
},
|
|
515
|
-
onPress: () => {
|
|
516
|
-
(context.incrementButtonProps.onClick as ((e?: MouseEvent) => void) | undefined)?.();
|
|
533
|
+
return isDisabled();
|
|
517
534
|
},
|
|
518
535
|
});
|
|
519
536
|
|
|
520
|
-
// Create hover
|
|
521
537
|
const { isHovered, hoverProps } = createHover({
|
|
522
538
|
get isDisabled() {
|
|
523
539
|
return context.isDisabled || !context.state.canIncrement();
|
|
524
540
|
},
|
|
525
541
|
});
|
|
526
542
|
|
|
527
|
-
const isDisabled = () => context.isDisabled || !context.state.canIncrement();
|
|
528
|
-
|
|
529
|
-
// Render props values
|
|
530
543
|
const renderValues = createMemo<NumberFieldButtonRenderProps>(() => ({
|
|
531
|
-
isPressed: isPressed(),
|
|
544
|
+
isPressed: buttonAria.isPressed(),
|
|
532
545
|
isHovered: isHovered(),
|
|
533
546
|
isDisabled: isDisabled(),
|
|
534
547
|
}));
|
|
535
548
|
|
|
536
|
-
// Resolve render props
|
|
537
549
|
const renderProps = useRenderProps(
|
|
538
550
|
{
|
|
539
551
|
children: props.children,
|
|
540
552
|
class: local.class,
|
|
541
553
|
style: local.style,
|
|
542
|
-
defaultClassName:
|
|
554
|
+
defaultClassName: "solidaria-NumberField-increment",
|
|
543
555
|
},
|
|
544
|
-
renderValues
|
|
556
|
+
renderValues,
|
|
545
557
|
);
|
|
546
558
|
|
|
547
|
-
// Remove ref from spread props
|
|
548
559
|
const cleanButtonProps = () => {
|
|
549
|
-
const { ref: _ref, ...rest } =
|
|
550
|
-
return rest;
|
|
551
|
-
};
|
|
552
|
-
const cleanPressProps = () => {
|
|
553
|
-
const { ref: _ref, ...rest } = pressProps as Record<string, unknown>;
|
|
560
|
+
const { ref: _ref, ...rest } = buttonAria.buttonProps as Record<string, unknown>;
|
|
554
561
|
return rest;
|
|
555
562
|
};
|
|
556
563
|
const cleanHoverProps = () => {
|
|
@@ -559,19 +566,19 @@ export function NumberFieldIncrementButton(props: NumberFieldIncrementButtonProp
|
|
|
559
566
|
};
|
|
560
567
|
|
|
561
568
|
return (
|
|
562
|
-
<
|
|
569
|
+
<div
|
|
563
570
|
{...domProps}
|
|
564
571
|
{...cleanButtonProps()}
|
|
565
|
-
{...cleanPressProps()}
|
|
566
572
|
{...cleanHoverProps()}
|
|
573
|
+
aria-disabled={isDisabled() || undefined}
|
|
567
574
|
class={renderProps.class()}
|
|
568
575
|
style={renderProps.style()}
|
|
569
|
-
data-pressed={isPressed() || undefined}
|
|
576
|
+
data-pressed={buttonAria.isPressed() || undefined}
|
|
570
577
|
data-hovered={isHovered() || undefined}
|
|
571
578
|
data-disabled={isDisabled() || undefined}
|
|
572
579
|
>
|
|
573
580
|
{renderProps.renderChildren()}
|
|
574
|
-
</
|
|
581
|
+
</div>
|
|
575
582
|
);
|
|
576
583
|
}
|
|
577
584
|
|
|
@@ -579,57 +586,47 @@ export function NumberFieldIncrementButton(props: NumberFieldIncrementButtonProp
|
|
|
579
586
|
* The decrement button for a number field.
|
|
580
587
|
*/
|
|
581
588
|
export function NumberFieldDecrementButton(props: NumberFieldDecrementButtonProps): JSX.Element {
|
|
582
|
-
const [local, domProps] = splitProps(props, [
|
|
589
|
+
const [local, domProps] = splitProps(props, ["class", "style", "slot", "children"]);
|
|
583
590
|
|
|
584
591
|
const context = useContext(NumberFieldContext);
|
|
585
592
|
if (!context) {
|
|
586
|
-
throw new Error(
|
|
593
|
+
throw new Error("NumberFieldDecrementButton must be used within a NumberField");
|
|
587
594
|
}
|
|
588
595
|
|
|
589
|
-
|
|
590
|
-
|
|
596
|
+
const isDisabled = () => context.isDisabled || !context.state.canDecrement();
|
|
597
|
+
|
|
598
|
+
const buttonAria = createButton({
|
|
599
|
+
...(context.decrementButtonProps as Record<string, unknown>),
|
|
600
|
+
elementType: "div",
|
|
591
601
|
get isDisabled() {
|
|
592
|
-
return
|
|
593
|
-
},
|
|
594
|
-
onPress: () => {
|
|
595
|
-
(context.decrementButtonProps.onClick as ((e?: MouseEvent) => void) | undefined)?.();
|
|
602
|
+
return isDisabled();
|
|
596
603
|
},
|
|
597
604
|
});
|
|
598
605
|
|
|
599
|
-
// Create hover
|
|
600
606
|
const { isHovered, hoverProps } = createHover({
|
|
601
607
|
get isDisabled() {
|
|
602
608
|
return context.isDisabled || !context.state.canDecrement();
|
|
603
609
|
},
|
|
604
610
|
});
|
|
605
611
|
|
|
606
|
-
const isDisabled = () => context.isDisabled || !context.state.canDecrement();
|
|
607
|
-
|
|
608
|
-
// Render props values
|
|
609
612
|
const renderValues = createMemo<NumberFieldButtonRenderProps>(() => ({
|
|
610
|
-
isPressed: isPressed(),
|
|
613
|
+
isPressed: buttonAria.isPressed(),
|
|
611
614
|
isHovered: isHovered(),
|
|
612
615
|
isDisabled: isDisabled(),
|
|
613
616
|
}));
|
|
614
617
|
|
|
615
|
-
// Resolve render props
|
|
616
618
|
const renderProps = useRenderProps(
|
|
617
619
|
{
|
|
618
620
|
children: props.children,
|
|
619
621
|
class: local.class,
|
|
620
622
|
style: local.style,
|
|
621
|
-
defaultClassName:
|
|
623
|
+
defaultClassName: "solidaria-NumberField-decrement",
|
|
622
624
|
},
|
|
623
|
-
renderValues
|
|
625
|
+
renderValues,
|
|
624
626
|
);
|
|
625
627
|
|
|
626
|
-
// Remove ref from spread props
|
|
627
628
|
const cleanButtonProps = () => {
|
|
628
|
-
const { ref: _ref, ...rest } =
|
|
629
|
-
return rest;
|
|
630
|
-
};
|
|
631
|
-
const cleanPressProps = () => {
|
|
632
|
-
const { ref: _ref, ...rest } = pressProps as Record<string, unknown>;
|
|
629
|
+
const { ref: _ref, ...rest } = buttonAria.buttonProps as Record<string, unknown>;
|
|
633
630
|
return rest;
|
|
634
631
|
};
|
|
635
632
|
const cleanHoverProps = () => {
|
|
@@ -638,23 +635,22 @@ export function NumberFieldDecrementButton(props: NumberFieldDecrementButtonProp
|
|
|
638
635
|
};
|
|
639
636
|
|
|
640
637
|
return (
|
|
641
|
-
<
|
|
638
|
+
<div
|
|
642
639
|
{...domProps}
|
|
643
640
|
{...cleanButtonProps()}
|
|
644
|
-
{...cleanPressProps()}
|
|
645
641
|
{...cleanHoverProps()}
|
|
642
|
+
aria-disabled={isDisabled() || undefined}
|
|
646
643
|
class={renderProps.class()}
|
|
647
644
|
style={renderProps.style()}
|
|
648
|
-
data-pressed={isPressed() || undefined}
|
|
645
|
+
data-pressed={buttonAria.isPressed() || undefined}
|
|
649
646
|
data-hovered={isHovered() || undefined}
|
|
650
647
|
data-disabled={isDisabled() || undefined}
|
|
651
648
|
>
|
|
652
649
|
{renderProps.renderChildren()}
|
|
653
|
-
</
|
|
650
|
+
</div>
|
|
654
651
|
);
|
|
655
652
|
}
|
|
656
653
|
|
|
657
|
-
// Attach sub-components
|
|
658
654
|
NumberField.Label = NumberFieldLabel;
|
|
659
655
|
NumberField.Group = NumberFieldGroup;
|
|
660
656
|
NumberField.Input = NumberFieldInput;
|