@saas-ui/forms 2.0.5 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
package/dist/index.mjs CHANGED
@@ -1,19 +1,16 @@
1
- import * as React11 from 'react';
2
- import React11__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, createStylesContext, useFormControlContext, useMenuButton, chakra, useMultiStyleConfig, omitThemingProps, Menu, 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';
10
- import { createContext } from '@chakra-ui/react-utils';
1
+ 'use client'
11
2
 
12
3
  // src/form-context.tsx
13
- var FormContext = React11.createContext(null);
4
+ import * as React from "react";
5
+ import {
6
+ FormProvider as HookFormProvider,
7
+ useFormContext as useHookFormContext
8
+ } from "react-hook-form";
9
+ import { jsx } from "react/jsx-runtime";
10
+ var FormContext = React.createContext(null);
14
11
  var useFormContext = () => {
15
- const context = React11.useContext(FormContext);
16
- const hookContext = useFormContext$1();
12
+ const context = React.useContext(FormContext);
13
+ const hookContext = useHookFormContext();
17
14
  if (!context) {
18
15
  throw new Error("FormProvider must be used within a Form component");
19
16
  }
@@ -30,8 +27,16 @@ var useFieldProps = (name) => {
30
27
  };
31
28
  var FormProvider = (props) => {
32
29
  const { children, fieldResolver, schema, fields, ...rest } = props;
33
- return /* @__PURE__ */ jsx(FormProvider$1, { ...rest, children: /* @__PURE__ */ jsx(FormContext.Provider, { value: { fieldResolver, schema, fields }, children }) });
30
+ return /* @__PURE__ */ jsx(HookFormProvider, { ...rest, children: /* @__PURE__ */ jsx(FormContext.Provider, { value: { fieldResolver, schema, fields }, children }) });
34
31
  };
32
+
33
+ // src/display-field.tsx
34
+ import {
35
+ Text,
36
+ FormControl,
37
+ FormLabel
38
+ } from "@chakra-ui/react";
39
+ import { jsx as jsx2, jsxs } from "react/jsx-runtime";
35
40
  var DisplayField = ({
36
41
  name,
37
42
  label,
@@ -39,8 +44,8 @@ var DisplayField = ({
39
44
  ...props
40
45
  }) => {
41
46
  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 }) })
47
+ label ? /* @__PURE__ */ jsx2(FormLabel, { htmlFor: name, children: label }) : null,
48
+ /* @__PURE__ */ jsx2(Text, { fontSize: "md", children: /* @__PURE__ */ jsx2(FormValue, { name }) })
44
49
  ] });
45
50
  };
46
51
  DisplayField.displayName = "DisplayField";
@@ -49,18 +54,49 @@ var FormValue = ({ name }) => {
49
54
  return getValues(name) || null;
50
55
  };
51
56
  FormValue.displayName = "FormValue";
57
+
58
+ // src/field.tsx
59
+ import * as React6 from "react";
60
+
61
+ // src/fields-context.tsx
62
+ import React5 from "react";
63
+
64
+ // src/default-fields.tsx
65
+ import {
66
+ forwardRef as forwardRef8,
67
+ Input as Input2,
68
+ Textarea,
69
+ Checkbox,
70
+ Switch,
71
+ InputGroup as InputGroup2,
72
+ PinInputField,
73
+ HStack,
74
+ PinInput
75
+ } from "@chakra-ui/react";
76
+
77
+ // src/number-input/number-input.tsx
78
+ import {
79
+ forwardRef,
80
+ NumberInput as ChakraNumberInput,
81
+ NumberInputField,
82
+ NumberInputStepper,
83
+ NumberIncrementStepper,
84
+ NumberDecrementStepper
85
+ } from "@chakra-ui/react";
86
+ import { ChevronDownIcon, ChevronUpIcon } from "@saas-ui/core";
87
+ import { jsx as jsx3, jsxs as jsxs2 } from "react/jsx-runtime";
52
88
  var NumberInput = forwardRef((props, ref) => {
53
89
  const {
54
90
  hideStepper,
55
- incrementIcon = /* @__PURE__ */ jsx(ChevronUpIcon, {}),
56
- decrementIcon = /* @__PURE__ */ jsx(ChevronDownIcon, {}),
91
+ incrementIcon = /* @__PURE__ */ jsx3(ChevronUpIcon, {}),
92
+ decrementIcon = /* @__PURE__ */ jsx3(ChevronDownIcon, {}),
57
93
  ...rest
58
94
  } = 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 })
95
+ return /* @__PURE__ */ jsxs2(ChakraNumberInput, { ...rest, ref, children: [
96
+ /* @__PURE__ */ jsx3(NumberInputField, {}),
97
+ !hideStepper && /* @__PURE__ */ jsxs2(NumberInputStepper, { children: [
98
+ /* @__PURE__ */ jsx3(NumberIncrementStepper, { children: incrementIcon }),
99
+ /* @__PURE__ */ jsx3(NumberDecrementStepper, { children: decrementIcon })
64
100
  ] })
65
101
  ] });
66
102
  });
@@ -68,14 +104,30 @@ NumberInput.defaultProps = {
68
104
  hideStepper: false
69
105
  };
70
106
  NumberInput.displayName = "NumberInput";
