@saas-ui/forms 0.5.3 → 0.6.0-next.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +32 -0
- package/dist/auto-form.d.ts +2 -1
- package/dist/auto-form.d.ts.map +1 -1
- package/dist/field-resolver.d.ts +8 -0
- package/dist/field-resolver.d.ts.map +1 -0
- package/dist/fields.d.ts +2 -0
- package/dist/fields.d.ts.map +1 -1
- package/dist/form.d.ts +3 -3
- package/dist/form.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.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/step-form.d.ts +4 -0
- package/dist/step-form.d.ts.map +1 -1
- package/dist/use-step-form.d.ts +3 -0
- package/dist/use-step-form.d.ts.map +1 -1
- package/package.json +20 -13
- package/src/auto-form.tsx +6 -5
- package/src/field-resolver.ts +39 -0
- package/src/fields.tsx +45 -30
- package/src/form.tsx +5 -12
- package/src/index.ts +1 -1
- package/src/step-form.tsx +6 -2
- package/src/use-step-form.tsx +5 -2
- package/yup/package.json +17 -0
- package/dist/resolvers/yup.d.ts +0 -12
- package/dist/resolvers/yup.d.ts.map +0 -1
- package/src/resolvers/yup.ts +0 -79
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,37 @@
|
|
1
1
|
# @saas-ui/forms
|
2
2
|
|
3
|
+
## 0.6.0-next.0
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- 9391c44: BREAKING: Removed yup dependency from forms and fixed peer dependency issues.
|
8
|
+
|
9
|
+
<Form> doesn't accept a Yup `schema` any more by default.
|
10
|
+
|
11
|
+
Use a schema resolver to use schema support. All hookform resolvers are supported.
|
12
|
+
|
13
|
+
```
|
14
|
+
import {yupResolver} from '@hookform/resolvers/yup'
|
15
|
+
|
16
|
+
<Form resolver={yupResolver(schema)} />
|
17
|
+
```
|
18
|
+
|
19
|
+
AutoForm only supports Yup for now and has a new API.
|
20
|
+
|
21
|
+
```
|
22
|
+
import { yupForm } from '@saas-ui/forms/yup'
|
23
|
+
|
24
|
+
<AutoForm {...yupForm(schema)} />
|
25
|
+
```
|
26
|
+
|
27
|
+
### Patch Changes
|
28
|
+
|
29
|
+
- Updated dependencies [9391c44]
|
30
|
+
- @saas-ui/button@0.4.0-next.0
|
31
|
+
- @saas-ui/select@0.4.0-next.0
|
32
|
+
- @saas-ui/input-right-button@0.3.1-next.0
|
33
|
+
- @saas-ui/password-input@0.3.1-next.0
|
34
|
+
|
3
35
|
## 0.5.3
|
4
36
|
|
5
37
|
### Patch Changes
|
package/dist/auto-form.d.ts
CHANGED
@@ -2,8 +2,9 @@ import * as React from 'react';
|
|
2
2
|
import { FieldValues, UseFormReturn } from 'react-hook-form';
|
3
3
|
import { FormProps } from './form';
|
4
4
|
interface AutoFormOptions {
|
5
|
-
schema: any;
|
6
5
|
submitLabel?: false | string;
|
6
|
+
schema: any;
|
7
|
+
fieldResolver?: any;
|
7
8
|
}
|
8
9
|
export interface AutoFormProps<TFieldValues extends FieldValues> extends Omit<FormProps<TFieldValues>, 'schema'>, AutoFormOptions {
|
9
10
|
}
|
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;AAKxC,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,CAAA"}
|
@@ -0,0 +1,8 @@
|
|
1
|
+
import { FieldProps } from './field';
|
2
|
+
export declare type FieldResolver = {
|
3
|
+
getFields(): FieldProps[];
|
4
|
+
getNestedFields(name: string): FieldProps[];
|
5
|
+
};
|
6
|
+
export declare type FormSchema = Record<string, any>;
|
7
|
+
export declare const defaultFieldResolver: (schema: FormSchema) => FieldResolver;
|
8
|
+
//# sourceMappingURL=field-resolver.d.ts.map
|
@@ -0,0 +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;AAGD,oBAAY,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;AAU5C,eAAO,MAAM,oBAAoB,WAAY,UAAU,KAAG,aAkBzD,CAAA"}
|
package/dist/fields.d.ts
CHANGED
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;AAO9B,OAAO,EAAE,aAAa,EAAE,MAAM,kBAAkB,CAAA;AAGhD,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,7 +1,7 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { HTMLChakraProps } from '@chakra-ui/react';
|
3
3
|
import { UseFormProps, UseFormReturn, FieldValues, SubmitHandler, SubmitErrorHandler } from 'react-hook-form';
|
4
|
-
export type { UseFormReturn, FieldValues };
|
4
|
+
export type { UseFormReturn, FieldValues, SubmitHandler };
|
5
5
|
interface FormOptions<TFieldValues extends FieldValues = FieldValues> {
|
6
6
|
/**
|
7
7
|
* The form schema, currently supports Yup schema only.
|
@@ -20,12 +20,12 @@ interface FormOptions<TFieldValues extends FieldValues = FieldValues> {
|
|
20
20
|
*/
|
21
21
|
formRef?: React.MutableRefObject<HTMLFormElement>;
|
22
22
|
}
|
23
|
-
export interface FormProps<TFieldValues extends FieldValues = FieldValues> extends UseFormProps<TFieldValues>, Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>, FormOptions<TFieldValues> {
|
24
|
-
}
|
25
23
|
/**
|
26
24
|
* @todo Figure out how to pass down FieldValues to all Field components,
|
27
25
|
* if at all possible.
|
28
26
|
*/
|
27
|
+
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
30
|
ref?: React.ForwardedRef<UseFormReturn<TFieldValues, object>> | undefined;
|
31
31
|
}) => React.ReactElement;
|
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,EACnB,MAAM,iBAAiB,CAAA;
|
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,EACnB,MAAM,iBAAiB,CAAA;AAExB,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;;MAyDZ,MAAM,YAAY,CAAA"}
|
package/dist/index.d.ts
CHANGED
@@ -11,6 +11,7 @@ export * from './object-field';
|
|
11
11
|
export * from './display-if';
|
12
12
|
export * from './step-form';
|
13
13
|
export * from './use-step-form';
|
14
|
+
export * from './field-resolver';
|
14
15
|
export * from '@saas-ui/input-right-button';
|
15
16
|
export type { FieldErrors } from 'react-hook-form';
|
16
17
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAA;AAC/B,cAAc,SAAS,CAAA;AACvB,cAAc,UAAU,CAAA;AACxB,cAAc,QAAQ,CAAA;AACtB,cAAc,aAAa,CAAA;AAC3B,cAAc,UAAU,CAAA;AACxB,cAAc,iBAAiB,CAAA;AAC/B,cAAc,eAAe,CAAA;AAC7B,cAAc,mBAAmB,CAAA;AACjC,cAAc,gBAAgB,CAAA;AAC9B,cAAc,cAAc,CAAA;AAC5B,cAAc,aAAa,CAAA;AAC3B,cAAc,iBAAiB,CAAA;AAC/B,cAAc,kBAAkB,CAAA;AAChC,cAAc,6BAA6B,CAAA;AAE3C,YAAY,EAAE,WAAW,EAAE,MAAM,iBAAiB,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("yup"),u=require("@hookform/resolvers/yup"),c=require("@chakra-ui/system"),m=require("@chakra-ui/icons"),d=require("@saas-ui/button"),p=require("@chakra-ui/react-utils"),f=require("@chakra-ui/utils"),v=require("@saas-ui/react-utils"),h=require("@saas-ui/input-right-button");function x(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 y=/*#__PURE__*/x(e);function b(){return b=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},b.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}function S(e,t){(null==t||t>e.length)&&(t=e.length);for(var r=0,n=new Array(t);r<t;r++)n[r]=e[r];return n}var F=["name","label","placeholder"],_=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null},C=["name","label","help","variant","hideLabel","children"],g=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],N=["name","rules"],k=["ref"],w=["name","rules"],I=["ref"],A=["label"],R=["label"],O={},V=function(e){var n=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=E(e,C),c=function(e,r){return t.get(r.errors,e)}(n,t.useFormContext().formState);/*#__PURE__*/return y.createElement(r.FormControl,b({variant:i},u,{isInvalid:!!c}),a&&!o?/*#__PURE__*/y.createElement(r.FormLabel,{variant:i},a):null,/*#__PURE__*/y.createElement(r.Box,null,s,!l||null!=c&&c.message?null:/*#__PURE__*/y.createElement(r.FormHelperText,null,l),(null==c?void 0:c.message)&&/*#__PURE__*/y.createElement(r.FormErrorMessage,null,null==c?void 0:c.message)))},D=r.forwardRef(function(e,t){var r=e.type;/*#__PURE__*/return y.createElement(O[void 0===r?"text":r]||O.text,b({ref:t},e))}),P=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=E(n,N),s=t.useFormContext();/*#__PURE__*/return y.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(t){var n=t.field,l=n.ref,i=E(n,k);/*#__PURE__*/return y.createElement(e,b({},i,o,{ref:r.useMergeRefs(a,l)}))}})})},L=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=E(n,w),s=(0,t.useFormContext().register)(l,i),u=s.ref,c=E(s,I);/*#__PURE__*/return y.createElement(e,b({},c,o,{ref:r.useMergeRefs(a,u)}))})},j=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,g),v=b({required:m},d);/*#__PURE__*/return y.createElement(l,{name:n,label:i,help:o,hideLabel:a,isDisabled:s,isInvalid:u,isReadOnly:c,isRequired:m,variant:p},/*#__PURE__*/y.createElement(e,b({ref:r,name:n,label:i,rules:v},f)))});return i.displayName=n,i}(null!=n&&n.isControlled?P(t):L(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)||V});return O[e]=a,a},q=j("text",r.Input),B=j("number",n.NumberInput,{isControlled:!0}),M=j("password",a.PasswordInput),T=j("textarea",r.Textarea),U=j("switch",r.forwardRef(function(e,t){var n=e.label,a=E(e,A);/*#__PURE__*/return y.createElement(r.Switch,b({ref:t},a),n)}),{isControlled:!0,hideLabel:!0}),H=j("select",o.Select,{isControlled:!0}),G=j("checkbox",r.forwardRef(function(e,t){var n=e.label,a=E(e,R);/*#__PURE__*/return y.createElement(r.Checkbox,b({ref:t},a),n)}),{hideLabel:!0}),z=j("radio",l.RadioInput,{isControlled:!0}),W=j("pin",i.PinInput,{isControlled:!0}),$=j("native-select",o.NativeSelect,{isControlled:!0}),J=function(e){var t;if(null!=(t=e.spec.meta)&&t.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},K=function(e,t){for(var r,n=function(e,t){var r="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(r)return(r=r.call(e)).next.bind(r);if(Array.isArray(e)||(r=function(e,t){if(e){if("string"==typeof e)return S(e,t);var r=Object.prototype.toString.call(e).slice(8,-1);return"Object"===r&&e.constructor&&(r=e.constructor.name),"Map"===r||"Set"===r?Array.from(e):"Arguments"===r||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(r)?S(e,t):void 0}}(e))){r&&(e=r);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.tests);!(r=n()).done;){var a,l=r.value;if(null!=(a=l.OPTIONS)&&a.params[t])return l.OPTIONS.params[t]}},Q=function(e){var t,r=[];for(var n in t="array"===e.type?e.innerType.fields:e.fields){var a=t[n],l={};"array"===a.type&&(l.min=K(a,"min"),l.max=K(a,"max")),r.push(b({name:n,label:a.spec.label||n,type:J(a)},l))}return r},X=["children"],Y=function(e){/*#__PURE__*/return y.createElement(r.chakra.div,null,e.children)},Z=function(e){var t,n,a,l=e.children,i=E(e,X),o=b({},null!=(t=null==(n=r.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return y.createElement(r.SimpleGrid,o,y.Children.map(l,function(e){return y.isValidElement(e)?/*#__PURE__*/y.createElement(Y,null,e):e}))},ee=function(e,t){return y.Children.map(t,function(t){return y.isValidElement(t)&&t.props.name?y.cloneElement(t,b({},t.props,{name:e+"."+t.props.name})):t})},te=p.createContext({name:"ArrayFieldContext"}),re=te[0],ne=te[1],ae=p.createContext({name:"ArrayFieldRowContext"}),le=ae[0],ie=ae[1],oe=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 b({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},se=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=ne(),l=a.name,i=a.remove,o=a.fields;return y.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:y.useCallback(function(){n(l),i(r)},[r])}},ue=function(){var e=ie(),t=e.isFirst,r=e.remove,n=ne(),a=n.min;return{onClick:function(){return r()},isDisabled:t&&!!(a&&n.fields.length<=a)}},ce=function(){var e=ne(),t=e.append,r=e.defaultValue,n=e.max;return{onClick:function(){return t(r,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},me=["children","columns","spacing"],de=["children"],pe=["name","defaultValue","keyName","min","max","children"],fe=function(e){/*#__PURE__*/return y.createElement(he,{index:e.index},/*#__PURE__*/y.createElement(ve,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/y.createElement(xe,null))},ve=function(e){var t=e.children,r=e.columns,n=e.spacing,a=E(e,me),l=ie().name;/*#__PURE__*/return y.createElement(Z,b({flex:"1",columns:r,gridGap:n,mr:"2"},a),ee(l,t))},he=function(e){var t=e.children,r=se({index:e.index});/*#__PURE__*/return y.createElement(le,{value:r},/*#__PURE__*/y.createElement(c.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},xe=function(e){/*#__PURE__*/return y.createElement(d.IconButton,b({icon:/*#__PURE__*/y.createElement(m.MinusIcon,null),"aria-label":"Remove row"},ue(),e))},ye=function(e){/*#__PURE__*/return y.createElement(d.IconButton,b({icon:/*#__PURE__*/y.createElement(m.AddIcon,null),"aria-label":"Add row",float:"right"},ce(),e))},be=y.forwardRef(function(e,t){var r=e.children,n=E(e,de);/*#__PURE__*/return y.createElement(Se,b({ref:t},n),/*#__PURE__*/y.createElement(Ee,null,function(e){/*#__PURE__*/return y.createElement(y.Fragment,null,e.map(function(e,t){/*#__PURE__*/return y.createElement(fe,{key:e.id,index:t},r)}))}),/*#__PURE__*/y.createElement(ye,null))}),Ee=function(e){return(0,e.children)(ne().fields)},Se=y.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,pe),u=oe({name:r,defaultValue:n,keyName:a,min:l,max:i});return y.useImperativeHandle(t,function(){return u},[t,u]),/*#__PURE__*/y.createElement(re,{value:u},/*#__PURE__*/y.createElement(V,b({name:r},s),o))}),Fe=["name","label","hideLabel","children","columns","spacing"],_e=function(e){var t=r.useStyles();/*#__PURE__*/return y.createElement(r.FormLabel,b({as:"legend",sx:t.legend},e))},Ce=function(e){var t=e.name,n=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=E(e,Fe);/*#__PURE__*/return y.createElement(r.FormControl,b({name:t,as:"fieldset"},s),/*#__PURE__*/y.createElement(_e,{display:a?"none":"block"},n),/*#__PURE__*/y.createElement(Z,{columns:i,gridGap:o},ee(t,l)))},ge=["name","type"],Ne=["schema"],ke=["name","type","defaultValue"],we=function(e,t){return Q(function(e,t){return s.reach(e,t)}(e,t)).map(function(e){var t=e.name,r=e.type,n=E(e,ge);/*#__PURE__*/return y.createElement(D,b({key:t,name:t,type:r},n))})},Ie=function(e){var t=e.schema,r=E(e,Ne);/*#__PURE__*/return y.createElement(Z,r,Q(t).map(function(e){var r=e.name,n=e.type,a=E(e,ke);return"array"===n?/*#__PURE__*/y.createElement(be,b({name:r},a),we(t,r)):"object"===n?/*#__PURE__*/y.createElement(Ce,b({name:r},a),we(t,r)):/*#__PURE__*/y.createElement(D,b({key:r,name:r,type:n},a))}))},Ae=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Re=r.forwardRef(function(e,n){var a=e.mode,l=void 0===a?"all":a,i=e.resolver,o=e.reValidateMode,s=e.shouldFocusError,c=e.shouldUnregister,m=e.shouldUseNativeValidation,d=e.criteriaMode,p=e.delayError,f=e.schema,v=e.defaultValues,h=e.onSubmit,x=e.onError,S=e.formRef,F=e.children,_=E(e,Ae),C={mode:l,resolver:i,defaultValues:v,reValidateMode:o,shouldFocusError:s,shouldUnregister:c,shouldUseNativeValidation:m,criteriaMode:d,delayError:p};f&&(C.resolver=u.yupResolver(f));var g=t.useForm(C),N=g.handleSubmit;return y.useImperativeHandle(n,function(){return g},[n,g]),/*#__PURE__*/y.createElement(t.FormProvider,g,/*#__PURE__*/y.createElement(r.chakra.form,b({ref:S,onSubmit:N(h,x)},_),F))}),Oe=["children","disableIfUntouched","disableIfInvalid"],Ve=c.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=E(e,Oe),o=t.useFormContext().formState;/*#__PURE__*/return y.createElement(d.Button,b({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});Ve.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var De=["schema","submitLabel"],Pe=r.forwardRef(function(e,t){var r=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=E(e,De);/*#__PURE__*/return y.createElement(Re,b({},l,{schema:r,ref:t}),/*#__PURE__*/y.createElement(Z,null,/*#__PURE__*/y.createElement(Ie,{schema:r}),a&&/*#__PURE__*/y.createElement(Ve,{label:a})))});function Le(){return Le=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},Le.apply(this,arguments)}function je(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 qe=p.createContext({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"}),Be=qe[0],Me=qe[1];function Te(e){var t=e.step,r=y.useState(-1),n=r[0],a=r[1],l=y.useRef([]),i=y.useState(Date.now())[1],o=y.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 y.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 Ue(e){var t=e.name,r=e.isActive,n=e.isCompleted,a=Me(),l=a.registerStep,i=a.unregisterStep,o=a.activeStep;return y.useEffect(function(){if(t)return l(t),function(){i(t)}},[]),{isActive:t?o===t:r,isCompleted:n}}var He=["children","orientation"],Ge=["children","orientation","stepComponent"],ze=["children","isOpen"],We=["icon","isActive","isCompleted","className"],$e=["title","icon","isActive","isCompleted"],Je=["isActive"],Ke=c.forwardRef(function(e,t){var r=c.useMultiStyleConfig("Stepper",e),n=c.omitThemingProps(e),a=n.children,l=n.orientation,i=je(n,He),o=Te(e),s=Le({display:"flex",flexDirection:"column"},r.container);return y.createElement(c.StylesProvider,{value:r},/*#__PURE__*/y.createElement(Be,{value:o},/*#__PURE__*/y.createElement(c.chakra.div,Le({ref:t,__css:s},i,{className:f.cx("saas-stepper__container",e.className)}),/*#__PURE__*/y.createElement(Qe,{orientation:l},a))))});f.__DEV__&&(Ke.displayName="Stepper");var Qe=function(e){var t,r,n=e.children,a=e.orientation,l=e.stepComponent,i=je(e,Ge),o=c.useStyles(),s=Me().activeIndex,u=Le({display:"flex",flexDirection:"row",alignItems:"center"},o.steps),m="vertical"===a,d=l||Ze,p=v.getChildrenOfType(n,d),h=p.reduce(function(e,t,r,n){return e.push(/*#__PURE__*/y.createElement(d,Le({key:r},t.props,{icon:t.props.icon||r+1,isActive:s===r,isCompleted:t.props.isCompleted||s>r}))),"vertical"===a&&e.push(/*#__PURE__*/y.createElement(Xe,{key:"content-"+r,isOpen:s===r},t.props.children)),r<n.length-1&&e.push(/*#__PURE__*/y.createElement(et,{key:"separator-"+r,isActive:r<s})),e},[]),x=v.getChildOfType(n,rt),b=s>=p.length?x:m?null:/*#__PURE__*/y.createElement(Xe,null,null==(t=p[s])||null==(r=t.props)?void 0:r.children);return y.createElement(y.Fragment,null,/*#__PURE__*/y.createElement(c.chakra.div,Le({__css:u},i,{className:f.cx("saas-stepper__steps",e.className)}),h),b)};f.__DEV__&&(Qe.displayName="StepperSteps");var Xe=function(e){var t=e.children,n=e.isOpen,a=void 0===n||n,l=je(e,ze),i=c.useStyles();return y.createElement(c.chakra.div,Le({__css:i.content},l,{className:f.cx("saas-stepper__content",e.className)}),/*#__PURE__*/y.createElement(r.Collapse,{in:a},t))};f.__DEV__&&(Xe.displayName="StepperContent");var Ye=function(e){var t,r=e.icon,n=e.isCompleted,a=e.className,l=je(e,We),i=Le({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},c.useStyles().icon);return t=n?/*#__PURE__*/y.createElement(m.Icon,{as:m.CheckIcon}):r,/*#__PURE__*/y.createElement(c.chakra.div,Le({__css:i},l,{className:f.cx("saas-stepper__icon",a)}),t)};f.__DEV__&&(Ye.displayName="StepperIcon");var Ze=function(e){var t=e.title,r=e.icon,n=e.isActive,a=e.isCompleted,l=je(e,$e),i=Ue(e),o=Le({display:"flex",alignItems:"center",flexDirection:"row"},c.useStyles().step);return y.createElement(c.chakra.div,Le({__css:o,"data-active":i.isActive,"data-completed":i.isCompleted},l,{className:f.cx("saas-stepper__step",e.className)}),/*#__PURE__*/y.createElement(Ye,{icon:r,isActive:n,isCompleted:a}),t&&/*#__PURE__*/y.createElement(tt,null,t))};f.__DEV__&&(Ze.displayName="StepperStep");var et=function(e){var t=e.isActive,r=je(e,Je),n=Le({flex:1,borderTopWidth:"1px",mx:2},c.useStyles().separator);return y.createElement(c.chakra.div,Le({"data-active":t},r,{className:f.cx("saas-stepper__separator",e.className),__css:n}))};f.__DEV__&&(et.displayName="StepperSeparator");var tt=function(e){var t=c.useStyles();return y.createElement(c.chakra.p,Le({},e,{__css:t.title,className:f.cx("saas-stepper__title",e.className)}))};f.__DEV__&&(tt.displayName="StepperStepTitle");var rt=function(e){var t=c.useStyles();return y.createElement(c.chakra.div,Le({__css:t.completed},e,{className:f.cx("saas-stepper__completed",e.className)}))};f.__DEV__&&(rt.displayName="StepperCompleted");var nt=p.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),at=nt[0],lt=nt[1];function it(e){var t=Te(e),r=t.activeStep,n=t.isLastStep,a=t.nextStep,l=y.useState({}),i=l[0],o=l[1],s=y.useCallback(function(t){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(t).then(function(){c(b({},i[r],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[r,n]),u=y.useCallback(function(e){var t=i[r];return{onSubmit:s,schema:null==t?void 0:t.schema}},[i,s,r]),c=y.useCallback(function(e){o(function(t){var r;return b({},t,((r={})[e.name]=e,r))})},[i]);return b({getFormProps:u,updateStep:c,steps:i},t)}function ot(e){var t=e.name,r=e.schema,n=Ue({name:t}),a=lt(),l=a.steps,i=a.updateStep;return y.useEffect(function(){i({name:t,schema:r})},[t,r]),b({},n,l[t]||{name:t,schema:r})}var st=["children","onSubmit"],ut=["getFormProps"],ct=["name","schema","children","className"],mt=["label","submitLabel"],dt=y.forwardRef(function(e,t){var r=e.children,n=E(e,st),a=it(e),l=a.getFormProps,i=E(a,ut),o=y.useMemo(function(){return i},[i]);/*#__PURE__*/return y.createElement(Be,{value:o},/*#__PURE__*/y.createElement(at,{value:o},/*#__PURE__*/y.createElement(Re,b({ref:t},n,l(e)),f.runIfFn(r,a))))}),pt=function(e){var t=e.name,r=e.schema,n=e.children,a=e.className,l=E(e,ct);return ot({name:t,schema:r}).isActive?/*#__PURE__*/y.createElement(c.chakra.div,b({},l,{className:f.cx("saas-form__step",a)}),n):null};f.__DEV__&&(pt.displayName="FormStep");var ft=function(e){var t=Me(),r=t.prevStep;/*#__PURE__*/return y.createElement(d.Button,b({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:f.cx("saas-form__prev-button",e.className),onClick:f.callAllHandlers(e.onClick,r)}))};f.__DEV__&&(ft.displayName="PrevButton");var vt=function(e){var t=e.label,r=void 0===t?"Next":t,n=e.submitLabel,a=void 0===n?"Complete":n,l=E(e,mt),i=Me(),o=i.isCompleted;/*#__PURE__*/return y.createElement(Ve,b({isDisabled:o,label:i.isLastStep||o?a:r},l,{className:f.cx("saas-form__next-button",e.className)}))};f.__DEV__&&(vt.displayName="NextButton"),exports.ArrayField=be,exports.ArrayFieldAddButton=ye,exports.ArrayFieldContainer=Se,exports.ArrayFieldProvider=re,exports.ArrayFieldRemoveButton=xe,exports.ArrayFieldRow=fe,exports.ArrayFieldRowContainer=he,exports.ArrayFieldRowFields=ve,exports.ArrayFieldRowProvider=le,exports.ArrayFieldRows=Ee,exports.AutoForm=Pe,exports.BaseField=V,exports.CheckboxField=G,exports.DisplayField=function(e){var t=e.name,n=e.label,a=E(e,F);/*#__PURE__*/return y.createElement(r.FormControl,a,n?/*#__PURE__*/y.createElement(r.FormLabel,{htmlFor:t},n):null,/*#__PURE__*/y.createElement(r.Text,{fontSize:"md"},/*#__PURE__*/y.createElement(_,{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=D,exports.Fields=Ie,exports.Form=Re,exports.FormLayout=Z,exports.FormLegend=_e,exports.FormStep=pt,exports.FormStepper=function(e){var t=c.useMultiStyleConfig("Stepper",e),r=y.Children.map(e.children,function(e){if(y.isValidElement(e)&&(null==e?void 0:e.type)===pt){var t=ot(e.props);/*#__PURE__*/return y.createElement(Ze,{name:e.props.name,title:e.props.title,isCompleted:t.isCompleted},e.props.children)}return e});/*#__PURE__*/return y.createElement(c.StylesProvider,{value:t},/*#__PURE__*/y.createElement(Qe,b({mb:"4"},e),r))},exports.FormValue=_,exports.InputField=q,exports.NativeSelectField=$,exports.NextButton=vt,exports.NumberInputField=B,exports.ObjectField=Ce,exports.PasswordInputFIeld=M,exports.PinField=W,exports.PrevButton=ft,exports.RadioField=z,exports.SelectField=H,exports.StepForm=dt,exports.StepFormProvider=at,exports.SubmitButton=Ve,exports.SwitchField=U,exports.TextareaField=T,exports.registerFieldType=j,exports.useArrayField=oe,exports.useArrayFieldAddButton=ce,exports.useArrayFieldContext=ne,exports.useArrayFieldRemoveButton=ue,exports.useArrayFieldRow=se,exports.useArrayFieldRowContext=ie,exports.useFormStep=ot,exports.useStepForm=it,exports.useStepFormContext=lt,exports.withControlledInput=P,exports.withUncontrolledInput=L,Object.keys(h).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return h[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/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]}})});
|
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/resolvers/yup.ts","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../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 { SchemaOf, AnySchema, reach } from 'yup'\nexport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '../field'\n\n// @TODO get proper typings for the schema fields\n\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\ntype Options = {\n min?: number\n max?: number\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (\n schema: SchemaOf<AnySchema>\n): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: SchemaOf<AnySchema>, path: string) => {\n return reach(schema, path)\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 * as React from 'react'\nimport { getFieldsFromSchema, getNestedSchema } from './resolvers/yup'\n\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\n\nexport interface FieldsProps {\n schema: any\n}\n\nconst getNestedFields = (schema: any, name: string) => {\n return getFieldsFromSchema(getNestedSchema(schema, name)).map(\n ({ name, type, ...nestedFieldProps }: FieldProps): React.ReactNode => (\n <Field key={name} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({ schema, ...props }) => {\n return (\n <FormLayout {...props}>\n {getFieldsFromSchema(schema).map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField name={name} {...fieldProps}>\n {getNestedFields(schema, 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\nimport { yupResolver } from './resolvers/yup'\n\nexport type { UseFormReturn, FieldValues }\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\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\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 // @todo remove yup dependency and just use resolver prop?\n if (schema) {\n form.resolver = yupResolver(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","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'\n\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\n\ninterface AutoFormOptions {\n schema: any\n submitLabel?: false | string\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', ...rest } = props\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} />}\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 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 }\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}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema })\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\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, children, className, ...rest } = props\n const step = useFormStep({ name, schema })\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","getType","spec","meta","_field$spec$meta","getArrayOption","tests","test","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","schemaFields","fields","innerType","min","max","push","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","useFieldArray","useArrayFieldRow","index","clearErrors","remove","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","getNestedFields","path","reach","getNestedSchema","nestedFieldProps","Fields","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","yupResolver","methods","useForm","handleSubmit","FormProvider","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","setStep","i","useLayoutEffect","activeStep","isFirstStep","isLastStep","isCompleted","nextStep","prevStep","unregisterStep","useStep","isActive","StepFormProvider","useStepFormContext","useStepForm","stepper","steps","updateSteps","onSubmitStep","data","then","updateStep","getFormProps","useFormStep","StepForm","ctx","useMemo","runIfFn","FormStep","className","cx","__DEV__","PrevButton","callAllHandlers","NextButton","htmlFor","Text","fontSize","condition","useWatch","disabled","exact","isExact","useMultiStyleConfig","elements","StepperStep","title","StylesProvider","StepperSteps"],"mappings":"yxCAgCaA,EAAwC,gBAAGC,IAAAA,KAEtD,OAAOC,EADeC,mBAAdD,WACSD,IAAS,kPC8EtBG,EAAsC,GAmB/BC,EAAkC,SA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EY,gBAACiQ,IACClR,KAAM8G,EAAMzG,MAAML,KAClBmR,MAAOrK,EAAMzG,MAAM8Q,MACnBxC,cALIA,aAOH7H,EAAMzG,MAAMK,UAInB,OAAOoG,iBAGT,OACE7F,gBAACmQ,kBAAejI,MAAOsB,gBACrBxJ,gBAACoQ,MAAa5H,GAAG,KAAQpJ,GACtB4Q"}
|
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","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,KAAMC,EACzBH,EADyBG,QAASC,EAClCJ,EADkCI,UAAWC,EAC7CL,EAD6CK,SAAaC,IAC1DN,KAIIO,EAjBS,SAACZ,EAAca,GAC9B,OAAOC,MAAID,EAAUE,OAAQf,GAgBfgB,CAAShB,EAFDE,mBAAdW,wBAIR,OACEI,gBAACC,iBAAYV,QAASA,GAAaG,GAAcQ,YAAaP,IAC3DN,IAAUG,eACTQ,gBAACG,aAAUZ,QAASA,GAAUF,GAC5B,kBACJW,gBAACI,WACEX,GACAH,SAASK,GAAAA,EAAOU,QAEb,kBADFL,gBA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