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

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