71
- var InputRightButton = forwardRef(
107
+
108
+ // src/password-input/password-input.tsx
109
+ import { useState } from "react";
110
+ import { forwardRef as forwardRef3, InputGroup, Input } from "@chakra-ui/react";
111
+ import { ViewIcon, ViewOffIcon } from "@saas-ui/core/icons";
112
+
113
+ // src/input-right-button/input-right-button.tsx
114
+ import {
115
+ Button,
116
+ forwardRef as forwardRef2,
117
+ InputRightElement
118
+ } from "@chakra-ui/react";
119
+ import { jsx as jsx4 } from "react/jsx-runtime";
120
+ var InputRightButton = forwardRef2(
72
121
  (props, ref) => {
73
- return /* @__PURE__ */ jsx(InputRightElement, { w: "auto", px: "1", py: "1", alignItems: "stretch", children: /* @__PURE__ */ jsx(Button, { ref, height: "auto", ...props }) });
122
+ return /* @__PURE__ */ jsx4(InputRightElement, { w: "auto", px: "1", py: "1", alignItems: "stretch", children: /* @__PURE__ */ jsx4(Button, { ref, height: "auto", ...props }) });
74
123
  }
75
124
  );
76
125
  InputRightButton.id = "InputRightElement";
77
126
  InputRightButton.displayName = "InputRightButton";
78
- var PasswordInput = forwardRef(
127
+
128
+ // src/password-input/password-input.tsx
129
+ import { jsx as jsx5, jsxs as jsxs3 } from "react/jsx-runtime";
130
+ var PasswordInput = forwardRef3(
79
131
  (props, ref) => {
80
132
  const {
81
133
  viewIcon,
@@ -93,18 +145,18 @@ var PasswordInput = forwardRef(
93
145
  const label = show ? "Hide password" : "Show password";
94
146
  let icon;
95
147
  if (show) {
96
- icon = viewIcon || /* @__PURE__ */ jsx(ViewIcon, {});
148
+ icon = viewIcon || /* @__PURE__ */ jsx5(ViewIcon, {});
97
149
  } else {
98
- icon = viewOffIcon || /* @__PURE__ */ jsx(ViewOffIcon, {});
150
+ icon = viewOffIcon || /* @__PURE__ */ jsx5(ViewOffIcon, {});
99
151
  }
100
152
  const groupProps = {
101
153
  width: w || width,
102
154
  size,
103
155
  variant
104
156
  };
105
- return /* @__PURE__ */ jsxs(InputGroup, { ...groupProps, children: [
157
+ return /* @__PURE__ */ jsxs3(InputGroup, { ...groupProps, children: [
106
158
  leftAddon,
107
- /* @__PURE__ */ jsx(
159
+ /* @__PURE__ */ jsx5(
108
160
  Input,
109
161
  {
110
162
  ...inputProps,
@@ -113,7 +165,7 @@ var PasswordInput = forwardRef(
113
165
  autoComplete: show ? "off" : autoComplete
114
166
  }
115
167
  ),
116
- /* @__PURE__ */ jsx(
168
+ /* @__PURE__ */ jsx5(
117
169
  InputRightButton,
118
170
  {
119
171
  onClick: handleClick,
@@ -126,16 +178,27 @@ var PasswordInput = forwardRef(
126
178
  }
127
179
  );
128
180
  PasswordInput.displayName = "PasswordInput";
181
+
182
+ // src/radio/radio-input.tsx
183
+ import {
184
+ forwardRef as forwardRef4,
185
+ Stack,
186
+ RadioGroup,
187
+ Radio
188
+ } from "@chakra-ui/react";
189
+
190
+ // src/utils.ts
191
+ import * as React3 from "react";
129
192
  var mapNestedFields = (name, children) => {
130
- return React11.Children.map(children, (child) => {
131
- if (React11.isValidElement(child) && child.props.name) {
193
+ return React3.Children.map(children, (child) => {
194
+ if (React3.isValidElement(child) && child.props.name) {
132
195
  let childName = child.props.name;
133
196
  if (childName.includes(".")) {
134
197
  childName = childName.replace(/^.*\.(.*)/, "$1");
135
198
  } else if (childName.includes(".$")) {
136
199
  childName = childName.replace(/^.*\.\$(.*)/, "$1");
137
200
  }
138
- return React11.cloneElement(child, {
201
+ return React3.cloneElement(child, {
139
202
  ...child.props,
140
203
  name: `${name}.${childName}`
141
204
  });
@@ -154,12 +217,15 @@ var mapOptions = (options) => {
154
217
  return option;
155
218
  });
156
219
  };
157
- var RadioInput = forwardRef(
220
+
221
+ // src/radio/radio-input.tsx
222
+ import { jsx as jsx6 } from "react/jsx-runtime";
223
+ var RadioInput = forwardRef4(
158
224
  ({ options: optionsProp, spacing, direction, ...props }, ref) => {
159
225
  const { onBlur, onChange, ...groupProps } = props;
160
226
  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(
227
+ return /* @__PURE__ */ jsx6(RadioGroup, { onChange, ...groupProps, children: /* @__PURE__ */ jsx6(Stack, { spacing, direction, children: options.map(({ value, label, ...radioProps }, i) => {
228
+ return /* @__PURE__ */ jsx6(
163
229
  Radio,
164
230
  {
165
231
  onBlur,
@@ -174,8 +240,34 @@ var RadioInput = forwardRef(
174
240
  }
175
241
  );
176
242
  RadioInput.displayName = "RadioInput";
243
+
244
+ // src/select/select.tsx
245
+ import {
246
+ chakra,
247
+ forwardRef as forwardRef5,
248
+ Menu,
249
+ MenuList,
250
+ MenuItemOption,
251
+ MenuOptionGroup,
252
+ Button as Button2,
253
+ omitThemingProps,
254
+ useMultiStyleConfig,
255
+ useFormControlContext,
256
+ useMenuButton
257
+ } from "@chakra-ui/react";
258
+ import { cx, dataAttr } from "@chakra-ui/utils";
259
+ import { ChevronDownIcon as ChevronDownIcon2 } from "@saas-ui/core";
260
+
261
+ // src/select/select-context.tsx
262
+ import {
263
+ createStylesContext,
264
+ useControllableState,
265
+ useFormControl
266
+ } from "@chakra-ui/react";
267
+ import { createContext as createContext2 } from "@chakra-ui/react-utils";
268
+ import React4 from "react";
177
269
  var [SelectStylesProvider, useSelectStyles] = createStylesContext("SuiSelect");
178
- var [SelectProvider, useSelectContext] = createContext({
270
+ var [SelectProvider, useSelectContext] = createContext2({
179
271
  strict: true
180
272
  });
181
273
  var useSelect = (props) => {
@@ -196,14 +288,14 @@ var useSelect = (props) => {
196
288
  onChange
197
289
  });
198
290
  const controlProps = useFormControl({ name });
199
- const options = React11__default.useMemo(
291
+ const options = React4.useMemo(
200
292
  () => optionsProp && mapOptions(optionsProp),
201
293
  [optionsProp]
202
294
  );
203
295
  const handleChange = (value2) => {
204
296
  setCurrentValue(value2);
205
297
  };
206
- const getDisplayValue = React11__default.useCallback(
298
+ const getDisplayValue = React4.useCallback(
207
299
  (value2) => {
208
300
  if (!options) {
209
301
  return value2;
@@ -217,7 +309,7 @@ var useSelect = (props) => {
217
309
  },
218
310
  [options]
219
311
  );
220
- const displayValue = React11__default.useMemo(
312
+ const displayValue = React4.useMemo(
221
313
  () => currentValue ? (Array.isArray(currentValue) ? currentValue : [currentValue]).map(
222
314
  getDisplayValue
223
315
  ) : [],
@@ -236,7 +328,10 @@ var useSelect = (props) => {
236
328
  isDisabled
237
329
  };
238
330
  };
239
- var SelectButton = forwardRef(
331
+
332
+ // src/select/select.tsx
333
+ import { jsx as jsx7, jsxs as jsxs4 } from "react/jsx-runtime";
334
+ var SelectButton = forwardRef5(
240
335
  (props, ref) => {
241
336
  var _a, _b, _c, _d, _e;
242
337
  const {
@@ -257,7 +352,7 @@ var SelectButton = forwardRef(
257
352
  onBlur,
258
353
  onFocus
259
354
  } = context || {};
260
- const { rightIcon = /* @__PURE__ */ jsx(ChevronDownIcon, {}), ...rest } = props;
355
+ const { rightIcon = /* @__PURE__ */ jsx7(ChevronDownIcon2, {}), ...rest } = props;
261
356
  const focusStyles = (_a = styles.field) == null ? void 0 : _a._focusVisible;
262
357
  const readOnlyStyles = (_b = styles.field) == null ? void 0 : _b._readOnly;
263
358
  const invalid = (_c = styles.field) == null ? void 0 : _c._invalid;
@@ -279,8 +374,8 @@ var SelectButton = forwardRef(
279
374
  h: "auto"
280
375
  };
281
376
  const buttonProps = useMenuButton(rest, ref);
282
- return /* @__PURE__ */ jsx(
283
- Button,
377
+ return /* @__PURE__ */ jsx7(
378
+ Button2,
284
379
  {
285
380
  ...buttonProps,
286
381
  ...buttonStyles,
@@ -294,7 +389,7 @@ var SelectButton = forwardRef(
294
389
  "data-focus": dataAttr(isFocused),
295
390
  "data-required": dataAttr(isRequired),
296
391
  rightIcon,
297
- children: /* @__PURE__ */ jsx(
392
+ children: /* @__PURE__ */ jsx7(
298
393
  chakra.span,
299
394
  {
300
395
  __css: {
@@ -313,15 +408,15 @@ var SelectButton = forwardRef(
313
408
  }
314
409
  );
315
410
  SelectButton.displayName = "SelectButton";
316
- var Select = forwardRef((props, ref) => {
411
+ var Select = forwardRef5((props, ref) => {
317
412
  const { name, children, isDisabled, multiple, ...rest } = props;
318
413
  const styles = useMultiStyleConfig("SuiSelect", props);
319
414
  const menuProps = omitThemingProps(rest);
320
415
  const context = useSelect(props);
321
416
  const { value, controlProps } = context;
322
- return /* @__PURE__ */ jsx(SelectProvider, { value: context, children: /* @__PURE__ */ jsx(SelectStylesProvider, { value: styles, children: /* @__PURE__ */ jsx(Menu, { ...menuProps, closeOnSelect: !multiple, children: /* @__PURE__ */ jsxs(chakra.div, { className: cx("sui-select"), children: [
417
+ return /* @__PURE__ */ jsx7(SelectProvider, { value: context, children: /* @__PURE__ */ jsx7(SelectStylesProvider, { value: styles, children: /* @__PURE__ */ jsx7(Menu, { ...menuProps, closeOnSelect: !multiple, children: /* @__PURE__ */ jsxs4(chakra.div, { className: cx("sui-select"), children: [
323
418
  children,
324
- /* @__PURE__ */ jsx(
419
+ /* @__PURE__ */ jsx7(
325
420
  chakra.input,
326
421
  {
327
422
  ...controlProps,
@@ -336,33 +431,56 @@ var Select = forwardRef((props, ref) => {
336
431
  });
337
432
  var SelectList = (props) => {
338
433
  const { defaultValue, value, options, multiple, onChange } = useSelectContext();
339
- return /* @__PURE__ */ jsx(MenuList, { maxH: "100vh", overflowY: "auto", ...props, children: /* @__PURE__ */ jsx(
434
+ return /* @__PURE__ */ jsx7(MenuList, { maxH: "100vh", overflowY: "auto", ...props, children: /* @__PURE__ */ jsx7(
340
435
  MenuOptionGroup,
341
436
  {
342
437
  defaultValue: defaultValue || value,
343
438
  value,
344
439
  onChange,
345
440
  type: multiple ? "checkbox" : "radio",
346
- children: options ? options.map(({ value: value2, label, ...rest }, i) => /* @__PURE__ */ jsx(SelectOption, { value: value2, ...rest, children: label || value2 }, i)) : props.children
441
+ children: options ? options.map(({ value: value2, label, ...rest }, i) => /* @__PURE__ */ jsx7(SelectOption, { value: value2, ...rest, children: label || value2 }, i)) : props.children
347
442
  }
348
443
  ) });
349
444
  };
350
445
  Select.displayName = "Select";
351
- var SelectOption = forwardRef(
446
+ var SelectOption = forwardRef5(
352
447
  (props, ref) => {
353
- return /* @__PURE__ */ jsx(MenuItemOption, { ref, ...props });
448
+ return /* @__PURE__ */ jsx7(MenuItemOption, { ref, ...props });
354
449
  }
355
450
  );
356
451
  SelectOption.id = "MenuItemOption";
357
452
  SelectOption.displayName = "SelectOption";
358
- var NativeSelect = forwardRef(
453
+
454
+ // src/select/native-select.tsx
455
+ import {
456
+ forwardRef as forwardRef6,
457
+ Select as ChakraSelect
458
+ } from "@chakra-ui/react";
459
+ import { jsx as jsx8 } from "react/jsx-runtime";
460
+ var NativeSelect = forwardRef6(
359
461
  ({ options, children, ...props }, ref) => {
360
- return /* @__PURE__ */ jsx(Select$1, { ref, ...props, children: children || (options == null ? void 0 : options.map(({ value, label }) => {
361
- return /* @__PURE__ */ jsx("option", { value, children: label || value }, value);
462
+ return /* @__PURE__ */ jsx8(ChakraSelect, { ref, ...props, children: children || (options == null ? void 0 : options.map(({ value, label }) => {
463
+ return /* @__PURE__ */ jsx8("option", { value, children: label || value }, value);
362
464
  })) });
363
465
  }
364
466
  );
365
467
  NativeSelect.displayName = "NativeSelect";
468
+
469
+ // src/create-field.tsx
470
+ import { Controller } from "react-hook-form";
471
+ import { forwardRef as forwardRef7, useMergeRefs } from "@chakra-ui/react";
472
+ import { callAllHandlers } from "@chakra-ui/utils";
473
+
474
+ // src/base-field.tsx
475
+ import { get } from "react-hook-form";
476
+ import {
477
+ Box,
478
+ FormControl as FormControl2,
479
+ FormLabel as FormLabel2,
480
+ FormHelperText,
481
+ FormErrorMessage
482
+ } from "@chakra-ui/react";
483
+ import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
366
484
  var getError = (name, formState) => {
367
485
  return get(formState.errors, name);
368
486
  };
@@ -370,18 +488,21 @@ var BaseField = (props) => {
370
488
  const { name, label, help, hideLabel, children, ...controlProps } = props;
371
489
  const { formState } = useFormContext();
372
490
  const error = getError(name, formState);
373
- return /* @__PURE__ */ jsxs(FormControl, { ...controlProps, isInvalid: !!error, children: [
374
- label && !hideLabel ? /* @__PURE__ */ jsx(FormLabel, { children: label }) : null,
375
- /* @__PURE__ */ jsxs(Box, { children: [
491
+ return /* @__PURE__ */ jsxs5(FormControl2, { ...controlProps, isInvalid: !!error, children: [
492
+ label && !hideLabel ? /* @__PURE__ */ jsx9(FormLabel2, { children: label }) : null,
493
+ /* @__PURE__ */ jsxs5(Box, { children: [
376
494
  children,
377
- help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */ jsx(FormHelperText, { children: help }) : null,
378
- (error == null ? void 0 : error.message) && /* @__PURE__ */ jsx(FormErrorMessage, { children: error == null ? void 0 : error.message })
495
+ help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */ jsx9(FormHelperText, { children: help }) : null,
496
+ (error == null ? void 0 : error.message) && /* @__PURE__ */ jsx9(FormErrorMessage, { children: error == null ? void 0 : error.message })
379
497
  ] })
380
498
  ] });
381
499
  };
382
500
  BaseField.displayName = "BaseField";
501
+
502
+ // src/create-field.tsx
503
+ import { jsx as jsx10 } from "react/jsx-runtime";
383
504
  var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseField2 }) => {
384
- const Field2 = forwardRef((props, ref) => {
505
+ const Field2 = forwardRef7((props, ref) => {
385
506
  const {
386
507
  id,
387
508
  name,
@@ -398,7 +519,7 @@ var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFie
398
519
  required: isRequired,
399
520
  ...rules
400
521
  };
401
- return /* @__PURE__ */ jsx(
522
+ return /* @__PURE__ */ jsx10(
402
523
  BaseField2,
403
524
  {
404
525
  id,
@@ -410,7 +531,7 @@ var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFie
410
531
  isInvalid,
411
532
  isReadOnly,
412
533
  isRequired,
413
- children: /* @__PURE__ */ jsx(
534
+ children: /* @__PURE__ */ jsx10(
414
535
  InputComponent,
415
536
  {
416
537
  ref,
@@ -428,16 +549,16 @@ var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFie
428
549
  return Field2;
429
550
  };
430
551
  var withControlledInput = (InputComponent) => {
431
- return forwardRef(
552
+ return forwardRef7(
432
553
  ({ name, rules, ...inputProps }, ref) => {
433
554
  const { control } = useFormContext();
434
- return /* @__PURE__ */ jsx(
555
+ return /* @__PURE__ */ jsx10(
435
556
  Controller,
436
557
  {
437
558
  name,
438
559
  control,
439
560
  rules,
440
- render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */ jsx(
561
+ render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */ jsx10(
441
562
  InputComponent,
442
563
  {
443
564
  ...field,
@@ -453,11 +574,11 @@ var withControlledInput = (InputComponent) => {
453
574
  );
454
575
  };
455
576
  var withUncontrolledInput = (InputComponent) => {
456
- return forwardRef(
577
+ return forwardRef7(
457
578
  ({ name, rules, ...inputProps }, ref) => {
458
579
  const { register } = useFormContext();
459
580
  const { ref: _ref, ...field } = register(name, rules);
460
- return /* @__PURE__ */ jsx(
581
+ return /* @__PURE__ */ jsx10(
461
582
  InputComponent,
462
583
  {
463
584
  ...field,
@@ -485,11 +606,14 @@ var createField = (component, options) => {
485
606
  });
486
607
  return Field2;
487
608
  };
609
+
610
+ // src/default-fields.tsx
611
+ import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
488
612
  var InputField = createField(
489
- forwardRef(({ type = "text", leftAddon, rightAddon, size, ...rest }, ref) => {
490
- const input = /* @__PURE__ */ jsx(Input, { type, size, ...rest, ref });
613
+ forwardRef8(({ type = "text", leftAddon, rightAddon, size, ...rest }, ref) => {
614
+ const input = /* @__PURE__ */ jsx11(Input2, { type, size, ...rest, ref });
491
615
  if (leftAddon || rightAddon) {
492
- return /* @__PURE__ */ jsxs(InputGroup, { size, children: [
616
+ return /* @__PURE__ */ jsxs6(InputGroup2, { size, children: [
493
617
  leftAddon,
494
618
  input,
495
619
  rightAddon
@@ -505,22 +629,22 @@ var NumberInputField2 = createField(
505
629
  }
506
630
  );
507
631
  var PasswordInputField = createField(
508
- forwardRef((props, ref) => /* @__PURE__ */ jsx(PasswordInput, { ref, ...props }))
632
+ forwardRef8((props, ref) => /* @__PURE__ */ jsx11(PasswordInput, { ref, ...props }))
509
633
  );
510
634
  var TextareaField = createField(Textarea);
511
635
  var SwitchField = createField(
512
- forwardRef(({ type, value, ...rest }, ref) => {
513
- return /* @__PURE__ */ jsx(Switch, { isChecked: !!value, ...rest, ref });
636
+ forwardRef8(({ type, value, ...rest }, ref) => {
637
+ return /* @__PURE__ */ jsx11(Switch, { isChecked: !!value, ...rest, ref });
514
638
  }),
515
639
  {
516
640
  isControlled: true
517
641
  }
518
642
  );
519
643
  var SelectField = createField(
520
- forwardRef((props, ref) => {
521
- return /* @__PURE__ */ jsxs(Select, { ref, ...props, children: [
522
- /* @__PURE__ */ jsx(SelectButton, {}),
523
- /* @__PURE__ */ jsx(SelectList, {})
644
+ forwardRef8((props, ref) => {
645
+ return /* @__PURE__ */ jsxs6(Select, { ref, ...props, children: [
646
+ /* @__PURE__ */ jsx11(SelectButton, {}),
647
+ /* @__PURE__ */ jsx11(SelectList, {})
524
648
  ] });
525
649
  }),
526
650
  {
@@ -528,8 +652,8 @@ var SelectField = createField(
528
652
  }
529
653
  );
530
654
  var CheckboxField = createField(
531
- forwardRef(({ label, type, ...props }, ref) => {
532
- return /* @__PURE__ */ jsx(Checkbox, { ref, ...props, children: label });
655
+ forwardRef8(({ label, type, ...props }, ref) => {
656
+ return /* @__PURE__ */ jsx11(Checkbox, { ref, ...props, children: label });
533
657
  }),
534
658
  {
535
659
  hideLabel: true
@@ -542,13 +666,13 @@ var NativeSelectField = createField(NativeSelect, {
542
666
  isControlled: true
543
667
  });
544
668
  var PinField = createField(
545
- forwardRef((props, ref) => {
669
+ forwardRef8((props, ref) => {
546
670
  const { pinLength = 4, pinType, spacing, ...inputProps } = props;
547
671
  const inputs = [];
548
672
  for (let i = 0; i < pinLength; i++) {
549
- inputs.push(/* @__PURE__ */ jsx(PinInputField, { ref }, i));
673
+ inputs.push(/* @__PURE__ */ jsx11(PinInputField, { ref }, i));
550
674
  }
551
- return /* @__PURE__ */ jsx(HStack, { spacing, children: /* @__PURE__ */ jsx(PinInput, { ...inputProps, type: pinType, children: inputs }) });
675
+ return /* @__PURE__ */ jsx11(HStack, { spacing, children: /* @__PURE__ */ jsx11(PinInput, { ...inputProps, type: pinType, children: inputs }) });
552
676
  }),
553
677
  {
554
678
  isControlled: true
@@ -569,28 +693,47 @@ var defaultFieldTypes = {
569
693
  pin: PinField,
570
694
  "native-select": NativeSelectField
571
695
  };
572
- var FieldsContext = React11__default.createContext(
696
+
697
+ // src/fields-context.tsx
698
+ import { jsx as jsx12 } from "react/jsx-runtime";
699
+ var FieldsContext = React5.createContext(
573
700
  null
574
701
  );
575
702
  var FieldsProvider = (props) => {
576
703
  const fields = { ...defaultFieldTypes, ...props.value };
577
- return /* @__PURE__ */ jsx(FieldsContext.Provider, { value: fields, children: props.children });
704
+ return /* @__PURE__ */ jsx12(FieldsContext.Provider, { value: fields, children: props.children });
578
705
  };
579
706
  var useField = (type) => {
580
- const context = React11__default.useContext(FieldsContext);
707
+ const context = React5.useContext(FieldsContext);
581
708
  return (context == null ? void 0 : context[type]) || InputField;
582
709
  };
710
+
711
+ // src/field.tsx
712
+ import { jsx as jsx13 } from "react/jsx-runtime";
583
713
  var defaultInputType = "text";
584
- var Field = React11.forwardRef(
714
+ var Field = React6.forwardRef(
585
715
  (props, ref) => {
586
716
  const { type = defaultInputType, name } = props;
587
717
  const overrides = useFieldProps(name);
588
718
  const InputComponent = useField((overrides == null ? void 0 : overrides.type) || type);
589
- return /* @__PURE__ */ jsx(InputComponent, { ref, ...props, ...overrides });
719
+ return /* @__PURE__ */ jsx13(InputComponent, { ref, ...props, ...overrides });
590
720
  }
591
721
  );
722
+
723
+ // src/fields.tsx
724
+ import * as React10 from "react";
725
+
726
+ // src/layout.tsx
727
+ import * as React7 from "react";
728
+ import {
729
+ chakra as chakra2,
730
+ SimpleGrid,
731
+ useTheme
732
+ } from "@chakra-ui/react";
733
+ import { cx as cx2 } from "@chakra-ui/utils";
734
+ import { jsx as jsx14 } from "react/jsx-runtime";
592
735
  var FormLayoutItem = ({ children }) => {
593
- return /* @__PURE__ */ jsx(chakra.div, { children });
736
+ return /* @__PURE__ */ jsx14(chakra2.div, { children });
594
737
  };
595
738
  FormLayoutItem.displayName = "FormLayoutItem";
596
739
  var FormLayout = ({ children, ...props }) => {
@@ -603,14 +746,14 @@ var FormLayout = ({ children, ...props }) => {
603
746
  ...defaultProps,
604
747
  ...props
605
748
  };
606
- return /* @__PURE__ */ jsx(
749
+ return /* @__PURE__ */ jsx14(
607
750
  SimpleGrid,
608
751
  {
609
752
  ...gridProps,
610
- className: cx("sui-form__layout", props.className),
611
- children: React11.Children.map(children, (child) => {
612
- if (React11.isValidElement(child)) {
613
- return /* @__PURE__ */ jsx(FormLayoutItem, { children: child });
753
+ className: cx2("sui-form__layout", props.className),
754
+ children: React7.Children.map(children, (child) => {
755
+ if (React7.isValidElement(child)) {
756
+ return /* @__PURE__ */ jsx14(FormLayoutItem, { children: child });
614
757
  }
615
758
  return child;
616
759
  })
@@ -618,10 +761,26 @@ var FormLayout = ({ children, ...props }) => {
618
761
  );
619
762
  };
620
763
  FormLayout.displayName = "FormLayout";
621
- var [ArrayFieldProvider, useArrayFieldContext] = createContext({
764
+
765
+ // src/array-field.tsx
766
+ import * as React9 from "react";
767
+ import {
768
+ chakra as chakra3,
769
+ forwardRef as forwardRef11,
770
+ Button as Button3
771
+ } from "@chakra-ui/react";
772
+ import { PlusIcon, MinusIcon } from "@saas-ui/core/icons";
773
+
774
+ // src/use-array-field.tsx
775
+ import * as React8 from "react";
776
+ import {
777
+ useFieldArray
778
+ } from "react-hook-form";
779
+ import { createContext as createContext3 } from "@chakra-ui/react-utils";
780
+ var [ArrayFieldProvider, useArrayFieldContext] = createContext3({
622
781
  name: "ArrayFieldContext"
623
782
  });
624
- var [ArrayFieldRowProvider, useArrayFieldRowContext] = createContext({
783
+ var [ArrayFieldRowProvider, useArrayFieldRowContext] = createContext3({
625
784
  name: "ArrayFieldRowContext"
626
785
  });
627
786
  var useArrayField = ({
@@ -648,7 +807,7 @@ var useArrayField = ({
648
807
  var useArrayFieldRow = ({ index }) => {
649
808
  const { clearErrors } = useFormContext();
650
809
  const { name, remove, fields } = useArrayFieldContext();
651
- React11.useEffect(() => {
810
+ React8.useEffect(() => {
652
811
  clearErrors(name);
653
812
  }, []);
654
813
  return {
@@ -656,7 +815,7 @@ var useArrayFieldRow = ({ index }) => {
656
815
  isFirst: index === 0,
657
816
  isLast: index === fields.length - 1,
658
817
  name: `${name}.${index}`,
659
- remove: React11.useCallback(() => {
818
+ remove: React8.useCallback(() => {
660
819
  clearErrors(name);
661
820
  remove(index);
662
821
  }, [index])
@@ -681,14 +840,18 @@ var useArrayFieldAddButton = () => {
681
840
  isDisabled
682
841
  };
683
842
  };
843
+
844
+ // src/array-field.tsx
845
+ import { isFunction } from "@chakra-ui/utils";
846
+ import { Fragment, jsx as jsx15, jsxs as jsxs7 } from "react/jsx-runtime";
684
847
  var ArrayFieldRow = ({
685
848
  children,
686
849
  index,
687
850
  ...rowFieldsProps
688
851
  }) => {
689
- return /* @__PURE__ */ jsxs(ArrayFieldRowContainer, { index, children: [
690
- /* @__PURE__ */ jsx(ArrayFieldRowFields, { ...rowFieldsProps, children }),
691
- /* @__PURE__ */ jsx(ArrayFieldRemoveButton, {})
852
+ return /* @__PURE__ */ jsxs7(ArrayFieldRowContainer, { index, children: [
853
+ /* @__PURE__ */ jsx15(ArrayFieldRowFields, { ...rowFieldsProps, children }),
854
+ /* @__PURE__ */ jsx15(ArrayFieldRemoveButton, {})
692
855
  ] });
693
856
  };
694
857
  ArrayFieldRow.displayName = "ArrayFieldRow";
@@ -697,7 +860,7 @@ var ArrayFieldRowFields = ({
697
860
  ...layoutProps
698
861
  }) => {
699
862
  const { name } = useArrayFieldRowContext();
700
- return /* @__PURE__ */ jsx(FormLayout, { flex: "1", mr: "2", ...layoutProps, children: mapNestedFields(name, children) });
863
+ return /* @__PURE__ */ jsx15(FormLayout, { flex: "1", mr: "2", ...layoutProps, children: mapNestedFields(name, children) });
701
864
  };
702
865
  ArrayFieldRowFields.displayName = "ArrayFieldRowFields";
703
866
  var ArrayFieldRowContainer = ({
@@ -713,33 +876,33 @@ var ArrayFieldRowContainer = ({
713
876
  width: "100%",
714
877
  mb: 4
715
878
  };
716
- return /* @__PURE__ */ jsx(ArrayFieldRowProvider, { value: context, children: /* @__PURE__ */ jsx(chakra.div, { ...rest, __css: styles, children }) });
879
+ return /* @__PURE__ */ jsx15(ArrayFieldRowProvider, { value: context, children: /* @__PURE__ */ jsx15(chakra3.div, { ...rest, __css: styles, children }) });
717
880
  };
718
881
  ArrayFieldRowContainer.displayName = "ArrayFieldRowContainer";
719
882
  var ArrayFieldRemoveButton = (props) => {
720
- return /* @__PURE__ */ jsx(Button, { "aria-label": "Remove row", ...useArrayFieldRemoveButton(), ...props, children: props.children || /* @__PURE__ */ jsx(MinusIcon, {}) });
883
+ return /* @__PURE__ */ jsx15(Button3, { "aria-label": "Remove row", ...useArrayFieldRemoveButton(), ...props, children: props.children || /* @__PURE__ */ jsx15(MinusIcon, {}) });
721
884
  };
722
885
  ArrayFieldRemoveButton.displayName = "ArrayFieldRemoveButton";
723
886
  var ArrayFieldAddButton = (props) => {
724
- return /* @__PURE__ */ jsx(
725
- Button,
887
+ return /* @__PURE__ */ jsx15(
888
+ Button3,
726
889
  {
727
890
  "aria-label": "Add row",
728
891
  float: "right",
729
892
  ...useArrayFieldAddButton(),
730
893
  ...props,
731
- children: props.children || /* @__PURE__ */ jsx(PlusIcon, {})
894
+ children: props.children || /* @__PURE__ */ jsx15(PlusIcon, {})
732
895
  }
733
896
  );
734
897
  };
735
898
  ArrayFieldAddButton.displayName = "ArrayFieldAddButton";
736
- var ArrayField = forwardRef(
899
+ var ArrayField = forwardRef11(
737
900
  (props, ref) => {
738
901
  const { children, ...containerProps } = props;
739
- const rowFn = isFunction(children) ? children : (fields) => /* @__PURE__ */ jsx(Fragment, { children: fields.map(({ id }, index) => /* @__PURE__ */ jsx(ArrayFieldRow, { index, children }, id)) || null });
740
- return /* @__PURE__ */ jsxs(ArrayFieldContainer, { ref, ...containerProps, children: [
741
- /* @__PURE__ */ jsx(ArrayFieldRows, { children: rowFn }),
742
- /* @__PURE__ */ jsx(ArrayFieldAddButton, {})
902
+ const rowFn = isFunction(children) ? children : (fields) => /* @__PURE__ */ jsx15(Fragment, { children: fields.map(({ id }, index) => /* @__PURE__ */ jsx15(ArrayFieldRow, { index, children }, id)) || null });
903
+ return /* @__PURE__ */ jsxs7(ArrayFieldContainer, { ref, ...containerProps, children: [
904
+ /* @__PURE__ */ jsx15(ArrayFieldRows, { children: rowFn }),
905
+ /* @__PURE__ */ jsx15(ArrayFieldAddButton, {})
743
906
  ] });
744
907
  }
745
908
  );
@@ -751,7 +914,7 @@ var ArrayFieldRows = ({
751
914
  return children(fields);
752
915
  };
753
916
  ArrayFieldRows.displayName = "ArrayFieldRows";
754
- var ArrayFieldContainer = React11.forwardRef(
917
+ var ArrayFieldContainer = React9.forwardRef(
755
918
  ({
756
919
  name,
757
920
  defaultValue,
@@ -769,14 +932,22 @@ var ArrayFieldContainer = React11.forwardRef(
769
932
  min: min || (overrides == null ? void 0 : overrides.min),
770
933
  max: max || (overrides == null ? void 0 : overrides.max)
771
934
  });
772
- React11.useImperativeHandle(ref, () => context, [ref, context]);
773
- return /* @__PURE__ */ jsx(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ jsx(BaseField, { name, ...fieldProps, ...overrides, children }) });
935
+ React9.useImperativeHandle(ref, () => context, [ref, context]);
936
+ return /* @__PURE__ */ jsx15(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ jsx15(BaseField, { name, ...fieldProps, ...overrides, children }) });
774
937
  }
775
938
  );
776
939
  ArrayFieldContainer.displayName = "ArrayFieldContainer";
940
+
941
+ // src/object-field.tsx
942
+ import {
943
+ FormControl as FormControl3,
944
+ FormLabel as FormLabel3,
945
+ useStyleConfig
946
+ } from "@chakra-ui/react";
947
+ import { jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
777
948
  var FormLegend = (props) => {
778
949
  const styles = useStyleConfig("SuiFormLegend");
779
- return /* @__PURE__ */ jsx(FormLabel, { as: "legend", sx: styles, ...props });
950
+ return /* @__PURE__ */ jsx16(FormLabel3, { as: "legend", sx: styles, ...props });
780
951
  };
781
952
  var ObjectField = (props) => {
782
953
  const {
@@ -791,9 +962,9 @@ var ObjectField = (props) => {
791
962
  const { hideLabel, columns, spacing, ...overrides } = useFieldProps(
792
963
  name
793
964
  );
794
- return /* @__PURE__ */ jsxs(FormControl, { name, as: "fieldset", ...fieldProps, ...overrides, children: [
795
- /* @__PURE__ */ jsx(FormLegend, { display: hideLabelProp || hideLabel ? "none" : "block", children: label }),
796
- /* @__PURE__ */ jsx(
965
+ return /* @__PURE__ */ jsxs8(FormControl3, { name, as: "fieldset", ...fieldProps, ...overrides, children: [
966
+ /* @__PURE__ */ jsx16(FormLegend, { display: hideLabelProp || hideLabel ? "none" : "block", children: label }),
967
+ /* @__PURE__ */ jsx16(
797
968
  FormLayout,
798
969
  {
799
970
  columns: columnsProp || columns,
@@ -804,10 +975,13 @@ var ObjectField = (props) => {
804
975
  ] });
805
976
  };
806
977
  ObjectField.displayName = "ObjectField";
978
+
979
+ // src/fields.tsx
980
+ import { jsx as jsx17 } from "react/jsx-runtime";
807
981
  var mapNestedFields2 = (resolver, name) => {
808
982
  var _a;
809
983
  return (_a = resolver.getNestedFields(name)) == null ? void 0 : _a.map(
810
- ({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */ jsx(
984
+ ({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */ jsx17(
811
985
  Field,
812
986
  {
813
987
  name: name2,
@@ -827,10 +1001,10 @@ var AutoFields = ({
827
1001
  const context = useFormContext();
828
1002
  const schema = schemaProp || context.schema;
829
1003
  const fieldResolver = fieldResolverProp || context.fieldResolver;
830
- const resolver = React11.useMemo(() => fieldResolver, [schema, fieldResolver]);
831
- const fields = React11.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
1004
+ const resolver = React10.useMemo(() => fieldResolver, [schema, fieldResolver]);
1005
+ const fields = React10.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
832
1006
  const form = useFormContext();
833
- React11.useEffect(() => {
1007
+ React10.useEffect(() => {
834
1008
  var _a;
835
1009
  if (focusFirstField && ((_a = fields == null ? void 0 : fields[0]) == null ? void 0 : _a.name)) {
836
1010
  form.setFocus(fields[0].name);
@@ -839,7 +1013,7 @@ var AutoFields = ({
839
1013
  if (!resolver) {
840
1014
  return null;
841
1015
  }
842
- return /* @__PURE__ */ jsx(FormLayout, { ...props, children: fields == null ? void 0 : fields.map(
1016
+ return /* @__PURE__ */ jsx17(FormLayout, { ...props, children: fields == null ? void 0 : fields.map(
843
1017
  ({
844
1018
  name,
845
1019
  type,
@@ -847,16 +1021,21 @@ var AutoFields = ({
847
1021
  ...fieldProps
848
1022
  }) => {
849
1023
  if (type === "array") {
850
- return /* @__PURE__ */ jsx(ArrayField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
1024
+ return /* @__PURE__ */ jsx17(ArrayField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
851
1025
  } else if (type === "object") {
852
- return /* @__PURE__ */ jsx(ObjectField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
1026
+ return /* @__PURE__ */ jsx17(ObjectField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
853
1027
  }
854
- return /* @__PURE__ */ jsx(Field, { name, type, ...fieldProps }, name);
1028
+ return /* @__PURE__ */ jsx17(Field, { name, type, ...fieldProps }, name);
855
1029
  }
856
1030
  ) });
857
1031
  };
858
1032
  AutoFields.displayName = "Fields";
859
- var SubmitButton = forwardRef(
1033
+
1034
+ // src/submit-button.tsx
1035
+ import { useFormContext as useFormContext2 } from "react-hook-form";
1036
+ import { Button as Button4, forwardRef as forwardRef12 } from "@chakra-ui/react";
1037
+ import { jsx as jsx18 } from "react/jsx-runtime";
1038
+ var SubmitButton = forwardRef12(
860
1039
  (props, ref) => {
861
1040
  const {
862
1041
  children = "Submit",
@@ -866,10 +1045,10 @@ var SubmitButton = forwardRef(
866
1045
  isLoading,
867
1046
  ...rest
868
1047
  } = props;
869
- const { formState } = useFormContext$1();
1048
+ const { formState } = useFormContext2();
870
1049
  const isDisabled = disableIfUntouched && !formState.isDirty || disableIfInvalid && !formState.isValid || isDisabledProp;
871
- return /* @__PURE__ */ jsx(
872
- Button,
1050
+ return /* @__PURE__ */ jsx18(
1051
+ Button4,
873
1052
  {
874
1053
  ...rest,
875
1054
  ref,
@@ -887,6 +1066,11 @@ SubmitButton.defaultProps = {
887
1066
  disableIfInvalid: false
888
1067
  };
889
1068
  SubmitButton.displayName = "SubmitButton";
1069
+
1070
+ // src/display-if.tsx
1071
+ import {
1072
+ useWatch
1073
+ } from "react-hook-form";
890
1074
  var DisplayIf = ({
891
1075
  children,
892
1076
  name,
@@ -905,7 +1089,28 @@ var DisplayIf = ({
905
1089
  return condition(value, context) ? children : null;
906
1090
  };
907
1091
  DisplayIf.displayName = "DisplayIf";
908
- var [StepFormProvider, useStepFormContext] = createContext({
1092
+
1093
+ // src/step-form.tsx
1094
+ import * as React12 from "react";
1095
+ import {
1096
+ chakra as chakra4,
1097
+ Button as Button5
1098
+ } from "@chakra-ui/react";
1099
+ import { callAllHandlers as callAllHandlers2, cx as cx3 } from "@chakra-ui/utils";
1100
+ import {
1101
+ Steps,
1102
+ StepsItem,
1103
+ useStepperContext
1104
+ } from "@saas-ui/core";
1105
+
1106
+ // src/use-step-form.tsx
1107
+ import * as React11 from "react";
1108
+ import { createContext as createContext4 } from "@chakra-ui/react-utils";
1109
+ import {
1110
+ useStepper,
1111
+ useStep
1112
+ } from "@saas-ui/core";
1113
+ var [StepFormProvider, useStepFormContext] = createContext4({
909
1114
  name: "StepFormContext",
910
1115
  errorMessage: "useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"
911
1116
  });
@@ -981,6 +1186,9 @@ function useFormStep(props) {
981
1186
  ...steps[name] || { name, schema }
982
1187
  };
983
1188
  }
1189
+
1190
+ // src/step-form.tsx
1191
+ import { jsx as jsx19 } from "react/jsx-runtime";
984
1192
  var FormStepper = (props) => {
985
1193
  const { activeIndex, setIndex } = useStepperContext();
986
1194
  const {
@@ -993,10 +1201,10 @@ var FormStepper = (props) => {
993
1201
  render,
994
1202
  ...rest
995
1203
  } = props;
996
- const elements = React11.Children.map(children, (child) => {
997
- if (React11.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
1204
+ const elements = React12.Children.map(children, (child) => {
1205
+ if (React12.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
998
1206
  const { isCompleted } = useFormStep(child.props);
999
- return /* @__PURE__ */ jsx(
1207
+ return /* @__PURE__ */ jsx19(
1000
1208
  StepsItem,
1001
1209
  {
1002
1210
  render,
@@ -1010,11 +1218,11 @@ var FormStepper = (props) => {
1010
1218
  }
1011
1219
  return child;
1012
1220
  });
1013
- const onChange = React11.useCallback((i) => {
1221
+ const onChange = React12.useCallback((i) => {
1014
1222
  setIndex(i);
1015
1223
  onChangeProp == null ? void 0 : onChangeProp(i);
1016
1224
  }, []);
1017
- return /* @__PURE__ */ jsx(
1225
+ return /* @__PURE__ */ jsx19(
1018
1226
  Steps,
1019
1227
  {
1020
1228
  orientation,
@@ -1031,19 +1239,19 @@ var FormStep = (props) => {
1031
1239
  const { name, children, className, onSubmit, ...rest } = props;
1032
1240
  const step = useFormStep({ name, onSubmit });
1033
1241
  const { isActive } = step;
1034
- return isActive ? /* @__PURE__ */ jsx(chakra.div, { ...rest, className: cx("sui-form__step", className), children }) : null;
1242
+ return isActive ? /* @__PURE__ */ jsx19(chakra4.div, { ...rest, className: cx3("sui-form__step", className), children }) : null;
1035
1243
  };
1036
1244
  FormStep.displayName = "FormStep";
1037
1245
  var PrevButton = (props) => {
1038
1246
  const { isFirstStep, isCompleted, prevStep } = useStepperContext();
1039
- return /* @__PURE__ */ jsx(
1040
- Button,
1247
+ return /* @__PURE__ */ jsx19(
1248
+ Button5,
1041
1249
  {
1042
1250
  isDisabled: isFirstStep || isCompleted,
1043
1251
  children: "Back",
1044
1252
  ...props,
1045
- className: cx("sui-form__prev-button", props.className),
1046
- onClick: callAllHandlers(props.onClick, prevStep)
1253
+ className: cx3("sui-form__prev-button", props.className),
1254
+ onClick: callAllHandlers2(props.onClick, prevStep)
1047
1255
  }
1048
1256
  );
1049
1257
  };
@@ -1051,17 +1259,20 @@ PrevButton.displayName = "PrevButton";
1051
1259
  var NextButton = (props) => {
1052
1260
  const { label = "Next", submitLabel = "Complete", ...rest } = props;
1053
1261
  const { isLastStep, isCompleted } = useStepperContext();
1054
- return /* @__PURE__ */ jsx(
1262
+ return /* @__PURE__ */ jsx19(
1055
1263
  SubmitButton,
1056
1264
  {
1057
1265
  ...rest,
1058
1266
  isDisabled: isCompleted,
1059
- className: cx("sui-form__next-button", props.className),
1267
+ className: cx3("sui-form__next-button", props.className),
1060
1268
  children: isLastStep || isCompleted ? submitLabel : label
1061
1269
  }
1062
1270
  );
1063
1271
  };
1064
1272
  NextButton.displayName = "NextButton";
1273
+
1274
+ // src/field-resolver.ts
1275
+ import { get as get2 } from "@chakra-ui/utils";
1065
1276
  var mapFields = (schema) => schema && Object.entries(schema).map(([name, { items, label, title, ...field }]) => {
1066
1277
  return {
1067
1278
  ...field,
@@ -1076,7 +1287,7 @@ var objectFieldResolver = (schema) => {
1076
1287
  };
1077
1288
  const getNestedFields = (name) => {
1078
1289
  var _a;
1079
- const field = get$1(schema, name);
1290
+ const field = get2(schema, name);
1080
1291
  if (!field)
1081
1292
  return [];
1082
1293
  if (((_a = field.items) == null ? void 0 : _a.type) === "object") {
@@ -1088,10 +1299,13 @@ var objectFieldResolver = (schema) => {
1088
1299
  };
1089
1300
  return { getFields, getNestedFields };
1090
1301
  };
1302
+
1303
+ // src/watch-field.tsx
1304
+ import { useWatch as useWatch2 } from "react-hook-form";
1091
1305
  var WatchField = (props) => {
1092
1306
  const { name, defaultValue, isDisabled, isExact } = props;
1093
1307
  const form = useFormContext();
1094
- const field = useWatch({
1308
+ const field = useWatch2({
1095
1309
  name,
1096
1310
  defaultValue,
1097
1311
  disabled: isDisabled,
@@ -1099,7 +1313,16 @@ var WatchField = (props) => {
1099
1313
  });
1100
1314
  return props.children(field, form) || null;
1101
1315
  };
1102
- var Form = forwardRef(
1316
+
1317
+ // src/form.tsx
1318
+ import * as React13 from "react";
1319
+ import { chakra as chakra5, forwardRef as forwardRef13 } from "@chakra-ui/react";
1320
+ import { cx as cx4, runIfFn } from "@chakra-ui/utils";
1321
+ import {
1322
+ useForm
1323
+ } from "react-hook-form";
1324
+ import { jsx as jsx20, jsxs as jsxs9 } from "react/jsx-runtime";
1325
+ var Form = forwardRef13(
1103
1326
  (props, ref) => {
1104
1327
  const {
1105
1328
  mode = "all",
@@ -1140,8 +1363,8 @@ var Form = forwardRef(
1140
1363
  };
1141
1364
  const methods = useForm(form);
1142
1365
  const { handleSubmit } = methods;
1143
- React11.useImperativeHandle(formRef, () => methods, [formRef, methods]);
1144
- React11.useEffect(() => {
1366
+ React13.useImperativeHandle(formRef, () => methods, [formRef, methods]);
1367
+ React13.useEffect(() => {
1145
1368
  let subscription;
1146
1369
  if (onChange) {
1147
1370
  subscription = methods.watch(onChange);
@@ -1150,25 +1373,25 @@ var Form = forwardRef(
1150
1373
  }, [methods, onChange]);
1151
1374
  let _children = children;
1152
1375
  if (!_children && fieldResolver) {
1153
- _children = /* @__PURE__ */ jsxs(FormLayout, { children: [
1154
- /* @__PURE__ */ jsx(AutoFields, {}),
1155
- /* @__PURE__ */ jsx(SubmitButton, { ...fields == null ? void 0 : fields.submit })
1376
+ _children = /* @__PURE__ */ jsxs9(FormLayout, { children: [
1377
+ /* @__PURE__ */ jsx20(AutoFields, {}),
1378
+ /* @__PURE__ */ jsx20(SubmitButton, { ...fields == null ? void 0 : fields.submit })
1156
1379
  ] });
1157
1380
  }
1158
- return /* @__PURE__ */ jsx(
1381
+ return /* @__PURE__ */ jsx20(
1159
1382
  FormProvider,
1160
1383
  {
1161
1384
  ...methods,
1162
1385
  schema,
1163
1386
  fieldResolver,
1164
1387
  fields,
1165
- children: /* @__PURE__ */ jsx(
1166
- chakra.form,
1388
+ children: /* @__PURE__ */ jsx20(
1389
+ chakra5.form,
1167
1390
  {
1168
1391
  ref,
1169
1392
  onSubmit: handleSubmit(onSubmit, onError),
1170
1393
  ...rest,
1171
- className: cx("sui-form", props.className),
1394
+ className: cx4("sui-form", props.className),
1172
1395
  children: runIfFn(_children, {
1173
1396
  Field,
1174
1397
  DisplayIf,
@@ -1183,15 +1406,19 @@ var Form = forwardRef(
1183
1406
  }
1184
1407
  );
1185
1408
  Form.displayName = "Form";
1409
+
1410
+ // src/create-form.tsx
1411
+ import { forwardRef as forwardRef14 } from "@chakra-ui/react";
1412
+ import { jsx as jsx21 } from "react/jsx-runtime";
1186
1413
  function createForm({
1187
1414
  resolver,
1188
1415
  fieldResolver = objectFieldResolver,
1189
1416
  fields
1190
1417
  } = {}) {
1191
- const DefaultForm = forwardRef(
1418
+ const DefaultForm = forwardRef14(
1192
1419
  (props, ref) => {
1193
1420
  const { schema, ...rest } = props;
1194
- return /* @__PURE__ */ jsx(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsx(
1421
+ return /* @__PURE__ */ jsx21(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsx21(
1195
1422
  Form,
1196
1423
  {
1197
1424
  ref,
@@ -1206,8 +1433,15 @@ function createForm({
1206
1433
  DefaultForm.id = "Form";
1207
1434
  return DefaultForm;
1208
1435
  }
1436
+
1437
+ // src/create-step-form.tsx
1438
+ import { useMemo as useMemo2 } from "react";
1439
+ import { forwardRef as forwardRef15 } from "@chakra-ui/react";
1440
+ import { StepperProvider } from "@saas-ui/core";
1441
+ import { runIfFn as runIfFn2 } from "@chakra-ui/utils";
1442
+ import { jsx as jsx22 } from "react/jsx-runtime";
1209
1443
  function createStepForm({ fields, resolver, fieldResolver } = {}) {
1210
- const StepForm2 = forwardRef((props, ref) => {
1444
+ const StepForm2 = forwardRef15((props, ref) => {
1211
1445
  const { children, steps, ...rest } = props;
1212
1446
  const stepper = useStepForm({
1213
1447
  resolver,
@@ -1215,8 +1449,8 @@ function createStepForm({ fields, resolver, fieldResolver } = {}) {
1215
1449
  ...props
1216
1450
  });
1217
1451
  const { getFormProps, ...ctx } = stepper;
1218
- const context = useMemo(() => ctx, [ctx]);
1219
- return /* @__PURE__ */ jsx(StepperProvider, { value: context, children: /* @__PURE__ */ jsx(StepFormProvider, { value: context, children: /* @__PURE__ */ jsx(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsx(Form, { ref, ...rest, ...getFormProps(), children: runIfFn(children, {
1452
+ const context = useMemo2(() => ctx, [ctx]);
1453
+ return /* @__PURE__ */ jsx22(StepperProvider, { value: context, children: /* @__PURE__ */ jsx22(StepFormProvider, { value: context, children: /* @__PURE__ */ jsx22(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsx22(Form, { ref, ...rest, ...getFormProps(), children: runIfFn2(children, {
1220
1454
  ...stepper,
1221
1455
  Field,
1222
1456
  FormStep,
@@ -1228,9 +1462,91 @@ function createStepForm({ fields, resolver, fieldResolver } = {}) {
1228
1462
  StepForm2.displayName = `Step${Form.displayName || Form.name}`;
1229
1463
  return StepForm2;
1230
1464
  }
1465
+
1466
+ // src/index.ts
1467
+ import {
1468
+ appendErrors,
1469
+ useController,
1470
+ useFieldArray as useFieldArray2,
1471
+ useForm as useForm2,
1472
+ useFormState,
1473
+ useWatch as useWatch3,
1474
+ Controller as Controller2
1475
+ } from "react-hook-form";
1231
1476
  var Form2 = createForm();
1232
1477
  var StepForm = createStepForm();
1233
-
1234
- 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 };
1235
- //# sourceMappingURL=out.js.map
1478
+ export {
1479
+ ArrayField,
1480
+ ArrayFieldAddButton,
1481
+ ArrayFieldContainer,
1482
+ ArrayFieldProvider,
1483
+ ArrayFieldRemoveButton,
1484
+ ArrayFieldRow,
1485
+ ArrayFieldRowContainer,
1486
+ ArrayFieldRowFields,
1487
+ ArrayFieldRowProvider,
1488
+ ArrayFieldRows,
1489
+ AutoFields,
1490
+ BaseField,
1491
+ Form as BaseForm,
1492
+ CheckboxField,
1493
+ Controller2 as Controller,
1494
+ DisplayField,
1495
+ DisplayIf,
1496
+ Field,
1497
+ FieldsProvider,
1498
+ Form2 as Form,
1499
+ FormLayout,
1500
+ FormLegend,
1501
+ FormProvider,
1502
+ FormStep,
1503
+ FormStepper,
1504
+ FormValue,
1505
+ InputField,
1506
+ InputRightButton,
1507
+ NativeSelect,
1508
+ NativeSelectField,
1509
+ NextButton,
1510
+ NumberInputField2 as NumberInputField,
1511
+ ObjectField,
1512
+ PasswordInput,
1513
+ PasswordInputField,
1514
+ PinField,
1515
+ PrevButton,
1516
+ RadioField,
1517
+ RadioInput,
1518
+ Select,
1519
+ SelectButton,
1520
+ SelectField,
1521
+ SelectList,
1522
+ SelectOption,
1523
+ StepForm,
1524
+ StepFormProvider,
1525
+ SubmitButton,
1526
+ SwitchField,
1527
+ TextareaField,
1528
+ WatchField,
1529
+ appendErrors,
1530
+ createField,
1531
+ createForm,
1532
+ createStepForm,
1533
+ defaultFieldTypes,
1534
+ objectFieldResolver,
1535
+ useArrayField,
1536
+ useArrayFieldAddButton,
1537
+ useArrayFieldContext,
1538
+ useArrayFieldRemoveButton,
1539
+ useArrayFieldRow,
1540
+ useArrayFieldRowContext,
1541
+ useController,
1542
+ useField,
1543
+ useFieldArray2 as useFieldArray,
1544
+ useForm2 as useForm,
1545
+ useFormContext,
1546
+ useFormState,
1547
+ useFormStep,
1548
+ useStepForm,
1549
+ useStepFormContext,
1550
+ useWatch3 as useWatch
1551
+ };
1236
1552
  //# sourceMappingURL=index.mjs.map