@saas-ui/forms 2.5.1 → 2.5.2
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/CHANGELOG.md +8 -0
- package/dist/index.d.mts +26 -25
- package/dist/index.d.ts +26 -25
- package/dist/index.js +162 -160
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +84 -82
- package/dist/index.mjs.map +1 -1
- package/dist/yup/index.d.mts +26 -26
- package/dist/yup/index.d.ts +26 -26
- package/dist/zod/index.d.mts +26 -26
- package/dist/zod/index.d.ts +26 -26
- package/package.json +2 -2
- package/src/base-field.tsx +1 -1
- package/src/create-field.tsx +1 -1
- package/src/create-form.tsx +7 -1
- package/src/create-step-form.tsx +10 -1
- package/src/default-fields.tsx +0 -2
- package/src/field.tsx +2 -1
- package/src/fields-context.tsx +8 -8
- package/src/form-context.tsx +1 -1
- package/src/types.ts +10 -10
package/dist/index.mjs
CHANGED
@@ -56,7 +56,20 @@ FormValue.displayName = "FormValue";
|
|
56
56
|
import * as React6 from "react";
|
57
57
|
|
58
58
|
// src/fields-context.tsx
|
59
|
-
import
|
59
|
+
import React2 from "react";
|
60
|
+
import { jsx as jsx3 } from "react/jsx-runtime";
|
61
|
+
var FieldsContext = React2.createContext(null);
|
62
|
+
var FieldsProvider = (props) => {
|
63
|
+
return /* @__PURE__ */ jsx3(FieldsContext.Provider, { value: props.value, children: props.children });
|
64
|
+
};
|
65
|
+
var useFieldsContext = () => {
|
66
|
+
return React2.useContext(FieldsContext);
|
67
|
+
};
|
68
|
+
var useField = (type, fallback) => {
|
69
|
+
var _a;
|
70
|
+
const context = React2.useContext(FieldsContext);
|
71
|
+
return ((_a = context == null ? void 0 : context.fields) == null ? void 0 : _a[type]) || fallback;
|
72
|
+
};
|
60
73
|
|
61
74
|
// src/default-fields.tsx
|
62
75
|
import {
|
@@ -82,15 +95,15 @@ import {
|
|
82
95
|
InputGroup
|
83
96
|
} from "@chakra-ui/react";
|
84
97
|
import { ChevronDownIcon, ChevronUpIcon } from "@saas-ui/core";
|
85
|
-
import { jsx as
|
86
|
-
var Input = forwardRef((props, ref) => /* @__PURE__ */
|
98
|
+
import { jsx as jsx4, jsxs as jsxs2 } from "react/jsx-runtime";
|
99
|
+
var Input = forwardRef((props, ref) => /* @__PURE__ */ jsx4(NumberInputField, { ref, ...props }));
|
87
100
|
Input.displayName = "NumberInputField";
|
88
101
|
Input.id = "Input";
|
89
102
|
var NumberInput = forwardRef((props, ref) => {
|
90
103
|
const {
|
91
104
|
hideStepper = false,
|
92
|
-
incrementIcon = /* @__PURE__ */
|
93
|
-
decrementIcon = /* @__PURE__ */
|
105
|
+
incrementIcon = /* @__PURE__ */ jsx4(ChevronUpIcon, {}),
|
106
|
+
decrementIcon = /* @__PURE__ */ jsx4(ChevronDownIcon, {}),
|
94
107
|
leftAddon,
|
95
108
|
rightAddon,
|
96
109
|
placeholder,
|
@@ -101,12 +114,12 @@ var NumberInput = forwardRef((props, ref) => {
|
|
101
114
|
return /* @__PURE__ */ jsxs2(ChakraNumberInput, { ...rest, ref, children: [
|
102
115
|
/* @__PURE__ */ jsxs2(InputGroup, { children: [
|
103
116
|
leftAddon,
|
104
|
-
/* @__PURE__ */
|
117
|
+
/* @__PURE__ */ jsx4(Input, { ...fieldProps }),
|
105
118
|
rightAddon
|
106
119
|
] }),
|
107
120
|
!hideStepper && !rightAddon ? /* @__PURE__ */ jsxs2(NumberInputStepper, { children: [
|
108
|
-
/* @__PURE__ */
|
109
|
-
/* @__PURE__ */
|
121
|
+
/* @__PURE__ */ jsx4(NumberIncrementStepper, { children: incrementIcon }),
|
122
|
+
/* @__PURE__ */ jsx4(NumberDecrementStepper, { children: decrementIcon })
|
110
123
|
] }) : null
|
111
124
|
] });
|
112
125
|
});
|
@@ -123,17 +136,17 @@ import {
|
|
123
136
|
forwardRef as forwardRef2,
|
124
137
|
InputRightElement as InputRightElement2
|
125
138
|
} from "@chakra-ui/react";
|
126
|
-
import { jsx as
|
139
|
+
import { jsx as jsx5 } from "react/jsx-runtime";
|
127
140
|
var InputRightButton = forwardRef2(
|
128
141
|
(props, ref) => {
|
129
|
-
return /* @__PURE__ */
|
142
|
+
return /* @__PURE__ */ jsx5(InputRightElement2, { w: "auto", px: "1", py: "1", alignItems: "stretch", children: /* @__PURE__ */ jsx5(Button, { ref, height: "auto", ...props }) });
|
130
143
|
}
|
131
144
|
);
|
132
145
|
InputRightButton.id = "InputRightElement";
|
133
146
|
InputRightButton.displayName = "InputRightButton";
|
134
147
|
|
135
148
|
// src/password-input/password-input.tsx
|
136
|
-
import { jsx as
|
149
|
+
import { jsx as jsx6, jsxs as jsxs3 } from "react/jsx-runtime";
|
137
150
|
var PasswordInput = forwardRef3(
|
138
151
|
(props, ref) => {
|
139
152
|
const {
|
@@ -152,9 +165,9 @@ var PasswordInput = forwardRef3(
|
|
152
165
|
const label = show ? "Hide password" : "Show password";
|
153
166
|
let icon;
|
154
167
|
if (show) {
|
155
|
-
icon = viewIcon || /* @__PURE__ */
|
168
|
+
icon = viewIcon || /* @__PURE__ */ jsx6(ViewIcon, {});
|
156
169
|
} else {
|
157
|
-
icon = viewOffIcon || /* @__PURE__ */
|
170
|
+
icon = viewOffIcon || /* @__PURE__ */ jsx6(ViewOffIcon, {});
|
158
171
|
}
|
159
172
|
const groupProps = {
|
160
173
|
width: w || width,
|
@@ -163,7 +176,7 @@ var PasswordInput = forwardRef3(
|
|
163
176
|
};
|
164
177
|
return /* @__PURE__ */ jsxs3(InputGroup2, { ...groupProps, children: [
|
165
178
|
leftAddon,
|
166
|
-
/* @__PURE__ */
|
179
|
+
/* @__PURE__ */ jsx6(
|
167
180
|
Input2,
|
168
181
|
{
|
169
182
|
...inputProps,
|
@@ -172,7 +185,7 @@ var PasswordInput = forwardRef3(
|
|
172
185
|
autoComplete: show ? "off" : autoComplete
|
173
186
|
}
|
174
187
|
),
|
175
|
-
/* @__PURE__ */
|
188
|
+
/* @__PURE__ */ jsx6(
|
176
189
|
InputRightButton,
|
177
190
|
{
|
178
191
|
onClick: handleClick,
|
@@ -195,17 +208,17 @@ import {
|
|
195
208
|
} from "@chakra-ui/react";
|
196
209
|
|
197
210
|
// src/utils.ts
|
198
|
-
import * as
|
211
|
+
import * as React4 from "react";
|
199
212
|
var mapNestedFields = (name, children) => {
|
200
|
-
return
|
201
|
-
if (
|
213
|
+
return React4.Children.map(children, (child) => {
|
214
|
+
if (React4.isValidElement(child) && child.props.name) {
|
202
215
|
let childName = child.props.name;
|
203
216
|
if (childName.includes(".")) {
|
204
217
|
childName = childName.replace(/^.*\.(.*)/, "$1");
|
205
218
|
} else if (childName.includes(".$")) {
|
206
219
|
childName = childName.replace(/^.*\.\$(.*)/, "$1");
|
207
220
|
}
|
208
|
-
return
|
221
|
+
return React4.cloneElement(child, {
|
209
222
|
...child.props,
|
210
223
|
name: `${name}.${childName}`
|
211
224
|
});
|
@@ -226,13 +239,13 @@ var mapOptions = (options) => {
|
|
226
239
|
};
|
227
240
|
|
228
241
|
// src/radio/radio-input.tsx
|
229
|
-
import { jsx as
|
242
|
+
import { jsx as jsx7 } from "react/jsx-runtime";
|
230
243
|
var RadioInput = forwardRef4(
|
231
244
|
({ options: optionsProp, spacing, direction, ...props }, ref) => {
|
232
245
|
const { onBlur, onChange, ...groupProps } = props;
|
233
246
|
const options = mapOptions(optionsProp);
|
234
|
-
return /* @__PURE__ */
|
235
|
-
return /* @__PURE__ */
|
247
|
+
return /* @__PURE__ */ jsx7(RadioGroup, { onChange, ...groupProps, children: /* @__PURE__ */ jsx7(Stack, { spacing, direction, children: options.map(({ value, label, ...radioProps }, i) => {
|
248
|
+
return /* @__PURE__ */ jsx7(
|
236
249
|
Radio,
|
237
250
|
{
|
238
251
|
onBlur,
|
@@ -272,7 +285,7 @@ import {
|
|
272
285
|
useFormControl
|
273
286
|
} from "@chakra-ui/react";
|
274
287
|
import { createContext as createContext2 } from "@chakra-ui/react-utils";
|
275
|
-
import
|
288
|
+
import React5 from "react";
|
276
289
|
var [SelectStylesProvider, useSelectStyles] = createStylesContext("SuiSelect");
|
277
290
|
var [SelectProvider, useSelectContext] = createContext2({
|
278
291
|
strict: true
|
@@ -295,14 +308,14 @@ var useSelect = (props) => {
|
|
295
308
|
onChange
|
296
309
|
});
|
297
310
|
const controlProps = useFormControl({ name });
|
298
|
-
const options =
|
311
|
+
const options = React5.useMemo(
|
299
312
|
() => optionsProp && mapOptions(optionsProp),
|
300
313
|
[optionsProp]
|
301
314
|
);
|
302
315
|
const handleChange = (value2) => {
|
303
316
|
setCurrentValue(value2);
|
304
317
|
};
|
305
|
-
const getDisplayValue =
|
318
|
+
const getDisplayValue = React5.useCallback(
|
306
319
|
(value2) => {
|
307
320
|
if (!options) {
|
308
321
|
return value2;
|
@@ -316,7 +329,7 @@ var useSelect = (props) => {
|
|
316
329
|
},
|
317
330
|
[options]
|
318
331
|
);
|
319
|
-
const displayValue =
|
332
|
+
const displayValue = React5.useMemo(
|
320
333
|
() => currentValue ? (Array.isArray(currentValue) ? currentValue : [currentValue]).map(
|
321
334
|
getDisplayValue
|
322
335
|
) : [],
|
@@ -337,7 +350,7 @@ var useSelect = (props) => {
|
|
337
350
|
};
|
338
351
|
|
339
352
|
// src/select/select.tsx
|
340
|
-
import { jsx as
|
353
|
+
import { jsx as jsx8, jsxs as jsxs4 } from "react/jsx-runtime";
|
341
354
|
var SelectButton = forwardRef5(
|
342
355
|
(props, ref) => {
|
343
356
|
var _a, _b, _c, _d, _e;
|
@@ -359,7 +372,7 @@ var SelectButton = forwardRef5(
|
|
359
372
|
onBlur,
|
360
373
|
onFocus
|
361
374
|
} = context || {};
|
362
|
-
const { rightIcon = /* @__PURE__ */
|
375
|
+
const { rightIcon = /* @__PURE__ */ jsx8(ChevronDownIcon2, {}), ...rest } = props;
|
363
376
|
const focusStyles = (_a = styles.field) == null ? void 0 : _a._focusVisible;
|
364
377
|
const readOnlyStyles = (_b = styles.field) == null ? void 0 : _b._readOnly;
|
365
378
|
const invalid = (_c = styles.field) == null ? void 0 : _c._invalid;
|
@@ -382,7 +395,7 @@ var SelectButton = forwardRef5(
|
|
382
395
|
...props.sx
|
383
396
|
};
|
384
397
|
const buttonProps = useMenuButton(rest, ref);
|
385
|
-
return /* @__PURE__ */
|
398
|
+
return /* @__PURE__ */ jsx8(
|
386
399
|
Button2,
|
387
400
|
{
|
388
401
|
...buttonProps,
|
@@ -396,7 +409,7 @@ var SelectButton = forwardRef5(
|
|
396
409
|
"data-focus": dataAttr(isFocused),
|
397
410
|
"data-required": dataAttr(isRequired),
|
398
411
|
rightIcon,
|
399
|
-
children: /* @__PURE__ */
|
412
|
+
children: /* @__PURE__ */ jsx8(
|
400
413
|
chakra.span,
|
401
414
|
{
|
402
415
|
__css: {
|
@@ -421,9 +434,9 @@ var Select = forwardRef5((props, ref) => {
|
|
421
434
|
const menuProps = omitThemingProps(rest);
|
422
435
|
const context = useSelect(props);
|
423
436
|
const { value, controlProps } = context;
|
424
|
-
return /* @__PURE__ */
|
437
|
+
return /* @__PURE__ */ jsx8(SelectProvider, { value: context, children: /* @__PURE__ */ jsx8(SelectStylesProvider, { value: styles, children: /* @__PURE__ */ jsx8(Menu, { ...menuProps, closeOnSelect: !multiple, children: /* @__PURE__ */ jsxs4(chakra.div, { className: cx("sui-select"), children: [
|
425
438
|
children,
|
426
|
-
/* @__PURE__ */
|
439
|
+
/* @__PURE__ */ jsx8(
|
427
440
|
chakra.input,
|
428
441
|
{
|
429
442
|
...controlProps,
|
@@ -438,21 +451,21 @@ var Select = forwardRef5((props, ref) => {
|
|
438
451
|
});
|
439
452
|
var SelectList = (props) => {
|
440
453
|
const { defaultValue, value, options, multiple, onChange } = useSelectContext();
|
441
|
-
return /* @__PURE__ */
|
454
|
+
return /* @__PURE__ */ jsx8(MenuList, { maxH: "100vh", overflowY: "auto", ...props, children: /* @__PURE__ */ jsx8(
|
442
455
|
MenuOptionGroup,
|
443
456
|
{
|
444
457
|
defaultValue: defaultValue || value,
|
445
458
|
value,
|
446
459
|
onChange,
|
447
460
|
type: multiple ? "checkbox" : "radio",
|
448
|
-
children: options ? options.map(({ value: value2, label, ...rest }, i) => /* @__PURE__ */
|
461
|
+
children: options ? options.map(({ value: value2, label, ...rest }, i) => /* @__PURE__ */ jsx8(SelectOption, { value: value2, ...rest, children: label || value2 }, i)) : props.children
|
449
462
|
}
|
450
463
|
) });
|
451
464
|
};
|
452
465
|
Select.displayName = "Select";
|
453
466
|
var SelectOption = forwardRef5(
|
454
467
|
(props, ref) => {
|
455
|
-
return /* @__PURE__ */
|
468
|
+
return /* @__PURE__ */ jsx8(MenuItemOption, { ref, ...props });
|
456
469
|
}
|
457
470
|
);
|
458
471
|
SelectOption.id = "MenuItemOption";
|
@@ -463,11 +476,11 @@ import {
|
|
463
476
|
forwardRef as forwardRef6,
|
464
477
|
Select as ChakraSelect
|
465
478
|
} from "@chakra-ui/react";
|
466
|
-
import { jsx as
|
479
|
+
import { jsx as jsx9 } from "react/jsx-runtime";
|
467
480
|
var NativeSelect = forwardRef6(
|
468
481
|
({ options, children, ...props }, ref) => {
|
469
|
-
return /* @__PURE__ */
|
470
|
-
return /* @__PURE__ */
|
482
|
+
return /* @__PURE__ */ jsx9(ChakraSelect, { ref, ...props, children: children || (options == null ? void 0 : options.map(({ value, label }) => {
|
483
|
+
return /* @__PURE__ */ jsx9("option", { value, children: label || value }, value);
|
471
484
|
})) });
|
472
485
|
}
|
473
486
|
);
|
@@ -477,7 +490,7 @@ NativeSelect.displayName = "NativeSelect";
|
|
477
490
|
import { Controller } from "react-hook-form";
|
478
491
|
import { forwardRef as forwardRef7, useMergeRefs } from "@chakra-ui/react";
|
479
492
|
import { callAllHandlers } from "@chakra-ui/utils";
|
480
|
-
import { splitProps as splitProps2 } from "@saas-ui/core
|
493
|
+
import { splitProps as splitProps2 } from "@saas-ui/core";
|
481
494
|
|
482
495
|
// src/base-field.tsx
|
483
496
|
import { get } from "react-hook-form";
|
@@ -489,7 +502,7 @@ import {
|
|
489
502
|
FormErrorMessage
|
490
503
|
} from "@chakra-ui/react";
|
491
504
|
import { splitProps } from "@saas-ui/core";
|
492
|
-
import { jsx as
|
505
|
+
import { jsx as jsx10, jsxs as jsxs5 } from "react/jsx-runtime";
|
493
506
|
var getError = (name, formState) => {
|
494
507
|
return get(formState.errors, name);
|
495
508
|
};
|
@@ -518,18 +531,18 @@ var useBaseField = (props) => {
|
|
518
531
|
var BaseField = (props) => {
|
519
532
|
const { controlProps, label, help, hideLabel, error } = useBaseField(props);
|
520
533
|
return /* @__PURE__ */ jsxs5(FormControl2, { ...controlProps, isInvalid: !!error, children: [
|
521
|
-
label && !hideLabel ? /* @__PURE__ */
|
534
|
+
label && !hideLabel ? /* @__PURE__ */ jsx10(FormLabel2, { children: label }) : null,
|
522
535
|
/* @__PURE__ */ jsxs5(Box, { children: [
|
523
536
|
props.children,
|
524
|
-
help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */
|
525
|
-
(error == null ? void 0 : error.message) && /* @__PURE__ */
|
537
|
+
help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */ jsx10(FormHelperText, { children: help }) : null,
|
538
|
+
(error == null ? void 0 : error.message) && /* @__PURE__ */ jsx10(FormErrorMessage, { children: error == null ? void 0 : error.message })
|
526
539
|
] })
|
527
540
|
] });
|
528
541
|
};
|
529
542
|
BaseField.displayName = "BaseField";
|
530
543
|
|
531
544
|
// src/create-field.tsx
|
532
|
-
import { jsx as
|
545
|
+
import { jsx as jsx11 } from "react/jsx-runtime";
|
533
546
|
var _createField = (InputComponent, { displayName, hideLabel, getBaseField: getBaseFieldProp }) => {
|
534
547
|
const Field2 = forwardRef7((props, ref) => {
|
535
548
|
var _a;
|
@@ -554,7 +567,7 @@ var _createField = (InputComponent, { displayName, hideLabel, getBaseField: getB
|
|
554
567
|
"help"
|
555
568
|
].concat(extraProps)
|
556
569
|
);
|
557
|
-
return /* @__PURE__ */
|
570
|
+
return /* @__PURE__ */ jsx11(BaseField2, { ...props, children: /* @__PURE__ */ jsx11(
|
558
571
|
InputComponent,
|
559
572
|
{
|
560
573
|
ref,
|
@@ -574,13 +587,13 @@ var withControlledInput = (InputComponent) => {
|
|
574
587
|
({ name, rules, ...inputProps }, ref) => {
|
575
588
|
const { control } = useFormContext();
|
576
589
|
const onChange = inputProps.onChange;
|
577
|
-
return /* @__PURE__ */
|
590
|
+
return /* @__PURE__ */ jsx11(
|
578
591
|
Controller,
|
579
592
|
{
|
580
593
|
name,
|
581
594
|
control,
|
582
595
|
rules,
|
583
|
-
render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */
|
596
|
+
render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */ jsx11(
|
584
597
|
InputComponent,
|
585
598
|
{
|
586
599
|
...field,
|
@@ -601,7 +614,7 @@ var withUncontrolledInput = (InputComponent) => {
|
|
601
614
|
const { register } = useFormContext();
|
602
615
|
const { ref: _ref, ...field } = register(name, rules);
|
603
616
|
const onChange = inputProps.onChange;
|
604
|
-
return /* @__PURE__ */
|
617
|
+
return /* @__PURE__ */ jsx11(
|
605
618
|
InputComponent,
|
606
619
|
{
|
607
620
|
...field,
|
@@ -634,10 +647,10 @@ var createField = (component, options) => {
|
|
634
647
|
};
|
635
648
|
|
636
649
|
// src/default-fields.tsx
|
637
|
-
import { jsx as
|
650
|
+
import { jsx as jsx12, jsxs as jsxs6 } from "react/jsx-runtime";
|
638
651
|
var InputField = createField(
|
639
652
|
forwardRef8(({ type = "text", leftAddon, rightAddon, size, ...rest }, ref) => {
|
640
|
-
const input = /* @__PURE__ */
|
653
|
+
const input = /* @__PURE__ */ jsx12(Input3, { type, size, ...rest, ref });
|
641
654
|
if (leftAddon || rightAddon) {
|
642
655
|
return /* @__PURE__ */ jsxs6(InputGroup3, { size, children: [
|
643
656
|
leftAddon,
|
@@ -655,12 +668,12 @@ var NumberInputField2 = createField(
|
|
655
668
|
}
|
656
669
|
);
|
657
670
|
var PasswordInputField = createField(
|
658
|
-
forwardRef8((props, ref) => /* @__PURE__ */
|
671
|
+
forwardRef8((props, ref) => /* @__PURE__ */ jsx12(PasswordInput, { ref, ...props }))
|
659
672
|
);
|
660
673
|
var TextareaField = createField(Textarea);
|
661
674
|
var SwitchField = createField(
|
662
675
|
forwardRef8(({ type, value, ...rest }, ref) => {
|
663
|
-
return /* @__PURE__ */
|
676
|
+
return /* @__PURE__ */ jsx12(Switch, { isChecked: !!value, ...rest, ref });
|
664
677
|
}),
|
665
678
|
{
|
666
679
|
isControlled: true
|
@@ -670,8 +683,8 @@ var SelectField = createField(
|
|
670
683
|
forwardRef8((props, ref) => {
|
671
684
|
const { buttonProps, listProps, ...rest } = props;
|
672
685
|
return /* @__PURE__ */ jsxs6(Select, { ref, ...rest, children: [
|
673
|
-
/* @__PURE__ */
|
674
|
-
/* @__PURE__ */
|
686
|
+
/* @__PURE__ */ jsx12(SelectButton, { ...buttonProps }),
|
687
|
+
/* @__PURE__ */ jsx12(SelectList, { ...listProps })
|
675
688
|
] });
|
676
689
|
}),
|
677
690
|
{
|
@@ -680,7 +693,7 @@ var SelectField = createField(
|
|
680
693
|
);
|
681
694
|
var CheckboxField = createField(
|
682
695
|
forwardRef8(({ label, type, ...props }, ref) => {
|
683
|
-
return /* @__PURE__ */
|
696
|
+
return /* @__PURE__ */ jsx12(Checkbox, { ref, ...props, children: label });
|
684
697
|
}),
|
685
698
|
{
|
686
699
|
hideLabel: true
|
@@ -700,9 +713,9 @@ var PinField = createField(
|
|
700
713
|
const { pinLength = 4, pinType, spacing, ...inputProps } = props;
|
701
714
|
const inputs = [];
|
702
715
|
for (let i = 0; i < pinLength; i++) {
|
703
|
-
inputs.push(/* @__PURE__ */
|
716
|
+
inputs.push(/* @__PURE__ */ jsx12(PinInputField, { ref }, i));
|
704
717
|
}
|
705
|
-
return /* @__PURE__ */
|
718
|
+
return /* @__PURE__ */ jsx12(HStack, { spacing, children: /* @__PURE__ */ jsx12(PinInput, { ...inputProps, type: pinType, children: inputs }) });
|
706
719
|
}),
|
707
720
|
{
|
708
721
|
isControlled: true
|
@@ -724,28 +737,6 @@ var defaultFieldTypes = {
|
|
724
737
|
"native-select": NativeSelectField
|
725
738
|
};
|
726
739
|
|
727
|
-
// src/fields-context.tsx
|
728
|
-
import { jsx as jsx12 } from "react/jsx-runtime";
|
729
|
-
var FieldsContext = React5.createContext(null);
|
730
|
-
var FieldsProvider = (props) => {
|
731
|
-
const fields = { ...defaultFieldTypes, ...props.value.fields };
|
732
|
-
return /* @__PURE__ */ jsx12(
|
733
|
-
FieldsContext.Provider,
|
734
|
-
{
|
735
|
-
value: { fields, getBaseField: props.value.getBaseField },
|
736
|
-
children: props.children
|
737
|
-
}
|
738
|
-
);
|
739
|
-
};
|
740
|
-
var useFieldsContext = () => {
|
741
|
-
return React5.useContext(FieldsContext);
|
742
|
-
};
|
743
|
-
var useField = (type) => {
|
744
|
-
var _a;
|
745
|
-
const context = React5.useContext(FieldsContext);
|
746
|
-
return ((_a = context == null ? void 0 : context.fields) == null ? void 0 : _a[type]) || InputField;
|
747
|
-
};
|
748
|
-
|
749
740
|
// src/field.tsx
|
750
741
|
import { jsx as jsx13 } from "react/jsx-runtime";
|
751
742
|
var defaultInputType = "text";
|
@@ -753,7 +744,7 @@ var Field = React6.forwardRef(
|
|
753
744
|
(props, ref) => {
|
754
745
|
const { type = defaultInputType, name } = props;
|
755
746
|
const overrides = useFieldProps(name);
|
756
|
-
const InputComponent = useField((overrides == null ? void 0 : overrides.type) || type);
|
747
|
+
const InputComponent = useField((overrides == null ? void 0 : overrides.type) || type, InputField);
|
757
748
|
return /* @__PURE__ */ jsx13(InputComponent, { ref, ...props, ...overrides });
|
758
749
|
}
|
759
750
|
);
|
@@ -1503,7 +1494,11 @@ function createForm({
|
|
1503
1494
|
fieldResolver: fieldResolverProp,
|
1504
1495
|
...rest
|
1505
1496
|
} = props;
|
1506
|
-
|
1497
|
+
const fieldsContext = {
|
1498
|
+
fields: { ...defaultFieldTypes, ...fields },
|
1499
|
+
getBaseField
|
1500
|
+
};
|
1501
|
+
return /* @__PURE__ */ jsx21(FieldsProvider, { value: fieldsContext, children: /* @__PURE__ */ jsx21(
|
1507
1502
|
Form,
|
1508
1503
|
{
|
1509
1504
|
ref,
|
@@ -1540,7 +1535,14 @@ function createStepForm({
|
|
1540
1535
|
});
|
1541
1536
|
const { getFormProps, ...ctx } = stepper;
|
1542
1537
|
const context = useMemo2(() => ctx, [ctx]);
|
1543
|
-
|
1538
|
+
const fieldsContext = {
|
1539
|
+
fields: {
|
1540
|
+
...defaultFieldTypes,
|
1541
|
+
...fields
|
1542
|
+
},
|
1543
|
+
getBaseField
|
1544
|
+
};
|
1545
|
+
return /* @__PURE__ */ jsx22(StepperProvider, { value: context, children: /* @__PURE__ */ jsx22(StepFormProvider, { value: context, children: /* @__PURE__ */ jsx22(FieldsProvider, { value: fieldsContext, children: /* @__PURE__ */ jsx22(Form, { ref, ...rest, ...getFormProps(), children: runIfFn2(children, {
|
1544
1546
|
...stepper,
|
1545
1547
|
Field,
|
1546
1548
|
FormStep,
|