@saas-ui/forms 0.6.0-next.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +26 -12
- package/dist/auto-form.d.ts +5 -2
- package/dist/auto-form.d.ts.map +1 -1
- package/dist/field-resolver.d.ts +7 -2
- package/dist/field-resolver.d.ts.map +1 -1
- package/dist/fields.d.ts.map +1 -1
- package/dist/form.d.ts +9 -3
- package/dist/form.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/yup/index.js +2 -0
- package/dist/yup/index.js.map +1 -0
- package/dist/yup/index.modern.js +2 -0
- package/dist/yup/index.modern.js.map +1 -0
- package/dist/yup/src/index.d.ts +2 -0
- package/dist/yup/src/index.d.ts.map +1 -0
- package/dist/yup/src/yup.d.ts +25 -0
- package/dist/yup/src/yup.d.ts.map +1 -0
- package/package.json +8 -12
- package/src/auto-form.tsx +4 -3
- package/src/field-resolver.ts +10 -5
- package/src/fields.tsx +2 -2
- package/src/form.tsx +25 -2
- package/yup/package.json +11 -4
package/CHANGELOG.md
CHANGED
@@ -1,36 +1,50 @@
|
|
1
1
|
# @saas-ui/forms
|
2
2
|
|
3
|
-
## 0.6.0
|
3
|
+
## 0.6.0
|
4
4
|
|
5
5
|
### Minor Changes
|
6
6
|
|
7
|
-
-
|
7
|
+
- 0e81abd: BREAKING: Removed Yup dependency, you now need to configure default Form resolvers
|
8
8
|
|
9
|
-
<Form>
|
9
|
+
<Form> no longer accepts a Yup `schema` by default.
|
10
10
|
|
11
11
|
Use a schema resolver to use schema support. All hookform resolvers are supported.
|
12
12
|
|
13
|
-
```
|
14
|
-
import {yupResolver} from '@hookform/resolvers/yup'
|
13
|
+
```ts
|
14
|
+
import { yupResolver } from '@hookform/resolvers/yup'
|
15
15
|
|
16
|
-
<Form resolver={yupResolver(schema)} />
|
16
|
+
const form = <Form resolver={yupResolver(schema)} />
|
17
17
|
```
|
18
18
|
|
19
19
|
AutoForm only supports Yup for now and has a new API.
|
20
20
|
|
21
|
-
```
|
21
|
+
```ts
|
22
22
|
import { yupForm } from '@saas-ui/forms/yup'
|
23
23
|
|
24
|
-
<AutoForm {...yupForm(schema)} />
|
24
|
+
const form = <AutoForm {...yupForm(schema)} />
|
25
25
|
```
|
26
26
|
|
27
|
+
Alternatively you can configure a default resolver for all forms.
|
28
|
+
Add this somewhere in the root of your project.
|
29
|
+
|
30
|
+
```ts
|
31
|
+
import { Form } from '@saas-ui/react'
|
32
|
+
import { yupResolver, yupFieldResolver } from '@saas-ui/forms/yup' // yupResolver is exported from here as well for convenience.
|
33
|
+
import { AnyObjectSchema } from 'yup'
|
34
|
+
|
35
|
+
Form.getResolver = (schema: AnyObjectSchema) => yupResolver(schema) // @hookform/resolvers
|
36
|
+
Form.getFieldResolver = (schema: AnyObjectSchema) => yupFieldResolver(schema) // AutoForm field resolver
|
37
|
+
```
|
38
|
+
|
39
|
+
- 9391c44: Fixed peer dependency issues.
|
40
|
+
|
27
41
|
### Patch Changes
|
28
42
|
|
29
43
|
- Updated dependencies [9391c44]
|
30
|
-
- @saas-ui/button@0.4.0
|
31
|
-
- @saas-ui/select@0.4.0
|
32
|
-
- @saas-ui/input-right-button@0.3.1
|
33
|
-
- @saas-ui/password-input@0.3.1
|
44
|
+
- @saas-ui/button@0.4.0
|
45
|
+
- @saas-ui/select@0.4.0
|
46
|
+
- @saas-ui/input-right-button@0.3.1
|
47
|
+
- @saas-ui/password-input@0.3.1
|
34
48
|
|
35
49
|
## 0.5.3
|
36
50
|
|
package/dist/auto-form.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { FieldValues, UseFormReturn } from 'react-hook-form';
|
3
3
|
import { FormProps } from './form';
|
4
|
+
import { FieldResolver } from '.';
|
4
5
|
interface AutoFormOptions {
|
5
6
|
submitLabel?: false | string;
|
6
7
|
schema: any;
|
@@ -8,8 +9,10 @@ interface AutoFormOptions {
|
|
8
9
|
}
|
9
10
|
export interface AutoFormProps<TFieldValues extends FieldValues> extends Omit<FormProps<TFieldValues>, 'schema'>, AutoFormOptions {
|
10
11
|
}
|
11
|
-
export declare const AutoForm: <TFieldValues extends FieldValues>(props: AutoFormProps<TFieldValues> & {
|
12
|
+
export declare const AutoForm: (<TFieldValues extends FieldValues>(props: AutoFormProps<TFieldValues> & {
|
12
13
|
ref?: React.ForwardedRef<UseFormReturn<TFieldValues, object>> | undefined;
|
13
|
-
}) => React.ReactElement
|
14
|
+
}) => React.ReactElement) & {
|
15
|
+
getFieldResolver?: ((schema: any) => FieldResolver) | undefined;
|
16
|
+
};
|
14
17
|
export {};
|
15
18
|
//# sourceMappingURL=auto-form.d.ts.map
|
package/dist/auto-form.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"auto-form.d.ts","sourceRoot":"","sources":["../src/auto-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAG5D,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAA;
|
1
|
+
{"version":3,"file":"auto-form.d.ts","sourceRoot":"","sources":["../src/auto-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAG5D,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAA;AAIxC,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAA;AAEjC,UAAU,eAAe;IACvB,WAAW,CAAC,EAAE,KAAK,GAAG,MAAM,CAAA;IAC5B,MAAM,EAAE,GAAG,CAAA;IACX,aAAa,CAAC,EAAE,GAAG,CAAA;CACpB;AAED,MAAM,WAAW,aAAa,CAAC,YAAY,SAAS,WAAW,CAC7D,SAAQ,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,EAAE,QAAQ,CAAC,EAC7C,eAAe;CAAG;AAEtB,eAAO,MAAM,QAAQ;;MAoBhB,MAAM,YAAY;iCAAkC,GAAG,KAAK,aAAa;CAAE,CAAA"}
|
package/dist/field-resolver.d.ts
CHANGED
@@ -3,6 +3,11 @@ export declare type FieldResolver = {
|
|
3
3
|
getFields(): FieldProps[];
|
4
4
|
getNestedFields(name: string): FieldProps[];
|
5
5
|
};
|
6
|
-
|
7
|
-
|
6
|
+
interface SchemaField extends FieldProps {
|
7
|
+
items?: SchemaField[];
|
8
|
+
properties?: Record<string, SchemaField>;
|
9
|
+
}
|
10
|
+
export declare type ObjectSchema = Record<string, SchemaField>;
|
11
|
+
export declare const objectFieldResolver: (schema: ObjectSchema) => FieldResolver;
|
12
|
+
export {};
|
8
13
|
//# sourceMappingURL=field-resolver.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"field-resolver.d.ts","sourceRoot":"","sources":["../src/field-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAIpC,oBAAY,aAAa,GAAG;IAC1B,SAAS,IAAI,UAAU,EAAE,CAAA;IACzB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CAAA;CAC5C,CAAA;
|
1
|
+
{"version":3,"file":"field-resolver.d.ts","sourceRoot":"","sources":["../src/field-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAIpC,oBAAY,aAAa,GAAG;IAC1B,SAAS,IAAI,UAAU,EAAE,CAAA;IACzB,eAAe,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,EAAE,CAAA;CAC5C,CAAA;AAED,UAAU,WAAY,SAAQ,UAAU;IACtC,KAAK,CAAC,EAAE,WAAW,EAAE,CAAA;IACrB,UAAU,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;CACzC;AAED,oBAAY,YAAY,GAAG,MAAM,CAAC,MAAM,EAAE,WAAW,CAAC,CAAA;AAWtD,eAAO,MAAM,mBAAmB,WAAY,YAAY,KAAG,aAkB1D,CAAA"}
|
package/dist/fields.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;
|
1
|
+
{"version":3,"file":"fields.d.ts","sourceRoot":"","sources":["../src/fields.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAQ9B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAEhD,MAAM,WAAW,WAAW;IAC1B,MAAM,EAAE,GAAG,CAAA;IACX,aAAa,CAAC,EAAE,aAAa,CAAA;CAC9B;AAYD,eAAO,MAAM,MAAM,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAwCxC,CAAA"}
|
package/dist/form.d.ts
CHANGED
@@ -1,6 +1,7 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { HTMLChakraProps } from '@chakra-ui/react';
|
3
|
-
import { UseFormProps, UseFormReturn, FieldValues, SubmitHandler, SubmitErrorHandler } from 'react-hook-form';
|
3
|
+
import { UseFormProps, UseFormReturn, FieldValues, SubmitHandler, SubmitErrorHandler, UnpackNestedValue, ResolverOptions, ResolverResult } from 'react-hook-form';
|
4
|
+
import { FieldResolver } from './field-resolver';
|
4
5
|
export type { UseFormReturn, FieldValues, SubmitHandler };
|
5
6
|
interface FormOptions<TFieldValues extends FieldValues = FieldValues> {
|
6
7
|
/**
|
@@ -26,7 +27,12 @@ interface FormOptions<TFieldValues extends FieldValues = FieldValues> {
|
|
26
27
|
*/
|
27
28
|
export interface FormProps<TFieldValues extends FieldValues = FieldValues> extends UseFormProps<TFieldValues>, Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>, FormOptions<TFieldValues> {
|
28
29
|
}
|
29
|
-
export declare const Form: <TFieldValues extends FieldValues>(props: FormProps<TFieldValues> & {
|
30
|
+
export declare const Form: (<TFieldValues extends FieldValues>(props: FormProps<TFieldValues> & {
|
30
31
|
ref?: React.ForwardedRef<UseFormReturn<TFieldValues, object>> | undefined;
|
31
|
-
}) => React.ReactElement
|
32
|
+
}) => React.ReactElement) & {
|
33
|
+
getResolver?: GetResolver | undefined;
|
34
|
+
getFieldResolver: GetFieldResolver;
|
35
|
+
};
|
36
|
+
export declare type GetResolver = (schema: any) => <TFieldValues extends FieldValues, TContext>(values: UnpackNestedValue<TFieldValues>, context: TContext | undefined, options: ResolverOptions<TFieldValues>) => Promise<ResolverResult<TFieldValues>>;
|
37
|
+
export declare type GetFieldResolver = (schema: any) => FieldResolver;
|
32
38
|
//# sourceMappingURL=form.d.ts.map
|
package/dist/form.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,eAAe,EAAc,MAAM,kBAAkB,CAAA;AAEtE,OAAO,EAGL,YAAY,EACZ,aAAa,EACb,WAAW,EACX,aAAa,EACb,kBAAkB,
|
1
|
+
{"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,eAAe,EAAc,MAAM,kBAAkB,CAAA;AAEtE,OAAO,EAGL,YAAY,EACZ,aAAa,EACb,WAAW,EACX,aAAa,EACb,kBAAkB,EAClB,iBAAiB,EACjB,eAAe,EACf,cAAc,EACf,MAAM,iBAAiB,CAAA;AACxB,OAAO,EAAuB,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAErE,YAAY,EAAE,aAAa,EAAE,WAAW,EAAE,aAAa,EAAE,CAAA;AAEzD,UAAU,WAAW,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW;IAClE;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ;;OAEG;IACH,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,CAAA;IACrC;;OAEG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAA;IAC1C;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAA;CAClD;AAED;;;GAGG;AACH,MAAM,WAAW,SAAS,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,CACvE,SAAQ,YAAY,CAAC,YAAY,CAAC,EAChC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,EACrD,WAAW,CAAC,YAAY,CAAC;CAAG;AAEhC,eAAO,MAAM,IAAI;;MA6DZ,MAAM,YAAY;;sBAEH,gBAAgB;CACnC,CAAA;AAID,oBAAY,WAAW,GAAG,CACxB,MAAM,EAAE,GAAG,KACR,CAAC,YAAY,SAAS,WAAW,EAAE,QAAQ,EAC9C,MAAM,EAAE,iBAAiB,CAAC,YAAY,CAAC,EACvC,OAAO,EAAE,QAAQ,GAAG,SAAS,EAC7B,OAAO,EAAE,eAAe,CAAC,YAAY,CAAC,KACnC,OAAO,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC,CAAA;AAE1C,oBAAY,gBAAgB,GAAG,CAAC,MAAM,EAAE,GAAG,KAAK,aAAa,CAAA"}
|
package/dist/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var e=require("react"),t=require("react-hook-form"),r=require("@chakra-ui/react"),n=require("@saas-ui/number-input"),a=require("@saas-ui/password-input"),l=require("@saas-ui/radio"),i=require("@saas-ui/pin-input"),o=require("@saas-ui/select"),s=require("@chakra-ui/system"),u=require("@chakra-ui/icons"),c=require("@saas-ui/button"),m=require("@chakra-ui/react-utils"),d=require("@chakra-ui/utils"),p=require("@saas-ui/react-utils"),f=require("@saas-ui/input-right-button");function v(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var h=/*#__PURE__*/v(e);function x(){return x=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},x.apply(this,arguments)}function E(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var b=["name","label","placeholder"],y=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null},F=["name","label","help","variant","hideLabel","children"],S=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],_=["name","rules"],C=["ref"],g=["name","rules"],N=["ref"],k=["label"],R=["label"],w={},I=function(e){var n=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=E(e,F),c=function(e,r){return t.get(r.errors,e)}(n,t.useFormContext().formState);/*#__PURE__*/return h.createElement(r.FormControl,x({variant:i},u,{isInvalid:!!c}),a&&!o?/*#__PURE__*/h.createElement(r.FormLabel,{variant:i},a):null,/*#__PURE__*/h.createElement(r.Box,null,s,!l||null!=c&&c.message?null:/*#__PURE__*/h.createElement(r.FormHelperText,null,l),(null==c?void 0:c.message)&&/*#__PURE__*/h.createElement(r.FormErrorMessage,null,null==c?void 0:c.message)))},A=r.forwardRef(function(e,t){var r=e.type;/*#__PURE__*/return h.createElement(w[void 0===r?"text":r]||w.text,x({ref:t},e))}),V=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=E(n,_),s=t.useFormContext();/*#__PURE__*/return h.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(t){var n=t.field,l=n.ref,i=E(n,C);/*#__PURE__*/return h.createElement(e,x({},i,o,{ref:r.useMergeRefs(a,l)}))}})})},O=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=E(n,g),s=(0,t.useFormContext().register)(l,i),u=s.ref,c=E(s,N);/*#__PURE__*/return h.createElement(e,x({},c,o,{ref:r.useMergeRefs(a,u)}))})},D=function(e,t,n){var a=function(e,t){var n=t.displayName,a=t.hideLabel,l=t.BaseField,i=r.forwardRef(function(t,r){var n=t.name,i=t.label,o=t.help,s=t.isDisabled,u=t.isInvalid,c=t.isReadOnly,m=t.isRequired,d=t.rules,p=t.variant,f=E(t,S),v=x({required:m},d);/*#__PURE__*/return h.createElement(l,{name:n,label:i,help:o,hideLabel:a,isDisabled:s,isInvalid:u,isReadOnly:c,isRequired:m,variant:p},/*#__PURE__*/h.createElement(e,x({ref:r,name:n,label:i,rules:v},f)))});return i.displayName=n,i}(null!=n&&n.isControlled?V(t):O(t),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||I});return w[e]=a,a},P=D("text",r.Input),L=D("number",n.NumberInput,{isControlled:!0}),j=D("password",a.PasswordInput),q=D("textarea",r.Textarea),B=D("switch",r.forwardRef(function(e,t){var n=e.label,a=E(e,k);/*#__PURE__*/return h.createElement(r.Switch,x({ref:t},a),n)}),{isControlled:!0,hideLabel:!0}),M=D("select",o.Select,{isControlled:!0}),T=D("checkbox",r.forwardRef(function(e,t){var n=e.label,a=E(e,R);/*#__PURE__*/return h.createElement(r.Checkbox,x({ref:t},a),n)}),{hideLabel:!0}),U=D("radio",l.RadioInput,{isControlled:!0}),H=D("pin",i.PinInput,{isControlled:!0}),G=D("native-select",o.NativeSelect,{isControlled:!0}),z=["children"],W=function(e){/*#__PURE__*/return h.createElement(r.chakra.div,null,e.children)},J=function(e){var t,n,a,l=e.children,i=E(e,z),o=x({},null!=(t=null==(n=r.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return h.createElement(r.SimpleGrid,o,h.Children.map(l,function(e){return h.isValidElement(e)?/*#__PURE__*/h.createElement(W,null,e):e}))},K=function(e,t){return h.Children.map(t,function(t){return h.isValidElement(t)&&t.props.name?h.cloneElement(t,x({},t.props,{name:e+"."+t.props.name})):t})},Q=m.createContext({name:"ArrayFieldContext"}),X=Q[0],Y=Q[1],Z=m.createContext({name:"ArrayFieldRowContext"}),$=Z[0],ee=Z[1],te=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,s=t.useFormContext();return x({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},re=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=Y(),l=a.name,i=a.remove,o=a.fields;return h.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:h.useCallback(function(){n(l),i(r)},[r])}},ne=function(){var e=ee(),t=e.isFirst,r=e.remove,n=Y(),a=n.min;return{onClick:function(){return r()},isDisabled:t&&!!(a&&n.fields.length<=a)}},ae=function(){var e=Y(),t=e.append,r=e.defaultValue,n=e.max;return{onClick:function(){return t(r,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},le=["children","columns","spacing"],ie=["children"],oe=["name","defaultValue","keyName","min","max","children"],se=function(e){/*#__PURE__*/return h.createElement(ce,{index:e.index},/*#__PURE__*/h.createElement(ue,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/h.createElement(me,null))},ue=function(e){var t=e.children,r=e.columns,n=e.spacing,a=E(e,le),l=ee().name;/*#__PURE__*/return h.createElement(J,x({flex:"1",columns:r,gridGap:n,mr:"2"},a),K(l,t))},ce=function(e){var t=e.children,r=re({index:e.index});/*#__PURE__*/return h.createElement($,{value:r},/*#__PURE__*/h.createElement(s.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},me=function(e){/*#__PURE__*/return h.createElement(c.IconButton,x({icon:/*#__PURE__*/h.createElement(u.MinusIcon,null),"aria-label":"Remove row"},ne(),e))},de=function(e){/*#__PURE__*/return h.createElement(c.IconButton,x({icon:/*#__PURE__*/h.createElement(u.AddIcon,null),"aria-label":"Add row",float:"right"},ae(),e))},pe=h.forwardRef(function(e,t){var r=e.children,n=E(e,ie);/*#__PURE__*/return h.createElement(ve,x({ref:t},n),/*#__PURE__*/h.createElement(fe,null,function(e){/*#__PURE__*/return h.createElement(h.Fragment,null,e.map(function(e,t){/*#__PURE__*/return h.createElement(se,{key:e.id,index:t},r)}))}),/*#__PURE__*/h.createElement(de,null))}),fe=function(e){return(0,e.children)(Y().fields)},ve=h.forwardRef(function(e,t){var r=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=E(e,oe),u=te({name:r,defaultValue:n,keyName:a,min:l,max:i});return h.useImperativeHandle(t,function(){return u},[t,u]),/*#__PURE__*/h.createElement(X,{value:u},/*#__PURE__*/h.createElement(I,x({name:r},s),o))}),he=["name","label","hideLabel","children","columns","spacing"],xe=function(e){var t=r.useStyles();/*#__PURE__*/return h.createElement(r.FormLabel,x({as:"legend",sx:t.legend},e))},Ee=function(e){var t=e.name,n=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=E(e,he);/*#__PURE__*/return h.createElement(r.FormControl,x({name:t,as:"fieldset"},s),/*#__PURE__*/h.createElement(xe,{display:a?"none":"block"},n),/*#__PURE__*/h.createElement(J,{columns:i,gridGap:o},K(t,l)))},be=function(e){return Object.entries(e).map(function(e){return x({name:e[0]},e[1])})},ye=function(e){return{getFields:function(){return be(e)},getNestedFields:function(t){var r,n=d.get(e,t);return n?"object"===(null==(r=n.items)?void 0:r.type)?be(n.items.properties):"object"===n.type?be(n.properties):[n.items]:[]}}},Fe=["name","type"],Se=["schema","fieldResolver"],_e=["name","type","defaultValue"],Ce=function(e,t){var r;return null==(r=e.getNestedFields(t))?void 0:r.map(function(e,t){var r=e.name,n=e.type,a=E(e,Fe);/*#__PURE__*/return h.createElement(A,x({key:r||t,name:r,type:n},a))})},ge=function(e){var t=e.schema,r=e.fieldResolver,n=E(e,Se),a=h.useMemo(function(){return r||ye(t)},[t,r]);/*#__PURE__*/return h.createElement(J,n,a.getFields().map(function(e){var t=e.name,r=e.type,n=E(e,_e);return"array"===r?/*#__PURE__*/h.createElement(pe,x({key:t,name:t},n),Ce(a,t)):"object"===r?/*#__PURE__*/h.createElement(Ee,x({key:t,name:t},n),Ce(a,t)):/*#__PURE__*/h.createElement(A,x({key:t,name:t,type:r},n))}))},Ne=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],ke=r.forwardRef(function(e,n){var a=e.mode,l=void 0===a?"all":a,i=e.resolver,o=e.reValidateMode,s=e.shouldFocusError,u=e.shouldUnregister,c=e.shouldUseNativeValidation,m=e.criteriaMode,d=e.delayError,p=e.defaultValues,f=e.onSubmit,v=e.onError,b=e.formRef,y=e.children,F=E(e,Ne),S=t.useForm({mode:l,resolver:i,defaultValues:p,reValidateMode:o,shouldFocusError:s,shouldUnregister:u,shouldUseNativeValidation:c,criteriaMode:m,delayError:d}),_=S.handleSubmit;return h.useImperativeHandle(n,function(){return S},[n,S]),/*#__PURE__*/h.createElement(t.FormProvider,S,/*#__PURE__*/h.createElement(r.chakra.form,x({ref:b,onSubmit:_(f,v)},F),y))}),Re=["children","disableIfUntouched","disableIfInvalid"],we=s.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=E(e,Re),o=t.useFormContext().formState;/*#__PURE__*/return h.createElement(c.Button,x({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});we.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var Ie=["schema","submitLabel","fieldResolver"],Ae=r.forwardRef(function(e,t){var r=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=E(e,Ie);/*#__PURE__*/return h.createElement(ke,x({},i,{ref:t}),/*#__PURE__*/h.createElement(J,null,/*#__PURE__*/h.createElement(ge,{schema:r,fieldResolver:l}),a&&/*#__PURE__*/h.createElement(we,{label:a})))});function Ve(){return Ve=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Ve.apply(this,arguments)}function Oe(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var De=m.createContext({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"}),Pe=De[0],Le=De[1];function je(e){var t=e.step,r=h.useState(-1),n=r[0],a=r[1],l=h.useRef([]),i=h.useState(Date.now())[1],o=h.useCallback(function(e){var t=[].concat(l.current);-1===t.indexOf(e)&&t.push(e),l.current=t,i(Date.now())},[l,i]),s=function(e){var t=l.current.indexOf(e);-1!==t&&a(t)};return h.useLayoutEffect(function(){"string"==typeof t?s(t):"number"==typeof t?a(t):-1===n&&a(0)},[t]),{stepsRef:l,activeStep:l.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===l.current.length-1,isCompleted:n>=l.current.length,setIndex:a,setStep:s,nextStep:function(){a(n+1)},prevStep:function(){a(n-1)},registerStep:o,unregisterStep:function(e){l.current=l.current.slice(l.current.indexOf(e),1)}}}function qe(e){var t=e.name,r=e.isActive,n=e.isCompleted,a=Le(),l=a.registerStep,i=a.unregisterStep,o=a.activeStep;return h.useEffect(function(){if(t)return l(t),function(){i(t)}},[]),{isActive:t?o===t:r,isCompleted:n}}var Be=["children","orientation"],Me=["children","orientation","stepComponent"],Te=["children","isOpen"],Ue=["icon","isActive","isCompleted","className"],He=["title","icon","isActive","isCompleted"],Ge=["isActive"],ze=s.forwardRef(function(e,t){var r=s.useMultiStyleConfig("Stepper",e),n=s.omitThemingProps(e),a=n.children,l=n.orientation,i=Oe(n,Be),o=je(e),u=Ve({display:"flex",flexDirection:"column"},r.container);return h.createElement(s.StylesProvider,{value:r},/*#__PURE__*/h.createElement(Pe,{value:o},/*#__PURE__*/h.createElement(s.chakra.div,Ve({ref:t,__css:u},i,{className:d.cx("saas-stepper__container",e.className)}),/*#__PURE__*/h.createElement(We,{orientation:l},a))))});d.__DEV__&&(ze.displayName="Stepper");var We=function(e){var t,r,n=e.children,a=e.orientation,l=e.stepComponent,i=Oe(e,Me),o=s.useStyles(),u=Le().activeIndex,c=Ve({display:"flex",flexDirection:"row",alignItems:"center"},o.steps),m="vertical"===a,f=l||Qe,v=p.getChildrenOfType(n,f),x=v.reduce(function(e,t,r,n){return e.push(/*#__PURE__*/h.createElement(f,Ve({key:r},t.props,{icon:t.props.icon||r+1,isActive:u===r,isCompleted:t.props.isCompleted||u>r}))),"vertical"===a&&e.push(/*#__PURE__*/h.createElement(Je,{key:"content-"+r,isOpen:u===r},t.props.children)),r<n.length-1&&e.push(/*#__PURE__*/h.createElement(Xe,{key:"separator-"+r,isActive:r<u})),e},[]),E=p.getChildOfType(n,Ze),b=u>=v.length?E:m?null:/*#__PURE__*/h.createElement(Je,null,null==(t=v[u])||null==(r=t.props)?void 0:r.children);return h.createElement(h.Fragment,null,/*#__PURE__*/h.createElement(s.chakra.div,Ve({__css:c},i,{className:d.cx("saas-stepper__steps",e.className)}),x),b)};d.__DEV__&&(We.displayName="StepperSteps");var Je=function(e){var t=e.children,n=e.isOpen,a=void 0===n||n,l=Oe(e,Te),i=s.useStyles();return h.createElement(s.chakra.div,Ve({__css:i.content},l,{className:d.cx("saas-stepper__content",e.className)}),/*#__PURE__*/h.createElement(r.Collapse,{in:a},t))};d.__DEV__&&(Je.displayName="StepperContent");var Ke=function(e){var t,r=e.icon,n=e.isCompleted,a=e.className,l=Oe(e,Ue),i=Ve({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},s.useStyles().icon);return t=n?/*#__PURE__*/h.createElement(u.Icon,{as:u.CheckIcon}):r,/*#__PURE__*/h.createElement(s.chakra.div,Ve({__css:i},l,{className:d.cx("saas-stepper__icon",a)}),t)};d.__DEV__&&(Ke.displayName="StepperIcon");var Qe=function(e){var t=e.title,r=e.icon,n=e.isActive,a=e.isCompleted,l=Oe(e,He),i=qe(e),o=Ve({display:"flex",alignItems:"center",flexDirection:"row"},s.useStyles().step);return h.createElement(s.chakra.div,Ve({__css:o,"data-active":i.isActive,"data-completed":i.isCompleted},l,{className:d.cx("saas-stepper__step",e.className)}),/*#__PURE__*/h.createElement(Ke,{icon:r,isActive:n,isCompleted:a}),t&&/*#__PURE__*/h.createElement(Ye,null,t))};d.__DEV__&&(Qe.displayName="StepperStep");var Xe=function(e){var t=e.isActive,r=Oe(e,Ge),n=Ve({flex:1,borderTopWidth:"1px",mx:2},s.useStyles().separator);return h.createElement(s.chakra.div,Ve({"data-active":t},r,{className:d.cx("saas-stepper__separator",e.className),__css:n}))};d.__DEV__&&(Xe.displayName="StepperSeparator");var Ye=function(e){var t=s.useStyles();return h.createElement(s.chakra.p,Ve({},e,{__css:t.title,className:d.cx("saas-stepper__title",e.className)}))};d.__DEV__&&(Ye.displayName="StepperStepTitle");var Ze=function(e){var t=s.useStyles();return h.createElement(s.chakra.div,Ve({__css:t.completed},e,{className:d.cx("saas-stepper__completed",e.className)}))};d.__DEV__&&(Ze.displayName="StepperCompleted");var $e=m.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),et=$e[0],tt=$e[1];function rt(e){var t=je(e),r=t.activeStep,n=t.isLastStep,a=t.nextStep,l=h.useState({}),i=l[0],o=l[1],s=h.useCallback(function(t){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(t).then(function(){c(x({},i[r],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[r,n]),u=h.useCallback(function(e){var t=i[r];return{onSubmit:s,schema:null==t?void 0:t.schema,resolver:null==t?void 0:t.resolver}},[i,s,r]),c=h.useCallback(function(e){o(function(t){var r;return x({},t,((r={})[e.name]=e,r))})},[i]);return x({getFormProps:u,updateStep:c,steps:i},t)}function nt(e){var t=e.name,r=e.schema,n=e.resolver,a=qe({name:t}),l=tt(),i=l.steps,o=l.updateStep;return h.useEffect(function(){o({name:t,schema:r,resolver:n})},[t,r]),x({},a,i[t]||{name:t,schema:r})}var at=["children","onSubmit"],lt=["getFormProps"],it=["name","schema","resolver","children","className"],ot=["label","submitLabel"],st=h.forwardRef(function(e,t){var r=e.children,n=E(e,at),a=rt(e),l=a.getFormProps,i=E(a,lt),o=h.useMemo(function(){return i},[i]);/*#__PURE__*/return h.createElement(Pe,{value:o},/*#__PURE__*/h.createElement(et,{value:o},/*#__PURE__*/h.createElement(ke,x({ref:t},n,l(e)),d.runIfFn(r,a))))}),ut=function(e){var t=e.name,r=e.schema,n=e.resolver,a=e.children,l=e.className,i=E(e,it);return nt({name:t,schema:r,resolver:n}).isActive?/*#__PURE__*/h.createElement(s.chakra.div,x({},i,{className:d.cx("saas-form__step",l)}),a):null};d.__DEV__&&(ut.displayName="FormStep");var ct=function(e){var t=Le(),r=t.prevStep;/*#__PURE__*/return h.createElement(c.Button,x({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:d.cx("saas-form__prev-button",e.className),onClick:d.callAllHandlers(e.onClick,r)}))};d.__DEV__&&(ct.displayName="PrevButton");var mt=function(e){var t=e.label,r=void 0===t?"Next":t,n=e.submitLabel,a=void 0===n?"Complete":n,l=E(e,ot),i=Le(),o=i.isCompleted;/*#__PURE__*/return h.createElement(we,x({isDisabled:o,label:i.isLastStep||o?a:r},l,{className:d.cx("saas-form__next-button",e.className)}))};d.__DEV__&&(mt.displayName="NextButton"),exports.ArrayField=pe,exports.ArrayFieldAddButton=de,exports.ArrayFieldContainer=ve,exports.ArrayFieldProvider=X,exports.ArrayFieldRemoveButton=me,exports.ArrayFieldRow=se,exports.ArrayFieldRowContainer=ce,exports.ArrayFieldRowFields=ue,exports.ArrayFieldRowProvider=$,exports.ArrayFieldRows=fe,exports.AutoForm=Ae,exports.BaseField=I,exports.CheckboxField=T,exports.DisplayField=function(e){var t=e.name,n=e.label,a=E(e,b);/*#__PURE__*/return h.createElement(r.FormControl,a,n?/*#__PURE__*/h.createElement(r.FormLabel,{htmlFor:t},n):null,/*#__PURE__*/h.createElement(r.Text,{fontSize:"md"},/*#__PURE__*/h.createElement(y,{name:t})))},exports.DisplayIf=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null},exports.Field=A,exports.Fields=ge,exports.Form=ke,exports.FormLayout=J,exports.FormLegend=xe,exports.FormStep=ut,exports.FormStepper=function(e){var t=s.useMultiStyleConfig("Stepper",e),r=h.Children.map(e.children,function(e){if(h.isValidElement(e)&&(null==e?void 0:e.type)===ut){var t=nt(e.props);/*#__PURE__*/return h.createElement(Qe,{name:e.props.name,title:e.props.title,isCompleted:t.isCompleted},e.props.children)}return e});/*#__PURE__*/return h.createElement(s.StylesProvider,{value:t},/*#__PURE__*/h.createElement(We,x({mb:"4"},e),r))},exports.FormValue=y,exports.InputField=P,exports.NativeSelectField=G,exports.NextButton=mt,exports.NumberInputField=L,exports.ObjectField=Ee,exports.PasswordInputFIeld=j,exports.PinField=H,exports.PrevButton=ct,exports.RadioField=U,exports.SelectField=M,exports.StepForm=st,exports.StepFormProvider=et,exports.SubmitButton=we,exports.SwitchField=B,exports.TextareaField=q,exports.defaultFieldResolver=ye,exports.registerFieldType=D,exports.useArrayField=te,exports.useArrayFieldAddButton=ae,exports.useArrayFieldContext=Y,exports.useArrayFieldRemoveButton=ne,exports.useArrayFieldRow=re,exports.useArrayFieldRowContext=ee,exports.useFormStep=nt,exports.useStepForm=rt,exports.useStepFormContext=tt,exports.withControlledInput=V,exports.withUncontrolledInput=O,Object.keys(f).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return f[e]}})});
|
1
|
+
var e=require("react"),t=require("react-hook-form"),r=require("@chakra-ui/react"),n=require("@saas-ui/number-input"),a=require("@saas-ui/password-input"),l=require("@saas-ui/radio"),i=require("@saas-ui/pin-input"),o=require("@saas-ui/select"),s=require("@chakra-ui/utils"),u=require("@chakra-ui/system"),c=require("@chakra-ui/icons"),m=require("@saas-ui/button"),d=require("@chakra-ui/react-utils"),p=require("@saas-ui/react-utils"),f=require("@saas-ui/input-right-button");function v(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var h=/*#__PURE__*/v(e);function x(){return x=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},x.apply(this,arguments)}function b(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var E=["name","label","placeholder"],y=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null},F=["name","label","help","variant","hideLabel","children"],S=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],_=["name","rules"],g=["ref"],C=["name","rules"],N=["ref"],k=["label"],R=["label"],w={},I=function(e){var n=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=b(e,F),c=function(e,r){return t.get(r.errors,e)}(n,t.useFormContext().formState);/*#__PURE__*/return h.createElement(r.FormControl,x({variant:i},u,{isInvalid:!!c}),a&&!o?/*#__PURE__*/h.createElement(r.FormLabel,{variant:i},a):null,/*#__PURE__*/h.createElement(r.Box,null,s,!l||null!=c&&c.message?null:/*#__PURE__*/h.createElement(r.FormHelperText,null,l),(null==c?void 0:c.message)&&/*#__PURE__*/h.createElement(r.FormErrorMessage,null,null==c?void 0:c.message)))},A=r.forwardRef(function(e,t){var r=e.type;/*#__PURE__*/return h.createElement(w[void 0===r?"text":r]||w.text,x({ref:t},e))}),V=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=b(n,_),s=t.useFormContext();/*#__PURE__*/return h.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(t){var n=t.field,l=n.ref,i=b(n,g);/*#__PURE__*/return h.createElement(e,x({},i,o,{ref:r.useMergeRefs(a,l)}))}})})},O=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=b(n,C),s=(0,t.useFormContext().register)(l,i),u=s.ref,c=b(s,N);/*#__PURE__*/return h.createElement(e,x({},c,o,{ref:r.useMergeRefs(a,u)}))})},D=function(e,t,n){var a=function(e,t){var n=t.displayName,a=t.hideLabel,l=t.BaseField,i=r.forwardRef(function(t,r){var n=t.name,i=t.label,o=t.help,s=t.isDisabled,u=t.isInvalid,c=t.isReadOnly,m=t.isRequired,d=t.rules,p=t.variant,f=b(t,S),v=x({required:m},d);/*#__PURE__*/return h.createElement(l,{name:n,label:i,help:o,hideLabel:a,isDisabled:s,isInvalid:u,isReadOnly:c,isRequired:m,variant:p},/*#__PURE__*/h.createElement(e,x({ref:r,name:n,label:i,rules:v},f)))});return i.displayName=n,i}(null!=n&&n.isControlled?V(t):O(t),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||I});return w[e]=a,a},P=D("text",r.Input),L=D("number",n.NumberInput,{isControlled:!0}),j=D("password",a.PasswordInput),q=D("textarea",r.Textarea),B=D("switch",r.forwardRef(function(e,t){var n=e.label,a=b(e,k);/*#__PURE__*/return h.createElement(r.Switch,x({ref:t},a),n)}),{isControlled:!0,hideLabel:!0}),M=D("select",o.Select,{isControlled:!0}),T=D("checkbox",r.forwardRef(function(e,t){var n=e.label,a=b(e,R);/*#__PURE__*/return h.createElement(r.Checkbox,x({ref:t},a),n)}),{hideLabel:!0}),U=D("radio",l.RadioInput,{isControlled:!0}),H=D("pin",i.PinInput,{isControlled:!0}),G=D("native-select",o.NativeSelect,{isControlled:!0}),z=function(e){return e&&Object.entries(e).map(function(e){return x({},e[1],{name:e[0]})})},W=function(e){return{getFields:function(){return z(e)},getNestedFields:function(t){var r,n=s.get(e,t);return n?"object"===(null==(r=n.items)?void 0:r.type)?z(n.items.properties):"object"===n.type?z(n.properties):[n.items]:[]}}},J=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],K=r.forwardRef(function(e,n){var a=e.mode,l=void 0===a?"all":a,i=e.resolver,o=e.reValidateMode,s=e.shouldFocusError,u=e.shouldUnregister,c=e.shouldUseNativeValidation,m=e.criteriaMode,d=e.delayError,p=e.schema,f=e.defaultValues,v=e.onSubmit,E=e.onError,y=e.formRef,F=e.children,S=b(e,J),_={mode:l,resolver:i,defaultValues:f,reValidateMode:o,shouldFocusError:s,shouldUnregister:u,shouldUseNativeValidation:c,criteriaMode:m,delayError:d};p&&!i&&(_.resolver=null==K.getResolver?void 0:K.getResolver(p));var g=t.useForm(_),C=g.handleSubmit;return h.useImperativeHandle(n,function(){return g},[n,g]),/*#__PURE__*/h.createElement(t.FormProvider,g,/*#__PURE__*/h.createElement(r.chakra.form,x({ref:y,onSubmit:C(v,E)},S),F))});K.getFieldResolver=W;var Q=["children"],X=function(e){/*#__PURE__*/return h.createElement(r.chakra.div,null,e.children)},Y=function(e){var t,n,a,l=e.children,i=b(e,Q),o=x({},null!=(t=null==(n=r.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return h.createElement(r.SimpleGrid,o,h.Children.map(l,function(e){return h.isValidElement(e)?/*#__PURE__*/h.createElement(X,null,e):e}))},Z=function(e,t){return h.Children.map(t,function(t){return h.isValidElement(t)&&t.props.name?h.cloneElement(t,x({},t.props,{name:e+"."+t.props.name})):t})},$=d.createContext({name:"ArrayFieldContext"}),ee=$[0],te=$[1],re=d.createContext({name:"ArrayFieldRowContext"}),ne=re[0],ae=re[1],le=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,s=t.useFormContext();return x({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},ie=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=te(),l=a.name,i=a.remove,o=a.fields;return h.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:h.useCallback(function(){n(l),i(r)},[r])}},oe=function(){var e=ae(),t=e.isFirst,r=e.remove,n=te(),a=n.min;return{onClick:function(){return r()},isDisabled:t&&!!(a&&n.fields.length<=a)}},se=function(){var e=te(),t=e.append,r=e.defaultValue,n=e.max;return{onClick:function(){return t(r,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},ue=["children","columns","spacing"],ce=["children"],me=["name","defaultValue","keyName","min","max","children"],de=function(e){/*#__PURE__*/return h.createElement(fe,{index:e.index},/*#__PURE__*/h.createElement(pe,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/h.createElement(ve,null))},pe=function(e){var t=e.children,r=e.columns,n=e.spacing,a=b(e,ue),l=ae().name;/*#__PURE__*/return h.createElement(Y,x({flex:"1",columns:r,gridGap:n,mr:"2"},a),Z(l,t))},fe=function(e){var t=e.children,r=ie({index:e.index});/*#__PURE__*/return h.createElement(ne,{value:r},/*#__PURE__*/h.createElement(u.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},ve=function(e){/*#__PURE__*/return h.createElement(m.IconButton,x({icon:/*#__PURE__*/h.createElement(c.MinusIcon,null),"aria-label":"Remove row"},oe(),e))},he=function(e){/*#__PURE__*/return h.createElement(m.IconButton,x({icon:/*#__PURE__*/h.createElement(c.AddIcon,null),"aria-label":"Add row",float:"right"},se(),e))},xe=h.forwardRef(function(e,t){var r=e.children,n=b(e,ce);/*#__PURE__*/return h.createElement(Ee,x({ref:t},n),/*#__PURE__*/h.createElement(be,null,function(e){/*#__PURE__*/return h.createElement(h.Fragment,null,e.map(function(e,t){/*#__PURE__*/return h.createElement(de,{key:e.id,index:t},r)}))}),/*#__PURE__*/h.createElement(he,null))}),be=function(e){return(0,e.children)(te().fields)},Ee=h.forwardRef(function(e,t){var r=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=b(e,me),u=le({name:r,defaultValue:n,keyName:a,min:l,max:i});return h.useImperativeHandle(t,function(){return u},[t,u]),/*#__PURE__*/h.createElement(ee,{value:u},/*#__PURE__*/h.createElement(I,x({name:r},s),o))}),ye=["name","label","hideLabel","children","columns","spacing"],Fe=function(e){var t=r.useStyles();/*#__PURE__*/return h.createElement(r.FormLabel,x({as:"legend",sx:t.legend},e))},Se=function(e){var t=e.name,n=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=b(e,ye);/*#__PURE__*/return h.createElement(r.FormControl,x({name:t,as:"fieldset"},s),/*#__PURE__*/h.createElement(Fe,{display:a?"none":"block"},n),/*#__PURE__*/h.createElement(Y,{columns:i,gridGap:o},Z(t,l)))},_e=["name","type"],ge=["schema","fieldResolver"],Ce=["name","type","defaultValue"],Ne=function(e,t){var r;return null==(r=e.getNestedFields(t))?void 0:r.map(function(e,t){var r=e.name,n=e.type,a=b(e,_e);/*#__PURE__*/return h.createElement(A,x({key:r||t,name:r,type:n},a))})},ke=function(e){var t=e.schema,r=e.fieldResolver,n=b(e,ge),a=h.useMemo(function(){return r||K.getFieldResolver(t)},[t,r]);/*#__PURE__*/return h.createElement(Y,n,a.getFields().map(function(e){var t=e.name,r=e.type,n=b(e,Ce);return"array"===r?/*#__PURE__*/h.createElement(xe,x({key:t,name:t},n),Ne(a,t)):"object"===r?/*#__PURE__*/h.createElement(Se,x({key:t,name:t},n),Ne(a,t)):/*#__PURE__*/h.createElement(A,x({key:t,name:t,type:r},n))}))},Re=["children","disableIfUntouched","disableIfInvalid"],we=u.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=b(e,Re),o=t.useFormContext().formState;/*#__PURE__*/return h.createElement(m.Button,x({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});we.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var Ie=["schema","submitLabel","fieldResolver"],Ae=r.forwardRef(function(e,t){var r=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=b(e,Ie);/*#__PURE__*/return h.createElement(K,x({},i,{schema:r,ref:t}),/*#__PURE__*/h.createElement(Y,null,/*#__PURE__*/h.createElement(ke,{schema:r,fieldResolver:l}),a&&/*#__PURE__*/h.createElement(we,{label:a})))});function Ve(){return Ve=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Ve.apply(this,arguments)}function Oe(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var De=d.createContext({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"}),Pe=De[0],Le=De[1];function je(e){var t=e.step,r=h.useState(-1),n=r[0],a=r[1],l=h.useRef([]),i=h.useState(Date.now())[1],o=h.useCallback(function(e){var t=[].concat(l.current);-1===t.indexOf(e)&&t.push(e),l.current=t,i(Date.now())},[l,i]),s=function(e){var t=l.current.indexOf(e);-1!==t&&a(t)};return h.useLayoutEffect(function(){"string"==typeof t?s(t):"number"==typeof t?a(t):-1===n&&a(0)},[t]),{stepsRef:l,activeStep:l.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===l.current.length-1,isCompleted:n>=l.current.length,setIndex:a,setStep:s,nextStep:function(){a(n+1)},prevStep:function(){a(n-1)},registerStep:o,unregisterStep:function(e){l.current=l.current.slice(l.current.indexOf(e),1)}}}function qe(e){var t=e.name,r=e.isActive,n=e.isCompleted,a=Le(),l=a.registerStep,i=a.unregisterStep,o=a.activeStep;return h.useEffect(function(){if(t)return l(t),function(){i(t)}},[]),{isActive:t?o===t:r,isCompleted:n}}var Be=["children","orientation"],Me=["children","orientation","stepComponent"],Te=["children","isOpen"],Ue=["icon","isActive","isCompleted","className"],He=["title","icon","isActive","isCompleted"],Ge=["isActive"],ze=u.forwardRef(function(e,t){var r=u.useMultiStyleConfig("Stepper",e),n=u.omitThemingProps(e),a=n.children,l=n.orientation,i=Oe(n,Be),o=je(e),c=Ve({display:"flex",flexDirection:"column"},r.container);return h.createElement(u.StylesProvider,{value:r},/*#__PURE__*/h.createElement(Pe,{value:o},/*#__PURE__*/h.createElement(u.chakra.div,Ve({ref:t,__css:c},i,{className:s.cx("saas-stepper__container",e.className)}),/*#__PURE__*/h.createElement(We,{orientation:l},a))))});s.__DEV__&&(ze.displayName="Stepper");var We=function(e){var t,r,n=e.children,a=e.orientation,l=e.stepComponent,i=Oe(e,Me),o=u.useStyles(),c=Le().activeIndex,m=Ve({display:"flex",flexDirection:"row",alignItems:"center"},o.steps),d="vertical"===a,f=l||Qe,v=p.getChildrenOfType(n,f),x=v.reduce(function(e,t,r,n){return e.push(/*#__PURE__*/h.createElement(f,Ve({key:r},t.props,{icon:t.props.icon||r+1,isActive:c===r,isCompleted:t.props.isCompleted||c>r}))),"vertical"===a&&e.push(/*#__PURE__*/h.createElement(Je,{key:"content-"+r,isOpen:c===r},t.props.children)),r<n.length-1&&e.push(/*#__PURE__*/h.createElement(Xe,{key:"separator-"+r,isActive:r<c})),e},[]),b=p.getChildOfType(n,Ze),E=c>=v.length?b:d?null:/*#__PURE__*/h.createElement(Je,null,null==(t=v[c])||null==(r=t.props)?void 0:r.children);return h.createElement(h.Fragment,null,/*#__PURE__*/h.createElement(u.chakra.div,Ve({__css:m},i,{className:s.cx("saas-stepper__steps",e.className)}),x),E)};s.__DEV__&&(We.displayName="StepperSteps");var Je=function(e){var t=e.children,n=e.isOpen,a=void 0===n||n,l=Oe(e,Te),i=u.useStyles();return h.createElement(u.chakra.div,Ve({__css:i.content},l,{className:s.cx("saas-stepper__content",e.className)}),/*#__PURE__*/h.createElement(r.Collapse,{in:a},t))};s.__DEV__&&(Je.displayName="StepperContent");var Ke=function(e){var t,r=e.icon,n=e.isCompleted,a=e.className,l=Oe(e,Ue),i=Ve({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},u.useStyles().icon);return t=n?/*#__PURE__*/h.createElement(c.Icon,{as:c.CheckIcon}):r,/*#__PURE__*/h.createElement(u.chakra.div,Ve({__css:i},l,{className:s.cx("saas-stepper__icon",a)}),t)};s.__DEV__&&(Ke.displayName="StepperIcon");var Qe=function(e){var t=e.title,r=e.icon,n=e.isActive,a=e.isCompleted,l=Oe(e,He),i=qe(e),o=Ve({display:"flex",alignItems:"center",flexDirection:"row"},u.useStyles().step);return h.createElement(u.chakra.div,Ve({__css:o,"data-active":i.isActive,"data-completed":i.isCompleted},l,{className:s.cx("saas-stepper__step",e.className)}),/*#__PURE__*/h.createElement(Ke,{icon:r,isActive:n,isCompleted:a}),t&&/*#__PURE__*/h.createElement(Ye,null,t))};s.__DEV__&&(Qe.displayName="StepperStep");var Xe=function(e){var t=e.isActive,r=Oe(e,Ge),n=Ve({flex:1,borderTopWidth:"1px",mx:2},u.useStyles().separator);return h.createElement(u.chakra.div,Ve({"data-active":t},r,{className:s.cx("saas-stepper__separator",e.className),__css:n}))};s.__DEV__&&(Xe.displayName="StepperSeparator");var Ye=function(e){var t=u.useStyles();return h.createElement(u.chakra.p,Ve({},e,{__css:t.title,className:s.cx("saas-stepper__title",e.className)}))};s.__DEV__&&(Ye.displayName="StepperStepTitle");var Ze=function(e){var t=u.useStyles();return h.createElement(u.chakra.div,Ve({__css:t.completed},e,{className:s.cx("saas-stepper__completed",e.className)}))};s.__DEV__&&(Ze.displayName="StepperCompleted");var $e=d.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),et=$e[0],tt=$e[1];function rt(e){var t=je(e),r=t.activeStep,n=t.isLastStep,a=t.nextStep,l=h.useState({}),i=l[0],o=l[1],s=h.useCallback(function(t){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(t).then(function(){c(x({},i[r],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[r,n]),u=h.useCallback(function(e){var t=i[r];return{onSubmit:s,schema:null==t?void 0:t.schema,resolver:null==t?void 0:t.resolver}},[i,s,r]),c=h.useCallback(function(e){o(function(t){var r;return x({},t,((r={})[e.name]=e,r))})},[i]);return x({getFormProps:u,updateStep:c,steps:i},t)}function nt(e){var t=e.name,r=e.schema,n=e.resolver,a=qe({name:t}),l=tt(),i=l.steps,o=l.updateStep;return h.useEffect(function(){o({name:t,schema:r,resolver:n})},[t,r]),x({},a,i[t]||{name:t,schema:r})}var at=["children","onSubmit"],lt=["getFormProps"],it=["name","schema","resolver","children","className"],ot=["label","submitLabel"],st=h.forwardRef(function(e,t){var r=e.children,n=b(e,at),a=rt(e),l=a.getFormProps,i=b(a,lt),o=h.useMemo(function(){return i},[i]);/*#__PURE__*/return h.createElement(Pe,{value:o},/*#__PURE__*/h.createElement(et,{value:o},/*#__PURE__*/h.createElement(K,x({ref:t},n,l(e)),s.runIfFn(r,a))))}),ut=function(e){var t=e.name,r=e.schema,n=e.resolver,a=e.children,l=e.className,i=b(e,it);return nt({name:t,schema:r,resolver:n}).isActive?/*#__PURE__*/h.createElement(u.chakra.div,x({},i,{className:s.cx("saas-form__step",l)}),a):null};s.__DEV__&&(ut.displayName="FormStep");var ct=function(e){var t=Le(),r=t.prevStep;/*#__PURE__*/return h.createElement(m.Button,x({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:s.cx("saas-form__prev-button",e.className),onClick:s.callAllHandlers(e.onClick,r)}))};s.__DEV__&&(ct.displayName="PrevButton");var mt=function(e){var t=e.label,r=void 0===t?"Next":t,n=e.submitLabel,a=void 0===n?"Complete":n,l=b(e,ot),i=Le(),o=i.isCompleted;/*#__PURE__*/return h.createElement(we,x({isDisabled:o,label:i.isLastStep||o?a:r},l,{className:s.cx("saas-form__next-button",e.className)}))};s.__DEV__&&(mt.displayName="NextButton"),exports.ArrayField=xe,exports.ArrayFieldAddButton=he,exports.ArrayFieldContainer=Ee,exports.ArrayFieldProvider=ee,exports.ArrayFieldRemoveButton=ve,exports.ArrayFieldRow=de,exports.ArrayFieldRowContainer=fe,exports.ArrayFieldRowFields=pe,exports.ArrayFieldRowProvider=ne,exports.ArrayFieldRows=be,exports.AutoForm=Ae,exports.BaseField=I,exports.CheckboxField=T,exports.DisplayField=function(e){var t=e.name,n=e.label,a=b(e,E);/*#__PURE__*/return h.createElement(r.FormControl,a,n?/*#__PURE__*/h.createElement(r.FormLabel,{htmlFor:t},n):null,/*#__PURE__*/h.createElement(r.Text,{fontSize:"md"},/*#__PURE__*/h.createElement(y,{name:t})))},exports.DisplayIf=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null},exports.Field=A,exports.Fields=ke,exports.Form=K,exports.FormLayout=Y,exports.FormLegend=Fe,exports.FormStep=ut,exports.FormStepper=function(e){var t=u.useMultiStyleConfig("Stepper",e),r=h.Children.map(e.children,function(e){if(h.isValidElement(e)&&(null==e?void 0:e.type)===ut){var t=nt(e.props);/*#__PURE__*/return h.createElement(Qe,{name:e.props.name,title:e.props.title,isCompleted:t.isCompleted},e.props.children)}return e});/*#__PURE__*/return h.createElement(u.StylesProvider,{value:t},/*#__PURE__*/h.createElement(We,x({mb:"4"},e),r))},exports.FormValue=y,exports.InputField=P,exports.NativeSelectField=G,exports.NextButton=mt,exports.NumberInputField=L,exports.ObjectField=Se,exports.PasswordInputFIeld=j,exports.PinField=H,exports.PrevButton=ct,exports.RadioField=U,exports.SelectField=M,exports.StepForm=st,exports.StepFormProvider=et,exports.SubmitButton=we,exports.SwitchField=B,exports.TextareaField=q,exports.objectFieldResolver=W,exports.registerFieldType=D,exports.useArrayField=le,exports.useArrayFieldAddButton=se,exports.useArrayFieldContext=te,exports.useArrayFieldRemoveButton=oe,exports.useArrayFieldRow=ie,exports.useArrayFieldRowContext=ae,exports.useFormStep=nt,exports.useStepForm=rt,exports.useStepFormContext=tt,exports.withControlledInput=V,exports.withUncontrolledInput=O,Object.keys(f).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return f[e]}})});
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/field-resolver.ts","../src/fields.tsx","../src/form.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../../saas-ui-stepper/dist/index.modern.js","../src/use-step-form.tsx","../src/step-form.tsx","../src/display-if.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">\n <FormValue name={name} />\n </Text>\n </FormControl>\n )\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\nimport { FocusableElement } from '@chakra-ui/utils'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<FocusableElement>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses a different 'id' field\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n UseArrayFieldReturn,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField = React.forwardRef(\n (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer ref={ref} {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n }\n)\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer = React.forwardRef(\n (\n {\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n }: ArrayFieldProps,\n ref: React.ForwardedRef<UseArrayFieldReturn>\n ) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n // This exposes the useArrayField api through the forwarded ref\n React.useImperativeHandle(ref, () => context, [ref, context])\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n }\n)\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyles()\n return <FormLabel as=\"legend\" sx={styles.legend} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\n// @todo finalize this\nexport type FormSchema = Record<string, any>\n\nconst mapFields = (schema: FormSchema) =>\n Object.entries(schema).map(([name, field]) => {\n return {\n name,\n ...field,\n }\n })\n\nexport const defaultFieldResolver = (schema: FormSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\nimport { defaultFieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || defaultFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n} from 'react-hook-form'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\n\ninterface AutoFormOptions {\n submitLabel?: false | string\n schema: any\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', fieldResolver, ...rest } = props\n\n return (\n <Form {...rest} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import*as e from\"react\";import{forwardRef as t,useMultiStyleConfig as s,omitThemingProps as r,StylesProvider as n,chakra as a,useStyles as i}from\"@chakra-ui/system\";import{Icon as c,CheckIcon as p}from\"@chakra-ui/icons\";import{Collapse as l}from\"@saas-ui/collapse\";import{getChildrenOfType as o,getChildOfType as m}from\"@saas-ui/react-utils\";import{cx as u,__DEV__ as d}from\"@chakra-ui/utils\";import{createContext as f}from\"@chakra-ui/react-utils\";function v(){return v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e},v.apply(this,arguments)}function S(e,t){if(null==e)return{};var s,r,n={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(s=a[r])>=0||(n[s]=e[s]);return n}const[_,N]=f({name:\"StepperContext\",errorMessage:\"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`\"});function h(t){const{step:s}=t,[r,n]=e.useState(-1),a=e.useRef([]),[,i]=e.useState(Date.now()),c=e.useCallback(e=>{const t=[...a.current];-1===t.indexOf(e)&&t.push(e),a.current=t,i(Date.now())},[a,i]),p=e=>{const t=a.current.indexOf(e);-1!==t&&n(t)};return e.useLayoutEffect(()=>{\"string\"==typeof s?p(s):\"number\"==typeof s?n(s):-1===r&&n(0)},[s]),{stepsRef:a,activeStep:a.current[r],activeIndex:r,isFirstStep:0===r,isLastStep:r===a.current.length-1,isCompleted:r>=a.current.length,setIndex:n,setStep:p,nextStep:()=>{n(r+1)},prevStep:()=>{n(r-1)},registerStep:c,unregisterStep:e=>{a.current=a.current.slice(a.current.indexOf(e),1)}}}function y(t){const{name:s,isActive:r,isCompleted:n}=t,{registerStep:a,unregisterStep:i,activeStep:c}=N();return e.useEffect(()=>{if(s)return a(s),()=>{i(s)}},[]),{isActive:s?c===s:r,isCompleted:n}}function x({label:e=\"Back\"}={}){const{isFirstStep:t,prevStep:s}=N();return{isDisabled:t,onClick:s,label:e}}function C({label:e=\"Next\",submitLabel:t=\"Submit\"}={}){const{isLastStep:s,isCompleted:r,nextStep:n}=N();return{isDisabled:r,onClick:n,label:s?t:e}}const E=[\"children\",\"orientation\"],g=[\"children\",\"orientation\",\"stepComponent\"],b=[\"children\",\"isOpen\"],k=[\"icon\",\"isActive\",\"isCompleted\",\"className\"],A=[\"title\",\"icon\",\"isActive\",\"isCompleted\"],O=[\"isActive\"],D=t((t,i)=>{const c=s(\"Stepper\",t),p=r(t),{children:l,orientation:o}=p,m=S(p,E),d=h(t),f=v({display:\"flex\",flexDirection:\"column\"},c.container);/*#__PURE__*/return e.createElement(n,{value:c},/*#__PURE__*/e.createElement(_,{value:d},/*#__PURE__*/e.createElement(a.div,v({ref:i,__css:f},m,{className:u(\"saas-stepper__container\",t.className)}),/*#__PURE__*/e.createElement(I,{orientation:o},l))))});d&&(D.displayName=\"Stepper\");const I=t=>{var s,r;const{children:n,orientation:c,stepComponent:p}=t,l=S(t,g),d=i(),{activeIndex:f}=N(),_=v({display:\"flex\",flexDirection:\"row\",alignItems:\"center\"},d.steps),h=\"vertical\"===c,y=p||L,x=o(n,y),C=x.reduce((t,s,r,n)=>(t.push(/*#__PURE__*/e.createElement(y,v({key:r},s.props,{icon:s.props.icon||r+1,isActive:f===r,isCompleted:s.props.isCompleted||f>r}))),\"vertical\"===c&&t.push(/*#__PURE__*/e.createElement(w,{key:`content-${r}`,isOpen:f===r},s.props.children)),r<n.length-1&&t.push(/*#__PURE__*/e.createElement(F,{key:`separator-${r}`,isActive:r<f})),t),[]),E=m(n,T),b=f>=x.length?E:h?null:/*#__PURE__*/e.createElement(w,null,null==(s=x[f])||null==(r=s.props)?void 0:r.children);/*#__PURE__*/return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(a.div,v({__css:_},l,{className:u(\"saas-stepper__steps\",t.className)}),C),b)};d&&(I.displayName=\"StepperSteps\");const w=t=>{const{children:s,isOpen:r=!0}=t,n=S(t,b),c=i();/*#__PURE__*/return e.createElement(a.div,v({__css:c.content},n,{className:u(\"saas-stepper__content\",t.className)}),/*#__PURE__*/e.createElement(l,{in:r},s))};d&&(w.displayName=\"StepperContent\");const j=t=>{const{icon:s,isCompleted:r,className:n}=t,l=S(t,k),o=v({display:\"flex\",alignItems:\"center\",justifyContent:\"center\",borderRadius:\"full\",fontSize:\"1em\",me:2},i().icon);let m;return m=r?/*#__PURE__*/e.createElement(c,{as:p}):s,/*#__PURE__*/e.createElement(a.div,v({__css:o},l,{className:u(\"saas-stepper__icon\",n)}),m)};d&&(j.displayName=\"StepperIcon\");const L=t=>{const{title:s,icon:r,isActive:n,isCompleted:c}=t,p=S(t,A),l=y(t),o=v({display:\"flex\",alignItems:\"center\",flexDirection:\"row\"},i().step);/*#__PURE__*/return e.createElement(a.div,v({__css:o,\"data-active\":l.isActive,\"data-completed\":l.isCompleted},p,{className:u(\"saas-stepper__step\",t.className)}),/*#__PURE__*/e.createElement(j,{icon:r,isActive:n,isCompleted:c}),s&&/*#__PURE__*/e.createElement(R,null,s))};d&&(L.displayName=\"StepperStep\");const F=t=>{const{isActive:s}=t,r=S(t,O),n=v({flex:1,borderTopWidth:\"1px\",mx:2},i().separator);/*#__PURE__*/return e.createElement(a.div,v({\"data-active\":s},r,{className:u(\"saas-stepper__separator\",t.className),__css:n}))};d&&(F.displayName=\"StepperSeparator\");const R=t=>{const s=i();/*#__PURE__*/return e.createElement(a.p,v({},t,{__css:s.title,className:u(\"saas-stepper__title\",t.className)}))};d&&(R.displayName=\"StepperStepTitle\");const T=t=>{const s=i();/*#__PURE__*/return e.createElement(a.div,v({__css:s.completed},t,{className:u(\"saas-stepper__completed\",t.className)}))};d&&(T.displayName=\"StepperCompleted\");export{D as Stepper,T as StepperCompleted,w as StepperContent,j as StepperIcon,_ as StepperProvider,F as StepperSeparator,L as StepperStep,R as StepperStepTitle,I as StepperSteps,C as useNext,x as usePrev,y as useStep,h as useStepper,N as useStepperContext};\n//# sourceMappingURL=index.modern.js.map\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler } from 'react-hook-form'\nimport { createContext } from '@chakra-ui/react-utils'\nimport {\n useStepper,\n useStep,\n UseStepperProps,\n UseStepperReturn,\n} from '@saas-ui/stepper'\n\nexport interface StepState {\n name: string\n schema?: any\n resolver?: any\n isActive?: boolean\n isCompleted?: boolean\n}\n\nexport interface StepFormContext extends UseStepperReturn {\n updateStep(state: StepState): void\n steps: Record<string, StepState>\n}\n\nexport const [StepFormProvider, useStepFormContext] =\n createContext<StepFormContext>({\n name: 'StepFormContext',\n errorMessage:\n 'useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`',\n })\n\nimport { FormProps } from './form'\n\nexport interface UseStepFormProps<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperProps,\n FormProps<TFieldValues> {}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n) {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(\n (props) => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n },\n [steps, onSubmitStep, activeStep]\n )\n\n const updateStep = React.useCallback(\n (step) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport type UseStepFormReturn = ReturnType<typeof useStepForm>\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {\n chakra,\n HTMLChakraProps,\n useMultiStyleConfig,\n StylesProvider,\n} from '@chakra-ui/system'\n\nimport { callAllHandlers, runIfFn, cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n StepperProvider,\n StepperSteps,\n StepperStepsProps,\n StepperStep,\n useStepperContext,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form, FormProps } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues>,\n FormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps(props)}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const styles = useMultiStyleConfig('Stepper', props)\n\n const { children } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n return (\n <StylesProvider value={styles}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StylesProvider>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, ...rest } = props\n const step = useFormStep({ name, schema, resolver })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n"],"names":["FormValue","name","getValues","useFormContext","inputTypes","BaseField","props","label","help","variant","hideLabel","children","controlProps","error","formState","get","errors","getError","React","FormControl","isInvalid","FormLabel","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","withControlledInput","InputComponent","rules","inputProps","Controller","control","render","field","_ref","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","FormLayoutItem","chakra","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","id","fieldProps","useImperativeHandle","FormLegend","styles","useStyles","as","sx","legend","ObjectField","mapFields","schema","Object","entries","defaultFieldResolver","getFields","getNestedFields","items","properties","resolver","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","Form","mode","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","methods","useForm","handleSubmit","FormProvider","form","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","errorMessage","StepperProvider","useStepperContext","useStepper","step","useState","activeIndex","setIndex","stepsRef","useRef","onUpdate","Date","now","registerStep","newSteps","current","indexOf","push","setStep","useLayoutEffect","activeStep","isFirstStep","isLastStep","isCompleted","nextStep","prevStep","unregisterStep","useStep","isActive","StepFormProvider","useStepFormContext","useStepForm","stepper","steps","updateSteps","onSubmitStep","data","then","updateStep","getFormProps","useFormStep","StepForm","ctx","runIfFn","FormStep","className","cx","__DEV__","PrevButton","callAllHandlers","NextButton","htmlFor","Text","fontSize","condition","useWatch","disabled","exact","isExact","useMultiStyle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3E,gBAAC2P,kBAAexI,MAAOsB,gBACrBzI,gBAAC4P,MAAanI,GAAG,KAAQrI,GACtBoQ"}
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../../saas-ui-stepper/dist/index.modern.js","../src/use-step-form.tsx","../src/step-form.tsx","../src/display-if.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">\n <FormValue name={name} />\n </Text>\n </FormControl>\n )\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\nimport { FocusableElement } from '@chakra-ui/utils'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<FocusableElement>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema) =>\n schema &&\n Object.entries(schema).map(([name, field]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses a different 'id' field\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n UseArrayFieldReturn,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField = React.forwardRef(\n (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer ref={ref} {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n }\n)\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer = React.forwardRef(\n (\n {\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n }: ArrayFieldProps,\n ref: React.ForwardedRef<UseArrayFieldReturn>\n ) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n // This exposes the useArrayField api through the forwarded ref\n React.useImperativeHandle(ref, () => context, [ref, context])\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n }\n)\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyles()\n return <FormLabel as=\"legend\" sx={styles.legend} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n","import * as React from 'react'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n submitLabel?: false | string\n schema: any\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', fieldResolver, ...rest } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & { getFieldResolver?: (schema: any) => FieldResolver }\n","import*as e from\"react\";import{forwardRef as t,useMultiStyleConfig as s,omitThemingProps as r,StylesProvider as n,chakra as a,useStyles as i}from\"@chakra-ui/system\";import{Icon as c,CheckIcon as p}from\"@chakra-ui/icons\";import{Collapse as l}from\"@saas-ui/collapse\";import{getChildrenOfType as o,getChildOfType as m}from\"@saas-ui/react-utils\";import{cx as u,__DEV__ as d}from\"@chakra-ui/utils\";import{createContext as f}from\"@chakra-ui/react-utils\";function v(){return v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e},v.apply(this,arguments)}function S(e,t){if(null==e)return{};var s,r,n={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(s=a[r])>=0||(n[s]=e[s]);return n}const[_,N]=f({name:\"StepperContext\",errorMessage:\"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`\"});function h(t){const{step:s}=t,[r,n]=e.useState(-1),a=e.useRef([]),[,i]=e.useState(Date.now()),c=e.useCallback(e=>{const t=[...a.current];-1===t.indexOf(e)&&t.push(e),a.current=t,i(Date.now())},[a,i]),p=e=>{const t=a.current.indexOf(e);-1!==t&&n(t)};return e.useLayoutEffect(()=>{\"string\"==typeof s?p(s):\"number\"==typeof s?n(s):-1===r&&n(0)},[s]),{stepsRef:a,activeStep:a.current[r],activeIndex:r,isFirstStep:0===r,isLastStep:r===a.current.length-1,isCompleted:r>=a.current.length,setIndex:n,setStep:p,nextStep:()=>{n(r+1)},prevStep:()=>{n(r-1)},registerStep:c,unregisterStep:e=>{a.current=a.current.slice(a.current.indexOf(e),1)}}}function y(t){const{name:s,isActive:r,isCompleted:n}=t,{registerStep:a,unregisterStep:i,activeStep:c}=N();return e.useEffect(()=>{if(s)return a(s),()=>{i(s)}},[]),{isActive:s?c===s:r,isCompleted:n}}function x({label:e=\"Back\"}={}){const{isFirstStep:t,prevStep:s}=N();return{isDisabled:t,onClick:s,label:e}}function C({label:e=\"Next\",submitLabel:t=\"Submit\"}={}){const{isLastStep:s,isCompleted:r,nextStep:n}=N();return{isDisabled:r,onClick:n,label:s?t:e}}const E=[\"children\",\"orientation\"],g=[\"children\",\"orientation\",\"stepComponent\"],b=[\"children\",\"isOpen\"],k=[\"icon\",\"isActive\",\"isCompleted\",\"className\"],A=[\"title\",\"icon\",\"isActive\",\"isCompleted\"],O=[\"isActive\"],D=t((t,i)=>{const c=s(\"Stepper\",t),p=r(t),{children:l,orientation:o}=p,m=S(p,E),d=h(t),f=v({display:\"flex\",flexDirection:\"column\"},c.container);/*#__PURE__*/return e.createElement(n,{value:c},/*#__PURE__*/e.createElement(_,{value:d},/*#__PURE__*/e.createElement(a.div,v({ref:i,__css:f},m,{className:u(\"saas-stepper__container\",t.className)}),/*#__PURE__*/e.createElement(I,{orientation:o},l))))});d&&(D.displayName=\"Stepper\");const I=t=>{var s,r;const{children:n,orientation:c,stepComponent:p}=t,l=S(t,g),d=i(),{activeIndex:f}=N(),_=v({display:\"flex\",flexDirection:\"row\",alignItems:\"center\"},d.steps),h=\"vertical\"===c,y=p||L,x=o(n,y),C=x.reduce((t,s,r,n)=>(t.push(/*#__PURE__*/e.createElement(y,v({key:r},s.props,{icon:s.props.icon||r+1,isActive:f===r,isCompleted:s.props.isCompleted||f>r}))),\"vertical\"===c&&t.push(/*#__PURE__*/e.createElement(w,{key:`content-${r}`,isOpen:f===r},s.props.children)),r<n.length-1&&t.push(/*#__PURE__*/e.createElement(F,{key:`separator-${r}`,isActive:r<f})),t),[]),E=m(n,T),b=f>=x.length?E:h?null:/*#__PURE__*/e.createElement(w,null,null==(s=x[f])||null==(r=s.props)?void 0:r.children);/*#__PURE__*/return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(a.div,v({__css:_},l,{className:u(\"saas-stepper__steps\",t.className)}),C),b)};d&&(I.displayName=\"StepperSteps\");const w=t=>{const{children:s,isOpen:r=!0}=t,n=S(t,b),c=i();/*#__PURE__*/return e.createElement(a.div,v({__css:c.content},n,{className:u(\"saas-stepper__content\",t.className)}),/*#__PURE__*/e.createElement(l,{in:r},s))};d&&(w.displayName=\"StepperContent\");const j=t=>{const{icon:s,isCompleted:r,className:n}=t,l=S(t,k),o=v({display:\"flex\",alignItems:\"center\",justifyContent:\"center\",borderRadius:\"full\",fontSize:\"1em\",me:2},i().icon);let m;return m=r?/*#__PURE__*/e.createElement(c,{as:p}):s,/*#__PURE__*/e.createElement(a.div,v({__css:o},l,{className:u(\"saas-stepper__icon\",n)}),m)};d&&(j.displayName=\"StepperIcon\");const L=t=>{const{title:s,icon:r,isActive:n,isCompleted:c}=t,p=S(t,A),l=y(t),o=v({display:\"flex\",alignItems:\"center\",flexDirection:\"row\"},i().step);/*#__PURE__*/return e.createElement(a.div,v({__css:o,\"data-active\":l.isActive,\"data-completed\":l.isCompleted},p,{className:u(\"saas-stepper__step\",t.className)}),/*#__PURE__*/e.createElement(j,{icon:r,isActive:n,isCompleted:c}),s&&/*#__PURE__*/e.createElement(R,null,s))};d&&(L.displayName=\"StepperStep\");const F=t=>{const{isActive:s}=t,r=S(t,O),n=v({flex:1,borderTopWidth:\"1px\",mx:2},i().separator);/*#__PURE__*/return e.createElement(a.div,v({\"data-active\":s},r,{className:u(\"saas-stepper__separator\",t.className),__css:n}))};d&&(F.displayName=\"StepperSeparator\");const R=t=>{const s=i();/*#__PURE__*/return e.createElement(a.p,v({},t,{__css:s.title,className:u(\"saas-stepper__title\",t.className)}))};d&&(R.displayName=\"StepperStepTitle\");const T=t=>{const s=i();/*#__PURE__*/return e.createElement(a.div,v({__css:s.completed},t,{className:u(\"saas-stepper__completed\",t.className)}))};d&&(T.displayName=\"StepperCompleted\");export{D as Stepper,T as StepperCompleted,w as StepperContent,j as StepperIcon,_ as StepperProvider,F as StepperSeparator,L as StepperStep,R as StepperStepTitle,I as StepperSteps,C as useNext,x as usePrev,y as useStep,h as useStepper,N as useStepperContext};\n//# sourceMappingURL=index.modern.js.map\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler } from 'react-hook-form'\nimport { createContext } from '@chakra-ui/react-utils'\nimport {\n useStepper,\n useStep,\n UseStepperProps,\n UseStepperReturn,\n} from '@saas-ui/stepper'\n\nexport interface StepState {\n name: string\n schema?: any\n resolver?: any\n isActive?: boolean\n isCompleted?: boolean\n}\n\nexport interface StepFormContext extends UseStepperReturn {\n updateStep(state: StepState): void\n steps: Record<string, StepState>\n}\n\nexport const [StepFormProvider, useStepFormContext] =\n createContext<StepFormContext>({\n name: 'StepFormContext',\n errorMessage:\n 'useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`',\n })\n\nimport { FormProps } from './form'\n\nexport interface UseStepFormProps<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperProps,\n FormProps<TFieldValues> {}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n) {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(\n (props) => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n },\n [steps, onSubmitStep, activeStep]\n )\n\n const updateStep = React.useCallback(\n (step) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport type UseStepFormReturn = ReturnType<typeof useStepForm>\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {\n chakra,\n HTMLChakraProps,\n useMultiStyleConfig,\n StylesProvider,\n} from '@chakra-ui/system'\n\nimport { callAllHandlers, runIfFn, cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n StepperProvider,\n StepperSteps,\n StepperStepsProps,\n StepperStep,\n useStepperContext,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form, FormProps } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues>,\n FormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps(props)}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const styles = useMultiStyleConfig('Stepper', props)\n\n const { children } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n return (\n <StylesProvider value={styles}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StylesProvider>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, ...rest } = props\n const step = useFormStep({ name, schema, resolver })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n"],"names":["FormValue","name","getValues","useFormContext","inputTypes","BaseField","props","label","help","variant","hideLabel","children","controlProps","error","formState","get","errors","getError","React","FormControl","isInvalid","FormLabel","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","withControlledInput","InputComponent","rules","inputProps","Controller","control","render","field","_ref","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","getFieldResolver","FormLayoutItem","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","id","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","errorMessage","StepperProvider","useStepperContext","useStepper","step","useState","activeIndex","setIndex","stepsRef","useRef","onUpdate","Date","now","registerStep","newSteps","current","indexOf","push","setStep","useLayoutEffect","activeStep","isFirstStep","isLastStep","isCompleted","nextStep","prevStep","unregisterStep","useStep","isActive","StepFormProvider","useStepFormContext","useStepForm","stepper","steps","updateSteps","onSubmitStep","data","then","updateStep","getFormProps","useFormStep","StepForm","ctx","runIfFn","FormStep","className","cx","__DEV__","PrevButton","callAllHandlers","NextButton","htmlFor","Text","fontSize","condition","useWatch","disabled","exact","isExact","useMultiStyleConfig","elements","StepperStep","title","StylesProvider","StepperSteps"],"mappings":"ynCAgCaA,EAAwC,gBAAGC,IAAAA,KAEtD,OAAOC,EADeC,mBAAdD,WACSD,IAAS,kPC8EtBG,EAAsC,GAmB/BC,EAAkC,SAACC,GAC9C,IAAQL,EACNK,EADML,KAAMM,EACZD,EADYC,MAAOC,EACnBF,EADmBE,K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