@saas-ui/forms 1.0.0-rc.2 → 1.0.0-rc.3
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +29 -0
- package/dist/auto-form.d.ts +13 -1
- package/dist/auto-form.d.ts.map +1 -1
- package/dist/field.d.ts +1 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.modern.mjs.map +1 -1
- package/dist/layout.d.ts +0 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/zod/index.js +1 -1
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.modern.mjs +1 -1
- package/dist/zod/index.modern.mjs.map +1 -1
- package/package.json +15 -15
- package/src/auto-form.tsx +22 -3
- package/src/field-resolver.ts +2 -2
- package/src/field.tsx +19 -19
- package/src/object-field.tsx +3 -3
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,34 @@
|
|
1
1
|
# @saas-ui/forms
|
2
2
|
|
3
|
+
## 1.0.0-rc.3
|
4
|
+
|
5
|
+
### Minor Changes
|
6
|
+
|
7
|
+
- 532a7d4: Updated to Chakra UI 2.2.1
|
8
|
+
- 7a16ef7: Updated to Chakra UI 2.2.1
|
9
|
+
|
10
|
+
### Patch Changes
|
11
|
+
|
12
|
+
- 6133901: No longer passing down label to input fields.
|
13
|
+
- ddec417: ArrayField no longer passing down items to the container element.
|
14
|
+
- 5f80cea: AutoForm now renders children.
|
15
|
+
- 532a7d4: Fixed all theme onconsistencies.
|
16
|
+
- 1c247cb: InputField now has type="text" by default.
|
17
|
+
- d1fb472: Select now renders a hidden input with the current value.
|
18
|
+
- Updated dependencies [c8621b8]
|
19
|
+
- Updated dependencies [532a7d4]
|
20
|
+
- Updated dependencies [7a16ef7]
|
21
|
+
- Updated dependencies [532a7d4]
|
22
|
+
- @saas-ui/select@1.0.0-rc.2
|
23
|
+
- @saas-ui/button@1.0.0-rc.2
|
24
|
+
- @saas-ui/input-right-button@1.0.0-rc.2
|
25
|
+
- @saas-ui/number-input@1.0.0-rc.2
|
26
|
+
- @saas-ui/password-input@1.0.0-rc.2
|
27
|
+
- @saas-ui/pin-input@1.0.0-rc.3
|
28
|
+
- @saas-ui/radio@1.0.0-rc.2
|
29
|
+
- @saas-ui/react-utils@1.0.0-rc.2
|
30
|
+
- @saas-ui/stepper@1.0.0-rc.2
|
31
|
+
|
3
32
|
## 1.0.0-rc.2
|
4
33
|
|
5
34
|
### Patch Changes
|
package/dist/auto-form.d.ts
CHANGED
@@ -3,8 +3,20 @@ import { FieldValues, UseFormReturn } from 'react-hook-form';
|
|
3
3
|
import { FormProps } from './form';
|
4
4
|
import { FieldResolver } from '.';
|
5
5
|
interface AutoFormOptions {
|
6
|
-
|
6
|
+
/**
|
7
|
+
* The submit button label.
|
8
|
+
* Pass `null` to render no submit button.
|
9
|
+
*/
|
10
|
+
submitLabel?: React.ReactNode;
|
11
|
+
/**
|
12
|
+
* The schema.
|
13
|
+
* Supports object schema, Yup or Zod.
|
14
|
+
* @see https://www.saas-ui.dev/docs/forms/auto-form
|
15
|
+
*/
|
7
16
|
schema: any;
|
17
|
+
/**
|
18
|
+
* The field resolver.
|
19
|
+
*/
|
8
20
|
fieldResolver?: any;
|
9
21
|
}
|
10
22
|
export interface AutoFormProps<TFieldValues extends FieldValues> extends Omit<FormProps<TFieldValues>, 'schema'>, AutoFormOptions {
|
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;AAI5D,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAA;AAIxC,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAA;AAEjC,UAAU,eAAe;IACvB,WAAW,CAAC,EAAE,KAAK,
|
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;AAI5D,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAA;AAIxC,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAA;AAEjC,UAAU,eAAe;IACvB;;;OAGG;IACH,WAAW,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC7B;;;;OAIG;IACH,MAAM,EAAE,GAAG,CAAA;IACX;;OAEG;IACH,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;;MA2BhB,MAAM,YAAY;;iCAEO,GAAG,KAAK,aAAa;CAClD,CAAA"}
|
package/dist/field.d.ts
CHANGED
@@ -76,7 +76,7 @@ export interface RegisterFieldTypeOptions {
|
|
76
76
|
* @param component The React component
|
77
77
|
* @param options
|
78
78
|
* @param options.isControlled Set this to true if this is a controlled field.
|
79
|
-
* @param options.hideLabel Hide the field label, for example for checkbox
|
79
|
+
* @param options.hideLabel Hide the field label, for example for the checkbox field.
|
80
80
|
*/
|
81
81
|
export declare const registerFieldType: (type: string, component: React.FC<any>, options?: RegisterFieldTypeOptions) => import("@chakra-ui/react").ComponentWithAs<import("@chakra-ui/react").ComponentWithAs<"div", FormControlProps>, FieldProps<FieldValues, string>>;
|
82
82
|
export declare const InputField: import("@chakra-ui/react").ComponentWithAs<import("@chakra-ui/react").ComponentWithAs<"div", FormControlProps>, FieldProps<FieldValues, string>>;
|
package/dist/field.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"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C,EAAE,KAAK,CAAC,EAAE,CAAC,GAAG,CAAC,CAAA;CAC1B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,iBAAiB,SACtB,MAAM,aACD,MAAM,EAAE,CAAC,GAAG,CAAC,YACd,wBAAwB,qJAqBnC,CAAA;AAED,eAAO,MAAM,UAAU,kJAKtB,CAAA;AACD,eAAO,MAAM,gBAAgB,kJAE3B,CAAA;AACF,eAAO,MAAM,kBAAkB,kJAA+C,CAAA;AAC9E,eAAO,MAAM,aAAa,kJAA0C,CAAA;AACpE,eAAO,MAAM,WAAW,kJAQvB,CAAA;AACD,eAAO,MAAM,WAAW,kJAEtB,CAAA;AACF,eAAO,MAAM,aAAa,kJAczB,CAAA;AACD,eAAO,MAAM,UAAU,kJAErB,CAAA;AACF,eAAO,MAAM,QAAQ,kJAEnB,CAAA;AACF,eAAO,MAAM,iBAAiB,kJAI7B,CAAA"}
|
package/dist/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var e=require("react"),r=require("@chakra-ui/utils"),t=require("react-hook-form"),n=require("@chakra-ui/react"),a=require("@saas-ui/number-input"),l=require("@saas-ui/password-input"),i=require("@saas-ui/radio"),o=require("@saas-ui/pin-input"),s=require("@saas-ui/select"),u=require("@chakra-ui/system"),d=require("@chakra-ui/icons"),m=require("@saas-ui/button"),c=require("@chakra-ui/react-utils"),p=require("@saas-ui/stepper"),f=require("@saas-ui/input-right-button");function v(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var x=/*#__PURE__*/v(e);function h(){return h=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},h.apply(this,arguments)}function F(e,r){if(null==e)return{};var t,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)r.indexOf(t=l[n])>=0||(a[t]=e[t]);return a}var b=["name","label","placeholder"],y=function(e){var r=e.name,t=e.label,a=F(e,b);/*#__PURE__*/return x.createElement(n.FormControl,a,t?/*#__PURE__*/x.createElement(n.FormLabel,{htmlFor:r},t):null,/*#__PURE__*/x.createElement(n.Text,{fontSize:"md"},/*#__PURE__*/x.createElement(E,{name:r})))};r.__DEV__&&(y.displayName="DisplayField");var E=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null};r.__DEV__&&(E.displayName="FormValue");var _=["name","label","help","variant","hideLabel","children"],g=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],C=["name","rules"],S=["ref"],N=["name","rules"],R=["ref"],V=["label"],w=["label"],D={},A=function(e){var r=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=F(e,_),d=function(e,r){return t.get(r.errors,e)}(r,t.useFormContext().formState);/*#__PURE__*/return x.createElement(n.FormControl,h({variant:i},u,{isInvalid:!!d}),a&&!o?/*#__PURE__*/x.createElement(n.FormLabel,{variant:i},a):null,/*#__PURE__*/x.createElement(n.Box,null,s,!l||null!=d&&d.message?null:/*#__PURE__*/x.createElement(n.FormHelperText,null,l),(null==d?void 0:d.message)&&/*#__PURE__*/x.createElement(n.FormErrorMessage,null,null==d?void 0:d.message)))};r.__DEV__&&(A.displayName="BaseField");var k=n.forwardRef(function(e,r){var t=e.type;/*#__PURE__*/return x.createElement(D[void 0===t?"text":t]||D.text,h({ref:r},e))}),I=function(e){return n.forwardRef(function(r,a){var l=r.name,i=r.rules,o=F(r,C),s=t.useFormContext();/*#__PURE__*/return x.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(r){var t=r.field,l=t.ref,i=F(t,S);/*#__PURE__*/return x.createElement(e,h({},i,o,{ref:n.useMergeRefs(a,l)}))}})})},L=function(e){return n.forwardRef(function(r,a){var l=r.name,i=r.rules,o=F(r,N),s=(0,t.useFormContext().register)(l,i),u=s.ref,d=F(s,R);/*#__PURE__*/return x.createElement(e,h({},d,o,{ref:n.useMergeRefs(a,u)}))})},P=function(e,r,t){var a=function(e,r){var t=r.displayName,a=r.hideLabel,l=r.BaseField,i=n.forwardRef(function(r,t){var n=r.id,i=r.name,o=r.label,s=r.help,u=r.isDisabled,d=r.isInvalid,m=r.isReadOnly,c=r.isRequired,p=r.rules,f=r.variant,v=F(r,g),b=h({required:c},p);/*#__PURE__*/return x.createElement(l,{id:n,name:i,label:o,help:s,hideLabel:a,isDisabled:u,isInvalid:d,isReadOnly:m,isRequired:c,variant:f},/*#__PURE__*/x.createElement(e,h({ref:t,id:n,name:i,label:o,rules:b},v)))});return i.displayName=t,i}(null!=t&&t.isControlled?I(r):L(r),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==t?void 0:t.hideLabel,BaseField:(null==t?void 0:t.BaseField)||A});return D[e]=a,a},B=P("text",n.Input),O=P("number",a.NumberInput,{isControlled:!0}),j=P("password",l.PasswordInput),q=P("textarea",n.Textarea),M=P("switch",n.forwardRef(function(e,r){var t=e.label,a=F(e,V);/*#__PURE__*/return x.createElement(n.Switch,h({ref:r},a),t)}),{isControlled:!0,hideLabel:!0}),U=P("select",s.Select,{isControlled:!0}),T=P("checkbox",n.forwardRef(function(e,r){var t=e.label,a=F(e,w);/*#__PURE__*/return x.createElement(n.Checkbox,h({ref:r},a),t)}),{hideLabel:!0}),H=P("radio",i.RadioInput,{isControlled:!0}),G=P("pin",o.PinInput,{isControlled:!0}),z=P("native-select",s.NativeSelect,{isControlled:!0}),W=function(e){return e&&Object.entries(e).map(function(e){return h({},e[1],{name:e[0]})})},J=function(e){return{getFields:function(){return W(e)},getNestedFields:function(t){var n,a=r.get(e,t);return a?"object"===(null==(n=a.items)?void 0:n.type)?W(a.items.properties):"object"===a.type?W(a.properties):[a.items]:[]}}},K=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Q=n.forwardRef(function(e,a){var l=e.mode,i=void 0===l?"all":l,o=e.resolver,s=e.reValidateMode,u=e.shouldFocusError,d=e.shouldUnregister,m=e.shouldUseNativeValidation,c=e.criteriaMode,p=e.delayError,f=e.schema,v=e.defaultValues,b=e.onSubmit,y=e.onError,E=e.formRef,_=e.children,g=F(e,K),C={mode:i,resolver:o,defaultValues:v,reValidateMode:s,shouldFocusError:u,shouldUnregister:d,shouldUseNativeValidation:m,criteriaMode:c,delayError:p};f&&!o&&(C.resolver=null==Q.getResolver?void 0:Q.getResolver(f));var S=t.useForm(C),N=S.handleSubmit;return x.useImperativeHandle(a,function(){return S},[a,S]),/*#__PURE__*/x.createElement(t.FormProvider,S,/*#__PURE__*/x.createElement(n.chakra.form,h({ref:E,onSubmit:N(b,y)},g,{className:r.cx("saas-form",e.className)}),_))});Q.getFieldResolver=J,r.__DEV__&&(Q.displayName="Form");var X=["children"],Y=function(e){/*#__PURE__*/return x.createElement(n.chakra.div,null,e.children)};r.__DEV__&&(Y.displayName="FormLayoutItem");var Z=function(e){var t,a,l,i=e.children,o=F(e,X),s=h({},null!=(t=null==(a=n.useTheme().components)||null==(l=a.FormLayout)?void 0:l.defaultProps)?t:{spacing:4},o);/*#__PURE__*/return x.createElement(n.SimpleGrid,h({},s,{className:r.cx("saas-form__layout",o.className)}),x.Children.map(i,function(e){return x.isValidElement(e)?/*#__PURE__*/x.createElement(Y,null,e):e}))};r.__DEV__&&(Z.displayName="FormLayout");var $=function(e,r){return x.Children.map(r,function(r){return x.isValidElement(r)&&r.props.name?x.cloneElement(r,h({},r.props,{name:e+"."+r.props.name})):r})},ee=c.createContext({name:"ArrayFieldContext"}),re=ee[0],te=ee[1],ne=c.createContext({name:"ArrayFieldRowContext"}),ae=ne[0],le=ne[1],ie=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 h({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},oe=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=te(),l=a.name,i=a.remove,o=a.fields;return x.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:x.useCallback(function(){n(l),i(r)},[r])}},se=function(){var e=le(),r=e.isFirst,t=e.remove,n=te(),a=n.min;return{onClick:function(){return t()},isDisabled:r&&!!(a&&n.fields.length<=a)}},ue=function(){var e=te(),r=e.append,t=e.defaultValue,n=e.max;return{onClick:function(){return r(t,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},de=["children","columns","spacing"],me=["children"],ce=["name","defaultValue","keyName","min","max","children"],pe=function(e){/*#__PURE__*/return x.createElement(ve,{index:e.index},/*#__PURE__*/x.createElement(fe,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/x.createElement(xe,null))};r.__DEV__&&(pe.displayName="ArrayFieldRow");var fe=function(e){var r=e.children,t=e.columns,n=e.spacing,a=F(e,de),l=le().name;/*#__PURE__*/return x.createElement(Z,h({flex:"1",columns:t,gridGap:n,mr:"2"},a),$(l,r))};r.__DEV__&&(fe.displayName="ArrayFieldRowFields");var ve=function(e){var r=e.children,t=oe({index:e.index});/*#__PURE__*/return x.createElement(ae,{value:t},/*#__PURE__*/x.createElement(u.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))};r.__DEV__&&(ve.displayName="ArrayFieldRowContainer");var xe=function(e){/*#__PURE__*/return x.createElement(m.IconButton,h({icon:/*#__PURE__*/x.createElement(d.MinusIcon,null),"aria-label":"Remove row"},se(),e))};r.__DEV__&&(xe.displayName="ArrayFieldRemoveButton");var he=function(e){/*#__PURE__*/return x.createElement(m.IconButton,h({icon:/*#__PURE__*/x.createElement(d.AddIcon,null),"aria-label":"Add row",float:"right"},ue(),e))};r.__DEV__&&(he.displayName="ArrayFieldAddButton");var Fe=x.forwardRef(function(e,r){var t=e.children,n=F(e,me);/*#__PURE__*/return x.createElement(ye,h({ref:r},n),/*#__PURE__*/x.createElement(be,null,function(e){/*#__PURE__*/return x.createElement(x.Fragment,null,e.map(function(e,r){/*#__PURE__*/return x.createElement(pe,{key:e.id,index:r},t)}))}),/*#__PURE__*/x.createElement(he,null))});r.__DEV__&&(Fe.displayName="ArrayField");var be=function(e){return(0,e.children)(te().fields)};r.__DEV__&&(be.displayName="ArrayFieldRows");var ye=x.forwardRef(function(e,r){var t=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=F(e,ce),u=ie({name:t,defaultValue:n,keyName:a,min:l,max:i});return x.useImperativeHandle(r,function(){return u},[r,u]),/*#__PURE__*/x.createElement(re,{value:u},/*#__PURE__*/x.createElement(A,h({name:t},s),o))});r.__DEV__&&(ye.displayName="ArrayFieldContainer");var Ee=["name","label","hideLabel","children","columns","spacing"],_e=function(e){var r=n.useStyles();/*#__PURE__*/return x.createElement(n.FormLabel,h({as:"legend",sx:r.legend},e))},ge=function(e){var r=e.name,t=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=F(e,Ee);/*#__PURE__*/return x.createElement(n.FormControl,h({name:r,as:"fieldset"},s),/*#__PURE__*/x.createElement(_e,{display:a?"none":"block"},t),/*#__PURE__*/x.createElement(Z,{columns:i,gridGap:o},$(r,l)))};r.__DEV__&&(ge.displayName="ObjectField");var Ce=["name","type"],Se=["schema","fieldResolver"],Ne=["name","type","defaultValue"],Re=function(e,r){var t;return null==(t=e.getNestedFields(r))?void 0:t.map(function(e,r){var t=e.name,n=e.type,a=F(e,Ce);/*#__PURE__*/return x.createElement(k,h({key:t||r,name:t,type:n},a))})},Ve=function(e){var r=e.schema,t=e.fieldResolver,n=F(e,Se),a=x.useMemo(function(){return t||Q.getFieldResolver(r)},[r,t]);/*#__PURE__*/return x.createElement(Z,n,a.getFields().map(function(e){var r=e.name,t=e.type,n=F(e,Ne);return"array"===t?/*#__PURE__*/x.createElement(Fe,h({key:r,name:r},n),Re(a,r)):"object"===t?/*#__PURE__*/x.createElement(ge,h({key:r,name:r},n),Re(a,r)):/*#__PURE__*/x.createElement(k,h({key:r,name:r,type:t},n))}))};r.__DEV__&&(Ve.displayName="Fields");var we=["children","disableIfUntouched","disableIfInvalid"],De=u.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=F(e,we),o=t.useFormContext().formState;/*#__PURE__*/return x.createElement(m.Button,h({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});De.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},r.__DEV__&&(De.displayName="SubmitButton");var Ae=["schema","submitLabel","fieldResolver"],ke=n.forwardRef(function(e,r){var t=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=F(e,Ae);/*#__PURE__*/return x.createElement(Q,h({},i,{schema:t,ref:r}),/*#__PURE__*/x.createElement(Z,null,/*#__PURE__*/x.createElement(Ve,{schema:t,fieldResolver:l}),a&&/*#__PURE__*/x.createElement(De,{label:a})))});r.__DEV__&&(ke.displayName="AutoForm");var Ie=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};r.__DEV__&&(Ie.displayName="DisplayIf");var Le=c.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),Pe=Le[0],Be=Le[1];function Oe(e){var r=p.useStepper(e),t=r.activeStep,n=r.isLastStep,a=r.nextStep,l=x.useState({}),i=l[0],o=l[1],s=x.useCallback(function(r){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(r).then(function(){d(h({},i[t],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[t,n]),u=x.useCallback(function(){var e=i[t];return{onSubmit:s,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[i,s,t]),d=x.useCallback(function(e){o(function(r){var t;return h({},r,((t={})[e.name]=e,t))})},[i]);return h({getFormProps:u,updateStep:d,steps:i},r)}function je(e){var r=e.name,t=e.schema,n=e.resolver,a=p.useStep({name:r}),l=Be(),i=l.steps,o=l.updateStep;return x.useEffect(function(){o({name:r,schema:t,resolver:n})},[r,t]),h({},a,i[r]||{name:r,schema:t})}var qe=["children"],Me=["getFormProps"],Ue=["name","schema","resolver","children","className"],Te=["label","submitLabel"],He=x.forwardRef(function(e,t){var n=e.children,a=F(e,qe),l=Oe(e),i=l.getFormProps,o=F(l,Me),s=x.useMemo(function(){return o},[o]);/*#__PURE__*/return x.createElement(p.StepperProvider,{value:s},/*#__PURE__*/x.createElement(Pe,{value:s},/*#__PURE__*/x.createElement(Q,h({ref:t},a,i()),r.runIfFn(n,l))))}),Ge=function(e){var t=e.name,n=e.schema,a=e.resolver,l=e.children,i=e.className,o=F(e,Ue);return je({name:t,schema:n,resolver:a}).isActive?/*#__PURE__*/x.createElement(u.chakra.div,h({},o,{className:r.cx("saas-form__step",i)}),l):null};r.__DEV__&&(Ge.displayName="FormStep");var ze=function(e){var t=p.useStepperContext(),n=t.prevStep;/*#__PURE__*/return x.createElement(m.Button,h({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:r.cx("saas-form__prev-button",e.className),onClick:r.callAllHandlers(e.onClick,n)}))};r.__DEV__&&(ze.displayName="PrevButton");var We=function(e){var t=e.label,n=void 0===t?"Next":t,a=e.submitLabel,l=void 0===a?"Complete":a,i=F(e,Te),o=p.useStepperContext(),s=o.isCompleted;/*#__PURE__*/return x.createElement(De,h({isDisabled:s,label:o.isLastStep||s?l:n},i,{className:r.cx("saas-form__next-button",e.className)}))};r.__DEV__&&(We.displayName="NextButton"),exports.ArrayField=Fe,exports.ArrayFieldAddButton=he,exports.ArrayFieldContainer=ye,exports.ArrayFieldProvider=re,exports.ArrayFieldRemoveButton=xe,exports.ArrayFieldRow=pe,exports.ArrayFieldRowContainer=ve,exports.ArrayFieldRowFields=fe,exports.ArrayFieldRowProvider=ae,exports.ArrayFieldRows=be,exports.AutoForm=ke,exports.BaseField=A,exports.CheckboxField=T,exports.DisplayField=y,exports.DisplayIf=Ie,exports.Field=k,exports.Fields=Ve,exports.Form=Q,exports.FormLayout=Z,exports.FormLegend=_e,exports.FormStep=Ge,exports.FormStepper=function(e){var r=u.useMultiStyleConfig("Stepper",e),t=x.Children.map(e.children,function(e){if(x.isValidElement(e)&&(null==e?void 0:e.type)===Ge){var r=je(e.props);/*#__PURE__*/return x.createElement(p.StepperStep,{name:e.props.name,title:e.props.title,isCompleted:r.isCompleted},e.props.children)}return e});/*#__PURE__*/return x.createElement(u.StylesProvider,{value:r},/*#__PURE__*/x.createElement(p.StepperSteps,h({mb:"4"},e),t))},exports.FormValue=E,exports.InputField=B,exports.NativeSelectField=z,exports.NextButton=We,exports.NumberInputField=O,exports.ObjectField=ge,exports.PasswordInputFIeld=j,exports.PinField=G,exports.PrevButton=ze,exports.RadioField=H,exports.SelectField=U,exports.StepForm=He,exports.StepFormProvider=Pe,exports.SubmitButton=De,exports.SwitchField=M,exports.TextareaField=q,exports.objectFieldResolver=J,exports.registerFieldType=P,exports.useArrayField=ie,exports.useArrayFieldAddButton=ue,exports.useArrayFieldContext=te,exports.useArrayFieldRemoveButton=se,exports.useArrayFieldRow=oe,exports.useArrayFieldRowContext=le,exports.useFormStep=je,exports.useStepForm=Oe,exports.useStepFormContext=Be,exports.withControlledInput=I,exports.withUncontrolledInput=L,Object.keys(f).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return f[e]}})});
|
1
|
+
var e=require("react"),r=require("@chakra-ui/utils"),t=require("react-hook-form"),n=require("@chakra-ui/react"),a=require("@saas-ui/number-input"),l=require("@saas-ui/password-input"),i=require("@saas-ui/radio"),o=require("@saas-ui/pin-input"),s=require("@saas-ui/select"),u=require("@chakra-ui/system"),d=require("@chakra-ui/icons"),m=require("@saas-ui/button"),c=require("@chakra-ui/react-utils"),p=require("@saas-ui/stepper"),f=require("@saas-ui/input-right-button");function v(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var x=/*#__PURE__*/v(e);function h(){return h=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},h.apply(this,arguments)}function y(e,r){if(null==e)return{};var t,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)r.indexOf(t=l[n])>=0||(a[t]=e[t]);return a}var F=["name","label","placeholder"],b=function(e){var r=e.name,t=e.label,a=y(e,F);/*#__PURE__*/return x.createElement(n.FormControl,a,t?/*#__PURE__*/x.createElement(n.FormLabel,{htmlFor:r},t):null,/*#__PURE__*/x.createElement(n.Text,{fontSize:"md"},/*#__PURE__*/x.createElement(E,{name:r})))};r.__DEV__&&(b.displayName="DisplayField");var E=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null};r.__DEV__&&(E.displayName="FormValue");var _=["name","label","help","variant","hideLabel","children"],g=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],C=["name","rules"],S=["ref"],N=["name","rules"],R=["ref"],V=["type"],w=["type"],D=["label","type"],A={},k=function(e){var r=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=y(e,_),d=function(e,r){return t.get(r.errors,e)}(r,t.useFormContext().formState);/*#__PURE__*/return x.createElement(n.FormControl,h({variant:i},u,{isInvalid:!!d}),a&&!o?/*#__PURE__*/x.createElement(n.FormLabel,{variant:i},a):null,/*#__PURE__*/x.createElement(n.Box,null,s,!l||null!=d&&d.message?null:/*#__PURE__*/x.createElement(n.FormHelperText,null,l),(null==d?void 0:d.message)&&/*#__PURE__*/x.createElement(n.FormErrorMessage,null,null==d?void 0:d.message)))};r.__DEV__&&(k.displayName="BaseField");var I=n.forwardRef(function(e,r){var t=e.type;/*#__PURE__*/return x.createElement(A[void 0===t?"text":t]||A.text,h({ref:r},e))}),L=function(e){return n.forwardRef(function(r,a){var l=r.name,i=r.rules,o=y(r,C),s=t.useFormContext();/*#__PURE__*/return x.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(r){var t=r.field,l=t.ref,i=y(t,S);/*#__PURE__*/return x.createElement(e,h({},i,o,{ref:n.useMergeRefs(a,l)}))}})})},P=function(e){return n.forwardRef(function(r,a){var l=r.name,i=r.rules,o=y(r,N),s=(0,t.useFormContext().register)(l,i),u=s.ref,d=y(s,R);/*#__PURE__*/return x.createElement(e,h({},d,o,{ref:n.useMergeRefs(a,u)}))})},B=function(e,r,t){var a=function(e,r){var t=r.displayName,a=r.hideLabel,l=r.BaseField,i=n.forwardRef(function(r,t){var n=r.id,i=r.name,o=r.label,s=r.help,u=r.isDisabled,d=r.isInvalid,m=r.isReadOnly,c=r.isRequired,p=r.rules,f=r.variant,v=y(r,g),F=h({required:c},p);/*#__PURE__*/return x.createElement(l,{id:n,name:i,label:o,help:s,hideLabel:a,isDisabled:u,isInvalid:d,isReadOnly:m,isRequired:c,variant:f},/*#__PURE__*/x.createElement(e,h({ref:t,id:n,name:i,label:a?o:void 0,rules:F},v)))});return i.displayName=t,i}(null!=t&&t.isControlled?L(r):P(r),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==t?void 0:t.hideLabel,BaseField:(null==t?void 0:t.BaseField)||k});return A[e]=a,a},O=B("text",n.forwardRef(function(e,r){var t=e.type,a=void 0===t?"text":t,l=y(e,V);/*#__PURE__*/return x.createElement(n.Input,h({type:a},l,{ref:r}))})),j=B("number",a.NumberInput,{isControlled:!0}),q=B("password",l.PasswordInput),M=B("textarea",n.Textarea),U=B("switch",n.forwardRef(function(e,r){var t=y(e,w);/*#__PURE__*/return x.createElement(n.Switch,h({},t,{ref:r}))}),{isControlled:!0}),T=B("select",s.Select,{isControlled:!0}),H=B("checkbox",n.forwardRef(function(e,r){var t=e.label,a=y(e,D);/*#__PURE__*/return x.createElement(n.Checkbox,h({ref:r},a),t)}),{hideLabel:!0}),G=B("radio",i.RadioInput,{isControlled:!0}),z=B("pin",o.PinInput,{isControlled:!0}),W=B("native-select",s.NativeSelect,{isControlled:!0}),J=["items"],K=function(e){return e&&Object.entries(e).map(function(e){var r=e[0];return h({},y(e[1],J),{name:r})})},Q=function(e){return{getFields:function(){return K(e)},getNestedFields:function(t){var n,a=r.get(e,t);return a?"object"===(null==(n=a.items)?void 0:n.type)?K(a.items.properties):"object"===a.type?K(a.properties):[a.items]:[]}}},X=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Y=n.forwardRef(function(e,a){var l=e.mode,i=void 0===l?"all":l,o=e.resolver,s=e.reValidateMode,u=e.shouldFocusError,d=e.shouldUnregister,m=e.shouldUseNativeValidation,c=e.criteriaMode,p=e.delayError,f=e.schema,v=e.defaultValues,F=e.onSubmit,b=e.onError,E=e.formRef,_=e.children,g=y(e,X),C={mode:i,resolver:o,defaultValues:v,reValidateMode:s,shouldFocusError:u,shouldUnregister:d,shouldUseNativeValidation:m,criteriaMode:c,delayError:p};f&&!o&&(C.resolver=null==Y.getResolver?void 0:Y.getResolver(f));var S=t.useForm(C),N=S.handleSubmit;return x.useImperativeHandle(a,function(){return S},[a,S]),/*#__PURE__*/x.createElement(t.FormProvider,S,/*#__PURE__*/x.createElement(n.chakra.form,h({ref:E,onSubmit:N(F,b)},g,{className:r.cx("saas-form",e.className)}),_))});Y.getFieldResolver=Q,r.__DEV__&&(Y.displayName="Form");var Z=["children"],$=function(e){/*#__PURE__*/return x.createElement(n.chakra.div,null,e.children)};r.__DEV__&&($.displayName="FormLayoutItem");var ee=function(e){var t,a,l,i=e.children,o=y(e,Z),s=h({},null!=(t=null==(a=n.useTheme().components)||null==(l=a.FormLayout)?void 0:l.defaultProps)?t:{spacing:4},o);/*#__PURE__*/return x.createElement(n.SimpleGrid,h({},s,{className:r.cx("saas-form__layout",o.className)}),x.Children.map(i,function(e){return x.isValidElement(e)?/*#__PURE__*/x.createElement($,null,e):e}))};r.__DEV__&&(ee.displayName="FormLayout");var re=function(e,r){return x.Children.map(r,function(r){return x.isValidElement(r)&&r.props.name?x.cloneElement(r,h({},r.props,{name:e+"."+r.props.name})):r})},te=c.createContext({name:"ArrayFieldContext"}),ne=te[0],ae=te[1],le=c.createContext({name:"ArrayFieldRowContext"}),ie=le[0],oe=le[1],se=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 h({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},ue=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=ae(),l=a.name,i=a.remove,o=a.fields;return x.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:x.useCallback(function(){n(l),i(r)},[r])}},de=function(){var e=oe(),r=e.isFirst,t=e.remove,n=ae(),a=n.min;return{onClick:function(){return t()},isDisabled:r&&!!(a&&n.fields.length<=a)}},me=function(){var e=ae(),r=e.append,t=e.defaultValue,n=e.max;return{onClick:function(){return r(t,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},ce=["children","columns","spacing"],pe=["children"],fe=["name","defaultValue","keyName","min","max","children"],ve=function(e){/*#__PURE__*/return x.createElement(he,{index:e.index},/*#__PURE__*/x.createElement(xe,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/x.createElement(ye,null))};r.__DEV__&&(ve.displayName="ArrayFieldRow");var xe=function(e){var r=e.children,t=e.columns,n=e.spacing,a=y(e,ce),l=oe().name;/*#__PURE__*/return x.createElement(ee,h({flex:"1",columns:t,gridGap:n,mr:"2"},a),re(l,r))};r.__DEV__&&(xe.displayName="ArrayFieldRowFields");var he=function(e){var r=e.children,t=ue({index:e.index});/*#__PURE__*/return x.createElement(ie,{value:t},/*#__PURE__*/x.createElement(u.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))};r.__DEV__&&(he.displayName="ArrayFieldRowContainer");var ye=function(e){/*#__PURE__*/return x.createElement(m.IconButton,h({icon:/*#__PURE__*/x.createElement(d.MinusIcon,null),"aria-label":"Remove row"},de(),e))};r.__DEV__&&(ye.displayName="ArrayFieldRemoveButton");var Fe=function(e){/*#__PURE__*/return x.createElement(m.IconButton,h({icon:/*#__PURE__*/x.createElement(d.AddIcon,null),"aria-label":"Add row",float:"right"},me(),e))};r.__DEV__&&(Fe.displayName="ArrayFieldAddButton");var be=x.forwardRef(function(e,r){var t=e.children,n=y(e,pe);/*#__PURE__*/return x.createElement(_e,h({ref:r},n),/*#__PURE__*/x.createElement(Ee,null,function(e){/*#__PURE__*/return x.createElement(x.Fragment,null,e.map(function(e,r){/*#__PURE__*/return x.createElement(ve,{key:e.id,index:r},t)}))}),/*#__PURE__*/x.createElement(Fe,null))});r.__DEV__&&(be.displayName="ArrayField");var Ee=function(e){return(0,e.children)(ae().fields)};r.__DEV__&&(Ee.displayName="ArrayFieldRows");var _e=x.forwardRef(function(e,r){var t=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=y(e,fe),u=se({name:t,defaultValue:n,keyName:a,min:l,max:i});return x.useImperativeHandle(r,function(){return u},[r,u]),/*#__PURE__*/x.createElement(ne,{value:u},/*#__PURE__*/x.createElement(k,h({name:t},s),o))});r.__DEV__&&(_e.displayName="ArrayFieldContainer");var ge=["name","label","hideLabel","children","columns","spacing"],Ce=function(e){var r=n.useStyleConfig("FormLegend");/*#__PURE__*/return x.createElement(n.FormLabel,h({as:"legend",sx:r},e))},Se=function(e){var r=e.name,t=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=y(e,ge);/*#__PURE__*/return x.createElement(n.FormControl,h({name:r,as:"fieldset"},s),/*#__PURE__*/x.createElement(Ce,{display:a?"none":"block"},t),/*#__PURE__*/x.createElement(ee,{columns:i,gridGap:o},re(r,l)))};r.__DEV__&&(Se.displayName="ObjectField");var Ne=["name","type"],Re=["schema","fieldResolver"],Ve=["name","type","defaultValue"],we=function(e,r){var t;return null==(t=e.getNestedFields(r))?void 0:t.map(function(e,r){var t=e.name,n=e.type,a=y(e,Ne);/*#__PURE__*/return x.createElement(I,h({key:t||r,name:t,type:n},a))})},De=function(e){var r=e.schema,t=e.fieldResolver,n=y(e,Re),a=x.useMemo(function(){return t||Y.getFieldResolver(r)},[r,t]);/*#__PURE__*/return x.createElement(ee,n,a.getFields().map(function(e){var r=e.name,t=e.type,n=y(e,Ve);return"array"===t?/*#__PURE__*/x.createElement(be,h({key:r,name:r},n),we(a,r)):"object"===t?/*#__PURE__*/x.createElement(Se,h({key:r,name:r},n),we(a,r)):/*#__PURE__*/x.createElement(I,h({key:r,name:r,type:t},n))}))};r.__DEV__&&(De.displayName="Fields");var Ae=["children","disableIfUntouched","disableIfInvalid"],ke=u.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=y(e,Ae),o=t.useFormContext().formState;/*#__PURE__*/return x.createElement(m.Button,h({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});ke.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},r.__DEV__&&(ke.displayName="SubmitButton");var Ie=["schema","submitLabel","fieldResolver","children"],Le=n.forwardRef(function(e,r){var t=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=e.children,o=y(e,Ie);/*#__PURE__*/return x.createElement(Y,h({},o,{schema:t,ref:r}),/*#__PURE__*/x.createElement(ee,null,/*#__PURE__*/x.createElement(De,{schema:t,fieldResolver:l}),a&&/*#__PURE__*/x.createElement(ke,{label:a}),i))});r.__DEV__&&(Le.displayName="AutoForm");var Pe=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};r.__DEV__&&(Pe.displayName="DisplayIf");var Be=c.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),Oe=Be[0],je=Be[1];function qe(e){var r=p.useStepper(e),t=r.activeStep,n=r.isLastStep,a=r.nextStep,l=x.useState({}),i=l[0],o=l[1],s=x.useCallback(function(r){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(r).then(function(){d(h({},i[t],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[t,n]),u=x.useCallback(function(){var e=i[t];return{onSubmit:s,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[i,s,t]),d=x.useCallback(function(e){o(function(r){var t;return h({},r,((t={})[e.name]=e,t))})},[i]);return h({getFormProps:u,updateStep:d,steps:i},r)}function Me(e){var r=e.name,t=e.schema,n=e.resolver,a=p.useStep({name:r}),l=je(),i=l.steps,o=l.updateStep;return x.useEffect(function(){o({name:r,schema:t,resolver:n})},[r,t]),h({},a,i[r]||{name:r,schema:t})}var Ue=["children"],Te=["getFormProps"],He=["name","schema","resolver","children","className"],Ge=["label","submitLabel"],ze=x.forwardRef(function(e,t){var n=e.children,a=y(e,Ue),l=qe(e),i=l.getFormProps,o=y(l,Te),s=x.useMemo(function(){return o},[o]);/*#__PURE__*/return x.createElement(p.StepperProvider,{value:s},/*#__PURE__*/x.createElement(Oe,{value:s},/*#__PURE__*/x.createElement(Y,h({ref:t},a,i()),r.runIfFn(n,l))))}),We=function(e){var t=e.name,n=e.schema,a=e.resolver,l=e.children,i=e.className,o=y(e,He);return Me({name:t,schema:n,resolver:a}).isActive?/*#__PURE__*/x.createElement(u.chakra.div,h({},o,{className:r.cx("saas-form__step",i)}),l):null};r.__DEV__&&(We.displayName="FormStep");var Je=function(e){var t=p.useStepperContext(),n=t.prevStep;/*#__PURE__*/return x.createElement(m.Button,h({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:r.cx("saas-form__prev-button",e.className),onClick:r.callAllHandlers(e.onClick,n)}))};r.__DEV__&&(Je.displayName="PrevButton");var Ke=function(e){var t=e.label,n=void 0===t?"Next":t,a=e.submitLabel,l=void 0===a?"Complete":a,i=y(e,Ge),o=p.useStepperContext(),s=o.isCompleted;/*#__PURE__*/return x.createElement(ke,h({isDisabled:s,label:o.isLastStep||s?l:n},i,{className:r.cx("saas-form__next-button",e.className)}))};r.__DEV__&&(Ke.displayName="NextButton"),exports.ArrayField=be,exports.ArrayFieldAddButton=Fe,exports.ArrayFieldContainer=_e,exports.ArrayFieldProvider=ne,exports.ArrayFieldRemoveButton=ye,exports.ArrayFieldRow=ve,exports.ArrayFieldRowContainer=he,exports.ArrayFieldRowFields=xe,exports.ArrayFieldRowProvider=ie,exports.ArrayFieldRows=Ee,exports.AutoForm=Le,exports.BaseField=k,exports.CheckboxField=H,exports.DisplayField=b,exports.DisplayIf=Pe,exports.Field=I,exports.Fields=De,exports.Form=Y,exports.FormLayout=ee,exports.FormLegend=Ce,exports.FormStep=We,exports.FormStepper=function(e){var r=u.useMultiStyleConfig("Stepper",e),t=x.Children.map(e.children,function(e){if(x.isValidElement(e)&&(null==e?void 0:e.type)===We){var r=Me(e.props);/*#__PURE__*/return x.createElement(p.StepperStep,{name:e.props.name,title:e.props.title,isCompleted:r.isCompleted},e.props.children)}return e});/*#__PURE__*/return x.createElement(u.StylesProvider,{value:r},/*#__PURE__*/x.createElement(p.StepperSteps,h({mb:"4"},e),t))},exports.FormValue=E,exports.InputField=O,exports.NativeSelectField=W,exports.NextButton=Ke,exports.NumberInputField=j,exports.ObjectField=Se,exports.PasswordInputFIeld=q,exports.PinField=z,exports.PrevButton=Je,exports.RadioField=G,exports.SelectField=T,exports.StepForm=ze,exports.StepFormProvider=Oe,exports.SubmitButton=ke,exports.SwitchField=U,exports.TextareaField=M,exports.objectFieldResolver=Q,exports.registerFieldType=B,exports.useArrayField=se,exports.useArrayFieldAddButton=me,exports.useArrayFieldContext=ae,exports.useArrayFieldRemoveButton=de,exports.useArrayFieldRow=ue,exports.useArrayFieldRowContext=oe,exports.useFormStep=Me,exports.useStepForm=qe,exports.useStepFormContext=je,exports.withControlledInput=L,exports.withUncontrolledInput=P,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/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../src/use-step-form.tsx","../src/step-form.tsx"],"sourcesContent":["import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n DisplayField.displayName = 'DisplayField'\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n\nif (__DEV__) {\n FormValue.displayName = 'FormValue'\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'\nimport { __DEV__ } from '@chakra-ui/utils'\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}\n\nif (__DEV__) {\n BaseField.displayName = 'BaseField'\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 id,\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 id={id}\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 id={id}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema) =>\n schema &&\n Object.entries(schema).map(([name, field]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\nimport { css } from '@emotion/react'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n className={cx('saas-form', props.className)}\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 displayName?: string\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nif (__DEV__) {\n Form.displayName = 'Form'\n}\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n FormLayoutItem.displayName = 'FormLayoutItem'\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\n {...gridProps}\n className={cx('saas-form__layout', props.className)}\n >\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\nif (__DEV__) {\n FormLayout.displayName = 'FormLayout'\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'\nimport { __DEV__ } from '@chakra-ui/utils'\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 children: React.ReactNode\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\nif (__DEV__) {\n ArrayFieldRow.displayName = 'ArrayFieldRow'\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 children: React.ReactNode\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\nif (__DEV__) {\n ArrayFieldRowFields.displayName = 'ArrayFieldRowFields'\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\nif (__DEV__) {\n ArrayFieldRowContainer.displayName = 'ArrayFieldRowContainer'\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\nif (__DEV__) {\n ArrayFieldRemoveButton.displayName = 'ArrayFieldRemoveButton'\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\nif (__DEV__) {\n ArrayFieldAddButton.displayName = 'ArrayFieldAddButton'\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\nif (__DEV__) {\n ArrayField.displayName = 'ArrayField'\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\nif (__DEV__) {\n ArrayFieldRows.displayName = 'ArrayFieldRows'\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\nif (__DEV__) {\n ArrayFieldContainer.displayName = 'ArrayFieldContainer'\n}\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n ObjectField.displayName = 'ObjectField'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n\nif (__DEV__) {\n Fields.displayName = 'Fields'\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n SubmitButton.displayName = 'SubmitButton'\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n submitLabel?: false | string\n schema: any\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', fieldResolver, ...rest } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n displayName?: string\n getFieldResolver?: (schema: any) => FieldResolver\n}\n\nif (__DEV__) {\n AutoForm.displayName = 'AutoForm'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n DisplayIf.displayName = 'DisplayIf'\n}\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 Omit<FormProps<TFieldValues>, 'children'> {\n children:\n | React.ReactNode\n | ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement)\n}\n\nexport interface UseStepFormReturn<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperReturn {\n getFormProps(): {\n onSubmit: SubmitHandler<TFieldValues>\n schema?: any\n resolver?: any\n }\n updateStep(step: any): void\n steps: Record<string, any>\n}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n): UseStepFormReturn<TFieldValues> {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState<Record<string, StepState>>({})\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 const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n }, [steps, onSubmitStep, activeStep])\n\n const updateStep = React.useCallback(\n (step: StepState) => {\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 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 SystemStyleObject,\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 UseStepFormReturn,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<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, ...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()}>\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"],"names":["_excluded","DisplayField","_ref","name","label","props","React","createElement","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","_ref2","getValues","useFormContext","inputTypes","BaseField","help","variant","hideLabel","children","controlProps","_objectWithoutPropertiesLoose","error","formState","get","errors","getError","_extends","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","_props$type","withControlledInput","InputComponent","_ref3","rules","inputProps","_excluded3","Controller","control","_useFormContext2","render","_ref4","_ref4$field","field","_excluded4","useMergeRefs","withUncontrolledInput","_ref5","_excluded5","register","_register","_excluded6","registerFieldType","component","options","id","isDisabled","isReadOnly","isRequired","_excluded2","inputRules","required","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","_ref6","_excluded7","Switch","SelectField","Select","CheckboxField","_ref7","_excluded8","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","getFields","getNestedFields","_field$items","items","properties","Form","mode","_props$mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","objectFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","gridProps","theme","useTheme","components","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","_createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","_ref$defaultValue","defaultValue","keyName","min","max","context","useFieldArray","useArrayFieldRow","index","clearErrors","_useArrayFieldContext","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","_useArrayFieldRowCont","_useArrayFieldContext2","onClick","append","_useArrayFieldContext3","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","useArrayFieldAddButton","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","_props$submitLabel","DisplayIf","condition","_ref$condition","useWatch","disabled","exact","isExact","errorMessage","StepFormProvider","useStepFormContext","stepper","useStepper","activeStep","isLastStep","nextStep","_React$useState","useState","steps","updateSteps","onSubmitStep","data","Promise","resolve","then","updateStep","step","isCompleted","e","reject","getFormProps","_extends2","useStep","_useStepFormContext","StepForm","useStepForm","ctx","StepperProvider","runIfFn","FormStep","useFormStep","isActive","PrevButton","useStepperContext","prevStep","_useStepperContext","isFirstStep","callAllHandlers","NextButton","_props$label","_useStepperContext2","useMultiStyleConfig","_useFormStep","StepperStep","title","StylesProvider","StepperSteps","elements"],"mappings":"omCAAA,IAAAA,EAAA,CAAA,OAAA,QAAA,eAiByBC,EAAgC,SAAAC,GACvDC,IAAAA,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,MAEGC,sBAEH,OACEC,EAAAC,cAACC,EAADA,YAAiBH,EACdD,eAAQE,EAACC,cAAAE,EAADA,UAAW,CAAAC,QAASP,GAAOC,GAAqB,kBACzDE,EAAAC,cAACI,EAADA,KAAA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AAtCgP,YAAAA,OAAc,IAAAC,EAAA,WAAepH,EAAAA,EAAS7H,EAAAA,MAC1B4R,EAAAA,EAAiBA,oBAAjChB,EAAAA,EAAAA,yBAEpB,OACE3Q,EAACC,cAAAoO,GACC3M,EAAA,CAAAoC,WAAY6M,EACZ7Q,MALJoS,EAAQpC,YAKiBa,EAAc5B,EAAcjP,GAC7C8H,EAHN,CAIES,UAAWC,EAAAA,GAAG,yBAA0BvI,EAAMsI,eAKhD7H,YACFwR,GAAWvR,YAAc,uiBAxF6B,SAACV,GACvD,MAAeoS,sBAAoB,UAAWpS,KAI7BC,EAAMsJ,SAAS/E,IAFXxE,EAAbmB,SAEsC,SAACqI,GAC7C,GAAIvJ,EAAMwJ,eAAeD,KAAU,MAAAA,OAAA,EAAAA,EAAOpH,QAASoP,GAAU,CAC3D,IAAAa,EAAwBZ,GAAYjI,EAAMxJ,oBAC1C,OACEC,EAACC,cAAAoS,EAAAA,YACC,CAAAxS,KAAM0J,EAAMxJ,MAAMF,KAClByS,MAAO/I,EAAMxJ,MAAMuS,MACnB3B,YALJyB,EAAQzB,aAOHpH,EAAMxJ,MAAMmB,UAInB,OAAOqI,iBAGT,OACEvJ,EAAAC,cAACsS,EAAAA,eAAD,CAAgBnG,MAAOqB,gBACrBzN,gBAACwS,EAAAA,aAAD9Q,EAAA,CAAcgL,GAAG,KAAQ3M,GACtB0S"}
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../src/use-step-form.tsx","../src/step-form.tsx"],"sourcesContent":["import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n DisplayField.displayName = 'DisplayField'\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n\nif (__DEV__) {\n FormValue.displayName = 'FormValue'\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'\nimport { __DEV__ } from '@chakra-ui/utils'\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}\n\nif (__DEV__) {\n BaseField.displayName = 'BaseField'\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 id,\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 id={id}\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 id={id}\n name={name}\n label={hideLabel ? label : undefined} // Only pass down the label when it should be inline.\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 the checkbox 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\nexport const InputField = registerFieldType(\n 'text',\n forwardRef(({ type = 'text', ...rest }, ref) => {\n return <Input type={type} {...rest} ref={ref} />\n })\n)\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(({ type, ...rest }, ref) => {\n return <Switch {...rest} ref={ref} />\n }),\n {\n isControlled: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(\n ({ label, type, ...props }: { label?: string; type: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }\n ),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema): FieldProps[] =>\n schema &&\n Object.entries(schema).map(([name, { items, ...field }]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\nimport { css } from '@emotion/react'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n className={cx('saas-form', props.className)}\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 displayName?: string\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nif (__DEV__) {\n Form.displayName = 'Form'\n}\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n FormLayoutItem.displayName = 'FormLayoutItem'\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\n {...gridProps}\n className={cx('saas-form__layout', props.className)}\n >\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\nif (__DEV__) {\n FormLayout.displayName = 'FormLayout'\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'\nimport { __DEV__ } from '@chakra-ui/utils'\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 children: React.ReactNode\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\nif (__DEV__) {\n ArrayFieldRow.displayName = 'ArrayFieldRow'\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 children: React.ReactNode\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\nif (__DEV__) {\n ArrayFieldRowFields.displayName = 'ArrayFieldRowFields'\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\nif (__DEV__) {\n ArrayFieldRowContainer.displayName = 'ArrayFieldRowContainer'\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\nif (__DEV__) {\n ArrayFieldRemoveButton.displayName = 'ArrayFieldRemoveButton'\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\nif (__DEV__) {\n ArrayFieldAddButton.displayName = 'ArrayFieldAddButton'\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\nif (__DEV__) {\n ArrayField.displayName = 'ArrayField'\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\nif (__DEV__) {\n ArrayFieldRows.displayName = 'ArrayFieldRows'\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\nif (__DEV__) {\n ArrayFieldContainer.displayName = 'ArrayFieldContainer'\n}\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyleConfig,\n} from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\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 = useStyleConfig('FormLegend')\n return <FormLabel as=\"legend\" sx={styles} {...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\nif (__DEV__) {\n ObjectField.displayName = 'ObjectField'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n\nif (__DEV__) {\n Fields.displayName = 'Fields'\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n SubmitButton.displayName = 'SubmitButton'\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton, SubmitButtonProps } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n /**\n * The submit button label.\n * Pass `null` to render no submit button.\n */\n submitLabel?: React.ReactNode\n /**\n * The schema.\n * Supports object schema, Yup or Zod.\n * @see https://www.saas-ui.dev/docs/forms/auto-form\n */\n schema: any\n /**\n * The field resolver.\n */\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 {\n schema,\n submitLabel = 'Submit',\n fieldResolver,\n children,\n ...rest\n } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n {children}\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 displayName?: string\n getFieldResolver?: (schema: any) => FieldResolver\n}\n\nif (__DEV__) {\n AutoForm.displayName = 'AutoForm'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n DisplayIf.displayName = 'DisplayIf'\n}\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 Omit<FormProps<TFieldValues>, 'children'> {\n children:\n | React.ReactNode\n | ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement)\n}\n\nexport interface UseStepFormReturn<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperReturn {\n getFormProps(): {\n onSubmit: SubmitHandler<TFieldValues>\n schema?: any\n resolver?: any\n }\n updateStep(step: any): void\n steps: Record<string, any>\n}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n): UseStepFormReturn<TFieldValues> {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState<Record<string, StepState>>({})\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 const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n }, [steps, onSubmitStep, activeStep])\n\n const updateStep = React.useCallback(\n (step: StepState) => {\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 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 SystemStyleObject,\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 UseStepFormReturn,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<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, ...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()}>\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"],"names":["_excluded","DisplayField","_ref","name","label","props","React","createElement","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","_ref2","getValues","useFormContext","_excluded2","_excluded3","_excluded4","_excluded5","_excluded6","_excluded7","_excluded8","_excluded9","inputTypes","BaseField","help","variant","hideLabel","children","controlProps","_objectWithoutPropertiesLoose","error","formState","get","errors","getError","_extends","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","_props$type","type","withControlledInput","InputComponent","_ref3","rules","inputProps","_useFormContext2","Controller","control","render","field","_ref4$field","useMergeRefs","withUncontrolledInput","_ref5","_register","register","registerFieldType","component","options","id","isDisabled","isReadOnly","isRequired","inputRules","required","undefined","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","_ref6$type","_ref6","rest","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","_ref7","Switch","SelectField","Select","CheckboxField","_ref8","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","_field$items","items","properties","Form","mode","_props$mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","gridProps","theme","useTheme","components","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","_createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","_ref$defaultValue","defaultValue","keyName","min","max","context","useFieldArray","useArrayFieldRow","index","clearErrors","_useArrayFieldContext","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","_useArrayFieldRowCont","_useArrayFieldContext2","onClick","append","_useArrayFieldContext3","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","useArrayFieldAddButton","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","_ref4","fieldProps","FormLegend","styles","useStyleConfig","as","sx","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","_props$submitLabel","submitLabel","DisplayIf","condition","_ref$condition","useWatch","disabled","exact","isExact","errorMessage","StepFormProvider","useStepFormContext","stepper","useStepper","activeStep","isLastStep","nextStep","_React$useState","useState","steps","updateSteps","onSubmitStep","data","Promise","resolve","then","updateStep","step","isCompleted","e","reject","getFormProps","_extends2","useStep","_useStepFormContext","StepForm","useStepForm","ctx","StepperProvider","runIfFn","FormStep","useFormStep","isActive","PrevButton","useStepperContext","prevStep","_useStepperContext","isFirstStep","callAllHandlers","NextButton","_props$label","_useStepperContext2","useMultiStyleConfig","_useFormStep","StepperStep","title","StylesProvider","StepperSteps","elements"],"mappings":"omCAAA,IAAAA,EAAA,CAAA,OAAA,QAAA,eAiByBC,EAAgC,SAAAC,GACvDC,IAAAA,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,MAEGC,sBAEH,OACEC,EAAAC,cAACC,EAADA,YAAiBH,EACdD,eAAQE,EAACC,cAAAE,EAADA,UAAW,CAAAC,QAASP,GAAOC,GAAqB,kBACzDE,EAAAC,cAACI,EAADA,KAAA,CAAMC,SAAS,mBACbN,EAACC,cAAAM,EAAU,CAAAV,KAAMA,OAMrBW,EAAAA,UACFb,EAAac,YAAc,gBAGhBF,MAAwC,SAAAG,GAAGb,IAAAA,EAAAA,EAAAA,KAEtD,OAAOc,EADeC,EAAcA,iBAA5BD,WACSd,IAAS,MAGxBW,EAAAA,UACFD,EAAUE,YAAc,aC3C1B,IAAAf,EAAA,CAAA,OAAA,QAAA,OAAA,UAAA,YAAA,YAAAmB,EAAA,CAAA,KAAA,OAAA,QAAA,OAAA,aAAA,YAAA,aAAA,aAAA,QAAA,WAAAC,EAAA,CAAA,OAAA,SAAAC,EAAA,CAAA,OAAAC,EAAA,CAAA,OAAA,SAAAC,EAAA,CAAA,OAAAC,EAAA,CAAA,QAAAC,EAAA,CAAA,QAAAC,EAAA,CAAA,QAAA,QAiHMC,EAAsC,GAmBtBC,EAAyB,SAACvB,GAC9C,IAAQF,EACNE,EADMF,KAAMC,EACZC,EADYD,MAAOyB,EACnBxB,EADmBwB,KAAMC,EACzBzB,EADyByB,QAASC,EAClC1B,EADkC0B,UAAWC,EAC7C3B,EAD6C2B,SAAaC,EAA5DC,EACE7B,EADFL,GAKMmC,EAjBS,SAAChC,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BA,oBAAjChB,EAAAA,EAAAA,yBAEpB,OACE9Q,EAACC,cAAAuO,GACCtM,EAAA,CAAA+B,WAAY6M,EACZhR,MALJuS,EAAQpC,YAKiBa,EAAc3B,EAAcrP,GAC7CqF,EAHN,CAIEsD,UAAWC,EAAAA,GAAG,yBAA0B3I,EAAM0I,eAKhDjI,YACF2R,GAAW1R,YAAc,wiBAxF6B,SAACV,GACvD,MAAeuS,sBAAoB,UAAWvS,KAI7BC,EAAMyJ,SAAS/E,IAFX3E,EAAb2B,SAEsC,SAACgI,GAC7C,GAAI1J,EAAM2J,eAAeD,KAAU,MAAAA,OAAA,EAAAA,EAAO9G,QAAS8O,GAAU,CAC3D,IAAAa,EAAwBZ,GAAYjI,EAAM3J,oBAC1C,OACEC,EAACC,cAAAuS,EAAAA,YACC,CAAA3S,KAAM6J,EAAM3J,MAAMF,KAClB4S,MAAO/I,EAAM3J,MAAM0S,MACnB3B,YALJyB,EAAQzB,aAOHpH,EAAM3J,MAAM2B,UAInB,OAAOgI,iBAGT,OACE1J,EAAAC,cAACyS,EAAAA,eAAD,CAAgBnG,MAAOsB,gBACrB7N,gBAAC2S,EAAAA,aAADzQ,EAAA,CAAc2K,GAAG,KAAQ9M,GACtB6S"}
|
package/dist/index.modern.mjs
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import*as e from"react";import{__DEV__ as t,get as a,cx as l,runIfFn as r,callAllHandlers as n}from"@chakra-ui/utils";import{useFormContext as s,get as i,Controller as o,useForm as m,FormProvider as c,useFieldArray as d,useWatch as u}from"react-hook-form";import{FormControl as p,FormLabel as f,Text as h,forwardRef as b,Switch as y,Checkbox as E,Box as v,FormHelperText as N,FormErrorMessage as F,useMergeRefs as g,Input as x,Textarea as C,chakra as k,useTheme as S,SimpleGrid as R,useStyles as V}from"@chakra-ui/react";import{NumberInput as L}from"@saas-ui/number-input";import{PasswordInput as w}from"@saas-ui/password-input";import{RadioInput as I}from"@saas-ui/radio";import{PinInput as A}from"@saas-ui/pin-input";import{Select as D,NativeSelect as O}from"@saas-ui/select";import{chakra as j,forwardRef as B,useMultiStyleConfig as U,StylesProvider as _}from"@chakra-ui/system";import{MinusIcon as M,AddIcon as P}from"@chakra-ui/icons";import{IconButton as $,Button as q}from"@saas-ui/button";import{createContext as G}from"@chakra-ui/react-utils";import{useStepper as H,useStep as z,StepperProvider as J,StepperStep as K,StepperSteps as Q,useStepperContext as T}from"@saas-ui/stepper";export*from"@saas-ui/input-right-button";function W(){return W=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(e[l]=a[l])}return e},W.apply(this,arguments)}function X(e,t){if(null==e)return{};var a,l,r={},n=Object.keys(e);for(l=0;l<n.length;l++)t.indexOf(a=n[l])>=0||(r[a]=e[a]);return r}const Y=["name","label","placeholder"],Z=t=>{let{name:a,label:l}=t,r=X(t,Y);/*#__PURE__*/return e.createElement(p,r,l?/*#__PURE__*/e.createElement(f,{htmlFor:a},l):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(ee,{name:a})))};t&&(Z.displayName="DisplayField");const ee=({name:e})=>{const{getValues:t}=s();return t(e)||null};t&&(ee.displayName="FormValue");const te=["name","label","help","variant","hideLabel","children"],ae=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],le=["name","rules"],re=["ref"],ne=["name","rules"],se=["ref"],ie=["label"],oe=["label"],me={},ce="text",de=t=>{const{name:a,label:l,help:r,variant:n,hideLabel:o,children:m}=t,c=X(t,te),{formState:d}=s(),u=((e,t)=>i(t.errors,e))(a,d);/*#__PURE__*/return e.createElement(p,W({variant:n},c,{isInvalid:!!u}),l&&!o?/*#__PURE__*/e.createElement(f,{variant:n},l):null,/*#__PURE__*/e.createElement(v,null,m,!r||null!=u&&u.message?null:/*#__PURE__*/e.createElement(N,null,r),(null==u?void 0:u.message)&&/*#__PURE__*/e.createElement(F,null,null==u?void 0:u.message)))};t&&(de.displayName="BaseField");const ue=b((t,a)=>{const{type:l=ce}=t,r=(e=>me[e]||me[ce])(l);/*#__PURE__*/return e.createElement(r,W({ref:a},t))}),pe=t=>b((a,l)=>{let{name:r,rules:n}=a,i=X(a,le);const{control:m}=s();/*#__PURE__*/return e.createElement(o,{name:r,control:m,rules:n,render:a=>{let{field:{ref:r}}=a,n=X(a.field,re);/*#__PURE__*/return e.createElement(t,W({},n,i,{ref:g(l,r)}))}})}),fe=t=>b((a,l)=>{let{name:r,rules:n}=a,i=X(a,ne);const{register:o}=s(),m=o(r,n),{ref:c}=m,d=X(m,se);/*#__PURE__*/return e.createElement(t,W({},d,i,{ref:g(l,c)}))}),he=(t,a,l)=>{let r;r=null!=l&&l.isControlled?pe(a):fe(a);const n=((t,{displayName:a,hideLabel:l,BaseField:r})=>{const n=b((a,n)=>{const{id:s,name:i,label:o,help:m,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,rules:f,variant:h}=a,b=X(a,ae),y=W({required:p},f);/*#__PURE__*/return e.createElement(r,{id:s,name:i,label:o,help:m,hideLabel:l,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,variant:h},/*#__PURE__*/e.createElement(t,W({ref:n,id:s,name:i,label:o,rules:y},b)))});return n.displayName=a,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==l?void 0:l.hideLabel,BaseField:(null==l?void 0:l.BaseField)||de});return me[t]=n,n},be=he("text",x),ye=he("number",L,{isControlled:!0}),Ee=he("password",w),ve=he("textarea",C),Ne=he("switch",b((t,a)=>{let{label:l}=t,r=X(t,ie);/*#__PURE__*/return e.createElement(y,W({ref:a},r),l)}),{isControlled:!0,hideLabel:!0}),Fe=he("select",D,{isControlled:!0}),ge=he("checkbox",b((t,a)=>{let{label:l}=t,r=X(t,oe);/*#__PURE__*/return e.createElement(E,W({ref:a},r),l)}),{hideLabel:!0}),xe=he("radio",I,{isControlled:!0}),Ce=he("pin",A,{isControlled:!0}),ke=he("native-select",O,{isControlled:!0}),Se=e=>e&&Object.entries(e).map(([e,t])=>W({},t,{name:e})),Re=e=>({getFields:()=>Se(e),getNestedFields:t=>{var l;const r=a(e,t);return r?"object"===(null==(l=r.items)?void 0:l.type)?Se(r.items.properties):"object"===r.type?Se(r.properties):[r.items]:[]}}),Ve=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Le=b((t,a)=>{const{mode:r="all",resolver:n,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:d,criteriaMode:u,delayError:p,schema:f,defaultValues:h,onSubmit:b,onError:y,formRef:E,children:v}=t,N=X(t,Ve),F={mode:r,resolver:n,defaultValues:h,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:d,criteriaMode:u,delayError:p};f&&!n&&(F.resolver=null==Le.getResolver?void 0:Le.getResolver(f));const g=m(F),{handleSubmit:x}=g;return e.useImperativeHandle(a,()=>g,[a,g]),/*#__PURE__*/e.createElement(c,g,/*#__PURE__*/e.createElement(k.form,W({ref:E,onSubmit:x(b,y)},N,{className:l("saas-form",t.className)}),v))});Le.getFieldResolver=Re,t&&(Le.displayName="Form");const we=["children"],Ie=({children:t})=>/*#__PURE__*/e.createElement(k.div,null,t);t&&(Ie.displayName="FormLayoutItem");const Ae=t=>{var a,r,n;let{children:s}=t,i=X(t,we);const o=W({},null!=(a=null==(r=S().components)||null==(n=r.FormLayout)?void 0:n.defaultProps)?a:{spacing:4},i);/*#__PURE__*/return e.createElement(R,W({},o,{className:l("saas-form__layout",i.className)}),e.Children.map(s,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(Ie,null,t):t))};t&&(Ae.displayName="FormLayout");const De=(t,a)=>e.Children.map(a,a=>e.isValidElement(a)&&a.props.name?e.cloneElement(a,W({},a.props,{name:`${t}.${a.props.name}`})):a),[Oe,je]=G({name:"ArrayFieldContext"}),[Be,Ue]=G({name:"ArrayFieldRowContext"}),_e=({name:e,defaultValue:t={},keyName:a,min:l,max:r})=>{const{control:n}=s();return W({},d({control:n,name:e,keyName:a}),{name:e,defaultValue:t,min:l,max:r})},Me=({index:t})=>{const{clearErrors:a}=s(),{name:l,remove:r,fields:n}=je();return e.useEffect(()=>{a(l)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${l}.${t}`,remove:e.useCallback(()=>{a(l),r(t)},[t])}},Pe=()=>{const{isFirst:e,remove:t}=Ue(),{min:a,fields:l}=je();return{onClick:()=>t(),isDisabled:e&&!!(a&&l.length<=a)}},$e=()=>{const{append:e,defaultValue:t,max:a,fields:l}=je();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(a&&l.length>=a)}},qe=["children","columns","spacing"],Ge=["children"],He=["name","defaultValue","keyName","min","max","children"],ze=({children:t,columns:a,spacing:l,index:r})=>/*#__PURE__*/e.createElement(Ke,{index:r},/*#__PURE__*/e.createElement(Je,{columns:a,spacing:l},t),/*#__PURE__*/e.createElement(Qe,null));t&&(ze.displayName="ArrayFieldRow");const Je=t=>{let{children:a,columns:l,spacing:r}=t,n=X(t,qe);const{name:s}=Ue();/*#__PURE__*/return e.createElement(Ae,W({flex:"1",columns:l,gridGap:r,mr:"2"},n),De(s,a))};t&&(Je.displayName="ArrayFieldRowFields");const Ke=({children:t,index:a})=>{const l=Me({index:a});/*#__PURE__*/return e.createElement(Be,{value:l},/*#__PURE__*/e.createElement(j.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))};t&&(Ke.displayName="ArrayFieldRowContainer");const Qe=t=>/*#__PURE__*/e.createElement($,W({icon:/*#__PURE__*/e.createElement(M,null),"aria-label":"Remove row"},Pe(),t));t&&(Qe.displayName="ArrayFieldRemoveButton");const Te=t=>/*#__PURE__*/e.createElement($,W({icon:/*#__PURE__*/e.createElement(P,null),"aria-label":"Add row",float:"right"},$e(),t));t&&(Te.displayName="ArrayFieldAddButton");const We=e.forwardRef((t,a)=>{const{children:l}=t,r=X(t,Ge);/*#__PURE__*/return e.createElement(Ye,W({ref:a},r),/*#__PURE__*/e.createElement(Xe,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},a)=>/*#__PURE__*/e.createElement(ze,{key:t,index:a},l)))),/*#__PURE__*/e.createElement(Te,null))});t&&(We.displayName="ArrayField");const Xe=({children:e})=>{const{fields:t}=je();return e(t)};t&&(Xe.displayName="ArrayFieldRows");const Ye=e.forwardRef((t,a)=>{let{name:l,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=X(t,He);const c=_e({name:l,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(a,()=>c,[a,c]),/*#__PURE__*/e.createElement(Oe,{value:c},/*#__PURE__*/e.createElement(de,W({name:l},m),o))});t&&(Ye.displayName="ArrayFieldContainer");const Ze=["name","label","hideLabel","children","columns","spacing"],et=t=>{const a=V();/*#__PURE__*/return e.createElement(f,W({as:"legend",sx:a.legend},t))},tt=t=>{const{name:a,label:l,hideLabel:r,children:n,columns:s,spacing:i}=t,o=X(t,Ze);/*#__PURE__*/return e.createElement(p,W({name:a,as:"fieldset"},o),/*#__PURE__*/e.createElement(et,{display:r?"none":"block"},l),/*#__PURE__*/e.createElement(Ae,{columns:s,gridGap:i},De(a,n)))};t&&(tt.displayName="ObjectField");const at=["name","type"],lt=["schema","fieldResolver"],rt=["name","type","defaultValue"],nt=(t,a)=>{var l;return null==(l=t.getNestedFields(a))?void 0:l.map((t,a)=>{let{name:l,type:r}=t,n=X(t,at);/*#__PURE__*/return e.createElement(ue,W({key:l||a,name:l,type:r},n))})},st=t=>{let{schema:a,fieldResolver:l}=t,r=X(t,lt);const n=e.useMemo(()=>l||Le.getFieldResolver(a),[a,l]);/*#__PURE__*/return e.createElement(Ae,r,n.getFields().map(t=>{let{name:a,type:l}=t,r=X(t,rt);return"array"===l?/*#__PURE__*/e.createElement(We,W({key:a,name:a},r),nt(n,a)):"object"===l?/*#__PURE__*/e.createElement(tt,W({key:a,name:a},r),nt(n,a)):/*#__PURE__*/e.createElement(ue,W({key:a,name:a,type:l},r))}))};t&&(st.displayName="Fields");const it=["children","disableIfUntouched","disableIfInvalid"],ot=B((t,a)=>{const{children:l,disableIfUntouched:r,disableIfInvalid:n}=t,i=X(t,it),{formState:o}=s();/*#__PURE__*/return e.createElement(q,W({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:a,isDisabled:r&&!o.isDirty||n&&!o.isValid},i),l)});ot.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(ot.displayName="SubmitButton");const mt=["schema","submitLabel","fieldResolver"],ct=b((t,a)=>{const{schema:l,submitLabel:r="Submit",fieldResolver:n}=t,s=X(t,mt);/*#__PURE__*/return e.createElement(Le,W({},s,{schema:l,ref:a}),/*#__PURE__*/e.createElement(Ae,null,/*#__PURE__*/e.createElement(st,{schema:l,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(ot,{label:r})))});t&&(ct.displayName="AutoForm");const dt=({children:e,name:t,defaultValue:a,isDisabled:l,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:a,disabled:l,exact:r}),s())?e:null;t&&(dt.displayName="DisplayIf");const[ut,pt]=G({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function ft(t){const a=H(t),{activeStep:l,isLastStep:r,nextStep:n}=a,[s,i]=e.useState({}),o=e.useCallback(async e=>{if(r)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{c(W({},s[l],{isCompleted:!0}))}).then(n);n()},[l,r]),m=e.useCallback(()=>{const e=s[l];return{onSubmit:o,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[s,o,l]),c=e.useCallback(e=>{i(t=>W({},t,{[e.name]:e}))},[s]);return W({getFormProps:m,updateStep:c,steps:s},a)}function ht(t){const{name:a,schema:l,resolver:r}=t,n=z({name:a}),{steps:s,updateStep:i}=pt();return e.useEffect(()=>{i({name:a,schema:l,resolver:r})},[a,l]),W({},n,s[a]||{name:a,schema:l})}const bt=["children"],yt=["getFormProps"],Et=["name","schema","resolver","children","className"],vt=["label","submitLabel"],Nt=e.forwardRef((t,a)=>{const{children:l}=t,n=X(t,bt),s=ft(t),{getFormProps:i}=s,o=X(s,yt),m=e.useMemo(()=>o,[o]);/*#__PURE__*/return e.createElement(J,{value:m},/*#__PURE__*/e.createElement(ut,{value:m},/*#__PURE__*/e.createElement(Le,W({ref:a},n,i()),r(l,s))))}),Ft=t=>{const a=U("Stepper",t),{children:l}=t,r=e.Children.map(l,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===gt){const{isCompleted:a}=ht(t.props);/*#__PURE__*/return e.createElement(K,{name:t.props.name,title:t.props.title,isCompleted:a},t.props.children)}return t});/*#__PURE__*/return e.createElement(_,{value:a},/*#__PURE__*/e.createElement(Q,W({mb:"4"},t),r))},gt=t=>{const{name:a,schema:r,resolver:n,children:s,className:i}=t,o=X(t,Et),m=ht({name:a,schema:r,resolver:n}),{isActive:c}=m;return c?/*#__PURE__*/e.createElement(j.div,W({},o,{className:l("saas-form__step",i)}),s):null};t&&(gt.displayName="FormStep");const xt=t=>{const{isFirstStep:a,isCompleted:r,prevStep:s}=T();/*#__PURE__*/return e.createElement(q,W({isDisabled:a||r,label:"Back"},t,{className:l("saas-form__prev-button",t.className),onClick:n(t.onClick,s)}))};t&&(xt.displayName="PrevButton");const Ct=t=>{const{label:a="Next",submitLabel:r="Complete"}=t,n=X(t,vt),{isLastStep:s,isCompleted:i}=T();/*#__PURE__*/return e.createElement(ot,W({isDisabled:i,label:s||i?r:a},n,{className:l("saas-form__next-button",t.className)}))};t&&(Ct.displayName="NextButton");export{We as ArrayField,Te as ArrayFieldAddButton,Ye as ArrayFieldContainer,Oe as ArrayFieldProvider,Qe as ArrayFieldRemoveButton,ze as ArrayFieldRow,Ke as ArrayFieldRowContainer,Je as ArrayFieldRowFields,Be as ArrayFieldRowProvider,Xe as ArrayFieldRows,ct as AutoForm,de as BaseField,ge as CheckboxField,Z as DisplayField,dt as DisplayIf,ue as Field,st as Fields,Le as Form,Ae as FormLayout,et as FormLegend,gt as FormStep,Ft as FormStepper,ee as FormValue,be as InputField,ke as NativeSelectField,Ct as NextButton,ye as NumberInputField,tt as ObjectField,Ee as PasswordInputFIeld,Ce as PinField,xt as PrevButton,xe as RadioField,Fe as SelectField,Nt as StepForm,ut as StepFormProvider,ot as SubmitButton,Ne as SwitchField,ve as TextareaField,Re as objectFieldResolver,he as registerFieldType,_e as useArrayField,$e as useArrayFieldAddButton,je as useArrayFieldContext,Pe as useArrayFieldRemoveButton,Me as useArrayFieldRow,Ue as useArrayFieldRowContext,ht as useFormStep,ft as useStepForm,pt as useStepFormContext,pe as withControlledInput,fe as withUncontrolledInput};
|
1
|
+
import*as e from"react";import{__DEV__ as t,get as a,cx as l,runIfFn as r,callAllHandlers as n}from"@chakra-ui/utils";import{useFormContext as s,get as i,Controller as o,useForm as m,FormProvider as c,useFieldArray as d,useWatch as u}from"react-hook-form";import{FormControl as p,FormLabel as f,Text as h,forwardRef as b,Input as y,Switch as E,Checkbox as v,Box as F,FormHelperText as N,FormErrorMessage as g,useMergeRefs as x,Textarea as C,chakra as k,useTheme as S,SimpleGrid as R,useStyleConfig as V}from"@chakra-ui/react";import{NumberInput as L}from"@saas-ui/number-input";import{PasswordInput as w}from"@saas-ui/password-input";import{RadioInput as I}from"@saas-ui/radio";import{PinInput as A}from"@saas-ui/pin-input";import{Select as D,NativeSelect as O}from"@saas-ui/select";import{chakra as j,forwardRef as B,useMultiStyleConfig as U,StylesProvider as _}from"@chakra-ui/system";import{MinusIcon as M,AddIcon as P}from"@chakra-ui/icons";import{IconButton as $,Button as q}from"@saas-ui/button";import{createContext as G}from"@chakra-ui/react-utils";import{useStepper as H,useStep as z,StepperProvider as J,StepperStep as K,StepperSteps as Q,useStepperContext as T}from"@saas-ui/stepper";export*from"@saas-ui/input-right-button";function W(){return W=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(e[l]=a[l])}return e},W.apply(this,arguments)}function X(e,t){if(null==e)return{};var a,l,r={},n=Object.keys(e);for(l=0;l<n.length;l++)t.indexOf(a=n[l])>=0||(r[a]=e[a]);return r}const Y=["name","label","placeholder"],Z=t=>{let{name:a,label:l}=t,r=X(t,Y);/*#__PURE__*/return e.createElement(p,r,l?/*#__PURE__*/e.createElement(f,{htmlFor:a},l):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(ee,{name:a})))};t&&(Z.displayName="DisplayField");const ee=({name:e})=>{const{getValues:t}=s();return t(e)||null};t&&(ee.displayName="FormValue");const te=["name","label","help","variant","hideLabel","children"],ae=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],le=["name","rules"],re=["ref"],ne=["name","rules"],se=["ref"],ie=["type"],oe=["type"],me=["label","type"],ce={},de="text",ue=t=>{const{name:a,label:l,help:r,variant:n,hideLabel:o,children:m}=t,c=X(t,te),{formState:d}=s(),u=((e,t)=>i(t.errors,e))(a,d);/*#__PURE__*/return e.createElement(p,W({variant:n},c,{isInvalid:!!u}),l&&!o?/*#__PURE__*/e.createElement(f,{variant:n},l):null,/*#__PURE__*/e.createElement(F,null,m,!r||null!=u&&u.message?null:/*#__PURE__*/e.createElement(N,null,r),(null==u?void 0:u.message)&&/*#__PURE__*/e.createElement(g,null,null==u?void 0:u.message)))};t&&(ue.displayName="BaseField");const pe=b((t,a)=>{const{type:l=de}=t,r=(e=>ce[e]||ce[de])(l);/*#__PURE__*/return e.createElement(r,W({ref:a},t))}),fe=t=>b((a,l)=>{let{name:r,rules:n}=a,i=X(a,le);const{control:m}=s();/*#__PURE__*/return e.createElement(o,{name:r,control:m,rules:n,render:a=>{let{field:{ref:r}}=a,n=X(a.field,re);/*#__PURE__*/return e.createElement(t,W({},n,i,{ref:x(l,r)}))}})}),he=t=>b((a,l)=>{let{name:r,rules:n}=a,i=X(a,ne);const{register:o}=s(),m=o(r,n),{ref:c}=m,d=X(m,se);/*#__PURE__*/return e.createElement(t,W({},d,i,{ref:x(l,c)}))}),be=(t,a,l)=>{let r;r=null!=l&&l.isControlled?fe(a):he(a);const n=((t,{displayName:a,hideLabel:l,BaseField:r})=>{const n=b((a,n)=>{const{id:s,name:i,label:o,help:m,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,rules:f,variant:h}=a,b=X(a,ae),y=W({required:p},f);/*#__PURE__*/return e.createElement(r,{id:s,name:i,label:o,help:m,hideLabel:l,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,variant:h},/*#__PURE__*/e.createElement(t,W({ref:n,id:s,name:i,label:l?o:void 0,rules:y},b)))});return n.displayName=a,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==l?void 0:l.hideLabel,BaseField:(null==l?void 0:l.BaseField)||ue});return ce[t]=n,n},ye=be("text",b((t,a)=>{let{type:l="text"}=t,r=X(t,ie);/*#__PURE__*/return e.createElement(y,W({type:l},r,{ref:a}))})),Ee=be("number",L,{isControlled:!0}),ve=be("password",w),Fe=be("textarea",C),Ne=be("switch",b((t,a)=>{let l=X(t,oe);/*#__PURE__*/return e.createElement(E,W({},l,{ref:a}))}),{isControlled:!0}),ge=be("select",D,{isControlled:!0}),xe=be("checkbox",b((t,a)=>{let{label:l}=t,r=X(t,me);/*#__PURE__*/return e.createElement(v,W({ref:a},r),l)}),{hideLabel:!0}),Ce=be("radio",I,{isControlled:!0}),ke=be("pin",A,{isControlled:!0}),Se=be("native-select",O,{isControlled:!0}),Re=["items"],Ve=e=>e&&Object.entries(e).map(([e,t])=>W({},X(t,Re),{name:e})),Le=e=>({getFields:()=>Ve(e),getNestedFields:t=>{var l;const r=a(e,t);return r?"object"===(null==(l=r.items)?void 0:l.type)?Ve(r.items.properties):"object"===r.type?Ve(r.properties):[r.items]:[]}}),we=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Ie=b((t,a)=>{const{mode:r="all",resolver:n,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:d,criteriaMode:u,delayError:p,schema:f,defaultValues:h,onSubmit:b,onError:y,formRef:E,children:v}=t,F=X(t,we),N={mode:r,resolver:n,defaultValues:h,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:d,criteriaMode:u,delayError:p};f&&!n&&(N.resolver=null==Ie.getResolver?void 0:Ie.getResolver(f));const g=m(N),{handleSubmit:x}=g;return e.useImperativeHandle(a,()=>g,[a,g]),/*#__PURE__*/e.createElement(c,g,/*#__PURE__*/e.createElement(k.form,W({ref:E,onSubmit:x(b,y)},F,{className:l("saas-form",t.className)}),v))});Ie.getFieldResolver=Le,t&&(Ie.displayName="Form");const Ae=["children"],De=({children:t})=>/*#__PURE__*/e.createElement(k.div,null,t);t&&(De.displayName="FormLayoutItem");const Oe=t=>{var a,r,n;let{children:s}=t,i=X(t,Ae);const o=W({},null!=(a=null==(r=S().components)||null==(n=r.FormLayout)?void 0:n.defaultProps)?a:{spacing:4},i);/*#__PURE__*/return e.createElement(R,W({},o,{className:l("saas-form__layout",i.className)}),e.Children.map(s,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(De,null,t):t))};t&&(Oe.displayName="FormLayout");const je=(t,a)=>e.Children.map(a,a=>e.isValidElement(a)&&a.props.name?e.cloneElement(a,W({},a.props,{name:`${t}.${a.props.name}`})):a),[Be,Ue]=G({name:"ArrayFieldContext"}),[_e,Me]=G({name:"ArrayFieldRowContext"}),Pe=({name:e,defaultValue:t={},keyName:a,min:l,max:r})=>{const{control:n}=s();return W({},d({control:n,name:e,keyName:a}),{name:e,defaultValue:t,min:l,max:r})},$e=({index:t})=>{const{clearErrors:a}=s(),{name:l,remove:r,fields:n}=Ue();return e.useEffect(()=>{a(l)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${l}.${t}`,remove:e.useCallback(()=>{a(l),r(t)},[t])}},qe=()=>{const{isFirst:e,remove:t}=Me(),{min:a,fields:l}=Ue();return{onClick:()=>t(),isDisabled:e&&!!(a&&l.length<=a)}},Ge=()=>{const{append:e,defaultValue:t,max:a,fields:l}=Ue();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(a&&l.length>=a)}},He=["children","columns","spacing"],ze=["children"],Je=["name","defaultValue","keyName","min","max","children"],Ke=({children:t,columns:a,spacing:l,index:r})=>/*#__PURE__*/e.createElement(Te,{index:r},/*#__PURE__*/e.createElement(Qe,{columns:a,spacing:l},t),/*#__PURE__*/e.createElement(We,null));t&&(Ke.displayName="ArrayFieldRow");const Qe=t=>{let{children:a,columns:l,spacing:r}=t,n=X(t,He);const{name:s}=Me();/*#__PURE__*/return e.createElement(Oe,W({flex:"1",columns:l,gridGap:r,mr:"2"},n),je(s,a))};t&&(Qe.displayName="ArrayFieldRowFields");const Te=({children:t,index:a})=>{const l=$e({index:a});/*#__PURE__*/return e.createElement(_e,{value:l},/*#__PURE__*/e.createElement(j.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))};t&&(Te.displayName="ArrayFieldRowContainer");const We=t=>/*#__PURE__*/e.createElement($,W({icon:/*#__PURE__*/e.createElement(M,null),"aria-label":"Remove row"},qe(),t));t&&(We.displayName="ArrayFieldRemoveButton");const Xe=t=>/*#__PURE__*/e.createElement($,W({icon:/*#__PURE__*/e.createElement(P,null),"aria-label":"Add row",float:"right"},Ge(),t));t&&(Xe.displayName="ArrayFieldAddButton");const Ye=e.forwardRef((t,a)=>{const{children:l}=t,r=X(t,ze);/*#__PURE__*/return e.createElement(et,W({ref:a},r),/*#__PURE__*/e.createElement(Ze,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},a)=>/*#__PURE__*/e.createElement(Ke,{key:t,index:a},l)))),/*#__PURE__*/e.createElement(Xe,null))});t&&(Ye.displayName="ArrayField");const Ze=({children:e})=>{const{fields:t}=Ue();return e(t)};t&&(Ze.displayName="ArrayFieldRows");const et=e.forwardRef((t,a)=>{let{name:l,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=X(t,Je);const c=Pe({name:l,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(a,()=>c,[a,c]),/*#__PURE__*/e.createElement(Be,{value:c},/*#__PURE__*/e.createElement(ue,W({name:l},m),o))});t&&(et.displayName="ArrayFieldContainer");const tt=["name","label","hideLabel","children","columns","spacing"],at=t=>{const a=V("FormLegend");/*#__PURE__*/return e.createElement(f,W({as:"legend",sx:a},t))},lt=t=>{const{name:a,label:l,hideLabel:r,children:n,columns:s,spacing:i}=t,o=X(t,tt);/*#__PURE__*/return e.createElement(p,W({name:a,as:"fieldset"},o),/*#__PURE__*/e.createElement(at,{display:r?"none":"block"},l),/*#__PURE__*/e.createElement(Oe,{columns:s,gridGap:i},je(a,n)))};t&&(lt.displayName="ObjectField");const rt=["name","type"],nt=["schema","fieldResolver"],st=["name","type","defaultValue"],it=(t,a)=>{var l;return null==(l=t.getNestedFields(a))?void 0:l.map((t,a)=>{let{name:l,type:r}=t,n=X(t,rt);/*#__PURE__*/return e.createElement(pe,W({key:l||a,name:l,type:r},n))})},ot=t=>{let{schema:a,fieldResolver:l}=t,r=X(t,nt);const n=e.useMemo(()=>l||Ie.getFieldResolver(a),[a,l]);/*#__PURE__*/return e.createElement(Oe,r,n.getFields().map(t=>{let{name:a,type:l}=t,r=X(t,st);return"array"===l?/*#__PURE__*/e.createElement(Ye,W({key:a,name:a},r),it(n,a)):"object"===l?/*#__PURE__*/e.createElement(lt,W({key:a,name:a},r),it(n,a)):/*#__PURE__*/e.createElement(pe,W({key:a,name:a,type:l},r))}))};t&&(ot.displayName="Fields");const mt=["children","disableIfUntouched","disableIfInvalid"],ct=B((t,a)=>{const{children:l,disableIfUntouched:r,disableIfInvalid:n}=t,i=X(t,mt),{formState:o}=s();/*#__PURE__*/return e.createElement(q,W({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:a,isDisabled:r&&!o.isDirty||n&&!o.isValid},i),l)});ct.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(ct.displayName="SubmitButton");const dt=["schema","submitLabel","fieldResolver","children"],ut=b((t,a)=>{const{schema:l,submitLabel:r="Submit",fieldResolver:n,children:s}=t,i=X(t,dt);/*#__PURE__*/return e.createElement(Ie,W({},i,{schema:l,ref:a}),/*#__PURE__*/e.createElement(Oe,null,/*#__PURE__*/e.createElement(ot,{schema:l,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(ct,{label:r}),s))});t&&(ut.displayName="AutoForm");const pt=({children:e,name:t,defaultValue:a,isDisabled:l,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:a,disabled:l,exact:r}),s())?e:null;t&&(pt.displayName="DisplayIf");const[ft,ht]=G({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function bt(t){const a=H(t),{activeStep:l,isLastStep:r,nextStep:n}=a,[s,i]=e.useState({}),o=e.useCallback(async e=>{if(r)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{c(W({},s[l],{isCompleted:!0}))}).then(n);n()},[l,r]),m=e.useCallback(()=>{const e=s[l];return{onSubmit:o,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[s,o,l]),c=e.useCallback(e=>{i(t=>W({},t,{[e.name]:e}))},[s]);return W({getFormProps:m,updateStep:c,steps:s},a)}function yt(t){const{name:a,schema:l,resolver:r}=t,n=z({name:a}),{steps:s,updateStep:i}=ht();return e.useEffect(()=>{i({name:a,schema:l,resolver:r})},[a,l]),W({},n,s[a]||{name:a,schema:l})}const Et=["children"],vt=["getFormProps"],Ft=["name","schema","resolver","children","className"],Nt=["label","submitLabel"],gt=e.forwardRef((t,a)=>{const{children:l}=t,n=X(t,Et),s=bt(t),{getFormProps:i}=s,o=X(s,vt),m=e.useMemo(()=>o,[o]);/*#__PURE__*/return e.createElement(J,{value:m},/*#__PURE__*/e.createElement(ft,{value:m},/*#__PURE__*/e.createElement(Ie,W({ref:a},n,i()),r(l,s))))}),xt=t=>{const a=U("Stepper",t),{children:l}=t,r=e.Children.map(l,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===Ct){const{isCompleted:a}=yt(t.props);/*#__PURE__*/return e.createElement(K,{name:t.props.name,title:t.props.title,isCompleted:a},t.props.children)}return t});/*#__PURE__*/return e.createElement(_,{value:a},/*#__PURE__*/e.createElement(Q,W({mb:"4"},t),r))},Ct=t=>{const{name:a,schema:r,resolver:n,children:s,className:i}=t,o=X(t,Ft),m=yt({name:a,schema:r,resolver:n}),{isActive:c}=m;return c?/*#__PURE__*/e.createElement(j.div,W({},o,{className:l("saas-form__step",i)}),s):null};t&&(Ct.displayName="FormStep");const kt=t=>{const{isFirstStep:a,isCompleted:r,prevStep:s}=T();/*#__PURE__*/return e.createElement(q,W({isDisabled:a||r,label:"Back"},t,{className:l("saas-form__prev-button",t.className),onClick:n(t.onClick,s)}))};t&&(kt.displayName="PrevButton");const St=t=>{const{label:a="Next",submitLabel:r="Complete"}=t,n=X(t,Nt),{isLastStep:s,isCompleted:i}=T();/*#__PURE__*/return e.createElement(ct,W({isDisabled:i,label:s||i?r:a},n,{className:l("saas-form__next-button",t.className)}))};t&&(St.displayName="NextButton");export{Ye as ArrayField,Xe as ArrayFieldAddButton,et as ArrayFieldContainer,Be as ArrayFieldProvider,We as ArrayFieldRemoveButton,Ke as ArrayFieldRow,Te as ArrayFieldRowContainer,Qe as ArrayFieldRowFields,_e as ArrayFieldRowProvider,Ze as ArrayFieldRows,ut as AutoForm,ue as BaseField,xe as CheckboxField,Z as DisplayField,pt as DisplayIf,pe as Field,ot as Fields,Ie as Form,Oe as FormLayout,at as FormLegend,Ct as FormStep,xt as FormStepper,ee as FormValue,ye as InputField,Se as NativeSelectField,St as NextButton,Ee as NumberInputField,lt as ObjectField,ve as PasswordInputFIeld,ke as PinField,kt as PrevButton,Ce as RadioField,ge as SelectField,gt as StepForm,ft as StepFormProvider,ct as SubmitButton,Ne as SwitchField,Fe as TextareaField,Le as objectFieldResolver,be as registerFieldType,Pe as useArrayField,Ge as useArrayFieldAddButton,Ue as useArrayFieldContext,qe as useArrayFieldRemoveButton,$e as useArrayFieldRow,Me as useArrayFieldRowContext,yt as useFormStep,bt as useStepForm,ht as useStepFormContext,fe as withControlledInput,he as withUncontrolledInput};
|
2
2
|
//# sourceMappingURL=index.modern.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.modern.mjs","sources":["../src/display-field.tsx","../src/field.tsx","../src/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../src/use-step-form.tsx","../src/step-form.tsx"],"sourcesContent":["import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n DisplayField.displayName = 'DisplayField'\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n\nif (__DEV__) {\n FormValue.displayName = 'FormValue'\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'\nimport { __DEV__ } from '@chakra-ui/utils'\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}\n\nif (__DEV__) {\n BaseField.displayName = 'BaseField'\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 id,\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 id={id}\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 id={id}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema) =>\n schema &&\n Object.entries(schema).map(([name, field]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\nimport { css } from '@emotion/react'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n className={cx('saas-form', props.className)}\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 displayName?: string\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nif (__DEV__) {\n Form.displayName = 'Form'\n}\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n FormLayoutItem.displayName = 'FormLayoutItem'\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\n {...gridProps}\n className={cx('saas-form__layout', props.className)}\n >\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\nif (__DEV__) {\n FormLayout.displayName = 'FormLayout'\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'\nimport { __DEV__ } from '@chakra-ui/utils'\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 children: React.ReactNode\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\nif (__DEV__) {\n ArrayFieldRow.displayName = 'ArrayFieldRow'\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 children: React.ReactNode\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\nif (__DEV__) {\n ArrayFieldRowFields.displayName = 'ArrayFieldRowFields'\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\nif (__DEV__) {\n ArrayFieldRowContainer.displayName = 'ArrayFieldRowContainer'\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\nif (__DEV__) {\n ArrayFieldRemoveButton.displayName = 'ArrayFieldRemoveButton'\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\nif (__DEV__) {\n ArrayFieldAddButton.displayName = 'ArrayFieldAddButton'\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\nif (__DEV__) {\n ArrayField.displayName = 'ArrayField'\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\nif (__DEV__) {\n ArrayFieldRows.displayName = 'ArrayFieldRows'\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\nif (__DEV__) {\n ArrayFieldContainer.displayName = 'ArrayFieldContainer'\n}\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n ObjectField.displayName = 'ObjectField'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n\nif (__DEV__) {\n Fields.displayName = 'Fields'\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n SubmitButton.displayName = 'SubmitButton'\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n submitLabel?: false | string\n schema: any\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', fieldResolver, ...rest } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n displayName?: string\n getFieldResolver?: (schema: any) => FieldResolver\n}\n\nif (__DEV__) {\n AutoForm.displayName = 'AutoForm'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n DisplayIf.displayName = 'DisplayIf'\n}\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 Omit<FormProps<TFieldValues>, 'children'> {\n children:\n | React.ReactNode\n | ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement)\n}\n\nexport interface UseStepFormReturn<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperReturn {\n getFormProps(): {\n onSubmit: SubmitHandler<TFieldValues>\n schema?: any\n resolver?: any\n }\n updateStep(step: any): void\n steps: Record<string, any>\n}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n): UseStepFormReturn<TFieldValues> {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState<Record<string, StepState>>({})\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 const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n }, [steps, onSubmitStep, activeStep])\n\n const updateStep = React.useCallback(\n (step: StepState) => {\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 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 SystemStyleObject,\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 UseStepFormReturn,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<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, ...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()}>\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"],"names":["DisplayField","_ref","name","label","props","_objectWithoutPropertiesLoose","_excluded","React","createElement","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","getValues","useFormContext","inputTypes","defaultInputType","BaseField","help","variant","hideLabel","children","controlProps","formState","error","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","InputComponent","getInput","_extends","withControlledInput","rules","inputProps","_ref2","_excluded3","control","Controller","render","_ref3","field","_excluded4","useMergeRefs","withUncontrolledInput","_ref4","_excluded5","register","registerFieldType","component","options","isControlled","id","isDisabled","isReadOnly","isRequired","_excluded2","inputRules","required","createField","split","map","part","charAt","toUpperCase","slice","join","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","_ref5","_excluded7","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","_field$items","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","defaultProps","theme","useTheme","components","spacing","SimpleGrid","gridProps","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","context","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","columns","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","ArrayFieldRow","layoutProps","flex","gridGap","mr","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","Fragment","key","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","DisplayIf","isExact","condition","useWatch","disabled","exact","StepFormProvider","useStepFormContext","errorMessage","useStepForm","stepper","useStepper","activeStep","isLastStep","nextStep","steps","updateSteps","useState","onSubmitStep","async","data","then","updateStep","step","isCompleted","getFormProps","useFormStep","useStep","StepForm","ctx","StepperProvider","runIfFn","FormStepper","useMultiStyleConfig","elements","FormStep","StepperStep","title","StylesProvider","StepperSteps","isActive","PrevButton","isFirstStep","prevStep","useStepperContext","callAllHandlers","NextButton"],"mappings":"8lDAiBaA,EAA4CC,QAACC,KACxDA,EADwDC,MAExDA,GAGGF,EADAG,EACAC,EAAAJ,EAAAK,gBACH,OACEC,EAAAC,cAACC,EAAgBL,EACdD,eAAQI,EAACC,cAAAE,EAAU,CAAAC,QAAST,GAAOC,GAAqB,kBACzDI,EAACC,cAAAI,GAAKC,SAAS,mBACbN,EAACC,cAAAM,GAAU,CAAAZ,KAAMA,OAMrBa,IACFf,EAAagB,YAAc,gBAGhBF,MAAAA,GAAwC,EAAGZ,KAAAA,MACtD,MAAMe,UAAEA,GAAcC,IACtB,OAAgBD,EAACf,IAAS,MAGxBa,IACFD,GAAUE,YAAc,4QCsEpBG,GAAsC,GAEtBC,GAAG,OAiBHC,GAA0BjB,IAC9C,MAAMF,KAAEA,EAAFC,MAAQA,EAARmB,KAAeA,EAAfC,QAAqBA,EAArBC,UAA8BA,EAA9BC,SAAyCA,GAC7CrB,EAD0DsB,EAA5DrB,EACED,EADFE,KAGMqB,UAAEA,GAA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AADpO,EAAA,CAAcuJ,GAAG,KAAQ9L,GACtBsQ,KAUIC,GAAqCvQ,IAChD,MAAMF,KAAEA,EAAFkG,OAAQA,EAARW,SAAgBA,EAAhBtF,SAA0BA,EAA1B0G,UAAoCA,GAAuB/H,EAATsH,EAAxDrH,EAAiED,EAAjE4C,IACM+M,EAAOG,GAAY,CAAEhQ,KAAAA,EAAMkG,OAAAA,EAAQW,SAAAA,KAEnCiK,SAAEA,GAAajB,EAErB,OAAeiB,eACbzQ,EAACC,cAAA0H,EAAOK,IAAQb,EAAAA,GAAAA,EAAM,CAAAS,UAAWC,EAAG,kBAAmBD,KACpD1G,GAED,MAGFV,IACF4P,GAAS3P,YAAc,YAGZiQ,MAAUA,GAA2B7Q,IAChD,MAAM8Q,YAAEA,EAAFlB,YAAeA,EAAfmB,SAA4BA,GAAaC,iBAE/C,OACE7Q,EAACC,cAAAwN,EACCrL,EAAA,CAAAsB,WAAYiN,GAAelB,EAC3B7P,MAAM,QACFC,EACJ,CAAA+H,UAAWC,EAAG,yBAA0BhI,EAAM+H,WAC9C4C,QAASsG,EAAgBjR,EAAM2K,QAASoG,OAK1CpQ,IACFkQ,GAAWjQ,YAAc,cAOdsQ,MAAAA,GAAyClR,IACpD,MAAMD,MAAEA,EAAQ,OAAVoO,YAAkBA,EAAc,YAAwBnO,EAATsH,EAArDrH,EAA8DD,EAA9DkD,KACM+L,WAAEA,EAAFW,YAAcA,GAAgBoB,iBAEpC,OACE7Q,EAACC,cAAAqN,GACClL,EAAA,CAAAsB,WAAY+L,EACZ7P,MAAOkP,GAAcW,EAAczB,EAAcpO,GAC7CuH,EACJ,CAAAS,UAAWC,EAAG,yBAA0BhI,EAAM+H,eAKhDpH,IACFuQ,GAAWtQ,YAAc"}
|
1
|
+
{"version":3,"file":"index.modern.mjs","sources":["../src/display-field.tsx","../src/field.tsx","../src/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../src/use-step-form.tsx","../src/step-form.tsx"],"sourcesContent":["import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n DisplayField.displayName = 'DisplayField'\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n\nif (__DEV__) {\n FormValue.displayName = 'FormValue'\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'\nimport { __DEV__ } from '@chakra-ui/utils'\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}\n\nif (__DEV__) {\n BaseField.displayName = 'BaseField'\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 id,\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 id={id}\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 id={id}\n name={name}\n label={hideLabel ? label : undefined} // Only pass down the label when it should be inline.\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 the checkbox 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\nexport const InputField = registerFieldType(\n 'text',\n forwardRef(({ type = 'text', ...rest }, ref) => {\n return <Input type={type} {...rest} ref={ref} />\n })\n)\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(({ type, ...rest }, ref) => {\n return <Switch {...rest} ref={ref} />\n }),\n {\n isControlled: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(\n ({ label, type, ...props }: { label?: string; type: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }\n ),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema): FieldProps[] =>\n schema &&\n Object.entries(schema).map(([name, { items, ...field }]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\nimport { css } from '@emotion/react'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n className={cx('saas-form', props.className)}\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 displayName?: string\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nif (__DEV__) {\n Form.displayName = 'Form'\n}\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n FormLayoutItem.displayName = 'FormLayoutItem'\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\n {...gridProps}\n className={cx('saas-form__layout', props.className)}\n >\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\nif (__DEV__) {\n FormLayout.displayName = 'FormLayout'\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'\nimport { __DEV__ } from '@chakra-ui/utils'\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 children: React.ReactNode\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\nif (__DEV__) {\n ArrayFieldRow.displayName = 'ArrayFieldRow'\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 children: React.ReactNode\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\nif (__DEV__) {\n ArrayFieldRowFields.displayName = 'ArrayFieldRowFields'\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\nif (__DEV__) {\n ArrayFieldRowContainer.displayName = 'ArrayFieldRowContainer'\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\nif (__DEV__) {\n ArrayFieldRemoveButton.displayName = 'ArrayFieldRemoveButton'\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\nif (__DEV__) {\n ArrayFieldAddButton.displayName = 'ArrayFieldAddButton'\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\nif (__DEV__) {\n ArrayField.displayName = 'ArrayField'\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\nif (__DEV__) {\n ArrayFieldRows.displayName = 'ArrayFieldRows'\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\nif (__DEV__) {\n ArrayFieldContainer.displayName = 'ArrayFieldContainer'\n}\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyleConfig,\n} from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\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 = useStyleConfig('FormLegend')\n return <FormLabel as=\"legend\" sx={styles} {...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\nif (__DEV__) {\n ObjectField.displayName = 'ObjectField'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n\nif (__DEV__) {\n Fields.displayName = 'Fields'\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n SubmitButton.displayName = 'SubmitButton'\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton, SubmitButtonProps } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n /**\n * The submit button label.\n * Pass `null` to render no submit button.\n */\n submitLabel?: React.ReactNode\n /**\n * The schema.\n * Supports object schema, Yup or Zod.\n * @see https://www.saas-ui.dev/docs/forms/auto-form\n */\n schema: any\n /**\n * The field resolver.\n */\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 {\n schema,\n submitLabel = 'Submit',\n fieldResolver,\n children,\n ...rest\n } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n {children}\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 displayName?: string\n getFieldResolver?: (schema: any) => FieldResolver\n}\n\nif (__DEV__) {\n AutoForm.displayName = 'AutoForm'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\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\nif (__DEV__) {\n DisplayIf.displayName = 'DisplayIf'\n}\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 Omit<FormProps<TFieldValues>, 'children'> {\n children:\n | React.ReactNode\n | ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement)\n}\n\nexport interface UseStepFormReturn<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperReturn {\n getFormProps(): {\n onSubmit: SubmitHandler<TFieldValues>\n schema?: any\n resolver?: any\n }\n updateStep(step: any): void\n steps: Record<string, any>\n}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n): UseStepFormReturn<TFieldValues> {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState<Record<string, StepState>>({})\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 const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n }, [steps, onSubmitStep, activeStep])\n\n const updateStep = React.useCallback(\n (step: StepState) => {\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 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 SystemStyleObject,\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 UseStepFormReturn,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<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, ...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()}>\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"],"names":["DisplayField","_ref","name","label","props","_objectWithoutPropertiesLoose","_excluded","React","createElement","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","getValues","useFormContext","defaultInputType","BaseField","help","variant","hideLabel","children","controlProps","formState","error","get","errors","getError","_extends","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","InputComponent","inputTypes","getInput","withControlledInput","rules","inputProps","_ref2","_excluded3","control","Controller","render","_ref3","field","_excluded4","useMergeRefs","_ref4","_excluded5","register","_register","_excluded6","registerFieldType","component","options","isControlled","withUncontrolledInput","id","isDisabled","isReadOnly","isRequired","_excluded2","inputRules","required","undefined","createField","split","map","part","charAt","toUpperCase","slice","join","InputField","_ref5","rest","_excluded7","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","_ref6","_excluded8","Switch","SelectField","Select","CheckboxField","_ref7","_excluded9","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","_field$items","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","defaultProps","theme","useTheme","components","spacing","SimpleGrid","gridProps","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","context","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","columns","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","ArrayFieldRow","layoutProps","flex","gridGap","mr","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","Fragment","key","fieldProps","FormLegend","styles","useStyleConfig","as","sx","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","DisplayIf","isExact","condition","useWatch","disabled","exact","StepFormProvider","useStepFormContext","errorMessage","useStepForm","stepper","useStepper","activeStep","isLastStep","nextStep","steps","updateSteps","useState","onSubmitStep","async","data","then","updateStep","step","isCompleted","getFormProps","useFormStep","useStep","StepForm","ctx","StepperProvider","runIfFn","FormStepper","useMultiStyleConfig","elements","FormStep","StepperStep","title","StylesProvider","StepperSteps","isActive","PrevButton","isFirstStep","prevStep","useStepperContext","callAllHandlers","NextButton"],"mappings":"mmDAiBaA,EAA4CC,QAACC,KACxDA,EADwDC,MAExDA,GAGGF,EADAG,EACAC,EAAAJ,EAAAK,gBACH,OACEC,EAAAC,cAACC,EAAgBL,EACdD,eAAQI,EAACC,cAAAE,EAAU,CAAAC,QAAST,GAAOC,GAAqB,kBACzDI,EAACC,cAAAI,GAAKC,SAAS,mBACbN,EAACC,cAAAM,GAAU,CAAAZ,KAAMA,OAMrBa,IACFf,EAAagB,YAAc,gBAGhBF,MAAAA,GAAwC,EAAGZ,KAAAA,MACtD,MAAMe,UAAEA,GAAcC,IACtB,OAAgBD,EAACf,IAAS,MAGxBa,IACFD,GAAUE,YAAc,iSCsEkB,GAEtBG,GAAG,OAiBZC,GAAmChB,IAC9C,MAAMF,KAAEA,EAAFC,MAAQA,EAARkB,KAAeA,EAAfC,QAAqBA,EAArBC,UAA8BA,EAA9BC,SAAyCA,GAC7CpB,EAD0DqB,EAA5DpB,EACED,EADFE,KAGMoB,UAAEA,GAAcR,IAEXS,EAjBI,EAACzB,EAAcwB,IACpBE,EAACF,EAAUG,OAAQ3B,GAgBf4B,CAAS5B,EAAMwB,gBAE7B,OACEnB,EAAAC,cAACC,EAADsB,EAAA,CAAaT,QAASA,GAAaG,EAAc,CAAAO,YAAaL,IAC3DxB,IAAUoB,eACThB,EAACC,cAAAE,GAAUY,QAASA,GAAUnB,GAC5B,kBACJI,EAAAC,cAACyB,EAAD,KACGT,GACAH,GAAQ,MAACM,GAAAA,EAAOO,QAEb,kBADF3B,EAAAC,cAAC2B,EAAD,KAAiBd,IAElB,MAAAM,OAA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ChD,MAAMF,KAAEA,EAAF2G,OAAQA,EAARW,SAAgBA,EAAhBhG,SAA0BA,EAA1BmH,UAAoCA,GAAuBvI,EAATgF,EAAxD/E,EAAiED,EAAjE4C,IACMsN,EAAOG,GAAY,CAAEvQ,KAAAA,EAAM2G,OAAAA,EAAQW,SAAAA,KAEnC+J,SAAEA,GAAajB,EAErB,OAAeiB,eACbhR,EAACC,cAAAkI,EAAOK,IAAQ3D,EAAAA,GAAAA,EAAM,CAAAuD,UAAWC,EAAG,kBAAmBD,KACpDnH,GAED,MAGFT,IACFmQ,GAASlQ,YAAc,YAGZwQ,MAAUA,GAA2BpR,IAChD,MAAMqR,YAAEA,EAAFlB,YAAeA,EAAfmB,SAA4BA,GAAaC,iBAE/C,OACEpR,EAACC,cAAA+N,EACCxM,EAAA,CAAAoC,WAAYsN,GAAelB,EAC3BpQ,MAAM,QACFC,EACJ,CAAAuI,UAAWC,EAAG,yBAA0BxI,EAAMuI,WAC9C4C,QAASqG,EAAgBxR,EAAMmL,QAASmG,OAK1C3Q,IACFyQ,GAAWxQ,YAAc,cAOd6Q,MAAAA,GAAyCzR,IACpD,MAAMD,MAAEA,EAAQ,OAAV2O,YAAkBA,EAAc,YAAwB1O,EAATgF,EAArD/E,EAA8DD,EAA9DkD,KACMsM,WAAEA,EAAFW,YAAcA,GAAgBoB,iBAEpC,OACEpR,EAACC,cAAA4N,GACCrM,EAAA,CAAAoC,WAAYoM,EACZpQ,MAAOyP,GAAcW,EAAczB,EAAc3O,GAC7CiF,EACJ,CAAAuD,UAAWC,EAAG,yBAA0BxI,EAAMuI,eAKhD5H,IACF8Q,GAAW7Q,YAAc"}
|
package/dist/layout.d.ts
CHANGED
package/dist/layout.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.tsx"],"names":[],"mappings":"
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAsB,eAAe,EAAY,MAAM,kBAAkB,CAAA;AAGhF,oBAAY,eAAe,GAAG,eAAe,CAAA;AAc7C;;;;;GAKG;AACH,eAAO,MAAM,UAAU;6BAA4B,eAAe;;CAyBjE,CAAA"}
|
package/dist/zod/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var e=require("@hookform/resolvers/zod"),r=require("@chakra-ui/utils");function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},t.apply(this,arguments)}var n=function(e){switch(e._def.typeName){case"ZodArray":return"array";case"ZodObject":return"object";case"ZodNumber":return"number";case"ZodDate":return"date";default:return"text"}},o=function(e,r){var t;return null==(t=e._def[r])?void 0:t.value},a=function(e){var r=[],a={};if("ZodArray"===e._def.typeName)a=e._def.type.shape;else{if("ZodObject"!==e._def.typeName)return r;a=e._def.shape()}for(var i in a){var
|
1
|
+
var e=require("@hookform/resolvers/zod"),r=require("@chakra-ui/utils");function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},t.apply(this,arguments)}var n=function(e){switch(e._def.typeName){case"ZodArray":return"array";case"ZodObject":return"object";case"ZodNumber":return"number";case"ZodDate":return"date";default:return"text"}},o=function(e,r){var t;return null==(t=e._def[r])?void 0:t.value},a=function(e){var r=[],a={};if("ZodArray"===e._def.typeName)a=e._def.type.shape;else{if("ZodObject"!==e._def.typeName)return r;a=e._def.shape()}for(var i in a){var u=a[i],d={};"ZodArray"===u._def.typeName&&(d.min=o(u,"minLength"),d.max=o(u,"maxLength"));var c=u.description&&s(u.description);r.push(t({name:i,label:(null==c?void 0:c.label)||u.description||i,type:(null==c?void 0:c.type)||n(u)},d))}return r},i=function(e,t){return r.get(e._def.shape(),t)},u=function(e){return{getFields:function(){return a(e)},getNestedFields:function(r){return a(i(e,r))}}},s=function(e){try{return JSON.parse(e)}catch(r){return e}};Object.defineProperty(exports,"zodResolver",{enumerable:!0,get:function(){return e.zodResolver}}),exports.getFieldsFromSchema=a,exports.getNestedSchema=i,exports.zodFieldResolver=u,exports.zodForm=function(r,t,n){return void 0===t&&(t={}),void 0===n&&(n={}),{schema:r,resolver:e.zodResolver(r,t,n),fieldResolver:u(r)}},exports.zodMeta=function(e){return JSON.stringify(e)},exports.zodParseMeta=s;
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/zod/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps, FieldTypes } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\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 = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta
|
1
|
+
{"version":3,"file":"index.js","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps, FieldTypes } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\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 = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const zodForm = <T extends z.ZodTypeAny>(\n schema: T,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: zodResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: zodFieldResolver(schema),\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: FieldTypes\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"names":["getType","field","_def","typeName","getArrayOption","name","_field$_def$name","value","getFieldsFromSchema","schema","fields","schemaFields","type","shape","options","min","max","meta","description","zodParseMeta","push","label","getNestedSchema","path","get","zodFieldResolver","getFields","getNestedFields","JSON","parse","e","schemaOptions","resolverOptions","resolver","zodResolver","fieldResolver","stringify"],"mappings":"2SAYA,IAAMA,EAAU,SAACC,GACf,OAAQA,EAAMC,KAAKC,UACjB,IAAK,WACH,MAAO,QACT,IAAK,YACH,MAAO,SACT,IAAK,YACH,MAAO,SACT,IAAK,UACH,MAAO,OAET,QACE,MAAO,SAIPC,EAAiB,SAACH,EAAYI,GAClC,IAAAC,EAAA,OAAA,OAAAA,EAAOL,EAAMC,KAAKG,SAAlB,EAAOC,EAAkBC,OASKC,EAAG,SAACC,GAClC,IAAYC,EAAiB,GAEbC,EAAwB,GACxC,GAA6B,aAAzBF,EAAOP,KAAKC,SACdQ,EAAeF,EAAOP,KAAKU,KAAKC,UACvBJ,CAAAA,GAAyB,cAAzBA,EAAOP,KAAKC,SAGrB,OACDO,EAHCC,EAAeF,EAAOP,KAAKW,QAK7B,IAAK,SAAcF,EAAc,CAC/B,IAAMV,EAAQU,EAAaN,GAEdS,EAAY,GACG,aAAxBb,EAAMC,KAAKC,WACbW,EAAQC,IAAMX,EAAeH,EAAO,aACpCa,EAAQE,IAAMZ,EAAeH,EAAO,cAGtC,IAAMgB,EAAOhB,EAAMiB,aAAeC,EAAalB,EAAMiB,aAErDR,EAAOU,QACLf,KAAAA,EACAgB,OAAW,MAAJJ,OAAAA,EAAAA,EAAMI,QAASpB,EAAMiB,aAAeb,EAC3CO,MAAM,MAAAK,OAAA,EAAAA,EAAML,OAAQZ,EAAQC,IACzBa,IAGP,OAAOJ,GAGIY,EAAkB,SAACb,EAAsBc,GACpD,OAAOC,MAAIf,EAAOP,KAAKW,QAASU,IAGLE,EAAG,SAAyBhB,GACvD,MAAO,CACLiB,UAAS,WACP,OAAOlB,EAAoBC,IAE7BkB,gBAJK,SAIWtB,GACd,OAAOG,EAAoBc,EAAgBb,EAAQJ,SA0B7B,SAACY,GAC3B,IACE,OAAWW,KAACC,MAAMZ,GAClB,MAAOa,GACP,OACDb,yMA1BoB,SACrBR,EACAsB,EACAC,GAEA,YAHAD,IAAAA,IAAAA,EAAgB,SAEd,IADFC,IAAAA,EAAkB,IAEX,CACLvB,OAAAA,EACAwB,SAAUC,EAAAA,YAAYzB,EAAQsB,EAAeC,GAC7CG,cAAeV,EAAiBhB,qBASb,SAACQ,GACtB,OAAOW,KAAKQ,UAAUnB"}
|
@@ -1,2 +1,2 @@
|
|
1
|
-
import{zodResolver as e}from"@hookform/resolvers/zod";export{zodResolver}from"@hookform/resolvers/zod";import{get as r}from"@chakra-ui/utils";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},t.apply(this,arguments)}const o=e=>{switch(e._def.typeName){case"ZodArray":return"array";case"ZodObject":return"object";case"ZodNumber":return"number";case"ZodDate":return"date";default:return"text"}},
|
1
|
+
import{zodResolver as e}from"@hookform/resolvers/zod";export{zodResolver}from"@hookform/resolvers/zod";import{get as r}from"@chakra-ui/utils";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},t.apply(this,arguments)}const o=e=>{switch(e._def.typeName){case"ZodArray":return"array";case"ZodObject":return"object";case"ZodNumber":return"number";case"ZodDate":return"date";default:return"text"}},n=(e,r)=>{var t;return null==(t=e._def[r])?void 0:t.value},a=e=>{const r=[];let a={};if("ZodArray"===e._def.typeName)a=e._def.type.shape;else{if("ZodObject"!==e._def.typeName)return r;a=e._def.shape()}for(const e in a){const s=a[e],d={};"ZodArray"===s._def.typeName&&(d.min=n(s,"minLength"),d.max=n(s,"maxLength"));const i=s.description&&c(s.description);r.push(t({name:e,label:(null==i?void 0:i.label)||s.description||e,type:(null==i?void 0:i.type)||o(s)},d))}return r},s=(e,t)=>r(e._def.shape(),t),d=e=>({getFields:()=>a(e),getNestedFields:r=>a(s(e,r))}),i=(r,t={},o={})=>({schema:r,resolver:e(r,t,o),fieldResolver:d(r)}),l=e=>JSON.stringify(e),c=e=>{try{return JSON.parse(e)}catch(r){return e}};export{a as getFieldsFromSchema,s as getNestedSchema,d as zodFieldResolver,i as zodForm,l as zodMeta,c as zodParseMeta};
|
2
2
|
//# sourceMappingURL=index.modern.mjs.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.modern.mjs","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps, FieldTypes } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\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 = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta
|
1
|
+
{"version":3,"file":"index.modern.mjs","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps, FieldTypes } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\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 = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const zodForm = <T extends z.ZodTypeAny>(\n schema: T,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: zodResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: zodFieldResolver(schema),\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: FieldTypes\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"names":["field","_def","typeName","getArrayOption","name","_field$_def$name","value","getFieldsFromSchema","schema","fields","schemaFields","type","shape","options","min","max","meta","description","zodParseMeta","push","_extends","label","getType","getNestedSchema","path","get","zodFieldResolver","getFields","getNestedFields","zodForm","schemaOptions","resolverOptions","resolver","zodResolver","fieldResolver","zodMeta","JSON","stringify","parse","e"],"mappings":"kXAYA,QAAiBA,IACf,OAAQA,EAAMC,KAAKC,UACjB,IAAK,WACH,MAAO,QACT,IAAK,YACH,MAAO,SACT,IAAK,YACH,MAAO,SACT,IAAK,UACH,MAAO,OAET,QACE,MAAO,SAIOC,EAAG,CAACH,EAAYI,KAAgB,IAAAC,EAClD,cAAOL,EAAAA,EAAMC,KAAKG,WAAXC,EAAkBC,OASKC,EAAIC,IAClC,MAAYC,EAAiB,GAE7B,IAAgBC,EAAwB,GACxC,GAA6B,aAAzBF,EAAOP,KAAKC,SACdQ,EAAeF,EAAOP,KAAKU,KAAKC,UACvBJ,CAAAA,GAAyB,cAAzBA,EAAOP,KAAKC,SAGrB,SAFAQ,EAAeF,EAAOP,KAAKW,QAK7B,IAAK,MAAMR,KAAQM,EAAc,CAC/B,QAAcA,EAAaN,GAErBS,EAAmB,GACG,aAAxBb,EAAMC,KAAKC,WACbW,EAAQC,IAAMX,EAAeH,EAAO,aACpCa,EAAQE,IAAMZ,EAAeH,EAAO,cAGtC,MAAUgB,EAAGhB,EAAMiB,aAAeC,EAAalB,EAAMiB,aAErDR,EAAOU,KAAPC,EAAA,CACEhB,KAAAA,EACAiB,aAAOL,OAAAA,EAAAA,EAAMK,QAASrB,EAAMiB,aAAeb,EAC3CO,MAAM,MAAAK,OAAA,EAAAA,EAAML,OAAQW,EAAQtB,IACzBa,IAGP,UAGWU,EAAkB,CAACf,EAAsBgB,IAC7CC,EAAIjB,EAAOP,KAAKW,QAASY,GAGLE,EAA4BlB,IAChD,CACLmB,UAAS,MACoBnB,GAE7BoB,gBAAgBxB,GACPG,EAAoBgB,EAAgBf,EAAQJ,MAK5CyB,EAAU,CACrBrB,EACAsB,EAAgB,GAChBC,EAAkB,MAEX,CACLvB,OAAAA,EACAwB,SAAUC,EAAYzB,EAAQsB,EAAeC,GAC7CG,cAAeR,EAAiBlB,KAShB2B,EAAInB,GACXoB,KAACC,UAAUrB,GAGCE,EAAIF,IAC3B,IACE,YAAYsB,MAAMtB,GAClB,MAAOuB,GACP,OACDvB"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@saas-ui/forms",
|
3
|
-
"version": "1.0.0-rc.
|
3
|
+
"version": "1.0.0-rc.3",
|
4
4
|
"description": "Fully functional forms for Chakra UI.",
|
5
5
|
"source": "src/index.ts",
|
6
6
|
"exports": {
|
@@ -79,20 +79,20 @@
|
|
79
79
|
"url": "https://storybook.saas-ui.dev"
|
80
80
|
},
|
81
81
|
"dependencies": {
|
82
|
-
"@chakra-ui/icons": "^2.0.
|
83
|
-
"@chakra-ui/react-utils": "^2.0.
|
84
|
-
"@chakra-ui/utils": "^2.0.
|
85
|
-
"@hookform/resolvers": "^2.
|
86
|
-
"@saas-ui/button": "1.0.0-rc.
|
87
|
-
"@saas-ui/input-right-button": "1.0.0-rc.
|
88
|
-
"@saas-ui/number-input": "1.0.0-rc.
|
89
|
-
"@saas-ui/password-input": "1.0.0-rc.
|
90
|
-
"@saas-ui/pin-input": "1.0.0-rc.
|
91
|
-
"@saas-ui/radio": "1.0.0-rc.
|
92
|
-
"@saas-ui/react-utils": "1.0.0-rc.
|
93
|
-
"@saas-ui/select": "1.0.0-rc.
|
94
|
-
"@saas-ui/stepper": "1.0.0-rc.
|
95
|
-
"react-hook-form": "^7.31.
|
82
|
+
"@chakra-ui/icons": "^2.0.2",
|
83
|
+
"@chakra-ui/react-utils": "^2.0.1",
|
84
|
+
"@chakra-ui/utils": "^2.0.2",
|
85
|
+
"@hookform/resolvers": "^2.9.0",
|
86
|
+
"@saas-ui/button": "1.0.0-rc.2",
|
87
|
+
"@saas-ui/input-right-button": "1.0.0-rc.2",
|
88
|
+
"@saas-ui/number-input": "1.0.0-rc.2",
|
89
|
+
"@saas-ui/password-input": "1.0.0-rc.2",
|
90
|
+
"@saas-ui/pin-input": "1.0.0-rc.3",
|
91
|
+
"@saas-ui/radio": "1.0.0-rc.2",
|
92
|
+
"@saas-ui/react-utils": "1.0.0-rc.2",
|
93
|
+
"@saas-ui/select": "1.0.0-rc.2",
|
94
|
+
"@saas-ui/stepper": "1.0.0-rc.2",
|
95
|
+
"react-hook-form": "^7.31.3"
|
96
96
|
},
|
97
97
|
"peerDependencies": {
|
98
98
|
"@chakra-ui/react": ">=2.1.0",
|
package/src/auto-form.tsx
CHANGED
@@ -6,12 +6,24 @@ import { __DEV__ } from '@chakra-ui/utils'
|
|
6
6
|
import { Form, FormProps } from './form'
|
7
7
|
import { FormLayout } from './layout'
|
8
8
|
import { Fields } from './fields'
|
9
|
-
import { SubmitButton } from './submit-button'
|
9
|
+
import { SubmitButton, SubmitButtonProps } from './submit-button'
|
10
10
|
import { FieldResolver } from '.'
|
11
11
|
|
12
12
|
interface AutoFormOptions {
|
13
|
-
|
13
|
+
/**
|
14
|
+
* The submit button label.
|
15
|
+
* Pass `null` to render no submit button.
|
16
|
+
*/
|
17
|
+
submitLabel?: React.ReactNode
|
18
|
+
/**
|
19
|
+
* The schema.
|
20
|
+
* Supports object schema, Yup or Zod.
|
21
|
+
* @see https://www.saas-ui.dev/docs/forms/auto-form
|
22
|
+
*/
|
14
23
|
schema: any
|
24
|
+
/**
|
25
|
+
* The field resolver.
|
26
|
+
*/
|
15
27
|
fieldResolver?: any
|
16
28
|
}
|
17
29
|
|
@@ -24,13 +36,20 @@ export const AutoForm = forwardRef(
|
|
24
36
|
props: AutoFormProps<TFieldValues>,
|
25
37
|
ref: React.ForwardedRef<UseFormReturn<TFieldValues>>
|
26
38
|
) => {
|
27
|
-
const {
|
39
|
+
const {
|
40
|
+
schema,
|
41
|
+
submitLabel = 'Submit',
|
42
|
+
fieldResolver,
|
43
|
+
children,
|
44
|
+
...rest
|
45
|
+
} = props
|
28
46
|
|
29
47
|
return (
|
30
48
|
<Form {...rest} schema={schema} ref={ref}>
|
31
49
|
<FormLayout>
|
32
50
|
{<Fields schema={schema} fieldResolver={fieldResolver} />}
|
33
51
|
{submitLabel && <SubmitButton label={submitLabel} />}
|
52
|
+
{children}
|
34
53
|
</FormLayout>
|
35
54
|
</Form>
|
36
55
|
)
|
package/src/field-resolver.ts
CHANGED
@@ -14,9 +14,9 @@ interface SchemaField extends FieldProps {
|
|
14
14
|
|
15
15
|
export type ObjectSchema = Record<string, SchemaField>
|
16
16
|
|
17
|
-
const mapFields = (schema: ObjectSchema) =>
|
17
|
+
const mapFields = (schema: ObjectSchema): FieldProps[] =>
|
18
18
|
schema &&
|
19
|
-
Object.entries(schema).map(([name, field]) => {
|
19
|
+
Object.entries(schema).map(([name, { items, ...field }]) => {
|
20
20
|
return {
|
21
21
|
...field,
|
22
22
|
name,
|
package/src/field.tsx
CHANGED
@@ -227,7 +227,7 @@ const createField = (
|
|
227
227
|
ref={ref}
|
228
228
|
id={id}
|
229
229
|
name={name}
|
230
|
-
label={label}
|
230
|
+
label={hideLabel ? label : undefined} // Only pass down the label when it should be inline.
|
231
231
|
rules={inputRules}
|
232
232
|
{...inputProps}
|
233
233
|
/>
|
@@ -292,7 +292,7 @@ export interface RegisterFieldTypeOptions {
|
|
292
292
|
* @param component The React component
|
293
293
|
* @param options
|
294
294
|
* @param options.isControlled Set this to true if this is a controlled field.
|
295
|
-
* @param options.hideLabel Hide the field label, for example for checkbox
|
295
|
+
* @param options.hideLabel Hide the field label, for example for the checkbox field.
|
296
296
|
*/
|
297
297
|
export const registerFieldType = (
|
298
298
|
type: string,
|
@@ -320,9 +320,12 @@ export const registerFieldType = (
|
|
320
320
|
return Field
|
321
321
|
}
|
322
322
|
|
323
|
-
|
324
|
-
|
325
|
-
|
323
|
+
export const InputField = registerFieldType(
|
324
|
+
'text',
|
325
|
+
forwardRef(({ type = 'text', ...rest }, ref) => {
|
326
|
+
return <Input type={type} {...rest} ref={ref} />
|
327
|
+
})
|
328
|
+
)
|
326
329
|
export const NumberInputField = registerFieldType('number', NumberInput, {
|
327
330
|
isControlled: true,
|
328
331
|
})
|
@@ -330,16 +333,11 @@ export const PasswordInputFIeld = registerFieldType('password', PasswordInput)
|
|
330
333
|
export const TextareaField = registerFieldType('textarea', Textarea)
|
331
334
|
export const SwitchField = registerFieldType(
|
332
335
|
'switch',
|
333
|
-
forwardRef(({
|
334
|
-
return
|
335
|
-
<Switch ref={ref} {...props}>
|
336
|
-
{label}
|
337
|
-
</Switch>
|
338
|
-
)
|
336
|
+
forwardRef(({ type, ...rest }, ref) => {
|
337
|
+
return <Switch {...rest} ref={ref} />
|
339
338
|
}),
|
340
339
|
{
|
341
340
|
isControlled: true,
|
342
|
-
hideLabel: true,
|
343
341
|
}
|
344
342
|
)
|
345
343
|
export const SelectField = registerFieldType('select', Select, {
|
@@ -347,13 +345,15 @@ export const SelectField = registerFieldType('select', Select, {
|
|
347
345
|
})
|
348
346
|
export const CheckboxField = registerFieldType(
|
349
347
|
'checkbox',
|
350
|
-
forwardRef(
|
351
|
-
|
352
|
-
|
353
|
-
{
|
354
|
-
|
355
|
-
|
356
|
-
|
348
|
+
forwardRef(
|
349
|
+
({ label, type, ...props }: { label?: string; type: string }, ref) => {
|
350
|
+
return (
|
351
|
+
<Checkbox ref={ref} {...props}>
|
352
|
+
{label}
|
353
|
+
</Checkbox>
|
354
|
+
)
|
355
|
+
}
|
356
|
+
),
|
357
357
|
{
|
358
358
|
hideLabel: true,
|
359
359
|
}
|
package/src/object-field.tsx
CHANGED
@@ -4,7 +4,7 @@ import {
|
|
4
4
|
FormLabel,
|
5
5
|
FormLabelProps,
|
6
6
|
ResponsiveValue,
|
7
|
-
|
7
|
+
useStyleConfig,
|
8
8
|
} from '@chakra-ui/react'
|
9
9
|
import { __DEV__ } from '@chakra-ui/utils'
|
10
10
|
|
@@ -21,8 +21,8 @@ export interface ObjectFieldProps extends FieldProps {
|
|
21
21
|
}
|
22
22
|
|
23
23
|
export const FormLegend = (props: FormLabelProps) => {
|
24
|
-
const styles =
|
25
|
-
return <FormLabel as="legend" sx={styles
|
24
|
+
const styles = useStyleConfig('FormLegend')
|
25
|
+
return <FormLabel as="legend" sx={styles} {...props} />
|
26
26
|
}
|
27
27
|
|
28
28
|
export const ObjectField: React.FC<ObjectFieldProps> = (props) => {
|