@saas-ui/forms 1.0.0-rc.4 → 1.0.0-rc.5
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +6 -0
- package/ajv/package.json +18 -0
- package/dist/ajv/ajv-resolver.d.ts +11 -0
- package/dist/ajv/ajv-resolver.d.ts.map +1 -0
- package/dist/ajv/index.d.ts +2 -0
- package/dist/ajv/index.d.ts.map +1 -0
- package/dist/ajv/index.js +97 -0
- package/dist/ajv/index.js.map +1 -0
- package/dist/ajv/index.modern.mjs +97 -0
- package/dist/ajv/index.modern.mjs.map +1 -0
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.modern.mjs.map +1 -1
- package/dist/step-form.d.ts.map +1 -1
- package/package.json +11 -3
- package/src/step-form.tsx +1 -10
- package/yup/package.json +2 -2
- package/zod/package.json +4 -4
package/dist/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var e=require("react"),r=require("@chakra-ui/utils"),t=require("react-hook-form"),n=require("@chakra-ui/react"),a=require("@saas-ui/number-input"),l=require("@saas-ui/password-input"),i=require("@saas-ui/radio"),o=require("@saas-ui/pin-input"),s=require("@saas-ui/select"),u=require("@chakra-ui/system"),d=require("@chakra-ui/icons"),m=require("@saas-ui/button"),c=require("@chakra-ui/react-utils"),p=require("@saas-ui/stepper"),f=require("@saas-ui/input-right-button");function v(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var x=/*#__PURE__*/v(e);function h(){return h=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},h.apply(this,arguments)}function F(e,r){if(null==e)return{};var t,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)r.indexOf(t=l[n])>=0||(a[t]=e[t]);return a}var 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"],g=["name","rules"],S=["ref"],N=["name","rules"],R=["ref"],V=["type"],w=["type"],D=["label","type"],k={},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 I=n.forwardRef(function(e,r){var t=e.type;/*#__PURE__*/return x.createElement(k[void 0===t?"text":t]||k.text,h({ref:r},e))}),L=function(e){return n.forwardRef(function(r,a){var l=r.name,i=r.rules,o=F(r,g),s=t.useFormContext();/*#__PURE__*/return x.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(r){var t=r.field,l=t.ref,i=F(t,S);/*#__PURE__*/return x.createElement(e,h({},i,o,{ref:n.useMergeRefs(a,l)}))}})})},P=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)}))})},B=function(e,r,t){var a=function(e,r){var t=r.displayName,a=r.hideLabel,l=r.BaseField,i=n.forwardRef(function(r,t){var n=r.id,i=r.name,o=r.label,s=r.help,u=r.isDisabled,d=r.isInvalid,m=r.isReadOnly,c=r.isRequired,p=r.rules,f=r.variant,v=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:a?o:void 0,rules:y},v)))});return i.displayName=t,i}(null!=t&&t.isControlled?L(r):P(r),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==t?void 0:t.hideLabel,BaseField:(null==t?void 0:t.BaseField)||A});return k[e]=a,a},O=B("text",n.forwardRef(function(e,r){var t=e.type,a=void 0===t?"text":t,l=F(e,V);/*#__PURE__*/return x.createElement(n.Input,h({type:a},l,{ref:r}))})),j=B("number",a.NumberInput,{isControlled:!0}),q=B("password",l.PasswordInput),M=B("textarea",n.Textarea),U=B("switch",n.forwardRef(function(e,r){var t=F(e,w);/*#__PURE__*/return x.createElement(n.Switch,h({},t,{ref:r}))}),{isControlled:!0}),T=B("select",s.Select,{isControlled:!0}),H=B("checkbox",n.forwardRef(function(e,r){var t=e.label,a=F(e,D);/*#__PURE__*/return x.createElement(n.Checkbox,h({ref:r},a),t)}),{hideLabel:!0}),G=B("radio",i.RadioInput,{isControlled:!0}),z=B("pin",o.PinInput,{isControlled:!0}),W=B("native-select",s.NativeSelect,{isControlled:!0}),J=["items"],K=function(e){return e&&Object.entries(e).map(function(e){var r=e[0];return h({},F(e[1],J),{name:r})})},Q=function(e){return{getFields:function(){return K(e)},getNestedFields:function(t){var n,a=r.get(e,t);return a?"object"===(null==(n=a.items)?void 0:n.type)?K(a.items.properties):"object"===a.type?K(a.properties):[a.items]:[]}}},X=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Y=n.forwardRef(function(e,a){var l=e.mode,i=void 0===l?"all":l,o=e.resolver,s=e.reValidateMode,u=e.shouldFocusError,d=e.shouldUnregister,m=e.shouldUseNativeValidation,c=e.criteriaMode,p=e.delayError,f=e.schema,v=e.defaultValues,y=e.onSubmit,b=e.onError,E=e.formRef,_=e.children,C=F(e,X),g={mode:i,resolver:o,defaultValues:v,reValidateMode:s,shouldFocusError:u,shouldUnregister:d,shouldUseNativeValidation:m,criteriaMode:c,delayError:p};f&&!o&&(g.resolver=null==Y.getResolver?void 0:Y.getResolver(f));var S=t.useForm(g),N=S.handleSubmit;return x.useImperativeHandle(a,function(){return S},[a,S]),/*#__PURE__*/x.createElement(t.FormProvider,S,/*#__PURE__*/x.createElement(n.chakra.form,h({ref:E,onSubmit:N(y,b)},C,{className:r.cx("saas-form",e.className)}),_))});Y.getFieldResolver=Q,r.__DEV__&&(Y.displayName="Form");var Z=["children"],$=function(e){/*#__PURE__*/return x.createElement(n.chakra.div,null,e.children)};r.__DEV__&&($.displayName="FormLayoutItem");var ee=function(e){var t,a,l,i=e.children,o=F(e,Z),s=h({},null!=(t=null==(a=n.useTheme().components)||null==(l=a.FormLayout)?void 0:l.defaultProps)?t:{spacing:4},o);/*#__PURE__*/return x.createElement(n.SimpleGrid,h({},s,{className:r.cx("saas-form__layout",o.className)}),x.Children.map(i,function(e){return x.isValidElement(e)?/*#__PURE__*/x.createElement($,null,e):e}))};r.__DEV__&&(ee.displayName="FormLayout");var re=function(e,r){return x.Children.map(r,function(r){return x.isValidElement(r)&&r.props.name?x.cloneElement(r,h({},r.props,{name:e+"."+r.props.name})):r})},te=c.createContext({name:"ArrayFieldContext"}),ne=te[0],ae=te[1],le=c.createContext({name:"ArrayFieldRowContext"}),ie=le[0],oe=le[1],se=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,s=t.useFormContext();return h({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},ue=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=ae(),l=a.name,i=a.remove,o=a.fields;return x.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:x.useCallback(function(){n(l),i(r)},[r])}},de=function(){var e=oe(),r=e.isFirst,t=e.remove,n=ae(),a=n.min;return{onClick:function(){return t()},isDisabled:r&&!!(a&&n.fields.length<=a)}},me=function(){var e=ae(),r=e.append,t=e.defaultValue,n=e.max;return{onClick:function(){return r(t,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},ce=["children","columns","spacing"],pe=["children"],fe=["name","defaultValue","keyName","min","max","children"],ve=function(e){/*#__PURE__*/return x.createElement(he,{index:e.index},/*#__PURE__*/x.createElement(xe,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/x.createElement(Fe,null))};r.__DEV__&&(ve.displayName="ArrayFieldRow");var xe=function(e){var r=e.children,t=e.columns,n=e.spacing,a=F(e,ce),l=oe().name;/*#__PURE__*/return x.createElement(ee,h({flex:"1",columns:t,gridGap:n,mr:"2"},a),re(l,r))};r.__DEV__&&(xe.displayName="ArrayFieldRowFields");var he=function(e){var r=e.children,t=ue({index:e.index});/*#__PURE__*/return x.createElement(ie,{value:t},/*#__PURE__*/x.createElement(u.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))};r.__DEV__&&(he.displayName="ArrayFieldRowContainer");var Fe=function(e){/*#__PURE__*/return x.createElement(m.IconButton,h({icon:/*#__PURE__*/x.createElement(d.MinusIcon,null),"aria-label":"Remove row"},de(),e))};r.__DEV__&&(Fe.displayName="ArrayFieldRemoveButton");var ye=function(e){/*#__PURE__*/return x.createElement(m.IconButton,h({icon:/*#__PURE__*/x.createElement(d.AddIcon,null),"aria-label":"Add row",float:"right"},me(),e))};r.__DEV__&&(ye.displayName="ArrayFieldAddButton");var be=x.forwardRef(function(e,r){var t=e.children,n=F(e,pe);/*#__PURE__*/return x.createElement(_e,h({ref:r},n),/*#__PURE__*/x.createElement(Ee,null,function(e){/*#__PURE__*/return x.createElement(x.Fragment,null,e.map(function(e,r){/*#__PURE__*/return x.createElement(ve,{key:e.id,index:r},t)}))}),/*#__PURE__*/x.createElement(ye,null))});r.__DEV__&&(be.displayName="ArrayField");var Ee=function(e){return(0,e.children)(ae().fields)};r.__DEV__&&(Ee.displayName="ArrayFieldRows");var _e=x.forwardRef(function(e,r){var t=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=F(e,fe),u=se({name:t,defaultValue:n,keyName:a,min:l,max:i});return x.useImperativeHandle(r,function(){return u},[r,u]),/*#__PURE__*/x.createElement(ne,{value:u},/*#__PURE__*/x.createElement(A,h({name:t},s),o))});r.__DEV__&&(_e.displayName="ArrayFieldContainer");var Ce=["name","label","hideLabel","children","columns","spacing"],ge=function(e){var r=n.useStyleConfig("FormLegend");/*#__PURE__*/return x.createElement(n.FormLabel,h({as:"legend",sx:r},e))},Se=function(e){var r=e.name,t=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=F(e,Ce);/*#__PURE__*/return x.createElement(n.FormControl,h({name:r,as:"fieldset"},s),/*#__PURE__*/x.createElement(ge,{display:a?"none":"block"},t),/*#__PURE__*/x.createElement(ee,{columns:i,gridGap:o},re(r,l)))};r.__DEV__&&(Se.displayName="ObjectField");var Ne=["name","type"],Re=["schema","fieldResolver"],Ve=["name","type","defaultValue"],we=function(e,r){var t;return null==(t=e.getNestedFields(r))?void 0:t.map(function(e,r){var t=e.name,n=e.type,a=F(e,Ne);/*#__PURE__*/return x.createElement(I,h({key:t||r,name:t,type:n},a))})},De=function(e){var r=e.schema,t=e.fieldResolver,n=F(e,Re),a=x.useMemo(function(){return t||Y.getFieldResolver(r)},[r,t]);/*#__PURE__*/return x.createElement(ee,n,a.getFields().map(function(e){var r=e.name,t=e.type,n=F(e,Ve);return"array"===t?/*#__PURE__*/x.createElement(be,h({key:r,name:r},n),we(a,r)):"object"===t?/*#__PURE__*/x.createElement(Se,h({key:r,name:r},n),we(a,r)):/*#__PURE__*/x.createElement(I,h({key:r,name:r,type:t},n))}))};r.__DEV__&&(De.displayName="Fields");var ke=["children","disableIfUntouched","disableIfInvalid"],Ae=u.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=F(e,ke),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)});Ae.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},r.__DEV__&&(Ae.displayName="SubmitButton");var Ie=["schema","submitLabel","fieldResolver","children"],Le=n.forwardRef(function(e,r){var t=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=e.children,o=F(e,Ie);/*#__PURE__*/return x.createElement(Y,h({},o,{schema:t,ref:r}),/*#__PURE__*/x.createElement(ee,null,/*#__PURE__*/x.createElement(De,{schema:t,fieldResolver:l}),a&&/*#__PURE__*/x.createElement(Ae,{label:a}),i))});r.__DEV__&&(Le.displayName="AutoForm");var Pe=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null};r.__DEV__&&(Pe.displayName="DisplayIf");var Be=["onChange"],Oe=c.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),je=Oe[0],qe=Oe[1];function Me(e){var r=F(e,Be),t=p.useStepper(r),n=t.activeStep,a=t.isLastStep,l=t.nextStep,i=x.useState({}),o=i[0],s=i[1],u=x.useCallback(function(r){try{return a?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(r).then(function(){m(h({},o[n],{isCompleted:!0}))}).then(l)):(l(),Promise.resolve())}catch(e){return Promise.reject(e)}},[n,a]),d=x.useCallback(function(){var e=o[n];return{onSubmit:u,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[o,u,n]),m=x.useCallback(function(e){s(function(r){var t;return h({},r,((t={})[e.name]=e,t))})},[o]);return h({getFormProps:d,updateStep:m,steps:o},t)}function Ue(e){var r=e.name,t=e.schema,n=e.resolver,a=p.useStep({name:r}),l=qe(),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 Te=["children"],He=["getFormProps"],Ge=["name","schema","resolver","children","className"],ze=["label","submitLabel"];u.createStylesContext("StepForm");var We=x.forwardRef(function(e,t){var n=e.children,a=F(e,Te),l=Me(e),i=l.getFormProps,o=F(l,He),s=x.useMemo(function(){return o},[o]);/*#__PURE__*/return x.createElement(p.StepperProvider,{value:s},/*#__PURE__*/x.createElement(je,{value:s},/*#__PURE__*/x.createElement(Y,h({ref:t},a,i()),r.runIfFn(n,l))))}),Je=function(e){var t=e.name,n=e.schema,a=e.resolver,l=e.children,i=e.className,o=F(e,Ge);return Ue({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__&&(Je.displayName="FormStep");var Ke=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__&&(Ke.displayName="PrevButton");var Qe=function(e){var t=e.label,n=void 0===t?"Next":t,a=e.submitLabel,l=void 0===a?"Complete":a,i=F(e,ze),o=p.useStepperContext(),s=o.isCompleted;/*#__PURE__*/return x.createElement(Ae,h({isDisabled:s,label:o.isLastStep||s?l:n},i,{className:r.cx("saas-form__next-button",e.className)}))};r.__DEV__&&(Qe.displayName="NextButton"),exports.ArrayField=be,exports.ArrayFieldAddButton=ye,exports.ArrayFieldContainer=_e,exports.ArrayFieldProvider=ne,exports.ArrayFieldRemoveButton=Fe,exports.ArrayFieldRow=ve,exports.ArrayFieldRowContainer=he,exports.ArrayFieldRowFields=xe,exports.ArrayFieldRowProvider=ie,exports.ArrayFieldRows=Ee,exports.AutoForm=Le,exports.BaseField=A,exports.CheckboxField=H,exports.DisplayField=b,exports.DisplayIf=Pe,exports.Field=I,exports.Fields=De,exports.Form=Y,exports.FormLayout=ee,exports.FormLegend=ge,exports.FormStep=Je,exports.FormStepper=function(e){var r=p.useStepperContext(),t=r.activeIndex,n=r.setIndex,a=x.Children.map(e.children,function(e){if(x.isValidElement(e)&&(null==e?void 0:e.type)===Je){var r=Ue(e.props);/*#__PURE__*/return x.createElement(p.StepperStep,{name:e.props.name,title:e.props.title,isCompleted:r.isCompleted},e.props.children)}return e}),l=x.useCallback(function(e){n(e)},[]);/*#__PURE__*/return x.createElement(p.StepperContainer,{step:t,onChange:l},/*#__PURE__*/x.createElement(p.StepperSteps,h({mb:"4"},e),a))},exports.FormValue=E,exports.InputField=O,exports.NativeSelectField=W,exports.NextButton=Qe,exports.NumberInputField=j,exports.ObjectField=Se,exports.PasswordInputFIeld=q,exports.PinField=z,exports.PrevButton=Ke,exports.RadioField=G,exports.SelectField=T,exports.StepForm=We,exports.StepFormProvider=je,exports.SubmitButton=Ae,exports.SwitchField=U,exports.TextareaField=M,exports.objectFieldResolver=Q,exports.registerFieldType=B,exports.useArrayField=se,exports.useArrayFieldAddButton=me,exports.useArrayFieldContext=ae,exports.useArrayFieldRemoveButton=de,exports.useArrayFieldRow=ue,exports.useArrayFieldRowContext=oe,exports.useFormStep=Ue,exports.useStepForm=Me,exports.useStepFormContext=qe,exports.withControlledInput=L,exports.withUncontrolledInput=P,Object.keys(f).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return f[e]}})});
|
1
|
+
var e=require("react"),r=require("@chakra-ui/utils"),t=require("react-hook-form"),n=require("@chakra-ui/react"),a=require("@saas-ui/number-input"),l=require("@saas-ui/password-input"),i=require("@saas-ui/radio"),o=require("@saas-ui/pin-input"),s=require("@saas-ui/select"),u=require("@chakra-ui/system"),d=require("@chakra-ui/icons"),m=require("@saas-ui/button"),c=require("@chakra-ui/react-utils"),p=require("@saas-ui/stepper"),f=require("@saas-ui/input-right-button");function v(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var x=/*#__PURE__*/v(e);function h(){return h=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},h.apply(this,arguments)}function F(e,r){if(null==e)return{};var t,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)r.indexOf(t=l[n])>=0||(a[t]=e[t]);return a}var 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"],g=["name","rules"],S=["ref"],N=["name","rules"],R=["ref"],V=["type"],w=["type"],D=["label","type"],k={},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 I=n.forwardRef(function(e,r){var t=e.type;/*#__PURE__*/return x.createElement(k[void 0===t?"text":t]||k.text,h({ref:r},e))}),L=function(e){return n.forwardRef(function(r,a){var l=r.name,i=r.rules,o=F(r,g),s=t.useFormContext();/*#__PURE__*/return x.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(r){var t=r.field,l=t.ref,i=F(t,S);/*#__PURE__*/return x.createElement(e,h({},i,o,{ref:n.useMergeRefs(a,l)}))}})})},P=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)}))})},B=function(e,r,t){var a=function(e,r){var t=r.displayName,a=r.hideLabel,l=r.BaseField,i=n.forwardRef(function(r,t){var n=r.id,i=r.name,o=r.label,s=r.help,u=r.isDisabled,d=r.isInvalid,m=r.isReadOnly,c=r.isRequired,p=r.rules,f=r.variant,v=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:a?o:void 0,rules:y},v)))});return i.displayName=t,i}(null!=t&&t.isControlled?L(r):P(r),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==t?void 0:t.hideLabel,BaseField:(null==t?void 0:t.BaseField)||A});return k[e]=a,a},O=B("text",n.forwardRef(function(e,r){var t=e.type,a=void 0===t?"text":t,l=F(e,V);/*#__PURE__*/return x.createElement(n.Input,h({type:a},l,{ref:r}))})),j=B("number",a.NumberInput,{isControlled:!0}),q=B("password",l.PasswordInput),M=B("textarea",n.Textarea),U=B("switch",n.forwardRef(function(e,r){var t=F(e,w);/*#__PURE__*/return x.createElement(n.Switch,h({},t,{ref:r}))}),{isControlled:!0}),T=B("select",s.Select,{isControlled:!0}),H=B("checkbox",n.forwardRef(function(e,r){var t=e.label,a=F(e,D);/*#__PURE__*/return x.createElement(n.Checkbox,h({ref:r},a),t)}),{hideLabel:!0}),G=B("radio",i.RadioInput,{isControlled:!0}),z=B("pin",o.PinInput,{isControlled:!0}),W=B("native-select",s.NativeSelect,{isControlled:!0}),J=["items"],K=function(e){return e&&Object.entries(e).map(function(e){var r=e[0];return h({},F(e[1],J),{name:r})})},Q=function(e){return{getFields:function(){return K(e)},getNestedFields:function(t){var n,a=r.get(e,t);return a?"object"===(null==(n=a.items)?void 0:n.type)?K(a.items.properties):"object"===a.type?K(a.properties):[a.items]:[]}}},X=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Y=n.forwardRef(function(e,a){var l=e.mode,i=void 0===l?"all":l,o=e.resolver,s=e.reValidateMode,u=e.shouldFocusError,d=e.shouldUnregister,m=e.shouldUseNativeValidation,c=e.criteriaMode,p=e.delayError,f=e.schema,v=e.defaultValues,y=e.onSubmit,b=e.onError,E=e.formRef,_=e.children,C=F(e,X),g={mode:i,resolver:o,defaultValues:v,reValidateMode:s,shouldFocusError:u,shouldUnregister:d,shouldUseNativeValidation:m,criteriaMode:c,delayError:p};f&&!o&&(g.resolver=null==Y.getResolver?void 0:Y.getResolver(f));var S=t.useForm(g),N=S.handleSubmit;return x.useImperativeHandle(a,function(){return S},[a,S]),/*#__PURE__*/x.createElement(t.FormProvider,S,/*#__PURE__*/x.createElement(n.chakra.form,h({ref:E,onSubmit:N(y,b)},C,{className:r.cx("saas-form",e.className)}),_))});Y.getFieldResolver=Q,r.__DEV__&&(Y.displayName="Form");var Z=["children"],$=function(e){/*#__PURE__*/return x.createElement(n.chakra.div,null,e.children)};r.__DEV__&&($.displayName="FormLayoutItem");var ee=function(e){var t,a,l,i=e.children,o=F(e,Z),s=h({},null!=(t=null==(a=n.useTheme().components)||null==(l=a.FormLayout)?void 0:l.defaultProps)?t:{spacing:4},o);/*#__PURE__*/return x.createElement(n.SimpleGrid,h({},s,{className:r.cx("saas-form__layout",o.className)}),x.Children.map(i,function(e){return x.isValidElement(e)?/*#__PURE__*/x.createElement($,null,e):e}))};r.__DEV__&&(ee.displayName="FormLayout");var re=function(e,r){return x.Children.map(r,function(r){return x.isValidElement(r)&&r.props.name?x.cloneElement(r,h({},r.props,{name:e+"."+r.props.name})):r})},te=c.createContext({name:"ArrayFieldContext"}),ne=te[0],ae=te[1],le=c.createContext({name:"ArrayFieldRowContext"}),ie=le[0],oe=le[1],se=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,s=t.useFormContext();return h({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},ue=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=ae(),l=a.name,i=a.remove,o=a.fields;return x.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:x.useCallback(function(){n(l),i(r)},[r])}},de=function(){var e=oe(),r=e.isFirst,t=e.remove,n=ae(),a=n.min;return{onClick:function(){return t()},isDisabled:r&&!!(a&&n.fields.length<=a)}},me=function(){var e=ae(),r=e.append,t=e.defaultValue,n=e.max;return{onClick:function(){return r(t,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},ce=["children","columns","spacing"],pe=["children"],fe=["name","defaultValue","keyName","min","max","children"],ve=function(e){/*#__PURE__*/return x.createElement(he,{index:e.index},/*#__PURE__*/x.createElement(xe,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/x.createElement(Fe,null))};r.__DEV__&&(ve.displayName="ArrayFieldRow");var xe=function(e){var r=e.children,t=e.columns,n=e.spacing,a=F(e,ce),l=oe().name;/*#__PURE__*/return x.createElement(ee,h({flex:"1",columns:t,gridGap:n,mr:"2"},a),re(l,r))};r.__DEV__&&(xe.displayName="ArrayFieldRowFields");var he=function(e){var r=e.children,t=ue({index:e.index});/*#__PURE__*/return x.createElement(ie,{value:t},/*#__PURE__*/x.createElement(u.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))};r.__DEV__&&(he.displayName="ArrayFieldRowContainer");var Fe=function(e){/*#__PURE__*/return x.createElement(m.IconButton,h({icon:/*#__PURE__*/x.createElement(d.MinusIcon,null),"aria-label":"Remove row"},de(),e))};r.__DEV__&&(Fe.displayName="ArrayFieldRemoveButton");var ye=function(e){/*#__PURE__*/return x.createElement(m.IconButton,h({icon:/*#__PURE__*/x.createElement(d.AddIcon,null),"aria-label":"Add row",float:"right"},me(),e))};r.__DEV__&&(ye.displayName="ArrayFieldAddButton");var be=x.forwardRef(function(e,r){var t=e.children,n=F(e,pe);/*#__PURE__*/return x.createElement(_e,h({ref:r},n),/*#__PURE__*/x.createElement(Ee,null,function(e){/*#__PURE__*/return x.createElement(x.Fragment,null,e.map(function(e,r){/*#__PURE__*/return x.createElement(ve,{key:e.id,index:r},t)}))}),/*#__PURE__*/x.createElement(ye,null))});r.__DEV__&&(be.displayName="ArrayField");var Ee=function(e){return(0,e.children)(ae().fields)};r.__DEV__&&(Ee.displayName="ArrayFieldRows");var _e=x.forwardRef(function(e,r){var t=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=F(e,fe),u=se({name:t,defaultValue:n,keyName:a,min:l,max:i});return x.useImperativeHandle(r,function(){return u},[r,u]),/*#__PURE__*/x.createElement(ne,{value:u},/*#__PURE__*/x.createElement(A,h({name:t},s),o))});r.__DEV__&&(_e.displayName="ArrayFieldContainer");var Ce=["name","label","hideLabel","children","columns","spacing"],ge=function(e){var r=n.useStyleConfig("FormLegend");/*#__PURE__*/return x.createElement(n.FormLabel,h({as:"legend",sx:r},e))},Se=function(e){var r=e.name,t=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=F(e,Ce);/*#__PURE__*/return x.createElement(n.FormControl,h({name:r,as:"fieldset"},s),/*#__PURE__*/x.createElement(ge,{display:a?"none":"block"},t),/*#__PURE__*/x.createElement(ee,{columns:i,gridGap:o},re(r,l)))};r.__DEV__&&(Se.displayName="ObjectField");var Ne=["name","type"],Re=["schema","fieldResolver"],Ve=["name","type","defaultValue"],we=function(e,r){var t;return null==(t=e.getNestedFields(r))?void 0:t.map(function(e,r){var t=e.name,n=e.type,a=F(e,Ne);/*#__PURE__*/return x.createElement(I,h({key:t||r,name:t,type:n},a))})},De=function(e){var r=e.schema,t=e.fieldResolver,n=F(e,Re),a=x.useMemo(function(){return t||Y.getFieldResolver(r)},[r,t]);/*#__PURE__*/return x.createElement(ee,n,a.getFields().map(function(e){var r=e.name,t=e.type,n=F(e,Ve);return"array"===t?/*#__PURE__*/x.createElement(be,h({key:r,name:r},n),we(a,r)):"object"===t?/*#__PURE__*/x.createElement(Se,h({key:r,name:r},n),we(a,r)):/*#__PURE__*/x.createElement(I,h({key:r,name:r,type:t},n))}))};r.__DEV__&&(De.displayName="Fields");var ke=["children","disableIfUntouched","disableIfInvalid"],Ae=u.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=F(e,ke),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)});Ae.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},r.__DEV__&&(Ae.displayName="SubmitButton");var Ie=["schema","submitLabel","fieldResolver","children"],Le=n.forwardRef(function(e,r){var t=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=e.children,o=F(e,Ie);/*#__PURE__*/return x.createElement(Y,h({},o,{schema:t,ref:r}),/*#__PURE__*/x.createElement(ee,null,/*#__PURE__*/x.createElement(De,{schema:t,fieldResolver:l}),a&&/*#__PURE__*/x.createElement(Ae,{label:a}),i))});r.__DEV__&&(Le.displayName="AutoForm");var Pe=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null};r.__DEV__&&(Pe.displayName="DisplayIf");var Be=["onChange"],Oe=c.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),je=Oe[0],qe=Oe[1];function Me(e){var r=F(e,Be),t=p.useStepper(r),n=t.activeStep,a=t.isLastStep,l=t.nextStep,i=x.useState({}),o=i[0],s=i[1],u=x.useCallback(function(r){try{return a?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(r).then(function(){m(h({},o[n],{isCompleted:!0}))}).then(l)):(l(),Promise.resolve())}catch(e){return Promise.reject(e)}},[n,a]),d=x.useCallback(function(){var e=o[n];return{onSubmit:u,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[o,u,n]),m=x.useCallback(function(e){s(function(r){var t;return h({},r,((t={})[e.name]=e,t))})},[o]);return h({getFormProps:d,updateStep:m,steps:o},t)}function Ue(e){var r=e.name,t=e.schema,n=e.resolver,a=p.useStep({name:r}),l=qe(),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 Te=["children"],He=["getFormProps"],Ge=["name","schema","resolver","children","className"],ze=["label","submitLabel"],We=x.forwardRef(function(e,t){var n=e.children,a=F(e,Te),l=Me(e),i=l.getFormProps,o=F(l,He),s=x.useMemo(function(){return o},[o]);/*#__PURE__*/return x.createElement(p.StepperProvider,{value:s},/*#__PURE__*/x.createElement(je,{value:s},/*#__PURE__*/x.createElement(Y,h({ref:t},a,i()),r.runIfFn(n,l))))}),Je=function(e){var t=e.name,n=e.schema,a=e.resolver,l=e.children,i=e.className,o=F(e,Ge);return Ue({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__&&(Je.displayName="FormStep");var Ke=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__&&(Ke.displayName="PrevButton");var Qe=function(e){var t=e.label,n=void 0===t?"Next":t,a=e.submitLabel,l=void 0===a?"Complete":a,i=F(e,ze),o=p.useStepperContext(),s=o.isCompleted;/*#__PURE__*/return x.createElement(Ae,h({isDisabled:s,label:o.isLastStep||s?l:n},i,{className:r.cx("saas-form__next-button",e.className)}))};r.__DEV__&&(Qe.displayName="NextButton"),exports.ArrayField=be,exports.ArrayFieldAddButton=ye,exports.ArrayFieldContainer=_e,exports.ArrayFieldProvider=ne,exports.ArrayFieldRemoveButton=Fe,exports.ArrayFieldRow=ve,exports.ArrayFieldRowContainer=he,exports.ArrayFieldRowFields=xe,exports.ArrayFieldRowProvider=ie,exports.ArrayFieldRows=Ee,exports.AutoForm=Le,exports.BaseField=A,exports.CheckboxField=H,exports.DisplayField=b,exports.DisplayIf=Pe,exports.Field=I,exports.Fields=De,exports.Form=Y,exports.FormLayout=ee,exports.FormLegend=ge,exports.FormStep=Je,exports.FormStepper=function(e){var r=p.useStepperContext(),t=r.activeIndex,n=r.setIndex,a=x.Children.map(e.children,function(e){if(x.isValidElement(e)&&(null==e?void 0:e.type)===Je){var r=Ue(e.props);/*#__PURE__*/return x.createElement(p.StepperStep,{name:e.props.name,title:e.props.title,isCompleted:r.isCompleted},e.props.children)}return e}),l=x.useCallback(function(e){n(e)},[]);/*#__PURE__*/return x.createElement(p.StepperContainer,{step:t,onChange:l},/*#__PURE__*/x.createElement(p.StepperSteps,h({mb:"4"},e),a))},exports.FormValue=E,exports.InputField=O,exports.NativeSelectField=W,exports.NextButton=Qe,exports.NumberInputField=j,exports.ObjectField=Se,exports.PasswordInputFIeld=q,exports.PinField=z,exports.PrevButton=Ke,exports.RadioField=G,exports.SelectField=T,exports.StepForm=We,exports.StepFormProvider=je,exports.SubmitButton=Ae,exports.SwitchField=U,exports.TextareaField=M,exports.objectFieldResolver=Q,exports.registerFieldType=B,exports.useArrayField=se,exports.useArrayFieldAddButton=me,exports.useArrayFieldContext=ae,exports.useArrayFieldRemoveButton=de,exports.useArrayFieldRow=ue,exports.useArrayFieldRowContext=oe,exports.useFormStep=Ue,exports.useStepForm=Me,exports.useStepFormContext=qe,exports.withControlledInput=L,exports.withUncontrolledInput=P,Object.keys(f).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return f[e]}})});
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../src/use-step-form.tsx","../src/step-form.tsx"],"sourcesContent":["import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">\n <FormValue name={name} />\n </Text>\n </FormControl>\n )\n}\n\nif (__DEV__) {\n DisplayField.displayName = 'DisplayField'\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n\nif (__DEV__) {\n FormValue.displayName = 'FormValue'\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\nimport { FocusableElement } from '@chakra-ui/utils'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\n\nif (__DEV__) {\n BaseField.displayName = 'BaseField'\n}\n\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<FocusableElement>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n id,\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n id={id}\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n id={id}\n name={name}\n label={hideLabel ? label : undefined} // Only pass down the label when it should be inline.\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for the checkbox field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\nexport const InputField = registerFieldType(\n 'text',\n forwardRef(({ type = 'text', ...rest }, ref) => {\n return <Input type={type} {...rest} ref={ref} />\n })\n)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ type, ...rest }, ref) => {\n return <Switch {...rest} ref={ref} />\n }),\n {\n isControlled: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(\n ({ label, type, ...props }: { label?: string; type: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }\n ),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema): FieldProps[] =>\n schema &&\n Object.entries(schema).map(([name, { items, ...field }]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\nimport { css } from '@emotion/react'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n className={cx('saas-form', props.className)}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n displayName?: string\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nif (__DEV__) {\n Form.displayName = 'Form'\n}\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\nif (__DEV__) {\n FormLayoutItem.displayName = 'FormLayoutItem'\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid\n {...gridProps}\n className={cx('saas-form__layout', props.className)}\n >\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n\nif (__DEV__) {\n FormLayout.displayName = 'FormLayout'\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses a different 'id' field\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\nimport { __DEV__ } from '@chakra-ui/utils'\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n UseArrayFieldReturn,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n\n children: React.ReactNode\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRow.displayName = 'ArrayFieldRow'\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n\n children: React.ReactNode\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRowFields.displayName = 'ArrayFieldRowFields'\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRowContainer.displayName = 'ArrayFieldRowContainer'\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nif (__DEV__) {\n ArrayFieldRemoveButton.displayName = 'ArrayFieldRemoveButton'\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nif (__DEV__) {\n ArrayFieldAddButton.displayName = 'ArrayFieldAddButton'\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField = React.forwardRef(\n (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer ref={ref} {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n }\n)\n\nif (__DEV__) {\n ArrayField.displayName = 'ArrayField'\n}\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nif (__DEV__) {\n ArrayFieldRows.displayName = 'ArrayFieldRows'\n}\n\nexport const ArrayFieldContainer = React.forwardRef(\n (\n {\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n }: ArrayFieldProps,\n ref: React.ForwardedRef<UseArrayFieldReturn>\n ) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n // This exposes the useArrayField api through the forwarded ref\n React.useImperativeHandle(ref, () => context, [ref, context])\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n }\n)\n\nif (__DEV__) {\n ArrayFieldContainer.displayName = 'ArrayFieldContainer'\n}\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyleConfig,\n} from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyleConfig('FormLegend')\n return <FormLabel as=\"legend\" sx={styles} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n\nif (__DEV__) {\n ObjectField.displayName = 'ObjectField'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n\nif (__DEV__) {\n Fields.displayName = 'Fields'\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n\nif (__DEV__) {\n SubmitButton.displayName = 'SubmitButton'\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton, SubmitButtonProps } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n /**\n * The submit button label.\n * Pass `null` to render no submit button.\n */\n submitLabel?: React.ReactNode\n /**\n * The schema.\n * Supports object schema, Yup or Zod.\n * @see https://www.saas-ui.dev/docs/forms/auto-form\n */\n schema: any\n /**\n * The field resolver.\n */\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n schema,\n submitLabel = 'Submit',\n fieldResolver,\n children,\n ...rest\n } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n {children}\n </FormLayout>\n </Form>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n displayName?: string\n getFieldResolver?: (schema: any) => FieldResolver\n}\n\nif (__DEV__) {\n AutoForm.displayName = 'AutoForm'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n\nif (__DEV__) {\n DisplayIf.displayName = 'DisplayIf'\n}\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler } from 'react-hook-form'\nimport { createContext } from '@chakra-ui/react-utils'\nimport {\n useStepper,\n useStep,\n UseStepperProps,\n UseStepperReturn,\n} from '@saas-ui/stepper'\n\nexport interface StepState {\n name: string\n schema?: any\n resolver?: any\n isActive?: boolean\n isCompleted?: boolean\n}\n\nexport interface StepFormContext extends UseStepperReturn {\n updateStep(state: StepState): void\n steps: Record<string, StepState>\n}\n\nexport const [StepFormProvider, useStepFormContext] =\n createContext<StepFormContext>({\n name: 'StepFormContext',\n errorMessage:\n 'useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`',\n })\n\nimport { FormProps } from './form'\n\nexport interface UseStepFormProps<\n TFieldValues extends FieldValues = FieldValues\n> extends Omit<UseStepperProps, 'onChange'>,\n Omit<FormProps<TFieldValues>, 'children'> {\n children:\n | React.ReactNode\n | ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement)\n}\n\nexport interface UseStepFormReturn<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperReturn {\n getFormProps(): {\n onSubmit: SubmitHandler<TFieldValues>\n schema?: any\n resolver?: any\n }\n updateStep(step: any): void\n steps: Record<string, any>\n}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n): UseStepFormReturn<TFieldValues> {\n const { onChange, ...rest } = props\n const stepper = useStepper(rest)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState<Record<string, StepState>>({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(() => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n }, [steps, onSubmitStep, activeStep])\n\n const updateStep = React.useCallback(\n (step: StepState) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {\n chakra,\n HTMLChakraProps,\n useMultiStyleConfig,\n SystemStyleObject,\n createStylesContext,\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 StepperContainer,\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\nconst [StylesProvider, useStyles] = createStylesContext('StepForm')\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps()}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const { activeIndex, setIndex } = useStepperContext()\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 const onChange = React.useCallback((i: number) => {\n setIndex(i)\n }, [])\n\n return (\n <StepperContainer step={activeIndex} onChange={onChange}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StepperContainer>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, ...rest } = props\n const step = useFormStep({ name, schema, resolver })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n"],"names":["_excluded","DisplayField","_ref","name","label","props","React","createElement","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","_ref2","getValues","useFormContext","_excluded2","_excluded3","_excluded4","_excluded5","_excluded6","_excluded7","_excluded8","_excluded9","inputTypes","BaseField","help","variant","hideLabel","children","controlProps","_objectWithoutPropertiesLoose","error","formState","get","errors","getError","_extends","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","_props$type","type","withControlledInput","InputComponent","_ref3","rules","inputProps","_useFormContext2","Controller","control","render","field","_ref4$field","useMergeRefs","withUncontrolledInput","_ref5","_register","register","registerFieldType","component","options","id","isDisabled","isReadOnly","isRequired","inputRules","required","undefined","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","_ref6$type","_ref6","rest","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","_ref7","Switch","SelectField","Select","CheckboxField","_ref8","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","_field$items","items","properties","Form","mode","_props$mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","gridProps","theme","useTheme","components","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","_createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","_ref$defaultValue","defaultValue","keyName","min","max","context","useFieldArray","useArrayFieldRow","index","clearErrors","_useArrayFieldContext","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","_useArrayFieldRowCont","_useArrayFieldContext2","onClick","append","_useArrayFieldContext3","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","useArrayFieldAddButton","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","_ref4","fieldProps","FormLegend","styles","useStyleConfig","as","sx","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","_props$submitLabel","submitLabel","DisplayIf","condition","_ref$condition","useWatch","disabled","exact","isExact","errorMessage","StepFormProvider","useStepFormContext","useStepForm","onChange","stepper","useStepper","activeStep","isLastStep","nextStep","_React$useState","useState","steps","updateSteps","onSubmitStep","data","then","updateStep","step","isCompleted","Promise","resolve","e","reject","getFormProps","_extends2","useFormStep","useStep","_useStepFormContext","createStylesContext","StepForm","ctx","StepperProvider","runIfFn","FormStep","isActive","PrevButton","useStepperContext","prevStep","_useStepperContext2","isFirstStep","callAllHandlers","NextButton","_props$label","activeIndex","setIndex","_useFormStep","StepperStep","title","StepperContainer","StepperSteps","elements"],"mappings":"omCAAA,IAAAA,EAAA,CAAA,OAAA,QAAA,eAiByBC,EAAgC,SAAAC,GACvDC,IAAAA,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,MAEGC,sBAEH,OACEC,EAAAC,cAACC,EAADA,YAAiBH,EACdD,eAAQE,EAACC,cAAAE,EAADA,UAAW,CAAAC,QAASP,GAAOC,GAAqB,kBACzDE,EAAAC,cAACI,EAADA,KAAA,CAAMC,SAAS,mBACbN,EAACC,cAAAM,EAAU,CAAAV,KAAMA,OAMrBW,EAAAA,UACFb,EAAac,YAAc,gBAGhBF,MAAwC,SAAAG,GAAGb,IAAAA,EAAAA,EAAAA,KAEtD,OAAOc,EADeC,EAAcA,iBAA5BD,WACSd,IAAS,MAGxBW,EAAAA,UACFD,EAAUE,YAAc,aC3C1B,IAAAf,EAAA,CAAA,OAAA,QAAA,OAAA,UAAA,YAAA,YAAAmB,EAAA,CAAA,KAAA,OAAA,QAAA,OAAA,aAAA,YAAA,aAAA,aAAA,QAAA,WAAAC,EAAA,CAAA,OAAA,SAAAC,EAAA,CAAA,OAAAC,EAAA,CAAA,OAAA,SAAAC,EAAA,CAAA,OAAAC,EAAA,CAAA,QAAAC,EAAA,CAAA,QAAAC,EAAA,CAAA,QAAA,QAiHMC,EAAsC,GAmBtBC,EAAyB,SAACvB,GAC9C,IAAQF,EAC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ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../src/use-step-form.tsx","../src/step-form.tsx"],"sourcesContent":["import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">\n <FormValue name={name} />\n </Text>\n </FormControl>\n )\n}\n\nif (__DEV__) {\n DisplayField.displayName = 'DisplayField'\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n\nif (__DEV__) {\n FormValue.displayName = 'FormValue'\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\nimport { FocusableElement } from '@chakra-ui/utils'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\n\nif (__DEV__) {\n BaseField.displayName = 'BaseField'\n}\n\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<FocusableElement>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n id,\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n id={id}\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n id={id}\n name={name}\n label={hideLabel ? label : undefined} // Only pass down the label when it should be inline.\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for the checkbox field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\nexport const InputField = registerFieldType(\n 'text',\n forwardRef(({ type = 'text', ...rest }, ref) => {\n return <Input type={type} {...rest} ref={ref} />\n })\n)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ type, ...rest }, ref) => {\n return <Switch {...rest} ref={ref} />\n }),\n {\n isControlled: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(\n ({ label, type, ...props }: { label?: string; type: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }\n ),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema): FieldProps[] =>\n schema &&\n Object.entries(schema).map(([name, { items, ...field }]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\nimport { css } from '@emotion/react'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n className={cx('saas-form', props.className)}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n displayName?: string\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nif (__DEV__) {\n Form.displayName = 'Form'\n}\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\nif (__DEV__) {\n FormLayoutItem.displayName = 'FormLayoutItem'\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid\n {...gridProps}\n className={cx('saas-form__layout', props.className)}\n >\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n\nif (__DEV__) {\n FormLayout.displayName = 'FormLayout'\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses a different 'id' field\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\nimport { __DEV__ } from '@chakra-ui/utils'\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n UseArrayFieldReturn,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n\n children: React.ReactNode\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRow.displayName = 'ArrayFieldRow'\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n\n children: React.ReactNode\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRowFields.displayName = 'ArrayFieldRowFields'\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRowContainer.displayName = 'ArrayFieldRowContainer'\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nif (__DEV__) {\n ArrayFieldRemoveButton.displayName = 'ArrayFieldRemoveButton'\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nif (__DEV__) {\n ArrayFieldAddButton.displayName = 'ArrayFieldAddButton'\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField = React.forwardRef(\n (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer ref={ref} {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n }\n)\n\nif (__DEV__) {\n ArrayField.displayName = 'ArrayField'\n}\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nif (__DEV__) {\n ArrayFieldRows.displayName = 'ArrayFieldRows'\n}\n\nexport const ArrayFieldContainer = React.forwardRef(\n (\n {\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n }: ArrayFieldProps,\n ref: React.ForwardedRef<UseArrayFieldReturn>\n ) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n // This exposes the useArrayField api through the forwarded ref\n React.useImperativeHandle(ref, () => context, [ref, context])\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n }\n)\n\nif (__DEV__) {\n ArrayFieldContainer.displayName = 'ArrayFieldContainer'\n}\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyleConfig,\n} from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyleConfig('FormLegend')\n return <FormLabel as=\"legend\" sx={styles} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n\nif (__DEV__) {\n ObjectField.displayName = 'ObjectField'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n\nif (__DEV__) {\n Fields.displayName = 'Fields'\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n\nif (__DEV__) {\n SubmitButton.displayName = 'SubmitButton'\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton, SubmitButtonProps } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n /**\n * The submit button label.\n * Pass `null` to render no submit button.\n */\n submitLabel?: React.ReactNode\n /**\n * The schema.\n * Supports object schema, Yup or Zod.\n * @see https://www.saas-ui.dev/docs/forms/auto-form\n */\n schema: any\n /**\n * The field resolver.\n */\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n schema,\n submitLabel = 'Submit',\n fieldResolver,\n children,\n ...rest\n } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n {children}\n </FormLayout>\n </Form>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n displayName?: string\n getFieldResolver?: (schema: any) => FieldResolver\n}\n\nif (__DEV__) {\n AutoForm.displayName = 'AutoForm'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n\nif (__DEV__) {\n DisplayIf.displayName = 'DisplayIf'\n}\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler } from 'react-hook-form'\nimport { createContext } from '@chakra-ui/react-utils'\nimport {\n useStepper,\n useStep,\n UseStepperProps,\n UseStepperReturn,\n} from '@saas-ui/stepper'\n\nexport interface StepState {\n name: string\n schema?: any\n resolver?: any\n isActive?: boolean\n isCompleted?: boolean\n}\n\nexport interface StepFormContext extends UseStepperReturn {\n updateStep(state: StepState): void\n steps: Record<string, StepState>\n}\n\nexport const [StepFormProvider, useStepFormContext] =\n createContext<StepFormContext>({\n name: 'StepFormContext',\n errorMessage:\n 'useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`',\n })\n\nimport { FormProps } from './form'\n\nexport interface UseStepFormProps<\n TFieldValues extends FieldValues = FieldValues\n> extends Omit<UseStepperProps, 'onChange'>,\n Omit<FormProps<TFieldValues>, 'children'> {\n children:\n | React.ReactNode\n | ((stepper: UseStepFormReturn<TFieldValues>) => React.ReactElement)\n}\n\nexport interface UseStepFormReturn<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperReturn {\n getFormProps(): {\n onSubmit: SubmitHandler<TFieldValues>\n schema?: any\n resolver?: any\n }\n updateStep(step: any): void\n steps: Record<string, any>\n}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n): UseStepFormReturn<TFieldValues> {\n const { onChange, ...rest } = props\n const stepper = useStepper(rest)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState<Record<string, StepState>>({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(() => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n }, [steps, onSubmitStep, activeStep])\n\n const updateStep = React.useCallback(\n (step: StepState) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport { chakra, HTMLChakraProps } 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 StepperContainer,\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\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps()}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const { activeIndex, setIndex } = useStepperContext()\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 const onChange = React.useCallback((i: number) => {\n setIndex(i)\n }, [])\n\n return (\n <StepperContainer step={activeIndex} onChange={onChange}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StepperContainer>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, ...rest } = props\n const step = useFormStep({ name, schema, resolver })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n"],"names":["_excluded","DisplayField","_ref","name","label","props","React","createElement","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","_ref2","getValues","useFormContext","_excluded2","_excluded3","_excluded4","_excluded5","_excluded6","_excluded7","_excluded8","_excluded9","inputTypes","BaseField","help","variant","hideLabel","children","controlProps","_objectWithoutPropertiesLoose","error","formState","get","errors","getError","_extends","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","_props$type","type","withControlledInput","InputComponent","_ref3","rules","inputProps","_useFormContext2","Controller","control","render","field","_ref4$field","useMergeRefs","withUncontrolledInput","_ref5","_register","register","registerFieldType","component","options","id","isDisabled","isReadOnly","isRequired","inputRules","required","undefined","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","_ref6$type","_ref6","rest","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","_ref7","Switch","SelectField","Select","CheckboxField","_ref8","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","_field$items","items","properties","Form","mode","_props$mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","gridProps","theme","useTheme","components","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","_createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","_ref$defaultValue","defaultValue","keyName","min","max","context","useFieldArray","useArrayFieldRow","index","clearErrors","_useArrayFieldContext","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","_useArrayFieldRowCont","_useArrayFieldContext2","onClick","append","_useArrayFieldContext3","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","useArrayFieldAddButton","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","_ref4","fieldProps","FormLegend","styles","useStyleConfig","as","sx","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","_props$submitLabel","submitLabel","DisplayIf","condition","_ref$condition","useWatch","disabled","exact","isExact","errorMessage","StepFormProvider","useStepFormContext","useStepForm","onChange","stepper","useStepper","activeStep","isLastStep","nextStep","_React$useState","useState","steps","updateSteps","onSubmitStep","data","then","updateStep","step","isCompleted","Promise","resolve","e","reject","getFormProps","_extends2","useFormStep","useStep","_useStepFormContext","StepForm","ctx","StepperProvider","runIfFn","FormStep","isActive","PrevButton","_useStepperContext2","useStepperContext","prevStep","isFirstStep","callAllHandlers","NextButton","_props$label","_useStepperContext3","_useStepperContext","activeIndex","setIndex","elements","StepperStep","title","StepperContainer","StepperSteps"],"mappings":"omCAAA,IAAAA,EAAA,CAAA,OAAA,QAAA,eAiByBC,EAAgC,SAAAC,GACvDC,IAAAA,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,MAEGC,sBAEH,OACEC,EAAAC,cAACC,EAADA,YAAiBH,EACdD,eAAQE,EAACC,cAAAE,EAADA,UAAW,CAAAC,QAASP,GAAOC,GAAqB,kBACzDE,EAAAC,cAACI,EAADA,KAAA,CAAMC,SAAS,mBACbN,EAACC,cAAAM,EAAU,CAAAV,KAAMA,OAMrBW,EAAAA,UACFb,EAAac,YAAc,gBAGhBF,MAAwC,SAAAG,GAAGb,IAAAA,EAAAA,EAAAA,KAEtD,OAAOc,EADeC,EAAcA,iBAA5BD,WACSd,IAAS,MAGxBW,EAAAA,UACFD,EAAUE,YAAc,aC3C1B,IAAAf,EAAA,CAAA,OAAA,QAAA,OAAA,UAAA,YAAA,YAAAmB,EAAA,CAAA,KAAA,OAAA,QAAA,OAAA,aAAA,YAAA,aAAA,aAAA,QAAA,WAAAC,EAAA,CAAA,OAAA,SAAAC,EA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cAAA6S,eAAa5Q,EAAA,CAAA2K,GAAG,KAAQ9M,GACtB2S"}
|
package/dist/index.modern.mjs
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import*as e from"react";import{__DEV__ as t,get as a,cx as l,runIfFn as r,callAllHandlers as n}from"@chakra-ui/utils";import{useFormContext as s,get as i,Controller as o,useForm as m,FormProvider as c,useFieldArray as d,useWatch as u}from"react-hook-form";import{FormControl as p,FormLabel as f,Text as h,forwardRef as b,Input as y,Switch as E,Checkbox as v,Box as F,FormHelperText as g,FormErrorMessage as N,useMergeRefs as x,Textarea as C,chakra as k,useTheme as S,SimpleGrid as R,useStyleConfig as V}from"@chakra-ui/react";import{NumberInput as L}from"@saas-ui/number-input";import{PasswordInput as I}from"@saas-ui/password-input";import{RadioInput as w}from"@saas-ui/radio";import{PinInput as A}from"@saas-ui/pin-input";import{Select as D,NativeSelect as O}from"@saas-ui/select";import{chakra as j,forwardRef as B,createStylesContext as U}from"@chakra-ui/system";import{MinusIcon as _,AddIcon as M}from"@chakra-ui/icons";import{IconButton as P,Button as $}from"@saas-ui/button";import{createContext as q}from"@chakra-ui/react-utils";import{useStepper as G,useStep as H,StepperProvider as z,useStepperContext as J,StepperStep as K,StepperContainer as Q,StepperSteps as T}from"@saas-ui/stepper";export*from"@saas-ui/input-right-button";function W(){return W=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(e[l]=a[l])}return e},W.apply(this,arguments)}function X(e,t){if(null==e)return{};var a,l,r={},n=Object.keys(e);for(l=0;l<n.length;l++)t.indexOf(a=n[l])>=0||(r[a]=e[a]);return r}const Y=["name","label","placeholder"],Z=t=>{let{name:a,label:l}=t,r=X(t,Y);/*#__PURE__*/return e.createElement(p,r,l?/*#__PURE__*/e.createElement(f,{htmlFor:a},l):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(ee,{name:a})))};t&&(Z.displayName="DisplayField");const ee=({name:e})=>{const{getValues:t}=s();return t(e)||null};t&&(ee.displayName="FormValue");const te=["name","label","help","variant","hideLabel","children"],ae=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],le=["name","rules"],re=["ref"],ne=["name","rules"],se=["ref"],ie=["type"],oe=["type"],me=["label","type"],ce={},de="text",ue=t=>{const{name:a,label:l,help:r,variant:n,hideLabel:o,children:m}=t,c=X(t,te),{formState:d}=s(),u=((e,t)=>i(t.errors,e))(a,d);/*#__PURE__*/return e.createElement(p,W({variant:n},c,{isInvalid:!!u}),l&&!o?/*#__PURE__*/e.createElement(f,{variant:n},l):null,/*#__PURE__*/e.createElement(F,null,m,!r||null!=u&&u.message?null:/*#__PURE__*/e.createElement(g,null,r),(null==u?void 0:u.message)&&/*#__PURE__*/e.createElement(N,null,null==u?void 0:u.message)))};t&&(ue.displayName="BaseField");const pe=b((t,a)=>{const{type:l=de}=t,r=(e=>ce[e]||ce[de])(l);/*#__PURE__*/return e.createElement(r,W({ref:a},t))}),fe=t=>b((a,l)=>{let{name:r,rules:n}=a,i=X(a,le);const{control:m}=s();/*#__PURE__*/return e.createElement(o,{name:r,control:m,rules:n,render:a=>{let{field:{ref:r}}=a,n=X(a.field,re);/*#__PURE__*/return e.createElement(t,W({},n,i,{ref:x(l,r)}))}})}),he=t=>b((a,l)=>{let{name:r,rules:n}=a,i=X(a,ne);const{register:o}=s(),m=o(r,n),{ref:c}=m,d=X(m,se);/*#__PURE__*/return e.createElement(t,W({},d,i,{ref:x(l,c)}))}),be=(t,a,l)=>{let r;r=null!=l&&l.isControlled?fe(a):he(a);const n=((t,{displayName:a,hideLabel:l,BaseField:r})=>{const n=b((a,n)=>{const{id:s,name:i,label:o,help:m,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,rules:f,variant:h}=a,b=X(a,ae),y=W({required:p},f);/*#__PURE__*/return e.createElement(r,{id:s,name:i,label:o,help:m,hideLabel:l,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,variant:h},/*#__PURE__*/e.createElement(t,W({ref:n,id:s,name:i,label:l?o:void 0,rules:y},b)))});return n.displayName=a,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==l?void 0:l.hideLabel,BaseField:(null==l?void 0:l.BaseField)||ue});return ce[t]=n,n},ye=be("text",b((t,a)=>{let{type:l="text"}=t,r=X(t,ie);/*#__PURE__*/return e.createElement(y,W({type:l},r,{ref:a}))})),Ee=be("number",L,{isControlled:!0}),ve=be("password",I),Fe=be("textarea",C),ge=be("switch",b((t,a)=>{let l=X(t,oe);/*#__PURE__*/return e.createElement(E,W({},l,{ref:a}))}),{isControlled:!0}),Ne=be("select",D,{isControlled:!0}),xe=be("checkbox",b((t,a)=>{let{label:l}=t,r=X(t,me);/*#__PURE__*/return e.createElement(v,W({ref:a},r),l)}),{hideLabel:!0}),Ce=be("radio",w,{isControlled:!0}),ke=be("pin",A,{isControlled:!0}),Se=be("native-select",O,{isControlled:!0}),Re=["items"],Ve=e=>e&&Object.entries(e).map(([e,t])=>W({},X(t,Re),{name:e})),Le=e=>({getFields:()=>Ve(e),getNestedFields:t=>{var l;const r=a(e,t);return r?"object"===(null==(l=r.items)?void 0:l.type)?Ve(r.items.properties):"object"===r.type?Ve(r.properties):[r.items]:[]}}),Ie=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],we=b((t,a)=>{const{mode:r="all",resolver:n,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:d,criteriaMode:u,delayError:p,schema:f,defaultValues:h,onSubmit:b,onError:y,formRef:E,children:v}=t,F=X(t,Ie),g={mode:r,resolver:n,defaultValues:h,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:d,criteriaMode:u,delayError:p};f&&!n&&(g.resolver=null==we.getResolver?void 0:we.getResolver(f));const N=m(g),{handleSubmit:x}=N;return e.useImperativeHandle(a,()=>N,[a,N]),/*#__PURE__*/e.createElement(c,N,/*#__PURE__*/e.createElement(k.form,W({ref:E,onSubmit:x(b,y)},F,{className:l("saas-form",t.className)}),v))});we.getFieldResolver=Le,t&&(we.displayName="Form");const Ae=["children"],De=({children:t})=>/*#__PURE__*/e.createElement(k.div,null,t);t&&(De.displayName="FormLayoutItem");const Oe=t=>{var a,r,n;let{children:s}=t,i=X(t,Ae);const o=W({},null!=(a=null==(r=S().components)||null==(n=r.FormLayout)?void 0:n.defaultProps)?a:{spacing:4},i);/*#__PURE__*/return e.createElement(R,W({},o,{className:l("saas-form__layout",i.className)}),e.Children.map(s,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(De,null,t):t))};t&&(Oe.displayName="FormLayout");const je=(t,a)=>e.Children.map(a,a=>e.isValidElement(a)&&a.props.name?e.cloneElement(a,W({},a.props,{name:`${t}.${a.props.name}`})):a),[Be,Ue]=q({name:"ArrayFieldContext"}),[_e,Me]=q({name:"ArrayFieldRowContext"}),Pe=({name:e,defaultValue:t={},keyName:a,min:l,max:r})=>{const{control:n}=s();return W({},d({control:n,name:e,keyName:a}),{name:e,defaultValue:t,min:l,max:r})},$e=({index:t})=>{const{clearErrors:a}=s(),{name:l,remove:r,fields:n}=Ue();return e.useEffect(()=>{a(l)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${l}.${t}`,remove:e.useCallback(()=>{a(l),r(t)},[t])}},qe=()=>{const{isFirst:e,remove:t}=Me(),{min:a,fields:l}=Ue();return{onClick:()=>t(),isDisabled:e&&!!(a&&l.length<=a)}},Ge=()=>{const{append:e,defaultValue:t,max:a,fields:l}=Ue();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(a&&l.length>=a)}},He=["children","columns","spacing"],ze=["children"],Je=["name","defaultValue","keyName","min","max","children"],Ke=({children:t,columns:a,spacing:l,index:r})=>/*#__PURE__*/e.createElement(Te,{index:r},/*#__PURE__*/e.createElement(Qe,{columns:a,spacing:l},t),/*#__PURE__*/e.createElement(We,null));t&&(Ke.displayName="ArrayFieldRow");const Qe=t=>{let{children:a,columns:l,spacing:r}=t,n=X(t,He);const{name:s}=Me();/*#__PURE__*/return e.createElement(Oe,W({flex:"1",columns:l,gridGap:r,mr:"2"},n),je(s,a))};t&&(Qe.displayName="ArrayFieldRowFields");const Te=({children:t,index:a})=>{const l=$e({index:a});/*#__PURE__*/return e.createElement(_e,{value:l},/*#__PURE__*/e.createElement(j.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))};t&&(Te.displayName="ArrayFieldRowContainer");const We=t=>/*#__PURE__*/e.createElement(P,W({icon:/*#__PURE__*/e.createElement(_,null),"aria-label":"Remove row"},qe(),t));t&&(We.displayName="ArrayFieldRemoveButton");const Xe=t=>/*#__PURE__*/e.createElement(P,W({icon:/*#__PURE__*/e.createElement(M,null),"aria-label":"Add row",float:"right"},Ge(),t));t&&(Xe.displayName="ArrayFieldAddButton");const Ye=e.forwardRef((t,a)=>{const{children:l}=t,r=X(t,ze);/*#__PURE__*/return e.createElement(et,W({ref:a},r),/*#__PURE__*/e.createElement(Ze,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},a)=>/*#__PURE__*/e.createElement(Ke,{key:t,index:a},l)))),/*#__PURE__*/e.createElement(Xe,null))});t&&(Ye.displayName="ArrayField");const Ze=({children:e})=>{const{fields:t}=Ue();return e(t)};t&&(Ze.displayName="ArrayFieldRows");const et=e.forwardRef((t,a)=>{let{name:l,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=X(t,Je);const c=Pe({name:l,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(a,()=>c,[a,c]),/*#__PURE__*/e.createElement(Be,{value:c},/*#__PURE__*/e.createElement(ue,W({name:l},m),o))});t&&(et.displayName="ArrayFieldContainer");const tt=["name","label","hideLabel","children","columns","spacing"],at=t=>{const a=V("FormLegend");/*#__PURE__*/return e.createElement(f,W({as:"legend",sx:a},t))},lt=t=>{const{name:a,label:l,hideLabel:r,children:n,columns:s,spacing:i}=t,o=X(t,tt);/*#__PURE__*/return e.createElement(p,W({name:a,as:"fieldset"},o),/*#__PURE__*/e.createElement(at,{display:r?"none":"block"},l),/*#__PURE__*/e.createElement(Oe,{columns:s,gridGap:i},je(a,n)))};t&&(lt.displayName="ObjectField");const rt=["name","type"],nt=["schema","fieldResolver"],st=["name","type","defaultValue"],it=(t,a)=>{var l;return null==(l=t.getNestedFields(a))?void 0:l.map((t,a)=>{let{name:l,type:r}=t,n=X(t,rt);/*#__PURE__*/return e.createElement(pe,W({key:l||a,name:l,type:r},n))})},ot=t=>{let{schema:a,fieldResolver:l}=t,r=X(t,nt);const n=e.useMemo(()=>l||we.getFieldResolver(a),[a,l]);/*#__PURE__*/return e.createElement(Oe,r,n.getFields().map(t=>{let{name:a,type:l}=t,r=X(t,st);return"array"===l?/*#__PURE__*/e.createElement(Ye,W({key:a,name:a},r),it(n,a)):"object"===l?/*#__PURE__*/e.createElement(lt,W({key:a,name:a},r),it(n,a)):/*#__PURE__*/e.createElement(pe,W({key:a,name:a,type:l},r))}))};t&&(ot.displayName="Fields");const mt=["children","disableIfUntouched","disableIfInvalid"],ct=B((t,a)=>{const{children:l,disableIfUntouched:r,disableIfInvalid:n}=t,i=X(t,mt),{formState:o}=s();/*#__PURE__*/return e.createElement($,W({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:a,isDisabled:r&&!o.isDirty||n&&!o.isValid},i),l)});ct.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(ct.displayName="SubmitButton");const dt=["schema","submitLabel","fieldResolver","children"],ut=b((t,a)=>{const{schema:l,submitLabel:r="Submit",fieldResolver:n,children:s}=t,i=X(t,dt);/*#__PURE__*/return e.createElement(we,W({},i,{schema:l,ref:a}),/*#__PURE__*/e.createElement(Oe,null,/*#__PURE__*/e.createElement(ot,{schema:l,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(ct,{label:r}),s))});t&&(ut.displayName="AutoForm");const pt=({children:e,name:t,defaultValue:a,isDisabled:l,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:a,disabled:l,exact:r}),s())?e:null;t&&(pt.displayName="DisplayIf");const ft=["onChange"],[ht,bt]=q({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function yt(t){const a=X(t,ft),l=G(a),{activeStep:r,isLastStep:n,nextStep:s}=l,[i,o]=e.useState({}),m=e.useCallback(async e=>{if(n)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{d(W({},i[r],{isCompleted:!0}))}).then(s);s()},[r,n]),c=e.useCallback(()=>{const e=i[r];return{onSubmit:m,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[i,m,r]),d=e.useCallback(e=>{o(t=>W({},t,{[e.name]:e}))},[i]);return W({getFormProps:c,updateStep:d,steps:i},l)}function Et(t){const{name:a,schema:l,resolver:r}=t,n=H({name:a}),{steps:s,updateStep:i}=bt();return e.useEffect(()=>{i({name:a,schema:l,resolver:r})},[a,l]),W({},n,s[a]||{name:a,schema:l})}const vt=["children"],Ft=["getFormProps"],gt=["name","schema","resolver","children","className"],Nt=["label","submitLabel"];U("StepForm");const xt=e.forwardRef((t,a)=>{const{children:l}=t,n=X(t,vt),s=yt(t),{getFormProps:i}=s,o=X(s,Ft),m=e.useMemo(()=>o,[o]);/*#__PURE__*/return e.createElement(z,{value:m},/*#__PURE__*/e.createElement(ht,{value:m},/*#__PURE__*/e.createElement(we,W({ref:a},n,i()),r(l,s))))}),Ct=t=>{const{activeIndex:a,setIndex:l}=J(),{children:r}=t,n=e.Children.map(r,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===kt){const{isCompleted:a}=Et(t.props);/*#__PURE__*/return e.createElement(K,{name:t.props.name,title:t.props.title,isCompleted:a},t.props.children)}return t}),s=e.useCallback(e=>{l(e)},[]);/*#__PURE__*/return e.createElement(Q,{step:a,onChange:s},/*#__PURE__*/e.createElement(T,W({mb:"4"},t),n))},kt=t=>{const{name:a,schema:r,resolver:n,children:s,className:i}=t,o=X(t,gt),m=Et({name:a,schema:r,resolver:n}),{isActive:c}=m;return c?/*#__PURE__*/e.createElement(j.div,W({},o,{className:l("saas-form__step",i)}),s):null};t&&(kt.displayName="FormStep");const St=t=>{const{isFirstStep:a,isCompleted:r,prevStep:s}=J();/*#__PURE__*/return e.createElement($,W({isDisabled:a||r,label:"Back"},t,{className:l("saas-form__prev-button",t.className),onClick:n(t.onClick,s)}))};t&&(St.displayName="PrevButton");const Rt=t=>{const{label:a="Next",submitLabel:r="Complete"}=t,n=X(t,Nt),{isLastStep:s,isCompleted:i}=J();/*#__PURE__*/return e.createElement(ct,W({isDisabled:i,label:s||i?r:a},n,{className:l("saas-form__next-button",t.className)}))};t&&(Rt.displayName="NextButton");export{Ye as ArrayField,Xe as ArrayFieldAddButton,et as ArrayFieldContainer,Be as ArrayFieldProvider,We as ArrayFieldRemoveButton,Ke as ArrayFieldRow,Te as ArrayFieldRowContainer,Qe as ArrayFieldRowFields,_e as ArrayFieldRowProvider,Ze as ArrayFieldRows,ut as AutoForm,ue as BaseField,xe as CheckboxField,Z as DisplayField,pt as DisplayIf,pe as Field,ot as Fields,we as Form,Oe as FormLayout,at as FormLegend,kt as FormStep,Ct as FormStepper,ee as FormValue,ye as InputField,Se as NativeSelectField,Rt as NextButton,Ee as NumberInputField,lt as ObjectField,ve as PasswordInputFIeld,ke as PinField,St as PrevButton,Ce as RadioField,Ne as SelectField,xt as StepForm,ht as StepFormProvider,ct as SubmitButton,ge as SwitchField,Fe as TextareaField,Le as objectFieldResolver,be as registerFieldType,Pe as useArrayField,Ge as useArrayFieldAddButton,Ue as useArrayFieldContext,qe as useArrayFieldRemoveButton,$e as useArrayFieldRow,Me as useArrayFieldRowContext,Et as useFormStep,yt as useStepForm,bt as useStepFormContext,fe as withControlledInput,he as withUncontrolledInput};
|
1
|
+
import*as e from"react";import{__DEV__ as t,get as a,cx as l,runIfFn as r,callAllHandlers as n}from"@chakra-ui/utils";import{useFormContext as s,get as i,Controller as o,useForm as m,FormProvider as c,useFieldArray as d,useWatch as u}from"react-hook-form";import{FormControl as p,FormLabel as f,Text as h,forwardRef as b,Input as y,Switch as E,Checkbox as v,Box as g,FormHelperText as F,FormErrorMessage as N,useMergeRefs as x,Textarea as C,chakra as k,useTheme as R,SimpleGrid as S,useStyleConfig as V}from"@chakra-ui/react";import{NumberInput as L}from"@saas-ui/number-input";import{PasswordInput as I}from"@saas-ui/password-input";import{RadioInput as w}from"@saas-ui/radio";import{PinInput as A}from"@saas-ui/pin-input";import{Select as D,NativeSelect as O}from"@saas-ui/select";import{chakra as j,forwardRef as B}from"@chakra-ui/system";import{MinusIcon as U,AddIcon as _}from"@chakra-ui/icons";import{IconButton as M,Button as P}from"@saas-ui/button";import{createContext as $}from"@chakra-ui/react-utils";import{useStepper as q,useStep as G,StepperProvider as H,useStepperContext as z,StepperStep as J,StepperContainer as K,StepperSteps as Q}from"@saas-ui/stepper";export*from"@saas-ui/input-right-button";function T(){return T=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var a=arguments[t];for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(e[l]=a[l])}return e},T.apply(this,arguments)}function W(e,t){if(null==e)return{};var a,l,r={},n=Object.keys(e);for(l=0;l<n.length;l++)t.indexOf(a=n[l])>=0||(r[a]=e[a]);return r}const X=["name","label","placeholder"],Y=t=>{let{name:a,label:l}=t,r=W(t,X);/*#__PURE__*/return e.createElement(p,r,l?/*#__PURE__*/e.createElement(f,{htmlFor:a},l):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(Z,{name:a})))};t&&(Y.displayName="DisplayField");const Z=({name:e})=>{const{getValues:t}=s();return t(e)||null};t&&(Z.displayName="FormValue");const ee=["name","label","help","variant","hideLabel","children"],te=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],ae=["name","rules"],le=["ref"],re=["name","rules"],ne=["ref"],se=["type"],ie=["type"],oe=["label","type"],me={},ce="text",de=t=>{const{name:a,label:l,help:r,variant:n,hideLabel:o,children:m}=t,c=W(t,ee),{formState:d}=s(),u=((e,t)=>i(t.errors,e))(a,d);/*#__PURE__*/return e.createElement(p,T({variant:n},c,{isInvalid:!!u}),l&&!o?/*#__PURE__*/e.createElement(f,{variant:n},l):null,/*#__PURE__*/e.createElement(g,null,m,!r||null!=u&&u.message?null:/*#__PURE__*/e.createElement(F,null,r),(null==u?void 0:u.message)&&/*#__PURE__*/e.createElement(N,null,null==u?void 0:u.message)))};t&&(de.displayName="BaseField");const ue=b((t,a)=>{const{type:l=ce}=t,r=(e=>me[e]||me[ce])(l);/*#__PURE__*/return e.createElement(r,T({ref:a},t))}),pe=t=>b((a,l)=>{let{name:r,rules:n}=a,i=W(a,ae);const{control:m}=s();/*#__PURE__*/return e.createElement(o,{name:r,control:m,rules:n,render:a=>{let{field:{ref:r}}=a,n=W(a.field,le);/*#__PURE__*/return e.createElement(t,T({},n,i,{ref:x(l,r)}))}})}),fe=t=>b((a,l)=>{let{name:r,rules:n}=a,i=W(a,re);const{register:o}=s(),m=o(r,n),{ref:c}=m,d=W(m,ne);/*#__PURE__*/return e.createElement(t,T({},d,i,{ref:x(l,c)}))}),he=(t,a,l)=>{let r;r=null!=l&&l.isControlled?pe(a):fe(a);const n=((t,{displayName:a,hideLabel:l,BaseField:r})=>{const n=b((a,n)=>{const{id:s,name:i,label:o,help:m,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,rules:f,variant:h}=a,b=W(a,te),y=T({required:p},f);/*#__PURE__*/return e.createElement(r,{id:s,name:i,label:o,help:m,hideLabel:l,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,variant:h},/*#__PURE__*/e.createElement(t,T({ref:n,id:s,name:i,label:l?o:void 0,rules:y},b)))});return n.displayName=a,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==l?void 0:l.hideLabel,BaseField:(null==l?void 0:l.BaseField)||de});return me[t]=n,n},be=he("text",b((t,a)=>{let{type:l="text"}=t,r=W(t,se);/*#__PURE__*/return e.createElement(y,T({type:l},r,{ref:a}))})),ye=he("number",L,{isControlled:!0}),Ee=he("password",I),ve=he("textarea",C),ge=he("switch",b((t,a)=>{let l=W(t,ie);/*#__PURE__*/return e.createElement(E,T({},l,{ref:a}))}),{isControlled:!0}),Fe=he("select",D,{isControlled:!0}),Ne=he("checkbox",b((t,a)=>{let{label:l}=t,r=W(t,oe);/*#__PURE__*/return e.createElement(v,T({ref:a},r),l)}),{hideLabel:!0}),xe=he("radio",w,{isControlled:!0}),Ce=he("pin",A,{isControlled:!0}),ke=he("native-select",O,{isControlled:!0}),Re=["items"],Se=e=>e&&Object.entries(e).map(([e,t])=>T({},W(t,Re),{name:e})),Ve=e=>({getFields:()=>Se(e),getNestedFields:t=>{var l;const r=a(e,t);return r?"object"===(null==(l=r.items)?void 0:l.type)?Se(r.items.properties):"object"===r.type?Se(r.properties):[r.items]:[]}}),Le=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Ie=b((t,a)=>{const{mode:r="all",resolver:n,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:d,criteriaMode:u,delayError:p,schema:f,defaultValues:h,onSubmit:b,onError:y,formRef:E,children:v}=t,g=W(t,Le),F={mode:r,resolver:n,defaultValues:h,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:d,criteriaMode:u,delayError:p};f&&!n&&(F.resolver=null==Ie.getResolver?void 0:Ie.getResolver(f));const N=m(F),{handleSubmit:x}=N;return e.useImperativeHandle(a,()=>N,[a,N]),/*#__PURE__*/e.createElement(c,N,/*#__PURE__*/e.createElement(k.form,T({ref:E,onSubmit:x(b,y)},g,{className:l("saas-form",t.className)}),v))});Ie.getFieldResolver=Ve,t&&(Ie.displayName="Form");const we=["children"],Ae=({children:t})=>/*#__PURE__*/e.createElement(k.div,null,t);t&&(Ae.displayName="FormLayoutItem");const De=t=>{var a,r,n;let{children:s}=t,i=W(t,we);const o=T({},null!=(a=null==(r=R().components)||null==(n=r.FormLayout)?void 0:n.defaultProps)?a:{spacing:4},i);/*#__PURE__*/return e.createElement(S,T({},o,{className:l("saas-form__layout",i.className)}),e.Children.map(s,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(Ae,null,t):t))};t&&(De.displayName="FormLayout");const Oe=(t,a)=>e.Children.map(a,a=>e.isValidElement(a)&&a.props.name?e.cloneElement(a,T({},a.props,{name:`${t}.${a.props.name}`})):a),[je,Be]=$({name:"ArrayFieldContext"}),[Ue,_e]=$({name:"ArrayFieldRowContext"}),Me=({name:e,defaultValue:t={},keyName:a,min:l,max:r})=>{const{control:n}=s();return T({},d({control:n,name:e,keyName:a}),{name:e,defaultValue:t,min:l,max:r})},Pe=({index:t})=>{const{clearErrors:a}=s(),{name:l,remove:r,fields:n}=Be();return e.useEffect(()=>{a(l)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${l}.${t}`,remove:e.useCallback(()=>{a(l),r(t)},[t])}},$e=()=>{const{isFirst:e,remove:t}=_e(),{min:a,fields:l}=Be();return{onClick:()=>t(),isDisabled:e&&!!(a&&l.length<=a)}},qe=()=>{const{append:e,defaultValue:t,max:a,fields:l}=Be();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(a&&l.length>=a)}},Ge=["children","columns","spacing"],He=["children"],ze=["name","defaultValue","keyName","min","max","children"],Je=({children:t,columns:a,spacing:l,index:r})=>/*#__PURE__*/e.createElement(Qe,{index:r},/*#__PURE__*/e.createElement(Ke,{columns:a,spacing:l},t),/*#__PURE__*/e.createElement(Te,null));t&&(Je.displayName="ArrayFieldRow");const Ke=t=>{let{children:a,columns:l,spacing:r}=t,n=W(t,Ge);const{name:s}=_e();/*#__PURE__*/return e.createElement(De,T({flex:"1",columns:l,gridGap:r,mr:"2"},n),Oe(s,a))};t&&(Ke.displayName="ArrayFieldRowFields");const Qe=({children:t,index:a})=>{const l=Pe({index:a});/*#__PURE__*/return e.createElement(Ue,{value:l},/*#__PURE__*/e.createElement(j.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))};t&&(Qe.displayName="ArrayFieldRowContainer");const Te=t=>/*#__PURE__*/e.createElement(M,T({icon:/*#__PURE__*/e.createElement(U,null),"aria-label":"Remove row"},$e(),t));t&&(Te.displayName="ArrayFieldRemoveButton");const We=t=>/*#__PURE__*/e.createElement(M,T({icon:/*#__PURE__*/e.createElement(_,null),"aria-label":"Add row",float:"right"},qe(),t));t&&(We.displayName="ArrayFieldAddButton");const Xe=e.forwardRef((t,a)=>{const{children:l}=t,r=W(t,He);/*#__PURE__*/return e.createElement(Ze,T({ref:a},r),/*#__PURE__*/e.createElement(Ye,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},a)=>/*#__PURE__*/e.createElement(Je,{key:t,index:a},l)))),/*#__PURE__*/e.createElement(We,null))});t&&(Xe.displayName="ArrayField");const Ye=({children:e})=>{const{fields:t}=Be();return e(t)};t&&(Ye.displayName="ArrayFieldRows");const Ze=e.forwardRef((t,a)=>{let{name:l,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=W(t,ze);const c=Me({name:l,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(a,()=>c,[a,c]),/*#__PURE__*/e.createElement(je,{value:c},/*#__PURE__*/e.createElement(de,T({name:l},m),o))});t&&(Ze.displayName="ArrayFieldContainer");const et=["name","label","hideLabel","children","columns","spacing"],tt=t=>{const a=V("FormLegend");/*#__PURE__*/return e.createElement(f,T({as:"legend",sx:a},t))},at=t=>{const{name:a,label:l,hideLabel:r,children:n,columns:s,spacing:i}=t,o=W(t,et);/*#__PURE__*/return e.createElement(p,T({name:a,as:"fieldset"},o),/*#__PURE__*/e.createElement(tt,{display:r?"none":"block"},l),/*#__PURE__*/e.createElement(De,{columns:s,gridGap:i},Oe(a,n)))};t&&(at.displayName="ObjectField");const lt=["name","type"],rt=["schema","fieldResolver"],nt=["name","type","defaultValue"],st=(t,a)=>{var l;return null==(l=t.getNestedFields(a))?void 0:l.map((t,a)=>{let{name:l,type:r}=t,n=W(t,lt);/*#__PURE__*/return e.createElement(ue,T({key:l||a,name:l,type:r},n))})},it=t=>{let{schema:a,fieldResolver:l}=t,r=W(t,rt);const n=e.useMemo(()=>l||Ie.getFieldResolver(a),[a,l]);/*#__PURE__*/return e.createElement(De,r,n.getFields().map(t=>{let{name:a,type:l}=t,r=W(t,nt);return"array"===l?/*#__PURE__*/e.createElement(Xe,T({key:a,name:a},r),st(n,a)):"object"===l?/*#__PURE__*/e.createElement(at,T({key:a,name:a},r),st(n,a)):/*#__PURE__*/e.createElement(ue,T({key:a,name:a,type:l},r))}))};t&&(it.displayName="Fields");const ot=["children","disableIfUntouched","disableIfInvalid"],mt=B((t,a)=>{const{children:l,disableIfUntouched:r,disableIfInvalid:n}=t,i=W(t,ot),{formState:o}=s();/*#__PURE__*/return e.createElement(P,T({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:a,isDisabled:r&&!o.isDirty||n&&!o.isValid},i),l)});mt.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(mt.displayName="SubmitButton");const ct=["schema","submitLabel","fieldResolver","children"],dt=b((t,a)=>{const{schema:l,submitLabel:r="Submit",fieldResolver:n,children:s}=t,i=W(t,ct);/*#__PURE__*/return e.createElement(Ie,T({},i,{schema:l,ref:a}),/*#__PURE__*/e.createElement(De,null,/*#__PURE__*/e.createElement(it,{schema:l,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(mt,{label:r}),s))});t&&(dt.displayName="AutoForm");const ut=({children:e,name:t,defaultValue:a,isDisabled:l,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:a,disabled:l,exact:r}),s())?e:null;t&&(ut.displayName="DisplayIf");const pt=["onChange"],[ft,ht]=$({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function bt(t){const a=W(t,pt),l=q(a),{activeStep:r,isLastStep:n,nextStep:s}=l,[i,o]=e.useState({}),m=e.useCallback(async e=>{if(n)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{d(T({},i[r],{isCompleted:!0}))}).then(s);s()},[r,n]),c=e.useCallback(()=>{const e=i[r];return{onSubmit:m,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[i,m,r]),d=e.useCallback(e=>{o(t=>T({},t,{[e.name]:e}))},[i]);return T({getFormProps:c,updateStep:d,steps:i},l)}function yt(t){const{name:a,schema:l,resolver:r}=t,n=G({name:a}),{steps:s,updateStep:i}=ht();return e.useEffect(()=>{i({name:a,schema:l,resolver:r})},[a,l]),T({},n,s[a]||{name:a,schema:l})}const Et=["children"],vt=["getFormProps"],gt=["name","schema","resolver","children","className"],Ft=["label","submitLabel"],Nt=e.forwardRef((t,a)=>{const{children:l}=t,n=W(t,Et),s=bt(t),{getFormProps:i}=s,o=W(s,vt),m=e.useMemo(()=>o,[o]);/*#__PURE__*/return e.createElement(H,{value:m},/*#__PURE__*/e.createElement(ft,{value:m},/*#__PURE__*/e.createElement(Ie,T({ref:a},n,i()),r(l,s))))}),xt=t=>{const{activeIndex:a,setIndex:l}=z(),{children:r}=t,n=e.Children.map(r,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===Ct){const{isCompleted:a}=yt(t.props);/*#__PURE__*/return e.createElement(J,{name:t.props.name,title:t.props.title,isCompleted:a},t.props.children)}return t}),s=e.useCallback(e=>{l(e)},[]);/*#__PURE__*/return e.createElement(K,{step:a,onChange:s},/*#__PURE__*/e.createElement(Q,T({mb:"4"},t),n))},Ct=t=>{const{name:a,schema:r,resolver:n,children:s,className:i}=t,o=W(t,gt),m=yt({name:a,schema:r,resolver:n}),{isActive:c}=m;return c?/*#__PURE__*/e.createElement(j.div,T({},o,{className:l("saas-form__step",i)}),s):null};t&&(Ct.displayName="FormStep");const kt=t=>{const{isFirstStep:a,isCompleted:r,prevStep:s}=z();/*#__PURE__*/return e.createElement(P,T({isDisabled:a||r,label:"Back"},t,{className:l("saas-form__prev-button",t.className),onClick:n(t.onClick,s)}))};t&&(kt.displayName="PrevButton");const Rt=t=>{const{label:a="Next",submitLabel:r="Complete"}=t,n=W(t,Ft),{isLastStep:s,isCompleted:i}=z();/*#__PURE__*/return e.createElement(mt,T({isDisabled:i,label:s||i?r:a},n,{className:l("saas-form__next-button",t.className)}))};t&&(Rt.displayName="NextButton");export{Xe as ArrayField,We as ArrayFieldAddButton,Ze as ArrayFieldContainer,je as ArrayFieldProvider,Te as ArrayFieldRemoveButton,Je as ArrayFieldRow,Qe as ArrayFieldRowContainer,Ke as ArrayFieldRowFields,Ue as ArrayFieldRowProvider,Ye as ArrayFieldRows,dt as AutoForm,de as BaseField,Ne as CheckboxField,Y as DisplayField,ut as DisplayIf,ue as Field,it as Fields,Ie as Form,De as FormLayout,tt as FormLegend,Ct as FormStep,xt as FormStepper,Z as FormValue,be as InputField,ke as NativeSelectField,Rt as NextButton,ye as NumberInputField,at as ObjectField,Ee as PasswordInputFIeld,Ce as PinField,kt as PrevButton,xe as RadioField,Fe as SelectField,Nt as StepForm,ft as StepFormProvider,mt as SubmitButton,ge as SwitchField,ve as TextareaField,Ve as objectFieldResolver,he as registerFieldType,Me as useArrayField,qe as useArrayFieldAddButton,Be as useArrayFieldContext,$e as useArrayFieldRemoveButton,Pe as useArrayFieldRow,_e as useArrayFieldRowContext,yt as useFormStep,bt as useStepForm,ht as useStepFormContext,pe as withControlledInput,fe as withUncontrolledInput};
|
2
2
|
//# sourceMappingURL=index.modern.mjs.map
|