@saas-ui/forms 0.7.5 → 0.7.8
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +18 -0
- 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.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/step-form.d.ts +2 -1
- package/dist/step-form.d.ts.map +1 -1
- package/dist/use-step-form.d.ts +8 -20
- package/dist/use-step-form.d.ts.map +1 -1
- package/dist/zod/{zod/src/index.d.ts → index.d.ts} +0 -0
- package/dist/zod/index.d.ts.map +1 -0
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.modern.js.map +1 -1
- package/dist/zod/{zod/src/zod-resolver.d.ts → zod-resolver.d.ts} +1 -2
- package/dist/zod/zod-resolver.d.ts.map +1 -0
- package/package.json +2 -2
- package/src/field.tsx +3 -0
- package/src/step-form.tsx +7 -2
- package/src/use-step-form.tsx +21 -14
- package/yup/package.json +0 -11
- package/zod/package.json +0 -11
- package/dist/zod/zod/src/index.d.ts.map +0 -1
- package/dist/zod/zod/src/zod-resolver.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
@@ -1,5 +1,23 @@
|
|
1
1
|
# @saas-ui/forms
|
2
2
|
|
3
|
+
## 0.7.8
|
4
|
+
|
5
|
+
### Patch Changes
|
6
|
+
|
7
|
+
- 391e21a: Field id now passed down to the internal FormControl for better a11y.
|
8
|
+
|
9
|
+
## 0.7.7
|
10
|
+
|
11
|
+
### Patch Changes
|
12
|
+
|
13
|
+
- c0b3dc9: Improved StepForm typings
|
14
|
+
|
15
|
+
## 0.7.6
|
16
|
+
|
17
|
+
### Patch Changes
|
18
|
+
|
19
|
+
- Fix zod resolver build
|
20
|
+
|
3
21
|
## 0.7.5
|
4
22
|
|
5
23
|
### Patch Changes
|
package/dist/field.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.tsx"],"names":[],"mappings":"A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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||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 y=["name","label","placeholder"],b=function(e){var r=e.name,t=e.label,a=F(e,y);/*#__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"],C=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],S=["name","rules"],g=["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,S),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,g);/*#__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.name,i=r.label,o=r.help,s=r.isDisabled,u=r.isInvalid,d=r.isReadOnly,m=r.isRequired,c=r.rules,p=r.variant,f=F(r,C),v=h({required:m},c);/*#__PURE__*/return x.createElement(l,{name:n,label:i,help:o,hideLabel:a,isDisabled:s,isInvalid:u,isReadOnly:d,isRequired:m,variant:p},/*#__PURE__*/x.createElement(e,h({ref:t,name:n,label:i,rules:v},f)))});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),q=P("number",a.NumberInput,{isControlled:!0}),O=P("password",l.PasswordInput),j=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,y=e.onSubmit,b=e.onError,E=e.formRef,_=e.children,C=F(e,K),S={mode:i,resolver:o,defaultValues:v,reValidateMode:s,shouldFocusError:u,shouldUnregister:d,shouldUseNativeValidation:m,criteriaMode:c,delayError:p};f&&!o&&(S.resolver=null==Q.getResolver?void 0:Q.getResolver(f));var g=t.useForm(S),N=g.handleSubmit;return x.useImperativeHandle(a,function(){return g},[a,g]),/*#__PURE__*/x.createElement(t.FormProvider,g,/*#__PURE__*/x.createElement(n.chakra.form,h({ref:E,onSubmit:N(y,b)},C,{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(be,h({ref:r},n),/*#__PURE__*/x.createElement(ye,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 ye=function(e){return(0,e.children)(te().fields)};r.__DEV__&&(ye.displayName="ArrayFieldRows");var be=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__&&(be.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))},Ce=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__&&(Ce.displayName="ObjectField");var Se=["name","type"],ge=["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,Se);/*#__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,ge),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(Ce,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 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(e){var r=i[t];return{onSubmit:s,schema:null==r?void 0:r.schema,resolver:null==r?void 0:r.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 Oe(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 je=["children","onSubmit"],Me=["getFormProps"],Ue=["name","schema","resolver","children","className"],Te=["label","submitLabel"],He=x.forwardRef(function(e,t){var n=e.children,a=F(e,je),l=qe(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(e)),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 Oe({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=be,exports.ArrayFieldProvider=re,exports.ArrayFieldRemoveButton=xe,exports.ArrayFieldRow=pe,exports.ArrayFieldRowContainer=ve,exports.ArrayFieldRowFields=fe,exports.ArrayFieldRowProvider=ae,exports.ArrayFieldRows=ye,exports.AutoForm=ke,exports.BaseField=A,exports.CheckboxField=T,exports.DisplayField=b,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=Oe(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=q,exports.ObjectField=Ce,exports.PasswordInputFIeld=O,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=j,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=Oe,exports.useStepForm=qe,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||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 y=["name","label","placeholder"],b=function(e){var r=e.name,t=e.label,a=F(e,y);/*#__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"],C=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],S=["name","rules"],g=["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,S),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,g);/*#__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,C),y=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:y},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),q=P("number",a.NumberInput,{isControlled:!0}),O=P("password",l.PasswordInput),j=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,y=e.onSubmit,b=e.onError,E=e.formRef,_=e.children,C=F(e,K),S={mode:i,resolver:o,defaultValues:v,reValidateMode:s,shouldFocusError:u,shouldUnregister:d,shouldUseNativeValidation:m,criteriaMode:c,delayError:p};f&&!o&&(S.resolver=null==Q.getResolver?void 0:Q.getResolver(f));var g=t.useForm(S),N=g.handleSubmit;return x.useImperativeHandle(a,function(){return g},[a,g]),/*#__PURE__*/x.createElement(t.FormProvider,g,/*#__PURE__*/x.createElement(n.chakra.form,h({ref:E,onSubmit:N(y,b)},C,{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(be,h({ref:r},n),/*#__PURE__*/x.createElement(ye,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 ye=function(e){return(0,e.children)(te().fields)};r.__DEV__&&(ye.displayName="ArrayFieldRows");var be=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__&&(be.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))},Ce=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__&&(Ce.displayName="ObjectField");var Se=["name","type"],ge=["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,Se);/*#__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,ge),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(Ce,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 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 Oe(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 je=["children","onSubmit"],Me=["getFormProps"],Ue=["name","schema","resolver","children","className"],Te=["label","submitLabel"],He=x.forwardRef(function(e,t){var n=e.children,a=F(e,je),l=qe(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 Oe({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=be,exports.ArrayFieldProvider=re,exports.ArrayFieldRemoveButton=xe,exports.ArrayFieldRow=pe,exports.ArrayFieldRowContainer=ve,exports.ArrayFieldRowFields=fe,exports.ArrayFieldRowProvider=ae,exports.ArrayFieldRows=ye,exports.AutoForm=ke,exports.BaseField=A,exports.CheckboxField=T,exports.DisplayField=b,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=Oe(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=q,exports.ObjectField=Ce,exports.PasswordInputFIeld=O,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=j,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=Oe,exports.useStepForm=qe,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]}})});
|
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 name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema) =>\n schema &&\n Object.entries(schema).map(([name, field]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\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\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\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 FormProps<TFieldValues> {}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n) {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(\n (props) => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n },\n [steps, onSubmitStep, activeStep]\n )\n\n const updateStep = React.useCallback(\n (step) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport type UseStepFormReturn = ReturnType<typeof useStepForm>\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {\n chakra,\n HTMLChakraProps,\n useMultiStyleConfig,\n StylesProvider,\n} from '@chakra-ui/system'\n\nimport { callAllHandlers, runIfFn, cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n StepperProvider,\n StepperSteps,\n StepperStepsProps,\n StepperStep,\n useStepperContext,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form, FormProps } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues>,\n FormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps(props)}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const styles = useMultiStyleConfig('Stepper', props)\n\n const { children } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n return (\n <StylesProvider value={styles}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StylesProvider>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, ...rest } = props\n const step = useFormStep({ name, schema, resolver })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n"],"names":["DisplayField","name","label","props","React","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","getValues","useFormContext","inputTypes","BaseField","help","variant","hideLabel","children","controlProps","error","formState","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","withControlledInput","InputComponent","rules","inputProps","Controller","control","render","field","_ref","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","isDisabled","isReadOnly","isRequired","inputRules","required","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","id","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","DisplayIf","condition","useWatch","disabled","exact","isExact","errorMessage","StepFormProvider","useStepFormContext","useStepForm","stepper","useStepper","activeStep","isLastStep","nextStep","useState","steps","updateSteps","onSubmitStep","data","then","updateStep","isCompleted","getFormProps","step","useFormStep","useStep","StepForm","ctx","StepperProvider","runIfFn","FormStep","isActive","PrevButton","useStepperContext","prevStep","isFirstStep","callAllHandlers","NextButton","useMultiStyleConfig","elements","StepperStep","title","StylesProvider","StepperSteps"],"mappings":"qnCAiBaA,EAA4C,YACvDC,IAAAA,IAAAA,KACAC,IAAAA,MAEGC,sBAEH,OACEC,gBAACC,cAAgBF,EACdD,eAAQE,gBAACE,aAAUC,QAASN,GAAOC,GAAqB,kBACzDE,gBAACI,QAAKC,SAAS,mBACbL,gBAACM,GAAUT,KAAMA,OAMrBU,YACFX,EAAaY,YAAc,gBAGhBF,IAAAA,EAAwC,gBAAGT,IAAAA,KAE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P,GAAWjP,YAAc,uiBAxF6B,SAACT,GACvD,IAAM6L,EAAS8D,sBAAoB,UAAW3P,GAIxC4P,EAAW3P,EAAM8H,SAASvE,IAFXxD,EAAbiB,SAEsC,SAAC+G,GAC7C,GAAI/H,EAAMgI,eAAeD,WAAUA,SAAAA,EAAOhG,QAASmN,GAAU,CAC3D,MAAwBN,GAAY7G,EAAMhI,oBAC1C,OACEC,gBAAC4P,eACC/P,KAAMkI,EAAMhI,MAAMF,KAClBgQ,MAAO9H,EAAMhI,MAAM8P,MACnBpB,cALIA,aAOH1G,EAAMhI,MAAMiB,UAInB,OAAO+G,iBAGT,OACE/H,gBAAC8P,kBAAevF,MAAOqB,gBACrB5L,gBAAC+P,kBAAalF,GAAG,KAAQ9K,GACtB4P"}
|
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\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\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 FormProps<TFieldValues> {}\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({})\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) => {\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} 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 FormProps<TFieldValues> {\n children:\n | React.ReactNode\n | ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement)\n}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps()}>\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","name","label","props","React","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","getValues","useFormContext","inputTypes","BaseField","help","variant","hideLabel","children","controlProps","error","formState","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","withControlledInput","InputComponent","rules","inputProps","Controller","control","render","field","_ref","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","id","isDisabled","isReadOnly","isRequired","inputRules","required","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","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","condition","useWatch","disabled","exact","isExact","errorMessage","StepFormProvider","useStepFormContext","useStepForm","stepper","useStepper","activeStep","isLastStep","nextStep","useState","steps","updateSteps","onSubmitStep","data","then","updateStep","isCompleted","getFormProps","step","useFormStep","useStep","StepForm","ctx","StepperProvider","runIfFn","FormStep","isActive","PrevButton","useStepperContext","prevStep","isFirstStep","callAllHandlers","NextButton","useMultiStyleConfig","elements","StepperStep","title","StylesProvider","StepperSteps"],"mappings":"qnCAiBaA,EAA4C,YACvDC,IAAAA,IAAAA,KACAC,IAAAA,MAEGC,sBAEH,OACEC,gBAACC,cAAgBF,EACdD,eAAQE,gBAACE,aAAUC,QAASN,GAAOC,GAAqB,kBACzDE,gBAACI,QAAKC,SAAS,mBACbL,gBAACM,GAAUT,KAAMA,OAMrBU,YACFX,EAAaY,YAAc,gBAGhBF,IAAAA,EAAwC,gBAAGT,IAAAA,KAEtD,OAAOY,EADeC,mBAAdD,WACSZ,IAAS,MAGxBU,YACFD,EAAUE,YAAc,kQCsEpBG,EAAsC,GAmB/BC,EAAkC,SAACb,GAC9C,IAAQF,EACNE,EADMF,KAAMC,EACZC,EADYD,MAAOe,EACnBd,EADmBc,KAAMC,EACzBf,EADyBe,QAASC,EAClChB,EADkCgB,UAAWC,EAC7CjB,EAD6CiB,SAAaC,IAC1DlB,KAIImB,EAjBS,SAACrB,EAAcsB,GAC9B,OAAOC,MAAID,EAAUE,OAAQxB,GAgBfyB,CAASzB,EAFDa,mBAAdS,wBAIR,OACEnB,gBAACC,iBAAYa,QAASA,GAAaG,GAAcM,YAAaL,IAC3DpB,IAAUiB,eACTf,gBAACE,aAAUY,QAASA,GAAUhB,GAC5B,kBACJE,gBAACwB,WACER,GACAH,SAASK,GAAAA,EAAOO,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/index.modern.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import*as e from"react";import{__DEV__ as t,get as l,cx as a,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 S,useTheme as k,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 B}from"@saas-ui/select";import{chakra as O,forwardRef as U,useMultiStyleConfig as _,StylesProvider as j}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||function(e){for(var t=1;t<arguments.length;t++){var l=arguments[t];for(var a in l)Object.prototype.hasOwnProperty.call(l,a)&&(e[a]=l[a])}return e},W.apply(this,arguments)}function X(e,t){if(null==e)return{};var l,a,r={},n=Object.keys(e);for(a=0;a<n.length;a++)t.indexOf(l=n[a])>=0||(r[l]=e[l]);return r}const Y=["name","label","placeholder"],Z=t=>{let{name:l,label:a}=t,r=X(t,Y);/*#__PURE__*/return e.createElement(p,r,a?/*#__PURE__*/e.createElement(f,{htmlFor:l},a):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(ee,{name:l})))};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"],le=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],ae=["name","rules"],re=["ref"],ne=["name","rules"],se=["ref"],ie=["label"],oe=["label"],me={},ce="text",de=t=>{const{name:l,label:a,help:r,variant:n,hideLabel:o,children:m}=t,c=X(t,te),{formState:d}=s(),u=((e,t)=>i(t.errors,e))(l,d);/*#__PURE__*/return e.createElement(p,W({variant:n},c,{isInvalid:!!u}),a&&!o?/*#__PURE__*/e.createElement(f,{variant:n},a):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,l)=>{const{type:a=ce}=t,r=(e=>me[e]||me[ce])(a);/*#__PURE__*/return e.createElement(r,W({ref:l},t))}),pe=t=>b((l,a)=>{let{name:r,rules:n}=l,i=X(l,ae);const{control:m}=s();/*#__PURE__*/return e.createElement(o,{name:r,control:m,rules:n,render:l=>{let{field:{ref:r}}=l,n=X(l.field,re);/*#__PURE__*/return e.createElement(t,W({},n,i,{ref:g(a,r)}))}})}),fe=t=>b((l,a)=>{let{name:r,rules:n}=l,i=X(l,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(a,c)}))}),he=(t,l,a)=>{let r;r=null!=a&&a.isControlled?pe(l):fe(l);const n=((t,{displayName:l,hideLabel:a,BaseField:r})=>{const n=b((l,n)=>{const{name:s,label:i,help:o,isDisabled:m,isInvalid:c,isReadOnly:d,isRequired:u,rules:p,variant:f}=l,h=X(l,le),b=W({required:u},p);/*#__PURE__*/return e.createElement(r,{name:s,label:i,help:o,hideLabel:a,isDisabled:m,isInvalid:c,isReadOnly:d,isRequired:u,variant:f},/*#__PURE__*/e.createElement(t,W({ref:n,name:s,label:i,rules:b},h)))});return n.displayName=l,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==a?void 0:a.hideLabel,BaseField:(null==a?void 0:a.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,l)=>{let{label:a}=t,r=X(t,ie);/*#__PURE__*/return e.createElement(y,W({ref:l},r),a)}),{isControlled:!0,hideLabel:!0}),Fe=he("select",D,{isControlled:!0}),ge=he("checkbox",b((t,l)=>{let{label:a}=t,r=X(t,oe);/*#__PURE__*/return e.createElement(E,W({ref:l},r),a)}),{hideLabel:!0}),xe=he("radio",I,{isControlled:!0}),Ce=he("pin",A,{isControlled:!0}),Se=he("native-select",B,{isControlled:!0}),ke=e=>e&&Object.entries(e).map(([e,t])=>W({},t,{name:e})),Re=e=>({getFields:()=>ke(e),getNestedFields:t=>{var a;const r=l(e,t);return r?"object"===(null==(a=r.items)?void 0:a.type)?ke(r.items.properties):"object"===r.type?ke(r.properties):[r.items]:[]}}),Ve=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Le=b((t,l)=>{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(l,()=>g,[l,g]),/*#__PURE__*/e.createElement(c,g,/*#__PURE__*/e.createElement(S.form,W({ref:E,onSubmit:x(b,y)},N,{className:a("saas-form",t.className)}),v))});Le.getFieldResolver=Re,t&&(Le.displayName="Form");const we=["children"],Ie=({children:t})=>/*#__PURE__*/e.createElement(S.div,null,t);t&&(Ie.displayName="FormLayoutItem");const Ae=t=>{var l,r,n;let{children:s}=t,i=X(t,we);const o=W({},null!=(l=null==(r=k().components)||null==(n=r.FormLayout)?void 0:n.defaultProps)?l:{spacing:4},i);/*#__PURE__*/return e.createElement(R,W({},o,{className:a("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,l)=>e.Children.map(l,l=>e.isValidElement(l)&&l.props.name?e.cloneElement(l,W({},l.props,{name:`${t}.${l.props.name}`})):l),[Be,Oe]=G({name:"ArrayFieldContext"}),[Ue,_e]=G({name:"ArrayFieldRowContext"}),je=({name:e,defaultValue:t={},keyName:l,min:a,max:r})=>{const{control:n}=s();return W({},d({control:n,name:e,keyName:l}),{name:e,defaultValue:t,min:a,max:r})},Me=({index:t})=>{const{clearErrors:l}=s(),{name:a,remove:r,fields:n}=Oe();return e.useEffect(()=>{l(a)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${a}.${t}`,remove:e.useCallback(()=>{l(a),r(t)},[t])}},Pe=()=>{const{isFirst:e,remove:t}=_e(),{min:l,fields:a}=Oe();return{onClick:()=>t(),isDisabled:e&&!!(l&&a.length<=l)}},$e=()=>{const{append:e,defaultValue:t,max:l,fields:a}=Oe();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(l&&a.length>=l)}},qe=["children","columns","spacing"],Ge=["children"],He=["name","defaultValue","keyName","min","max","children"],ze=({children:t,columns:l,spacing:a,index:r})=>/*#__PURE__*/e.createElement(Ke,{index:r},/*#__PURE__*/e.createElement(Je,{columns:l,spacing:a},t),/*#__PURE__*/e.createElement(Qe,null));t&&(ze.displayName="ArrayFieldRow");const Je=t=>{let{children:l,columns:a,spacing:r}=t,n=X(t,qe);const{name:s}=_e();/*#__PURE__*/return e.createElement(Ae,W({flex:"1",columns:a,gridGap:r,mr:"2"},n),De(s,l))};t&&(Je.displayName="ArrayFieldRowFields");const Ke=({children:t,index:l})=>{const a=Me({index:l});/*#__PURE__*/return e.createElement(Ue,{value:a},/*#__PURE__*/e.createElement(O.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,l)=>{const{children:a}=t,r=X(t,Ge);/*#__PURE__*/return e.createElement(Ye,W({ref:l},r),/*#__PURE__*/e.createElement(Xe,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},l)=>/*#__PURE__*/e.createElement(ze,{key:t,index:l},a)))),/*#__PURE__*/e.createElement(Te,null))});t&&(We.displayName="ArrayField");const Xe=({children:e})=>{const{fields:t}=Oe();return e(t)};t&&(Xe.displayName="ArrayFieldRows");const Ye=e.forwardRef((t,l)=>{let{name:a,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=X(t,He);const c=je({name:a,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(l,()=>c,[l,c]),/*#__PURE__*/e.createElement(Be,{value:c},/*#__PURE__*/e.createElement(de,W({name:a},m),o))});t&&(Ye.displayName="ArrayFieldContainer");const Ze=["name","label","hideLabel","children","columns","spacing"],et=t=>{const l=V();/*#__PURE__*/return e.createElement(f,W({as:"legend",sx:l.legend},t))},tt=t=>{const{name:l,label:a,hideLabel:r,children:n,columns:s,spacing:i}=t,o=X(t,Ze);/*#__PURE__*/return e.createElement(p,W({name:l,as:"fieldset"},o),/*#__PURE__*/e.createElement(et,{display:r?"none":"block"},a),/*#__PURE__*/e.createElement(Ae,{columns:s,gridGap:i},De(l,n)))};t&&(tt.displayName="ObjectField");const lt=["name","type"],at=["schema","fieldResolver"],rt=["name","type","defaultValue"],nt=(t,l)=>{var a;return null==(a=t.getNestedFields(l))?void 0:a.map((t,l)=>{let{name:a,type:r}=t,n=X(t,lt);/*#__PURE__*/return e.createElement(ue,W({key:a||l,name:a,type:r},n))})},st=t=>{let{schema:l,fieldResolver:a}=t,r=X(t,at);const n=e.useMemo(()=>a||Le.getFieldResolver(l),[l,a]);/*#__PURE__*/return e.createElement(Ae,r,n.getFields().map(t=>{let{name:l,type:a}=t,r=X(t,rt);return"array"===a?/*#__PURE__*/e.createElement(We,W({key:l,name:l},r),nt(n,l)):"object"===a?/*#__PURE__*/e.createElement(tt,W({key:l,name:l},r),nt(n,l)):/*#__PURE__*/e.createElement(ue,W({key:l,name:l,type:a},r))}))};t&&(st.displayName="Fields");const it=["children","disableIfUntouched","disableIfInvalid"],ot=U((t,l)=>{const{children:a,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:l,isDisabled:r&&!o.isDirty||n&&!o.isValid},i),a)});ot.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(ot.displayName="SubmitButton");const mt=["schema","submitLabel","fieldResolver"],ct=b((t,l)=>{const{schema:a,submitLabel:r="Submit",fieldResolver:n}=t,s=X(t,mt);/*#__PURE__*/return e.createElement(Le,W({},s,{schema:a,ref:l}),/*#__PURE__*/e.createElement(Ae,null,/*#__PURE__*/e.createElement(st,{schema:a,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(ot,{label:r})))});t&&(ct.displayName="AutoForm");const dt=({children:e,name:t,defaultValue:l,isDisabled:a,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:l,disabled:a,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 l=H(t),{activeStep:a,isLastStep:r,nextStep:n}=l,[s,i]=e.useState({}),o=e.useCallback(async e=>{if(r)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{c(W({},s[a],{isCompleted:!0}))}).then(n);n()},[a,r]),m=e.useCallback(e=>{const t=s[a];return{onSubmit:o,schema:null==t?void 0:t.schema,resolver:null==t?void 0:t.resolver}},[s,o,a]),c=e.useCallback(e=>{i(t=>W({},t,{[e.name]:e}))},[s]);return W({getFormProps:m,updateStep:c,steps:s},l)}function ht(t){const{name:l,schema:a,resolver:r}=t,n=z({name:l}),{steps:s,updateStep:i}=pt();return e.useEffect(()=>{i({name:l,schema:a,resolver:r})},[l,a]),W({},n,s[l]||{name:l,schema:a})}const bt=["children","onSubmit"],yt=["getFormProps"],Et=["name","schema","resolver","children","className"],vt=["label","submitLabel"],Nt=e.forwardRef((t,l)=>{const{children:a}=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:l},n,i(t)),r(a,s))))}),Ft=t=>{const l=_("Stepper",t),{children:a}=t,r=e.Children.map(a,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===gt){const{isCompleted:l}=ht(t.props);/*#__PURE__*/return e.createElement(K,{name:t.props.name,title:t.props.title,isCompleted:l},t.props.children)}return t});/*#__PURE__*/return e.createElement(j,{value:l},/*#__PURE__*/e.createElement(Q,W({mb:"4"},t),r))},gt=t=>{const{name:l,schema:r,resolver:n,children:s,className:i}=t,o=X(t,Et),m=ht({name:l,schema:r,resolver:n}),{isActive:c}=m;return c?/*#__PURE__*/e.createElement(O.div,W({},o,{className:a("saas-form__step",i)}),s):null};t&&(gt.displayName="FormStep");const xt=t=>{const{isFirstStep:l,isCompleted:r,prevStep:s}=T();/*#__PURE__*/return e.createElement(q,W({isDisabled:l||r,label:"Back"},t,{className:a("saas-form__prev-button",t.className),onClick:n(t.onClick,s)}))};t&&(xt.displayName="PrevButton");const Ct=t=>{const{label:l="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:l},n,{className:a("saas-form__next-button",t.className)}))};t&&(Ct.displayName="NextButton");export{We as ArrayField,Te as ArrayFieldAddButton,Ye as ArrayFieldContainer,Be as ArrayFieldProvider,Qe as ArrayFieldRemoveButton,ze as ArrayFieldRow,Ke as ArrayFieldRowContainer,Je as ArrayFieldRowFields,Ue 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,Se 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,je as useArrayField,$e as useArrayFieldAddButton,Oe as useArrayFieldContext,Pe as useArrayFieldRemoveButton,Me as useArrayFieldRow,_e 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 l,cx as a,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 S,useTheme as k,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 B}from"@saas-ui/select";import{chakra as O,forwardRef as U,useMultiStyleConfig as _,StylesProvider as j}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||function(e){for(var t=1;t<arguments.length;t++){var l=arguments[t];for(var a in l)Object.prototype.hasOwnProperty.call(l,a)&&(e[a]=l[a])}return e},W.apply(this,arguments)}function X(e,t){if(null==e)return{};var l,a,r={},n=Object.keys(e);for(a=0;a<n.length;a++)t.indexOf(l=n[a])>=0||(r[l]=e[l]);return r}const Y=["name","label","placeholder"],Z=t=>{let{name:l,label:a}=t,r=X(t,Y);/*#__PURE__*/return e.createElement(p,r,a?/*#__PURE__*/e.createElement(f,{htmlFor:l},a):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(ee,{name:l})))};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"],le=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],ae=["name","rules"],re=["ref"],ne=["name","rules"],se=["ref"],ie=["label"],oe=["label"],me={},ce="text",de=t=>{const{name:l,label:a,help:r,variant:n,hideLabel:o,children:m}=t,c=X(t,te),{formState:d}=s(),u=((e,t)=>i(t.errors,e))(l,d);/*#__PURE__*/return e.createElement(p,W({variant:n},c,{isInvalid:!!u}),a&&!o?/*#__PURE__*/e.createElement(f,{variant:n},a):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,l)=>{const{type:a=ce}=t,r=(e=>me[e]||me[ce])(a);/*#__PURE__*/return e.createElement(r,W({ref:l},t))}),pe=t=>b((l,a)=>{let{name:r,rules:n}=l,i=X(l,ae);const{control:m}=s();/*#__PURE__*/return e.createElement(o,{name:r,control:m,rules:n,render:l=>{let{field:{ref:r}}=l,n=X(l.field,re);/*#__PURE__*/return e.createElement(t,W({},n,i,{ref:g(a,r)}))}})}),fe=t=>b((l,a)=>{let{name:r,rules:n}=l,i=X(l,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(a,c)}))}),he=(t,l,a)=>{let r;r=null!=a&&a.isControlled?pe(l):fe(l);const n=((t,{displayName:l,hideLabel:a,BaseField:r})=>{const n=b((l,n)=>{const{id:s,name:i,label:o,help:m,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,rules:f,variant:h}=l,b=X(l,le),y=W({required:p},f);/*#__PURE__*/return e.createElement(r,{id:s,name:i,label:o,help:m,hideLabel:a,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=l,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==a?void 0:a.hideLabel,BaseField:(null==a?void 0:a.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,l)=>{let{label:a}=t,r=X(t,ie);/*#__PURE__*/return e.createElement(y,W({ref:l},r),a)}),{isControlled:!0,hideLabel:!0}),Fe=he("select",D,{isControlled:!0}),ge=he("checkbox",b((t,l)=>{let{label:a}=t,r=X(t,oe);/*#__PURE__*/return e.createElement(E,W({ref:l},r),a)}),{hideLabel:!0}),xe=he("radio",I,{isControlled:!0}),Ce=he("pin",A,{isControlled:!0}),Se=he("native-select",B,{isControlled:!0}),ke=e=>e&&Object.entries(e).map(([e,t])=>W({},t,{name:e})),Re=e=>({getFields:()=>ke(e),getNestedFields:t=>{var a;const r=l(e,t);return r?"object"===(null==(a=r.items)?void 0:a.type)?ke(r.items.properties):"object"===r.type?ke(r.properties):[r.items]:[]}}),Ve=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Le=b((t,l)=>{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(l,()=>g,[l,g]),/*#__PURE__*/e.createElement(c,g,/*#__PURE__*/e.createElement(S.form,W({ref:E,onSubmit:x(b,y)},N,{className:a("saas-form",t.className)}),v))});Le.getFieldResolver=Re,t&&(Le.displayName="Form");const we=["children"],Ie=({children:t})=>/*#__PURE__*/e.createElement(S.div,null,t);t&&(Ie.displayName="FormLayoutItem");const Ae=t=>{var l,r,n;let{children:s}=t,i=X(t,we);const o=W({},null!=(l=null==(r=k().components)||null==(n=r.FormLayout)?void 0:n.defaultProps)?l:{spacing:4},i);/*#__PURE__*/return e.createElement(R,W({},o,{className:a("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,l)=>e.Children.map(l,l=>e.isValidElement(l)&&l.props.name?e.cloneElement(l,W({},l.props,{name:`${t}.${l.props.name}`})):l),[Be,Oe]=G({name:"ArrayFieldContext"}),[Ue,_e]=G({name:"ArrayFieldRowContext"}),je=({name:e,defaultValue:t={},keyName:l,min:a,max:r})=>{const{control:n}=s();return W({},d({control:n,name:e,keyName:l}),{name:e,defaultValue:t,min:a,max:r})},Me=({index:t})=>{const{clearErrors:l}=s(),{name:a,remove:r,fields:n}=Oe();return e.useEffect(()=>{l(a)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${a}.${t}`,remove:e.useCallback(()=>{l(a),r(t)},[t])}},Pe=()=>{const{isFirst:e,remove:t}=_e(),{min:l,fields:a}=Oe();return{onClick:()=>t(),isDisabled:e&&!!(l&&a.length<=l)}},$e=()=>{const{append:e,defaultValue:t,max:l,fields:a}=Oe();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(l&&a.length>=l)}},qe=["children","columns","spacing"],Ge=["children"],He=["name","defaultValue","keyName","min","max","children"],ze=({children:t,columns:l,spacing:a,index:r})=>/*#__PURE__*/e.createElement(Ke,{index:r},/*#__PURE__*/e.createElement(Je,{columns:l,spacing:a},t),/*#__PURE__*/e.createElement(Qe,null));t&&(ze.displayName="ArrayFieldRow");const Je=t=>{let{children:l,columns:a,spacing:r}=t,n=X(t,qe);const{name:s}=_e();/*#__PURE__*/return e.createElement(Ae,W({flex:"1",columns:a,gridGap:r,mr:"2"},n),De(s,l))};t&&(Je.displayName="ArrayFieldRowFields");const Ke=({children:t,index:l})=>{const a=Me({index:l});/*#__PURE__*/return e.createElement(Ue,{value:a},/*#__PURE__*/e.createElement(O.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,l)=>{const{children:a}=t,r=X(t,Ge);/*#__PURE__*/return e.createElement(Ye,W({ref:l},r),/*#__PURE__*/e.createElement(Xe,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},l)=>/*#__PURE__*/e.createElement(ze,{key:t,index:l},a)))),/*#__PURE__*/e.createElement(Te,null))});t&&(We.displayName="ArrayField");const Xe=({children:e})=>{const{fields:t}=Oe();return e(t)};t&&(Xe.displayName="ArrayFieldRows");const Ye=e.forwardRef((t,l)=>{let{name:a,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=X(t,He);const c=je({name:a,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(l,()=>c,[l,c]),/*#__PURE__*/e.createElement(Be,{value:c},/*#__PURE__*/e.createElement(de,W({name:a},m),o))});t&&(Ye.displayName="ArrayFieldContainer");const Ze=["name","label","hideLabel","children","columns","spacing"],et=t=>{const l=V();/*#__PURE__*/return e.createElement(f,W({as:"legend",sx:l.legend},t))},tt=t=>{const{name:l,label:a,hideLabel:r,children:n,columns:s,spacing:i}=t,o=X(t,Ze);/*#__PURE__*/return e.createElement(p,W({name:l,as:"fieldset"},o),/*#__PURE__*/e.createElement(et,{display:r?"none":"block"},a),/*#__PURE__*/e.createElement(Ae,{columns:s,gridGap:i},De(l,n)))};t&&(tt.displayName="ObjectField");const lt=["name","type"],at=["schema","fieldResolver"],rt=["name","type","defaultValue"],nt=(t,l)=>{var a;return null==(a=t.getNestedFields(l))?void 0:a.map((t,l)=>{let{name:a,type:r}=t,n=X(t,lt);/*#__PURE__*/return e.createElement(ue,W({key:a||l,name:a,type:r},n))})},st=t=>{let{schema:l,fieldResolver:a}=t,r=X(t,at);const n=e.useMemo(()=>a||Le.getFieldResolver(l),[l,a]);/*#__PURE__*/return e.createElement(Ae,r,n.getFields().map(t=>{let{name:l,type:a}=t,r=X(t,rt);return"array"===a?/*#__PURE__*/e.createElement(We,W({key:l,name:l},r),nt(n,l)):"object"===a?/*#__PURE__*/e.createElement(tt,W({key:l,name:l},r),nt(n,l)):/*#__PURE__*/e.createElement(ue,W({key:l,name:l,type:a},r))}))};t&&(st.displayName="Fields");const it=["children","disableIfUntouched","disableIfInvalid"],ot=U((t,l)=>{const{children:a,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:l,isDisabled:r&&!o.isDirty||n&&!o.isValid},i),a)});ot.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(ot.displayName="SubmitButton");const mt=["schema","submitLabel","fieldResolver"],ct=b((t,l)=>{const{schema:a,submitLabel:r="Submit",fieldResolver:n}=t,s=X(t,mt);/*#__PURE__*/return e.createElement(Le,W({},s,{schema:a,ref:l}),/*#__PURE__*/e.createElement(Ae,null,/*#__PURE__*/e.createElement(st,{schema:a,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(ot,{label:r})))});t&&(ct.displayName="AutoForm");const dt=({children:e,name:t,defaultValue:l,isDisabled:a,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:l,disabled:a,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 l=H(t),{activeStep:a,isLastStep:r,nextStep:n}=l,[s,i]=e.useState({}),o=e.useCallback(async e=>{if(r)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{c(W({},s[a],{isCompleted:!0}))}).then(n);n()},[a,r]),m=e.useCallback(()=>{const e=s[a];return{onSubmit:o,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[s,o,a]),c=e.useCallback(e=>{i(t=>W({},t,{[e.name]:e}))},[s]);return W({getFormProps:m,updateStep:c,steps:s},l)}function ht(t){const{name:l,schema:a,resolver:r}=t,n=z({name:l}),{steps:s,updateStep:i}=pt();return e.useEffect(()=>{i({name:l,schema:a,resolver:r})},[l,a]),W({},n,s[l]||{name:l,schema:a})}const bt=["children","onSubmit"],yt=["getFormProps"],Et=["name","schema","resolver","children","className"],vt=["label","submitLabel"],Nt=e.forwardRef((t,l)=>{const{children:a}=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:l},n,i()),r(a,s))))}),Ft=t=>{const l=_("Stepper",t),{children:a}=t,r=e.Children.map(a,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===gt){const{isCompleted:l}=ht(t.props);/*#__PURE__*/return e.createElement(K,{name:t.props.name,title:t.props.title,isCompleted:l},t.props.children)}return t});/*#__PURE__*/return e.createElement(j,{value:l},/*#__PURE__*/e.createElement(Q,W({mb:"4"},t),r))},gt=t=>{const{name:l,schema:r,resolver:n,children:s,className:i}=t,o=X(t,Et),m=ht({name:l,schema:r,resolver:n}),{isActive:c}=m;return c?/*#__PURE__*/e.createElement(O.div,W({},o,{className:a("saas-form__step",i)}),s):null};t&&(gt.displayName="FormStep");const xt=t=>{const{isFirstStep:l,isCompleted:r,prevStep:s}=T();/*#__PURE__*/return e.createElement(q,W({isDisabled:l||r,label:"Back"},t,{className:a("saas-form__prev-button",t.className),onClick:n(t.onClick,s)}))};t&&(xt.displayName="PrevButton");const Ct=t=>{const{label:l="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:l},n,{className:a("saas-form__next-button",t.className)}))};t&&(Ct.displayName="NextButton");export{We as ArrayField,Te as ArrayFieldAddButton,Ye as ArrayFieldContainer,Be as ArrayFieldProvider,Qe as ArrayFieldRemoveButton,ze as ArrayFieldRow,Ke as ArrayFieldRowContainer,Je as ArrayFieldRowFields,Ue 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,Se 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,je as useArrayField,$e as useArrayFieldAddButton,Oe as useArrayFieldContext,Pe as useArrayFieldRemoveButton,Me as useArrayFieldRow,_e as useArrayFieldRowContext,ht as useFormStep,ft as useStepForm,pt as useStepFormContext,pe as withControlledInput,fe as withUncontrolledInput};
|
2
2
|
//# sourceMappingURL=index.modern.js.map
|
package/dist/index.modern.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.modern.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 name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema) =>\n schema &&\n Object.entries(schema).map(([name, field]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\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\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\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 FormProps<TFieldValues> {}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n) {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(\n (props) => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n },\n [steps, onSubmitStep, activeStep]\n )\n\n const updateStep = React.useCallback(\n (step) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport type UseStepFormReturn = ReturnType<typeof useStepForm>\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {\n chakra,\n HTMLChakraProps,\n useMultiStyleConfig,\n StylesProvider,\n} from '@chakra-ui/system'\n\nimport { callAllHandlers, runIfFn, cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n StepperProvider,\n StepperSteps,\n StepperStepsProps,\n StepperStep,\n useStepperContext,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form, FormProps } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues>,\n FormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps(props)}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const styles = useMultiStyleConfig('Stepper', props)\n\n const { children } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n return (\n <StylesProvider value={styles}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StylesProvider>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, ...rest } = props\n const step = useFormStep({ name, schema, resolver })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n"],"names":["DisplayField","_ref","name","label","props","React","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","withControlledInput","rules","inputProps","control","Controller","render","_ref3","field","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","isControlled","isDisabled","isReadOnly","isRequired","inputRules","required","createField","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","columns","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","id","key","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","_ref2","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","isCompleted","getFormProps","step","useFormStep","useStep","StepForm","ctx","StepperProvider","runIfFn","FormStepper","useMultiStyleConfig","elements","FormStep","StepperStep","title","StylesProvider","StepperSteps","isActive","PrevButton","isFirstStep","prevStep","useStepperContext","callAllHandlers","NextButton"],"mappings":"0kDAiBaA,EAA4CC,QAACC,KACxDA,EADwDC,MAExDA,KAEGC,sBAEH,OACEC,gBAACC,EAAgBF,EACdD,eAAQE,gBAACE,GAAUC,QAASN,GAAOC,GAAqB,kBACzDE,gBAACI,GAAKC,SAAS,mBACbL,gBAACM,IAAUT,KAAMA,OAMrBU,IACFZ,EAAaa,YAAc,gBAGhBF,MAAAA,GAAwC,EAAGT,KAAAA,MACtD,MAAMY,UAAEA,GAAcC,IACtB,OAAOD,EAAUZ,IAAS,MAGxBU,IACFD,GAAUE,YAAc,uQCsEpBG,GAAsC,GAEtCC,GAAmB,OAiBZC,GAAmCd,IAC9C,MAAMF,KAAEA,EAAFC,MAAQA,EAARgB,KAAeA,EAAfC,QAAqBA,EAArBC,UAA8BA,EAA9BC,SAAyCA,GAC7ClB,EAD0DmB,IAC1DnB,OAEIoB,UAAEA,GAAcT,IAEhBU,EAjBS,EAACvB,EAAcsB,IACvBE,EAAIF,EAAUG,OAAQzB,GAgBf0B,CAAS1B,EAAMsB,gBAE7B,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EAAcvN,GAC7C2G,GACJS,UAAWC,EAAG,yBAA0BpH,EAAMmH,eAKhD3G,IACF6P,GAAW5P,YAAc"}
|
1
|
+
{"version":3,"file":"index.modern.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\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\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 FormProps<TFieldValues> {}\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({})\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) => {\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} 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 FormProps<TFieldValues> {\n children:\n | React.ReactNode\n | ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement)\n}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps()}>\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","React","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","withControlledInput","rules","inputProps","control","Controller","render","_ref3","field","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","isControlled","id","isDisabled","isReadOnly","isRequired","inputRules","required","createField","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","columns","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","_ref2","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","isCompleted","getFormProps","step","useFormStep","useStep","StepForm","ctx","StepperProvider","runIfFn","FormStepper","useMultiStyleConfig","elements","FormStep","StepperStep","title","StylesProvider","StepperSteps","isActive","PrevButton","isFirstStep","prevStep","useStepperContext","callAllHandlers","NextButton"],"mappings":"0kDAiBaA,EAA4CC,QAACC,KACxDA,EADwDC,MAExDA,KAEGC,sBAEH,OACEC,gBAACC,EAAgBF,EACdD,eAAQE,gBAACE,GAAUC,QAASN,GAAOC,GAAqB,kBACzDE,gBAACI,GAAKC,SAAS,mBACbL,gBAACM,IAAUT,KAAMA,OAMrBU,IACFZ,EAAaa,YAAc,gBAGhBF,MAAAA,GAAwC,EAAGT,KAAAA,MACtD,MAAMY,UAAEA,GAAcC,IACtB,OAAOD,EAAUZ,IAAS,MAGxBU,IACFD,GAAUE,YAAc,4QCsEpBG,GAAsC,GAEtCC,GAAmB,OAiBZC,GAAmCd,IAC9C,MAAMF,KAAEA,EAAFC,MAAQA,EAARgB,KAAeA,EAAfC,QAAqBA,EAArBC,UAA8BA,EAA9BC,SAAyCA,GAC7ClB,EAD0DmB,IAC1DnB,OAEIoB,UAAEA,GAAcT,IAEhBU,EAjBS,EAACvB,EAAcsB,IACvBE,EAAIF,EAAUG,OAAQzB,GAgBf0B,CAAS1B,EAAMsB,gBAE7B,OACEnB,gBAACC,KAAYc,QAASA,GAAaG,GAAcM,YAAaJ,IAC3DtB,IAAUkB,eACThB,gBAACE,GAAUa,QAASA,GAAUjB,GAC5B,kBACJE,gBAACyB,OACER,GACAH,SAASM,GAAAA,EAAOM,QAEb,kBADF1B,gBAAC2B,OAAgBb,UAElBM,SAAAA,EAAOM,uBACN1B,gBAAC4B,aAAkBR,SAAAA,EAAOM,YAOhCnB,IACFM,GAAUL,YAAc,aAGbqB,MAAAA,GAAQC,EACnB,CACE/B,EAGAgC,KAEA,MAAMC,KAAEA,EAAOpB,IAAqBb,EAC9BkC,EArDQD,CAAAA,GACTrB,GAAWqB,IAASrB,GAAWC,IAoDbsB,CAASF,gBAEhC,OAAOhC,gBAACiC,KAAeF,IAAKA,GAAShC,MAqE5BoC,GAAuBF,GAC3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AhB9E,SAA0BA,EAA1BkG,UAAoCA,GAAuBpH,EAAT2G,IAAS3G,MAC3DgP,EAAOC,GAAY,CAAEnP,KAAAA,EAAMwF,OAAAA,EAAQU,SAAAA,KAEnC+J,SAAEA,GAAaf,EAErB,OAAOe,eACL9P,gBAACkH,EAAOK,SAAQb,GAAMS,UAAWC,EAAG,kBAAmBD,KACpDlG,GAED,MAGFV,IACFkP,GAASjP,YAAc,YAGZuP,MAAAA,GAAqChQ,IAChD,MAAMiQ,YAAEA,EAAFnB,YAAeA,EAAfoB,SAA4BA,GAAaC,iBAE/C,OACElQ,gBAAC8M,KACC3J,WAAY6M,GAAenB,EAC3B/O,MAAM,QACFC,GACJoH,UAAWC,EAAG,yBAA0BrH,EAAMoH,WAC9CyC,QAASuG,EAAgBpQ,EAAM6J,QAASqG,OAK1C1P,IACFwP,GAAWvP,YAAc,cAOd4P,MAAAA,GAAyCrQ,IACpD,MAAMD,MAAEA,EAAQ,OAAVuN,YAAkBA,EAAc,YAAwBtN,EAAT2G,IAAS3G,OACxDoO,WAAEA,EAAFU,YAAcA,GAAgBqB,iBAEpC,OACElQ,gBAAC2M,MACCxJ,WAAY0L,EACZ/O,MAAOqO,GAAcU,EAAcxB,EAAcvN,GAC7C4G,GACJS,UAAWC,EAAG,yBAA0BrH,EAAMoH,eAKhD5G,IACF6P,GAAW5P,YAAc"}
|
package/dist/step-form.d.ts
CHANGED
@@ -4,8 +4,9 @@ import { HTMLChakraProps } from '@chakra-ui/system';
|
|
4
4
|
import { StepperStepsProps } from '@saas-ui/stepper';
|
5
5
|
import { ButtonProps } from '@saas-ui/button';
|
6
6
|
import { FormProps } from './form';
|
7
|
-
import { UseStepFormProps } from './use-step-form';
|
7
|
+
import { UseStepFormProps, UseStepFormReturn } from './use-step-form';
|
8
8
|
export interface StepFormProps<TFieldValues extends FieldValues = FieldValues> extends UseStepFormProps<TFieldValues>, FormProps<TFieldValues> {
|
9
|
+
children: React.ReactNode | ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement);
|
9
10
|
}
|
10
11
|
export declare const StepForm: <TFieldValues extends FieldValues>(props: FormProps<TFieldValues> & {
|
11
12
|
ref?: React.ForwardedRef<UseFormReturn<TFieldValues, object>> | undefined;
|
package/dist/step-form.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"step-form.d.ts","sourceRoot":"","sources":["../src/step-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE5D,OAAO,EAEL,eAAe,EAGhB,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAGL,iBAAiB,EAGlB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAU,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAA;AAGxC,OAAO,EAIL,gBAAgB,
|
1
|
+
{"version":3,"file":"step-form.d.ts","sourceRoot":"","sources":["../src/step-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE5D,OAAO,EAEL,eAAe,EAGhB,MAAM,mBAAmB,CAAA;AAI1B,OAAO,EAGL,iBAAiB,EAGlB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAU,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAA;AAGxC,OAAO,EAIL,gBAAgB,EAChB,iBAAiB,EAClB,MAAM,iBAAiB,CAAA;AAExB,MAAM,WAAW,aAAa,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,CAC3E,SAAQ,gBAAgB,CAAC,YAAY,CAAC,EACpC,SAAS,CAAC,YAAY,CAAC;IACzB,QAAQ,EACJ,KAAK,CAAC,SAAS,GACf,CAAC,CAAC,OAAO,EAAE,iBAAiB,CAAC,YAAY,CAAC,KAAK,KAAK,CAAC,YAAY,CAAC,CAAA;CACvE;AAED,eAAO,MAAM,QAAQ;;MA2BhB,MAAM,YAAY,CAAA;AAEvB,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAA;CACf;AAED,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4BnD,CAAA;AAED,MAAM,WAAW,aACf,SAAQ,eAAe,EACrB,eAAe,CAAC,KAAK,CAAC;CAAG;AAE7B,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAW5C,CAAA;AAMD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAY5C,CAAA;AAMD,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAClD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAYhD,CAAA"}
|
package/dist/use-step-form.d.ts
CHANGED
@@ -16,28 +16,16 @@ export declare const StepFormProvider: React.Provider<StepFormContext>, useStepF
|
|
16
16
|
import { FormProps } from './form';
|
17
17
|
export interface UseStepFormProps<TFieldValues extends FieldValues = FieldValues> extends UseStepperProps, FormProps<TFieldValues> {
|
18
18
|
}
|
19
|
-
export
|
20
|
-
|
21
|
-
activeStep: string;
|
22
|
-
activeIndex: number;
|
23
|
-
isFirstStep: boolean;
|
24
|
-
isLastStep: boolean;
|
25
|
-
isCompleted: boolean;
|
26
|
-
setIndex: React.Dispatch<React.SetStateAction<number>>;
|
27
|
-
setStep: (name: string) => void;
|
28
|
-
nextStep: () => void;
|
29
|
-
prevStep: () => void;
|
30
|
-
registerStep: (name: string) => void;
|
31
|
-
unregisterStep: (name: string) => void;
|
32
|
-
getFormProps: (props: any) => {
|
19
|
+
export interface UseStepFormReturn<TFieldValues extends FieldValues = FieldValues> extends UseStepperReturn {
|
20
|
+
getFormProps(): {
|
33
21
|
onSubmit: SubmitHandler<TFieldValues>;
|
34
|
-
schema
|
35
|
-
resolver
|
22
|
+
schema?: any;
|
23
|
+
resolver?: any;
|
36
24
|
};
|
37
|
-
updateStep
|
38
|
-
steps:
|
39
|
-
}
|
40
|
-
export declare
|
25
|
+
updateStep(step: any): void;
|
26
|
+
steps: Record<string, any>;
|
27
|
+
}
|
28
|
+
export declare function useStepForm<TFieldValues extends FieldValues = FieldValues>(props: UseStepFormProps<TFieldValues>): UseStepFormReturn<TFieldValues>;
|
41
29
|
export interface UseFormStepProps {
|
42
30
|
name: string;
|
43
31
|
schema?: any;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-step-form.d.ts","sourceRoot":"","sources":["../src/use-step-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE5D,OAAO,EAGL,eAAe,EACf,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AAEzB,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,QAAQ,CAAC,EAAE,GAAG,CAAA;IACd,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAA;IAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;CACjC;AAED,eAAO,MAAO,gBAAgB,mCAAE,kBAAkB,uBAK9C,CAAA;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EAAE,GAAG,CAAA;KACf,CAAA;IACD,UAAU,CAAC,IAAI,EAAE,GAAG,GAAG,IAAI,CAAA;IAC3B,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC3B;AAED,wBAAgB,WAAW,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,EACxE,KAAK,EAAE,gBAAgB,CAAC,YAAY,CAAC,GACpC,iBAAiB,CAAC,YAAY,CAAC,CAsDjC;AAED,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,QAAQ,CAAC,EAAE,GAAG,CAAA;CACf;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAc9D"}
|
File without changes
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../zod/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
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 } from '@saas-ui/forms'\
|
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","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zB,EAAQsB,EAAeC,GAC7CG,cAAeV,EAAiBhB,qBASb,SAACQ,GACtB,OAAOW,KAAKQ,UAAUnB"}
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.modern.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 } from '@saas-ui/forms'\
|
1
|
+
{"version":3,"file":"index.modern.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","zodForm","schemaOptions","resolverOptions","resolver","zodResolver","fieldResolver","zodMeta","JSON","stringify","parse","e"],"mappings":"8VAYA,MAAMA,EAAWC,IACf,OAAQA,EAAMC,KAAKC,UACjB,IAAK,WACH,MAAO,QACT,IAAK,YACH,MAAO,SACT,IAAK,YACH,MAAO,SACT,IAAK,UACH,MAAO,OAET,QACE,MAAO,SAIPC,EAAiB,CAACH,EAAYI,WAClC,gBAAOJ,EAAMC,KAAKG,WAAXC,EAAkBC,OASdC,EAAuBC,IAClC,MAAMC,EAAuB,GAE7B,IAAIC,EAAoC,GACxC,GAA6B,aAAzBF,EAAOP,KAAKC,SACdQ,EAAeF,EAAOP,KAAKU,KAAKC,cACE,cAAzBJ,EAAOP,KAAKC,SAGrB,OAAOO,EAFPC,EAAeF,EAAOP,KAAKW,QAK7B,IAAK,MAAMR,KAAQM,EAAc,CAC/B,MAAMV,EAAQU,EAAaN,GAErBS,EAAmB,GACG,aAAxBb,EAAMC,KAAKC,WACbW,EAAQC,IAAMX,EAAeH,EAAO,aACpCa,EAAQE,IAAMZ,EAAeH,EAAO,cAGtC,MAAMgB,EAAOhB,EAAMiB,aAAeC,EAAalB,EAAMiB,aAErDR,EAAOU,QACLf,KAAAA,EACAgB,MAAOJ,EAAKI,OAASpB,EAAMiB,aAAeb,EAC1CO,KAAMK,EAAKL,MAAQZ,EAAQC,IACxBa,IAGP,OAAOJ,GAGIY,EAAkB,CAACb,EAAsBc,IAC7CC,EAAIf,EAAOP,KAAKW,QAASU,GAGrBE,EAA4ChB,IAChD,CACLiB,UAAS,IACAlB,EAAoBC,GAE7BkB,gBAAgBtB,GACPG,EAAoBc,EAAgBb,EAAQJ,MAK5CuB,EAAU,CACrBnB,EACAoB,EAAgB,GAChBC,EAAkB,MAEX,CACLrB,OAAAA,EACAsB,SAAUC,EAAYvB,EAAQoB,EAAeC,GAC7CG,cAAeR,EAAiBhB,KASvByB,EAAWjB,GACfkB,KAAKC,UAAUnB,GAGXE,EAAgBF,IAC3B,IACE,OAAOkB,KAAKE,MAAMpB,GAClB,MAAOqB,GACP,OAAOrB"}
|
@@ -1,7 +1,6 @@
|
|
1
1
|
import * as z from 'zod';
|
2
2
|
import { zodResolver } from '@hookform/resolvers/zod';
|
3
|
-
import { FieldProps } from '@saas-ui/forms';
|
4
|
-
import { FieldTypes } from '../../src';
|
3
|
+
import { FieldProps, FieldTypes } from '@saas-ui/forms';
|
5
4
|
export { zodResolver };
|
6
5
|
export declare type Options = {
|
7
6
|
min?: number;
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"zod-resolver.d.ts","sourceRoot":"","sources":["../../zod/src/zod-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAEvD,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,oBAAY,OAAO,GAAG;IACpB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAsBD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,4BAA2B,UAAU,EA+BpE,CAAA;AAED,eAAO,MAAM,eAAe,+BAAgC,MAAM,QAEjE,CAAA;AAED,eAAO,MAAM,gBAAgB;;0BAKH,MAAM;CAI/B,CAAA;AAED,eAAO,MAAM,OAAO;;;;;8BANM,MAAM;;CAgB/B,CAAA;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB;AAED,eAAO,MAAM,OAAO,SAAU,OAAO,WAEpC,CAAA;AAED,eAAO,MAAM,YAAY,SAAU,MAAM,QAMxC,CAAA"}
|
package/package.json
CHANGED
package/src/field.tsx
CHANGED
@@ -192,6 +192,7 @@ const createField = (
|
|
192
192
|
) => {
|
193
193
|
const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {
|
194
194
|
const {
|
195
|
+
id,
|
195
196
|
name,
|
196
197
|
label,
|
197
198
|
help,
|
@@ -211,6 +212,7 @@ const createField = (
|
|
211
212
|
|
212
213
|
return (
|
213
214
|
<BaseField
|
215
|
+
id={id}
|
214
216
|
name={name}
|
215
217
|
label={label}
|
216
218
|
help={help}
|
@@ -223,6 +225,7 @@ const createField = (
|
|
223
225
|
>
|
224
226
|
<InputComponent
|
225
227
|
ref={ref}
|
228
|
+
id={id}
|
226
229
|
name={name}
|
227
230
|
label={label}
|
228
231
|
rules={inputRules}
|
package/src/step-form.tsx
CHANGED
@@ -28,11 +28,16 @@ import {
|
|
28
28
|
useFormStep,
|
29
29
|
StepFormProvider,
|
30
30
|
UseStepFormProps,
|
31
|
+
UseStepFormReturn,
|
31
32
|
} from './use-step-form'
|
32
33
|
|
33
34
|
export interface StepFormProps<TFieldValues extends FieldValues = FieldValues>
|
34
35
|
extends UseStepFormProps<TFieldValues>,
|
35
|
-
FormProps<TFieldValues> {
|
36
|
+
FormProps<TFieldValues> {
|
37
|
+
children:
|
38
|
+
| React.ReactNode
|
39
|
+
| ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement)
|
40
|
+
}
|
36
41
|
|
37
42
|
export const StepForm = React.forwardRef(
|
38
43
|
<TFieldValues extends FieldValues = FieldValues>(
|
@@ -50,7 +55,7 @@ export const StepForm = React.forwardRef(
|
|
50
55
|
return (
|
51
56
|
<StepperProvider value={context}>
|
52
57
|
<StepFormProvider value={context}>
|
53
|
-
<Form ref={ref} {...rest} {...getFormProps(
|
58
|
+
<Form ref={ref} {...rest} {...getFormProps()}>
|
54
59
|
{runIfFn(children, stepper)}
|
55
60
|
</Form>
|
56
61
|
</StepFormProvider>
|
package/src/use-step-form.tsx
CHANGED
@@ -35,9 +35,21 @@ export interface UseStepFormProps<
|
|
35
35
|
> extends UseStepperProps,
|
36
36
|
FormProps<TFieldValues> {}
|
37
37
|
|
38
|
+
export interface UseStepFormReturn<
|
39
|
+
TFieldValues extends FieldValues = FieldValues
|
40
|
+
> extends UseStepperReturn {
|
41
|
+
getFormProps(): {
|
42
|
+
onSubmit: SubmitHandler<TFieldValues>
|
43
|
+
schema?: any
|
44
|
+
resolver?: any
|
45
|
+
}
|
46
|
+
updateStep(step: any): void
|
47
|
+
steps: Record<string, any>
|
48
|
+
}
|
49
|
+
|
38
50
|
export function useStepForm<TFieldValues extends FieldValues = FieldValues>(
|
39
51
|
props: UseStepFormProps<TFieldValues>
|
40
|
-
) {
|
52
|
+
): UseStepFormReturn<TFieldValues> {
|
41
53
|
const stepper = useStepper(props)
|
42
54
|
|
43
55
|
const { activeStep, isLastStep, nextStep } = stepper
|
@@ -64,17 +76,14 @@ export function useStepForm<TFieldValues extends FieldValues = FieldValues>(
|
|
64
76
|
[activeStep, isLastStep]
|
65
77
|
)
|
66
78
|
|
67
|
-
const getFormProps = React.useCallback(
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
},
|
76
|
-
[steps, onSubmitStep, activeStep]
|
77
|
-
)
|
79
|
+
const getFormProps = React.useCallback(() => {
|
80
|
+
const step = steps[activeStep]
|
81
|
+
return {
|
82
|
+
onSubmit: onSubmitStep,
|
83
|
+
schema: step?.schema,
|
84
|
+
resolver: step?.resolver,
|
85
|
+
}
|
86
|
+
}, [steps, onSubmitStep, activeStep])
|
78
87
|
|
79
88
|
const updateStep = React.useCallback(
|
80
89
|
(step) => {
|
@@ -96,8 +105,6 @@ export function useStepForm<TFieldValues extends FieldValues = FieldValues>(
|
|
96
105
|
}
|
97
106
|
}
|
98
107
|
|
99
|
-
export type UseStepFormReturn = ReturnType<typeof useStepForm>
|
100
|
-
|
101
108
|
export interface UseFormStepProps {
|
102
109
|
name: string
|
103
110
|
schema?: any
|
package/yup/package.json
CHANGED
@@ -4,17 +4,6 @@
|
|
4
4
|
"version": "1.0.0",
|
5
5
|
"private": true,
|
6
6
|
"source": "./src/index.ts",
|
7
|
-
"exports": {
|
8
|
-
".": {
|
9
|
-
"development": "./src/index.ts",
|
10
|
-
"require": "./../dist/yup/index.js",
|
11
|
-
"types": "./../dist/yup/src/index.d.ts",
|
12
|
-
"default": "./../dist/yup/index.modern.js"
|
13
|
-
},
|
14
|
-
"./src": {
|
15
|
-
"default": "./src/index.ts"
|
16
|
-
}
|
17
|
-
},
|
18
7
|
"main": "../dist/yup/index.js",
|
19
8
|
"module": "../dist/yup/index.modern.js",
|
20
9
|
"types": "../dist/yup/index.d.ts",
|
package/zod/package.json
CHANGED
@@ -4,17 +4,6 @@
|
|
4
4
|
"version": "1.0.0",
|
5
5
|
"private": true,
|
6
6
|
"source": "./src/index.ts",
|
7
|
-
"exports": {
|
8
|
-
".": {
|
9
|
-
"development": "./src/index.ts",
|
10
|
-
"require": "./../dist/zod/index.js",
|
11
|
-
"types": "./../dist/zod/src/index.d.ts",
|
12
|
-
"default": "./../dist/zod/index.modern.js"
|
13
|
-
},
|
14
|
-
"./src": {
|
15
|
-
"default": "./src/index.ts"
|
16
|
-
}
|
17
|
-
},
|
18
7
|
"main": "../dist/zod/index.js",
|
19
8
|
"module": "../dist/zod/index.modern.js",
|
20
9
|
"types": "../dist/zod/index.d.ts",
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../zod/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
|
@@ -1 +0,0 @@
|
|
1
|
-
{"version":3,"file":"zod-resolver.d.ts","sourceRoot":"","sources":["../../../../zod/src/zod-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,KAAK,CAAA;AACxB,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,WAAW,CAAA;AAEtC,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,oBAAY,OAAO,GAAG;IACpB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AAsBD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,4BAA2B,UAAU,EA+BpE,CAAA;AAED,eAAO,MAAM,eAAe,+BAAgC,MAAM,QAEjE,CAAA;AAED,eAAO,MAAM,gBAAgB;;0BAKH,MAAM;CAI/B,CAAA;AAED,eAAO,MAAM,OAAO;;;;;8BANM,MAAM;;CAgB/B,CAAA;AAED,MAAM,WAAW,OAAO;IACtB,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,UAAU,CAAA;CAClB;AAED,eAAO,MAAM,OAAO,SAAU,OAAO,WAEpC,CAAA;AAED,eAAO,MAAM,YAAY,SAAU,MAAM,QAMxC,CAAA"}
|