@saas-ui/forms 2.0.5 → 2.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/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;
@@ -276,14 +371,15 @@ var SelectButton = forwardRef(
276
371
  _invalid: invalid,
277
372
  minW: 0,
278
373
  ...styles.field,
279
- h: "auto"
374
+ h: "auto",
375
+ ...props.sx
280
376
  };
281
377
  const buttonProps = useMenuButton(rest, ref);
282
- return /* @__PURE__ */ jsx(
283
- Button,
378
+ return /* @__PURE__ */ jsx7(
379
+ Button2,
284
380
  {
285
381
  ...buttonProps,
286
- ...buttonStyles,
382
+ sx: buttonStyles,
287
383
  id: id || buttonProps.id,
288
384
  ...rest,
289
385
  onFocus,
@@ -294,7 +390,7 @@ var SelectButton = forwardRef(
294
390
  "data-focus": dataAttr(isFocused),
295
391
  "data-required": dataAttr(isRequired),
296
392
  rightIcon,
297
- children: /* @__PURE__ */ jsx(
393
+ children: /* @__PURE__ */ jsx7(
298
394
  chakra.span,
299
395
  {
300
396
  __css: {
@@ -313,15 +409,15 @@ var SelectButton = forwardRef(
313
409
  }
314
410
  );
315
411
  SelectButton.displayName = "SelectButton";
316
- var Select = forwardRef((props, ref) => {
412
+ var Select = forwardRef5((props, ref) => {
317
413
  const { name, children, isDisabled, multiple, ...rest } = props;
318
414
  const styles = useMultiStyleConfig("SuiSelect", props);
319
415
  const menuProps = omitThemingProps(rest);
320
416
  const context = useSelect(props);
321
417
  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: [
418
+ 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
419
  children,
324
- /* @__PURE__ */ jsx(
420
+ /* @__PURE__ */ jsx7(
325
421
  chakra.input,
326
422
  {
327
423
  ...controlProps,
@@ -336,33 +432,56 @@ var Select = forwardRef((props, ref) => {
336
432
  });
337
433
  var SelectList = (props) => {
338
434
  const { defaultValue, value, options, multiple, onChange } = useSelectContext();
339
- return /* @__PURE__ */ jsx(MenuList, { maxH: "100vh", overflowY: "auto", ...props, children: /* @__PURE__ */ jsx(
435
+ return /* @__PURE__ */ jsx7(MenuList, { maxH: "100vh", overflowY: "auto", ...props, children: /* @__PURE__ */ jsx7(
340
436
  MenuOptionGroup,
341
437
  {
342
438
  defaultValue: defaultValue || value,
343
439
  value,
344
440
  onChange,
345
441
  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
442
+ children: options ? options.map(({ value: value2, label, ...rest }, i) => /* @__PURE__ */ jsx7(SelectOption, { value: value2, ...rest, children: label || value2 }, i)) : props.children
347
443
  }
348
444
  ) });
349
445
  };
350
446
  Select.displayName = "Select";
351
- var SelectOption = forwardRef(
447
+ var SelectOption = forwardRef5(
352
448
  (props, ref) => {
353
- return /* @__PURE__ */ jsx(MenuItemOption, { ref, ...props });
449
+ return /* @__PURE__ */ jsx7(MenuItemOption, { ref, ...props });
354
450
  }
355
451
  );
356
452
  SelectOption.id = "MenuItemOption";
357
453
  SelectOption.displayName = "SelectOption";
358
- var NativeSelect = forwardRef(
454
+
455
+ // src/select/native-select.tsx
456
+ import {
457
+ forwardRef as forwardRef6,
458
+ Select as ChakraSelect
459
+ } from "@chakra-ui/react";
460
+ import { jsx as jsx8 } from "react/jsx-runtime";
461
+ var NativeSelect = forwardRef6(
359
462
  ({ 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);
463
+ return /* @__PURE__ */ jsx8(ChakraSelect, { ref, ...props, children: children || (options == null ? void 0 : options.map(({ value, label }) => {
464
+ return /* @__PURE__ */ jsx8("option", { value, children: label || value }, value);
362
465
  })) });
363
466
  }
364
467
  );
365
468
  NativeSelect.displayName = "NativeSelect";
469
+
470
+ // src/create-field.tsx
471
+ import { Controller } from "react-hook-form";
472
+ import { forwardRef as forwardRef7, useMergeRefs } from "@chakra-ui/react";
473
+ import { callAllHandlers } from "@chakra-ui/utils";
474
+
475
+ // src/base-field.tsx
476
+ import { get } from "react-hook-form";
477
+ import {
478
+ Box,
479
+ FormControl as FormControl2,
480
+ FormLabel as FormLabel2,
481
+ FormHelperText,
482
+ FormErrorMessage
483
+ } from "@chakra-ui/react";
484
+ import { jsx as jsx9, jsxs as jsxs5 } from "react/jsx-runtime";
366
485
  var getError = (name, formState) => {
367
486
  return get(formState.errors, name);
368
487
  };
@@ -370,18 +489,21 @@ var BaseField = (props) => {
370
489
  const { name, label, help, hideLabel, children, ...controlProps } = props;
371
490
  const { formState } = useFormContext();
372
491
  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: [
492
+ return /* @__PURE__ */ jsxs5(FormControl2, { ...controlProps, isInvalid: !!error, children: [
493
+ label && !hideLabel ? /* @__PURE__ */ jsx9(FormLabel2, { children: label }) : null,
494
+ /* @__PURE__ */ jsxs5(Box, { children: [
376
495
  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 })
496
+ help && !(error == null ? void 0 : error.message) ? /* @__PURE__ */ jsx9(FormHelperText, { children: help }) : null,
497
+ (error == null ? void 0 : error.message) && /* @__PURE__ */ jsx9(FormErrorMessage, { children: error == null ? void 0 : error.message })
379
498
  ] })
380
499
  ] });
381
500
  };
382
501
  BaseField.displayName = "BaseField";
502
+
503
+ // src/create-field.tsx
504
+ import { jsx as jsx10 } from "react/jsx-runtime";
383
505
  var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseField2 }) => {
384
- const Field2 = forwardRef((props, ref) => {
506
+ const Field2 = forwardRef7((props, ref) => {
385
507
  const {
386
508
  id,
387
509
  name,
@@ -398,7 +520,7 @@ var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFie
398
520
  required: isRequired,
399
521
  ...rules
400
522
  };
401
- return /* @__PURE__ */ jsx(
523
+ return /* @__PURE__ */ jsx10(
402
524
  BaseField2,
403
525
  {
404
526
  id,
@@ -410,7 +532,7 @@ var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFie
410
532
  isInvalid,
411
533
  isReadOnly,
412
534
  isRequired,
413
- children: /* @__PURE__ */ jsx(
535
+ children: /* @__PURE__ */ jsx10(
414
536
  InputComponent,
415
537
  {
416
538
  ref,
@@ -428,16 +550,16 @@ var _createField = (InputComponent, { displayName, hideLabel, BaseField: BaseFie
428
550
  return Field2;
429
551
  };
430
552
  var withControlledInput = (InputComponent) => {
431
- return forwardRef(
553
+ return forwardRef7(
432
554
  ({ name, rules, ...inputProps }, ref) => {
433
555
  const { control } = useFormContext();
434
- return /* @__PURE__ */ jsx(
556
+ return /* @__PURE__ */ jsx10(
435
557
  Controller,
436
558
  {
437
559
  name,
438
560
  control,
439
561
  rules,
440
- render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */ jsx(
562
+ render: ({ field: { ref: _ref, ...field } }) => /* @__PURE__ */ jsx10(
441
563
  InputComponent,
442
564
  {
443
565
  ...field,
@@ -453,11 +575,11 @@ var withControlledInput = (InputComponent) => {
453
575
  );
454
576
  };
455
577
  var withUncontrolledInput = (InputComponent) => {
456
- return forwardRef(
578
+ return forwardRef7(
457
579
  ({ name, rules, ...inputProps }, ref) => {
458
580
  const { register } = useFormContext();
459
581
  const { ref: _ref, ...field } = register(name, rules);
460
- return /* @__PURE__ */ jsx(
582
+ return /* @__PURE__ */ jsx10(
461
583
  InputComponent,
462
584
  {
463
585
  ...field,
@@ -485,11 +607,14 @@ var createField = (component, options) => {
485
607
  });
486
608
  return Field2;
487
609
  };
610
+
611
+ // src/default-fields.tsx
612
+ import { jsx as jsx11, jsxs as jsxs6 } from "react/jsx-runtime";
488
613
  var InputField = createField(
489
- forwardRef(({ type = "text", leftAddon, rightAddon, size, ...rest }, ref) => {
490
- const input = /* @__PURE__ */ jsx(Input, { type, size, ...rest, ref });
614
+ forwardRef8(({ type = "text", leftAddon, rightAddon, size, ...rest }, ref) => {
615
+ const input = /* @__PURE__ */ jsx11(Input2, { type, size, ...rest, ref });
491
616
  if (leftAddon || rightAddon) {
492
- return /* @__PURE__ */ jsxs(InputGroup, { size, children: [
617
+ return /* @__PURE__ */ jsxs6(InputGroup2, { size, children: [
493
618
  leftAddon,
494
619
  input,
495
620
  rightAddon
@@ -505,22 +630,22 @@ var NumberInputField2 = createField(
505
630
  }
506
631
  );
507
632
  var PasswordInputField = createField(
508
- forwardRef((props, ref) => /* @__PURE__ */ jsx(PasswordInput, { ref, ...props }))
633
+ forwardRef8((props, ref) => /* @__PURE__ */ jsx11(PasswordInput, { ref, ...props }))
509
634
  );
510
635
  var TextareaField = createField(Textarea);
511
636
  var SwitchField = createField(
512
- forwardRef(({ type, value, ...rest }, ref) => {
513
- return /* @__PURE__ */ jsx(Switch, { isChecked: !!value, ...rest, ref });
637
+ forwardRef8(({ type, value, ...rest }, ref) => {
638
+ return /* @__PURE__ */ jsx11(Switch, { isChecked: !!value, ...rest, ref });
514
639
  }),
515
640
  {
516
641
  isControlled: true
517
642
  }
518
643
  );
519
644
  var SelectField = createField(
520
- forwardRef((props, ref) => {
521
- return /* @__PURE__ */ jsxs(Select, { ref, ...props, children: [
522
- /* @__PURE__ */ jsx(SelectButton, {}),
523
- /* @__PURE__ */ jsx(SelectList, {})
645
+ forwardRef8((props, ref) => {
646
+ return /* @__PURE__ */ jsxs6(Select, { ref, ...props, children: [
647
+ /* @__PURE__ */ jsx11(SelectButton, {}),
648
+ /* @__PURE__ */ jsx11(SelectList, {})
524
649
  ] });
525
650
  }),
526
651
  {
@@ -528,8 +653,8 @@ var SelectField = createField(
528
653
  }
529
654
  );
530
655
  var CheckboxField = createField(
531
- forwardRef(({ label, type, ...props }, ref) => {
532
- return /* @__PURE__ */ jsx(Checkbox, { ref, ...props, children: label });
656
+ forwardRef8(({ label, type, ...props }, ref) => {
657
+ return /* @__PURE__ */ jsx11(Checkbox, { ref, ...props, children: label });
533
658
  }),
534
659
  {
535
660
  hideLabel: true
@@ -542,13 +667,13 @@ var NativeSelectField = createField(NativeSelect, {
542
667
  isControlled: true
543
668
  });
544
669
  var PinField = createField(
545
- forwardRef((props, ref) => {
670
+ forwardRef8((props, ref) => {
546
671
  const { pinLength = 4, pinType, spacing, ...inputProps } = props;
547
672
  const inputs = [];
548
673
  for (let i = 0; i < pinLength; i++) {
549
- inputs.push(/* @__PURE__ */ jsx(PinInputField, { ref }, i));
674
+ inputs.push(/* @__PURE__ */ jsx11(PinInputField, { ref }, i));
550
675
  }
551
- return /* @__PURE__ */ jsx(HStack, { spacing, children: /* @__PURE__ */ jsx(PinInput, { ...inputProps, type: pinType, children: inputs }) });
676
+ return /* @__PURE__ */ jsx11(HStack, { spacing, children: /* @__PURE__ */ jsx11(PinInput, { ...inputProps, type: pinType, children: inputs }) });
552
677
  }),
553
678
  {
554
679
  isControlled: true
@@ -569,28 +694,47 @@ var defaultFieldTypes = {
569
694
  pin: PinField,
570
695
  "native-select": NativeSelectField
571
696
  };
572
- var FieldsContext = React11__default.createContext(
697
+
698
+ // src/fields-context.tsx
699
+ import { jsx as jsx12 } from "react/jsx-runtime";
700
+ var FieldsContext = React5.createContext(
573
701
  null
574
702
  );
575
703
  var FieldsProvider = (props) => {
576
704
  const fields = { ...defaultFieldTypes, ...props.value };
577
- return /* @__PURE__ */ jsx(FieldsContext.Provider, { value: fields, children: props.children });
705
+ return /* @__PURE__ */ jsx12(FieldsContext.Provider, { value: fields, children: props.children });
578
706
  };
579
707
  var useField = (type) => {
580
- const context = React11__default.useContext(FieldsContext);
708
+ const context = React5.useContext(FieldsContext);
581
709
  return (context == null ? void 0 : context[type]) || InputField;
582
710
  };
711
+
712
+ // src/field.tsx
713
+ import { jsx as jsx13 } from "react/jsx-runtime";
583
714
  var defaultInputType = "text";
584
- var Field = React11.forwardRef(
715
+ var Field = React6.forwardRef(
585
716
  (props, ref) => {
586
717
  const { type = defaultInputType, name } = props;
587
718
  const overrides = useFieldProps(name);
588
719
  const InputComponent = useField((overrides == null ? void 0 : overrides.type) || type);
589
- return /* @__PURE__ */ jsx(InputComponent, { ref, ...props, ...overrides });
720
+ return /* @__PURE__ */ jsx13(InputComponent, { ref, ...props, ...overrides });
590
721
  }
591
722
  );
723
+
724
+ // src/fields.tsx
725
+ import * as React10 from "react";
726
+
727
+ // src/layout.tsx
728
+ import * as React7 from "react";
729
+ import {
730
+ chakra as chakra2,
731
+ SimpleGrid,
732
+ useTheme
733
+ } from "@chakra-ui/react";
734
+ import { cx as cx2 } from "@chakra-ui/utils";
735
+ import { jsx as jsx14 } from "react/jsx-runtime";
592
736
  var FormLayoutItem = ({ children }) => {
593
- return /* @__PURE__ */ jsx(chakra.div, { children });
737
+ return /* @__PURE__ */ jsx14(chakra2.div, { children });
594
738
  };
595
739
  FormLayoutItem.displayName = "FormLayoutItem";
596
740
  var FormLayout = ({ children, ...props }) => {
@@ -603,14 +747,14 @@ var FormLayout = ({ children, ...props }) => {
603
747
  ...defaultProps,
604
748
  ...props
605
749
  };
606
- return /* @__PURE__ */ jsx(
750
+ return /* @__PURE__ */ jsx14(
607
751
  SimpleGrid,
608
752
  {
609
753
  ...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 });
754
+ className: cx2("sui-form__layout", props.className),
755
+ children: React7.Children.map(children, (child) => {
756
+ if (React7.isValidElement(child)) {
757
+ return /* @__PURE__ */ jsx14(FormLayoutItem, { children: child });
614
758
  }
615
759
  return child;
616
760
  })
@@ -618,10 +762,26 @@ var FormLayout = ({ children, ...props }) => {
618
762
  );
619
763
  };
620
764
  FormLayout.displayName = "FormLayout";
621
- var [ArrayFieldProvider, useArrayFieldContext] = createContext({
765
+
766
+ // src/array-field.tsx
767
+ import * as React9 from "react";
768
+ import {
769
+ chakra as chakra3,
770
+ forwardRef as forwardRef11,
771
+ Button as Button3
772
+ } from "@chakra-ui/react";
773
+ import { PlusIcon, MinusIcon } from "@saas-ui/core/icons";
774
+
775
+ // src/use-array-field.tsx
776
+ import * as React8 from "react";
777
+ import {
778
+ useFieldArray
779
+ } from "react-hook-form";
780
+ import { createContext as createContext3 } from "@chakra-ui/react-utils";
781
+ var [ArrayFieldProvider, useArrayFieldContext] = createContext3({
622
782
  name: "ArrayFieldContext"
623
783
  });
624
- var [ArrayFieldRowProvider, useArrayFieldRowContext] = createContext({
784
+ var [ArrayFieldRowProvider, useArrayFieldRowContext] = createContext3({
625
785
  name: "ArrayFieldRowContext"
626
786
  });
627
787
  var useArrayField = ({
@@ -648,7 +808,7 @@ var useArrayField = ({
648
808
  var useArrayFieldRow = ({ index }) => {
649
809
  const { clearErrors } = useFormContext();
650
810
  const { name, remove, fields } = useArrayFieldContext();
651
- React11.useEffect(() => {
811
+ React8.useEffect(() => {
652
812
  clearErrors(name);
653
813
  }, []);
654
814
  return {
@@ -656,7 +816,7 @@ var useArrayFieldRow = ({ index }) => {
656
816
  isFirst: index === 0,
657
817
  isLast: index === fields.length - 1,
658
818
  name: `${name}.${index}`,
659
- remove: React11.useCallback(() => {
819
+ remove: React8.useCallback(() => {
660
820
  clearErrors(name);
661
821
  remove(index);
662
822
  }, [index])
@@ -681,14 +841,18 @@ var useArrayFieldAddButton = () => {
681
841
  isDisabled
682
842
  };
683
843
  };
844
+
845
+ // src/array-field.tsx
846
+ import { isFunction } from "@chakra-ui/utils";
847
+ import { Fragment, jsx as jsx15, jsxs as jsxs7 } from "react/jsx-runtime";
684
848
  var ArrayFieldRow = ({
685
849
  children,
686
850
  index,
687
851
  ...rowFieldsProps
688
852
  }) => {
689
- return /* @__PURE__ */ jsxs(ArrayFieldRowContainer, { index, children: [
690
- /* @__PURE__ */ jsx(ArrayFieldRowFields, { ...rowFieldsProps, children }),
691
- /* @__PURE__ */ jsx(ArrayFieldRemoveButton, {})
853
+ return /* @__PURE__ */ jsxs7(ArrayFieldRowContainer, { index, children: [
854
+ /* @__PURE__ */ jsx15(ArrayFieldRowFields, { ...rowFieldsProps, children }),
855
+ /* @__PURE__ */ jsx15(ArrayFieldRemoveButton, {})
692
856
  ] });
693
857
  };
694
858
  ArrayFieldRow.displayName = "ArrayFieldRow";
@@ -697,7 +861,7 @@ var ArrayFieldRowFields = ({
697
861
  ...layoutProps
698
862
  }) => {
699
863
  const { name } = useArrayFieldRowContext();
700
- return /* @__PURE__ */ jsx(FormLayout, { flex: "1", mr: "2", ...layoutProps, children: mapNestedFields(name, children) });
864
+ return /* @__PURE__ */ jsx15(FormLayout, { flex: "1", mr: "2", ...layoutProps, children: mapNestedFields(name, children) });
701
865
  };
702
866
  ArrayFieldRowFields.displayName = "ArrayFieldRowFields";
703
867
  var ArrayFieldRowContainer = ({
@@ -713,33 +877,33 @@ var ArrayFieldRowContainer = ({
713
877
  width: "100%",
714
878
  mb: 4
715
879
  };
716
- return /* @__PURE__ */ jsx(ArrayFieldRowProvider, { value: context, children: /* @__PURE__ */ jsx(chakra.div, { ...rest, __css: styles, children }) });
880
+ return /* @__PURE__ */ jsx15(ArrayFieldRowProvider, { value: context, children: /* @__PURE__ */ jsx15(chakra3.div, { ...rest, __css: styles, children }) });
717
881
  };
718
882
  ArrayFieldRowContainer.displayName = "ArrayFieldRowContainer";
719
883
  var ArrayFieldRemoveButton = (props) => {
720
- return /* @__PURE__ */ jsx(Button, { "aria-label": "Remove row", ...useArrayFieldRemoveButton(), ...props, children: props.children || /* @__PURE__ */ jsx(MinusIcon, {}) });
884
+ return /* @__PURE__ */ jsx15(Button3, { "aria-label": "Remove row", ...useArrayFieldRemoveButton(), ...props, children: props.children || /* @__PURE__ */ jsx15(MinusIcon, {}) });
721
885
  };
722
886
  ArrayFieldRemoveButton.displayName = "ArrayFieldRemoveButton";
723
887
  var ArrayFieldAddButton = (props) => {
724
- return /* @__PURE__ */ jsx(
725
- Button,
888
+ return /* @__PURE__ */ jsx15(
889
+ Button3,
726
890
  {
727
891
  "aria-label": "Add row",
728
892
  float: "right",
729
893
  ...useArrayFieldAddButton(),
730
894
  ...props,
731
- children: props.children || /* @__PURE__ */ jsx(PlusIcon, {})
895
+ children: props.children || /* @__PURE__ */ jsx15(PlusIcon, {})
732
896
  }
733
897
  );
734
898
  };
735
899
  ArrayFieldAddButton.displayName = "ArrayFieldAddButton";
736
- var ArrayField = forwardRef(
900
+ var ArrayField = forwardRef11(
737
901
  (props, ref) => {
738
902
  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, {})
903
+ const rowFn = isFunction(children) ? children : (fields) => /* @__PURE__ */ jsx15(Fragment, { children: fields.map(({ id }, index) => /* @__PURE__ */ jsx15(ArrayFieldRow, { index, children }, id)) || null });
904
+ return /* @__PURE__ */ jsxs7(ArrayFieldContainer, { ref, ...containerProps, children: [
905
+ /* @__PURE__ */ jsx15(ArrayFieldRows, { children: rowFn }),
906
+ /* @__PURE__ */ jsx15(ArrayFieldAddButton, {})
743
907
  ] });
744
908
  }
745
909
  );
@@ -751,7 +915,7 @@ var ArrayFieldRows = ({
751
915
  return children(fields);
752
916
  };
753
917
  ArrayFieldRows.displayName = "ArrayFieldRows";
754
- var ArrayFieldContainer = React11.forwardRef(
918
+ var ArrayFieldContainer = React9.forwardRef(
755
919
  ({
756
920
  name,
757
921
  defaultValue,
@@ -769,14 +933,22 @@ var ArrayFieldContainer = React11.forwardRef(
769
933
  min: min || (overrides == null ? void 0 : overrides.min),
770
934
  max: max || (overrides == null ? void 0 : overrides.max)
771
935
  });
772
- React11.useImperativeHandle(ref, () => context, [ref, context]);
773
- return /* @__PURE__ */ jsx(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ jsx(BaseField, { name, ...fieldProps, ...overrides, children }) });
936
+ React9.useImperativeHandle(ref, () => context, [ref, context]);
937
+ return /* @__PURE__ */ jsx15(ArrayFieldProvider, { value: context, children: /* @__PURE__ */ jsx15(BaseField, { name, ...fieldProps, ...overrides, children }) });
774
938
  }
775
939
  );
776
940
  ArrayFieldContainer.displayName = "ArrayFieldContainer";
941
+
942
+ // src/object-field.tsx
943
+ import {
944
+ FormControl as FormControl3,
945
+ FormLabel as FormLabel3,
946
+ useStyleConfig
947
+ } from "@chakra-ui/react";
948
+ import { jsx as jsx16, jsxs as jsxs8 } from "react/jsx-runtime";
777
949
  var FormLegend = (props) => {
778
950
  const styles = useStyleConfig("SuiFormLegend");
779
- return /* @__PURE__ */ jsx(FormLabel, { as: "legend", sx: styles, ...props });
951
+ return /* @__PURE__ */ jsx16(FormLabel3, { as: "legend", sx: styles, ...props });
780
952
  };
781
953
  var ObjectField = (props) => {
782
954
  const {
@@ -791,9 +963,9 @@ var ObjectField = (props) => {
791
963
  const { hideLabel, columns, spacing, ...overrides } = useFieldProps(
792
964
  name
793
965
  );
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(
966
+ return /* @__PURE__ */ jsxs8(FormControl3, { name, as: "fieldset", ...fieldProps, ...overrides, children: [
967
+ /* @__PURE__ */ jsx16(FormLegend, { display: hideLabelProp || hideLabel ? "none" : "block", children: label }),
968
+ /* @__PURE__ */ jsx16(
797
969
  FormLayout,
798
970
  {
799
971
  columns: columnsProp || columns,
@@ -804,10 +976,13 @@ var ObjectField = (props) => {
804
976
  ] });
805
977
  };
806
978
  ObjectField.displayName = "ObjectField";
979
+
980
+ // src/fields.tsx
981
+ import { jsx as jsx17 } from "react/jsx-runtime";
807
982
  var mapNestedFields2 = (resolver, name) => {
808
983
  var _a;
809
984
  return (_a = resolver.getNestedFields(name)) == null ? void 0 : _a.map(
810
- ({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */ jsx(
985
+ ({ name: name2, type, ...nestedFieldProps }, i) => /* @__PURE__ */ jsx17(
811
986
  Field,
812
987
  {
813
988
  name: name2,
@@ -827,10 +1002,10 @@ var AutoFields = ({
827
1002
  const context = useFormContext();
828
1003
  const schema = schemaProp || context.schema;
829
1004
  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]);
1005
+ const resolver = React10.useMemo(() => fieldResolver, [schema, fieldResolver]);
1006
+ const fields = React10.useMemo(() => resolver == null ? void 0 : resolver.getFields(), [resolver]);
832
1007
  const form = useFormContext();
833
- React11.useEffect(() => {
1008
+ React10.useEffect(() => {
834
1009
  var _a;
835
1010
  if (focusFirstField && ((_a = fields == null ? void 0 : fields[0]) == null ? void 0 : _a.name)) {
836
1011
  form.setFocus(fields[0].name);
@@ -839,7 +1014,7 @@ var AutoFields = ({
839
1014
  if (!resolver) {
840
1015
  return null;
841
1016
  }
842
- return /* @__PURE__ */ jsx(FormLayout, { ...props, children: fields == null ? void 0 : fields.map(
1017
+ return /* @__PURE__ */ jsx17(FormLayout, { ...props, children: fields == null ? void 0 : fields.map(
843
1018
  ({
844
1019
  name,
845
1020
  type,
@@ -847,16 +1022,21 @@ var AutoFields = ({
847
1022
  ...fieldProps
848
1023
  }) => {
849
1024
  if (type === "array") {
850
- return /* @__PURE__ */ jsx(ArrayField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
1025
+ return /* @__PURE__ */ jsx17(ArrayField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
851
1026
  } else if (type === "object") {
852
- return /* @__PURE__ */ jsx(ObjectField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
1027
+ return /* @__PURE__ */ jsx17(ObjectField, { name, ...fieldProps, children: mapNestedFields2(resolver, name) }, name);
853
1028
  }
854
- return /* @__PURE__ */ jsx(Field, { name, type, ...fieldProps }, name);
1029
+ return /* @__PURE__ */ jsx17(Field, { name, type, ...fieldProps }, name);
855
1030
  }
856
1031
  ) });
857
1032
  };
858
1033
  AutoFields.displayName = "Fields";
859
- var SubmitButton = forwardRef(
1034
+
1035
+ // src/submit-button.tsx
1036
+ import { useFormContext as useFormContext2 } from "react-hook-form";
1037
+ import { Button as Button4, forwardRef as forwardRef12 } from "@chakra-ui/react";
1038
+ import { jsx as jsx18 } from "react/jsx-runtime";
1039
+ var SubmitButton = forwardRef12(
860
1040
  (props, ref) => {
861
1041
  const {
862
1042
  children = "Submit",
@@ -866,10 +1046,10 @@ var SubmitButton = forwardRef(
866
1046
  isLoading,
867
1047
  ...rest
868
1048
  } = props;
869
- const { formState } = useFormContext$1();
1049
+ const { formState } = useFormContext2();
870
1050
  const isDisabled = disableIfUntouched && !formState.isDirty || disableIfInvalid && !formState.isValid || isDisabledProp;
871
- return /* @__PURE__ */ jsx(
872
- Button,
1051
+ return /* @__PURE__ */ jsx18(
1052
+ Button4,
873
1053
  {
874
1054
  ...rest,
875
1055
  ref,
@@ -887,6 +1067,11 @@ SubmitButton.defaultProps = {
887
1067
  disableIfInvalid: false
888
1068
  };
889
1069
  SubmitButton.displayName = "SubmitButton";
1070
+
1071
+ // src/display-if.tsx
1072
+ import {
1073
+ useWatch
1074
+ } from "react-hook-form";
890
1075
  var DisplayIf = ({
891
1076
  children,
892
1077
  name,
@@ -905,7 +1090,28 @@ var DisplayIf = ({
905
1090
  return condition(value, context) ? children : null;
906
1091
  };
907
1092
  DisplayIf.displayName = "DisplayIf";
908
- var [StepFormProvider, useStepFormContext] = createContext({
1093
+
1094
+ // src/step-form.tsx
1095
+ import * as React12 from "react";
1096
+ import {
1097
+ chakra as chakra4,
1098
+ Button as Button5
1099
+ } from "@chakra-ui/react";
1100
+ import { callAllHandlers as callAllHandlers2, cx as cx3 } from "@chakra-ui/utils";
1101
+ import {
1102
+ Steps,
1103
+ StepsItem,
1104
+ useStepperContext
1105
+ } from "@saas-ui/core";
1106
+
1107
+ // src/use-step-form.tsx
1108
+ import * as React11 from "react";
1109
+ import { createContext as createContext4 } from "@chakra-ui/react-utils";
1110
+ import {
1111
+ useStepper,
1112
+ useStep
1113
+ } from "@saas-ui/core";
1114
+ var [StepFormProvider, useStepFormContext] = createContext4({
909
1115
  name: "StepFormContext",
910
1116
  errorMessage: "useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"
911
1117
  });
@@ -981,6 +1187,9 @@ function useFormStep(props) {
981
1187
  ...steps[name] || { name, schema }
982
1188
  };
983
1189
  }
1190
+
1191
+ // src/step-form.tsx
1192
+ import { jsx as jsx19 } from "react/jsx-runtime";
984
1193
  var FormStepper = (props) => {
985
1194
  const { activeIndex, setIndex } = useStepperContext();
986
1195
  const {
@@ -993,10 +1202,10 @@ var FormStepper = (props) => {
993
1202
  render,
994
1203
  ...rest
995
1204
  } = props;
996
- const elements = React11.Children.map(children, (child) => {
997
- if (React11.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
1205
+ const elements = React12.Children.map(children, (child) => {
1206
+ if (React12.isValidElement(child) && (child == null ? void 0 : child.type) === FormStep) {
998
1207
  const { isCompleted } = useFormStep(child.props);
999
- return /* @__PURE__ */ jsx(
1208
+ return /* @__PURE__ */ jsx19(
1000
1209
  StepsItem,
1001
1210
  {
1002
1211
  render,
@@ -1010,11 +1219,11 @@ var FormStepper = (props) => {
1010
1219
  }
1011
1220
  return child;
1012
1221
  });
1013
- const onChange = React11.useCallback((i) => {
1222
+ const onChange = React12.useCallback((i) => {
1014
1223
  setIndex(i);
1015
1224
  onChangeProp == null ? void 0 : onChangeProp(i);
1016
1225
  }, []);
1017
- return /* @__PURE__ */ jsx(
1226
+ return /* @__PURE__ */ jsx19(
1018
1227
  Steps,
1019
1228
  {
1020
1229
  orientation,
@@ -1031,19 +1240,19 @@ var FormStep = (props) => {
1031
1240
  const { name, children, className, onSubmit, ...rest } = props;
1032
1241
  const step = useFormStep({ name, onSubmit });
1033
1242
  const { isActive } = step;
1034
- return isActive ? /* @__PURE__ */ jsx(chakra.div, { ...rest, className: cx("sui-form__step", className), children }) : null;
1243
+ return isActive ? /* @__PURE__ */ jsx19(chakra4.div, { ...rest, className: cx3("sui-form__step", className), children }) : null;
1035
1244
  };
1036
1245
  FormStep.displayName = "FormStep";
1037
1246
  var PrevButton = (props) => {
1038
1247
  const { isFirstStep, isCompleted, prevStep } = useStepperContext();
1039
- return /* @__PURE__ */ jsx(
1040
- Button,
1248
+ return /* @__PURE__ */ jsx19(
1249
+ Button5,
1041
1250
  {
1042
1251
  isDisabled: isFirstStep || isCompleted,
1043
1252
  children: "Back",
1044
1253
  ...props,
1045
- className: cx("sui-form__prev-button", props.className),
1046
- onClick: callAllHandlers(props.onClick, prevStep)
1254
+ className: cx3("sui-form__prev-button", props.className),
1255
+ onClick: callAllHandlers2(props.onClick, prevStep)
1047
1256
  }
1048
1257
  );
1049
1258
  };
@@ -1051,17 +1260,20 @@ PrevButton.displayName = "PrevButton";
1051
1260
  var NextButton = (props) => {
1052
1261
  const { label = "Next", submitLabel = "Complete", ...rest } = props;
1053
1262
  const { isLastStep, isCompleted } = useStepperContext();
1054
- return /* @__PURE__ */ jsx(
1263
+ return /* @__PURE__ */ jsx19(
1055
1264
  SubmitButton,
1056
1265
  {
1057
1266
  ...rest,
1058
1267
  isDisabled: isCompleted,
1059
- className: cx("sui-form__next-button", props.className),
1268
+ className: cx3("sui-form__next-button", props.className),
1060
1269
  children: isLastStep || isCompleted ? submitLabel : label
1061
1270
  }
1062
1271
  );
1063
1272
  };
1064
1273
  NextButton.displayName = "NextButton";
1274
+
1275
+ // src/field-resolver.ts
1276
+ import { get as get2 } from "@chakra-ui/utils";
1065
1277
  var mapFields = (schema) => schema && Object.entries(schema).map(([name, { items, label, title, ...field }]) => {
1066
1278
  return {
1067
1279
  ...field,
@@ -1076,7 +1288,7 @@ var objectFieldResolver = (schema) => {
1076
1288
  };
1077
1289
  const getNestedFields = (name) => {
1078
1290
  var _a;
1079
- const field = get$1(schema, name);
1291
+ const field = get2(schema, name);
1080
1292
  if (!field)
1081
1293
  return [];
1082
1294
  if (((_a = field.items) == null ? void 0 : _a.type) === "object") {
@@ -1088,10 +1300,13 @@ var objectFieldResolver = (schema) => {
1088
1300
  };
1089
1301
  return { getFields, getNestedFields };
1090
1302
  };
1303
+
1304
+ // src/watch-field.tsx
1305
+ import { useWatch as useWatch2 } from "react-hook-form";
1091
1306
  var WatchField = (props) => {
1092
1307
  const { name, defaultValue, isDisabled, isExact } = props;
1093
1308
  const form = useFormContext();
1094
- const field = useWatch({
1309
+ const field = useWatch2({
1095
1310
  name,
1096
1311
  defaultValue,
1097
1312
  disabled: isDisabled,
@@ -1099,7 +1314,16 @@ var WatchField = (props) => {
1099
1314
  });
1100
1315
  return props.children(field, form) || null;
1101
1316
  };
1102
- var Form = forwardRef(
1317
+
1318
+ // src/form.tsx
1319
+ import * as React13 from "react";
1320
+ import { chakra as chakra5, forwardRef as forwardRef13 } from "@chakra-ui/react";
1321
+ import { cx as cx4, runIfFn } from "@chakra-ui/utils";
1322
+ import {
1323
+ useForm
1324
+ } from "react-hook-form";
1325
+ import { jsx as jsx20, jsxs as jsxs9 } from "react/jsx-runtime";
1326
+ var Form = forwardRef13(
1103
1327
  (props, ref) => {
1104
1328
  const {
1105
1329
  mode = "all",
@@ -1140,8 +1364,8 @@ var Form = forwardRef(
1140
1364
  };
1141
1365
  const methods = useForm(form);
1142
1366
  const { handleSubmit } = methods;
1143
- React11.useImperativeHandle(formRef, () => methods, [formRef, methods]);
1144
- React11.useEffect(() => {
1367
+ React13.useImperativeHandle(formRef, () => methods, [formRef, methods]);
1368
+ React13.useEffect(() => {
1145
1369
  let subscription;
1146
1370
  if (onChange) {
1147
1371
  subscription = methods.watch(onChange);
@@ -1150,25 +1374,25 @@ var Form = forwardRef(
1150
1374
  }, [methods, onChange]);
1151
1375
  let _children = children;
1152
1376
  if (!_children && fieldResolver) {
1153
- _children = /* @__PURE__ */ jsxs(FormLayout, { children: [
1154
- /* @__PURE__ */ jsx(AutoFields, {}),
1155
- /* @__PURE__ */ jsx(SubmitButton, { ...fields == null ? void 0 : fields.submit })
1377
+ _children = /* @__PURE__ */ jsxs9(FormLayout, { children: [
1378
+ /* @__PURE__ */ jsx20(AutoFields, {}),
1379
+ /* @__PURE__ */ jsx20(SubmitButton, { ...fields == null ? void 0 : fields.submit })
1156
1380
  ] });
1157
1381
  }
1158
- return /* @__PURE__ */ jsx(
1382
+ return /* @__PURE__ */ jsx20(
1159
1383
  FormProvider,
1160
1384
  {
1161
1385
  ...methods,
1162
1386
  schema,
1163
1387
  fieldResolver,
1164
1388
  fields,
1165
- children: /* @__PURE__ */ jsx(
1166
- chakra.form,
1389
+ children: /* @__PURE__ */ jsx20(
1390
+ chakra5.form,
1167
1391
  {
1168
1392
  ref,
1169
1393
  onSubmit: handleSubmit(onSubmit, onError),
1170
1394
  ...rest,
1171
- className: cx("sui-form", props.className),
1395
+ className: cx4("sui-form", props.className),
1172
1396
  children: runIfFn(_children, {
1173
1397
  Field,
1174
1398
  DisplayIf,
@@ -1183,15 +1407,19 @@ var Form = forwardRef(
1183
1407
  }
1184
1408
  );
1185
1409
  Form.displayName = "Form";
1410
+
1411
+ // src/create-form.tsx
1412
+ import { forwardRef as forwardRef14 } from "@chakra-ui/react";
1413
+ import { jsx as jsx21 } from "react/jsx-runtime";
1186
1414
  function createForm({
1187
1415
  resolver,
1188
1416
  fieldResolver = objectFieldResolver,
1189
1417
  fields
1190
1418
  } = {}) {
1191
- const DefaultForm = forwardRef(
1419
+ const DefaultForm = forwardRef14(
1192
1420
  (props, ref) => {
1193
1421
  const { schema, ...rest } = props;
1194
- return /* @__PURE__ */ jsx(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsx(
1422
+ return /* @__PURE__ */ jsx21(FieldsProvider, { value: fields || {}, children: /* @__PURE__ */ jsx21(
1195
1423
  Form,
1196
1424
  {
1197
1425
  ref,
@@ -1206,8 +1434,15 @@ function createForm({
1206
1434
  DefaultForm.id = "Form";
1207
1435
  return DefaultForm;
1208
1436
  }
1437
+
1438
+ // src/create-step-form.tsx
1439
+ import { useMemo as useMemo2 } from "react";
1440
+ import { forwardRef as forwardRef15 } from "@chakra-ui/react";
1441
+ import { StepperProvider } from "@saas-ui/core";
1442
+ import { runIfFn as runIfFn2 } from "@chakra-ui/utils";
1443
+ import { jsx as jsx22 } from "react/jsx-runtime";
1209
1444
  function createStepForm({ fields, resolver, fieldResolver } = {}) {
1210
- const StepForm2 = forwardRef((props, ref) => {
1445
+ const StepForm2 = forwardRef15((props, ref) => {
1211
1446
  const { children, steps, ...rest } = props;
1212
1447
  const stepper = useStepForm({
1213
1448
  resolver,
@@ -1215,8 +1450,8 @@ function createStepForm({ fields, resolver, fieldResolver } = {}) {
1215
1450
  ...props
1216
1451
  });
1217
1452
  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, {
1453
+ const context = useMemo2(() => ctx, [ctx]);
1454
+ 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
1455
  ...stepper,
1221
1456
  Field,
1222
1457
  FormStep,
@@ -1228,9 +1463,91 @@ function createStepForm({ fields, resolver, fieldResolver } = {}) {
1228
1463
  StepForm2.displayName = `Step${Form.displayName || Form.name}`;
1229
1464
  return StepForm2;
1230
1465
  }
1466
+
1467
+ // src/index.ts
1468
+ import {
1469
+ appendErrors,
1470
+ useController,
1471
+ useFieldArray as useFieldArray2,
1472
+ useForm as useForm2,
1473
+ useFormState,
1474
+ useWatch as useWatch3,
1475
+ Controller as Controller2
1476
+ } from "react-hook-form";
1231
1477
  var Form2 = createForm();
1232
1478
  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
1479
+ export {
1480
+ ArrayField,
1481
+ ArrayFieldAddButton,
1482
+ ArrayFieldContainer,
1483
+ ArrayFieldProvider,
1484
+ ArrayFieldRemoveButton,
1485
+ ArrayFieldRow,
1486
+ ArrayFieldRowContainer,
1487
+ ArrayFieldRowFields,
1488
+ ArrayFieldRowProvider,
1489
+ ArrayFieldRows,
1490
+ AutoFields,
1491
+ BaseField,
1492
+ Form as BaseForm,
1493
+ CheckboxField,
1494
+ Controller2 as Controller,
1495
+ DisplayField,
1496
+ DisplayIf,
1497
+ Field,
1498
+ FieldsProvider,
1499
+ Form2 as Form,
1500
+ FormLayout,
1501
+ FormLegend,
1502
+ FormProvider,
1503
+ FormStep,
1504
+ FormStepper,
1505
+ FormValue,
1506
+ InputField,
1507
+ InputRightButton,
1508
+ NativeSelect,
1509
+ NativeSelectField,
1510
+ NextButton,
1511
+ NumberInputField2 as NumberInputField,
1512
+ ObjectField,
1513
+ PasswordInput,
1514
+ PasswordInputField,
1515
+ PinField,
1516
+ PrevButton,
1517
+ RadioField,
1518
+ RadioInput,
1519
+ Select,
1520
+ SelectButton,
1521
+ SelectField,
1522
+ SelectList,
1523
+ SelectOption,
1524
+ StepForm,
1525
+ StepFormProvider,
1526
+ SubmitButton,
1527
+ SwitchField,
1528
+ TextareaField,
1529
+ WatchField,
1530
+ appendErrors,
1531
+ createField,
1532
+ createForm,
1533
+ createStepForm,
1534
+ defaultFieldTypes,
1535
+ objectFieldResolver,
1536
+ useArrayField,
1537
+ useArrayFieldAddButton,
1538
+ useArrayFieldContext,
1539
+ useArrayFieldRemoveButton,
1540
+ useArrayFieldRow,
1541
+ useArrayFieldRowContext,
1542
+ useController,
1543
+ useField,
1544
+ useFieldArray2 as useFieldArray,
1545
+ useForm2 as useForm,
1546
+ useFormContext,
1547
+ useFormState,
1548
+ useFormStep,
1549
+ useStepForm,
1550
+ useStepFormContext,
1551
+ useWatch3 as useWatch
1552
+ };
1236
1553
  //# sourceMappingURL=index.mjs.map