@saas-ui/forms 2.0.0-next.2 → 2.0.0-next.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (62) hide show
  1. package/CHANGELOG.md +188 -0
  2. package/README.md +53 -6
  3. package/dist/ajv/index.d.ts +24 -11
  4. package/dist/ajv/index.js +7 -9
  5. package/dist/ajv/index.js.map +1 -1
  6. package/dist/ajv/index.mjs +7 -10
  7. package/dist/ajv/index.mjs.map +1 -1
  8. package/dist/index.d.ts +519 -280
  9. package/dist/index.js +777 -696
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +756 -676
  12. package/dist/index.mjs.map +1 -1
  13. package/dist/yup/index.d.ts +525 -21
  14. package/dist/yup/index.js +21 -9
  15. package/dist/yup/index.js.map +1 -1
  16. package/dist/yup/index.mjs +21 -10
  17. package/dist/yup/index.mjs.map +1 -1
  18. package/dist/zod/index.d.ts +525 -12
  19. package/dist/zod/index.js +21 -1
  20. package/dist/zod/index.js.map +1 -1
  21. package/dist/zod/index.mjs +21 -3
  22. package/dist/zod/index.mjs.map +1 -1
  23. package/package.json +33 -10
  24. package/src/array-field.tsx +88 -48
  25. package/src/auto-form.tsx +7 -3
  26. package/src/base-field.tsx +54 -0
  27. package/src/create-field.tsx +144 -0
  28. package/src/create-form.tsx +68 -0
  29. package/src/create-step-form.tsx +100 -0
  30. package/src/default-fields.tsx +163 -0
  31. package/src/display-field.tsx +9 -11
  32. package/src/display-if.tsx +20 -13
  33. package/src/field-resolver.ts +10 -8
  34. package/src/field.tsx +18 -445
  35. package/src/fields-context.tsx +23 -0
  36. package/src/fields.tsx +34 -21
  37. package/src/form-context.tsx +84 -0
  38. package/src/form.tsx +77 -55
  39. package/src/index.ts +58 -4
  40. package/src/input-right-button/input-right-button.stories.tsx +1 -1
  41. package/src/input-right-button/input-right-button.tsx +0 -2
  42. package/src/layout.tsx +16 -11
  43. package/src/number-input/number-input.tsx +9 -5
  44. package/src/object-field.tsx +35 -13
  45. package/src/password-input/password-input.stories.tsx +23 -2
  46. package/src/password-input/password-input.tsx +6 -6
  47. package/src/pin-input/pin-input.tsx +1 -5
  48. package/src/radio/radio-input.stories.tsx +1 -1
  49. package/src/radio/radio-input.tsx +12 -10
  50. package/src/select/native-select.tsx +1 -4
  51. package/src/select/select-context.tsx +130 -0
  52. package/src/select/select.stories.tsx +116 -85
  53. package/src/select/select.test.tsx +1 -1
  54. package/src/select/select.tsx +162 -146
  55. package/src/step-form.tsx +76 -76
  56. package/src/submit-button.tsx +5 -1
  57. package/src/types.ts +149 -0
  58. package/src/use-array-field.tsx +9 -3
  59. package/src/use-step-form.tsx +54 -9
  60. package/src/utils.ts +23 -1
  61. package/src/watch-field.tsx +2 -6
  62. /package/src/radio/{radio.test.tsx → radio-input.test.tsx} +0 -0
package/dist/index.mjs CHANGED
@@ -1,75 +1,80 @@
1
- import * as React8 from 'react';
2
- import React8__default, { useState } from 'react';
3
- import { __DEV__, cx, runIfFn, callAllHandlers, get as get$1 } from '@chakra-ui/utils';
4
- import { useForm, FormProvider, useFormContext, Controller, useFieldArray, useWatch, get } from 'react-hook-form';
5
- export { Controller, FormProvider, appendErrors, useController, useFieldArray, useForm, useFormContext, useFormState, useWatch } from 'react-hook-form';
6
- import { forwardRef, NumberInput as NumberInput$1, NumberInputField, NumberInputStepper, NumberIncrementStepper, NumberDecrementStepper, InputRightElement, Button, InputGroup, Input, RadioGroup, Stack, Radio, useMultiStyleConfig, MenuButton, omitThemingProps, useFormControl, Menu, chakra, MenuList, MenuOptionGroup, MenuItemOption, Select as Select$1, Switch, Checkbox, HStack, PinInput, FormControl, FormLabel, Text, Box, FormHelperText, FormErrorMessage, useMergeRefs, Textarea, PinInputField, useTheme, SimpleGrid, useStyleConfig } from '@chakra-ui/react';
7
- import { ViewIcon, ViewOffIcon, ChevronDownIcon, MinusIcon, AddIcon } from '@chakra-ui/icons';
1
+ import * as React12 from 'react';
2
+ import React12__default, { useState, useMemo } from 'react';
3
+ import { useFormContext as useFormContext$1, useForm, FormProvider as FormProvider$1, useFieldArray, useWatch, get, Controller } from 'react-hook-form';
4
+ export { Controller, appendErrors, useController, useFieldArray, useForm, useFormState, useWatch } from 'react-hook-form';
5
+ import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
6
+ import { forwardRef, NumberInput as NumberInput$1, NumberInputField, NumberInputStepper, NumberIncrementStepper, NumberDecrementStepper, InputRightElement, Button, InputGroup, Input, RadioGroup, Stack, Radio, useMultiStyleConfig, useFormControlContext, MenuButton, omitThemingProps, Menu, chakra, MenuItemOption, Select as Select$1, Switch, Checkbox, HStack, PinInput, FormControl, FormLabel, Text, useControllableState, useFormControl, MenuList, MenuOptionGroup, Box, FormHelperText, FormErrorMessage, PinInputField, useTheme, SimpleGrid, useStyleConfig, useMergeRefs, Textarea } from '@chakra-ui/react';
7
+ import { ChevronUpIcon, ChevronDownIcon, useStepper, useStep, useStepperContext, StepsItem, Steps, StepperProvider } from '@saas-ui/core';
8
+ import { ViewIcon, ViewOffIcon, MinusIcon, PlusIcon } from '@saas-ui/core/icons';
9
+ import { dataAttr, cx, isFunction, runIfFn, callAllHandlers, get as get$1 } from '@chakra-ui/utils';
8
10
  import { createContext } from '@chakra-ui/react-utils';
9
- import { StepperProvider, useStepper, useStep, useStepperContext, StepperStep, StepperContainer, StepperSteps } from '@saas-ui/core';
10
11
 
11
- // src/display-field.tsx
12
+ // src/form-context.tsx
13
+ var FormContext = React12.createContext(null);
14
+ var useFormContext = () => {
15
+ const context = React12.useContext(FormContext);
16
+ const hookContext = useFormContext$1();
17
+ if (!context) {
18
+ throw new Error("FormProvider must be used within a Form component");
19
+ }
20
+ return {
21
+ ...hookContext,
22
+ ...context
23
+ };
24
+ };
25
+ var useFieldProps = (name) => {
26
+ var _a;
27
+ const parsedName = name == null ? void 0 : name.replace(/\.[0-9]/g, ".$");
28
+ const context = useFormContext();
29
+ return ((_a = context == null ? void 0 : context.fields) == null ? void 0 : _a[parsedName]) || {};
30
+ };
31
+ var FormProvider = (props) => {
32
+ const { children, fieldResolver, schema, fields, ...rest } = props;
33
+ return /* @__PURE__ */ jsx(FormProvider$1, { ...rest, children: /* @__PURE__ */ jsx(FormContext.Provider, { value: { fieldResolver, schema, fields }, children }) });
34
+ };
12
35
  var DisplayField = ({
13
36
  name,
14
37
  label,
15
38
  placeholder,
16
39
  ...props
17
40
  }) => {
18
- return /* @__PURE__ */ React8.createElement(FormControl, {
19
- ...props
20
- }, label ? /* @__PURE__ */ React8.createElement(FormLabel, {
21
- htmlFor: name
22
- }, label) : null, /* @__PURE__ */ React8.createElement(Text, {
23
- fontSize: "md"
24
- }, /* @__PURE__ */ React8.createElement(FormValue, {
25
- name
26
- })));
41
+ return /* @__PURE__ */ jsxs(FormControl, { ...props, children: [
42
+ label ? /* @__PURE__ */ jsx(FormLabel, { htmlFor: name, children: label }) : null,
43
+ /* @__PURE__ */ jsx(Text, { fontSize: "md", children: /* @__PURE__ */ jsx(FormValue, { name }) })
44
+ ] });
27
45
  };
28
- if (__DEV__) {
29
- DisplayField.displayName = "DisplayField";
30
- }
46
+ DisplayField.displayName = "DisplayField";
31
47
  var FormValue = ({ name }) => {
32
48
  const { getValues } = useFormContext();
33
49
  return getValues(name) || null;
34
50
  };
35
- if (__DEV__) {
36
- FormValue.displayName = "FormValue";
37
- }
51
+ FormValue.displayName = "FormValue";
38
52
  var NumberInput = forwardRef((props, ref) => {
39
- const { hideStepper, incrementIcon, decrementIcon, ...rest } = props;
40
- return /* @__PURE__ */ React8.createElement(NumberInput$1, {
41
- ...rest,
42
- ref
43
- }, /* @__PURE__ */ React8.createElement(NumberInputField, null), !hideStepper && /* @__PURE__ */ React8.createElement(NumberInputStepper, null, /* @__PURE__ */ React8.createElement(NumberIncrementStepper, {
44
- children: incrementIcon
45
- }), /* @__PURE__ */ React8.createElement(NumberDecrementStepper, {
46
- children: decrementIcon
47
- })));
53
+ const {
54
+ hideStepper,
55
+ incrementIcon = /* @__PURE__ */ jsx(ChevronUpIcon, {}),
56
+ decrementIcon = /* @__PURE__ */ jsx(ChevronDownIcon, {}),
57
+ ...rest
58
+ } = props;
59
+ return /* @__PURE__ */ jsxs(NumberInput$1, { ...rest, ref, children: [
60
+ /* @__PURE__ */ jsx(NumberInputField, {}),
61
+ !hideStepper && /* @__PURE__ */ jsxs(NumberInputStepper, { children: [
62
+ /* @__PURE__ */ jsx(NumberIncrementStepper, { children: incrementIcon }),
63
+ /* @__PURE__ */ jsx(NumberDecrementStepper, { children: decrementIcon })
64
+ ] })
65
+ ] });
48
66
  });
