@saas-ui/forms 1.4.1 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +6 -0
- package/dist/ajv/index.js +82 -76
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/index.modern.js +82 -76
- package/dist/ajv/index.modern.js.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +1 -1
- package/dist/index.modern.js.map +1 -1
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/index.modern.js.map +1 -1
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.modern.js.map +1 -1
- package/package.json +1 -1
- package/src/field.tsx +2 -2
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"),o=require("@saas-ui/radio"),i=require("@saas-ui/select"),u=require("@chakra-ui/system"),s=require("@chakra-ui/icons"),d=require("@saas-ui/button"),c=require("@chakra-ui/react-utils"),m=require("@saas-ui/stepper"),p=require("@saas-ui/input-right-button");function f(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 v=/*#__PURE__*/f(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 b(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 x=["name","label","placeholder"],F=function(e){var r=e.name,t=e.label,a=b(e,x);/*#__PURE__*/return v.createElement(n.FormControl,a,t?/*#__PURE__*/v.createElement(n.FormLabel,{htmlFor:r},t):null,/*#__PURE__*/v.createElement(n.Text,{fontSize:"md"},/*#__PURE__*/v.createElement(y,{name:r})))};r.__DEV__&&(F.displayName="DisplayField");var y=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null};r.__DEV__&&(y.displayName="FormValue");var E=["name","label","help","hideLabel","children"],_=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules"],g=["name","rules"],C=["ref"],S=["name","rules"],N=["ref"],R=["type","leftAddon","rightAddon","size"],V=["type"],A=["label","type"],w=["pinLength","pinType","spacing"],D={},k=function(e){var r=e.name,a=e.label,l=e.help,o=e.hideLabel,i=e.children,u=b(e,E),s=function(e,r){return t.get(r.errors,e)}(r,t.useFormContext().formState);/*#__PURE__*/return v.createElement(n.FormControl,h({},u,{isInvalid:!!s}),a&&!o?/*#__PURE__*/v.createElement(n.FormLabel,null,a):null,/*#__PURE__*/v.createElement(n.Box,null,i,!l||null!=s&&s.message?null:/*#__PURE__*/v.createElement(n.FormHelperText,null,l),(null==s?void 0:s.message)&&/*#__PURE__*/v.createElement(n.FormErrorMessage,null,null==s?void 0:s.message)))};r.__DEV__&&(k.displayName="BaseField");var I=v.forwardRef(function(e,r){var t=e.type;/*#__PURE__*/return v.createElement(D[void 0===t?"text":t]||D.text,h({ref:r},e))}),P=function(e){return n.forwardRef(function(a,l){var o=a.name,i=a.rules,u=b(a,g),s=t.useFormContext();/*#__PURE__*/return v.createElement(t.Controller,{name:o,control:s.control,rules:i,render:function(t){var a=t.field,o=a.ref,i=b(a,C);/*#__PURE__*/return v.createElement(e,h({},i,u,{onChange:r.callAllHandlers(u.onChange,i.onChange),onBlur:r.callAllHandlers(u.onBlur,i.onBlur),ref:n.useMergeRefs(l,o)}))}})})},L=function(e){return n.forwardRef(function(a,l){var o=a.name,i=a.rules,u=b(a,S),s=(0,t.useFormContext().register)(o,i),d=s.ref,c=b(s,N);/*#__PURE__*/return v.createElement(e,h({},c,u,{onChange:r.callAllHandlers(u.onChange,c.onChange),onBlur:r.callAllHandlers(u.onBlur,c.onBlur),ref:n.useMergeRefs(l,d)}))})},B=function(e,r,t){var a=function(e,r){var t=r.displayName,a=r.hideLabel,l=r.BaseField,o=n.forwardRef(function(r,t){var n=r.id,o=r.name,i=r.label,u=r.help,s=r.isDisabled,d=r.isInvalid,c=r.isReadOnly,m=r.isRequired,p=r.rules,f=b(r,_),x=h({required:m},p);/*#__PURE__*/return v.createElement(l,{id:n,name:o,label:i,help:u,hideLabel:a,isDisabled:s,isInvalid:d,isReadOnly:c,isRequired:m},/*#__PURE__*/v.createElement(e,h({ref:t,id:n,name:o,label:a?i:void 0,rules:x},f)))});return o.displayName=t,o}(null!=t&&t.isControlled?P(r):L(r),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==t?void 0:t.hideLabel,BaseField:(null==t?void 0:t.BaseField)||k});return D[e]=a,a},O=B("text",n.forwardRef(function(e,r){var t=e.type,a=void 0===t?"text":t,l=e.leftAddon,o=e.rightAddon,i=e.size,u=b(e,R),s=/*#__PURE__*/v.createElement(n.Input,h({type:a,size:i},u,{ref:r}));return l||o?/*#__PURE__*/v.createElement(n.InputGroup,{size:i},l,s,o):s})),j=B("number",a.NumberInput,{isControlled:!0}),q=B("password",n.forwardRef(function(e,r){/*#__PURE__*/return v.createElement(l.PasswordInput,h({ref:r},e))})),M=B("textarea",n.Textarea),U=B("switch",n.forwardRef(function(e,r){var t=b(e,V);/*#__PURE__*/return v.createElement(n.Switch,h({},t,{ref:r}))}),{isControlled:!0}),H=B("select",i.Select,{isControlled:!0}),z=B("checkbox",n.forwardRef(function(e,r){var t=e.label,a=b(e,A);/*#__PURE__*/return v.createElement(n.Checkbox,h({ref:r},a),t)}),{hideLabel:!0}),T=B("radio",o.RadioInput,{isControlled:!0}),W=B("native-select",i.NativeSelect,{isControlled:!0}),G=B("pin",n.forwardRef(function(e,r){for(var t=e.pinLength,a=void 0===t?4:t,l=e.pinType,o=e.spacing,i=b(e,w),u=[],s=0;s<a;s++)u.push(/*#__PURE__*/v.createElement(n.PinInputField,{key:s,ref:r}));/*#__PURE__*/return v.createElement(n.HStack,{spacing:o},/*#__PURE__*/v.createElement(n.PinInput,h({},i,{type:l}),u))}),{isControlled:!0}),J=["items","label","title"],K=function(e){return e&&Object.entries(e).map(function(e){var r=e[0],t=e[1],n=t.label,a=t.title;return h({},b(t,J),{name:r,label:n||a})})},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","onChange","onSubmit","onError","formRef","children"],Y=n.forwardRef(function(e,a){var l=e.mode,o=void 0===l?"all":l,i=e.resolver,u=e.reValidateMode,s=e.shouldFocusError,d=e.shouldUnregister,c=e.shouldUseNativeValidation,m=e.criteriaMode,p=e.delayError,f=e.schema,x=e.defaultValues,F=e.onChange,y=e.onSubmit,E=e.onError,_=e.formRef,g=e.children,C=b(e,X),S={mode:o,resolver:i,defaultValues:x,reValidateMode:u,shouldFocusError:s,shouldUnregister:d,shouldUseNativeValidation:c,criteriaMode:m,delayError:p};f&&!i&&(S.resolver=null==Y.getResolver?void 0:Y.getResolver(f));var N=t.useForm(S),R=N.handleSubmit;return v.useImperativeHandle(a,function(){return N},[a,N]),v.useEffect(function(){var e;return F&&(e=N.watch(F)),function(){var r;return null==(r=e)?void 0:r.unsubscribe()}},[N,F]),/*#__PURE__*/v.createElement(t.FormProvider,N,/*#__PURE__*/v.createElement(n.chakra.form,h({ref:_,onSubmit:R(y,E)},C,{className:r.cx("saas-form",e.className)}),r.runIfFn(g,N)))});Y.getFieldResolver=Q,r.__DEV__&&(Y.displayName="Form");var Z=["children"],$=function(e){/*#__PURE__*/return v.createElement(n.chakra.div,null,e.children)};r.__DEV__&&($.displayName="FormLayoutItem");var ee=function(e){var t,a,l,o=e.children,i=b(e,Z),u=h({},null!=(t=null==(a=n.useTheme().components)||null==(l=a.FormLayout)?void 0:l.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return v.createElement(n.SimpleGrid,h({},u,{className:r.cx("saas-form__layout",i.className)}),v.Children.map(o,function(e){return v.isValidElement(e)?/*#__PURE__*/v.createElement($,null,e):e}))};r.__DEV__&&(ee.displayName="FormLayout");var re=function(e,r){return v.Children.map(r,function(r){return v.isValidElement(r)&&r.props.name?v.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"}),oe=le[0],ie=le[1],ue=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,o=e.min,i=e.max,u=t.useFormContext();return h({},t.useFieldArray({control:u.control,name:r,keyName:l}),{name:r,defaultValue:a,min:o,max:i})},se=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=ae(),l=a.name,o=a.remove,i=a.fields;return v.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===i.length-1,name:l+"."+r,remove:v.useCallback(function(){n(l),o(r)},[r])}},de=function(){var e=ie(),r=e.isFirst,t=e.remove,n=ae(),a=n.min;return{onClick:function(){return t()},isDisabled:r&&!!(a&&n.fields.length<=a)}},ce=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)}},me=["children","index"],pe=["children"],fe=["children"],ve=["name","defaultValue","keyName","min","max","children"],he=function(e){var r=e.children,t=e.index,n=b(e,me);/*#__PURE__*/return v.createElement(xe,{index:t},/*#__PURE__*/v.createElement(be,n,r),/*#__PURE__*/v.createElement(Fe,null))};r.__DEV__&&(he.displayName="ArrayFieldRow");var be=function(e){var r=e.children,t=b(e,pe),n=ie().name;/*#__PURE__*/return v.createElement(ee,h({flex:"1",mr:"2"},t),re(n,r))};r.__DEV__&&(be.displayName="ArrayFieldRowFields");var xe=function(e){var r=e.children,t=se({index:e.index});/*#__PURE__*/return v.createElement(oe,{value:t},/*#__PURE__*/v.createElement(u.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))};r.__DEV__&&(xe.displayName="ArrayFieldRowContainer");var Fe=function(e){/*#__PURE__*/return v.createElement(d.IconButton,h({icon:/*#__PURE__*/v.createElement(s.MinusIcon,null),"aria-label":"Remove row"},de(),e))};r.__DEV__&&(Fe.displayName="ArrayFieldRemoveButton");var ye=function(e){/*#__PURE__*/return v.createElement(d.IconButton,h({icon:/*#__PURE__*/v.createElement(s.AddIcon,null),"aria-label":"Add row",float:"right"},ce(),e))};r.__DEV__&&(ye.displayName="ArrayFieldAddButton");var Ee=u.forwardRef(function(e,r){var t=e.children,n=b(e,fe);/*#__PURE__*/return v.createElement(ge,h({ref:r},n),/*#__PURE__*/v.createElement(_e,null,function(e){/*#__PURE__*/return v.createElement(v.Fragment,null,e.map(function(e,r){/*#__PURE__*/return v.createElement(he,{key:e.id,index:r},t)}))}),/*#__PURE__*/v.createElement(ye,null))});r.__DEV__&&(Ee.displayName="ArrayField");var _e=function(e){return(0,e.children)(ae().fields)};r.__DEV__&&(_e.displayName="ArrayFieldRows");var ge=v.forwardRef(function(e,r){var t=e.name,n=e.defaultValue,a=e.keyName,l=e.min,o=e.max,i=e.children,u=b(e,ve),s=ue({name:t,defaultValue:n,keyName:a,min:l,max:o});return v.useImperativeHandle(r,function(){return s},[r,s]),/*#__PURE__*/v.createElement(ne,{value:s},/*#__PURE__*/v.createElement(k,h({name:t},u),i))});r.__DEV__&&(ge.displayName="ArrayFieldContainer");var Ce=["name","label","hideLabel","children","columns","spacing"],Se=function(e){var r=n.useStyleConfig("FormLegend");/*#__PURE__*/return v.createElement(n.FormLabel,h({as:"legend",sx:r},e))},Ne=function(e){var r=e.name,t=e.label,a=e.hideLabel,l=e.children,o=e.columns,i=e.spacing,u=b(e,Ce);/*#__PURE__*/return v.createElement(n.FormControl,h({name:r,as:"fieldset"},u),/*#__PURE__*/v.createElement(Se,{display:a?"none":"block"},t),/*#__PURE__*/v.createElement(ee,{columns:o,gridGap:i},re(r,l)))};r.__DEV__&&(Ne.displayName="ObjectField");var Re=["name","type"],Ve=["schema","fieldResolver","focusFirstField"],Ae=["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=b(e,Re);/*#__PURE__*/return v.createElement(I,h({key:t||r,name:t,type:n},a))})},De=function(e){var r=e.schema,n=e.fieldResolver,a=e.focusFirstField,l=b(e,Ve),o=v.useMemo(function(){return n||Y.getFieldResolver(r)},[r,n]),i=v.useMemo(function(){return o.getFields()},[o]),u=t.useFormContext();return v.useEffect(function(){var e;a&&null!=(e=i[0])&&e.name&&u.setFocus(i[0].name)},[r,n,a]),/*#__PURE__*/v.createElement(ee,l,i.map(function(e){var r=e.name,t=e.type,n=b(e,Ae);return"array"===t?/*#__PURE__*/v.createElement(Ee,h({key:r,name:r},n),we(o,r)):"object"===t?/*#__PURE__*/v.createElement(Ne,h({key:r,name:r},n),we(o,r)):/*#__PURE__*/v.createElement(I,h({key:r,name:r,type:t},n))}))};r.__DEV__&&(De.displayName="Fields");var ke=["children","disableIfUntouched","disableIfInvalid","isDisabled","isLoading"],Ie=v.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,o=e.isDisabled,i=e.isLoading,u=b(e,ke),s=t.useFormContext().formState;/*#__PURE__*/return v.createElement(d.Button,h({},u,{ref:r,variant:"primary",type:"submit",isLoading:s.isSubmitting||i,isDisabled:a&&!s.isDirty||l&&!s.isValid||o}),n)});Ie.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},r.__DEV__&&(Ie.displayName="SubmitButton");var Pe=["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,o=e.children,i=b(e,Pe);/*#__PURE__*/return v.createElement(Y,h({},i,{schema:t,ref:r}),/*#__PURE__*/v.createElement(ee,null,/*#__PURE__*/v.createElement(De,{schema:t,fieldResolver:l}),a&&/*#__PURE__*/v.createElement(Ie,null,a),o))});r.__DEV__&&(Le.displayName="AutoForm");var Be=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__&&(Be.displayName="DisplayIf");var Oe=["onChange"],je=c.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),qe=je[0],Me=je[1];function Ue(e){var r=b(e,Oe),t=m.useStepper(r),n=t.activeStep,a=t.isLastStep,l=t.nextStep,o=v.useState({}),i=o[0],u=o[1],s=v.useCallback(function(r){var o;return Promise.resolve(function(u,s){try{var d=function(){function u(e){return o?e:Promise.resolve(null==s.onSubmit?void 0:s.onSubmit(r,t)).then(function(){l()})}var s=i[n],d=function(){if(a)return Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(r)).then(function(){c(h({},s,{isCompleted:!0})),l(),o=1})}();return d&&d.then?d.then(u):u(d)}()}catch(e){return}return d&&d.then?d.then(void 0,function(){}):d}())},[i,n,a]),d=v.useCallback(function(){var e=i[n];return{onSubmit:s,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[i,s,n]),c=v.useCallback(function(e){u(function(r){var t;return h({},r,((t={})[e.name]=e,t))})},[i]);return h({getFormProps:d,updateStep:c,steps:i},t)}function He(e){var r=e.name,t=e.schema,n=e.resolver,a=e.onSubmit,l=m.useStep({name:r}),o=Me(),i=o.steps,u=o.updateStep;return v.useEffect(function(){u({name:r,schema:t,resolver:n,onSubmit:a})},[r,t]),h({},l,i[r]||{name:r,schema:t})}var ze=["children"],Te=["getFormProps"],We=["children","orientation","variant","colorScheme","size"],Ge=["name","schema","resolver","children","className","onSubmit"],Je=["label","submitLabel"],Ke=v.forwardRef(function(e,t){var n=e.children,a=b(e,ze),l=Ue(e),o=l.getFormProps,i=b(l,Te),u=v.useMemo(function(){return i},[i]);/*#__PURE__*/return v.createElement(m.StepperProvider,{value:u},/*#__PURE__*/v.createElement(qe,{value:u},/*#__PURE__*/v.createElement(Y,h({ref:t},a,o()),r.runIfFn(n,l))))}),Qe=function(e){var t=e.name,n=e.schema,a=e.resolver,l=e.children,o=e.className,i=e.onSubmit,s=b(e,Ge);return He({name:t,schema:n,resolver:a,onSubmit:i}).isActive?/*#__PURE__*/v.createElement(u.chakra.div,h({},s,{className:r.cx("saas-form__step",o)}),l):null};r.__DEV__&&(Qe.displayName="FormStep");var Xe=function(e){var t=m.useStepperContext(),n=t.prevStep;/*#__PURE__*/return v.createElement(d.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__&&(Xe.displayName="PrevButton");var Ye=function(e){var t=e.label,n=void 0===t?"Next":t,a=e.submitLabel,l=void 0===a?"Complete":a,o=b(e,Je),i=m.useStepperContext(),u=i.isLastStep,s=i.isCompleted;/*#__PURE__*/return v.createElement(Ie,h({},o,{isDisabled:s,className:r.cx("saas-form__next-button",e.className)}),u||s?l:n)};r.__DEV__&&(Ye.displayName="NextButton"),Object.defineProperty(exports,"Controller",{enumerable:!0,get:function(){return t.Controller}}),Object.defineProperty(exports,"FormProvider",{enumerable:!0,get:function(){return t.FormProvider}}),Object.defineProperty(exports,"appendErrors",{enumerable:!0,get:function(){return t.appendErrors}}),Object.defineProperty(exports,"useController",{enumerable:!0,get:function(){return t.useController}}),Object.defineProperty(exports,"useFieldArray",{enumerable:!0,get:function(){return t.useFieldArray}}),Object.defineProperty(exports,"useForm",{enumerable:!0,get:function(){return t.useForm}}),Object.defineProperty(exports,"useFormContext",{enumerable:!0,get:function(){return t.useFormContext}}),Object.defineProperty(exports,"useFormState",{enumerable:!0,get:function(){return t.useFormState}}),Object.defineProperty(exports,"useWatch",{enumerable:!0,get:function(){return t.useWatch}}),exports.ArrayField=Ee,exports.ArrayFieldAddButton=ye,exports.ArrayFieldContainer=ge,exports.ArrayFieldProvider=ne,exports.ArrayFieldRemoveButton=Fe,exports.ArrayFieldRow=he,exports.ArrayFieldRowContainer=xe,exports.ArrayFieldRowFields=be,exports.ArrayFieldRowProvider=oe,exports.ArrayFieldRows=_e,exports.AutoForm=Le,exports.BaseField=k,exports.CheckboxField=z,exports.DisplayField=F,exports.DisplayIf=Be,exports.Field=I,exports.Fields=De,exports.Form=Y,exports.FormLayout=ee,exports.FormLegend=Se,exports.FormStep=Qe,exports.FormStepper=function(e){var r=m.useStepperContext(),t=r.activeIndex,n=r.setIndex,a=e.children,l=e.orientation,o=e.variant,i=e.colorScheme,u=e.size,s=b(e,We),d=v.Children.map(a,function(e){if(v.isValidElement(e)&&(null==e?void 0:e.type)===Qe){var r=He(e.props);/*#__PURE__*/return v.createElement(m.StepperStep,h({name:e.props.name,title:e.props.title,isCompleted:r.isCompleted},s),e.props.children)}return e}),c=v.useCallback(function(e){n(e)},[]);/*#__PURE__*/return v.createElement(m.StepperContainer,{orientation:l,step:t,variant:o,colorScheme:i,size:u,onChange:c},/*#__PURE__*/v.createElement(m.StepperSteps,h({mb:"4"},e),d))},exports.FormValue=y,exports.InputField=O,exports.NativeSelectField=W,exports.NextButton=Ye,exports.NumberInputField=j,exports.ObjectField=Ne,exports.PasswordInputField=q,exports.PinField=G,exports.PrevButton=Xe,exports.RadioField=T,exports.SelectField=H,exports.StepForm=Ke,exports.StepFormProvider=qe,exports.SubmitButton=Ie,exports.SwitchField=U,exports.TextareaField=M,exports.WatchField=function(e){var r=e.name,n=e.defaultValue,a=e.isDisabled,l=e.isExact,o=t.useFormContext(),i=t.useWatch({name:r,defaultValue:n,disabled:a,exact:l});return e.children(i,o)||null},exports.objectFieldResolver=Q,exports.registerFieldType=B,exports.useArrayField=ue,exports.useArrayFieldAddButton=ce,exports.useArrayFieldContext=ae,exports.useArrayFieldRemoveButton=de,exports.useArrayFieldRow=se,exports.useArrayFieldRowContext=ie,exports.useFormStep=He,exports.useStepForm=Ue,exports.useStepFormContext=Me,exports.withControlledInput=P,exports.withUncontrolledInput=L,Object.keys(p).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return p[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"),o=require("@saas-ui/radio"),i=require("@saas-ui/select"),u=require("@chakra-ui/system"),s=require("@chakra-ui/icons"),d=require("@saas-ui/button"),c=require("@chakra-ui/react-utils"),m=require("@saas-ui/stepper"),p=require("@saas-ui/input-right-button");function f(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 v=/*#__PURE__*/f(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 b(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 x=["name","label","placeholder"],F=function(e){var r=e.name,t=e.label,a=b(e,x);/*#__PURE__*/return v.createElement(n.FormControl,a,t?/*#__PURE__*/v.createElement(n.FormLabel,{htmlFor:r},t):null,/*#__PURE__*/v.createElement(n.Text,{fontSize:"md"},/*#__PURE__*/v.createElement(y,{name:r})))};r.__DEV__&&(F.displayName="DisplayField");var y=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null};r.__DEV__&&(y.displayName="FormValue");var E=["name","label","help","hideLabel","children"],_=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules"],g=["name","rules"],C=["ref"],S=["name","rules"],N=["ref"],R=["type","leftAddon","rightAddon","size"],V=["type","value"],A=["label","type"],w=["pinLength","pinType","spacing"],D={},k=function(e){var r=e.name,a=e.label,l=e.help,o=e.hideLabel,i=e.children,u=b(e,E),s=function(e,r){return t.get(r.errors,e)}(r,t.useFormContext().formState);/*#__PURE__*/return v.createElement(n.FormControl,h({},u,{isInvalid:!!s}),a&&!o?/*#__PURE__*/v.createElement(n.FormLabel,null,a):null,/*#__PURE__*/v.createElement(n.Box,null,i,!l||null!=s&&s.message?null:/*#__PURE__*/v.createElement(n.FormHelperText,null,l),(null==s?void 0:s.message)&&/*#__PURE__*/v.createElement(n.FormErrorMessage,null,null==s?void 0:s.message)))};r.__DEV__&&(k.displayName="BaseField");var I=v.forwardRef(function(e,r){var t=e.type;/*#__PURE__*/return v.createElement(D[void 0===t?"text":t]||D.text,h({ref:r},e))}),P=function(e){return n.forwardRef(function(a,l){var o=a.name,i=a.rules,u=b(a,g),s=t.useFormContext();/*#__PURE__*/return v.createElement(t.Controller,{name:o,control:s.control,rules:i,render:function(t){var a=t.field,o=a.ref,i=b(a,C);/*#__PURE__*/return v.createElement(e,h({},i,u,{onChange:r.callAllHandlers(u.onChange,i.onChange),onBlur:r.callAllHandlers(u.onBlur,i.onBlur),ref:n.useMergeRefs(l,o)}))}})})},L=function(e){return n.forwardRef(function(a,l){var o=a.name,i=a.rules,u=b(a,S),s=(0,t.useFormContext().register)(o,i),d=s.ref,c=b(s,N);/*#__PURE__*/return v.createElement(e,h({},c,u,{onChange:r.callAllHandlers(u.onChange,c.onChange),onBlur:r.callAllHandlers(u.onBlur,c.onBlur),ref:n.useMergeRefs(l,d)}))})},B=function(e,r,t){var a=function(e,r){var t=r.displayName,a=r.hideLabel,l=r.BaseField,o=n.forwardRef(function(r,t){var n=r.id,o=r.name,i=r.label,u=r.help,s=r.isDisabled,d=r.isInvalid,c=r.isReadOnly,m=r.isRequired,p=r.rules,f=b(r,_),x=h({required:m},p);/*#__PURE__*/return v.createElement(l,{id:n,name:o,label:i,help:u,hideLabel:a,isDisabled:s,isInvalid:d,isReadOnly:c,isRequired:m},/*#__PURE__*/v.createElement(e,h({ref:t,id:n,name:o,label:a?i:void 0,rules:x},f)))});return o.displayName=t,o}(null!=t&&t.isControlled?P(r):L(r),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==t?void 0:t.hideLabel,BaseField:(null==t?void 0:t.BaseField)||k});return D[e]=a,a},O=B("text",n.forwardRef(function(e,r){var t=e.type,a=void 0===t?"text":t,l=e.leftAddon,o=e.rightAddon,i=e.size,u=b(e,R),s=/*#__PURE__*/v.createElement(n.Input,h({type:a,size:i},u,{ref:r}));return l||o?/*#__PURE__*/v.createElement(n.InputGroup,{size:i},l,s,o):s})),j=B("number",a.NumberInput,{isControlled:!0}),q=B("password",n.forwardRef(function(e,r){/*#__PURE__*/return v.createElement(l.PasswordInput,h({ref:r},e))})),M=B("textarea",n.Textarea),U=B("switch",n.forwardRef(function(e,r){var t=e.value,a=b(e,V);/*#__PURE__*/return v.createElement(n.Switch,h({isChecked:!!t},a,{ref:r}))}),{isControlled:!0}),H=B("select",i.Select,{isControlled:!0}),z=B("checkbox",n.forwardRef(function(e,r){var t=e.label,a=b(e,A);/*#__PURE__*/return v.createElement(n.Checkbox,h({ref:r},a),t)}),{hideLabel:!0}),T=B("radio",o.RadioInput,{isControlled:!0}),W=B("native-select",i.NativeSelect,{isControlled:!0}),G=B("pin",n.forwardRef(function(e,r){for(var t=e.pinLength,a=void 0===t?4:t,l=e.pinType,o=e.spacing,i=b(e,w),u=[],s=0;s<a;s++)u.push(/*#__PURE__*/v.createElement(n.PinInputField,{key:s,ref:r}));/*#__PURE__*/return v.createElement(n.HStack,{spacing:o},/*#__PURE__*/v.createElement(n.PinInput,h({},i,{type:l}),u))}),{isControlled:!0}),J=["items","label","title"],K=function(e){return e&&Object.entries(e).map(function(e){var r=e[0],t=e[1],n=t.label,a=t.title;return h({},b(t,J),{name:r,label:n||a})})},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","onChange","onSubmit","onError","formRef","children"],Y=n.forwardRef(function(e,a){var l=e.mode,o=void 0===l?"all":l,i=e.resolver,u=e.reValidateMode,s=e.shouldFocusError,d=e.shouldUnregister,c=e.shouldUseNativeValidation,m=e.criteriaMode,p=e.delayError,f=e.schema,x=e.defaultValues,F=e.onChange,y=e.onSubmit,E=e.onError,_=e.formRef,g=e.children,C=b(e,X),S={mode:o,resolver:i,defaultValues:x,reValidateMode:u,shouldFocusError:s,shouldUnregister:d,shouldUseNativeValidation:c,criteriaMode:m,delayError:p};f&&!i&&(S.resolver=null==Y.getResolver?void 0:Y.getResolver(f));var N=t.useForm(S),R=N.handleSubmit;return v.useImperativeHandle(a,function(){return N},[a,N]),v.useEffect(function(){var e;return F&&(e=N.watch(F)),function(){var r;return null==(r=e)?void 0:r.unsubscribe()}},[N,F]),/*#__PURE__*/v.createElement(t.FormProvider,N,/*#__PURE__*/v.createElement(n.chakra.form,h({ref:_,onSubmit:R(y,E)},C,{className:r.cx("saas-form",e.className)}),r.runIfFn(g,N)))});Y.getFieldResolver=Q,r.__DEV__&&(Y.displayName="Form");var Z=["children"],$=function(e){/*#__PURE__*/return v.createElement(n.chakra.div,null,e.children)};r.__DEV__&&($.displayName="FormLayoutItem");var ee=function(e){var t,a,l,o=e.children,i=b(e,Z),u=h({},null!=(t=null==(a=n.useTheme().components)||null==(l=a.FormLayout)?void 0:l.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return v.createElement(n.SimpleGrid,h({},u,{className:r.cx("saas-form__layout",i.className)}),v.Children.map(o,function(e){return v.isValidElement(e)?/*#__PURE__*/v.createElement($,null,e):e}))};r.__DEV__&&(ee.displayName="FormLayout");var re=function(e,r){return v.Children.map(r,function(r){return v.isValidElement(r)&&r.props.name?v.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"}),oe=le[0],ie=le[1],ue=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,o=e.min,i=e.max,u=t.useFormContext();return h({},t.useFieldArray({control:u.control,name:r,keyName:l}),{name:r,defaultValue:a,min:o,max:i})},se=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=ae(),l=a.name,o=a.remove,i=a.fields;return v.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===i.length-1,name:l+"."+r,remove:v.useCallback(function(){n(l),o(r)},[r])}},de=function(){var e=ie(),r=e.isFirst,t=e.remove,n=ae(),a=n.min;return{onClick:function(){return t()},isDisabled:r&&!!(a&&n.fields.length<=a)}},ce=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)}},me=["children","index"],pe=["children"],fe=["children"],ve=["name","defaultValue","keyName","min","max","children"],he=function(e){var r=e.children,t=e.index,n=b(e,me);/*#__PURE__*/return v.createElement(xe,{index:t},/*#__PURE__*/v.createElement(be,n,r),/*#__PURE__*/v.createElement(Fe,null))};r.__DEV__&&(he.displayName="ArrayFieldRow");var be=function(e){var r=e.children,t=b(e,pe),n=ie().name;/*#__PURE__*/return v.createElement(ee,h({flex:"1",mr:"2"},t),re(n,r))};r.__DEV__&&(be.displayName="ArrayFieldRowFields");var xe=function(e){var r=e.children,t=se({index:e.index});/*#__PURE__*/return v.createElement(oe,{value:t},/*#__PURE__*/v.createElement(u.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))};r.__DEV__&&(xe.displayName="ArrayFieldRowContainer");var Fe=function(e){/*#__PURE__*/return v.createElement(d.IconButton,h({icon:/*#__PURE__*/v.createElement(s.MinusIcon,null),"aria-label":"Remove row"},de(),e))};r.__DEV__&&(Fe.displayName="ArrayFieldRemoveButton");var ye=function(e){/*#__PURE__*/return v.createElement(d.IconButton,h({icon:/*#__PURE__*/v.createElement(s.AddIcon,null),"aria-label":"Add row",float:"right"},ce(),e))};r.__DEV__&&(ye.displayName="ArrayFieldAddButton");var Ee=u.forwardRef(function(e,r){var t=e.children,n=b(e,fe);/*#__PURE__*/return v.createElement(ge,h({ref:r},n),/*#__PURE__*/v.createElement(_e,null,function(e){/*#__PURE__*/return v.createElement(v.Fragment,null,e.map(function(e,r){/*#__PURE__*/return v.createElement(he,{key:e.id,index:r},t)}))}),/*#__PURE__*/v.createElement(ye,null))});r.__DEV__&&(Ee.displayName="ArrayField");var _e=function(e){return(0,e.children)(ae().fields)};r.__DEV__&&(_e.displayName="ArrayFieldRows");var ge=v.forwardRef(function(e,r){var t=e.name,n=e.defaultValue,a=e.keyName,l=e.min,o=e.max,i=e.children,u=b(e,ve),s=ue({name:t,defaultValue:n,keyName:a,min:l,max:o});return v.useImperativeHandle(r,function(){return s},[r,s]),/*#__PURE__*/v.createElement(ne,{value:s},/*#__PURE__*/v.createElement(k,h({name:t},u),i))});r.__DEV__&&(ge.displayName="ArrayFieldContainer");var Ce=["name","label","hideLabel","children","columns","spacing"],Se=function(e){var r=n.useStyleConfig("FormLegend");/*#__PURE__*/return v.createElement(n.FormLabel,h({as:"legend",sx:r},e))},Ne=function(e){var r=e.name,t=e.label,a=e.hideLabel,l=e.children,o=e.columns,i=e.spacing,u=b(e,Ce);/*#__PURE__*/return v.createElement(n.FormControl,h({name:r,as:"fieldset"},u),/*#__PURE__*/v.createElement(Se,{display:a?"none":"block"},t),/*#__PURE__*/v.createElement(ee,{columns:o,gridGap:i},re(r,l)))};r.__DEV__&&(Ne.displayName="ObjectField");var Re=["name","type"],Ve=["schema","fieldResolver","focusFirstField"],Ae=["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=b(e,Re);/*#__PURE__*/return v.createElement(I,h({key:t||r,name:t,type:n},a))})},De=function(e){var r=e.schema,n=e.fieldResolver,a=e.focusFirstField,l=b(e,Ve),o=v.useMemo(function(){return n||Y.getFieldResolver(r)},[r,n]),i=v.useMemo(function(){return o.getFields()},[o]),u=t.useFormContext();return v.useEffect(function(){var e;a&&null!=(e=i[0])&&e.name&&u.setFocus(i[0].name)},[r,n,a]),/*#__PURE__*/v.createElement(ee,l,i.map(function(e){var r=e.name,t=e.type,n=b(e,Ae);return"array"===t?/*#__PURE__*/v.createElement(Ee,h({key:r,name:r},n),we(o,r)):"object"===t?/*#__PURE__*/v.createElement(Ne,h({key:r,name:r},n),we(o,r)):/*#__PURE__*/v.createElement(I,h({key:r,name:r,type:t},n))}))};r.__DEV__&&(De.displayName="Fields");var ke=["children","disableIfUntouched","disableIfInvalid","isDisabled","isLoading"],Ie=v.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,o=e.isDisabled,i=e.isLoading,u=b(e,ke),s=t.useFormContext().formState;/*#__PURE__*/return v.createElement(d.Button,h({},u,{ref:r,variant:"primary",type:"submit",isLoading:s.isSubmitting||i,isDisabled:a&&!s.isDirty||l&&!s.isValid||o}),n)});Ie.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},r.__DEV__&&(Ie.displayName="SubmitButton");var Pe=["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,o=e.children,i=b(e,Pe);/*#__PURE__*/return v.createElement(Y,h({},i,{schema:t,ref:r}),/*#__PURE__*/v.createElement(ee,null,/*#__PURE__*/v.createElement(De,{schema:t,fieldResolver:l}),a&&/*#__PURE__*/v.createElement(Ie,null,a),o))});r.__DEV__&&(Le.displayName="AutoForm");var Be=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__&&(Be.displayName="DisplayIf");var Oe=["onChange"],je=c.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),qe=je[0],Me=je[1];function Ue(e){var r=b(e,Oe),t=m.useStepper(r),n=t.activeStep,a=t.isLastStep,l=t.nextStep,o=v.useState({}),i=o[0],u=o[1],s=v.useCallback(function(r){var o;return Promise.resolve(function(u,s){try{var d=function(){function u(e){return o?e:Promise.resolve(null==s.onSubmit?void 0:s.onSubmit(r,t)).then(function(){l()})}var s=i[n],d=function(){if(a)return Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(r)).then(function(){c(h({},s,{isCompleted:!0})),l(),o=1})}();return d&&d.then?d.then(u):u(d)}()}catch(e){return}return d&&d.then?d.then(void 0,function(){}):d}())},[i,n,a]),d=v.useCallback(function(){var e=i[n];return{onSubmit:s,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[i,s,n]),c=v.useCallback(function(e){u(function(r){var t;return h({},r,((t={})[e.name]=e,t))})},[i]);return h({getFormProps:d,updateStep:c,steps:i},t)}function He(e){var r=e.name,t=e.schema,n=e.resolver,a=e.onSubmit,l=m.useStep({name:r}),o=Me(),i=o.steps,u=o.updateStep;return v.useEffect(function(){u({name:r,schema:t,resolver:n,onSubmit:a})},[r,t]),h({},l,i[r]||{name:r,schema:t})}var ze=["children"],Te=["getFormProps"],We=["children","orientation","variant","colorScheme","size"],Ge=["name","schema","resolver","children","className","onSubmit"],Je=["label","submitLabel"],Ke=v.forwardRef(function(e,t){var n=e.children,a=b(e,ze),l=Ue(e),o=l.getFormProps,i=b(l,Te),u=v.useMemo(function(){return i},[i]);/*#__PURE__*/return v.createElement(m.StepperProvider,{value:u},/*#__PURE__*/v.createElement(qe,{value:u},/*#__PURE__*/v.createElement(Y,h({ref:t},a,o()),r.runIfFn(n,l))))}),Qe=function(e){var t=e.name,n=e.schema,a=e.resolver,l=e.children,o=e.className,i=e.onSubmit,s=b(e,Ge);return He({name:t,schema:n,resolver:a,onSubmit:i}).isActive?/*#__PURE__*/v.createElement(u.chakra.div,h({},s,{className:r.cx("saas-form__step",o)}),l):null};r.__DEV__&&(Qe.displayName="FormStep");var Xe=function(e){var t=m.useStepperContext(),n=t.prevStep;/*#__PURE__*/return v.createElement(d.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__&&(Xe.displayName="PrevButton");var Ye=function(e){var t=e.label,n=void 0===t?"Next":t,a=e.submitLabel,l=void 0===a?"Complete":a,o=b(e,Je),i=m.useStepperContext(),u=i.isLastStep,s=i.isCompleted;/*#__PURE__*/return v.createElement(Ie,h({},o,{isDisabled:s,className:r.cx("saas-form__next-button",e.className)}),u||s?l:n)};r.__DEV__&&(Ye.displayName="NextButton"),Object.defineProperty(exports,"Controller",{enumerable:!0,get:function(){return t.Controller}}),Object.defineProperty(exports,"FormProvider",{enumerable:!0,get:function(){return t.FormProvider}}),Object.defineProperty(exports,"appendErrors",{enumerable:!0,get:function(){return t.appendErrors}}),Object.defineProperty(exports,"useController",{enumerable:!0,get:function(){return t.useController}}),Object.defineProperty(exports,"useFieldArray",{enumerable:!0,get:function(){return t.useFieldArray}}),Object.defineProperty(exports,"useForm",{enumerable:!0,get:function(){return t.useForm}}),Object.defineProperty(exports,"useFormContext",{enumerable:!0,get:function(){return t.useFormContext}}),Object.defineProperty(exports,"useFormState",{enumerable:!0,get:function(){return t.useFormState}}),Object.defineProperty(exports,"useWatch",{enumerable:!0,get:function(){return t.useWatch}}),exports.ArrayField=Ee,exports.ArrayFieldAddButton=ye,exports.ArrayFieldContainer=ge,exports.ArrayFieldProvider=ne,exports.ArrayFieldRemoveButton=Fe,exports.ArrayFieldRow=he,exports.ArrayFieldRowContainer=xe,exports.ArrayFieldRowFields=be,exports.ArrayFieldRowProvider=oe,exports.ArrayFieldRows=_e,exports.AutoForm=Le,exports.BaseField=k,exports.CheckboxField=z,exports.DisplayField=F,exports.DisplayIf=Be,exports.Field=I,exports.Fields=De,exports.Form=Y,exports.FormLayout=ee,exports.FormLegend=Se,exports.FormStep=Qe,exports.FormStepper=function(e){var r=m.useStepperContext(),t=r.activeIndex,n=r.setIndex,a=e.children,l=e.orientation,o=e.variant,i=e.colorScheme,u=e.size,s=b(e,We),d=v.Children.map(a,function(e){if(v.isValidElement(e)&&(null==e?void 0:e.type)===Qe){var r=He(e.props);/*#__PURE__*/return v.createElement(m.StepperStep,h({name:e.props.name,title:e.props.title,isCompleted:r.isCompleted},s),e.props.children)}return e}),c=v.useCallback(function(e){n(e)},[]);/*#__PURE__*/return v.createElement(m.StepperContainer,{orientation:l,step:t,variant:o,colorScheme:i,size:u,onChange:c},/*#__PURE__*/v.createElement(m.StepperSteps,h({mb:"4"},e),d))},exports.FormValue=y,exports.InputField=O,exports.NativeSelectField=W,exports.NextButton=Ye,exports.NumberInputField=j,exports.ObjectField=Ne,exports.PasswordInputField=q,exports.PinField=G,exports.PrevButton=Xe,exports.RadioField=T,exports.SelectField=H,exports.StepForm=Ke,exports.StepFormProvider=qe,exports.SubmitButton=Ie,exports.SwitchField=U,exports.TextareaField=M,exports.WatchField=function(e){var r=e.name,n=e.defaultValue,a=e.isDisabled,l=e.isExact,o=t.useFormContext(),i=t.useWatch({name:r,defaultValue:n,disabled:a,exact:l});return e.children(i,o)||null},exports.objectFieldResolver=Q,exports.registerFieldType=B,exports.useArrayField=ue,exports.useArrayFieldAddButton=ce,exports.useArrayFieldContext=ae,exports.useArrayFieldRemoveButton=de,exports.useArrayFieldRow=se,exports.useArrayFieldRowContext=ie,exports.useFormStep=He,exports.useStepForm=Ue,exports.useStepFormContext=Me,exports.withControlledInput=P,exports.withUncontrolledInput=L,Object.keys(p).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return p[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","../src/watch-field.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 InputGroup,\n InputProps,\n TextareaProps,\n SwitchProps,\n CheckboxProps,\n PinInputField,\n HStack,\n PinInput,\n UsePinInputProps,\n SystemProps,\n} from '@chakra-ui/react'\nimport { __DEV__, FocusableElement, callAllHandlers } from '@chakra-ui/utils'\n\nimport { NumberInput, NumberInputProps } from '@saas-ui/number-input'\nimport { PasswordInput, PasswordInputProps } from '@saas-ui/password-input'\nimport { RadioInput, RadioInputProps } from '@saas-ui/radio'\n\nimport {\n Select,\n SelectProps,\n NativeSelect,\n NativeSelectProps,\n} from '@saas-ui/select'\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 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 * 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 */\n type?: string\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<string, React.FC<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, hideLabel, children, ...controlProps } = props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? <FormLabel>{label}</FormLabel> : 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 type As<Props = any> = React.ElementType<Props>\n\nexport type PropsOf<T extends As> = React.ComponentPropsWithoutRef<T> & {\n type?: FieldTypes\n}\n\n/**\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 */\nexport const Field = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> | FieldTypeProps,\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 FieldTypeProps & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement) & {\n displayName?: string\n}\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((props, ref) => {\n const {\n id,\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\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 >\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: React.FC<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 onChange={callAllHandlers(inputProps.onChange, field.onChange)}\n onBlur={callAllHandlers(inputProps.onBlur, field.onBlur)}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: React.FC<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 onChange={callAllHandlers(inputProps.onChange, field.onChange)}\n onBlur={callAllHandlers(inputProps.onBlur, field.onBlur)}\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 = <T extends object>(\n type: string,\n component: React.FC<T>,\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 }) as React.FC<T & FieldProps>\n\n inputTypes[type] = Field\n\n return Field\n}\n\nexport interface InputFieldProps extends InputProps {\n type?: string\n leftAddon?: React.ReactNode\n rightAddon?: React.ReactNode\n}\n\nexport const InputField = registerFieldType<InputFieldProps>(\n 'text',\n forwardRef(({ type = 'text', leftAddon, rightAddon, size, ...rest }, ref) => {\n const input = <Input type={type} size={size} {...rest} ref={ref} />\n if (leftAddon || rightAddon) {\n return (\n <InputGroup size={size}>\n {leftAddon}\n {input}\n {rightAddon}\n </InputGroup>\n )\n }\n return input\n })\n)\n\nexport interface NumberInputFieldProps extends NumberInputProps {\n type: 'number'\n}\n\nexport const NumberInputField = registerFieldType<NumberInputFieldProps>(\n 'number',\n NumberInput,\n {\n isControlled: true,\n }\n)\n\nexport const PasswordInputField = registerFieldType<PasswordInputProps>(\n 'password',\n forwardRef((props, ref) => <PasswordInput ref={ref} {...props} />)\n)\n\nexport const TextareaField = registerFieldType<TextareaProps>(\n 'textarea',\n Textarea\n)\n\nexport const SwitchField = registerFieldType<SwitchProps>(\n 'switch',\n forwardRef(({ type, ...rest }, ref) => {\n return <Switch {...rest} ref={ref} />\n }),\n {\n isControlled: true,\n }\n)\n\nexport const SelectField = registerFieldType<SelectProps>('select', Select, {\n isControlled: true,\n})\n\nexport const CheckboxField = registerFieldType<CheckboxProps>(\n 'checkbox',\n forwardRef(({ label, type, ...props }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\n\nexport const RadioField = registerFieldType<RadioInputProps>(\n 'radio',\n RadioInput,\n {\n isControlled: true,\n }\n)\n\nexport const NativeSelectField = registerFieldType<NativeSelectProps>(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n\nexport interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {\n pinLength?: number\n pinType?: 'alphanumeric' | 'number'\n spacing?: SystemProps['margin']\n}\n\nexport const PinField = registerFieldType<PinFieldProps>(\n 'pin',\n forwardRef((props, ref) => {\n const { pinLength = 4, pinType, spacing, ...inputProps } = props\n\n const inputs: React.ReactNode[] = []\n for (let i = 0; i < pinLength; i++) {\n inputs.push(<PinInputField key={i} ref={ref} />)\n }\n\n return (\n <HStack spacing={spacing}>\n <PinInput {...inputProps} type={pinType}>\n {inputs}\n </PinInput>\n </HStack>\n )\n }),\n {\n isControlled: true,\n }\n)\n\nconst fieldTypes = {\n text: InputField,\n email: InputField,\n url: InputField,\n phone: InputField,\n number: NumberInputField,\n password: PasswordInputField,\n textarea: TextareaField,\n switch: SwitchField,\n checkbox: CheckboxField,\n radio: RadioField,\n pin: PinField,\n select: SelectField,\n 'native-select': NativeSelectField,\n}\n\ntype FieldTypes = typeof fieldTypes\n\ntype FieldType<Props = any> = React.ElementType<Props>\n\ntype TypeProps<P extends FieldType, T> = React.ComponentPropsWithoutRef<P> & {\n type: T\n}\n\ntype FieldTypeProps =\n | {\n [Property in keyof FieldTypes]: TypeProps<FieldTypes[Property], Property>\n }[keyof FieldTypes]\n | { type?: string }\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, label, title, ...field }]) => {\n return {\n ...field,\n name,\n label: label || title, // json schema compatibility\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, MaybeFunction, runIfFn, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n ResolverOptions,\n ResolverResult,\n ChangeHandler,\n WatchObserver,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\nimport { MaybeRenderProp } from '@chakra-ui/react-utils'\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 * Triggers when any of the field change.\n */\n onChange?: WatchObserver<TFieldValues>\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.RefObject<HTMLFormElement>\n /**\n * The form children, can be a render prop or a ReactNode.\n */\n children?: MaybeRenderProp<UseFormReturn<TFieldValues>>\n}\n\n// @todo Figure out how to pass down FieldValues to all Field components, if at all possible.\n\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<\n HTMLChakraProps<'form'>,\n 'children' | 'onChange' | 'onSubmit' | 'onError'\n >,\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 onChange,\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 React.useEffect(() => {\n let subscription: any\n if (onChange) {\n subscription = methods.watch(onChange)\n }\n return () => subscription?.unsubscribe()\n }, [methods, onChange])\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 {runIfFn(children, methods)}\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: 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, forwardRef } 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, FormLayoutProps } 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 extends FormLayoutProps {\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 * The fields\n */\n children: React.ReactNode\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n ...rowFieldsProps\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields {...rowFieldsProps}>{children}</ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRow.displayName = 'ArrayFieldRow'\n}\n\nexport interface ArrayFieldRowFieldsProps extends FormLayoutProps {\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 fields\n */\n children: React.ReactNode\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout flex=\"1\" mr=\"2\" {...layoutProps}>\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 = 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) as ((\n props: ArrayFieldProps & {\n ref?: React.ForwardedRef<UseArrayFieldReturn>\n }\n) => React.ReactElement) & {\n displayName: string\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'\nimport { useFormContext } from 'react-hook-form'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n focusFirstField?: boolean\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 focusFirstField,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n const fields = React.useMemo(() => resolver.getFields(), [resolver])\n\n const form = useFormContext()\n\n React.useEffect(() => {\n if (focusFirstField && fields[0]?.name) {\n form.setFocus(fields[0].name)\n }\n }, [schema, fieldResolver, focusFirstField])\n\n return (\n <FormLayout {...props}>\n {fields.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 { __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 = React.forwardRef<\n HTMLButtonElement,\n SubmitButtonProps\n>((props, ref) => {\n const {\n children,\n disableIfUntouched,\n disableIfInvalid,\n isDisabled: isDisabledProp,\n isLoading,\n ...rest\n } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid) ||\n isDisabledProp\n\n return (\n <Button\n {...rest}\n ref={ref}\n variant=\"primary\"\n type=\"submit\"\n isLoading={formState.isSubmitting || isLoading}\n isDisabled={isDisabled}\n >\n {children}\n </Button>\n )\n})\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n\nif (__DEV__) {\n SubmitButton.displayName = 'SubmitButton'\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n /**\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, Zod, Yup or Ajv (JSON Schema).\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' | 'children'>,\n AutoFormOptions {\n children?: React.ReactNode\n}\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>{submitLabel}</SubmitButton>}\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<\n TFieldValues extends FieldValues = FieldValues\n> {\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, MaybeRenderProp } 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 onSubmit?: FormStepSubmitHandler\n}\n\nexport type FormStepSubmitHandler<\n TFieldValues extends FieldValues = FieldValues\n> = (data: TFieldValues, stepper: UseStepperReturn) => Promise<void>\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: MaybeRenderProp<UseStepFormReturn<TFieldValues>>\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 try {\n const step = steps[activeStep]\n\n if (isLastStep) {\n await props.onSubmit?.(data)\n\n updateStep({\n ...step,\n isCompleted: true,\n })\n\n nextStep() // show completed step\n return\n }\n\n await step.onSubmit?.(data, stepper)\n\n nextStep()\n } catch (e) {\n // Step submission failed.\n }\n },\n [steps, 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 onSubmit?: FormStepSubmitHandler\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver, onSubmit } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver, onSubmit })\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, ThemingProps } 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 StepperProps,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n FormStepSubmitHandler,\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: StepFormProps<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 interface FormStepperProps\n extends StepperStepsProps,\n ThemingProps<'Stepper'> {}\n\nexport const FormStepper: React.FC<FormStepperProps> = (props) => {\n const { activeIndex, setIndex } = useStepperContext()\n\n const { children, orientation, variant, colorScheme, size, ...rest } = props\n\n const elements = React.Children.map(children, (child) => {\n if (\n React.isValidElement<FormStepProps>(child) &&\n child?.type === FormStep\n ) {\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 {...rest}\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\n orientation={orientation}\n step={activeIndex}\n variant={variant}\n colorScheme={colorScheme}\n size={size}\n onChange={onChange}\n >\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StepperContainer>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n Omit<HTMLChakraProps<'div'>, 'onSubmit'> {\n onSubmit?: FormStepSubmitHandler\n}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, onSubmit, ...rest } =\n props\n const step = useFormStep({ name, schema, resolver, onSubmit })\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 {...rest}\n isDisabled={isCompleted}\n className={cx('saas-form__next-button', props.className)}\n >\n {isLastStep || isCompleted ? submitLabel : label}\n </SubmitButton>\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n","import {\n FieldValues,\n useFormContext,\n UseFormReturn,\n useWatch,\n} from 'react-hook-form'\n\nexport interface WatchFieldProps<\n Value = unknown,\n TFieldValues extends FieldValues = FieldValues\n> {\n name: string\n defaultValue?: Value\n isDisabled?: boolean\n isExact?: boolean\n children: (\n value: Value,\n form: UseFormReturn<TFieldValues>\n ) => React.ReactElement | void\n}\n\nexport const WatchField = <\n Value = unknown,\n TFieldValues extends FieldValues = FieldValues\n>(\n props: WatchFieldProps<Value, TFieldValues>\n) => {\n const { name, defaultValue, isDisabled, isExact } = props\n const form = useFormContext<TFieldValues>()\n\n const field = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n\n return props.children(field, form) || null\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","_excluded10","inputTypes","BaseField","help","hideLabel","children","controlProps","formState","get","errors","getError","_extends","isInvalid","error","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","_props$type","type","defaultInputType","withControlledInput","InputComponent","_ref3","rules","inputProps","_objectWithoutPropertiesLoose","Controller","control","render","_ref4","_ref4$field","field","onChange","callAllHandlers","onBlur","useMergeRefs","_ref5","register","_register","registerFieldType","component","options","id","isDisabled","isReadOnly","isRequired","inputRules","required","undefined","createField","isControlled","withUncontrolledInput","split","map","part","charAt","toUpperCase","slice","join","_ref6$type","leftAddon","_ref6","rightAddon","size","rest","input","Input","InputGroup","NumberInputField","NumberInput","PasswordInputField","PasswordInput","TextareaField","Textarea","SwitchField","_ref7","Switch","SelectField","Select","CheckboxField","_ref8","Checkbox","RadioInput","NativeSelectField","NativeSelect","PinField","pinLength","_props$pinLength","pinType","spacing","inputs","i","push","PinInputField","key","HStack","PinInput","schema","Object","entries","title","_ref$","objectFieldResolver","getFields","getNestedFields","_field$items","items","mapFields","properties","Form","mode","_props$mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","useEffect","subscription","watch","_subscription","unsubscribe","FormProvider","chakra","className","cx","runIfFn","getFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","gridProps","theme","useTheme","components","defaultProps","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","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","_useArrayFieldRowCont","_useArrayFieldContext2","onClick","append","_useArrayFieldContext3","shouldFocus","ArrayFieldRow","rowFieldsProps","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","mr","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","useArrayFieldAddButton","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","Fragment","fieldProps","FormLegend","styles","useStyleConfig","as","sx","columns","gridGap","ObjectField","_resolver$getNestedFi","nestedFieldProps","Fields","fieldResolver","focusFirstField","useMemo","_fields$","setFocus","SubmitButton","disableIfUntouched","disableIfInvalid","isDisabledProp","isLoading","Button","variant","isSubmitting","isDirty","isValid","AutoForm","submitLabel","_props$submitLabel","DisplayIf","condition","_ref$condition","useWatch","disabled","exact","isExact","errorMessage","StepFormProvider","useStepFormContext","useStepForm","stepper","useStepper","activeStep","isLastStep","nextStep","_React$useState","useState","steps","updateSteps","onSubmitStep","data","step","_temp","then","updateStep","isCompleted","_exit","_temp2","getFormProps","_extends2","useStep","StepForm","ctx","StepperProvider","FormStep","useFormStep","isActive","PrevButton","useStepperContext","prevStep","isFirstStep","_useStepperContext2","NextButton","_props$label","_useStepperContext3","activeIndex","setIndex","_useStepperContext","orientation","colorScheme","elements","StepperStep","_useFormStep","StepperContainer","StepperSteps"],"mappings":"okCAAA,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,KAIxB,EAEGW,EAAAA,UACFb,EAAac,YAAc,gBAGhBF,MAAwC,SAAAG,GAAGb,IAAAA,EAAAA,EAAAA,KAEtD,OAAOc,EADeC,EAAcA,iBAA5BD,WACSd,IAAS,IAC3B,EAEGW,EAAAA,UACFD,EAAUE,YAAc,aC3C1B,IAAAf,EAAA,CAAA,OAAA,QAAA,OAAA,YAAA,YAAAmB,EAAA,CAAA,KAAA,OAAA,QAAA,OAAA,aAAA,YAAA,aAAA,aAAA,SAAAC,EAAA,CAAA,OAAA,SAAAC,EAAA,CAAA,OAAAC,EAAA,CAAA,OAAA,SAAAC,EAAA,CAAA,OAAAC,EAAA,CAAA,OAAA,YAAA,aAAA,QAAAC,EAAA,CAAA,QAAAC,EAAA,CAAA,QAAA,QAAAC,EAAA,CAAA,YAAA,UAAA,WA4GMC,E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nS,EAAuE3B,EAA/D2B,SAAUqS,EAAqDhU,EAArDgU,YAAaxD,EAAwCxQ,EAAxCwQ,QAASyD,EAA+BjU,EAA/BiU,YAAaxO,EAAkBzF,EAAlByF,KAASC,EAA9DvC,EAAuEnD,EAAvEe,IAEcmT,EAAGjU,EAAMiL,SAASnG,IAAIpD,EAAU,SAACwJ,GAC7C,GACElL,EAAMmL,eAA8BD,KAC/B,MAALA,SAAAA,EAAOvI,QAASsQ,GAChB,CACA,IAAwBC,EAAAA,GAAYhI,EAAMnL,oBAC1C,OACEC,EAACC,cAAAiU,EAAAA,YACClS,EAAA,CAAAnC,KAAMqL,EAAMnL,MAAMF,KAClBgI,MAAOqD,EAAMnL,MAAM8H,MACnB2K,YALJ2B,EAAQ3B,aAMA/M,GAEHyF,EAAMnL,MAAM2B,SAGlB,CACD,OAAOwJ,CACR,GAEKzH,EAAWzD,EAAM6M,YAAY,SAACzF,GAClCyM,EAASzM,EACV,EAAE,iBAEH,OACEpH,EAAAC,cAACmU,EAAAA,iBAAD,CACEL,YAAaA,EACb3B,KAAMwB,EACNrD,QAASA,EACTyD,YAAaA,EACbxO,KAAMA,EACN/B,SAAUA,gBAEVzD,EAAAC,cAACoU,EAAAA,aAADrS,EAAA,CAAcmM,GAAG,KAAQpO,GACtBkU,GAIR,yYCvGyB,SAIxBlU,GAEA,IAAAF,EAAoDE,EAA5CF,KAAMiM,EAAsC/L,EAAtC+L,aAAc1H,EAAwBrE,EAAxBqE,WAAYgN,EAAYrR,EAAZqR,UAC3BxQ,EAAcA,iBAEhB4C,EAAGyN,WAAS,CACrBpR,KAAAA,EACAiM,aAAAA,EACAoF,SAAU9M,EACV+M,MAAOC,IAGT,OAAYrR,EAAC2B,SAAS8B,EAAO4F,IAAS,IACvC"}
|
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","../src/watch-field.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 InputGroup,\n InputProps,\n TextareaProps,\n SwitchProps,\n CheckboxProps,\n PinInputField,\n HStack,\n PinInput,\n UsePinInputProps,\n SystemProps,\n} from '@chakra-ui/react'\nimport { __DEV__, FocusableElement, callAllHandlers } from '@chakra-ui/utils'\n\nimport { NumberInput, NumberInputProps } from '@saas-ui/number-input'\nimport { PasswordInput, PasswordInputProps } from '@saas-ui/password-input'\nimport { RadioInput, RadioInputProps } from '@saas-ui/radio'\n\nimport {\n Select,\n SelectProps,\n NativeSelect,\n NativeSelectProps,\n} from '@saas-ui/select'\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 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 * 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 */\n type?: string\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<string, React.FC<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, hideLabel, children, ...controlProps } = props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? <FormLabel>{label}</FormLabel> : 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 type As<Props = any> = React.ElementType<Props>\n\nexport type PropsOf<T extends As> = React.ComponentPropsWithoutRef<T> & {\n type?: FieldTypes\n}\n\n/**\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 */\nexport const Field = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> | FieldTypeProps,\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 FieldTypeProps & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement) & {\n displayName?: string\n}\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((props, ref) => {\n const {\n id,\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\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 >\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: React.FC<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 onChange={callAllHandlers(inputProps.onChange, field.onChange)}\n onBlur={callAllHandlers(inputProps.onBlur, field.onBlur)}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: React.FC<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 onChange={callAllHandlers(inputProps.onChange, field.onChange)}\n onBlur={callAllHandlers(inputProps.onBlur, field.onBlur)}\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 = <T extends object>(\n type: string,\n component: React.FC<T>,\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 }) as React.FC<T & FieldProps>\n\n inputTypes[type] = Field\n\n return Field\n}\n\nexport interface InputFieldProps extends InputProps {\n type?: string\n leftAddon?: React.ReactNode\n rightAddon?: React.ReactNode\n}\n\nexport const InputField = registerFieldType<InputFieldProps>(\n 'text',\n forwardRef(({ type = 'text', leftAddon, rightAddon, size, ...rest }, ref) => {\n const input = <Input type={type} size={size} {...rest} ref={ref} />\n if (leftAddon || rightAddon) {\n return (\n <InputGroup size={size}>\n {leftAddon}\n {input}\n {rightAddon}\n </InputGroup>\n )\n }\n return input\n })\n)\n\nexport interface NumberInputFieldProps extends NumberInputProps {\n type: 'number'\n}\n\nexport const NumberInputField = registerFieldType<NumberInputFieldProps>(\n 'number',\n NumberInput,\n {\n isControlled: true,\n }\n)\n\nexport const PasswordInputField = registerFieldType<PasswordInputProps>(\n 'password',\n forwardRef((props, ref) => <PasswordInput ref={ref} {...props} />)\n)\n\nexport const TextareaField = registerFieldType<TextareaProps>(\n 'textarea',\n Textarea\n)\n\nexport const SwitchField = registerFieldType<SwitchProps>(\n 'switch',\n forwardRef(({ type, value, ...rest }, ref) => {\n return <Switch isChecked={!!value} {...rest} ref={ref} />\n }),\n {\n isControlled: true,\n }\n)\n\nexport const SelectField = registerFieldType<SelectProps>('select', Select, {\n isControlled: true,\n})\n\nexport const CheckboxField = registerFieldType<CheckboxProps>(\n 'checkbox',\n forwardRef(({ label, type, ...props }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\n\nexport const RadioField = registerFieldType<RadioInputProps>(\n 'radio',\n RadioInput,\n {\n isControlled: true,\n }\n)\n\nexport const NativeSelectField = registerFieldType<NativeSelectProps>(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n\nexport interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {\n pinLength?: number\n pinType?: 'alphanumeric' | 'number'\n spacing?: SystemProps['margin']\n}\n\nexport const PinField = registerFieldType<PinFieldProps>(\n 'pin',\n forwardRef((props, ref) => {\n const { pinLength = 4, pinType, spacing, ...inputProps } = props\n\n const inputs: React.ReactNode[] = []\n for (let i = 0; i < pinLength; i++) {\n inputs.push(<PinInputField key={i} ref={ref} />)\n }\n\n return (\n <HStack spacing={spacing}>\n <PinInput {...inputProps} type={pinType}>\n {inputs}\n </PinInput>\n </HStack>\n )\n }),\n {\n isControlled: true,\n }\n)\n\nconst fieldTypes = {\n text: InputField,\n email: InputField,\n url: InputField,\n phone: InputField,\n number: NumberInputField,\n password: PasswordInputField,\n textarea: TextareaField,\n switch: SwitchField,\n checkbox: CheckboxField,\n radio: RadioField,\n pin: PinField,\n select: SelectField,\n 'native-select': NativeSelectField,\n}\n\ntype FieldTypes = typeof fieldTypes\n\ntype FieldType<Props = any> = React.ElementType<Props>\n\ntype TypeProps<P extends FieldType, T> = React.ComponentPropsWithoutRef<P> & {\n type: T\n}\n\ntype FieldTypeProps =\n | {\n [Property in keyof FieldTypes]: TypeProps<FieldTypes[Property], Property>\n }[keyof FieldTypes]\n | { type?: string }\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, label, title, ...field }]) => {\n return {\n ...field,\n name,\n label: label || title, // json schema compatibility\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, MaybeFunction, runIfFn, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n ResolverOptions,\n ResolverResult,\n ChangeHandler,\n WatchObserver,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\nimport { MaybeRenderProp } from '@chakra-ui/react-utils'\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 * Triggers when any of the field change.\n */\n onChange?: WatchObserver<TFieldValues>\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.RefObject<HTMLFormElement>\n /**\n * The form children, can be a render prop or a ReactNode.\n */\n children?: MaybeRenderProp<UseFormReturn<TFieldValues>>\n}\n\n// @todo Figure out how to pass down FieldValues to all Field components, if at all possible.\n\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<\n HTMLChakraProps<'form'>,\n 'children' | 'onChange' | 'onSubmit' | 'onError'\n >,\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 onChange,\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 React.useEffect(() => {\n let subscription: any\n if (onChange) {\n subscription = methods.watch(onChange)\n }\n return () => subscription?.unsubscribe()\n }, [methods, onChange])\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 {runIfFn(children, methods)}\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: 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, forwardRef } 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, FormLayoutProps } 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 extends FormLayoutProps {\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 * The fields\n */\n children: React.ReactNode\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n ...rowFieldsProps\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields {...rowFieldsProps}>{children}</ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRow.displayName = 'ArrayFieldRow'\n}\n\nexport interface ArrayFieldRowFieldsProps extends FormLayoutProps {\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 fields\n */\n children: React.ReactNode\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout flex=\"1\" mr=\"2\" {...layoutProps}>\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 = 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) as ((\n props: ArrayFieldProps & {\n ref?: React.ForwardedRef<UseArrayFieldReturn>\n }\n) => React.ReactElement) & {\n displayName: string\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'\nimport { useFormContext } from 'react-hook-form'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n focusFirstField?: boolean\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 focusFirstField,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n const fields = React.useMemo(() => resolver.getFields(), [resolver])\n\n const form = useFormContext()\n\n React.useEffect(() => {\n if (focusFirstField && fields[0]?.name) {\n form.setFocus(fields[0].name)\n }\n }, [schema, fieldResolver, focusFirstField])\n\n return (\n <FormLayout {...props}>\n {fields.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 { __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 = React.forwardRef<\n HTMLButtonElement,\n SubmitButtonProps\n>((props, ref) => {\n const {\n children,\n disableIfUntouched,\n disableIfInvalid,\n isDisabled: isDisabledProp,\n isLoading,\n ...rest\n } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid) ||\n isDisabledProp\n\n return (\n <Button\n {...rest}\n ref={ref}\n variant=\"primary\"\n type=\"submit\"\n isLoading={formState.isSubmitting || isLoading}\n isDisabled={isDisabled}\n >\n {children}\n </Button>\n )\n})\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n\nif (__DEV__) {\n SubmitButton.displayName = 'SubmitButton'\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n /**\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, Zod, Yup or Ajv (JSON Schema).\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' | 'children'>,\n AutoFormOptions {\n children?: React.ReactNode\n}\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>{submitLabel}</SubmitButton>}\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<\n TFieldValues extends FieldValues = FieldValues\n> {\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, MaybeRenderProp } 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 onSubmit?: FormStepSubmitHandler\n}\n\nexport type FormStepSubmitHandler<\n TFieldValues extends FieldValues = FieldValues\n> = (data: TFieldValues, stepper: UseStepperReturn) => Promise<void>\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: MaybeRenderProp<UseStepFormReturn<TFieldValues>>\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 try {\n const step = steps[activeStep]\n\n if (isLastStep) {\n await props.onSubmit?.(data)\n\n updateStep({\n ...step,\n isCompleted: true,\n })\n\n nextStep() // show completed step\n return\n }\n\n await step.onSubmit?.(data, stepper)\n\n nextStep()\n } catch (e) {\n // Step submission failed.\n }\n },\n [steps, 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 onSubmit?: FormStepSubmitHandler\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver, onSubmit } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver, onSubmit })\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, ThemingProps } 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 StepperProps,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n FormStepSubmitHandler,\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: StepFormProps<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 interface FormStepperProps\n extends StepperStepsProps,\n ThemingProps<'Stepper'> {}\n\nexport const FormStepper: React.FC<FormStepperProps> = (props) => {\n const { activeIndex, setIndex } = useStepperContext()\n\n const { children, orientation, variant, colorScheme, size, ...rest } = props\n\n const elements = React.Children.map(children, (child) => {\n if (\n React.isValidElement<FormStepProps>(child) &&\n child?.type === FormStep\n ) {\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 {...rest}\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\n orientation={orientation}\n step={activeIndex}\n variant={variant}\n colorScheme={colorScheme}\n size={size}\n onChange={onChange}\n >\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StepperContainer>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n Omit<HTMLChakraProps<'div'>, 'onSubmit'> {\n onSubmit?: FormStepSubmitHandler\n}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, onSubmit, ...rest } =\n props\n const step = useFormStep({ name, schema, resolver, onSubmit })\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 {...rest}\n isDisabled={isCompleted}\n className={cx('saas-form__next-button', props.className)}\n >\n {isLastStep || isCompleted ? submitLabel : label}\n </SubmitButton>\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n","import {\n FieldValues,\n useFormContext,\n UseFormReturn,\n useWatch,\n} from 'react-hook-form'\n\nexport interface WatchFieldProps<\n Value = unknown,\n TFieldValues extends FieldValues = FieldValues\n> {\n name: string\n defaultValue?: Value\n isDisabled?: boolean\n isExact?: boolean\n children: (\n value: Value,\n form: UseFormReturn<TFieldValues>\n ) => React.ReactElement | void\n}\n\nexport const WatchField = <\n Value = unknown,\n TFieldValues extends FieldValues = FieldValues\n>(\n props: WatchFieldProps<Value, TFieldValues>\n) => {\n const { name, defaultValue, isDisabled, isExact } = props\n const form = useFormContext<TFieldValues>()\n\n const field = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n\n return props.children(field, form) || null\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","_excluded10","inputTypes","BaseField","help","hideLabel","children","controlProps","formState","errors","getError","_extends","isInvalid","error","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","_props$type","type","withControlledInput","InputComponent","rules","_ref3","inputProps","_objectWithoutPropertiesLoose","_useFormContext2","Controller","control","render","_ref4","_ref4$field","field","onChange","callAllHandlers","onBlur","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","_ref6$type","leftAddon","rightAddon","size","rest","input","Input","InputGroup","NumberInput","PasswordInputField","PasswordInput","TextareaField","Textarea","SwitchField","_ref7","value","Switch","isChecked","SelectField","Select","_ref8","Checkbox","RadioField","RadioInput","NativeSelectField","NativeSelect","PinField","pinLength","_props$pinLength","pinType","spacing","inputs","i","push","PinInputField","key","HStack","PinInput","schema","Object","entries","title","_ref$","objectFieldResolver","getFields","mapFields","getNestedFields","get","items","_field$items","properties","Form","mode","_props$mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","useEffect","subscription","watch","_subscription","unsubscribe","FormProvider","chakra","className","cx","runIfFn","getFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","gridProps","theme","useTheme","components","defaultProps","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","_createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","_ref$defaultValue","defaultValue","keyName","min","max","_useFormContext","useFieldArray","useArrayFieldRow","index","clearErrors","remove","_useArrayFieldContext","fields","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","_useArrayFieldRowCont","_useArrayFieldContext2","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","rowFieldsProps","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","mr","context","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","Fragment","fieldProps","FormLegend","styles","useStyleConfig","as","sx","columns","gridGap","ObjectField","_resolver$getNestedFi","nestedFieldProps","Fields","fieldResolver","focusFirstField","useMemo","_fields$","setFocus","SubmitButton","disableIfUntouched","disableIfInvalid","isDisabledProp","isLoading","Button","variant","isSubmitting","isDirty","isValid","AutoForm","submitLabel","_props$submitLabel","DisplayIf","condition","_ref$condition","useWatch","disabled","exact","isExact","errorMessage","StepFormProvider","useStepFormContext","useStepForm","stepper","useStepper","activeStep","isLastStep","nextStep","_React$useState","useState","steps","updateSteps","onSubmitStep","data","_exit","Promise","resolve","step","updateStep","isCompleted","_temp","then","_temp2","_catch","getFormProps","_extends2","useStep","_useStepFormContext","StepForm","ctx","StepperProvider","FormStep","useFormStep","isActive","PrevButton","useStepperContext","prevStep","isFirstStep","_useStepperContext2","NextButton","_props$label","_useStepperContext3","activeIndex","setIndex","_useStepperContext","orientation","colorScheme","elements","StepperStep","_useFormStep","StepperContainer","StepperSteps"],"mappings":"okCAAA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MACnB4K,YALe8B,EAAX9B,aAMAjN,GAEH2F,EAAMrL,MAAM2B,SAGlB,CACD,OAAO0J,CACT,GAEM5H,EAAWxD,EAAM+M,YAAY,SAAC1F,GAClC6M,EAAS7M,EACX,EAAG,iBAEH,OACErH,EAAAC,cAACwU,EAAAA,iBAAgB,CACfL,YAAaA,EACb5B,KAAMyB,EACNzD,QAASA,EACT6D,YAAaA,EACb7O,KAAMA,EACNhC,SAAUA,gBAEVxD,EAAAC,cAACyU,EAAAA,aAAY3S,EAAA,CAACsM,GAAG,KAAQtO,GACtBuU,GAIT,yYCvG0B,SAIxBvU,GAEA,IAAYF,EAAwCE,EAA5CF,KAAMmM,EAAsCjM,EAAtCiM,aAAc5H,EAAwBrE,EAAxBqE,WAAYiN,EAAYtR,EAAZsR,QAClC/H,EAAO1I,EAAcA,mBAEbsQ,WAAS,CACrBrR,KAAAA,EACAmM,aAAAA,EACAmF,SAAU/M,EACVgN,MAAOC,IAGT,OAAOtR,EAAM2B,SAAS6B,EAAO+F,IAAS,IACxC"}
|
package/dist/index.modern.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
import*as e from"react";import{__DEV__ as t,callAllHandlers as l,get as a,cx as r,runIfFn as n}from"@chakra-ui/utils";import{useFormContext as s,Controller as i,get as o,useForm as m,FormProvider as c,useFieldArray as d,useWatch as u}from"react-hook-form";export{Controller,FormProvider,appendErrors,useController,useFieldArray,useForm,useFormContext,useFormState,useWatch}from"react-hook-form";import{FormControl as p,FormLabel as f,Text as h,forwardRef as b,Input as y,InputGroup as E,Switch as v,Checkbox as g,HStack as F,PinInput as N,Box as C,FormHelperText as x,FormErrorMessage as S,useMergeRefs as k,Textarea as R,PinInputField as V,chakra as L,useTheme as w,SimpleGrid as A,useStyleConfig as I}from"@chakra-ui/react";import{NumberInput as B}from"@saas-ui/number-input";import{PasswordInput as D}from"@saas-ui/password-input";import{RadioInput as O}from"@saas-ui/radio";import{Select as j,NativeSelect as M}from"@saas-ui/select";import{forwardRef as U,chakra as _}from"@chakra-ui/system";import{MinusIcon as z,AddIcon as P}from"@chakra-ui/icons";import{IconButton as $,Button as q}from"@saas-ui/button";import{createContext as H}from"@chakra-ui/react-utils";import{useStepper as T,useStep as G,StepperProvider as W,useStepperContext as J,StepperStep as K,StepperContainer as Q,StepperSteps as X}from"@saas-ui/stepper";export*from"@saas-ui/input-right-button";function Y(){return Y=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var l=arguments[t];for(var a in l)Object.prototype.hasOwnProperty.call(l,a)&&(e[a]=l[a])}return e},Y.apply(this,arguments)}function Z(e,t){if(null==e)return{};var l,a,r={},n=Object.keys(e);for(a=0;a<n.length;a++)t.indexOf(l=n[a])>=0||(r[l]=e[l]);return r}const ee=["name","label","placeholder"],te=t=>{let{name:l,label:a}=t,r=Z(t,ee);/*#__PURE__*/return e.createElement(p,r,a?/*#__PURE__*/e.createElement(f,{htmlFor:l},a):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(le,{name:l})))};t&&(te.displayName="DisplayField");const le=({name:e})=>{const{getValues:t}=s();return t(e)||null};t&&(le.displayName="FormValue");const ae=["name","label","help","hideLabel","children"],re=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules"],ne=["name","rules"],se=["ref"],ie=["name","rules"],oe=["ref"],me=["type","leftAddon","rightAddon","size"],ce=["type"],de=["label","type"],ue=["pinLength","pinType","spacing"],pe={},fe="text",he=t=>{const{name:l,label:a,help:r,hideLabel:n,children:i}=t,m=Z(t,ae),{formState:c}=s(),d=((e,t)=>o(t.errors,e))(l,c);/*#__PURE__*/return e.createElement(p,Y({},m,{isInvalid:!!d}),a&&!n?/*#__PURE__*/e.createElement(f,null,a):null,/*#__PURE__*/e.createElement(C,null,i,!r||null!=d&&d.message?null:/*#__PURE__*/e.createElement(x,null,r),(null==d?void 0:d.message)&&/*#__PURE__*/e.createElement(S,null,null==d?void 0:d.message)))};t&&(he.displayName="BaseField");const be=e.forwardRef((t,l)=>{const{type:a=fe}=t,r=(e=>pe[e]||pe[fe])(a);/*#__PURE__*/return e.createElement(r,Y({ref:l},t))}),ye=t=>b((a,r)=>{let{name:n,rules:o}=a,m=Z(a,ne);const{control:c}=s();/*#__PURE__*/return e.createElement(i,{name:n,control:c,rules:o,render:a=>{let{field:{ref:n}}=a,s=Z(a.field,se);/*#__PURE__*/return e.createElement(t,Y({},s,m,{onChange:l(m.onChange,s.onChange),onBlur:l(m.onBlur,s.onBlur),ref:k(r,n)}))}})}),Ee=t=>b((a,r)=>{let{name:n,rules:i}=a,o=Z(a,ie);const{register:m}=s(),c=m(n,i),{ref:d}=c,u=Z(c,oe);/*#__PURE__*/return e.createElement(t,Y({},u,o,{onChange:l(o.onChange,u.onChange),onBlur:l(o.onBlur,u.onBlur),ref:k(r,d)}))}),ve=(t,l,a)=>{let r;r=null!=a&&a.isControlled?ye(l):Ee(l);const n=((t,{displayName:l,hideLabel:a,BaseField:r})=>{const n=b((l,n)=>{const{id:s,name:i,label:o,help:m,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,rules:f}=l,h=Z(l,re),b=Y({required:p},f);/*#__PURE__*/return e.createElement(r,{id:s,name:i,label:o,help:m,hideLabel:a,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p},/*#__PURE__*/e.createElement(t,Y({ref:n,id:s,name:i,label:a?o:void 0,rules:b},h)))});return n.displayName=l,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==a?void 0:a.hideLabel,BaseField:(null==a?void 0:a.BaseField)||he});return pe[t]=n,n},ge=ve("text",b((t,l)=>{let{type:a="text",leftAddon:r,rightAddon:n,size:s}=t,i=Z(t,me);const o=/*#__PURE__*/e.createElement(y,Y({type:a,size:s},i,{ref:l}));return r||n?/*#__PURE__*/e.createElement(E,{size:s},r,o,n):o})),Fe=ve("number",B,{isControlled:!0}),Ne=ve("password",b((t,l)=>/*#__PURE__*/e.createElement(D,Y({ref:l},t)))),Ce=ve("textarea",R),xe=ve("switch",b((t,l)=>{let a=Z(t,ce);/*#__PURE__*/return e.createElement(v,Y({},a,{ref:l}))}),{isControlled:!0}),Se=ve("select",j,{isControlled:!0}),ke=ve("checkbox",b((t,l)=>{let{label:a}=t,r=Z(t,de);/*#__PURE__*/return e.createElement(g,Y({ref:l},r),a)}),{hideLabel:!0}),Re=ve("radio",O,{isControlled:!0}),Ve=ve("native-select",M,{isControlled:!0}),Le=ve("pin",b((t,l)=>{const{pinLength:a=4,pinType:r,spacing:n}=t,s=Z(t,ue),i=[];for(let t=0;t<a;t++)i.push(/*#__PURE__*/e.createElement(V,{key:t,ref:l}));/*#__PURE__*/return e.createElement(F,{spacing:n},/*#__PURE__*/e.createElement(N,Y({},s,{type:r}),i))}),{isControlled:!0}),we=["items","label","title"],Ae=e=>e&&Object.entries(e).map(([e,t])=>{let{label:l,title:a}=t;return Y({},Z(t,we),{name:e,label:l||a})}),Ie=e=>({getFields:()=>Ae(e),getNestedFields:t=>{var l;const r=a(e,t);return r?"object"===(null==(l=r.items)?void 0:l.type)?Ae(r.items.properties):"object"===r.type?Ae(r.properties):[r.items]:[]}}),Be=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onChange","onSubmit","onError","formRef","children"],De=b((t,l)=>{const{mode:a="all",resolver:s,reValidateMode:i,shouldFocusError:o,shouldUnregister:d,shouldUseNativeValidation:u,criteriaMode:p,delayError:f,schema:h,defaultValues:b,onChange:y,onSubmit:E,onError:v,formRef:g,children:F}=t,N=Z(t,Be),C={mode:a,resolver:s,defaultValues:b,reValidateMode:i,shouldFocusError:o,shouldUnregister:d,shouldUseNativeValidation:u,criteriaMode:p,delayError:f};h&&!s&&(C.resolver=null==De.getResolver?void 0:De.getResolver(h));const x=m(C),{handleSubmit:S}=x;return e.useImperativeHandle(l,()=>x,[l,x]),e.useEffect(()=>{let e;return y&&(e=x.watch(y)),()=>{var t;return null==(t=e)?void 0:t.unsubscribe()}},[x,y]),/*#__PURE__*/e.createElement(c,x,/*#__PURE__*/e.createElement(L.form,Y({ref:g,onSubmit:S(E,v)},N,{className:r("saas-form",t.className)}),n(F,x)))});De.getFieldResolver=Ie,t&&(De.displayName="Form");const Oe=["children"],je=({children:t})=>/*#__PURE__*/e.createElement(L.div,null,t);t&&(je.displayName="FormLayoutItem");const Me=t=>{var l,a,n;let{children:s}=t,i=Z(t,Oe);const o=Y({},null!=(l=null==(a=w().components)||null==(n=a.FormLayout)?void 0:n.defaultProps)?l:{spacing:4},i);/*#__PURE__*/return e.createElement(A,Y({},o,{className:r("saas-form__layout",i.className)}),e.Children.map(s,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(je,null,t):t))};t&&(Me.displayName="FormLayout");const Ue=(t,l)=>e.Children.map(l,l=>e.isValidElement(l)&&l.props.name?e.cloneElement(l,Y({},l.props,{name:`${t}.${l.props.name}`})):l),[_e,ze]=H({name:"ArrayFieldContext"}),[Pe,$e]=H({name:"ArrayFieldRowContext"}),qe=({name:e,defaultValue:t={},keyName:l,min:a,max:r})=>{const{control:n}=s();return Y({},d({control:n,name:e,keyName:l}),{name:e,defaultValue:t,min:a,max:r})},He=({index:t})=>{const{clearErrors:l}=s(),{name:a,remove:r,fields:n}=ze();return e.useEffect(()=>{l(a)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${a}.${t}`,remove:e.useCallback(()=>{l(a),r(t)},[t])}},Te=()=>{const{isFirst:e,remove:t}=$e(),{min:l,fields:a}=ze();return{onClick:()=>t(),isDisabled:e&&!!(l&&a.length<=l)}},Ge=()=>{const{append:e,defaultValue:t,max:l,fields:a}=ze();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(l&&a.length>=l)}},We=["children","index"],Je=["children"],Ke=["children"],Qe=["name","defaultValue","keyName","min","max","children"],Xe=t=>{let{children:l,index:a}=t,r=Z(t,We);/*#__PURE__*/return e.createElement(Ze,{index:a},/*#__PURE__*/e.createElement(Ye,r,l),/*#__PURE__*/e.createElement(et,null))};t&&(Xe.displayName="ArrayFieldRow");const Ye=t=>{let{children:l}=t,a=Z(t,Je);const{name:r}=$e();/*#__PURE__*/return e.createElement(Me,Y({flex:"1",mr:"2"},a),Ue(r,l))};t&&(Ye.displayName="ArrayFieldRowFields");const Ze=({children:t,index:l})=>{const a=He({index:l});/*#__PURE__*/return e.createElement(Pe,{value:a},/*#__PURE__*/e.createElement(_.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))};t&&(Ze.displayName="ArrayFieldRowContainer");const et=t=>/*#__PURE__*/e.createElement($,Y({icon:/*#__PURE__*/e.createElement(z,null),"aria-label":"Remove row"},Te(),t));t&&(et.displayName="ArrayFieldRemoveButton");const tt=t=>/*#__PURE__*/e.createElement($,Y({icon:/*#__PURE__*/e.createElement(P,null),"aria-label":"Add row",float:"right"},Ge(),t));t&&(tt.displayName="ArrayFieldAddButton");const lt=U((t,l)=>{const{children:a}=t,r=Z(t,Ke);/*#__PURE__*/return e.createElement(rt,Y({ref:l},r),/*#__PURE__*/e.createElement(at,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},l)=>/*#__PURE__*/e.createElement(Xe,{key:t,index:l},a)))),/*#__PURE__*/e.createElement(tt,null))});t&&(lt.displayName="ArrayField");const at=({children:e})=>{const{fields:t}=ze();return e(t)};t&&(at.displayName="ArrayFieldRows");const rt=e.forwardRef((t,l)=>{let{name:a,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=Z(t,Qe);const c=qe({name:a,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(l,()=>c,[l,c]),/*#__PURE__*/e.createElement(_e,{value:c},/*#__PURE__*/e.createElement(he,Y({name:a},m),o))});t&&(rt.displayName="ArrayFieldContainer");const nt=["name","label","hideLabel","children","columns","spacing"],st=t=>{const l=I("FormLegend");/*#__PURE__*/return e.createElement(f,Y({as:"legend",sx:l},t))},it=t=>{const{name:l,label:a,hideLabel:r,children:n,columns:s,spacing:i}=t,o=Z(t,nt);/*#__PURE__*/return e.createElement(p,Y({name:l,as:"fieldset"},o),/*#__PURE__*/e.createElement(st,{display:r?"none":"block"},a),/*#__PURE__*/e.createElement(Me,{columns:s,gridGap:i},Ue(l,n)))};t&&(it.displayName="ObjectField");const ot=["name","type"],mt=["schema","fieldResolver","focusFirstField"],ct=["name","type","defaultValue"],dt=(t,l)=>{var a;return null==(a=t.getNestedFields(l))?void 0:a.map((t,l)=>{let{name:a,type:r}=t,n=Z(t,ot);/*#__PURE__*/return e.createElement(be,Y({key:a||l,name:a,type:r},n))})},ut=t=>{let{schema:l,fieldResolver:a,focusFirstField:r}=t,n=Z(t,mt);const i=e.useMemo(()=>a||De.getFieldResolver(l),[l,a]),o=e.useMemo(()=>i.getFields(),[i]),m=s();return e.useEffect(()=>{var e;r&&null!=(e=o[0])&&e.name&&m.setFocus(o[0].name)},[l,a,r]),/*#__PURE__*/e.createElement(Me,n,o.map(t=>{let{name:l,type:a}=t,r=Z(t,ct);return"array"===a?/*#__PURE__*/e.createElement(lt,Y({key:l,name:l},r),dt(i,l)):"object"===a?/*#__PURE__*/e.createElement(it,Y({key:l,name:l},r),dt(i,l)):/*#__PURE__*/e.createElement(be,Y({key:l,name:l,type:a},r))}))};t&&(ut.displayName="Fields");const pt=["children","disableIfUntouched","disableIfInvalid","isDisabled","isLoading"],ft=e.forwardRef((t,l)=>{const{children:a,disableIfUntouched:r,disableIfInvalid:n,isDisabled:i,isLoading:o}=t,m=Z(t,pt),{formState:c}=s();/*#__PURE__*/return e.createElement(q,Y({},m,{ref:l,variant:"primary",type:"submit",isLoading:c.isSubmitting||o,isDisabled:r&&!c.isDirty||n&&!c.isValid||i}),a)});ft.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(ft.displayName="SubmitButton");const ht=["schema","submitLabel","fieldResolver","children"],bt=b((t,l)=>{const{schema:a,submitLabel:r="Submit",fieldResolver:n,children:s}=t,i=Z(t,ht);/*#__PURE__*/return e.createElement(De,Y({},i,{schema:a,ref:l}),/*#__PURE__*/e.createElement(Me,null,/*#__PURE__*/e.createElement(ut,{schema:a,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(ft,null,r),s))});t&&(bt.displayName="AutoForm");const yt=({children:e,name:t,defaultValue:l,isDisabled:a,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:l,disabled:a,exact:r}),s())?e:null;t&&(yt.displayName="DisplayIf");const Et=["onChange"],[vt,gt]=H({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function Ft(t){const l=Z(t,Et),a=T(l),{activeStep:r,isLastStep:n,nextStep:s}=a,[i,o]=e.useState({}),m=e.useCallback(async e=>{try{const l=i[r];if(n)return await(null==t.onSubmit?void 0:t.onSubmit(e)),d(Y({},l,{isCompleted:!0})),void s();await(null==l.onSubmit?void 0:l.onSubmit(e,a)),s()}catch(e){}},[i,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=>Y({},t,{[e.name]:e}))},[i]);return Y({getFormProps:c,updateStep:d,steps:i},a)}function Nt(t){const{name:l,schema:a,resolver:r,onSubmit:n}=t,s=G({name:l}),{steps:i,updateStep:o}=gt();return e.useEffect(()=>{o({name:l,schema:a,resolver:r,onSubmit:n})},[l,a]),Y({},s,i[l]||{name:l,schema:a})}const Ct=["children"],xt=["getFormProps"],St=["children","orientation","variant","colorScheme","size"],kt=["name","schema","resolver","children","className","onSubmit"],Rt=["label","submitLabel"],Vt=e.forwardRef((t,l)=>{const{children:a}=t,r=Z(t,Ct),s=Ft(t),{getFormProps:i}=s,o=Z(s,xt),m=e.useMemo(()=>o,[o]);/*#__PURE__*/return e.createElement(W,{value:m},/*#__PURE__*/e.createElement(vt,{value:m},/*#__PURE__*/e.createElement(De,Y({ref:l},r,i()),n(a,s))))}),Lt=t=>{const{activeIndex:l,setIndex:a}=J(),{children:r,orientation:n,variant:s,colorScheme:i,size:o}=t,m=Z(t,St),c=e.Children.map(r,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===wt){const{isCompleted:l}=Nt(t.props);/*#__PURE__*/return e.createElement(K,Y({name:t.props.name,title:t.props.title,isCompleted:l},m),t.props.children)}return t}),d=e.useCallback(e=>{a(e)},[]);/*#__PURE__*/return e.createElement(Q,{orientation:n,step:l,variant:s,colorScheme:i,size:o,onChange:d},/*#__PURE__*/e.createElement(X,Y({mb:"4"},t),c))},wt=t=>{const{name:l,schema:a,resolver:n,children:s,className:i,onSubmit:o}=t,m=Z(t,kt),c=Nt({name:l,schema:a,resolver:n,onSubmit:o}),{isActive:d}=c;return d?/*#__PURE__*/e.createElement(_.div,Y({},m,{className:r("saas-form__step",i)}),s):null};t&&(wt.displayName="FormStep");const At=t=>{const{isFirstStep:a,isCompleted:n,prevStep:s}=J();/*#__PURE__*/return e.createElement(q,Y({isDisabled:a||n,label:"Back"},t,{className:r("saas-form__prev-button",t.className),onClick:l(t.onClick,s)}))};t&&(At.displayName="PrevButton");const It=t=>{const{label:l="Next",submitLabel:a="Complete"}=t,n=Z(t,Rt),{isLastStep:s,isCompleted:i}=J();/*#__PURE__*/return e.createElement(ft,Y({},n,{isDisabled:i,className:r("saas-form__next-button",t.className)}),s||i?a:l)};t&&(It.displayName="NextButton");const Bt=e=>{const{name:t,defaultValue:l,isDisabled:a,isExact:r}=e,n=s(),i=u({name:t,defaultValue:l,disabled:a,exact:r});return e.children(i,n)||null};export{lt as ArrayField,tt as ArrayFieldAddButton,rt as ArrayFieldContainer,_e as ArrayFieldProvider,et as ArrayFieldRemoveButton,Xe as ArrayFieldRow,Ze as ArrayFieldRowContainer,Ye as ArrayFieldRowFields,Pe as ArrayFieldRowProvider,at as ArrayFieldRows,bt as AutoForm,he as BaseField,ke as CheckboxField,te as DisplayField,yt as DisplayIf,be as Field,ut as Fields,De as Form,Me as FormLayout,st as FormLegend,wt as FormStep,Lt as FormStepper,le as FormValue,ge as InputField,Ve as NativeSelectField,It as NextButton,Fe as NumberInputField,it as ObjectField,Ne as PasswordInputField,Le as PinField,At as PrevButton,Re as RadioField,Se as SelectField,Vt as StepForm,vt as StepFormProvider,ft as SubmitButton,xe as SwitchField,Ce as TextareaField,Bt as WatchField,Ie as objectFieldResolver,ve as registerFieldType,qe as useArrayField,Ge as useArrayFieldAddButton,ze as useArrayFieldContext,Te as useArrayFieldRemoveButton,He as useArrayFieldRow,$e as useArrayFieldRowContext,Nt as useFormStep,Ft as useStepForm,gt as useStepFormContext,ye as withControlledInput,Ee as withUncontrolledInput};
|
1
|
+
import*as e from"react";import{__DEV__ as t,callAllHandlers as l,get as a,cx as r,runIfFn as n}from"@chakra-ui/utils";import{useFormContext as s,Controller as i,get as o,useForm as m,FormProvider as c,useFieldArray as d,useWatch as u}from"react-hook-form";export{Controller,FormProvider,appendErrors,useController,useFieldArray,useForm,useFormContext,useFormState,useWatch}from"react-hook-form";import{FormControl as p,FormLabel as f,Text as h,forwardRef as b,Input as y,InputGroup as E,Switch as v,Checkbox as g,HStack as F,PinInput as N,Box as C,FormHelperText as x,FormErrorMessage as S,useMergeRefs as k,Textarea as R,PinInputField as V,chakra as L,useTheme as w,SimpleGrid as A,useStyleConfig as I}from"@chakra-ui/react";import{NumberInput as B}from"@saas-ui/number-input";import{PasswordInput as D}from"@saas-ui/password-input";import{RadioInput as O}from"@saas-ui/radio";import{Select as j,NativeSelect as M}from"@saas-ui/select";import{forwardRef as U,chakra as _}from"@chakra-ui/system";import{MinusIcon as z,AddIcon as P}from"@chakra-ui/icons";import{IconButton as $,Button as q}from"@saas-ui/button";import{createContext as H}from"@chakra-ui/react-utils";import{useStepper as T,useStep as G,StepperProvider as W,useStepperContext as J,StepperStep as K,StepperContainer as Q,StepperSteps as X}from"@saas-ui/stepper";export*from"@saas-ui/input-right-button";function Y(){return Y=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var l=arguments[t];for(var a in l)Object.prototype.hasOwnProperty.call(l,a)&&(e[a]=l[a])}return e},Y.apply(this,arguments)}function Z(e,t){if(null==e)return{};var l,a,r={},n=Object.keys(e);for(a=0;a<n.length;a++)t.indexOf(l=n[a])>=0||(r[l]=e[l]);return r}const ee=["name","label","placeholder"],te=t=>{let{name:l,label:a}=t,r=Z(t,ee);/*#__PURE__*/return e.createElement(p,r,a?/*#__PURE__*/e.createElement(f,{htmlFor:l},a):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(le,{name:l})))};t&&(te.displayName="DisplayField");const le=({name:e})=>{const{getValues:t}=s();return t(e)||null};t&&(le.displayName="FormValue");const ae=["name","label","help","hideLabel","children"],re=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules"],ne=["name","rules"],se=["ref"],ie=["name","rules"],oe=["ref"],me=["type","leftAddon","rightAddon","size"],ce=["type","value"],de=["label","type"],ue=["pinLength","pinType","spacing"],pe={},fe="text",he=t=>{const{name:l,label:a,help:r,hideLabel:n,children:i}=t,m=Z(t,ae),{formState:c}=s(),d=((e,t)=>o(t.errors,e))(l,c);/*#__PURE__*/return e.createElement(p,Y({},m,{isInvalid:!!d}),a&&!n?/*#__PURE__*/e.createElement(f,null,a):null,/*#__PURE__*/e.createElement(C,null,i,!r||null!=d&&d.message?null:/*#__PURE__*/e.createElement(x,null,r),(null==d?void 0:d.message)&&/*#__PURE__*/e.createElement(S,null,null==d?void 0:d.message)))};t&&(he.displayName="BaseField");const be=e.forwardRef((t,l)=>{const{type:a=fe}=t,r=(e=>pe[e]||pe[fe])(a);/*#__PURE__*/return e.createElement(r,Y({ref:l},t))}),ye=t=>b((a,r)=>{let{name:n,rules:o}=a,m=Z(a,ne);const{control:c}=s();/*#__PURE__*/return e.createElement(i,{name:n,control:c,rules:o,render:a=>{let{field:{ref:n}}=a,s=Z(a.field,se);/*#__PURE__*/return e.createElement(t,Y({},s,m,{onChange:l(m.onChange,s.onChange),onBlur:l(m.onBlur,s.onBlur),ref:k(r,n)}))}})}),Ee=t=>b((a,r)=>{let{name:n,rules:i}=a,o=Z(a,ie);const{register:m}=s(),c=m(n,i),{ref:d}=c,u=Z(c,oe);/*#__PURE__*/return e.createElement(t,Y({},u,o,{onChange:l(o.onChange,u.onChange),onBlur:l(o.onBlur,u.onBlur),ref:k(r,d)}))}),ve=(t,l,a)=>{let r;r=null!=a&&a.isControlled?ye(l):Ee(l);const n=((t,{displayName:l,hideLabel:a,BaseField:r})=>{const n=b((l,n)=>{const{id:s,name:i,label:o,help:m,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,rules:f}=l,h=Z(l,re),b=Y({required:p},f);/*#__PURE__*/return e.createElement(r,{id:s,name:i,label:o,help:m,hideLabel:a,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p},/*#__PURE__*/e.createElement(t,Y({ref:n,id:s,name:i,label:a?o:void 0,rules:b},h)))});return n.displayName=l,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==a?void 0:a.hideLabel,BaseField:(null==a?void 0:a.BaseField)||he});return pe[t]=n,n},ge=ve("text",b((t,l)=>{let{type:a="text",leftAddon:r,rightAddon:n,size:s}=t,i=Z(t,me);const o=/*#__PURE__*/e.createElement(y,Y({type:a,size:s},i,{ref:l}));return r||n?/*#__PURE__*/e.createElement(E,{size:s},r,o,n):o})),Fe=ve("number",B,{isControlled:!0}),Ne=ve("password",b((t,l)=>/*#__PURE__*/e.createElement(D,Y({ref:l},t)))),Ce=ve("textarea",R),xe=ve("switch",b((t,l)=>{let{value:a}=t,r=Z(t,ce);/*#__PURE__*/return e.createElement(v,Y({isChecked:!!a},r,{ref:l}))}),{isControlled:!0}),Se=ve("select",j,{isControlled:!0}),ke=ve("checkbox",b((t,l)=>{let{label:a}=t,r=Z(t,de);/*#__PURE__*/return e.createElement(g,Y({ref:l},r),a)}),{hideLabel:!0}),Re=ve("radio",O,{isControlled:!0}),Ve=ve("native-select",M,{isControlled:!0}),Le=ve("pin",b((t,l)=>{const{pinLength:a=4,pinType:r,spacing:n}=t,s=Z(t,ue),i=[];for(let t=0;t<a;t++)i.push(/*#__PURE__*/e.createElement(V,{key:t,ref:l}));/*#__PURE__*/return e.createElement(F,{spacing:n},/*#__PURE__*/e.createElement(N,Y({},s,{type:r}),i))}),{isControlled:!0}),we=["items","label","title"],Ae=e=>e&&Object.entries(e).map(([e,t])=>{let{label:l,title:a}=t;return Y({},Z(t,we),{name:e,label:l||a})}),Ie=e=>({getFields:()=>Ae(e),getNestedFields:t=>{var l;const r=a(e,t);return r?"object"===(null==(l=r.items)?void 0:l.type)?Ae(r.items.properties):"object"===r.type?Ae(r.properties):[r.items]:[]}}),Be=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onChange","onSubmit","onError","formRef","children"],De=b((t,l)=>{const{mode:a="all",resolver:s,reValidateMode:i,shouldFocusError:o,shouldUnregister:d,shouldUseNativeValidation:u,criteriaMode:p,delayError:f,schema:h,defaultValues:b,onChange:y,onSubmit:E,onError:v,formRef:g,children:F}=t,N=Z(t,Be),C={mode:a,resolver:s,defaultValues:b,reValidateMode:i,shouldFocusError:o,shouldUnregister:d,shouldUseNativeValidation:u,criteriaMode:p,delayError:f};h&&!s&&(C.resolver=null==De.getResolver?void 0:De.getResolver(h));const x=m(C),{handleSubmit:S}=x;return e.useImperativeHandle(l,()=>x,[l,x]),e.useEffect(()=>{let e;return y&&(e=x.watch(y)),()=>{var t;return null==(t=e)?void 0:t.unsubscribe()}},[x,y]),/*#__PURE__*/e.createElement(c,x,/*#__PURE__*/e.createElement(L.form,Y({ref:g,onSubmit:S(E,v)},N,{className:r("saas-form",t.className)}),n(F,x)))});De.getFieldResolver=Ie,t&&(De.displayName="Form");const Oe=["children"],je=({children:t})=>/*#__PURE__*/e.createElement(L.div,null,t);t&&(je.displayName="FormLayoutItem");const Me=t=>{var l,a,n;let{children:s}=t,i=Z(t,Oe);const o=Y({},null!=(l=null==(a=w().components)||null==(n=a.FormLayout)?void 0:n.defaultProps)?l:{spacing:4},i);/*#__PURE__*/return e.createElement(A,Y({},o,{className:r("saas-form__layout",i.className)}),e.Children.map(s,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(je,null,t):t))};t&&(Me.displayName="FormLayout");const Ue=(t,l)=>e.Children.map(l,l=>e.isValidElement(l)&&l.props.name?e.cloneElement(l,Y({},l.props,{name:`${t}.${l.props.name}`})):l),[_e,ze]=H({name:"ArrayFieldContext"}),[Pe,$e]=H({name:"ArrayFieldRowContext"}),qe=({name:e,defaultValue:t={},keyName:l,min:a,max:r})=>{const{control:n}=s();return Y({},d({control:n,name:e,keyName:l}),{name:e,defaultValue:t,min:a,max:r})},He=({index:t})=>{const{clearErrors:l}=s(),{name:a,remove:r,fields:n}=ze();return e.useEffect(()=>{l(a)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${a}.${t}`,remove:e.useCallback(()=>{l(a),r(t)},[t])}},Te=()=>{const{isFirst:e,remove:t}=$e(),{min:l,fields:a}=ze();return{onClick:()=>t(),isDisabled:e&&!!(l&&a.length<=l)}},Ge=()=>{const{append:e,defaultValue:t,max:l,fields:a}=ze();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(l&&a.length>=l)}},We=["children","index"],Je=["children"],Ke=["children"],Qe=["name","defaultValue","keyName","min","max","children"],Xe=t=>{let{children:l,index:a}=t,r=Z(t,We);/*#__PURE__*/return e.createElement(Ze,{index:a},/*#__PURE__*/e.createElement(Ye,r,l),/*#__PURE__*/e.createElement(et,null))};t&&(Xe.displayName="ArrayFieldRow");const Ye=t=>{let{children:l}=t,a=Z(t,Je);const{name:r}=$e();/*#__PURE__*/return e.createElement(Me,Y({flex:"1",mr:"2"},a),Ue(r,l))};t&&(Ye.displayName="ArrayFieldRowFields");const Ze=({children:t,index:l})=>{const a=He({index:l});/*#__PURE__*/return e.createElement(Pe,{value:a},/*#__PURE__*/e.createElement(_.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))};t&&(Ze.displayName="ArrayFieldRowContainer");const et=t=>/*#__PURE__*/e.createElement($,Y({icon:/*#__PURE__*/e.createElement(z,null),"aria-label":"Remove row"},Te(),t));t&&(et.displayName="ArrayFieldRemoveButton");const tt=t=>/*#__PURE__*/e.createElement($,Y({icon:/*#__PURE__*/e.createElement(P,null),"aria-label":"Add row",float:"right"},Ge(),t));t&&(tt.displayName="ArrayFieldAddButton");const lt=U((t,l)=>{const{children:a}=t,r=Z(t,Ke);/*#__PURE__*/return e.createElement(rt,Y({ref:l},r),/*#__PURE__*/e.createElement(at,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},l)=>/*#__PURE__*/e.createElement(Xe,{key:t,index:l},a)))),/*#__PURE__*/e.createElement(tt,null))});t&&(lt.displayName="ArrayField");const at=({children:e})=>{const{fields:t}=ze();return e(t)};t&&(at.displayName="ArrayFieldRows");const rt=e.forwardRef((t,l)=>{let{name:a,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=Z(t,Qe);const c=qe({name:a,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(l,()=>c,[l,c]),/*#__PURE__*/e.createElement(_e,{value:c},/*#__PURE__*/e.createElement(he,Y({name:a},m),o))});t&&(rt.displayName="ArrayFieldContainer");const nt=["name","label","hideLabel","children","columns","spacing"],st=t=>{const l=I("FormLegend");/*#__PURE__*/return e.createElement(f,Y({as:"legend",sx:l},t))},it=t=>{const{name:l,label:a,hideLabel:r,children:n,columns:s,spacing:i}=t,o=Z(t,nt);/*#__PURE__*/return e.createElement(p,Y({name:l,as:"fieldset"},o),/*#__PURE__*/e.createElement(st,{display:r?"none":"block"},a),/*#__PURE__*/e.createElement(Me,{columns:s,gridGap:i},Ue(l,n)))};t&&(it.displayName="ObjectField");const ot=["name","type"],mt=["schema","fieldResolver","focusFirstField"],ct=["name","type","defaultValue"],dt=(t,l)=>{var a;return null==(a=t.getNestedFields(l))?void 0:a.map((t,l)=>{let{name:a,type:r}=t,n=Z(t,ot);/*#__PURE__*/return e.createElement(be,Y({key:a||l,name:a,type:r},n))})},ut=t=>{let{schema:l,fieldResolver:a,focusFirstField:r}=t,n=Z(t,mt);const i=e.useMemo(()=>a||De.getFieldResolver(l),[l,a]),o=e.useMemo(()=>i.getFields(),[i]),m=s();return e.useEffect(()=>{var e;r&&null!=(e=o[0])&&e.name&&m.setFocus(o[0].name)},[l,a,r]),/*#__PURE__*/e.createElement(Me,n,o.map(t=>{let{name:l,type:a}=t,r=Z(t,ct);return"array"===a?/*#__PURE__*/e.createElement(lt,Y({key:l,name:l},r),dt(i,l)):"object"===a?/*#__PURE__*/e.createElement(it,Y({key:l,name:l},r),dt(i,l)):/*#__PURE__*/e.createElement(be,Y({key:l,name:l,type:a},r))}))};t&&(ut.displayName="Fields");const pt=["children","disableIfUntouched","disableIfInvalid","isDisabled","isLoading"],ft=e.forwardRef((t,l)=>{const{children:a,disableIfUntouched:r,disableIfInvalid:n,isDisabled:i,isLoading:o}=t,m=Z(t,pt),{formState:c}=s();/*#__PURE__*/return e.createElement(q,Y({},m,{ref:l,variant:"primary",type:"submit",isLoading:c.isSubmitting||o,isDisabled:r&&!c.isDirty||n&&!c.isValid||i}),a)});ft.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(ft.displayName="SubmitButton");const ht=["schema","submitLabel","fieldResolver","children"],bt=b((t,l)=>{const{schema:a,submitLabel:r="Submit",fieldResolver:n,children:s}=t,i=Z(t,ht);/*#__PURE__*/return e.createElement(De,Y({},i,{schema:a,ref:l}),/*#__PURE__*/e.createElement(Me,null,/*#__PURE__*/e.createElement(ut,{schema:a,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(ft,null,r),s))});t&&(bt.displayName="AutoForm");const yt=({children:e,name:t,defaultValue:l,isDisabled:a,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:l,disabled:a,exact:r}),s())?e:null;t&&(yt.displayName="DisplayIf");const Et=["onChange"],[vt,gt]=H({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function Ft(t){const l=Z(t,Et),a=T(l),{activeStep:r,isLastStep:n,nextStep:s}=a,[i,o]=e.useState({}),m=e.useCallback(async e=>{try{const l=i[r];if(n)return await(null==t.onSubmit?void 0:t.onSubmit(e)),d(Y({},l,{isCompleted:!0})),void s();await(null==l.onSubmit?void 0:l.onSubmit(e,a)),s()}catch(e){}},[i,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=>Y({},t,{[e.name]:e}))},[i]);return Y({getFormProps:c,updateStep:d,steps:i},a)}function Nt(t){const{name:l,schema:a,resolver:r,onSubmit:n}=t,s=G({name:l}),{steps:i,updateStep:o}=gt();return e.useEffect(()=>{o({name:l,schema:a,resolver:r,onSubmit:n})},[l,a]),Y({},s,i[l]||{name:l,schema:a})}const Ct=["children"],xt=["getFormProps"],St=["children","orientation","variant","colorScheme","size"],kt=["name","schema","resolver","children","className","onSubmit"],Rt=["label","submitLabel"],Vt=e.forwardRef((t,l)=>{const{children:a}=t,r=Z(t,Ct),s=Ft(t),{getFormProps:i}=s,o=Z(s,xt),m=e.useMemo(()=>o,[o]);/*#__PURE__*/return e.createElement(W,{value:m},/*#__PURE__*/e.createElement(vt,{value:m},/*#__PURE__*/e.createElement(De,Y({ref:l},r,i()),n(a,s))))}),Lt=t=>{const{activeIndex:l,setIndex:a}=J(),{children:r,orientation:n,variant:s,colorScheme:i,size:o}=t,m=Z(t,St),c=e.Children.map(r,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===wt){const{isCompleted:l}=Nt(t.props);/*#__PURE__*/return e.createElement(K,Y({name:t.props.name,title:t.props.title,isCompleted:l},m),t.props.children)}return t}),d=e.useCallback(e=>{a(e)},[]);/*#__PURE__*/return e.createElement(Q,{orientation:n,step:l,variant:s,colorScheme:i,size:o,onChange:d},/*#__PURE__*/e.createElement(X,Y({mb:"4"},t),c))},wt=t=>{const{name:l,schema:a,resolver:n,children:s,className:i,onSubmit:o}=t,m=Z(t,kt),c=Nt({name:l,schema:a,resolver:n,onSubmit:o}),{isActive:d}=c;return d?/*#__PURE__*/e.createElement(_.div,Y({},m,{className:r("saas-form__step",i)}),s):null};t&&(wt.displayName="FormStep");const At=t=>{const{isFirstStep:a,isCompleted:n,prevStep:s}=J();/*#__PURE__*/return e.createElement(q,Y({isDisabled:a||n,label:"Back"},t,{className:r("saas-form__prev-button",t.className),onClick:l(t.onClick,s)}))};t&&(At.displayName="PrevButton");const It=t=>{const{label:l="Next",submitLabel:a="Complete"}=t,n=Z(t,Rt),{isLastStep:s,isCompleted:i}=J();/*#__PURE__*/return e.createElement(ft,Y({},n,{isDisabled:i,className:r("saas-form__next-button",t.className)}),s||i?a:l)};t&&(It.displayName="NextButton");const Bt=e=>{const{name:t,defaultValue:l,isDisabled:a,isExact:r}=e,n=s(),i=u({name:t,defaultValue:l,disabled:a,exact:r});return e.children(i,n)||null};export{lt as ArrayField,tt as ArrayFieldAddButton,rt as ArrayFieldContainer,_e as ArrayFieldProvider,et as ArrayFieldRemoveButton,Xe as ArrayFieldRow,Ze as ArrayFieldRowContainer,Ye as ArrayFieldRowFields,Pe as ArrayFieldRowProvider,at as ArrayFieldRows,bt as AutoForm,he as BaseField,ke as CheckboxField,te as DisplayField,yt as DisplayIf,be as Field,ut as Fields,De as Form,Me as FormLayout,st as FormLegend,wt as FormStep,Lt as FormStepper,le as FormValue,ge as InputField,Ve as NativeSelectField,It as NextButton,Fe as NumberInputField,it as ObjectField,Ne as PasswordInputField,Le as PinField,At as PrevButton,Re as RadioField,Se as SelectField,Vt as StepForm,vt as StepFormProvider,ft as SubmitButton,xe as SwitchField,Ce as TextareaField,Bt as WatchField,Ie as objectFieldResolver,ve as registerFieldType,qe as useArrayField,Ge as useArrayFieldAddButton,ze as useArrayFieldContext,Te as useArrayFieldRemoveButton,He as useArrayFieldRow,$e as useArrayFieldRowContext,Nt as useFormStep,Ft as useStepForm,gt as useStepFormContext,ye as withControlledInput,Ee as withUncontrolledInput};
|
2
2
|
//# sourceMappingURL=index.modern.js.map
|