49
67
  NumberInput.defaultProps = {
50
68
  hideStepper: false
51
69
  };
52
- if (__DEV__) {
53
- NumberInput.displayName = "NumberInput";
54
- }
70
+ NumberInput.displayName = "NumberInput";
55
71
  var InputRightButton = forwardRef(
56
72
  (props, ref) => {
57
- return /* @__PURE__ */ React8.createElement(InputRightElement, {
58
- w: "auto",
59
- px: "1",
60
- py: "1",
61
- alignItems: "stretch"
62
- }, /* @__PURE__ */ React8.createElement(Button, {
63
- ref,
64
- height: "auto",
65
- ...props
66
- }));
73
+ return /* @__PURE__ */ jsx(InputRightElement, { w: "auto", px: "1", py: "1", alignItems: "stretch", children: /* @__PURE__ */ jsx(Button, { ref, height: "auto", ...props }) });
67
74
  }
68
75
  );
69
76
  InputRightButton.id = "InputRightElement";
70
77
  InputRightButton.displayName = "InputRightButton";
71
-
72
- // src/password-input/password-input.tsx
73
78
  var PasswordInput = forwardRef(
74
79
  (props, ref) => {
75
80
  const {
@@ -80,6 +85,7 @@ var PasswordInput = forwardRef(
80
85
  width,
81
86
  size,
82
87
  variant,
88
+ leftAddon,
83
89
  ...inputProps
84
90
  } = props;
85
91
  const [show, setShow] = useState(false);
@@ -87,186 +93,260 @@ var PasswordInput = forwardRef(
87
93
  const label = show ? "Hide password" : "Show password";
88
94
  let icon;
89
95
  if (show) {
90
- icon = viewIcon || /* @__PURE__ */ React8__default.createElement(ViewIcon, null);
96
+ icon = viewIcon || /* @__PURE__ */ jsx(ViewIcon, {});
91
97
  } else {
92
- icon = viewOffIcon || /* @__PURE__ */ React8__default.createElement(ViewOffIcon, null);
98
+ icon = viewOffIcon || /* @__PURE__ */ jsx(ViewOffIcon, {});
93
99
  }
94
100
  const groupProps = {
95
101
  width: w || width,
96
102
  size,
97
103
  variant
98
104
  };
99
- return /* @__PURE__ */ React8__default.createElement(InputGroup, {
100
- ...groupProps
101
- }, /* @__PURE__ */ React8__default.createElement(Input, {
102
- ...inputProps,
103
- ref,
104
- type: show ? "text" : "password",
105
- autoComplete: show ? "off" : autoComplete
106
- }), /* @__PURE__ */ React8__default.createElement(InputRightButton, {
107
- onClick: handleClick,
108
- "aria-label": label,
109
- variant: "ghost"
110
- }, icon));
105
+ return /* @__PURE__ */ jsxs(InputGroup, { ...groupProps, children: [
106
+ leftAddon,
107
+ /* @__PURE__ */ jsx(
108
+ Input,
109
+ {
110
+ ...inputProps,
111
+ ref,
112
+ type: show ? "text" : "password",
113
+ autoComplete: show ? "off" : autoComplete
114
+ }
115
+ ),
116
+ /* @__PURE__ */ jsx(
117
+ InputRightButton,
118
+ {
119
+ onClick: handleClick,
120
+ "aria-label": label,
121
+ variant: "ghost",
122
+ children: icon
123
+ }
124
+ )
125
+ ] });
111
126
  }
112
127
  );
113
- if (__DEV__) {
114
- PasswordInput.displayName = "PasswordInput";
115
- }
128
+ PasswordInput.displayName = "PasswordInput";
129
+ var mapNestedFields = (name, children) => {
130
+ return React12.Children.map(children, (child) => {
131
+ if (React12.isValidElement(child) && child.props.name) {
132
+ let childName = child.props.name;
133
+ if (childName.includes(".")) {
134
+ childName = childName.replace(/^.*\.(.*)/, "$1");
135
+ } else if (childName.includes(".$")) {
136
+ childName = childName.replace(/^.*\.\$(.*)/, "$1");
137
+ }
138
+ return React12.cloneElement(child, {
139
+ ...child.props,
140
+ name: `${name}.${childName}`
141
+ });
142
+ }
143
+ return child;
144
+ });
145
+ };
146
+ var mapOptions = (options) => {
147
+ return options.map((option) => {
148
+ if (typeof option === "string") {
149
+ return {
150
+ label: option,
151
+ value: option
152
+ };
153
+ }
154
+ return option;
155
+ });
156
+ };
116
157
  var RadioInput = forwardRef(
117
- ({ options, spacing, direction, ...props }, ref) => {
158
+ ({ options: optionsProp, spacing, direction, ...props }, ref) => {
118
159
  const { onBlur, onChange, ...groupProps } = props;
119
- return /* @__PURE__ */ React8.createElement(RadioGroup, {
120
- onChange,
121
- ...groupProps
122
- }, /* @__PURE__ */ React8.createElement(Stack, {
123
- spacing,
124
- direction
125
- }, options.map(({ value, label, ...radioProps }, i) => {
126
- return /* @__PURE__ */ React8.createElement(Radio, {
127
- key: i,
128
- onBlur,
129
- value,
130
- ref,
131
- ...radioProps
132
- }, label || value);
133
- })));
160
+ const options = mapOptions(optionsProp);
161
+ return /* @__PURE__ */ jsx(RadioGroup, { onChange, ...groupProps, children: /* @__PURE__ */ jsx(Stack, { spacing, direction, children: options.map(({ value, label, ...radioProps }, i) => {
162
+ return /* @__PURE__ */ jsx(
163
+ Radio,
164
+ {
165
+ onBlur,
166
+ value,
167
+ ref,
168
+ ...radioProps,
169
+ children: label || value
170
+ },
171
+ i
172
+ );
173
+ }) }) });
134
174
  }
135
175
  );
136
- if (__DEV__) {
137
- RadioInput.displayName = "RadioInput";
138
- }
139
- var SelectButton = forwardRef((props, ref) => {
140
- const styles = useMultiStyleConfig("Input", props);
141
- const focusStyles = styles.field._focusVisible;
142
- const height = styles.field.h || styles.field.height;
143
- const buttonStyles = {
144
- fontWeight: "normal",
145
- textAlign: "left",
146
- color: "inherit",
147
- _active: {
148
- bg: "transparent"
149
- },
150
- minH: height,
151
- _focus: focusStyles,
152
- _expanded: focusStyles,
153
- ...styles.field,
154
- h: "auto"
155
- };
156
- return /* @__PURE__ */ React8.createElement(MenuButton, {
157
- as: Button,
158
- ...props,
159
- ref,
160
- sx: buttonStyles
161
- });
176
+ RadioInput.displayName = "RadioInput";
177
+ var [SelectProvider, useSelectContext] = createContext({
178
+ strict: true
162
179
  });
163
- if (__DEV__) {
164
- SelectButton.displayName = "SelectButton";
165
- }
166
- var Select = forwardRef((props, ref) => {
180
+ var useSelect = (props) => {
167
181
  const {
168
182
  name,
169
- options,
170
- children,
171
- onChange,
172
- defaultValue,
173
183
  value,
184
+ defaultValue,
185
+ onChange,
186
+ multiple,
174
187
  placeholder,
188
+ options: optionsProp,
175
189
  isDisabled,
176
- leftIcon,
177
- rightIcon = /* @__PURE__ */ React8.createElement(ChevronDownIcon, null),
178
- multiple,
179
- size,
180
- variant,
181
- menuListProps,
182
- renderValue = (value2) => value2 == null ? void 0 : value2.join(", "),
183
- ...rest
190
+ renderValue = (value2) => typeof value2 === "string" ? value2 : value2 == null ? void 0 : value2.join(", ")
184
191
  } = props;
185
- const menuProps = omitThemingProps(rest);
186
- const [currentValue, setCurrentValue] = React8.useState(value || defaultValue);
192
+ const [currentValue, setCurrentValue] = useControllableState({
193
+ value,
194
+ defaultValue,
195
+ onChange
196
+ });
187
197
  const controlProps = useFormControl({ name });
198
+ const options = React12__default.useMemo(
199
+ () => optionsProp && mapOptions(optionsProp),
200
+ [optionsProp]
201
+ );
188
202
  const handleChange = (value2) => {
189
203
  setCurrentValue(value2);
190
- onChange == null ? void 0 : onChange(value2);
191
- };
192
- const buttonProps = {
193
- isDisabled,
194
- leftIcon,
195
- rightIcon,
196
- size,
197
- variant
198
204
  };
199
- const getDisplayValue = React8.useCallback(
205
+ const getDisplayValue = React12__default.useCallback(
200
206
  (value2) => {
201
207
  if (!options) {
202
208
  return value2;
203
209
  }
204
210
  for (const option of options) {
205
- if (option.label && option.value === value2) {
206
- return option.label;
211
+ if (option.value === value2) {
212
+ return option.label || option.value;
207
213
  }
208
214
  }
209
215
  return value2;
210
216
  },
211
217
  [options]
212
218
  );
213
- const displayValue = currentValue ? (Array.isArray(currentValue) ? currentValue : [currentValue]).map(
214
- getDisplayValue
215
- ) : [];
216
- return /* @__PURE__ */ React8.createElement(Menu, {
217
- ...menuProps,
218
- closeOnSelect: !multiple
219
- }, /* @__PURE__ */ React8.createElement(chakra.div, {
220
- className: cx("sui-select")
221
- }, /* @__PURE__ */ React8.createElement(SelectButton, {
222
- ref,
223
- ...buttonProps
224
- }, renderValue(displayValue) || placeholder), /* @__PURE__ */ React8.createElement(MenuList, {
225
- maxH: "60vh",
226
- overflowY: "auto",
227
- ...menuListProps
228
- }, /* @__PURE__ */ React8.createElement(MenuOptionGroup, {
229
- defaultValue: defaultValue || value,
230
- onChange: handleChange,
231
- type: multiple ? "checkbox" : "radio"
232
- }, options ? options.map(({ value: value2, label, ...rest2 }, i) => /* @__PURE__ */ React8.createElement(MenuItemOption, {
233
- key: i,
234
- value: value2,
235
- ...rest2
236
- }, label || value2)) : children)), /* @__PURE__ */ React8.createElement(chakra.input, {
237
- ...controlProps,
238
- name,
239
- type: "hidden",
219
+ const displayValue = React12__default.useMemo(
220
+ () => currentValue ? (Array.isArray(currentValue) ? currentValue : [currentValue]).map(
221
+ getDisplayValue
222
+ ) : [],
223
+ [currentValue, getDisplayValue]
224
+ );
225
+ return {
226
+ defaultValue,
240
227
  value: currentValue,
241
- className: "saas-select__input"
242
- })));
228
+ displayValue,
229
+ renderValue,
230
+ onChange: handleChange,
231
+ options,
232
+ multiple,
233
+ controlProps,
234
+ placeholder,
235
+ isDisabled
236
+ };
237
+ };
238
+ var SelectButton = forwardRef(
239
+ (props, ref) => {
240
+ var _a, _b, _c, _d, _e;
241
+ const styles = useMultiStyleConfig("SuiSelect", props);
242
+ const {
243
+ displayValue,
244
+ renderValue,
245
+ placeholder,
246
+ isDisabled: isSelectDisabled
247
+ } = useSelectContext();
248
+ const context = useFormControlContext();
249
+ const {
250
+ isInvalid,
251
+ isReadOnly,
252
+ isDisabled,
253
+ isFocused,
254
+ isRequired,
255
+ id,
256
+ onBlur,
257
+ onFocus
258
+ } = context || {};
259
+ const { rightIcon = /* @__PURE__ */ jsx(ChevronDownIcon, {}), ...rest } = props;
260
+ const focusStyles = (_a = styles.field) == null ? void 0 : _a._focusVisible;
261
+ const readOnlyStyles = (_b = styles.field) == null ? void 0 : _b._readOnly;
262
+ const invalid = (_c = styles.field) == null ? void 0 : _c._invalid;
263
+ const height = ((_d = styles.field) == null ? void 0 : _d.h) || ((_e = styles.field) == null ? void 0 : _e.height);
264
+ const buttonStyles = {
265
+ fontWeight: "normal",
266
+ textAlign: "left",
267
+ color: "inherit",
268
+ _active: {
269
+ bg: "transparent"
270
+ },
271
+ minH: height,
272
+ _focus: focusStyles,
273
+ _expanded: focusStyles,
274
+ _readOnly: readOnlyStyles,
275
+ _invalid: invalid,
276
+ ...styles.field,
277
+ h: "auto"
278
+ };
279
+ return /* @__PURE__ */ jsx(
280
+ MenuButton,
281
+ {
282
+ as: Button,
283
+ id: id || React12.useId(),
284
+ ...buttonStyles,
285
+ ...rest,
286
+ onFocus,
287
+ onBlur,
288
+ isDisabled: isDisabled || isSelectDisabled,
289
+ "data-invalid": dataAttr(isInvalid),
290
+ "data-read-only": dataAttr(isReadOnly),
291
+ "data-focus": dataAttr(isFocused),
292
+ "data-required": dataAttr(isRequired),
293
+ rightIcon,
294
+ ref,
295
+ children: renderValue(displayValue) || placeholder
296
+ }
297
+ );
298
+ }
299
+ );
300
+ SelectButton.displayName = "SelectButton";
301
+ var Select = forwardRef((props, ref) => {
302
+ const { name, children, isDisabled, multiple, ...rest } = props;
303
+ const menuProps = omitThemingProps(rest);
304
+ const context = useSelect(props);
305
+ const { value, controlProps } = context;
306
+ return /* @__PURE__ */ jsx(SelectProvider, { value: context, children: /* @__PURE__ */ jsx(Menu, { ...menuProps, closeOnSelect: !multiple, children: /* @__PURE__ */ jsxs(chakra.div, { className: cx("sui-select"), children: [
307
+ children,
308
+ /* @__PURE__ */ jsx(
309
+ chakra.input,
310
+ {
311
+ ...controlProps,
312
+ ref,
313
+ name,
314
+ type: "hidden",
315
+ value: value || "",
316
+ className: "saas-select__input"
317
+ }
318
+ )
319
+ ] }) }) });
243
320
  });
244
- if (__DEV__) {
245
- Select.displayName = "Select";
246
- }
321
+ var SelectList = (props) => {
322
+ const { defaultValue, value, options, multiple, onChange } = useSelectContext();
323
+ return /* @__PURE__ */ jsx(MenuList, { maxH: "100vh", overflowY: "auto", ...props, children: /* @__PURE__ */ jsx(
324
+ MenuOptionGroup,
325
+ {
326
+ defaultValue: defaultValue || value,
327
+ value,
328
+ onChange,
329
+ type: multiple ? "checkbox" : "radio",
330
+ children: options ? options.map(({ value: value2, label, ...rest }, i) => /* @__PURE__ */ jsx(SelectOption, { value: value2, ...rest, children: label || value2 }, i)) : props.children
331
+ }
332
+ ) });
333
+ };
334
+ Select.displayName = "Select";
335
+ var SelectOption = forwardRef(
336
+ (props, ref) => {
337
+ return /* @__PURE__ */ jsx(MenuItemOption, { ref, ...props });
338
+ }
339
+ );
340
+ SelectOption.id = "MenuItemOption";
341
+ SelectOption.displayName = "SelectOption";
247
342
  var NativeSelect = forwardRef(
248
343
  ({ options, children, ...props }, ref) => {
249
- return /* @__PURE__ */ React8.createElement(Select$1, {
250
- ref,
251
- ...props
252
- }, children || (options == null ? void 0 : options.map(({ value, label }) => {
253
- return /* @__PURE__ */ React8.createElement("option", {
254
- key: value,
255
- value
256
- }, label || value);
257
- })));
344
+ return /* @__PURE__ */ jsx(Select$1, { ref, ...props, children: children || (options == null ? void 0 : options.map(({ value, label }) => {
345
+ return /* @__PURE__ */ jsx("option", { value, children: label || value }, value);
346
+ })) });
258
347
  }
259
348
  );
260
- if (__DEV__) {
261
- NativeSelect.displayName = "NativeSelect";
262
- }
263
-
264
- // src/field.tsx
265
- var inputTypes = {};
266
- var defaultInputType = "text";
267
- var getInput = (type) => {
268
- return inputTypes[type] || inputTypes[defaultInputType];
269
- };
349
+ NativeSelect.displayName = "NativeSelect";
270
350
  var getError = (name, formState) => {
271
351
  return get(formState.errors, name);
272
352
  };
@@ -274,25 +354,17 @@ var BaseField = (props) => {
274
354
  const { name, label, help, hideLabel, children, ...controlProps } = props;
275
355
  const { formState } = useFormContext();
276
356
  const error = getError(name, formState);
277
- return /* @__PURE__ */ React8.createElement(FormControl, {
278
- ...controlProps,
279
- isInvalid: !!error
280
- }, label && !hideLabel ? /* @__PURE__ */ React8.createElement(FormLabel, null, label) : null, /* @__PURE__ */ React8.createElement(Box, null, children, help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */ React8.createElement(FormHelperText, null, help) : null, (error == null ? void 0 : error.message) && /* @__PURE__ */ React8.createElement(FormErrorMessage, null, error == null ? void 0 : error.message)));
357
+ return /* @__PURE__ */ jsxs(FormControl, { ...controlProps, isInvalid: !!error, children: [
358
+ label && !hideLabel ? /* @__PURE__ */ jsx(FormLabel, { children: label }) : null,
359
+ /* @__PURE__ */ jsxs(Box, { children: [
360
+ children,
361
+ help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */ jsx(FormHelperText, { children: help }) : null,
362
+ (error == null ? void 0 : error.message) && /* @__PURE__ */ jsx(FormErrorMessage, { children: error == null ? void 0 : error.message })
363
+ ] })
364
+ ] });
281
365
  };
282
- if (__DEV__) {
283
- BaseField.displayName = "BaseField";
284
- }
285
- var Field = React8.forwardRef(
286
- (props, ref) => {
287
- const { type = defaultInputType } = props;
288
- const InputComponent = getInput(type);
289
- return /* @__PURE__ */ React8.createElement(InputComponent, {
290
- ref,
291
- ...props
292
- });
293
- }
294
- );
295
- var createField = (InputComponent, { displayName, hideLabel, BaseField: BaseField2 }) => {
366
+ BaseField.displayName = "BaseField";
367
+ var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseField2 }) => {
296
368
  const Field2 = forwardRef((props, ref) => {
297
369
  const {
298
370
  id,
@@ -310,24 +382,31 @@ var createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFiel
310
382
  required: isRequired,
311
383
  ...rules
312
384
  };
313
- return /* @__PURE__ */ React8.createElement(BaseField2, {
314
- id,
315
- name,
316
- label,
317
- help,
318
- hideLabel,
319
- isDisabled,
320
- isInvalid,
321
- isReadOnly,
322
- isRequired
323
- }, /* @__PURE__ */ React8.createElement(InputComponent, {
324
- ref,
325
- id,
326
- name,
327
- label: hideLabel ? label : void 0,
328
- rules: inputRules,
329
- ...inputProps
330
- }));
385
+ return /* @__PURE__ */ jsx(
386
+ BaseField2,
387
+ {
388
+ id,
389
+ name,
390
+ label,
391
+ help,
392
+ hideLabel,
393
+ isDisabled,
394
+ isInvalid,
395
+ isReadOnly,
396
+ isRequired,
397
+ children: /* @__PURE__ */ jsx(
398
+ InputComponent,
399
+ {
400
+ ref,
401
+ id,
402
+ name,
403
+ label: hideLabel ? label : void 0,
404
+ rules: inputRules,
405
+ ...inputProps
406
+ }
407
+ )
408
+ }
409
+ );
331
410
  });
332
411
  Field2.displayName = displayName;
333
412
  return Field2;
@@ -336,18 +415,24 @@ var withControlledInput = (InputComponent) => {
336
415
  return forwardRef(
337
416
  ({ name, rules, ...inputProps }, ref) => {
338
417
  const { control } = useFormContext();
339
- return /* @__PURE__ */ React8.createElement(Controller, {
340
- name,
341
- control,
342
- rules,
343
- render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */ React8.createElement(InputComponent, {
344
- ...field,
345
- ...inputProps,
346
- onChange: callAllHandlers(inputProps.onChange, field.onChange),
347
- onBlur: callAllHandlers(inputProps.onBlur, field.onBlur),
348
- ref: useMergeRefs(ref, _ref)
349
- })
350
- });
418
+ return /* @__PURE__ */ jsx(
419
+ Controller,
420
+ {
421
+ name,
422
+ control,
423
+ rules,
424
+ render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */ jsx(
425
+ InputComponent,
426
+ {
427
+ ...field,
428
+ ...inputProps,
429
+ onChange: callAllHandlers(inputProps.onChange, field.onChange),
430
+ onBlur: callAllHandlers(inputProps.onBlur, field.onBlur),
431
+ ref: useMergeRefs(ref, _ref)
432
+ }
433
+ )
434
+ }
435
+ );
351
436
  }
352
437
  );
353
438
  };
@@ -356,277 +441,167 @@ var withUncontrolledInput = (InputComponent) => {
356
441
  ({ name, rules, ...inputProps }, ref) => {
357
442
  const { register } = useFormContext();
358
443
  const { ref: _ref, ...field } = register(name, rules);
359
- return /* @__PURE__ */ React8.createElement(InputComponent, {
360
- ...field,
361
- ...inputProps,
362
- onChange: callAllHandlers(inputProps.onChange, field.onChange),
363
- onBlur: callAllHandlers(inputProps.onBlur, field.onBlur),
364
- ref: useMergeRefs(ref, _ref)
365
- });
444
+ return /* @__PURE__ */ jsx(
445
+ InputComponent,
446
+ {
447
+ ...field,
448
+ ...inputProps,
449
+ onChange: callAllHandlers(inputProps.onChange, field.onChange),
450
+ onBlur: callAllHandlers(inputProps.onBlur, field.onBlur),
451
+ ref: useMergeRefs(ref, _ref)
452
+ }
453
+ );
366
454
  }
367
455
  );
368
456
  };
369
- var registerFieldType = (type, component, options) => {
457
+ var createField = (component, options) => {
458
+ var _a;
370
459
  let InputComponent;
371
460
  if (options == null ? void 0 : options.isControlled) {
372
461
  InputComponent = withControlledInput(component);
373
462
  } else {
374
463
  InputComponent = withUncontrolledInput(component);
375
464
  }
376
- const Field2 = createField(InputComponent, {
377
- displayName: `${type.split("-").map((part) => part.charAt(0).toUpperCase() + part.slice(1)).join("")}Field`,
465
+ const Field2 = _createField(InputComponent, {
466
+ displayName: `${(_a = component.displayName) != null ? _a : "Custom"}Field`,
378
467
  hideLabel: options == null ? void 0 : options.hideLabel,
379
468
  BaseField: (options == null ? void 0 : options.BaseField) || BaseField
380
469
  });
381
- inputTypes[type] = Field2;
382
470
  return Field2;
383
471
  };
384
- var InputField = registerFieldType(
385
- "text",
472
+ var InputField = createField(
386
473
  forwardRef(({ type = "text", leftAddon, rightAddon, size, ...rest }, ref) => {
387
- const input = /* @__PURE__ */ React8.createElement(Input, {
388
- type,
389
- size,
390
- ...rest,
391
- ref
392
- });
474
+ const input = /* @__PURE__ */ jsx(Input, { type, size, ...rest, ref });
393
475
  if (leftAddon || rightAddon) {
394
- return /* @__PURE__ */ React8.createElement(InputGroup, {
395
- size
396
- }, leftAddon, input, rightAddon);
476
+ return /* @__PURE__ */ jsxs(InputGroup, { size, children: [
477
+ leftAddon,
478
+ input,
479
+ rightAddon
480
+ ] });
397
481
  }
398
482
  return input;
399
483
  })
400
484
  );
401
- var NumberInputField2 = registerFieldType(
402
- "number",
485
+ var NumberInputField2 = createField(
403
486
  NumberInput,
404
487
  {
405
488
  isControlled: true
406
489
  }
407
490
  );
408
- var PasswordInputField = registerFieldType(
409
- "password",
410
- forwardRef((props, ref) => /* @__PURE__ */ React8.createElement(PasswordInput, {
411
- ref,
412
- ...props
413
- }))
491
+ var PasswordInputField = createField(
492
+ forwardRef((props, ref) => /* @__PURE__ */ jsx(PasswordInput, { ref, ...props }))
414
493
  );
415
- var TextareaField = registerFieldType(
416
- "textarea",
417
- Textarea
418
- );
419
- var SwitchField = registerFieldType(
420
- "switch",
494
+ var TextareaField = createField(Textarea);
495
+ var SwitchField = createField(
421
496
  forwardRef(({ type, value, ...rest }, ref) => {
422
- return /* @__PURE__ */ React8.createElement(Switch, {
423
- isChecked: !!value,
424
- ...rest,
425
- ref
426
- });
497
+ return /* @__PURE__ */ jsx(Switch, { isChecked: !!value, ...rest, ref });
427
498
  }),
428
499
  {
429
500
  isControlled: true
430
501
  }
431
502
  );
432
- var SelectField = registerFieldType("select", Select, {
433
- isControlled: true
434
- });
435
- var CheckboxField = registerFieldType(
436
- "checkbox",
437
- forwardRef(({ label, type, ...props }, ref) => {
438
- return /* @__PURE__ */ React8.createElement(Checkbox, {
439
- ref,
440
- ...props
441
- }, label);
503
+ var SelectField = createField(
504
+ forwardRef((props, ref) => {
505
+ return /* @__PURE__ */ jsxs(Select, { ref, ...props, children: [
506
+ /* @__PURE__ */ jsx(SelectButton, {}),
507
+ /* @__PURE__ */ jsx(SelectList, {})
508
+ ] });
442
509
  }),
443
510
  {
444
- hideLabel: true
511
+ isControlled: true
445
512
  }
446
513
  );
447
- var RadioField = registerFieldType(
448
- "radio",
449
- RadioInput,
514
+ var CheckboxField = createField(
515
+ forwardRef(({ label, type, ...props }, ref) => {
516
+ return /* @__PURE__ */ jsx(Checkbox, { ref, ...props, children: label });
517
+ }),
450
518
  {
451
- isControlled: true
519
+ hideLabel: true
452
520
  }
453
521
  );
454
- var NativeSelectField = registerFieldType(
455
- "native-select",
456
- NativeSelect,
457
- { isControlled: true }
458
- );
459
- var PinField = registerFieldType(
460
- "pin",
522
+ var RadioField = createField(RadioInput, {
523
+ isControlled: true
524
+ });
525
+ var NativeSelectField = createField(NativeSelect, {
526
+ isControlled: true
527
+ });
528
+ var PinField = createField(
461
529
  forwardRef((props, ref) => {
462
530
  const { pinLength = 4, pinType, spacing, ...inputProps } = props;
463
531
  const inputs = [];
464
532
  for (let i = 0; i < pinLength; i++) {
465
- inputs.push(/* @__PURE__ */ React8.createElement(PinInputField, {
466
- key: i,
467
- ref
468
- }));
533
+ inputs.push(/* @__PURE__ */ jsx(PinInputField, { ref }, i));
469
534
  }
470
- return /* @__PURE__ */ React8.createElement(HStack, {
471
- spacing
472
- }, /* @__PURE__ */ React8.createElement(PinInput, {
473
- ...inputProps,
474
- type: pinType
475
- }, inputs));
535
+ return /* @__PURE__ */ jsx(HStack, { spacing, children: /* @__PURE__ */ jsx(PinInput, { ...inputProps, type: pinType, children: inputs }) });
476
536
  }),
477
537
  {
478
538
  isControlled: true
479
539
  }
480
540
  );
481
- var mapFields = (schema) => schema && Object.entries(schema).map(([name, { items, label, title, ...field }]) => {
482
- return {
483
- ...field,
484
- name,
485
- label: label || title || name
486
- };
487
- });
488
- var objectFieldResolver = (schema) => {
489
- const getFields = () => {
490
- return mapFields(schema);
491
- };
492
- const getNestedFields = (name) => {
493
- var _a;
494
- const field = get$1(schema, name);
495
- if (!field)
496
- return [];
497
- if (((_a = field.items) == null ? void 0 : _a.type) === "object") {
498
- return mapFields(field.items.properties);
499
- } else if (field.type === "object") {
500
- return mapFields(field.properties);
501
- }
502
- return [field.items];
503
- };
504
- return { getFields, getNestedFields };
541
+ var defaultFieldTypes = {
542
+ text: InputField,
543
+ email: InputField,
544
+ url: InputField,
545
+ phone: InputField,
546
+ number: NumberInputField2,
547
+ password: PasswordInputField,
548
+ textarea: TextareaField,
549
+ switch: SwitchField,
550
+ select: SelectField,
551
+ checkbox: CheckboxField,
552
+ radio: RadioField,
553
+ pin: PinField,
554
+ "native-select": NativeSelectField
505
555
  };
506
-
507
- // src/form.tsx
508
- var Form = forwardRef(
556
+ var FieldsContext = React12__default.createContext(
557
+ null
558
+ );
559
+ var FieldsProvider = (props) => {
560
+ const fields = { ...defaultFieldTypes, ...props.value };
561
+ return /* @__PURE__ */ jsx(FieldsContext.Provider, { value: fields, children: props.children });
562
+ };
563
+ var useField = (type) => {
564
+ const context = React12__default.useContext(FieldsContext);
565
+ return (context == null ? void 0 : context[type]) || InputField;
566
+ };
567
+ var defaultInputType = "text";
568
+ var Field = React12.forwardRef(
509
569
  (props, ref) => {
510
- var _a;
511
- const {
512
- mode = "all",
513
- resolver,
514
- reValidateMode,
515
- shouldFocusError,
516
- shouldUnregister,
517
- shouldUseNativeValidation,
518
- criteriaMode,
519
- delayError,
520
- schema,
521
- defaultValues,
522
- values,
523
- context,
524
- resetOptions,
525
- onChange,
526
- onSubmit,
527
- onError,
528
- formRef,
529
- children,
530
- ...rest
531
- } = props;
532
- const form = {
533
- mode,
534
- resolver,
535
- defaultValues,
536
- values,
537
- reValidateMode,
538
- shouldFocusError,
539
- shouldUnregister,
540
- shouldUseNativeValidation,
541
- criteriaMode,
542
- delayError,
543
- context,
544
- resetOptions
545
- };
546
- if (schema && !resolver) {
547
- form.resolver = (_a = Form.getResolver) == null ? void 0 : _a.call(Form, schema);
548
- }
549
- const methods = useForm(form);
550
- const { handleSubmit } = methods;
551
- React8.useImperativeHandle(formRef, () => methods, [formRef, methods]);
552
- React8.useEffect(() => {
553
- let subscription;
554
- if (onChange) {
555
- subscription = methods.watch(onChange);
556
- }
557
- return () => subscription == null ? void 0 : subscription.unsubscribe();
558
- }, [methods, onChange]);
559
- const Field2 = React8.useMemo(
560
- () => (props2) => /* @__PURE__ */ React8.createElement(Field, {
561
- ...props2
562
- }),
563
- []
564
- );
565
- return /* @__PURE__ */ React8.createElement(FormProvider, {
566
- ...methods
567
- }, /* @__PURE__ */ React8.createElement(chakra.form, {
568
- ref,
569
- onSubmit: handleSubmit(onSubmit, onError),
570
- ...rest,
571
- className: cx("sui-form", props.className)
572
- }, runIfFn(children, {
573
- Field: Field2,
574
- ...methods
575
- })));
570
+ const { type = defaultInputType, name } = props;
571
+ const overrides = useFieldProps(name);
572
+ const InputComponent = useField((overrides == null ? void 0 : overrides.type) || type);
573
+ return /* @__PURE__ */ jsx(InputComponent, { ref, ...props, ...overrides });
576
574
  }
577
575
  );
578
- Form.getFieldResolver = objectFieldResolver;
579
- Form.displayName = "Form";
580
- function createForm({ resolver }) {
581
- const CreateForm = (props) => {
582
- const { schema, ...rest } = props;
583
- return /* @__PURE__ */ React8.createElement(Form, {
584
- resolver: resolver == null ? void 0 : resolver(props.schema),
585
- ...rest
586
- });
587
- };
588
- return CreateForm;
589
- }
590
576
  var FormLayoutItem = ({ children }) => {
591
- return /* @__PURE__ */ React8.createElement(chakra.div, null, children);
577
+ return /* @__PURE__ */ jsx(chakra.div, { children });
592
578
  };
593
- if (__DEV__) {
594
- FormLayoutItem.displayName = "FormLayoutItem";
595
- }
579
+ FormLayoutItem.displayName = "FormLayoutItem";
596
580
  var FormLayout = ({ children, ...props }) => {
597
581
  var _a, _b, _c;
598
582
  const theme = useTheme();
599
- const defaultProps = (_c = (_b = (_a = theme.components) == null ? void 0 : _a.FormLayout) == null ? void 0 : _b.defaultProps) != null ? _c : {
583
+ const defaultProps = (_c = (_b = (_a = theme.components) == null ? void 0 : _a.SuiFormLayout) == null ? void 0 : _b.defaultProps) != null ? _c : {
600
584
  spacing: 4
601
585
  };
602
586
  const gridProps = {
603
587
  ...defaultProps,
604
588
  ...props
605
589
  };
606
- return /* @__PURE__ */ React8.createElement(SimpleGrid, {
607
- ...gridProps,
608
- className: cx("sui-form__layout", props.className)
609
- }, React8.Children.map(children, (child) => {
610
- if (React8.isValidElement(child)) {
611
- return /* @__PURE__ */ React8.createElement(FormLayoutItem, null, child);
612
- }
613
- return child;
614
- }));
615
- };
616
- if (__DEV__) {
617
- FormLayout.displayName = "FormLayout";
618
- }
619
- var mapNestedFields = (name, children) => {
620
- return React8.Children.map(children, (child) => {
621
- if (React8.isValidElement(child) && child.props.name) {
622
- return React8.cloneElement(child, {
623
- ...child.props,
624
- name: `${name}.${child.props.name}`
625
- });
590
+ return /* @__PURE__ */ jsx(
591
+ SimpleGrid,
592
+ {
593
+ ...gridProps,
594
+ className: cx("sui-form__layout", props.className),
595
+ children: React12.Children.map(children, (child) => {
596
+ if (React12.isValidElement(child)) {
597
+ return /* @__PURE__ */ jsx(FormLayoutItem, { children: child });
598
+ }
599
+ return child;
600
+ })
626
601
  }
627
- return child;
628
- });
602
+ );
629
603
  };
604
+ FormLayout.displayName = "FormLayout";
630
605
  var [ArrayFieldProvider, useArrayFieldContext] = createContext({
631
606
  name: "ArrayFieldContext"
632
607
  });
@@ -657,7 +632,7 @@ var useArrayField = ({
657
632
  var useArrayFieldRow = ({ index }) => {
658
633
  const { clearErrors } = useFormContext();
659
634
  const { name, remove, fields } = useArrayFieldContext();
660
- React8.useEffect(() => {
635
+ React12.useEffect(() => {
661
636
  clearErrors(name);
662
637
  }, []);
663
638
  return {
@@ -665,7 +640,7 @@ var useArrayFieldRow = ({ index }) => {
665
640
  isFirst: index === 0,
666
641
  isLast: index === fields.length - 1,
667
642
  name: `${name}.${index}`,
668
- remove: React8.useCallback(() => {
643
+ remove: React12.useCallback(() => {
669
644
  clearErrors(name);
670
645
  remove(index);
671
646
  }, [index])
@@ -690,39 +665,29 @@ var useArrayFieldAddButton = () => {
690
665
  isDisabled
691
666
  };
692
667
  };
693
-
694
- // src/array-field.tsx
695
668
  var ArrayFieldRow = ({
696
669
  children,
697
670
  index,
698
671
  ...rowFieldsProps
699
672
  }) => {
700
- return /* @__PURE__ */ React8.createElement(ArrayFieldRowContainer, {
701
- index
702
- }, /* @__PURE__ */ React8.createElement(ArrayFieldRowFields, {
703
- ...rowFieldsProps
704
- }, children), /* @__PURE__ */ React8.createElement(ArrayFieldRemoveButton, null));
673
+ return /* @__PURE__ */ jsxs(ArrayFieldRowContainer, { index, children: [
674
+ /* @__PURE__ */ jsx(ArrayFieldRowFields, { ...rowFieldsProps, children }),
675
+ /* @__PURE__ */ jsx(ArrayFieldRemoveButton, {})
676
+ ] });
705
677
  };
706
- if (__DEV__) {
707
- ArrayFieldRow.displayName = "ArrayFieldRow";
708
- }
678
+ ArrayFieldRow.displayName = "ArrayFieldRow";
709
679
  var ArrayFieldRowFields = ({
710
680
  children,
711
681
  ...layoutProps
712
682
  }) => {
713
683
  const { name } = useArrayFieldRowContext();
714
- return /* @__PURE__ */ React8.createElement(FormLayout, {
715
- flex: "1",
716
- mr: "2",
717
- ...layoutProps
718
- }, mapNestedFields(name, children));
684
+ return /* @__PURE__ */ jsx(FormLayout, { flex: "1", mr: "2", ...layoutProps, children: mapNestedFields(name, children) });
719
685
  };
720
- if (__DEV__) {
721
- ArrayFieldRowFields.displayName = "ArrayFieldRowFields";
722
- }
686
+ ArrayFieldRowFields.displayName = "ArrayFieldRowFields";
723
687
  var ArrayFieldRowContainer = ({
724
688
  children,
725
- index
689
+ index,
690
+ ...rest
726
691
  }) => {
727
692
  const context = useArrayFieldRow({ index });
728
693
  const styles = {
@@ -732,61 +697,45 @@ var ArrayFieldRowContainer = ({
732
697
  width: "100%",
733
698
  mb: 4
734
699
  };
735
- return /* @__PURE__ */ React8.createElement(ArrayFieldRowProvider, {
736
- value: context
737
- }, /* @__PURE__ */ React8.createElement(chakra.div, {
738
- __css: styles
739
- }, children));
700
+ return /* @__PURE__ */ jsx(ArrayFieldRowProvider, { value: context, children: /* @__PURE__ */ jsx(chakra.div, { ...rest, __css: styles, children }) });
740
701
  };
741
- if (__DEV__) {
742
- ArrayFieldRowContainer.displayName = "ArrayFieldRowContainer";
743
- }
702
+ ArrayFieldRowContainer.displayName = "ArrayFieldRowContainer";
744
703
  var ArrayFieldRemoveButton = (props) => {
745
- return /* @__PURE__ */ React8.createElement(Button, {
746
- "aria-label": "Remove row",
747
- ...useArrayFieldRemoveButton(),
748
- ...props
749
- }, props.children || /* @__PURE__ */ React8.createElement(MinusIcon, null));
704
+ return /* @__PURE__ */ jsx(Button, { "aria-label": "Remove row", ...useArrayFieldRemoveButton(), ...props, children: props.children || /* @__PURE__ */ jsx(MinusIcon, {}) });
750
705
  };
751
- if (__DEV__) {
752
- ArrayFieldRemoveButton.displayName = "ArrayFieldRemoveButton";
753
- }
706
+ ArrayFieldRemoveButton.displayName = "ArrayFieldRemoveButton";
754
707
  var ArrayFieldAddButton = (props) => {
755
- return /* @__PURE__ */ React8.createElement(Button, {
756
- "aria-label": "Add row",
757
- float: "right",
758
- ...useArrayFieldAddButton(),
759
- ...props
760
- }, props.children || /* @__PURE__ */ React8.createElement(AddIcon, null));
708
+ return /* @__PURE__ */ jsx(
709
+ Button,
710
+ {
711
+ "aria-label": "Add row",
712
+ float: "right",
713
+ ...useArrayFieldAddButton(),
714
+ ...props,
715
+ children: props.children || /* @__PURE__ */ jsx(PlusIcon, {})
716
+ }
717
+ );
761
718
  };
762
- if (__DEV__) {
763
- ArrayFieldAddButton.displayName = "ArrayFieldAddButton";
764
- }
719
+ ArrayFieldAddButton.displayName = "ArrayFieldAddButton";
765
720
  var ArrayField = forwardRef(
766
721
  (props, ref) => {
767
722
  const { children, ...containerProps } = props;
768
- return /* @__PURE__ */ React8.createElement(ArrayFieldContainer, {
769
- ref,
770
- ...containerProps
771
- }, /* @__PURE__ */ React8.createElement(ArrayFieldRows, null, (fields) => /* @__PURE__ */ React8.createElement(React8.Fragment, null, fields.map(({ id }, index) => /* @__PURE__ */ React8.createElement(ArrayFieldRow, {
772
- key: id,
773
- index
774
- }, children)))), /* @__PURE__ */ React8.createElement(ArrayFieldAddButton, null));
723
+ const rowFn = isFunction(children) ? children : (fields) => /* @__PURE__ */ jsx(Fragment, { children: fields.map(({ id }, index) => /* @__PURE__ */ jsx(ArrayFieldRow, { index, children }, id)) || null });
724
+ return /* @__PURE__ */ jsxs(ArrayFieldContainer, { ref, ...containerProps, children: [
725
+ /* @__PURE__ */ jsx(ArrayFieldRows, { children: rowFn }),
726
+ /* @__PURE__ */ jsx(ArrayFieldAddButton, {})
727
+ ] });
775
728
  }
776
729
  );
777
- if (__DEV__) {
778
- ArrayField.displayName = "ArrayField";
779
- }
730
+ ArrayField.displayName = "ArrayField";
780
731
  var ArrayFieldRows = ({
781
732
  children
782
733
  }) => {
783
734
  const { fields } = useArrayFieldContext();
784
735
  return children(fields);
785
736
  };
786
- if (__DEV__) {
787
- ArrayFieldRows.displayName = "ArrayFieldRows";
788
- }
789
- var ArrayFieldContainer = React8.forwardRef(
737
+ ArrayFieldRows.displayName = "ArrayFieldRows";
738
+ var ArrayFieldContainer = React12.forwardRef(
790
739
  ({
791
740
  name,
792
741
  defaultValue,
@@ -796,81 +745,85 @@ var ArrayFieldContainer = React8.forwardRef(
796
745
  children,
797
746
  ...fieldProps
798
747
  }, ref) => {
748
+ const overrides = useFieldProps(name);
799
749
  const context = useArrayField({
800
750
  name,
801
751
  defaultValue,
802
752
  keyName,
803
- min,
804
- max
753
+ min: min || (overrides == null ? void 0 : overrides.min),
754
+ max: max || (overrides == null ? void 0 : overrides.max)
805
755
  });
806
- React8.useImperativeHandle(ref, () => context, [ref, context]);
807
- return /* @__PURE__ */ React8.createElement(ArrayFieldProvider, {
808
- value: context
809
- }, /* @__PURE__ */ React8.createElement(BaseField, {
810
- name,
811
- ...fieldProps
812
- }, children));
756
+ React12.useImperativeHandle(ref, () => context, [ref, context]);
757
+ return /* @__PURE__ */ jsx(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ jsx(BaseField, { name, ...fieldProps, ...overrides, children }) });
813
758
  }
814
759
  );
815
- if (__DEV__) {
816
- ArrayFieldContainer.displayName = "ArrayFieldContainer";
817
- }
760
+ ArrayFieldContainer.displayName = "ArrayFieldContainer";
818
761
  var FormLegend = (props) => {
819
762
  const styles = useStyleConfig("SuiFormLegend");
820
- return /* @__PURE__ */ React8.createElement(FormLabel, {
821
- as: "legend",
822
- sx: styles,
823
- ...props
824
- });
763
+ return /* @__PURE__ */ jsx(FormLabel, { as: "legend", sx: styles, ...props });
825
764
  };
826
765
  var ObjectField = (props) => {
827
- const { name, label, hideLabel, children, columns, spacing, ...fieldProps } = props;
828
- return /* @__PURE__ */ React8.createElement(FormControl, {
766
+ const {
829
767
  name,
830
- as: "fieldset",
768
+ label,
769
+ hideLabel: hideLabelProp,
770
+ children,
771
+ columns: columnsProp,
772
+ spacing: spacingProp,
831
773
  ...fieldProps
832
- }, /* @__PURE__ */ React8.createElement(FormLegend, {
833
- display: hideLabel ? "none" : "block"
834
- }, label), /* @__PURE__ */ React8.createElement(FormLayout, {
835
- columns,
836
- gridGap: spacing
837
- }, mapNestedFields(name, children)));
774
+ } = props;
775
+ const { hideLabel, columns, spacing, ...overrides } = useFieldProps(
776
+ name
777
+ );
778
+ return /* @__PURE__ */ jsxs(FormControl, { name, as: "fieldset", ...fieldProps, ...overrides, children: [
779
+ /* @__PURE__ */ jsx(FormLegend, { display: hideLabelProp || hideLabel ? "none" : "block", children: label }),
780
+ /* @__PURE__ */ jsx(
781
+ FormLayout,
782
+ {
783
+ columns: columnsProp || columns,
784
+ gridGap: spacingProp || spacing,
785
+ children: mapNestedFields(name, children)
786
+ }
787
+ )
788
+ ] });
838
789
  };
839
- if (__DEV__) {
840
- ObjectField.displayName = "ObjectField";
841
- }
790
+ ObjectField.displayName = "ObjectField";
842
791
  var mapNestedFields2 = (resolver, name) => {
843
792
  var _a;
844
793
  return (_a = resolver.getNestedFields(name)) == null ? void 0 : _a.map(
845
- ({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */ React8.createElement(Field, {
846
- key: name2 || i,
847
- name: name2,
848
- type,
849
- ...nestedFieldProps
850
- })
794
+ ({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */ jsx(
795
+ Field,
796
+ {
797
+ name: name2,
798
+ type,
799
+ ...nestedFieldProps
800
+ },
801
+ name2 || i
802
+ )
851
803
  );
852
804
  };
853
- var Fields = ({
854
- schema,
855
- fieldResolver,
805
+ var AutoFields = ({
806
+ schema: schemaProp,
807
+ fieldResolver: fieldResolverProp,
856
808
  focusFirstField,
857
809
  ...props
858
810
  }) => {
859
- const resolver = React8.useMemo(
860
- () => fieldResolver || Form.getFieldResolver(schema),
861
- [schema, fieldResolver]
862
- );
863
- const fields = React8.useMemo(() => resolver.getFields(), [resolver]);
811
+ const context = useFormContext();
812
+ const schema = schemaProp || context.schema;
813
+ const fieldResolver = fieldResolverProp || context.fieldResolver;
814
+ const resolver = React12.useMemo(() => fieldResolver, [schema, fieldResolver]);
815
+ const fields = React12.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
864
816
  const form = useFormContext();
865
- React8.useEffect(() => {
817
+ React12.useEffect(() => {
866
818
  var _a;
867
- if (focusFirstField && ((_a = fields[0]) == null ? void 0 : _a.name)) {
819
+ if (focusFirstField && ((_a = fields == null ? void 0 : fields[0]) == null ? void 0 : _a.name)) {
868
820
  form.setFocus(fields[0].name);
869
821
  }
870
822
  }, [schema, fieldResolver, focusFirstField]);
871
- return /* @__PURE__ */ React8.createElement(FormLayout, {
872
- ...props
873
- }, fields.map(
823
+ if (!resolver) {
824
+ return null;
825
+ }
826
+ return /* @__PURE__ */ jsx(FormLayout, { ...props, children: fields == null ? void 0 : fields.map(
874
827
  ({
875
828
  name,
876
829
  type,
@@ -878,28 +831,15 @@ var Fields = ({
878
831
  ...fieldProps
879
832
  }) => {
880
833
  if (type === "array") {
881
- return /* @__PURE__ */ React8.createElement(ArrayField, {
882
- key: name,
883
- name,
884
- ...fieldProps
885
- }, mapNestedFields2(resolver, name));
834
+ return /* @__PURE__ */ jsx(ArrayField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
886
835
  } else if (type === "object") {
887
- return /* @__PURE__ */ React8.createElement(ObjectField, {
888
- key: name,
889
- name,
890
- ...fieldProps
891
- }, mapNestedFields2(resolver, name));
836
+ return /* @__PURE__ */ jsx(ObjectField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
892
837
  }
893
- return /* @__PURE__ */ React8.createElement(Field, {
894
- key: name,
895
- name,
896
- type,
897
- ...fieldProps
898
- });
838
+ return /* @__PURE__ */ jsx(Field, { name, type, ...fieldProps }, name);
899
839
  }
900
- ));
840
+ ) });
901
841
  };
902
- Fields.displayName = "Fields";
842
+ AutoFields.displayName = "Fields";
903
843
  var SubmitButton = forwardRef(
904
844
  (props, ref) => {
905
845
  const {
@@ -910,15 +850,19 @@ var SubmitButton = forwardRef(
910
850
  isLoading,
911
851
  ...rest
912
852
  } = props;
913
- const { formState } = useFormContext();
853
+ const { formState } = useFormContext$1();
914
854
  const isDisabled = disableIfUntouched && !formState.isDirty || disableIfInvalid && !formState.isValid || isDisabledProp;
915
- return /* @__PURE__ */ React8.createElement(Button, {
916
- ...rest,
917
- ref,
918
- type: "submit",
919
- isLoading: formState.isSubmitting || isLoading,
920
- isDisabled
921
- }, children);
855
+ return /* @__PURE__ */ jsx(
856
+ Button,
857
+ {
858
+ ...rest,
859
+ ref,
860
+ type: "submit",
861
+ isLoading: formState.isSubmitting || isLoading,
862
+ isDisabled,
863
+ children
864
+ }
865
+ );
922
866
  }
923
867
  );
924
868
  SubmitButton.defaultProps = {
@@ -927,28 +871,6 @@ SubmitButton.defaultProps = {
927
871
  disableIfInvalid: false
928
872
  };
929
873
  SubmitButton.displayName = "SubmitButton";
930
-
931
- // src/auto-form.tsx
932
- var AutoForm = forwardRef(
933
- (props, ref) => {
934
- const {
935
- schema,
936
- submitLabel = "Submit",
937
- fieldResolver,
938
- children,
939
- ...rest
940
- } = props;
941
- return /* @__PURE__ */ React8.createElement(Form, {
942
- ...rest,
943
- schema,
944
- ref
945
- }, /* @__PURE__ */ React8.createElement(FormLayout, null, /* @__PURE__ */ React8.createElement(Fields, {
946
- schema,
947
- fieldResolver
948
- }), submitLabel && /* @__PURE__ */ React8.createElement(SubmitButton, null, submitLabel), children));
949
- }
950
- );
951
- AutoForm.displayName = "AutoForm";
952
874
  var DisplayIf = ({
953
875
  children,
954
876
  name,
@@ -966,19 +888,18 @@ var DisplayIf = ({
966
888
  const context = useFormContext();
967
889
  return condition(value, context) ? children : null;
968
890
  };
969
- if (__DEV__) {
970
- DisplayIf.displayName = "DisplayIf";
971
- }
891
+ DisplayIf.displayName = "DisplayIf";
972
892
  var [StepFormProvider, useStepFormContext] = createContext({
973
893
  name: "StepFormContext",
974
894
  errorMessage: "useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"
975
895
  });
976
896
  function useStepForm(props) {
977
- const { onChange, ...rest } = props;
897
+ const { onChange, steps: stepsOptions, resolver, ...rest } = props;
978
898
  const stepper = useStepper(rest);
899
+ const [options, setOptions] = React12.useState(stepsOptions);
979
900
  const { activeStep, isLastStep, nextStep } = stepper;
980
- const [steps, updateSteps] = React8.useState({});
981
- const onSubmitStep = React8.useCallback(
901
+ const [steps, updateSteps] = React12.useState({});
902
+ const onSubmitStep = React12.useCallback(
982
903
  async (data) => {
983
904
  var _a, _b;
984
905
  try {
@@ -999,24 +920,31 @@ function useStepForm(props) {
999
920
  },
1000
921
  [steps, activeStep, isLastStep]
1001
922
  );
1002
- const getFormProps = React8.useCallback(() => {
923
+ const getFormProps = React12.useCallback(() => {
1003
924
  const step = steps[activeStep];
1004
925
  return {
1005
926
  onSubmit: onSubmitStep,
1006
927
  schema: step == null ? void 0 : step.schema,
1007
- resolver: step == null ? void 0 : step.resolver
928
+ resolver: (step == null ? void 0 : step.schema) ? (
929
+ /* @todo fix resolver type */
930
+ resolver == null ? void 0 : resolver(step.schema)
931
+ ) : void 0
1008
932
  };
1009
933
  }, [steps, onSubmitStep, activeStep]);
1010
- const updateStep = React8.useCallback(
934
+ const updateStep = React12.useCallback(
1011
935
  (step) => {
936
+ const stepOptions = options == null ? void 0 : options.find((s) => s.name === step.name);
1012
937
  updateSteps((steps2) => {
1013
938
  return {
1014
939
  ...steps2,
1015
- [step.name]: step
940
+ [step.name]: {
941
+ ...step,
942
+ schema: stepOptions == null ? void 0 : stepOptions.schema
943
+ }
1016
944
  };
1017
945
  });
1018
946
  },
1019
- [steps]
947
+ [steps, options]
1020
948
  );
1021
949
  return {
1022
950
  getFormProps,
@@ -1029,7 +957,7 @@ function useFormStep(props) {
1029
957
  const { name, schema, resolver, onSubmit } = props;
1030
958
  const step = useStep({ name });
1031
959
  const { steps, updateStep } = useStepFormContext();
1032
- React8.useEffect(() => {
960
+ React12.useEffect(() => {
1033
961
  updateStep({ name, schema, resolver, onSubmit });
1034
962
  }, [name, schema]);
1035
963
  return {
@@ -1037,92 +965,113 @@ function useFormStep(props) {
1037
965
  ...steps[name] || { name, schema }
1038
966
  };
1039
967
  }
1040
-
1041
- // src/step-form.tsx
1042
- var StepForm = React8.forwardRef(
1043
- (props, ref) => {
1044
- const { children, ...rest } = props;
1045
- const stepper = useStepForm(props);
1046
- const { getFormProps, ...ctx } = stepper;
1047
- const context = React8.useMemo(() => ctx, [ctx]);
1048
- return /* @__PURE__ */ React8.createElement(StepperProvider, {
1049
- value: context
1050
- }, /* @__PURE__ */ React8.createElement(StepFormProvider, {
1051
- value: context
1052
- }, /* @__PURE__ */ React8.createElement(Form, {
1053
- ref,
1054
- ...rest,
1055
- ...getFormProps()
1056
- }, runIfFn(children, stepper))));
1057
- }
1058
- );
1059
968
  var FormStepper = (props) => {
1060
969
  const { activeIndex, setIndex } = useStepperContext();
1061
- const { children, orientation, variant, colorScheme, size, ...rest } = props;
1062
- const elements = React8.Children.map(children, (child) => {
1063
- if (React8.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
970
+ const {
971
+ children,
972
+ orientation,
973
+ variant,
974
+ colorScheme,
975
+ size,
976
+ onChange: onChangeProp,
977
+ render,
978
+ ...rest
979
+ } = props;
980
+ const elements = React12.Children.map(children, (child) => {
981
+ if (React12.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
1064
982
  const { isCompleted } = useFormStep(child.props);
1065
- return /* @__PURE__ */ React8.createElement(StepperStep, {
1066
- name: child.props.name,
1067
- title: child.props.title,
1068
- isCompleted,
1069
- ...rest
1070
- }, child.props.children);
983
+ return /* @__PURE__ */ jsx(
984
+ StepsItem,
985
+ {
986
+ render,
987
+ name: child.props.name,
988
+ title: child.props.title,
989
+ isCompleted,
990
+ ...rest,
991
+ children: child.props.children
992
+ }
993
+ );
1071
994
  }
1072
995
  return child;
1073
996
  });
1074
- const onChange = React8.useCallback((i) => {
997
+ const onChange = React12.useCallback((i) => {
1075
998
  setIndex(i);
999
+ onChangeProp == null ? void 0 : onChangeProp(i);
1076
1000
  }, []);
1077
- return /* @__PURE__ */ React8.createElement(StepperContainer, {
1078
- orientation,
1079
- step: activeIndex,
1080
- variant,
1081
- colorScheme,
1082
- size,
1083
- onChange
1084
- }, /* @__PURE__ */ React8.createElement(StepperSteps, {
1085
- mb: "4",
1086
- ...props
1087
- }, elements));
1001
+ return /* @__PURE__ */ jsx(
1002
+ Steps,
1003
+ {
1004
+ orientation,
1005
+ step: activeIndex,
1006
+ variant,
1007
+ colorScheme,
1008
+ size,
1009
+ onChange,
1010
+ children: elements
1011
+ }
1012
+ );
1088
1013
  };
1089
1014
  var FormStep = (props) => {
1090
- const { name, schema, resolver, children, className, onSubmit, ...rest } = props;
1091
- const step = useFormStep({ name, schema, resolver, onSubmit });
1015
+ const { name, children, className, onSubmit, ...rest } = props;
1016
+ const step = useFormStep({ name, onSubmit });
1092
1017
  const { isActive } = step;
1093
- return isActive ? /* @__PURE__ */ React8.createElement(chakra.div, {
1094
- ...rest,
1095
- className: cx("sui-form__step", className)
1096
- }, children) : null;
1018
+ return isActive ? /* @__PURE__ */ jsx(chakra.div, { ...rest, className: cx("sui-form__step", className), children }) : null;
1097
1019
  };
1098
- if (__DEV__) {
1099
- FormStep.displayName = "FormStep";
1100
- }
1020
+ FormStep.displayName = "FormStep";
1101
1021
  var PrevButton = (props) => {
1102
1022
  const { isFirstStep, isCompleted, prevStep } = useStepperContext();
1103
- return /* @__PURE__ */ React8.createElement(Button, {
1104
- isDisabled: isFirstStep || isCompleted,
1105
- label: "Back",
1106
- ...props,
1107
- className: cx("sui-form__prev-button", props.className),
1108
- onClick: callAllHandlers(props.onClick, prevStep)
1109
- });
1023
+ return /* @__PURE__ */ jsx(
1024
+ Button,
1025
+ {
1026
+ isDisabled: isFirstStep || isCompleted,
1027
+ children: "Back",
1028
+ ...props,
1029
+ className: cx("sui-form__prev-button", props.className),
1030
+ onClick: callAllHandlers(props.onClick, prevStep)
1031
+ }
1032
+ );
1110
1033
  };
1111
- if (__DEV__) {
1112
- PrevButton.displayName = "PrevButton";
1113
- }
1034
+ PrevButton.displayName = "PrevButton";
1114
1035
  var NextButton = (props) => {
1115
1036
  const { label = "Next", submitLabel = "Complete", ...rest } = props;
1116
1037
  const { isLastStep, isCompleted } = useStepperContext();
1117
- return /* @__PURE__ */ React8.createElement(SubmitButton, {
1118
- ...rest,
1119
- isDisabled: isCompleted,
1120
- className: cx("sui-form__next-button", props.className)
1121
- }, isLastStep || isCompleted ? submitLabel : label);
1038
+ return /* @__PURE__ */ jsx(
1039
+ SubmitButton,
1040
+ {
1041
+ ...rest,
1042
+ isDisabled: isCompleted,
1043
+ className: cx("sui-form__next-button", props.className),
1044
+ children: isLastStep || isCompleted ? submitLabel : label
1045
+ }
1046
+ );
1047
+ };
1048
+ NextButton.displayName = "NextButton";
1049
+ var mapFields = (schema) => schema && Object.entries(schema).map(([name, { items, label, title, ...field }]) => {
1050
+ return {
1051
+ ...field,
1052
+ name,
1053
+ label: label || title || name
1054
+ // json schema compatibility
1055
+ };
1056
+ });
1057
+ var objectFieldResolver = (schema) => {
1058
+ const getFields = () => {
1059
+ return mapFields(schema);
1060
+ };
1061
+ const getNestedFields = (name) => {
1062
+ var _a;
1063
+ const field = get$1(schema, name);
1064
+ if (!field)
1065
+ return [];
1066
+ if (((_a = field.items) == null ? void 0 : _a.type) === "object") {
1067
+ return mapFields(field.items.properties);
1068
+ } else if (field.type === "object") {
1069
+ return mapFields(field.properties);
1070
+ }
1071
+ return [field.items];
1072
+ };
1073
+ return { getFields, getNestedFields };
1122
1074
  };
1123
- if (__DEV__) {
1124
- NextButton.displayName = "NextButton";
1125
- }
1126
1075
  var WatchField = (props) => {
1127
1076
  const { name, defaultValue, isDisabled, isExact } = props;
1128
1077
  const form = useFormContext();
@@ -1134,7 +1083,138 @@ var WatchField = (props) => {
1134
1083
  });
1135
1084
  return props.children(field, form) || null;
1136
1085
  };
1086
+ var Form = forwardRef(
1087
+ (props, ref) => {
1088
+ const {
1089
+ mode = "all",
1090
+ resolver,
1091
+ fieldResolver,
1092
+ fields,
1093
+ reValidateMode,
1094
+ shouldFocusError,
1095
+ shouldUnregister,
1096
+ shouldUseNativeValidation,
1097
+ criteriaMode,
1098
+ delayError,
1099
+ schema,
1100
+ defaultValues,
1101
+ values,
1102
+ context,
1103
+ resetOptions,
1104
+ onChange,
1105
+ onSubmit,
1106
+ onError,
1107
+ formRef,
1108
+ children,
1109
+ ...rest
1110
+ } = props;
1111
+ const form = {
1112
+ mode,
1113
+ resolver,
1114
+ defaultValues,
1115
+ values,
1116
+ reValidateMode,
1117
+ shouldFocusError,
1118
+ shouldUnregister,
1119
+ shouldUseNativeValidation,
1120
+ criteriaMode,
1121
+ delayError,
1122
+ context,
1123
+ resetOptions
1124
+ };
1125
+ const methods = useForm(form);
1126
+ const { handleSubmit } = methods;
1127
+ React12.useImperativeHandle(formRef, () => methods, [formRef, methods]);
1128
+ React12.useEffect(() => {
1129
+ let subscription;
1130
+ if (onChange) {
1131
+ subscription = methods.watch(onChange);
1132
+ }
1133
+ return () => subscription == null ? void 0 : subscription.unsubscribe();
1134
+ }, [methods, onChange]);
1135
+ let _children = children;
1136
+ if (!_children && fieldResolver) {
1137
+ _children = /* @__PURE__ */ jsxs(FormLayout, { children: [
1138
+ /* @__PURE__ */ jsx(AutoFields, {}),
1139
+ /* @__PURE__ */ jsx(SubmitButton, { ...fields == null ? void 0 : fields.submit })
1140
+ ] });
1141
+ }
1142
+ return /* @__PURE__ */ jsx(
1143
+ FormProvider,
1144
+ {
1145
+ ...methods,
1146
+ schema,
1147
+ fieldResolver,
1148
+ fields,
1149
+ children: /* @__PURE__ */ jsx(
1150
+ chakra.form,
1151
+ {
1152
+ ref,
1153
+ onSubmit: handleSubmit(onSubmit, onError),
1154
+ ...rest,
1155
+ className: cx("sui-form", props.className),
1156
+ children: runIfFn(_children, {
1157
+ Field,
1158
+ DisplayIf,
1159
+ ArrayField,
1160
+ ObjectField,
1161
+ ...methods
1162
+ })
1163
+ }
1164
+ )
1165
+ }
1166
+ );
1167
+ }
1168
+ );
1169
+ Form.displayName = "Form";
1170
+ function createForm({
1171
+ resolver,
1172
+ fieldResolver = objectFieldResolver,
1173
+ fields
1174
+ } = {}) {
1175
+ const DefaultForm = forwardRef(
1176
+ (props, ref) => {
1177
+ const { schema, ...rest } = props;
1178
+ return /* @__PURE__ */ jsx(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsx(
1179
+ Form,
1180
+ {
1181
+ ref,
1182
+ resolver: resolver == null ? void 0 : resolver(props.schema),
1183
+ fieldResolver: fieldResolver == null ? void 0 : fieldResolver(schema),
1184
+ ...rest
1185
+ }
1186
+ ) });
1187
+ }
1188
+ );
1189
+ DefaultForm.displayName = "Form";
1190
+ DefaultForm.id = "Form";
1191
+ return DefaultForm;
1192
+ }
1193
+ function createStepForm({ fields, resolver, fieldResolver } = {}) {
1194
+ const StepForm2 = forwardRef((props, ref) => {
1195
+ const { children, steps, ...rest } = props;
1196
+ const stepper = useStepForm({
1197
+ resolver,
1198
+ fieldResolver,
1199
+ ...props
1200
+ });
1201
+ const { getFormProps, ...ctx } = stepper;
1202
+ const context = useMemo(() => ctx, [ctx]);
1203
+ return /* @__PURE__ */ jsx(StepperProvider, { value: context, children: /* @__PURE__ */ jsx(StepFormProvider, { value: context, children: /* @__PURE__ */ jsx(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsx(Form2, { ref, ...rest, ...getFormProps(), children: runIfFn(children, {
1204
+ ...stepper,
1205
+ Field,
1206
+ FormStep,
1207
+ DisplayIf,
1208
+ ArrayField,
1209
+ ObjectField
1210
+ }) }) }) }) });
1211
+ });
1212
+ StepForm2.displayName = `Step${Form2.displayName || Form2.name}`;
1213
+ return StepForm2;
1214
+ }
1215
+ var Form2 = createForm();
1216
+ var StepForm = createStepForm();
1137
1217
 
1138
- export { ArrayField, ArrayFieldAddButton, ArrayFieldContainer, ArrayFieldProvider, ArrayFieldRemoveButton, ArrayFieldRow, ArrayFieldRowContainer, ArrayFieldRowFields, ArrayFieldRowProvider, ArrayFieldRows, AutoForm, BaseField, CheckboxField, DisplayField, DisplayIf, Field, Fields, Form, FormLayout, FormLegend, FormStep, FormStepper, FormValue, InputField, InputRightButton, NativeSelect, NativeSelectField, NextButton, NumberInputField2 as NumberInputField, ObjectField, PasswordInput, PasswordInputField, PinField, PrevButton, RadioField, Select, SelectField, StepForm, StepFormProvider, SubmitButton, SwitchField, TextareaField, WatchField, createForm, objectFieldResolver, registerFieldType, useArrayField, useArrayFieldAddButton, useArrayFieldContext, useArrayFieldRemoveButton, useArrayFieldRow, useArrayFieldRowContext, useFormStep, useStepForm, useStepFormContext, withControlledInput, withUncontrolledInput };
1218
+ export { ArrayField, ArrayFieldAddButton, ArrayFieldContainer, ArrayFieldProvider, ArrayFieldRemoveButton, ArrayFieldRow, ArrayFieldRowContainer, ArrayFieldRowFields, ArrayFieldRowProvider, ArrayFieldRows, AutoFields, BaseField, Form as BaseForm, CheckboxField, DisplayField, DisplayIf, Field, FieldsProvider, Form2 as Form, FormLayout, FormLegend, FormProvider, FormStep, FormStepper, FormValue, InputField, InputRightButton, NativeSelect, NativeSelectField, NextButton, NumberInputField2 as NumberInputField, ObjectField, PasswordInput, PasswordInputField, PinField, PrevButton, RadioField, RadioInput, Select, SelectButton, SelectField, SelectList, SelectOption, StepForm, StepFormProvider, SubmitButton, SwitchField, TextareaField, WatchField, createField, createForm, createStepForm, defaultFieldTypes, objectFieldResolver, useArrayField, useArrayFieldAddButton, useArrayFieldContext, useArrayFieldRemoveButton, useArrayFieldRow, useArrayFieldRowContext, useField, useFormContext, useFormStep, useStepForm, useStepFormContext };
1139
1219
  //# sourceMappingURL=out.js.map
1140
1220
  //# sourceMappingURL=index.mjs.map