@saas-ui/forms 0.6.0 → 0.7.0

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,28 @@
1
1
  # @saas-ui/forms
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - bab579f: Added Zod resolver for AutoForm
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [f6269cb]
12
+ - @saas-ui/password-input@0.3.2
13
+
14
+ ## 0.6.2
15
+
16
+ ### Patch Changes
17
+
18
+ - 6696203: Fixed Yup resolver types
19
+
20
+ ## 0.6.1
21
+
22
+ ### Patch Changes
23
+
24
+ - Release an updated build
25
+
3
26
  ## 0.6.0
4
27
 
5
28
  ### Minor Changes
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("react"),t=require("react-hook-form"),r=require("@chakra-ui/react"),n=require("@saas-ui/number-input"),a=require("@saas-ui/password-input"),l=require("@saas-ui/radio"),i=require("@saas-ui/pin-input"),o=require("@saas-ui/select"),s=require("@chakra-ui/utils"),u=require("@chakra-ui/system"),c=require("@chakra-ui/icons"),m=require("@saas-ui/button"),d=require("@chakra-ui/react-utils"),p=require("@saas-ui/react-utils"),f=require("@saas-ui/input-right-button");function v(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var h=/*#__PURE__*/v(e);function x(){return x=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},x.apply(this,arguments)}function b(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var E=["name","label","placeholder"],y=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null},F=["name","label","help","variant","hideLabel","children"],S=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],_=["name","rules"],g=["ref"],C=["name","rules"],N=["ref"],k=["label"],R=["label"],w={},I=function(e){var n=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=b(e,F),c=function(e,r){return t.get(r.errors,e)}(n,t.useFormContext().formState);/*#__PURE__*/return h.createElement(r.FormControl,x({variant:i},u,{isInvalid:!!c}),a&&!o?/*#__PURE__*/h.createElement(r.FormLabel,{variant:i},a):null,/*#__PURE__*/h.createElement(r.Box,null,s,!l||null!=c&&c.message?null:/*#__PURE__*/h.createElement(r.FormHelperText,null,l),(null==c?void 0:c.message)&&/*#__PURE__*/h.createElement(r.FormErrorMessage,null,null==c?void 0:c.message)))},A=r.forwardRef(function(e,t){var r=e.type;/*#__PURE__*/return h.createElement(w[void 0===r?"text":r]||w.text,x({ref:t},e))}),V=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=b(n,_),s=t.useFormContext();/*#__PURE__*/return h.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(t){var n=t.field,l=n.ref,i=b(n,g);/*#__PURE__*/return h.createElement(e,x({},i,o,{ref:r.useMergeRefs(a,l)}))}})})},O=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=b(n,C),s=(0,t.useFormContext().register)(l,i),u=s.ref,c=b(s,N);/*#__PURE__*/return h.createElement(e,x({},c,o,{ref:r.useMergeRefs(a,u)}))})},D=function(e,t,n){var a=function(e,t){var n=t.displayName,a=t.hideLabel,l=t.BaseField,i=r.forwardRef(function(t,r){var n=t.name,i=t.label,o=t.help,s=t.isDisabled,u=t.isInvalid,c=t.isReadOnly,m=t.isRequired,d=t.rules,p=t.variant,f=b(t,S),v=x({required:m},d);/*#__PURE__*/return h.createElement(l,{name:n,label:i,help:o,hideLabel:a,isDisabled:s,isInvalid:u,isReadOnly:c,isRequired:m,variant:p},/*#__PURE__*/h.createElement(e,x({ref:r,name:n,label:i,rules:v},f)))});return i.displayName=n,i}(null!=n&&n.isControlled?V(t):O(t),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||I});return w[e]=a,a},P=D("text",r.Input),L=D("number",n.NumberInput,{isControlled:!0}),j=D("password",a.PasswordInput),q=D("textarea",r.Textarea),B=D("switch",r.forwardRef(function(e,t){var n=e.label,a=b(e,k);/*#__PURE__*/return h.createElement(r.Switch,x({ref:t},a),n)}),{isControlled:!0,hideLabel:!0}),M=D("select",o.Select,{isControlled:!0}),T=D("checkbox",r.forwardRef(function(e,t){var n=e.label,a=b(e,R);/*#__PURE__*/return h.createElement(r.Checkbox,x({ref:t},a),n)}),{hideLabel:!0}),U=D("radio",l.RadioInput,{isControlled:!0}),H=D("pin",i.PinInput,{isControlled:!0}),G=D("native-select",o.NativeSelect,{isControlled:!0}),z=function(e){return e&&Object.entries(e).map(function(e){return x({},e[1],{name:e[0]})})},W=function(e){return{getFields:function(){return z(e)},getNestedFields:function(t){var r,n=s.get(e,t);return n?"object"===(null==(r=n.items)?void 0:r.type)?z(n.items.properties):"object"===n.type?z(n.properties):[n.items]:[]}}},J=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],K=r.forwardRef(function(e,n){var a=e.mode,l=void 0===a?"all":a,i=e.resolver,o=e.reValidateMode,s=e.shouldFocusError,u=e.shouldUnregister,c=e.shouldUseNativeValidation,m=e.criteriaMode,d=e.delayError,p=e.schema,f=e.defaultValues,v=e.onSubmit,E=e.onError,y=e.formRef,F=e.children,S=b(e,J),_={mode:l,resolver:i,defaultValues:f,reValidateMode:o,shouldFocusError:s,shouldUnregister:u,shouldUseNativeValidation:c,criteriaMode:m,delayError:d};p&&!i&&(_.resolver=null==K.getResolver?void 0:K.getResolver(p));var g=t.useForm(_),C=g.handleSubmit;return h.useImperativeHandle(n,function(){return g},[n,g]),/*#__PURE__*/h.createElement(t.FormProvider,g,/*#__PURE__*/h.createElement(r.chakra.form,x({ref:y,onSubmit:C(v,E)},S),F))});K.getFieldResolver=W;var Q=["children"],X=function(e){/*#__PURE__*/return h.createElement(r.chakra.div,null,e.children)},Y=function(e){var t,n,a,l=e.children,i=b(e,Q),o=x({},null!=(t=null==(n=r.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return h.createElement(r.SimpleGrid,o,h.Children.map(l,function(e){return h.isValidElement(e)?/*#__PURE__*/h.createElement(X,null,e):e}))},Z=function(e,t){return h.Children.map(t,function(t){return h.isValidElement(t)&&t.props.name?h.cloneElement(t,x({},t.props,{name:e+"."+t.props.name})):t})},$=d.createContext({name:"ArrayFieldContext"}),ee=$[0],te=$[1],re=d.createContext({name:"ArrayFieldRowContext"}),ne=re[0],ae=re[1],le=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,s=t.useFormContext();return x({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},ie=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=te(),l=a.name,i=a.remove,o=a.fields;return h.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:h.useCallback(function(){n(l),i(r)},[r])}},oe=function(){var e=ae(),t=e.isFirst,r=e.remove,n=te(),a=n.min;return{onClick:function(){return r()},isDisabled:t&&!!(a&&n.fields.length<=a)}},se=function(){var e=te(),t=e.append,r=e.defaultValue,n=e.max;return{onClick:function(){return t(r,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},ue=["children","columns","spacing"],ce=["children"],me=["name","defaultValue","keyName","min","max","children"],de=function(e){/*#__PURE__*/return h.createElement(fe,{index:e.index},/*#__PURE__*/h.createElement(pe,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/h.createElement(ve,null))},pe=function(e){var t=e.children,r=e.columns,n=e.spacing,a=b(e,ue),l=ae().name;/*#__PURE__*/return h.createElement(Y,x({flex:"1",columns:r,gridGap:n,mr:"2"},a),Z(l,t))},fe=function(e){var t=e.children,r=ie({index:e.index});/*#__PURE__*/return h.createElement(ne,{value:r},/*#__PURE__*/h.createElement(u.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},ve=function(e){/*#__PURE__*/return h.createElement(m.IconButton,x({icon:/*#__PURE__*/h.createElement(c.MinusIcon,null),"aria-label":"Remove row"},oe(),e))},he=function(e){/*#__PURE__*/return h.createElement(m.IconButton,x({icon:/*#__PURE__*/h.createElement(c.AddIcon,null),"aria-label":"Add row",float:"right"},se(),e))},xe=h.forwardRef(function(e,t){var r=e.children,n=b(e,ce);/*#__PURE__*/return h.createElement(Ee,x({ref:t},n),/*#__PURE__*/h.createElement(be,null,function(e){/*#__PURE__*/return h.createElement(h.Fragment,null,e.map(function(e,t){/*#__PURE__*/return h.createElement(de,{key:e.id,index:t},r)}))}),/*#__PURE__*/h.createElement(he,null))}),be=function(e){return(0,e.children)(te().fields)},Ee=h.forwardRef(function(e,t){var r=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=b(e,me),u=le({name:r,defaultValue:n,keyName:a,min:l,max:i});return h.useImperativeHandle(t,function(){return u},[t,u]),/*#__PURE__*/h.createElement(ee,{value:u},/*#__PURE__*/h.createElement(I,x({name:r},s),o))}),ye=["name","label","hideLabel","children","columns","spacing"],Fe=function(e){var t=r.useStyles();/*#__PURE__*/return h.createElement(r.FormLabel,x({as:"legend",sx:t.legend},e))},Se=function(e){var t=e.name,n=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=b(e,ye);/*#__PURE__*/return h.createElement(r.FormControl,x({name:t,as:"fieldset"},s),/*#__PURE__*/h.createElement(Fe,{display:a?"none":"block"},n),/*#__PURE__*/h.createElement(Y,{columns:i,gridGap:o},Z(t,l)))},_e=["name","type"],ge=["schema","fieldResolver"],Ce=["name","type","defaultValue"],Ne=function(e,t){var r;return null==(r=e.getNestedFields(t))?void 0:r.map(function(e,t){var r=e.name,n=e.type,a=b(e,_e);/*#__PURE__*/return h.createElement(A,x({key:r||t,name:r,type:n},a))})},ke=function(e){var t=e.schema,r=e.fieldResolver,n=b(e,ge),a=h.useMemo(function(){return r||K.getFieldResolver(t)},[t,r]);/*#__PURE__*/return h.createElement(Y,n,a.getFields().map(function(e){var t=e.name,r=e.type,n=b(e,Ce);return"array"===r?/*#__PURE__*/h.createElement(xe,x({key:t,name:t},n),Ne(a,t)):"object"===r?/*#__PURE__*/h.createElement(Se,x({key:t,name:t},n),Ne(a,t)):/*#__PURE__*/h.createElement(A,x({key:t,name:t,type:r},n))}))},Re=["children","disableIfUntouched","disableIfInvalid"],we=u.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=b(e,Re),o=t.useFormContext().formState;/*#__PURE__*/return h.createElement(m.Button,x({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});we.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var Ie=["schema","submitLabel","fieldResolver"],Ae=r.forwardRef(function(e,t){var r=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=b(e,Ie);/*#__PURE__*/return h.createElement(K,x({},i,{schema:r,ref:t}),/*#__PURE__*/h.createElement(Y,null,/*#__PURE__*/h.createElement(ke,{schema:r,fieldResolver:l}),a&&/*#__PURE__*/h.createElement(we,{label:a})))});function Ve(){return Ve=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Ve.apply(this,arguments)}function Oe(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var De=d.createContext({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"}),Pe=De[0],Le=De[1];function je(e){var t=e.step,r=h.useState(-1),n=r[0],a=r[1],l=h.useRef([]),i=h.useState(Date.now())[1],o=h.useCallback(function(e){var t=[].concat(l.current);-1===t.indexOf(e)&&t.push(e),l.current=t,i(Date.now())},[l,i]),s=function(e){var t=l.current.indexOf(e);-1!==t&&a(t)};return h.useLayoutEffect(function(){"string"==typeof t?s(t):"number"==typeof t?a(t):-1===n&&a(0)},[t]),{stepsRef:l,activeStep:l.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===l.current.length-1,isCompleted:n>=l.current.length,setIndex:a,setStep:s,nextStep:function(){a(n+1)},prevStep:function(){a(n-1)},registerStep:o,unregisterStep:function(e){l.current=l.current.slice(l.current.indexOf(e),1)}}}function qe(e){var t=e.name,r=e.isActive,n=e.isCompleted,a=Le(),l=a.registerStep,i=a.unregisterStep,o=a.activeStep;return h.useEffect(function(){if(t)return l(t),function(){i(t)}},[]),{isActive:t?o===t:r,isCompleted:n}}var Be=["children","orientation"],Me=["children","orientation","stepComponent"],Te=["children","isOpen"],Ue=["icon","isActive","isCompleted","className"],He=["title","icon","isActive","isCompleted"],Ge=["isActive"],ze=u.forwardRef(function(e,t){var r=u.useMultiStyleConfig("Stepper",e),n=u.omitThemingProps(e),a=n.children,l=n.orientation,i=Oe(n,Be),o=je(e),c=Ve({display:"flex",flexDirection:"column"},r.container);return h.createElement(u.StylesProvider,{value:r},/*#__PURE__*/h.createElement(Pe,{value:o},/*#__PURE__*/h.createElement(u.chakra.div,Ve({ref:t,__css:c},i,{className:s.cx("saas-stepper__container",e.className)}),/*#__PURE__*/h.createElement(We,{orientation:l},a))))});s.__DEV__&&(ze.displayName="Stepper");var We=function(e){var t,r,n=e.children,a=e.orientation,l=e.stepComponent,i=Oe(e,Me),o=u.useStyles(),c=Le().activeIndex,m=Ve({display:"flex",flexDirection:"row",alignItems:"center"},o.steps),d="vertical"===a,f=l||Qe,v=p.getChildrenOfType(n,f),x=v.reduce(function(e,t,r,n){return e.push(/*#__PURE__*/h.createElement(f,Ve({key:r},t.props,{icon:t.props.icon||r+1,isActive:c===r,isCompleted:t.props.isCompleted||c>r}))),"vertical"===a&&e.push(/*#__PURE__*/h.createElement(Je,{key:"content-"+r,isOpen:c===r},t.props.children)),r<n.length-1&&e.push(/*#__PURE__*/h.createElement(Xe,{key:"separator-"+r,isActive:r<c})),e},[]),b=p.getChildOfType(n,Ze),E=c>=v.length?b:d?null:/*#__PURE__*/h.createElement(Je,null,null==(t=v[c])||null==(r=t.props)?void 0:r.children);return h.createElement(h.Fragment,null,/*#__PURE__*/h.createElement(u.chakra.div,Ve({__css:m},i,{className:s.cx("saas-stepper__steps",e.className)}),x),E)};s.__DEV__&&(We.displayName="StepperSteps");var Je=function(e){var t=e.children,n=e.isOpen,a=void 0===n||n,l=Oe(e,Te),i=u.useStyles();return h.createElement(u.chakra.div,Ve({__css:i.content},l,{className:s.cx("saas-stepper__content",e.className)}),/*#__PURE__*/h.createElement(r.Collapse,{in:a},t))};s.__DEV__&&(Je.displayName="StepperContent");var Ke=function(e){var t,r=e.icon,n=e.isCompleted,a=e.className,l=Oe(e,Ue),i=Ve({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},u.useStyles().icon);return t=n?/*#__PURE__*/h.createElement(c.Icon,{as:c.CheckIcon}):r,/*#__PURE__*/h.createElement(u.chakra.div,Ve({__css:i},l,{className:s.cx("saas-stepper__icon",a)}),t)};s.__DEV__&&(Ke.displayName="StepperIcon");var Qe=function(e){var t=e.title,r=e.icon,n=e.isActive,a=e.isCompleted,l=Oe(e,He),i=qe(e),o=Ve({display:"flex",alignItems:"center",flexDirection:"row"},u.useStyles().step);return h.createElement(u.chakra.div,Ve({__css:o,"data-active":i.isActive,"data-completed":i.isCompleted},l,{className:s.cx("saas-stepper__step",e.className)}),/*#__PURE__*/h.createElement(Ke,{icon:r,isActive:n,isCompleted:a}),t&&/*#__PURE__*/h.createElement(Ye,null,t))};s.__DEV__&&(Qe.displayName="StepperStep");var Xe=function(e){var t=e.isActive,r=Oe(e,Ge),n=Ve({flex:1,borderTopWidth:"1px",mx:2},u.useStyles().separator);return h.createElement(u.chakra.div,Ve({"data-active":t},r,{className:s.cx("saas-stepper__separator",e.className),__css:n}))};s.__DEV__&&(Xe.displayName="StepperSeparator");var Ye=function(e){var t=u.useStyles();return h.createElement(u.chakra.p,Ve({},e,{__css:t.title,className:s.cx("saas-stepper__title",e.className)}))};s.__DEV__&&(Ye.displayName="StepperStepTitle");var Ze=function(e){var t=u.useStyles();return h.createElement(u.chakra.div,Ve({__css:t.completed},e,{className:s.cx("saas-stepper__completed",e.className)}))};s.__DEV__&&(Ze.displayName="StepperCompleted");var $e=d.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),et=$e[0],tt=$e[1];function rt(e){var t=je(e),r=t.activeStep,n=t.isLastStep,a=t.nextStep,l=h.useState({}),i=l[0],o=l[1],s=h.useCallback(function(t){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(t).then(function(){c(x({},i[r],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[r,n]),u=h.useCallback(function(e){var t=i[r];return{onSubmit:s,schema:null==t?void 0:t.schema,resolver:null==t?void 0:t.resolver}},[i,s,r]),c=h.useCallback(function(e){o(function(t){var r;return x({},t,((r={})[e.name]=e,r))})},[i]);return x({getFormProps:u,updateStep:c,steps:i},t)}function nt(e){var t=e.name,r=e.schema,n=e.resolver,a=qe({name:t}),l=tt(),i=l.steps,o=l.updateStep;return h.useEffect(function(){o({name:t,schema:r,resolver:n})},[t,r]),x({},a,i[t]||{name:t,schema:r})}var at=["children","onSubmit"],lt=["getFormProps"],it=["name","schema","resolver","children","className"],ot=["label","submitLabel"],st=h.forwardRef(function(e,t){var r=e.children,n=b(e,at),a=rt(e),l=a.getFormProps,i=b(a,lt),o=h.useMemo(function(){return i},[i]);/*#__PURE__*/return h.createElement(Pe,{value:o},/*#__PURE__*/h.createElement(et,{value:o},/*#__PURE__*/h.createElement(K,x({ref:t},n,l(e)),s.runIfFn(r,a))))}),ut=function(e){var t=e.name,r=e.schema,n=e.resolver,a=e.children,l=e.className,i=b(e,it);return nt({name:t,schema:r,resolver:n}).isActive?/*#__PURE__*/h.createElement(u.chakra.div,x({},i,{className:s.cx("saas-form__step",l)}),a):null};s.__DEV__&&(ut.displayName="FormStep");var ct=function(e){var t=Le(),r=t.prevStep;/*#__PURE__*/return h.createElement(m.Button,x({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:s.cx("saas-form__prev-button",e.className),onClick:s.callAllHandlers(e.onClick,r)}))};s.__DEV__&&(ct.displayName="PrevButton");var mt=function(e){var t=e.label,r=void 0===t?"Next":t,n=e.submitLabel,a=void 0===n?"Complete":n,l=b(e,ot),i=Le(),o=i.isCompleted;/*#__PURE__*/return h.createElement(we,x({isDisabled:o,label:i.isLastStep||o?a:r},l,{className:s.cx("saas-form__next-button",e.className)}))};s.__DEV__&&(mt.displayName="NextButton"),exports.ArrayField=xe,exports.ArrayFieldAddButton=he,exports.ArrayFieldContainer=Ee,exports.ArrayFieldProvider=ee,exports.ArrayFieldRemoveButton=ve,exports.ArrayFieldRow=de,exports.ArrayFieldRowContainer=fe,exports.ArrayFieldRowFields=pe,exports.ArrayFieldRowProvider=ne,exports.ArrayFieldRows=be,exports.AutoForm=Ae,exports.BaseField=I,exports.CheckboxField=T,exports.DisplayField=function(e){var t=e.name,n=e.label,a=b(e,E);/*#__PURE__*/return h.createElement(r.FormControl,a,n?/*#__PURE__*/h.createElement(r.FormLabel,{htmlFor:t},n):null,/*#__PURE__*/h.createElement(r.Text,{fontSize:"md"},/*#__PURE__*/h.createElement(y,{name:t})))},exports.DisplayIf=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null},exports.Field=A,exports.Fields=ke,exports.Form=K,exports.FormLayout=Y,exports.FormLegend=Fe,exports.FormStep=ut,exports.FormStepper=function(e){var t=u.useMultiStyleConfig("Stepper",e),r=h.Children.map(e.children,function(e){if(h.isValidElement(e)&&(null==e?void 0:e.type)===ut){var t=nt(e.props);/*#__PURE__*/return h.createElement(Qe,{name:e.props.name,title:e.props.title,isCompleted:t.isCompleted},e.props.children)}return e});/*#__PURE__*/return h.createElement(u.StylesProvider,{value:t},/*#__PURE__*/h.createElement(We,x({mb:"4"},e),r))},exports.FormValue=y,exports.InputField=P,exports.NativeSelectField=G,exports.NextButton=mt,exports.NumberInputField=L,exports.ObjectField=Se,exports.PasswordInputFIeld=j,exports.PinField=H,exports.PrevButton=ct,exports.RadioField=U,exports.SelectField=M,exports.StepForm=st,exports.StepFormProvider=et,exports.SubmitButton=we,exports.SwitchField=B,exports.TextareaField=q,exports.objectFieldResolver=W,exports.registerFieldType=D,exports.useArrayField=le,exports.useArrayFieldAddButton=se,exports.useArrayFieldContext=te,exports.useArrayFieldRemoveButton=oe,exports.useArrayFieldRow=ie,exports.useArrayFieldRowContext=ae,exports.useFormStep=nt,exports.useStepForm=rt,exports.useStepFormContext=tt,exports.withControlledInput=V,exports.withUncontrolledInput=O,Object.keys(f).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return f[e]}})});
1
+ var e=require("react"),t=require("react-hook-form"),r=require("@chakra-ui/react"),n=require("@saas-ui/number-input"),a=require("@saas-ui/password-input"),l=require("@saas-ui/radio"),i=require("@saas-ui/pin-input"),o=require("@saas-ui/select"),s=require("@chakra-ui/utils"),u=require("@chakra-ui/system"),c=require("@chakra-ui/icons"),m=require("@saas-ui/button"),d=require("@chakra-ui/react-utils"),p=require("@saas-ui/react-utils"),f=require("@saas-ui/input-right-button");function v(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach(function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}}),t.default=e,t}var h=/*#__PURE__*/v(e);function x(){return x=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},x.apply(this,arguments)}function E(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var b=["name","label","placeholder"],y=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null},F=["name","label","help","variant","hideLabel","children"],S=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],_=["name","rules"],g=["ref"],C=["name","rules"],N=["ref"],k=["label"],R=["label"],w={},I=function(e){var n=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=E(e,F),c=function(e,r){return t.get(r.errors,e)}(n,t.useFormContext().formState);/*#__PURE__*/return h.createElement(r.FormControl,x({variant:i},u,{isInvalid:!!c}),a&&!o?/*#__PURE__*/h.createElement(r.FormLabel,{variant:i},a):null,/*#__PURE__*/h.createElement(r.Box,null,s,!l||null!=c&&c.message?null:/*#__PURE__*/h.createElement(r.FormHelperText,null,l),(null==c?void 0:c.message)&&/*#__PURE__*/h.createElement(r.FormErrorMessage,null,null==c?void 0:c.message)))},A=r.forwardRef(function(e,t){var r=e.type;/*#__PURE__*/return h.createElement(w[void 0===r?"text":r]||w.text,x({ref:t},e))}),V=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=E(n,_),s=t.useFormContext();/*#__PURE__*/return h.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(t){var n=t.field,l=n.ref,i=E(n,g);/*#__PURE__*/return h.createElement(e,x({},i,o,{ref:r.useMergeRefs(a,l)}))}})})},O=function(e){return r.forwardRef(function(n,a){var l=n.name,i=n.rules,o=E(n,C),s=(0,t.useFormContext().register)(l,i),u=s.ref,c=E(s,N);/*#__PURE__*/return h.createElement(e,x({},c,o,{ref:r.useMergeRefs(a,u)}))})},D=function(e,t,n){var a=function(e,t){var n=t.displayName,a=t.hideLabel,l=t.BaseField,i=r.forwardRef(function(t,r){var n=t.name,i=t.label,o=t.help,s=t.isDisabled,u=t.isInvalid,c=t.isReadOnly,m=t.isRequired,d=t.rules,p=t.variant,f=E(t,S),v=x({required:m},d);/*#__PURE__*/return h.createElement(l,{name:n,label:i,help:o,hideLabel:a,isDisabled:s,isInvalid:u,isReadOnly:c,isRequired:m,variant:p},/*#__PURE__*/h.createElement(e,x({ref:r,name:n,label:i,rules:v},f)))});return i.displayName=n,i}(null!=n&&n.isControlled?V(t):O(t),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||I});return w[e]=a,a},P=D("text",r.Input),L=D("number",n.NumberInput,{isControlled:!0}),j=D("password",a.PasswordInput),q=D("textarea",r.Textarea),B=D("switch",r.forwardRef(function(e,t){var n=e.label,a=E(e,k);/*#__PURE__*/return h.createElement(r.Switch,x({ref:t},a),n)}),{isControlled:!0,hideLabel:!0}),M=D("select",o.Select,{isControlled:!0}),U=D("checkbox",r.forwardRef(function(e,t){var n=e.label,a=E(e,R);/*#__PURE__*/return h.createElement(r.Checkbox,x({ref:t},a),n)}),{hideLabel:!0}),T=D("radio",l.RadioInput,{isControlled:!0}),z=D("pin",i.PinInput,{isControlled:!0}),H=D("native-select",o.NativeSelect,{isControlled:!0}),G=function(e){return e&&Object.entries(e).map(function(e){return x({},e[1],{name:e[0]})})},W=function(e){return{getFields:function(){return G(e)},getNestedFields:function(t){var r,n=s.get(e,t);return n?"object"===(null==(r=n.items)?void 0:r.type)?G(n.items.properties):"object"===n.type?G(n.properties):[n.items]:[]}}},J=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],K=r.forwardRef(function(e,n){var a=e.mode,l=void 0===a?"all":a,i=e.resolver,o=e.reValidateMode,s=e.shouldFocusError,u=e.shouldUnregister,c=e.shouldUseNativeValidation,m=e.criteriaMode,d=e.delayError,p=e.schema,f=e.defaultValues,v=e.onSubmit,b=e.onError,y=e.formRef,F=e.children,S=E(e,J),_={mode:l,resolver:i,defaultValues:f,reValidateMode:o,shouldFocusError:s,shouldUnregister:u,shouldUseNativeValidation:c,criteriaMode:m,delayError:d};p&&!i&&(_.resolver=null==K.getResolver?void 0:K.getResolver(p));var g=t.useForm(_),C=g.handleSubmit;return h.useImperativeHandle(n,function(){return g},[n,g]),/*#__PURE__*/h.createElement(t.FormProvider,g,/*#__PURE__*/h.createElement(r.chakra.form,x({ref:y,onSubmit:C(v,b)},S),F))});K.getFieldResolver=W;var Q=["children"],X=function(e){/*#__PURE__*/return h.createElement(r.chakra.div,null,e.children)},Y=function(e){var t,n,a,l=e.children,i=E(e,Q),o=x({},null!=(t=null==(n=r.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return h.createElement(r.SimpleGrid,o,h.Children.map(l,function(e){return h.isValidElement(e)?/*#__PURE__*/h.createElement(X,null,e):e}))},Z=function(e,t){return h.Children.map(t,function(t){return h.isValidElement(t)&&t.props.name?h.cloneElement(t,x({},t.props,{name:e+"."+t.props.name})):t})},$=d.createContext({name:"ArrayFieldContext"}),ee=$[0],te=$[1],re=d.createContext({name:"ArrayFieldRowContext"}),ne=re[0],ae=re[1],le=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,s=t.useFormContext();return x({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},ie=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=te(),l=a.name,i=a.remove,o=a.fields;return h.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:h.useCallback(function(){n(l),i(r)},[r])}},oe=function(){var e=ae(),t=e.isFirst,r=e.remove,n=te(),a=n.min;return{onClick:function(){return r()},isDisabled:t&&!!(a&&n.fields.length<=a)}},se=function(){var e=te(),t=e.append,r=e.defaultValue,n=e.max;return{onClick:function(){return t(r,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},ue=["children","columns","spacing"],ce=["children"],me=["name","defaultValue","keyName","min","max","children"],de=function(e){/*#__PURE__*/return h.createElement(fe,{index:e.index},/*#__PURE__*/h.createElement(pe,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/h.createElement(ve,null))},pe=function(e){var t=e.children,r=e.columns,n=e.spacing,a=E(e,ue),l=ae().name;/*#__PURE__*/return h.createElement(Y,x({flex:"1",columns:r,gridGap:n,mr:"2"},a),Z(l,t))},fe=function(e){var t=e.children,r=ie({index:e.index});/*#__PURE__*/return h.createElement(ne,{value:r},/*#__PURE__*/h.createElement(u.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},ve=function(e){/*#__PURE__*/return h.createElement(m.IconButton,x({icon:/*#__PURE__*/h.createElement(c.MinusIcon,null),"aria-label":"Remove row"},oe(),e))},he=function(e){/*#__PURE__*/return h.createElement(m.IconButton,x({icon:/*#__PURE__*/h.createElement(c.AddIcon,null),"aria-label":"Add row",float:"right"},se(),e))},xe=h.forwardRef(function(e,t){var r=e.children,n=E(e,ce);/*#__PURE__*/return h.createElement(be,x({ref:t},n),/*#__PURE__*/h.createElement(Ee,null,function(e){/*#__PURE__*/return h.createElement(h.Fragment,null,e.map(function(e,t){/*#__PURE__*/return h.createElement(de,{key:e.id,index:t},r)}))}),/*#__PURE__*/h.createElement(he,null))}),Ee=function(e){return(0,e.children)(te().fields)},be=h.forwardRef(function(e,t){var r=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=E(e,me),u=le({name:r,defaultValue:n,keyName:a,min:l,max:i});return h.useImperativeHandle(t,function(){return u},[t,u]),/*#__PURE__*/h.createElement(ee,{value:u},/*#__PURE__*/h.createElement(I,x({name:r},s),o))}),ye=["name","label","hideLabel","children","columns","spacing"],Fe=function(e){var t=r.useStyles();/*#__PURE__*/return h.createElement(r.FormLabel,x({as:"legend",sx:t.legend},e))},Se=function(e){var t=e.name,n=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=E(e,ye);/*#__PURE__*/return h.createElement(r.FormControl,x({name:t,as:"fieldset"},s),/*#__PURE__*/h.createElement(Fe,{display:a?"none":"block"},n),/*#__PURE__*/h.createElement(Y,{columns:i,gridGap:o},Z(t,l)))},_e=["name","type"],ge=["schema","fieldResolver"],Ce=["name","type","defaultValue"],Ne=function(e,t){var r;return null==(r=e.getNestedFields(t))?void 0:r.map(function(e,t){var r=e.name,n=e.type,a=E(e,_e);/*#__PURE__*/return h.createElement(A,x({key:r||t,name:r,type:n},a))})},ke=function(e){var t=e.schema,r=e.fieldResolver,n=E(e,ge),a=h.useMemo(function(){return r||K.getFieldResolver(t)},[t,r]);/*#__PURE__*/return h.createElement(Y,n,a.getFields().map(function(e){var t=e.name,r=e.type,n=E(e,Ce);return"array"===r?/*#__PURE__*/h.createElement(xe,x({key:t,name:t},n),Ne(a,t)):"object"===r?/*#__PURE__*/h.createElement(Se,x({key:t,name:t},n),Ne(a,t)):/*#__PURE__*/h.createElement(A,x({key:t,name:t,type:r},n))}))},Re=["children","disableIfUntouched","disableIfInvalid"],we=u.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=E(e,Re),o=t.useFormContext().formState;/*#__PURE__*/return h.createElement(m.Button,x({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:r,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});we.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var Ie=["schema","submitLabel","fieldResolver"],Ae=r.forwardRef(function(e,t){var r=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=E(e,Ie);/*#__PURE__*/return h.createElement(K,x({},i,{schema:r,ref:t}),/*#__PURE__*/h.createElement(Y,null,/*#__PURE__*/h.createElement(ke,{schema:r,fieldResolver:l}),a&&/*#__PURE__*/h.createElement(we,{label:a})))});function Ve(){return Ve=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Ve.apply(this,arguments)}function Oe(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}var De=d.createContext({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"}),Pe=De[0],Le=De[1];function je(e){var t=e.step,r=h.useState(-1),n=r[0],a=r[1],l=h.useRef([]),i=h.useState(Date.now())[1],o=h.useCallback(function(e){var t=[].concat(l.current);-1===t.indexOf(e)&&t.push(e),l.current=t,i(Date.now())},[l,i]),s=function(e){var t=l.current.indexOf(e);-1!==t&&a(t)};return h.useEffect(function(){"string"==typeof t?s(t):"number"==typeof t?a(t):-1===n&&a(0)},[t]),{stepsRef:l,activeStep:l.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===l.current.length-1,isCompleted:n>=l.current.length,setIndex:a,setStep:s,nextStep:function(){a(n+1)},prevStep:function(){a(n-1)},registerStep:o,unregisterStep:function(e){l.current=l.current.slice(l.current.indexOf(e),1)}}}function qe(e){var t=e.name,r=e.isActive,n=e.isCompleted,a=Le(),l=a.registerStep,i=a.unregisterStep,o=a.activeStep;return h.useEffect(function(){if(t)return l(t),function(){i(t)}},[]),{isActive:t?o===t:r,isCompleted:n}}var Be=["children","orientation","step"],Me=["children","orientation","stepComponent"],Ue=["children","isOpen"],Te=["icon","isActive","isCompleted","className"],ze=["title","icon","isActive","isCompleted"],He=["isActive"],Ge=u.forwardRef(function(e,t){var r=e.children,n=e.orientation,a=void 0===n?"horizontal":n,l=Oe(e,Be),i=u.useMultiStyleConfig("Stepper",Ve({},l,{orientation:a})),o=u.omitThemingProps(l),c=je(e),m=Ve({display:"flex",flexDirection:"column"},i.container);return h.createElement(u.StylesProvider,{value:i},/*#__PURE__*/h.createElement(Pe,{value:c},/*#__PURE__*/h.createElement(u.chakra.div,Ve({ref:t,__css:m},o,{className:s.cx("saas-stepper",e.className)}),/*#__PURE__*/h.createElement(We,{orientation:a},r))))});s.__DEV__&&(Ge.displayName="Stepper");var We=function(e){var t,r,n=e.children,a=e.orientation,l=void 0===a?"horizontal":a,i=e.stepComponent,o=Oe(e,Me),c=u.useStyles(),m=Le().activeIndex,d=Ve({display:"flex",flexDirection:"row",alignItems:"center"},c.steps),f="vertical"===l,v=i||Qe,x=p.getChildrenOfType(n,v),E=x.reduce(function(e,t,r,n){return e.push(/*#__PURE__*/h.createElement(v,Ve({key:r},t.props,{icon:t.props.icon||r+1,isActive:m===r,isCompleted:t.props.isCompleted||m>r}))),f&&e.push(/*#__PURE__*/h.createElement(Je,{key:"content-"+r,isOpen:m===r},t.props.children)),r<n.length-1&&e.push(/*#__PURE__*/h.createElement(Xe,{key:"separator-"+r,isActive:r<m})),e},[]),b=p.getChildOfType(n,Ze),y=m>=x.length?b:f?null:/*#__PURE__*/h.createElement(Je,null,null==(t=x[m])||null==(r=t.props)?void 0:r.children);return h.createElement(h.Fragment,null,/*#__PURE__*/h.createElement(u.chakra.div,Ve({__css:d},o,{className:s.cx("saas-stepper__steps",e.className)}),E),y)};s.__DEV__&&(We.displayName="StepperSteps");var Je=function(e){var t=e.children,n=e.isOpen,a=void 0===n||n,l=Oe(e,Ue),i=u.useStyles();return h.createElement(u.chakra.div,Ve({__css:i.content},l,{className:s.cx("saas-stepper__content",e.className)}),/*#__PURE__*/h.createElement(r.Collapse,{in:a},t))};s.__DEV__&&(Je.displayName="StepperContent");var Ke=function(e){var t,r=e.icon,n=e.isCompleted,a=e.className,l=Oe(e,Te),i=Ve({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em"},u.useStyles().icon);return t=n?/*#__PURE__*/h.createElement(c.Icon,{as:c.CheckIcon}):r,/*#__PURE__*/h.createElement(u.chakra.div,Ve({__css:i},l,{className:s.cx("saas-stepper__icon",a)}),t)};s.__DEV__&&(Ke.displayName="StepperIcon");var Qe=function(e){var t=e.title,r=e.icon,n=e.isActive,a=e.isCompleted,l=Oe(e,ze),i=qe(e),o=Ve({display:"flex",alignItems:"center",flexDirection:"row"},u.useStyles().step);return h.createElement(u.chakra.div,Ve({},l,{__css:o,"data-active":s.dataAttr(i.isActive),"data-completed":s.dataAttr(i.isCompleted),className:s.cx("saas-stepper__step",e.className)}),/*#__PURE__*/h.createElement(Ke,{icon:r,isActive:n,isCompleted:a}),t&&/*#__PURE__*/h.createElement(Ye,null,t))};s.__DEV__&&(Qe.displayName="StepperStep");var Xe=function(e){var t=e.isActive,r=Oe(e,He),n=Ve({flex:1,mx:2},u.useStyles().separator);return h.createElement(u.chakra.div,Ve({},r,{"data-active":s.dataAttr(t),className:s.cx("saas-stepper__separator",e.className),__css:n}))};s.__DEV__&&(Xe.displayName="StepperSeparator");var Ye=function(e){var t=u.useStyles();return h.createElement(u.chakra.p,Ve({},e,{__css:t.title,className:s.cx("saas-stepper__title",e.className)}))};s.__DEV__&&(Ye.displayName="StepperStepTitle");var Ze=function(e){var t=u.useStyles();return h.createElement(u.chakra.div,Ve({__css:t.completed},e,{className:s.cx("saas-stepper__completed",e.className)}))};s.__DEV__&&(Ze.displayName="StepperCompleted");var $e=d.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),et=$e[0],tt=$e[1];function rt(e){var t=je(e),r=t.activeStep,n=t.isLastStep,a=t.nextStep,l=h.useState({}),i=l[0],o=l[1],s=h.useCallback(function(t){try{return n?Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(t).then(function(){c(x({},i[r],{isCompleted:!0}))}).then(a)):(a(),Promise.resolve())}catch(e){return Promise.reject(e)}},[r,n]),u=h.useCallback(function(e){var t=i[r];return{onSubmit:s,schema:null==t?void 0:t.schema,resolver:null==t?void 0:t.resolver}},[i,s,r]),c=h.useCallback(function(e){o(function(t){var r;return x({},t,((r={})[e.name]=e,r))})},[i]);return x({getFormProps:u,updateStep:c,steps:i},t)}function nt(e){var t=e.name,r=e.schema,n=e.resolver,a=qe({name:t}),l=tt(),i=l.steps,o=l.updateStep;return h.useEffect(function(){o({name:t,schema:r,resolver:n})},[t,r]),x({},a,i[t]||{name:t,schema:r})}var at=["children","onSubmit"],lt=["getFormProps"],it=["name","schema","resolver","children","className"],ot=["label","submitLabel"],st=h.forwardRef(function(e,t){var r=e.children,n=E(e,at),a=rt(e),l=a.getFormProps,i=E(a,lt),o=h.useMemo(function(){return i},[i]);/*#__PURE__*/return h.createElement(Pe,{value:o},/*#__PURE__*/h.createElement(et,{value:o},/*#__PURE__*/h.createElement(K,x({ref:t},n,l(e)),s.runIfFn(r,a))))}),ut=function(e){var t=e.name,r=e.schema,n=e.resolver,a=e.children,l=e.className,i=E(e,it);return nt({name:t,schema:r,resolver:n}).isActive?/*#__PURE__*/h.createElement(u.chakra.div,x({},i,{className:s.cx("saas-form__step",l)}),a):null};s.__DEV__&&(ut.displayName="FormStep");var ct=function(e){var t=Le(),r=t.prevStep;/*#__PURE__*/return h.createElement(m.Button,x({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:s.cx("saas-form__prev-button",e.className),onClick:s.callAllHandlers(e.onClick,r)}))};s.__DEV__&&(ct.displayName="PrevButton");var mt=function(e){var t=e.label,r=void 0===t?"Next":t,n=e.submitLabel,a=void 0===n?"Complete":n,l=E(e,ot),i=Le(),o=i.isCompleted;/*#__PURE__*/return h.createElement(we,x({isDisabled:o,label:i.isLastStep||o?a:r},l,{className:s.cx("saas-form__next-button",e.className)}))};s.__DEV__&&(mt.displayName="NextButton"),exports.ArrayField=xe,exports.ArrayFieldAddButton=he,exports.ArrayFieldContainer=be,exports.ArrayFieldProvider=ee,exports.ArrayFieldRemoveButton=ve,exports.ArrayFieldRow=de,exports.ArrayFieldRowContainer=fe,exports.ArrayFieldRowFields=pe,exports.ArrayFieldRowProvider=ne,exports.ArrayFieldRows=Ee,exports.AutoForm=Ae,exports.BaseField=I,exports.CheckboxField=U,exports.DisplayField=function(e){var t=e.name,n=e.label,a=E(e,b);/*#__PURE__*/return h.createElement(r.FormControl,a,n?/*#__PURE__*/h.createElement(r.FormLabel,{htmlFor:t},n):null,/*#__PURE__*/h.createElement(r.Text,{fontSize:"md"},/*#__PURE__*/h.createElement(y,{name:t})))},exports.DisplayIf=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null},exports.Field=A,exports.Fields=ke,exports.Form=K,exports.FormLayout=Y,exports.FormLegend=Fe,exports.FormStep=ut,exports.FormStepper=function(e){var t=u.useMultiStyleConfig("Stepper",e),r=h.Children.map(e.children,function(e){if(h.isValidElement(e)&&(null==e?void 0:e.type)===ut){var t=nt(e.props);/*#__PURE__*/return h.createElement(Qe,{name:e.props.name,title:e.props.title,isCompleted:t.isCompleted},e.props.children)}return e});/*#__PURE__*/return h.createElement(u.StylesProvider,{value:t},/*#__PURE__*/h.createElement(We,x({mb:"4"},e),r))},exports.FormValue=y,exports.InputField=P,exports.NativeSelectField=H,exports.NextButton=mt,exports.NumberInputField=L,exports.ObjectField=Se,exports.PasswordInputFIeld=j,exports.PinField=z,exports.PrevButton=ct,exports.RadioField=T,exports.SelectField=M,exports.StepForm=st,exports.StepFormProvider=et,exports.SubmitButton=we,exports.SwitchField=B,exports.TextareaField=q,exports.objectFieldResolver=W,exports.registerFieldType=D,exports.useArrayField=le,exports.useArrayFieldAddButton=se,exports.useArrayFieldContext=te,exports.useArrayFieldRemoveButton=oe,exports.useArrayFieldRow=ie,exports.useArrayFieldRowContext=ae,exports.useFormStep=nt,exports.useStepForm=rt,exports.useStepFormContext=tt,exports.withControlledInput=V,exports.withUncontrolledInput=O,Object.keys(f).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return f[e]}})});
2
2
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/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","../../saas-ui-stepper/dist/index.modern.js","../src/use-step-form.tsx","../src/step-form.tsx","../src/display-if.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">\n <FormValue name={name} />\n </Text>\n </FormControl>\n )\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\nimport { FocusableElement } from '@chakra-ui/utils'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<FocusableElement>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema) =>\n schema &&\n Object.entries(schema).map(([name, field]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses a different 'id' field\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n UseArrayFieldReturn,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField = React.forwardRef(\n (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer ref={ref} {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n }\n)\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer = React.forwardRef(\n (\n {\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n }: ArrayFieldProps,\n ref: React.ForwardedRef<UseArrayFieldReturn>\n ) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n // This exposes the useArrayField api through the forwarded ref\n React.useImperativeHandle(ref, () => context, [ref, context])\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n }\n)\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyles()\n return <FormLabel as=\"legend\" sx={styles.legend} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n","import * as React from 'react'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n submitLabel?: false | string\n schema: any\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', fieldResolver, ...rest } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & { getFieldResolver?: (schema: any) => FieldResolver }\n","import*as e from\"react\";import{forwardRef as t,useMultiStyleConfig as s,omitThemingProps as r,StylesProvider as n,chakra as a,useStyles as i}from\"@chakra-ui/system\";import{Icon as c,CheckIcon as p}from\"@chakra-ui/icons\";import{Collapse as l}from\"@saas-ui/collapse\";import{getChildrenOfType as o,getChildOfType as m}from\"@saas-ui/react-utils\";import{cx as u,__DEV__ as d}from\"@chakra-ui/utils\";import{createContext as f}from\"@chakra-ui/react-utils\";function v(){return v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e},v.apply(this,arguments)}function S(e,t){if(null==e)return{};var s,r,n={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(s=a[r])>=0||(n[s]=e[s]);return n}const[_,N]=f({name:\"StepperContext\",errorMessage:\"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`\"});function h(t){const{step:s}=t,[r,n]=e.useState(-1),a=e.useRef([]),[,i]=e.useState(Date.now()),c=e.useCallback(e=>{const t=[...a.current];-1===t.indexOf(e)&&t.push(e),a.current=t,i(Date.now())},[a,i]),p=e=>{const t=a.current.indexOf(e);-1!==t&&n(t)};return e.useLayoutEffect(()=>{\"string\"==typeof s?p(s):\"number\"==typeof s?n(s):-1===r&&n(0)},[s]),{stepsRef:a,activeStep:a.current[r],activeIndex:r,isFirstStep:0===r,isLastStep:r===a.current.length-1,isCompleted:r>=a.current.length,setIndex:n,setStep:p,nextStep:()=>{n(r+1)},prevStep:()=>{n(r-1)},registerStep:c,unregisterStep:e=>{a.current=a.current.slice(a.current.indexOf(e),1)}}}function y(t){const{name:s,isActive:r,isCompleted:n}=t,{registerStep:a,unregisterStep:i,activeStep:c}=N();return e.useEffect(()=>{if(s)return a(s),()=>{i(s)}},[]),{isActive:s?c===s:r,isCompleted:n}}function x({label:e=\"Back\"}={}){const{isFirstStep:t,prevStep:s}=N();return{isDisabled:t,onClick:s,label:e}}function C({label:e=\"Next\",submitLabel:t=\"Submit\"}={}){const{isLastStep:s,isCompleted:r,nextStep:n}=N();return{isDisabled:r,onClick:n,label:s?t:e}}const E=[\"children\",\"orientation\"],g=[\"children\",\"orientation\",\"stepComponent\"],b=[\"children\",\"isOpen\"],k=[\"icon\",\"isActive\",\"isCompleted\",\"className\"],A=[\"title\",\"icon\",\"isActive\",\"isCompleted\"],O=[\"isActive\"],D=t((t,i)=>{const c=s(\"Stepper\",t),p=r(t),{children:l,orientation:o}=p,m=S(p,E),d=h(t),f=v({display:\"flex\",flexDirection:\"column\"},c.container);/*#__PURE__*/return e.createElement(n,{value:c},/*#__PURE__*/e.createElement(_,{value:d},/*#__PURE__*/e.createElement(a.div,v({ref:i,__css:f},m,{className:u(\"saas-stepper__container\",t.className)}),/*#__PURE__*/e.createElement(I,{orientation:o},l))))});d&&(D.displayName=\"Stepper\");const I=t=>{var s,r;const{children:n,orientation:c,stepComponent:p}=t,l=S(t,g),d=i(),{activeIndex:f}=N(),_=v({display:\"flex\",flexDirection:\"row\",alignItems:\"center\"},d.steps),h=\"vertical\"===c,y=p||L,x=o(n,y),C=x.reduce((t,s,r,n)=>(t.push(/*#__PURE__*/e.createElement(y,v({key:r},s.props,{icon:s.props.icon||r+1,isActive:f===r,isCompleted:s.props.isCompleted||f>r}))),\"vertical\"===c&&t.push(/*#__PURE__*/e.createElement(w,{key:`content-${r}`,isOpen:f===r},s.props.children)),r<n.length-1&&t.push(/*#__PURE__*/e.createElement(F,{key:`separator-${r}`,isActive:r<f})),t),[]),E=m(n,T),b=f>=x.length?E:h?null:/*#__PURE__*/e.createElement(w,null,null==(s=x[f])||null==(r=s.props)?void 0:r.children);/*#__PURE__*/return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(a.div,v({__css:_},l,{className:u(\"saas-stepper__steps\",t.className)}),C),b)};d&&(I.displayName=\"StepperSteps\");const w=t=>{const{children:s,isOpen:r=!0}=t,n=S(t,b),c=i();/*#__PURE__*/return e.createElement(a.div,v({__css:c.content},n,{className:u(\"saas-stepper__content\",t.className)}),/*#__PURE__*/e.createElement(l,{in:r},s))};d&&(w.displayName=\"StepperContent\");const j=t=>{const{icon:s,isCompleted:r,className:n}=t,l=S(t,k),o=v({display:\"flex\",alignItems:\"center\",justifyContent:\"center\",borderRadius:\"full\",fontSize:\"1em\",me:2},i().icon);let m;return m=r?/*#__PURE__*/e.createElement(c,{as:p}):s,/*#__PURE__*/e.createElement(a.div,v({__css:o},l,{className:u(\"saas-stepper__icon\",n)}),m)};d&&(j.displayName=\"StepperIcon\");const L=t=>{const{title:s,icon:r,isActive:n,isCompleted:c}=t,p=S(t,A),l=y(t),o=v({display:\"flex\",alignItems:\"center\",flexDirection:\"row\"},i().step);/*#__PURE__*/return e.createElement(a.div,v({__css:o,\"data-active\":l.isActive,\"data-completed\":l.isCompleted},p,{className:u(\"saas-stepper__step\",t.className)}),/*#__PURE__*/e.createElement(j,{icon:r,isActive:n,isCompleted:c}),s&&/*#__PURE__*/e.createElement(R,null,s))};d&&(L.displayName=\"StepperStep\");const F=t=>{const{isActive:s}=t,r=S(t,O),n=v({flex:1,borderTopWidth:\"1px\",mx:2},i().separator);/*#__PURE__*/return e.createElement(a.div,v({\"data-active\":s},r,{className:u(\"saas-stepper__separator\",t.className),__css:n}))};d&&(F.displayName=\"StepperSeparator\");const R=t=>{const s=i();/*#__PURE__*/return e.createElement(a.p,v({},t,{__css:s.title,className:u(\"saas-stepper__title\",t.className)}))};d&&(R.displayName=\"StepperStepTitle\");const T=t=>{const s=i();/*#__PURE__*/return e.createElement(a.div,v({__css:s.completed},t,{className:u(\"saas-stepper__completed\",t.className)}))};d&&(T.displayName=\"StepperCompleted\");export{D as Stepper,T as StepperCompleted,w as StepperContent,j as StepperIcon,_ as StepperProvider,F as StepperSeparator,L as StepperStep,R as StepperStepTitle,I as StepperSteps,C as useNext,x as usePrev,y as useStep,h as useStepper,N as useStepperContext};\n//# sourceMappingURL=index.modern.js.map\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler } from 'react-hook-form'\nimport { createContext } from '@chakra-ui/react-utils'\nimport {\n useStepper,\n useStep,\n UseStepperProps,\n UseStepperReturn,\n} from '@saas-ui/stepper'\n\nexport interface StepState {\n name: string\n schema?: any\n resolver?: any\n isActive?: boolean\n isCompleted?: boolean\n}\n\nexport interface StepFormContext extends UseStepperReturn {\n updateStep(state: StepState): void\n steps: Record<string, StepState>\n}\n\nexport const [StepFormProvider, useStepFormContext] =\n createContext<StepFormContext>({\n name: 'StepFormContext',\n errorMessage:\n 'useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`',\n })\n\nimport { FormProps } from './form'\n\nexport interface UseStepFormProps<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperProps,\n FormProps<TFieldValues> {}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n) {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(\n (props) => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n },\n [steps, onSubmitStep, activeStep]\n )\n\n const updateStep = React.useCallback(\n (step) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport type UseStepFormReturn = ReturnType<typeof useStepForm>\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {\n chakra,\n HTMLChakraProps,\n useMultiStyleConfig,\n StylesProvider,\n} from '@chakra-ui/system'\n\nimport { callAllHandlers, runIfFn, cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n StepperProvider,\n StepperSteps,\n StepperStepsProps,\n StepperStep,\n useStepperContext,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form, FormProps } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues>,\n FormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps(props)}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const styles = useMultiStyleConfig('Stepper', props)\n\n const { children } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n return (\n <StylesProvider value={styles}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StylesProvider>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, ...rest } = props\n const step = useFormStep({ name, schema, resolver })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n"],"names":["FormValue","name","getValues","useFormContext","inputTypes","BaseField","props","label","help","variant","hideLabel","children","controlProps","error","formState","get","errors","getError","React","FormControl","isInvalid","FormLabel","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","withControlledInput","InputComponent","rules","inputProps","Controller","control","render","field","_ref","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","getFieldResolver","FormLayoutItem","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","id","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","errorMessage","StepperProvider","useStepperContext","useStepper","step","useState","activeIndex","setIndex","stepsRef","useRef","onUpdate","Date","now","registerStep","newSteps","current","indexOf","push","setStep","useLayoutEffect","activeStep","isFirstStep","isLastStep","isCompleted","nextStep","prevStep","unregisterStep","useStep","isActive","StepFormProvider","useStepFormContext","useStepForm","stepper","steps","updateSteps","onSubmitStep","data","then","updateStep","getFormProps","useFormStep","StepForm","ctx","runIfFn","FormStep","className","cx","__DEV__","PrevButton","callAllHandlers","NextButton","htmlFor","Text","fontSize","condition","useWatch","disabled","exact","isExact","useMultiStyleConfig","elements","StepperStep","title","StylesProvider","StepperSteps"],"mappings":"ynCAgCaA,EAAwC,gBAAGC,IAAAA,KAEtD,OAAOC,EADeC,mBAAdD,WACSD,IAAS,kPC8EtBG,EAAsC,GAmB/BC,EAAkC,SAACC,GAC9C,IAAQL,EACNK,EADML,KAAMM,EACZD,EADYC,MAAOC,EACnBF,EADmBE,KAAMC,EACzBH,EADyBG,QAASC,EAClCJ,EADkCI,UAAWC,EAC7CL,EAD6CK,SAAaC,IAC1DN,KAIIO,EAjBS,SAACZ,EAAca,GAC9B,OAAOC,MAAID,EAAUE,OAAQf,GAgBfgB,CAAShB,EAFDE,mBAAdW,wBAIR,OACEI,gBAACC,iBAAYV,QAASA,GAAaG,GAAcQ,YAAaP,IAC3DN,IAAUG,eACTQ,gBAACG,aAAUZ,QAASA,GAAUF,GAC5B,kBACJW,gBAACI,WACEX,GACAH,SAASK,GAAAA,EAAOU,QAEb,kBADFL,gBAACM,sBAAgBhB,UAElBK,SAAAA,EAAOU,uBACNL,gBAACO,8BAAkBZ,SAAAA,EAAOU,YAMvBG,EAAQC,aACnB,SACErB,EAGAsB,GAEA,MAAoCtB,EAA5BuB,kBAGR,OAAOX,gBAjDFd,aAHgB,WAGIA,EAAU,QAiDZwB,IAAKA,GAAStB,MAkE5BwB,EAAsB,SAACC,GAClC,OAAOJ,aACL,WAAiCC,OAA9B3B,IAAAA,KAAM+B,IAAAA,MAAUC,WACG9B,gCAEpB,OACEe,gBAACgB,cACCjC,KAAMA,EACNkC,UALIA,QAMJH,MAAOA,EACPI,OAAQ,oBAAGC,MAAcC,IAALV,IAAcS,6BAChCnB,gBAACa,OACKM,EACAJ,GACJL,IAAKW,eAAaX,EAAKU,YASxBE,EAAwB,SAACT,GACpC,OAAOJ,aACL,WAAiCC,OAA9B3B,IAAAA,KAAM+B,IAAAA,M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,SAASrE,IAFXhD,EAAbK,SAEsC,SAACiH,GAC7C,GAAI1G,EAAM2G,eAAeD,WAAUA,SAAAA,EAAO/F,QAAS+N,GAAU,CAC3D,MAAwBJ,GAAY5H,EAAMtH,oBAC1C,OACEY,gBAAC2P,IACC5Q,KAAM2H,EAAMtH,MAAML,KAClB6Q,MAAOlJ,EAAMtH,MAAMwQ,MACnBvC,cALIA,aAOH3G,EAAMtH,MAAMK,UAInB,OAAOiH,iBAGT,OACE1G,gBAAC6P,kBAAe3G,MAAOqB,gBACrBvK,gBAAC8P,MAAatG,GAAG,KAAQpK,GACtBsQ"}
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","../../saas-ui-stepper/dist/index.modern.js","../src/use-step-form.tsx","../src/step-form.tsx","../src/display-if.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">\n <FormValue name={name} />\n </Text>\n </FormControl>\n )\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\nimport { FocusableElement } from '@chakra-ui/utils'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<FocusableElement>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema) =>\n schema &&\n Object.entries(schema).map(([name, field]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses a different 'id' field\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n UseArrayFieldReturn,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField = React.forwardRef(\n (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer ref={ref} {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n }\n)\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer = React.forwardRef(\n (\n {\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n }: ArrayFieldProps,\n ref: React.ForwardedRef<UseArrayFieldReturn>\n ) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n // This exposes the useArrayField api through the forwarded ref\n React.useImperativeHandle(ref, () => context, [ref, context])\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n }\n)\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyles()\n return <FormLabel as=\"legend\" sx={styles.legend} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n","import * as React from 'react'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n submitLabel?: false | string\n schema: any\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', fieldResolver, ...rest } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & { getFieldResolver?: (schema: any) => FieldResolver }\n","import*as e from\"react\";import{forwardRef as t,useMultiStyleConfig as s,omitThemingProps as n,StylesProvider as r,chakra as a,useStyles as i}from\"@chakra-ui/system\";import{Icon as c,CheckIcon as l}from\"@chakra-ui/icons\";import{Collapse as p}from\"@saas-ui/collapse\";import{getChildrenOfType as o,getChildOfType as m}from\"@saas-ui/react-utils\";import{cx as u,__DEV__ as d,dataAttr as f}from\"@chakra-ui/utils\";import{createContext as S}from\"@chakra-ui/react-utils\";function v(){return v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(e[n]=s[n])}return e},v.apply(this,arguments)}function _(e,t){if(null==e)return{};var s,n,r={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(s=a[n])>=0||(r[s]=e[s]);return r}const[h,N]=S({name:\"StepperContext\",errorMessage:\"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`\"});function y(t){const{step:s}=t,[n,r]=e.useState(-1),a=e.useRef([]),[,i]=e.useState(Date.now()),c=e.useCallback(e=>{const t=[...a.current];-1===t.indexOf(e)&&t.push(e),a.current=t,i(Date.now())},[a,i]),l=e=>{const t=a.current.indexOf(e);-1!==t&&r(t)};return e.useEffect(()=>{\"string\"==typeof s?l(s):\"number\"==typeof s?r(s):-1===n&&r(0)},[s]),{stepsRef:a,activeStep:a.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===a.current.length-1,isCompleted:n>=a.current.length,setIndex:r,setStep:l,nextStep:()=>{r(n+1)},prevStep:()=>{r(n-1)},registerStep:c,unregisterStep:e=>{a.current=a.current.slice(a.current.indexOf(e),1)}}}function x(t){const{name:s,isActive:n,isCompleted:r}=t,{registerStep:a,unregisterStep:i,activeStep:c}=N();return e.useEffect(()=>{if(s)return a(s),()=>{i(s)}},[]),{isActive:s?c===s:n,isCompleted:r}}function C({label:e=\"Back\"}={}){const{isFirstStep:t,prevStep:s}=N();return{isDisabled:t,onClick:s,label:e}}function E({label:e=\"Next\",submitLabel:t=\"Submit\"}={}){const{isLastStep:s,isCompleted:n,nextStep:r}=N();return{isDisabled:n,onClick:r,label:s?t:e}}const g=[\"children\",\"orientation\",\"step\"],b=[\"children\",\"orientation\",\"stepComponent\"],k=[\"children\",\"isOpen\"],A=[\"icon\",\"isActive\",\"isCompleted\",\"className\"],O=[\"title\",\"icon\",\"isActive\",\"isCompleted\"],D=[\"isActive\"],I=t((t,i)=>{const{children:c,orientation:l=\"horizontal\"}=t,p=_(t,g),o=s(\"Stepper\",v({},p,{orientation:l})),m=n(p),d=y(t),f=v({display:\"flex\",flexDirection:\"column\"},o.container);/*#__PURE__*/return e.createElement(r,{value:o},/*#__PURE__*/e.createElement(h,{value:d},/*#__PURE__*/e.createElement(a.div,v({ref:i,__css:f},m,{className:u(\"saas-stepper\",t.className)}),/*#__PURE__*/e.createElement(w,{orientation:l},c))))});d&&(I.displayName=\"Stepper\");const w=t=>{var s,n;const{children:r,orientation:c=\"horizontal\",stepComponent:l}=t,p=_(t,b),d=i(),{activeIndex:f}=N(),S=v({display:\"flex\",flexDirection:\"row\",alignItems:\"center\"},d.steps),h=\"vertical\"===c,y=l||F,x=o(r,y),C=x.reduce((t,s,n,r)=>(t.push(/*#__PURE__*/e.createElement(y,v({key:n},s.props,{icon:s.props.icon||n+1,isActive:f===n,isCompleted:s.props.isCompleted||f>n}))),h&&t.push(/*#__PURE__*/e.createElement(j,{key:`content-${n}`,isOpen:f===n},s.props.children)),n<r.length-1&&t.push(/*#__PURE__*/e.createElement(L,{key:`separator-${n}`,isActive:n<f})),t),[]),E=m(r,$),g=f>=x.length?E:h?null:/*#__PURE__*/e.createElement(j,null,null==(s=x[f])||null==(n=s.props)?void 0:n.children);/*#__PURE__*/return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(a.div,v({__css:S},p,{className:u(\"saas-stepper__steps\",t.className)}),C),g)};d&&(w.displayName=\"StepperSteps\");const j=t=>{const{children:s,isOpen:n=!0}=t,r=_(t,k),c=i();/*#__PURE__*/return e.createElement(a.div,v({__css:c.content},r,{className:u(\"saas-stepper__content\",t.className)}),/*#__PURE__*/e.createElement(p,{in:n},s))};d&&(j.displayName=\"StepperContent\");const z=t=>{const{icon:s,isCompleted:n,className:r}=t,p=_(t,A),o=v({display:\"flex\",alignItems:\"center\",justifyContent:\"center\",borderRadius:\"full\",fontSize:\"1em\"},i().icon);let m;return m=n?/*#__PURE__*/e.createElement(c,{as:l}):s,/*#__PURE__*/e.createElement(a.div,v({__css:o},p,{className:u(\"saas-stepper__icon\",r)}),m)};d&&(z.displayName=\"StepperIcon\");const F=t=>{const{title:s,icon:n,isActive:r,isCompleted:c}=t,l=_(t,O),p=x(t),o=v({display:\"flex\",alignItems:\"center\",flexDirection:\"row\"},i().step);/*#__PURE__*/return e.createElement(a.div,v({},l,{__css:o,\"data-active\":f(p.isActive),\"data-completed\":f(p.isCompleted),className:u(\"saas-stepper__step\",t.className)}),/*#__PURE__*/e.createElement(z,{icon:n,isActive:r,isCompleted:c}),s&&/*#__PURE__*/e.createElement(R,null,s))};d&&(F.displayName=\"StepperStep\");const L=t=>{const{isActive:s}=t,n=_(t,D),r=v({flex:1,mx:2},i().separator);/*#__PURE__*/return e.createElement(a.div,v({},n,{\"data-active\":f(s),className:u(\"saas-stepper__separator\",t.className),__css:r}))};d&&(L.displayName=\"StepperSeparator\");const R=t=>{const s=i();/*#__PURE__*/return e.createElement(a.p,v({},t,{__css:s.title,className:u(\"saas-stepper__title\",t.className)}))};d&&(R.displayName=\"StepperStepTitle\");const $=t=>{const s=i();/*#__PURE__*/return e.createElement(a.div,v({__css:s.completed},t,{className:u(\"saas-stepper__completed\",t.className)}))};d&&($.displayName=\"StepperCompleted\");export{I as Stepper,$ as StepperCompleted,j as StepperContent,z as StepperIcon,h as StepperProvider,L as StepperSeparator,F as StepperStep,R as StepperStepTitle,w as StepperSteps,E as useNext,C as usePrev,x as useStep,y as useStepper,N as useStepperContext};\n//# sourceMappingURL=index.modern.js.map\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler } from 'react-hook-form'\nimport { createContext } from '@chakra-ui/react-utils'\nimport {\n useStepper,\n useStep,\n UseStepperProps,\n UseStepperReturn,\n} from '@saas-ui/stepper'\n\nexport interface StepState {\n name: string\n schema?: any\n resolver?: any\n isActive?: boolean\n isCompleted?: boolean\n}\n\nexport interface StepFormContext extends UseStepperReturn {\n updateStep(state: StepState): void\n steps: Record<string, StepState>\n}\n\nexport const [StepFormProvider, useStepFormContext] =\n createContext<StepFormContext>({\n name: 'StepFormContext',\n errorMessage:\n 'useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`',\n })\n\nimport { FormProps } from './form'\n\nexport interface UseStepFormProps<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperProps,\n FormProps<TFieldValues> {}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n) {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(\n (props) => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n },\n [steps, onSubmitStep, activeStep]\n )\n\n const updateStep = React.useCallback(\n (step) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport type UseStepFormReturn = ReturnType<typeof useStepForm>\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {\n chakra,\n HTMLChakraProps,\n useMultiStyleConfig,\n StylesProvider,\n} from '@chakra-ui/system'\n\nimport { callAllHandlers, runIfFn, cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n StepperProvider,\n StepperSteps,\n StepperStepsProps,\n StepperStep,\n useStepperContext,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form, FormProps } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues>,\n FormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps(props)}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const styles = useMultiStyleConfig('Stepper', props)\n\n const { children } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n return (\n <StylesProvider value={styles}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StylesProvider>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, ...rest } = props\n const step = useFormStep({ name, schema, resolver })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n"],"names":["FormValue","name","getValues","useFormContext","inputTypes","BaseField","props","label","help","variant","hideLabel","children","controlProps","error","formState","get","errors","getError","React","FormControl","isInvalid","FormLabel","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","withControlledInput","InputComponent","rules","inputProps","Controller","control","render","field","_ref","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","getFieldResolver","FormLayoutItem","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","id","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","errorMessage","StepperProvider","useStepperContext","useStepper","step","useState","activeIndex","setIndex","stepsRef","useRef","onUpdate","Date","now","registerStep","newSteps","current","indexOf","push","setStep","activeStep","isFirstStep","isLastStep","isCompleted","nextStep","prevStep","unregisterStep","useStep","isActive","StepFormProvider","useStepFormContext","useStepForm","stepper","steps","updateSteps","onSubmitStep","data","then","updateStep","getFormProps","useFormStep","StepForm","ctx","runIfFn","FormStep","className","cx","__DEV__","PrevButton","callAllHandlers","NextButton","htmlFor","Text","fontSize","condition","useWatch","disabled","exact","isExact","useMultiStyleConfig","elements","StepperStep","title","StylesProvider","StepperSteps"],"mappings":"ynCAgCaA,EAAwC,gBAAGC,IAAAA,KAEtD,OAAOC,EADeC,mBAAdD,WACSD,IAAS,kPC8EtBG,EAAsC,GAmB/BC,EAAkC,SAACC,GAC9C,IAAQL,EACNK,EADML,KAAMM,EACZD,EADYC,MAAOC,EACnBF,EADmBE,KAAMC,EACzBH,EADyBG,QAASC,EAClCJ,EADkCI,UAAWC,EAC7CL,EAD6CK,SAAaC,IAC1DN,KAIIO,EAjBS,SAACZ,EAAca,GAC9B,OAAOC,MAAID,EAAUE,OAAQf,GAgBfgB,CAAShB,EAFDE,mBAAdW,wBAIR,OACEI,gBAACC,iBAAYV,QAASA,GAAaG,GAAcQ,YAAaP,IAC3DN,IAAUG,eACTQ,gBAACG,aAAUZ,QAASA,GAAUF,GAC5B,kBACJW,gBAACI,WACEX,GACAH,SAASK,GAAAA,EAAOU,QAEb,kBADFL,gBAACM,sBAAgBhB,UAElBK,SAAAA,EAAOU,uBACNL,gBAACO,8BAAkBZ,SAAAA,EAAOU,YAMvBG,EAAQC,aACnB,SACErB,EAGAsB,GAEA,MAAoCtB,EAA5BuB,kBAGR,OAAOX,gBAjDFd,aAHgB,WAGIA,EAAU,QAiDZwB,IAAKA,GAAStB,MAkE5BwB,EAAsB,SAACC,GAClC,OAAOJ,aACL,WAAiCC,OAA9B3B,IAAAA,KAAM+B,IAAAA,MAAUC,WACG9B,gCAEpB,OACEe,gBAACgB,cACCjC,KAAMA,EACNkC,UALIA,QAMJH,MAAOA,EACPI,OAAQ,oBAAGC,MAAcC,IAALV,IAAcS,6BAChCnB,gBAACa,OACKM,EACAJ,GACJL,IAAKW,eAAaX,EAAKU,YASxBE,EAAwB,SAACT,GACpC,OAAOJ,aACL,WAAiCC,OAA9B3B,IAAAA,KAAM+B,IAAAA,MAAUC,YAGeQ,EAFXt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hD,EAAbK,SAEsC,SAACiH,GAC7C,GAAI1G,EAAM2G,eAAeD,WAAUA,SAAAA,EAAO/F,QAAS8N,GAAU,CAC3D,MAAwBJ,GAAY3H,EAAMtH,oBAC1C,OACEY,gBAAC0P,IACC3Q,KAAM2H,EAAMtH,MAAML,KAClB4Q,MAAOjJ,EAAMtH,MAAMuQ,MACnBvC,cALIA,aAOH1G,EAAMtH,MAAMK,UAInB,OAAOiH,iBAGT,OACE1G,gBAAC4P,kBAAe1G,MAAOqB,gBACrBvK,gBAAC6P,MAAarG,GAAG,KAAQpK,GACtBqQ"}
@@ -1,2 +1,2 @@
1
- import*as e from"react";import{useFormContext as t,get as r,Controller as n,useForm as l,FormProvider as a,useFieldArray as s,useWatch as i}from"react-hook-form";import{FormControl as o,FormLabel as c,Text as m,forwardRef as d,Switch as u,Checkbox as p,Box as f,FormHelperText as h,FormErrorMessage as v,useMergeRefs as E,Input as b,Textarea as y,chakra as g,useTheme as S,SimpleGrid as x,useStyles as N,Collapse as C}from"@chakra-ui/react";import{NumberInput as _}from"@saas-ui/number-input";import{PasswordInput as k}from"@saas-ui/password-input";import{RadioInput as F}from"@saas-ui/radio";import{PinInput as R}from"@saas-ui/pin-input";import{Select as I,NativeSelect as V}from"@saas-ui/select";import{get as L,cx as w,__DEV__ as O,runIfFn as A,callAllHandlers as D}from"@chakra-ui/utils";import{chakra as j,forwardRef as M,useMultiStyleConfig as U,omitThemingProps as P,StylesProvider as $,useStyles as B}from"@chakra-ui/system";import{MinusIcon as q,AddIcon as z,Icon as G,CheckIcon as H}from"@chakra-ui/icons";import{IconButton as T,Button as W}from"@saas-ui/button";import{createContext as J}from"@chakra-ui/react-utils";import{getChildrenOfType as K,getChildOfType as Q}from"@saas-ui/react-utils";export*from"@saas-ui/input-right-button";function X(){return X=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},X.apply(this,arguments)}function Y(e,t){if(null==e)return{};var r,n,l={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(l[r]=e[r]);return l}const Z=["name","label","placeholder"],ee=t=>{let{name:r,label:n}=t,l=Y(t,Z);/*#__PURE__*/return e.createElement(o,l,n?/*#__PURE__*/e.createElement(c,{htmlFor:r},n):null,/*#__PURE__*/e.createElement(m,{fontSize:"md"},/*#__PURE__*/e.createElement(te,{name:r})))},te=({name:e})=>{const{getValues:r}=t();return r(e)||null},re=["name","label","help","variant","hideLabel","children"],ne=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],le=["name","rules"],ae=["ref"],se=["name","rules"],ie=["ref"],oe=["label"],ce=["label"],me={},de="text",ue=n=>{const{name:l,label:a,help:s,variant:i,hideLabel:m,children:d}=n,u=Y(n,re),{formState:p}=t(),E=((e,t)=>r(t.errors,e))(l,p);/*#__PURE__*/return e.createElement(o,X({variant:i},u,{isInvalid:!!E}),a&&!m?/*#__PURE__*/e.createElement(c,{variant:i},a):null,/*#__PURE__*/e.createElement(f,null,d,!s||null!=E&&E.message?null:/*#__PURE__*/e.createElement(h,null,s),(null==E?void 0:E.message)&&/*#__PURE__*/e.createElement(v,null,null==E?void 0:E.message)))},pe=d((t,r)=>{const{type:n=de}=t,l=(e=>me[e]||me[de])(n);/*#__PURE__*/return e.createElement(l,X({ref:r},t))}),fe=r=>d((l,a)=>{let{name:s,rules:i}=l,o=Y(l,le);const{control:c}=t();/*#__PURE__*/return e.createElement(n,{name:s,control:c,rules:i,render:t=>{let{field:{ref:n}}=t,l=Y(t.field,ae);/*#__PURE__*/return e.createElement(r,X({},l,o,{ref:E(a,n)}))}})}),he=r=>d((n,l)=>{let{name:a,rules:s}=n,i=Y(n,se);const{register:o}=t(),c=o(a,s),{ref:m}=c,d=Y(c,ie);/*#__PURE__*/return e.createElement(r,X({},d,i,{ref:E(l,m)}))}),ve=(t,r,n)=>{let l;l=null!=n&&n.isControlled?fe(r):he(r);const a=((t,{displayName:r,hideLabel:n,BaseField:l})=>{const a=d((r,a)=>{const{name:s,label:i,help:o,isDisabled:c,isInvalid:m,isReadOnly:d,isRequired:u,rules:p,variant:f}=r,h=Y(r,ne),v=X({required:u},p);/*#__PURE__*/return e.createElement(l,{name:s,label:i,help:o,hideLabel:n,isDisabled:c,isInvalid:m,isReadOnly:d,isRequired:u,variant:f},/*#__PURE__*/e.createElement(t,X({ref:a,name:s,label:i,rules:v},h)))});return a.displayName=r,a})(l,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||ue});return me[t]=a,a},Ee=ve("text",b),be=ve("number",_,{isControlled:!0}),ye=ve("password",k),ge=ve("textarea",y),Se=ve("switch",d((t,r)=>{let{label:n}=t,l=Y(t,oe);/*#__PURE__*/return e.createElement(u,X({ref:r},l),n)}),{isControlled:!0,hideLabel:!0}),xe=ve("select",I,{isControlled:!0}),Ne=ve("checkbox",d((t,r)=>{let{label:n}=t,l=Y(t,ce);/*#__PURE__*/return e.createElement(p,X({ref:r},l),n)}),{hideLabel:!0}),Ce=ve("radio",F,{isControlled:!0}),_e=ve("pin",R,{isControlled:!0}),ke=ve("native-select",V,{isControlled:!0}),Fe=e=>e&&Object.entries(e).map(([e,t])=>X({},t,{name:e})),Re=e=>({getFields:()=>Fe(e),getNestedFields:t=>{var r;const n=L(e,t);return n?"object"===(null==(r=n.items)?void 0:r.type)?Fe(n.items.properties):"object"===n.type?Fe(n.properties):[n.items]:[]}}),Ie=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Ve=d((t,r)=>{const{mode:n="all",resolver:s,reValidateMode:i,shouldFocusError:o,shouldUnregister:c,shouldUseNativeValidation:m,criteriaMode:d,delayError:u,schema:p,defaultValues:f,onSubmit:h,onError:v,formRef:E,children:b}=t,y=Y(t,Ie),S={mode:n,resolver:s,defaultValues:f,reValidateMode:i,shouldFocusError:o,shouldUnregister:c,shouldUseNativeValidation:m,criteriaMode:d,delayError:u};p&&!s&&(S.resolver=null==Ve.getResolver?void 0:Ve.getResolver(p));const x=l(S),{handleSubmit:N}=x;return e.useImperativeHandle(r,()=>x,[r,x]),/*#__PURE__*/e.createElement(a,x,/*#__PURE__*/e.createElement(g.form,X({ref:E,onSubmit:N(h,v)},y),b))});Ve.getFieldResolver=Re;const Le=["children"],we=({children:t})=>/*#__PURE__*/e.createElement(g.div,null,t),Oe=t=>{var r,n,l;let{children:a}=t,s=Y(t,Le);const i=X({},null!=(r=null==(n=S().components)||null==(l=n.FormLayout)?void 0:l.defaultProps)?r:{spacing:4},s);/*#__PURE__*/return e.createElement(x,i,e.Children.map(a,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(we,null,t):t))},Ae=(t,r)=>e.Children.map(r,r=>e.isValidElement(r)&&r.props.name?e.cloneElement(r,X({},r.props,{name:`${t}.${r.props.name}`})):r),[De,je]=J({name:"ArrayFieldContext"}),[Me,Ue]=J({name:"ArrayFieldRowContext"}),Pe=({name:e,defaultValue:r={},keyName:n,min:l,max:a})=>{const{control:i}=t();return X({},s({control:i,name:e,keyName:n}),{name:e,defaultValue:r,min:l,max:a})},$e=({index:r})=>{const{clearErrors:n}=t(),{name:l,remove:a,fields:s}=je();return e.useEffect(()=>{n(l)},[]),{index:r,isFirst:0===r,isLast:r===s.length-1,name:`${l}.${r}`,remove:e.useCallback(()=>{n(l),a(r)},[r])}},Be=()=>{const{isFirst:e,remove:t}=Ue(),{min:r,fields:n}=je();return{onClick:()=>t(),isDisabled:e&&!!(r&&n.length<=r)}},qe=()=>{const{append:e,defaultValue:t,max:r,fields:n}=je();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(r&&n.length>=r)}},ze=["children","columns","spacing"],Ge=["children"],He=["name","defaultValue","keyName","min","max","children"],Te=({children:t,columns:r,spacing:n,index:l})=>/*#__PURE__*/e.createElement(Je,{index:l},/*#__PURE__*/e.createElement(We,{columns:r,spacing:n},t),/*#__PURE__*/e.createElement(Ke,null)),We=t=>{let{children:r,columns:n,spacing:l}=t,a=Y(t,ze);const{name:s}=Ue();/*#__PURE__*/return e.createElement(Oe,X({flex:"1",columns:n,gridGap:l,mr:"2"},a),Ae(s,r))},Je=({children:t,index:r})=>{const n=$e({index:r});/*#__PURE__*/return e.createElement(Me,{value:n},/*#__PURE__*/e.createElement(j.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},Ke=t=>/*#__PURE__*/e.createElement(T,X({icon:/*#__PURE__*/e.createElement(q,null),"aria-label":"Remove row"},Be(),t)),Qe=t=>/*#__PURE__*/e.createElement(T,X({icon:/*#__PURE__*/e.createElement(z,null),"aria-label":"Add row",float:"right"},qe(),t)),Xe=e.forwardRef((t,r)=>{const{children:n}=t,l=Y(t,Ge);/*#__PURE__*/return e.createElement(Ze,X({ref:r},l),/*#__PURE__*/e.createElement(Ye,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},r)=>/*#__PURE__*/e.createElement(Te,{key:t,index:r},n)))),/*#__PURE__*/e.createElement(Qe,null))}),Ye=({children:e})=>{const{fields:t}=je();return e(t)},Ze=e.forwardRef((t,r)=>{let{name:n,defaultValue:l,keyName:a,min:s,max:i,children:o}=t,c=Y(t,He);const m=Pe({name:n,defaultValue:l,keyName:a,min:s,max:i});return e.useImperativeHandle(r,()=>m,[r,m]),/*#__PURE__*/e.createElement(De,{value:m},/*#__PURE__*/e.createElement(ue,X({name:n},c),o))}),et=["name","label","hideLabel","children","columns","spacing"],tt=t=>{const r=N();/*#__PURE__*/return e.createElement(c,X({as:"legend",sx:r.legend},t))},rt=t=>{const{name:r,label:n,hideLabel:l,children:a,columns:s,spacing:i}=t,c=Y(t,et);/*#__PURE__*/return e.createElement(o,X({name:r,as:"fieldset"},c),/*#__PURE__*/e.createElement(tt,{display:l?"none":"block"},n),/*#__PURE__*/e.createElement(Oe,{columns:s,gridGap:i},Ae(r,a)))},nt=["name","type"],lt=["schema","fieldResolver"],at=["name","type","defaultValue"],st=(t,r)=>{var n;return null==(n=t.getNestedFields(r))?void 0:n.map((t,r)=>{let{name:n,type:l}=t,a=Y(t,nt);/*#__PURE__*/return e.createElement(pe,X({key:n||r,name:n,type:l},a))})},it=t=>{let{schema:r,fieldResolver:n}=t,l=Y(t,lt);const a=e.useMemo(()=>n||Ve.getFieldResolver(r),[r,n]);/*#__PURE__*/return e.createElement(Oe,l,a.getFields().map(t=>{let{name:r,type:n}=t,l=Y(t,at);return"array"===n?/*#__PURE__*/e.createElement(Xe,X({key:r,name:r},l),st(a,r)):"object"===n?/*#__PURE__*/e.createElement(rt,X({key:r,name:r},l),st(a,r)):/*#__PURE__*/e.createElement(pe,X({key:r,name:r,type:n},l))}))},ot=["children","disableIfUntouched","disableIfInvalid"],ct=M((r,n)=>{const{children:l,disableIfUntouched:a,disableIfInvalid:s}=r,i=Y(r,ot),{formState:o}=t();/*#__PURE__*/return e.createElement(W,X({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:n,isDisabled:a&&!o.isDirty||s&&!o.isValid},i),l)});ct.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};const mt=["schema","submitLabel","fieldResolver"],dt=d((t,r)=>{const{schema:n,submitLabel:l="Submit",fieldResolver:a}=t,s=Y(t,mt);/*#__PURE__*/return e.createElement(Ve,X({},s,{schema:n,ref:r}),/*#__PURE__*/e.createElement(Oe,null,/*#__PURE__*/e.createElement(it,{schema:n,fieldResolver:a}),l&&/*#__PURE__*/e.createElement(ct,{label:l})))}),ut=({children:e,name:r,defaultValue:n,isDisabled:l,isExact:a,condition:s=(e=>!!e)})=>s(i({name:r,defaultValue:n,disabled:l,exact:a}),t())?e:null;function pt(){return pt=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},pt.apply(this,arguments)}function ft(e,t){if(null==e)return{};var r,n,l={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(l[r]=e[r]);return l}const[ht,vt]=J({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"});function Et(t){const{step:r}=t,[n,l]=e.useState(-1),a=e.useRef([]),[,s]=e.useState(Date.now()),i=e.useCallback(e=>{const t=[...a.current];-1===t.indexOf(e)&&t.push(e),a.current=t,s(Date.now())},[a,s]),o=e=>{const t=a.current.indexOf(e);-1!==t&&l(t)};return e.useLayoutEffect(()=>{"string"==typeof r?o(r):"number"==typeof r?l(r):-1===n&&l(0)},[r]),{stepsRef:a,activeStep:a.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===a.current.length-1,isCompleted:n>=a.current.length,setIndex:l,setStep:o,nextStep:()=>{l(n+1)},prevStep:()=>{l(n-1)},registerStep:i,unregisterStep:e=>{a.current=a.current.slice(a.current.indexOf(e),1)}}}function bt(t){const{name:r,isActive:n,isCompleted:l}=t,{registerStep:a,unregisterStep:s,activeStep:i}=vt();return e.useEffect(()=>{if(r)return a(r),()=>{s(r)}},[]),{isActive:r?i===r:n,isCompleted:l}}const yt=["children","orientation"],gt=["children","orientation","stepComponent"],St=["children","isOpen"],xt=["icon","isActive","isCompleted","className"],Nt=["title","icon","isActive","isCompleted"],Ct=["isActive"],_t=M((t,r)=>{const n=U("Stepper",t),l=P(t),{children:a,orientation:s}=l,i=ft(l,yt),o=Et(t),c=pt({display:"flex",flexDirection:"column"},n.container);return e.createElement($,{value:n},/*#__PURE__*/e.createElement(ht,{value:o},/*#__PURE__*/e.createElement(j.div,pt({ref:r,__css:c},i,{className:w("saas-stepper__container",t.className)}),/*#__PURE__*/e.createElement(kt,{orientation:s},a))))});O&&(_t.displayName="Stepper");const kt=t=>{var r,n;const{children:l,orientation:a,stepComponent:s}=t,i=ft(t,gt),o=B(),{activeIndex:c}=vt(),m=pt({display:"flex",flexDirection:"row",alignItems:"center"},o.steps),d="vertical"===a,u=s||It,p=K(l,u),f=p.reduce((t,r,n,l)=>(t.push(/*#__PURE__*/e.createElement(u,pt({key:n},r.props,{icon:r.props.icon||n+1,isActive:c===n,isCompleted:r.props.isCompleted||c>n}))),"vertical"===a&&t.push(/*#__PURE__*/e.createElement(Ft,{key:`content-${n}`,isOpen:c===n},r.props.children)),n<l.length-1&&t.push(/*#__PURE__*/e.createElement(Vt,{key:`separator-${n}`,isActive:n<c})),t),[]),h=Q(l,wt),v=c>=p.length?h:d?null:/*#__PURE__*/e.createElement(Ft,null,null==(r=p[c])||null==(n=r.props)?void 0:n.children);return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(j.div,pt({__css:m},i,{className:w("saas-stepper__steps",t.className)}),f),v)};O&&(kt.displayName="StepperSteps");const Ft=t=>{const{children:r,isOpen:n=!0}=t,l=ft(t,St),a=B();return e.createElement(j.div,pt({__css:a.content},l,{className:w("saas-stepper__content",t.className)}),/*#__PURE__*/e.createElement(C,{in:n},r))};O&&(Ft.displayName="StepperContent");const Rt=t=>{const{icon:r,isCompleted:n,className:l}=t,a=ft(t,xt),s=pt({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},B().icon);let i;return i=n?/*#__PURE__*/e.createElement(G,{as:H}):r,/*#__PURE__*/e.createElement(j.div,pt({__css:s},a,{className:w("saas-stepper__icon",l)}),i)};O&&(Rt.displayName="StepperIcon");const It=t=>{const{title:r,icon:n,isActive:l,isCompleted:a}=t,s=ft(t,Nt),i=bt(t),o=pt({display:"flex",alignItems:"center",flexDirection:"row"},B().step);return e.createElement(j.div,pt({__css:o,"data-active":i.isActive,"data-completed":i.isCompleted},s,{className:w("saas-stepper__step",t.className)}),/*#__PURE__*/e.createElement(Rt,{icon:n,isActive:l,isCompleted:a}),r&&/*#__PURE__*/e.createElement(Lt,null,r))};O&&(It.displayName="StepperStep");const Vt=t=>{const{isActive:r}=t,n=ft(t,Ct),l=pt({flex:1,borderTopWidth:"1px",mx:2},B().separator);return e.createElement(j.div,pt({"data-active":r},n,{className:w("saas-stepper__separator",t.className),__css:l}))};O&&(Vt.displayName="StepperSeparator");const Lt=t=>{const r=B();return e.createElement(j.p,pt({},t,{__css:r.title,className:w("saas-stepper__title",t.className)}))};O&&(Lt.displayName="StepperStepTitle");const wt=t=>{const r=B();return e.createElement(j.div,pt({__css:r.completed},t,{className:w("saas-stepper__completed",t.className)}))};O&&(wt.displayName="StepperCompleted");const[Ot,At]=J({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function Dt(t){const r=Et(t),{activeStep:n,isLastStep:l,nextStep:a}=r,[s,i]=e.useState({}),o=e.useCallback(async e=>{if(l)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{m(X({},s[n],{isCompleted:!0}))}).then(a);a()},[n,l]),c=e.useCallback(e=>{const t=s[n];return{onSubmit:o,schema:null==t?void 0:t.schema,resolver:null==t?void 0:t.resolver}},[s,o,n]),m=e.useCallback(e=>{i(t=>X({},t,{[e.name]:e}))},[s]);return X({getFormProps:c,updateStep:m,steps:s},r)}function jt(t){const{name:r,schema:n,resolver:l}=t,a=bt({name:r}),{steps:s,updateStep:i}=At();return e.useEffect(()=>{i({name:r,schema:n,resolver:l})},[r,n]),X({},a,s[r]||{name:r,schema:n})}const Mt=["children","onSubmit"],Ut=["getFormProps"],Pt=["name","schema","resolver","children","className"],$t=["label","submitLabel"],Bt=e.forwardRef((t,r)=>{const{children:n}=t,l=Y(t,Mt),a=Dt(t),{getFormProps:s}=a,i=Y(a,Ut),o=e.useMemo(()=>i,[i]);/*#__PURE__*/return e.createElement(ht,{value:o},/*#__PURE__*/e.createElement(Ot,{value:o},/*#__PURE__*/e.createElement(Ve,X({ref:r},l,s(t)),A(n,a))))}),qt=t=>{const r=U("Stepper",t),{children:n}=t,l=e.Children.map(n,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===zt){const{isCompleted:r}=jt(t.props);/*#__PURE__*/return e.createElement(It,{name:t.props.name,title:t.props.title,isCompleted:r},t.props.children)}return t});/*#__PURE__*/return e.createElement($,{value:r},/*#__PURE__*/e.createElement(kt,X({mb:"4"},t),l))},zt=t=>{const{name:r,schema:n,resolver:l,children:a,className:s}=t,i=Y(t,Pt),o=jt({name:r,schema:n,resolver:l}),{isActive:c}=o;return c?/*#__PURE__*/e.createElement(j.div,X({},i,{className:w("saas-form__step",s)}),a):null};O&&(zt.displayName="FormStep");const Gt=t=>{const{isFirstStep:r,isCompleted:n,prevStep:l}=vt();/*#__PURE__*/return e.createElement(W,X({isDisabled:r||n,label:"Back"},t,{className:w("saas-form__prev-button",t.className),onClick:D(t.onClick,l)}))};O&&(Gt.displayName="PrevButton");const Ht=t=>{const{label:r="Next",submitLabel:n="Complete"}=t,l=Y(t,$t),{isLastStep:a,isCompleted:s}=vt();/*#__PURE__*/return e.createElement(ct,X({isDisabled:s,label:a||s?n:r},l,{className:w("saas-form__next-button",t.className)}))};O&&(Ht.displayName="NextButton");export{Xe as ArrayField,Qe as ArrayFieldAddButton,Ze as ArrayFieldContainer,De as ArrayFieldProvider,Ke as ArrayFieldRemoveButton,Te as ArrayFieldRow,Je as ArrayFieldRowContainer,We as ArrayFieldRowFields,Me as ArrayFieldRowProvider,Ye as ArrayFieldRows,dt as AutoForm,ue as BaseField,Ne as CheckboxField,ee as DisplayField,ut as DisplayIf,pe as Field,it as Fields,Ve as Form,Oe as FormLayout,tt as FormLegend,zt as FormStep,qt as FormStepper,te as FormValue,Ee as InputField,ke as NativeSelectField,Ht as NextButton,be as NumberInputField,rt as ObjectField,ye as PasswordInputFIeld,_e as PinField,Gt as PrevButton,Ce as RadioField,xe as SelectField,Bt as StepForm,Ot as StepFormProvider,ct as SubmitButton,Se as SwitchField,ge as TextareaField,Re as objectFieldResolver,ve as registerFieldType,Pe as useArrayField,qe as useArrayFieldAddButton,je as useArrayFieldContext,Be as useArrayFieldRemoveButton,$e as useArrayFieldRow,Ue as useArrayFieldRowContext,jt as useFormStep,Dt as useStepForm,At as useStepFormContext,fe as withControlledInput,he as withUncontrolledInput};
1
+ import*as e from"react";import{useFormContext as t,get as r,Controller as n,useForm as l,FormProvider as a,useFieldArray as s,useWatch as i}from"react-hook-form";import{FormControl as o,FormLabel as c,Text as m,forwardRef as d,Switch as u,Checkbox as p,Box as f,FormHelperText as h,FormErrorMessage as v,useMergeRefs as E,Input as b,Textarea as y,chakra as g,useTheme as S,SimpleGrid as x,useStyles as N,Collapse as C}from"@chakra-ui/react";import{NumberInput as _}from"@saas-ui/number-input";import{PasswordInput as k}from"@saas-ui/password-input";import{RadioInput as F}from"@saas-ui/radio";import{PinInput as R}from"@saas-ui/pin-input";import{Select as I,NativeSelect as V}from"@saas-ui/select";import{get as w,cx as L,__DEV__ as O,dataAttr as A,runIfFn as D,callAllHandlers as j}from"@chakra-ui/utils";import{chakra as M,forwardRef as U,useMultiStyleConfig as P,omitThemingProps as $,StylesProvider as B,useStyles as q}from"@chakra-ui/system";import{MinusIcon as z,AddIcon as G,Icon as H,CheckIcon as T}from"@chakra-ui/icons";import{IconButton as J,Button as K}from"@saas-ui/button";import{createContext as Q}from"@chakra-ui/react-utils";import{getChildrenOfType as W,getChildOfType as X}from"@saas-ui/react-utils";export*from"@saas-ui/input-right-button";function Y(){return Y=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},Y.apply(this,arguments)}function Z(e,t){if(null==e)return{};var r,n,l={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(l[r]=e[r]);return l}const ee=["name","label","placeholder"],te=t=>{let{name:r,label:n}=t,l=Z(t,ee);/*#__PURE__*/return e.createElement(o,l,n?/*#__PURE__*/e.createElement(c,{htmlFor:r},n):null,/*#__PURE__*/e.createElement(m,{fontSize:"md"},/*#__PURE__*/e.createElement(re,{name:r})))},re=({name:e})=>{const{getValues:r}=t();return r(e)||null},ne=["name","label","help","variant","hideLabel","children"],le=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],ae=["name","rules"],se=["ref"],ie=["name","rules"],oe=["ref"],ce=["label"],me=["label"],de={},ue="text",pe=n=>{const{name:l,label:a,help:s,variant:i,hideLabel:m,children:d}=n,u=Z(n,ne),{formState:p}=t(),E=((e,t)=>r(t.errors,e))(l,p);/*#__PURE__*/return e.createElement(o,Y({variant:i},u,{isInvalid:!!E}),a&&!m?/*#__PURE__*/e.createElement(c,{variant:i},a):null,/*#__PURE__*/e.createElement(f,null,d,!s||null!=E&&E.message?null:/*#__PURE__*/e.createElement(h,null,s),(null==E?void 0:E.message)&&/*#__PURE__*/e.createElement(v,null,null==E?void 0:E.message)))},fe=d((t,r)=>{const{type:n=ue}=t,l=(e=>de[e]||de[ue])(n);/*#__PURE__*/return e.createElement(l,Y({ref:r},t))}),he=r=>d((l,a)=>{let{name:s,rules:i}=l,o=Z(l,ae);const{control:c}=t();/*#__PURE__*/return e.createElement(n,{name:s,control:c,rules:i,render:t=>{let{field:{ref:n}}=t,l=Z(t.field,se);/*#__PURE__*/return e.createElement(r,Y({},l,o,{ref:E(a,n)}))}})}),ve=r=>d((n,l)=>{let{name:a,rules:s}=n,i=Z(n,ie);const{register:o}=t(),c=o(a,s),{ref:m}=c,d=Z(c,oe);/*#__PURE__*/return e.createElement(r,Y({},d,i,{ref:E(l,m)}))}),Ee=(t,r,n)=>{let l;l=null!=n&&n.isControlled?he(r):ve(r);const a=((t,{displayName:r,hideLabel:n,BaseField:l})=>{const a=d((r,a)=>{const{name:s,label:i,help:o,isDisabled:c,isInvalid:m,isReadOnly:d,isRequired:u,rules:p,variant:f}=r,h=Z(r,le),v=Y({required:u},p);/*#__PURE__*/return e.createElement(l,{name:s,label:i,help:o,hideLabel:n,isDisabled:c,isInvalid:m,isReadOnly:d,isRequired:u,variant:f},/*#__PURE__*/e.createElement(t,Y({ref:a,name:s,label:i,rules:v},h)))});return a.displayName=r,a})(l,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||pe});return de[t]=a,a},be=Ee("text",b),ye=Ee("number",_,{isControlled:!0}),ge=Ee("password",k),Se=Ee("textarea",y),xe=Ee("switch",d((t,r)=>{let{label:n}=t,l=Z(t,ce);/*#__PURE__*/return e.createElement(u,Y({ref:r},l),n)}),{isControlled:!0,hideLabel:!0}),Ne=Ee("select",I,{isControlled:!0}),Ce=Ee("checkbox",d((t,r)=>{let{label:n}=t,l=Z(t,me);/*#__PURE__*/return e.createElement(p,Y({ref:r},l),n)}),{hideLabel:!0}),_e=Ee("radio",F,{isControlled:!0}),ke=Ee("pin",R,{isControlled:!0}),Fe=Ee("native-select",V,{isControlled:!0}),Re=e=>e&&Object.entries(e).map(([e,t])=>Y({},t,{name:e})),Ie=e=>({getFields:()=>Re(e),getNestedFields:t=>{var r;const n=w(e,t);return n?"object"===(null==(r=n.items)?void 0:r.type)?Re(n.items.properties):"object"===n.type?Re(n.properties):[n.items]:[]}}),Ve=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],we=d((t,r)=>{const{mode:n="all",resolver:s,reValidateMode:i,shouldFocusError:o,shouldUnregister:c,shouldUseNativeValidation:m,criteriaMode:d,delayError:u,schema:p,defaultValues:f,onSubmit:h,onError:v,formRef:E,children:b}=t,y=Z(t,Ve),S={mode:n,resolver:s,defaultValues:f,reValidateMode:i,shouldFocusError:o,shouldUnregister:c,shouldUseNativeValidation:m,criteriaMode:d,delayError:u};p&&!s&&(S.resolver=null==we.getResolver?void 0:we.getResolver(p));const x=l(S),{handleSubmit:N}=x;return e.useImperativeHandle(r,()=>x,[r,x]),/*#__PURE__*/e.createElement(a,x,/*#__PURE__*/e.createElement(g.form,Y({ref:E,onSubmit:N(h,v)},y),b))});we.getFieldResolver=Ie;const Le=["children"],Oe=({children:t})=>/*#__PURE__*/e.createElement(g.div,null,t),Ae=t=>{var r,n,l;let{children:a}=t,s=Z(t,Le);const i=Y({},null!=(r=null==(n=S().components)||null==(l=n.FormLayout)?void 0:l.defaultProps)?r:{spacing:4},s);/*#__PURE__*/return e.createElement(x,i,e.Children.map(a,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(Oe,null,t):t))},De=(t,r)=>e.Children.map(r,r=>e.isValidElement(r)&&r.props.name?e.cloneElement(r,Y({},r.props,{name:`${t}.${r.props.name}`})):r),[je,Me]=Q({name:"ArrayFieldContext"}),[Ue,Pe]=Q({name:"ArrayFieldRowContext"}),$e=({name:e,defaultValue:r={},keyName:n,min:l,max:a})=>{const{control:i}=t();return Y({},s({control:i,name:e,keyName:n}),{name:e,defaultValue:r,min:l,max:a})},Be=({index:r})=>{const{clearErrors:n}=t(),{name:l,remove:a,fields:s}=Me();return e.useEffect(()=>{n(l)},[]),{index:r,isFirst:0===r,isLast:r===s.length-1,name:`${l}.${r}`,remove:e.useCallback(()=>{n(l),a(r)},[r])}},qe=()=>{const{isFirst:e,remove:t}=Pe(),{min:r,fields:n}=Me();return{onClick:()=>t(),isDisabled:e&&!!(r&&n.length<=r)}},ze=()=>{const{append:e,defaultValue:t,max:r,fields:n}=Me();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(r&&n.length>=r)}},Ge=["children","columns","spacing"],He=["children"],Te=["name","defaultValue","keyName","min","max","children"],Je=({children:t,columns:r,spacing:n,index:l})=>/*#__PURE__*/e.createElement(Qe,{index:l},/*#__PURE__*/e.createElement(Ke,{columns:r,spacing:n},t),/*#__PURE__*/e.createElement(We,null)),Ke=t=>{let{children:r,columns:n,spacing:l}=t,a=Z(t,Ge);const{name:s}=Pe();/*#__PURE__*/return e.createElement(Ae,Y({flex:"1",columns:n,gridGap:l,mr:"2"},a),De(s,r))},Qe=({children:t,index:r})=>{const n=Be({index:r});/*#__PURE__*/return e.createElement(Ue,{value:n},/*#__PURE__*/e.createElement(M.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},We=t=>/*#__PURE__*/e.createElement(J,Y({icon:/*#__PURE__*/e.createElement(z,null),"aria-label":"Remove row"},qe(),t)),Xe=t=>/*#__PURE__*/e.createElement(J,Y({icon:/*#__PURE__*/e.createElement(G,null),"aria-label":"Add row",float:"right"},ze(),t)),Ye=e.forwardRef((t,r)=>{const{children:n}=t,l=Z(t,He);/*#__PURE__*/return e.createElement(et,Y({ref:r},l),/*#__PURE__*/e.createElement(Ze,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},r)=>/*#__PURE__*/e.createElement(Je,{key:t,index:r},n)))),/*#__PURE__*/e.createElement(Xe,null))}),Ze=({children:e})=>{const{fields:t}=Me();return e(t)},et=e.forwardRef((t,r)=>{let{name:n,defaultValue:l,keyName:a,min:s,max:i,children:o}=t,c=Z(t,Te);const m=$e({name:n,defaultValue:l,keyName:a,min:s,max:i});return e.useImperativeHandle(r,()=>m,[r,m]),/*#__PURE__*/e.createElement(je,{value:m},/*#__PURE__*/e.createElement(pe,Y({name:n},c),o))}),tt=["name","label","hideLabel","children","columns","spacing"],rt=t=>{const r=N();/*#__PURE__*/return e.createElement(c,Y({as:"legend",sx:r.legend},t))},nt=t=>{const{name:r,label:n,hideLabel:l,children:a,columns:s,spacing:i}=t,c=Z(t,tt);/*#__PURE__*/return e.createElement(o,Y({name:r,as:"fieldset"},c),/*#__PURE__*/e.createElement(rt,{display:l?"none":"block"},n),/*#__PURE__*/e.createElement(Ae,{columns:s,gridGap:i},De(r,a)))},lt=["name","type"],at=["schema","fieldResolver"],st=["name","type","defaultValue"],it=(t,r)=>{var n;return null==(n=t.getNestedFields(r))?void 0:n.map((t,r)=>{let{name:n,type:l}=t,a=Z(t,lt);/*#__PURE__*/return e.createElement(fe,Y({key:n||r,name:n,type:l},a))})},ot=t=>{let{schema:r,fieldResolver:n}=t,l=Z(t,at);const a=e.useMemo(()=>n||we.getFieldResolver(r),[r,n]);/*#__PURE__*/return e.createElement(Ae,l,a.getFields().map(t=>{let{name:r,type:n}=t,l=Z(t,st);return"array"===n?/*#__PURE__*/e.createElement(Ye,Y({key:r,name:r},l),it(a,r)):"object"===n?/*#__PURE__*/e.createElement(nt,Y({key:r,name:r},l),it(a,r)):/*#__PURE__*/e.createElement(fe,Y({key:r,name:r,type:n},l))}))},ct=["children","disableIfUntouched","disableIfInvalid"],mt=U((r,n)=>{const{children:l,disableIfUntouched:a,disableIfInvalid:s}=r,i=Z(r,ct),{formState:o}=t();/*#__PURE__*/return e.createElement(K,Y({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:n,isDisabled:a&&!o.isDirty||s&&!o.isValid},i),l)});mt.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};const dt=["schema","submitLabel","fieldResolver"],ut=d((t,r)=>{const{schema:n,submitLabel:l="Submit",fieldResolver:a}=t,s=Z(t,dt);/*#__PURE__*/return e.createElement(we,Y({},s,{schema:n,ref:r}),/*#__PURE__*/e.createElement(Ae,null,/*#__PURE__*/e.createElement(ot,{schema:n,fieldResolver:a}),l&&/*#__PURE__*/e.createElement(mt,{label:l})))}),pt=({children:e,name:r,defaultValue:n,isDisabled:l,isExact:a,condition:s=(e=>!!e)})=>s(i({name:r,defaultValue:n,disabled:l,exact:a}),t())?e:null;function ft(){return ft=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},ft.apply(this,arguments)}function ht(e,t){if(null==e)return{};var r,n,l={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(r=a[n])>=0||(l[r]=e[r]);return l}const[vt,Et]=Q({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"});function bt(t){const{step:r}=t,[n,l]=e.useState(-1),a=e.useRef([]),[,s]=e.useState(Date.now()),i=e.useCallback(e=>{const t=[...a.current];-1===t.indexOf(e)&&t.push(e),a.current=t,s(Date.now())},[a,s]),o=e=>{const t=a.current.indexOf(e);-1!==t&&l(t)};return e.useEffect(()=>{"string"==typeof r?o(r):"number"==typeof r?l(r):-1===n&&l(0)},[r]),{stepsRef:a,activeStep:a.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===a.current.length-1,isCompleted:n>=a.current.length,setIndex:l,setStep:o,nextStep:()=>{l(n+1)},prevStep:()=>{l(n-1)},registerStep:i,unregisterStep:e=>{a.current=a.current.slice(a.current.indexOf(e),1)}}}function yt(t){const{name:r,isActive:n,isCompleted:l}=t,{registerStep:a,unregisterStep:s,activeStep:i}=Et();return e.useEffect(()=>{if(r)return a(r),()=>{s(r)}},[]),{isActive:r?i===r:n,isCompleted:l}}const gt=["children","orientation","step"],St=["children","orientation","stepComponent"],xt=["children","isOpen"],Nt=["icon","isActive","isCompleted","className"],Ct=["title","icon","isActive","isCompleted"],_t=["isActive"],kt=U((t,r)=>{const{children:n,orientation:l="horizontal"}=t,a=ht(t,gt),s=P("Stepper",ft({},a,{orientation:l})),i=$(a),o=bt(t),c=ft({display:"flex",flexDirection:"column"},s.container);return e.createElement(B,{value:s},/*#__PURE__*/e.createElement(vt,{value:o},/*#__PURE__*/e.createElement(M.div,ft({ref:r,__css:c},i,{className:L("saas-stepper",t.className)}),/*#__PURE__*/e.createElement(Ft,{orientation:l},n))))});O&&(kt.displayName="Stepper");const Ft=t=>{var r,n;const{children:l,orientation:a="horizontal",stepComponent:s}=t,i=ht(t,St),o=q(),{activeIndex:c}=Et(),m=ft({display:"flex",flexDirection:"row",alignItems:"center"},o.steps),d="vertical"===a,u=s||Vt,p=W(l,u),f=p.reduce((t,r,n,l)=>(t.push(/*#__PURE__*/e.createElement(u,ft({key:n},r.props,{icon:r.props.icon||n+1,isActive:c===n,isCompleted:r.props.isCompleted||c>n}))),d&&t.push(/*#__PURE__*/e.createElement(Rt,{key:`content-${n}`,isOpen:c===n},r.props.children)),n<l.length-1&&t.push(/*#__PURE__*/e.createElement(wt,{key:`separator-${n}`,isActive:n<c})),t),[]),h=X(l,Ot),v=c>=p.length?h:d?null:/*#__PURE__*/e.createElement(Rt,null,null==(r=p[c])||null==(n=r.props)?void 0:n.children);return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(M.div,ft({__css:m},i,{className:L("saas-stepper__steps",t.className)}),f),v)};O&&(Ft.displayName="StepperSteps");const Rt=t=>{const{children:r,isOpen:n=!0}=t,l=ht(t,xt),a=q();return e.createElement(M.div,ft({__css:a.content},l,{className:L("saas-stepper__content",t.className)}),/*#__PURE__*/e.createElement(C,{in:n},r))};O&&(Rt.displayName="StepperContent");const It=t=>{const{icon:r,isCompleted:n,className:l}=t,a=ht(t,Nt),s=ft({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em"},q().icon);let i;return i=n?/*#__PURE__*/e.createElement(H,{as:T}):r,/*#__PURE__*/e.createElement(M.div,ft({__css:s},a,{className:L("saas-stepper__icon",l)}),i)};O&&(It.displayName="StepperIcon");const Vt=t=>{const{title:r,icon:n,isActive:l,isCompleted:a}=t,s=ht(t,Ct),i=yt(t),o=ft({display:"flex",alignItems:"center",flexDirection:"row"},q().step);return e.createElement(M.div,ft({},s,{__css:o,"data-active":A(i.isActive),"data-completed":A(i.isCompleted),className:L("saas-stepper__step",t.className)}),/*#__PURE__*/e.createElement(It,{icon:n,isActive:l,isCompleted:a}),r&&/*#__PURE__*/e.createElement(Lt,null,r))};O&&(Vt.displayName="StepperStep");const wt=t=>{const{isActive:r}=t,n=ht(t,_t),l=ft({flex:1,mx:2},q().separator);return e.createElement(M.div,ft({},n,{"data-active":A(r),className:L("saas-stepper__separator",t.className),__css:l}))};O&&(wt.displayName="StepperSeparator");const Lt=t=>{const r=q();return e.createElement(M.p,ft({},t,{__css:r.title,className:L("saas-stepper__title",t.className)}))};O&&(Lt.displayName="StepperStepTitle");const Ot=t=>{const r=q();return e.createElement(M.div,ft({__css:r.completed},t,{className:L("saas-stepper__completed",t.className)}))};O&&(Ot.displayName="StepperCompleted");const[At,Dt]=Q({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function jt(t){const r=bt(t),{activeStep:n,isLastStep:l,nextStep:a}=r,[s,i]=e.useState({}),o=e.useCallback(async e=>{if(l)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{m(Y({},s[n],{isCompleted:!0}))}).then(a);a()},[n,l]),c=e.useCallback(e=>{const t=s[n];return{onSubmit:o,schema:null==t?void 0:t.schema,resolver:null==t?void 0:t.resolver}},[s,o,n]),m=e.useCallback(e=>{i(t=>Y({},t,{[e.name]:e}))},[s]);return Y({getFormProps:c,updateStep:m,steps:s},r)}function Mt(t){const{name:r,schema:n,resolver:l}=t,a=yt({name:r}),{steps:s,updateStep:i}=Dt();return e.useEffect(()=>{i({name:r,schema:n,resolver:l})},[r,n]),Y({},a,s[r]||{name:r,schema:n})}const Ut=["children","onSubmit"],Pt=["getFormProps"],$t=["name","schema","resolver","children","className"],Bt=["label","submitLabel"],qt=e.forwardRef((t,r)=>{const{children:n}=t,l=Z(t,Ut),a=jt(t),{getFormProps:s}=a,i=Z(a,Pt),o=e.useMemo(()=>i,[i]);/*#__PURE__*/return e.createElement(vt,{value:o},/*#__PURE__*/e.createElement(At,{value:o},/*#__PURE__*/e.createElement(we,Y({ref:r},l,s(t)),D(n,a))))}),zt=t=>{const r=P("Stepper",t),{children:n}=t,l=e.Children.map(n,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===Gt){const{isCompleted:r}=Mt(t.props);/*#__PURE__*/return e.createElement(Vt,{name:t.props.name,title:t.props.title,isCompleted:r},t.props.children)}return t});/*#__PURE__*/return e.createElement(B,{value:r},/*#__PURE__*/e.createElement(Ft,Y({mb:"4"},t),l))},Gt=t=>{const{name:r,schema:n,resolver:l,children:a,className:s}=t,i=Z(t,$t),o=Mt({name:r,schema:n,resolver:l}),{isActive:c}=o;return c?/*#__PURE__*/e.createElement(M.div,Y({},i,{className:L("saas-form__step",s)}),a):null};O&&(Gt.displayName="FormStep");const Ht=t=>{const{isFirstStep:r,isCompleted:n,prevStep:l}=Et();/*#__PURE__*/return e.createElement(K,Y({isDisabled:r||n,label:"Back"},t,{className:L("saas-form__prev-button",t.className),onClick:j(t.onClick,l)}))};O&&(Ht.displayName="PrevButton");const Tt=t=>{const{label:r="Next",submitLabel:n="Complete"}=t,l=Z(t,Bt),{isLastStep:a,isCompleted:s}=Et();/*#__PURE__*/return e.createElement(mt,Y({isDisabled:s,label:a||s?n:r},l,{className:L("saas-form__next-button",t.className)}))};O&&(Tt.displayName="NextButton");export{Ye as ArrayField,Xe as ArrayFieldAddButton,et as ArrayFieldContainer,je as ArrayFieldProvider,We as ArrayFieldRemoveButton,Je as ArrayFieldRow,Qe as ArrayFieldRowContainer,Ke as ArrayFieldRowFields,Ue as ArrayFieldRowProvider,Ze as ArrayFieldRows,ut as AutoForm,pe as BaseField,Ce as CheckboxField,te as DisplayField,pt as DisplayIf,fe as Field,ot as Fields,we as Form,Ae as FormLayout,rt as FormLegend,Gt as FormStep,zt as FormStepper,re as FormValue,be as InputField,Fe as NativeSelectField,Tt as NextButton,ye as NumberInputField,nt as ObjectField,ge as PasswordInputFIeld,ke as PinField,Ht as PrevButton,_e as RadioField,Ne as SelectField,qt as StepForm,At as StepFormProvider,mt as SubmitButton,xe as SwitchField,Se as TextareaField,Ie as objectFieldResolver,Ee as registerFieldType,$e as useArrayField,ze as useArrayFieldAddButton,Me as useArrayFieldContext,qe as useArrayFieldRemoveButton,Be as useArrayFieldRow,Pe as useArrayFieldRowContext,Mt as useFormStep,jt as useStepForm,Dt as useStepFormContext,he as withControlledInput,ve as withUncontrolledInput};
2
2
  //# sourceMappingURL=index.modern.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../../saas-ui-stepper/dist/index.modern.js","../src/use-step-form.tsx","../src/step-form.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">\n <FormValue name={name} />\n </Text>\n </FormControl>\n )\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\nimport { FocusableElement } from '@chakra-ui/utils'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<FocusableElement>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema) =>\n schema &&\n Object.entries(schema).map(([name, field]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses a different 'id' field\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n UseArrayFieldReturn,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField = React.forwardRef(\n (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer ref={ref} {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n }\n)\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer = React.forwardRef(\n (\n {\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n }: ArrayFieldProps,\n ref: React.ForwardedRef<UseArrayFieldReturn>\n ) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n // This exposes the useArrayField api through the forwarded ref\n React.useImperativeHandle(ref, () => context, [ref, context])\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n }\n)\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyles()\n return <FormLabel as=\"legend\" sx={styles.legend} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n","import * as React from 'react'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n submitLabel?: false | string\n schema: any\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', fieldResolver, ...rest } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & { getFieldResolver?: (schema: any) => FieldResolver }\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n","import*as e from\"react\";import{forwardRef as t,useMultiStyleConfig as s,omitThemingProps as r,StylesProvider as n,chakra as a,useStyles as i}from\"@chakra-ui/system\";import{Icon as c,CheckIcon as p}from\"@chakra-ui/icons\";import{Collapse as l}from\"@saas-ui/collapse\";import{getChildrenOfType as o,getChildOfType as m}from\"@saas-ui/react-utils\";import{cx as u,__DEV__ as d}from\"@chakra-ui/utils\";import{createContext as f}from\"@chakra-ui/react-utils\";function v(){return v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var r in s)Object.prototype.hasOwnProperty.call(s,r)&&(e[r]=s[r])}return e},v.apply(this,arguments)}function S(e,t){if(null==e)return{};var s,r,n={},a=Object.keys(e);for(r=0;r<a.length;r++)t.indexOf(s=a[r])>=0||(n[s]=e[s]);return n}const[_,N]=f({name:\"StepperContext\",errorMessage:\"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`\"});function h(t){const{step:s}=t,[r,n]=e.useState(-1),a=e.useRef([]),[,i]=e.useState(Date.now()),c=e.useCallback(e=>{const t=[...a.current];-1===t.indexOf(e)&&t.push(e),a.current=t,i(Date.now())},[a,i]),p=e=>{const t=a.current.indexOf(e);-1!==t&&n(t)};return e.useLayoutEffect(()=>{\"string\"==typeof s?p(s):\"number\"==typeof s?n(s):-1===r&&n(0)},[s]),{stepsRef:a,activeStep:a.current[r],activeIndex:r,isFirstStep:0===r,isLastStep:r===a.current.length-1,isCompleted:r>=a.current.length,setIndex:n,setStep:p,nextStep:()=>{n(r+1)},prevStep:()=>{n(r-1)},registerStep:c,unregisterStep:e=>{a.current=a.current.slice(a.current.indexOf(e),1)}}}function y(t){const{name:s,isActive:r,isCompleted:n}=t,{registerStep:a,unregisterStep:i,activeStep:c}=N();return e.useEffect(()=>{if(s)return a(s),()=>{i(s)}},[]),{isActive:s?c===s:r,isCompleted:n}}function x({label:e=\"Back\"}={}){const{isFirstStep:t,prevStep:s}=N();return{isDisabled:t,onClick:s,label:e}}function C({label:e=\"Next\",submitLabel:t=\"Submit\"}={}){const{isLastStep:s,isCompleted:r,nextStep:n}=N();return{isDisabled:r,onClick:n,label:s?t:e}}const E=[\"children\",\"orientation\"],g=[\"children\",\"orientation\",\"stepComponent\"],b=[\"children\",\"isOpen\"],k=[\"icon\",\"isActive\",\"isCompleted\",\"className\"],A=[\"title\",\"icon\",\"isActive\",\"isCompleted\"],O=[\"isActive\"],D=t((t,i)=>{const c=s(\"Stepper\",t),p=r(t),{children:l,orientation:o}=p,m=S(p,E),d=h(t),f=v({display:\"flex\",flexDirection:\"column\"},c.container);/*#__PURE__*/return e.createElement(n,{value:c},/*#__PURE__*/e.createElement(_,{value:d},/*#__PURE__*/e.createElement(a.div,v({ref:i,__css:f},m,{className:u(\"saas-stepper__container\",t.className)}),/*#__PURE__*/e.createElement(I,{orientation:o},l))))});d&&(D.displayName=\"Stepper\");const I=t=>{var s,r;const{children:n,orientation:c,stepComponent:p}=t,l=S(t,g),d=i(),{activeIndex:f}=N(),_=v({display:\"flex\",flexDirection:\"row\",alignItems:\"center\"},d.steps),h=\"vertical\"===c,y=p||L,x=o(n,y),C=x.reduce((t,s,r,n)=>(t.push(/*#__PURE__*/e.createElement(y,v({key:r},s.props,{icon:s.props.icon||r+1,isActive:f===r,isCompleted:s.props.isCompleted||f>r}))),\"vertical\"===c&&t.push(/*#__PURE__*/e.createElement(w,{key:`content-${r}`,isOpen:f===r},s.props.children)),r<n.length-1&&t.push(/*#__PURE__*/e.createElement(F,{key:`separator-${r}`,isActive:r<f})),t),[]),E=m(n,T),b=f>=x.length?E:h?null:/*#__PURE__*/e.createElement(w,null,null==(s=x[f])||null==(r=s.props)?void 0:r.children);/*#__PURE__*/return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(a.div,v({__css:_},l,{className:u(\"saas-stepper__steps\",t.className)}),C),b)};d&&(I.displayName=\"StepperSteps\");const w=t=>{const{children:s,isOpen:r=!0}=t,n=S(t,b),c=i();/*#__PURE__*/return e.createElement(a.div,v({__css:c.content},n,{className:u(\"saas-stepper__content\",t.className)}),/*#__PURE__*/e.createElement(l,{in:r},s))};d&&(w.displayName=\"StepperContent\");const j=t=>{const{icon:s,isCompleted:r,className:n}=t,l=S(t,k),o=v({display:\"flex\",alignItems:\"center\",justifyContent:\"center\",borderRadius:\"full\",fontSize:\"1em\",me:2},i().icon);let m;return m=r?/*#__PURE__*/e.createElement(c,{as:p}):s,/*#__PURE__*/e.createElement(a.div,v({__css:o},l,{className:u(\"saas-stepper__icon\",n)}),m)};d&&(j.displayName=\"StepperIcon\");const L=t=>{const{title:s,icon:r,isActive:n,isCompleted:c}=t,p=S(t,A),l=y(t),o=v({display:\"flex\",alignItems:\"center\",flexDirection:\"row\"},i().step);/*#__PURE__*/return e.createElement(a.div,v({__css:o,\"data-active\":l.isActive,\"data-completed\":l.isCompleted},p,{className:u(\"saas-stepper__step\",t.className)}),/*#__PURE__*/e.createElement(j,{icon:r,isActive:n,isCompleted:c}),s&&/*#__PURE__*/e.createElement(R,null,s))};d&&(L.displayName=\"StepperStep\");const F=t=>{const{isActive:s}=t,r=S(t,O),n=v({flex:1,borderTopWidth:\"1px\",mx:2},i().separator);/*#__PURE__*/return e.createElement(a.div,v({\"data-active\":s},r,{className:u(\"saas-stepper__separator\",t.className),__css:n}))};d&&(F.displayName=\"StepperSeparator\");const R=t=>{const s=i();/*#__PURE__*/return e.createElement(a.p,v({},t,{__css:s.title,className:u(\"saas-stepper__title\",t.className)}))};d&&(R.displayName=\"StepperStepTitle\");const T=t=>{const s=i();/*#__PURE__*/return e.createElement(a.div,v({__css:s.completed},t,{className:u(\"saas-stepper__completed\",t.className)}))};d&&(T.displayName=\"StepperCompleted\");export{D as Stepper,T as StepperCompleted,w as StepperContent,j as StepperIcon,_ as StepperProvider,F as StepperSeparator,L as StepperStep,R as StepperStepTitle,I as StepperSteps,C as useNext,x as usePrev,y as useStep,h as useStepper,N as useStepperContext};\n//# sourceMappingURL=index.modern.js.map\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler } from 'react-hook-form'\nimport { createContext } from '@chakra-ui/react-utils'\nimport {\n useStepper,\n useStep,\n UseStepperProps,\n UseStepperReturn,\n} from '@saas-ui/stepper'\n\nexport interface StepState {\n name: string\n schema?: any\n resolver?: any\n isActive?: boolean\n isCompleted?: boolean\n}\n\nexport interface StepFormContext extends UseStepperReturn {\n updateStep(state: StepState): void\n steps: Record<string, StepState>\n}\n\nexport const [StepFormProvider, useStepFormContext] =\n createContext<StepFormContext>({\n name: 'StepFormContext',\n errorMessage:\n 'useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`',\n })\n\nimport { FormProps } from './form'\n\nexport interface UseStepFormProps<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperProps,\n FormProps<TFieldValues> {}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n) {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(\n (props) => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n },\n [steps, onSubmitStep, activeStep]\n )\n\n const updateStep = React.useCallback(\n (step) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport type UseStepFormReturn = ReturnType<typeof useStepForm>\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {\n chakra,\n HTMLChakraProps,\n useMultiStyleConfig,\n StylesProvider,\n} from '@chakra-ui/system'\n\nimport { callAllHandlers, runIfFn, cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n StepperProvider,\n StepperSteps,\n StepperStepsProps,\n StepperStep,\n useStepperContext,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form, FormProps } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues>,\n FormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps(props)}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const styles = useMultiStyleConfig('Stepper', props)\n\n const { children } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n return (\n <StylesProvider value={styles}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StylesProvider>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, ...rest } = props\n const step = useFormStep({ name, schema, resolver })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n"],"names":["DisplayField","_ref","name","label","props","React","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","getValues","useFormContext","inputTypes","defaultInputType","BaseField","help","variant","hideLabel","children","controlProps","formState","error","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","InputComponent","getInput","withControlledInput","rules","inputProps","control","Controller","render","_ref3","field","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","isControlled","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","getFieldResolver","FormLayoutItem","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","columns","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","id","key","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","_ref2","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","DisplayIf","isExact","condition","useWatch","disabled","exact","StepperProvider","useStepperContext","errorMessage","useStepper","step","activeIndex","setIndex","useState","stepsRef","useRef","onUpdate","Date","now","registerStep","newSteps","current","indexOf","push","setStep","useLayoutEffect","activeStep","isFirstStep","isLastStep","isCompleted","nextStep","prevStep","unregisterStep","useStep","isActive","StepFormProvider","useStepFormContext","useStepForm","stepper","steps","updateSteps","onSubmitStep","async","data","then","updateStep","getFormProps","useFormStep","StepForm","ctx","runIfFn","FormStepper","useMultiStyleConfig","elements","FormStep","StepperStep","title","StylesProvider","StepperSteps","className","cx","__DEV__","PrevButton","callAllHandlers","NextButton"],"mappings":"ylDAgBaA,GAA4CC,QAACC,KACxDA,EADwDC,MAExDA,KAEGC,sBAEH,OACEC,gBAACC,EAAgBF,EACdD,eAAQE,gBAACE,GAAUC,QAASN,GAAOC,GAAqB,kBACzDE,gBAACI,GAAKC,SAAS,mBACbL,gBAACM,IAAUT,KAAMA,OAMZS,GAAwC,EAAGT,KAAAA,MACtD,MAAMU,U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AM+Q,eAKhDE,IACFG,GAAWnO,YAAc"}
1
+ {"version":3,"file":"index.modern.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../../saas-ui-stepper/dist/index.modern.js","../src/use-step-form.tsx","../src/step-form.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">\n <FormValue name={name} />\n </Text>\n </FormControl>\n )\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\nimport { FocusableElement } from '@chakra-ui/utils'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<FocusableElement>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema) =>\n schema &&\n Object.entries(schema).map(([name, field]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses a different 'id' field\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n UseArrayFieldReturn,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField = React.forwardRef(\n (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer ref={ref} {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n }\n)\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer = React.forwardRef(\n (\n {\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n }: ArrayFieldProps,\n ref: React.ForwardedRef<UseArrayFieldReturn>\n ) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n // This exposes the useArrayField api through the forwarded ref\n React.useImperativeHandle(ref, () => context, [ref, context])\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n }\n)\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyles()\n return <FormLabel as=\"legend\" sx={styles.legend} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n","import * as React from 'react'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n submitLabel?: false | string\n schema: any\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', fieldResolver, ...rest } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & { getFieldResolver?: (schema: any) => FieldResolver }\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n","import*as e from\"react\";import{forwardRef as t,useMultiStyleConfig as s,omitThemingProps as n,StylesProvider as r,chakra as a,useStyles as i}from\"@chakra-ui/system\";import{Icon as c,CheckIcon as l}from\"@chakra-ui/icons\";import{Collapse as p}from\"@saas-ui/collapse\";import{getChildrenOfType as o,getChildOfType as m}from\"@saas-ui/react-utils\";import{cx as u,__DEV__ as d,dataAttr as f}from\"@chakra-ui/utils\";import{createContext as S}from\"@chakra-ui/react-utils\";function v(){return v=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var s=arguments[t];for(var n in s)Object.prototype.hasOwnProperty.call(s,n)&&(e[n]=s[n])}return e},v.apply(this,arguments)}function _(e,t){if(null==e)return{};var s,n,r={},a=Object.keys(e);for(n=0;n<a.length;n++)t.indexOf(s=a[n])>=0||(r[s]=e[s]);return r}const[h,N]=S({name:\"StepperContext\",errorMessage:\"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`\"});function y(t){const{step:s}=t,[n,r]=e.useState(-1),a=e.useRef([]),[,i]=e.useState(Date.now()),c=e.useCallback(e=>{const t=[...a.current];-1===t.indexOf(e)&&t.push(e),a.current=t,i(Date.now())},[a,i]),l=e=>{const t=a.current.indexOf(e);-1!==t&&r(t)};return e.useEffect(()=>{\"string\"==typeof s?l(s):\"number\"==typeof s?r(s):-1===n&&r(0)},[s]),{stepsRef:a,activeStep:a.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===a.current.length-1,isCompleted:n>=a.current.length,setIndex:r,setStep:l,nextStep:()=>{r(n+1)},prevStep:()=>{r(n-1)},registerStep:c,unregisterStep:e=>{a.current=a.current.slice(a.current.indexOf(e),1)}}}function x(t){const{name:s,isActive:n,isCompleted:r}=t,{registerStep:a,unregisterStep:i,activeStep:c}=N();return e.useEffect(()=>{if(s)return a(s),()=>{i(s)}},[]),{isActive:s?c===s:n,isCompleted:r}}function C({label:e=\"Back\"}={}){const{isFirstStep:t,prevStep:s}=N();return{isDisabled:t,onClick:s,label:e}}function E({label:e=\"Next\",submitLabel:t=\"Submit\"}={}){const{isLastStep:s,isCompleted:n,nextStep:r}=N();return{isDisabled:n,onClick:r,label:s?t:e}}const g=[\"children\",\"orientation\",\"step\"],b=[\"children\",\"orientation\",\"stepComponent\"],k=[\"children\",\"isOpen\"],A=[\"icon\",\"isActive\",\"isCompleted\",\"className\"],O=[\"title\",\"icon\",\"isActive\",\"isCompleted\"],D=[\"isActive\"],I=t((t,i)=>{const{children:c,orientation:l=\"horizontal\"}=t,p=_(t,g),o=s(\"Stepper\",v({},p,{orientation:l})),m=n(p),d=y(t),f=v({display:\"flex\",flexDirection:\"column\"},o.container);/*#__PURE__*/return e.createElement(r,{value:o},/*#__PURE__*/e.createElement(h,{value:d},/*#__PURE__*/e.createElement(a.div,v({ref:i,__css:f},m,{className:u(\"saas-stepper\",t.className)}),/*#__PURE__*/e.createElement(w,{orientation:l},c))))});d&&(I.displayName=\"Stepper\");const w=t=>{var s,n;const{children:r,orientation:c=\"horizontal\",stepComponent:l}=t,p=_(t,b),d=i(),{activeIndex:f}=N(),S=v({display:\"flex\",flexDirection:\"row\",alignItems:\"center\"},d.steps),h=\"vertical\"===c,y=l||F,x=o(r,y),C=x.reduce((t,s,n,r)=>(t.push(/*#__PURE__*/e.createElement(y,v({key:n},s.props,{icon:s.props.icon||n+1,isActive:f===n,isCompleted:s.props.isCompleted||f>n}))),h&&t.push(/*#__PURE__*/e.createElement(j,{key:`content-${n}`,isOpen:f===n},s.props.children)),n<r.length-1&&t.push(/*#__PURE__*/e.createElement(L,{key:`separator-${n}`,isActive:n<f})),t),[]),E=m(r,$),g=f>=x.length?E:h?null:/*#__PURE__*/e.createElement(j,null,null==(s=x[f])||null==(n=s.props)?void 0:n.children);/*#__PURE__*/return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(a.div,v({__css:S},p,{className:u(\"saas-stepper__steps\",t.className)}),C),g)};d&&(w.displayName=\"StepperSteps\");const j=t=>{const{children:s,isOpen:n=!0}=t,r=_(t,k),c=i();/*#__PURE__*/return e.createElement(a.div,v({__css:c.content},r,{className:u(\"saas-stepper__content\",t.className)}),/*#__PURE__*/e.createElement(p,{in:n},s))};d&&(j.displayName=\"StepperContent\");const z=t=>{const{icon:s,isCompleted:n,className:r}=t,p=_(t,A),o=v({display:\"flex\",alignItems:\"center\",justifyContent:\"center\",borderRadius:\"full\",fontSize:\"1em\"},i().icon);let m;return m=n?/*#__PURE__*/e.createElement(c,{as:l}):s,/*#__PURE__*/e.createElement(a.div,v({__css:o},p,{className:u(\"saas-stepper__icon\",r)}),m)};d&&(z.displayName=\"StepperIcon\");const F=t=>{const{title:s,icon:n,isActive:r,isCompleted:c}=t,l=_(t,O),p=x(t),o=v({display:\"flex\",alignItems:\"center\",flexDirection:\"row\"},i().step);/*#__PURE__*/return e.createElement(a.div,v({},l,{__css:o,\"data-active\":f(p.isActive),\"data-completed\":f(p.isCompleted),className:u(\"saas-stepper__step\",t.className)}),/*#__PURE__*/e.createElement(z,{icon:n,isActive:r,isCompleted:c}),s&&/*#__PURE__*/e.createElement(R,null,s))};d&&(F.displayName=\"StepperStep\");const L=t=>{const{isActive:s}=t,n=_(t,D),r=v({flex:1,mx:2},i().separator);/*#__PURE__*/return e.createElement(a.div,v({},n,{\"data-active\":f(s),className:u(\"saas-stepper__separator\",t.className),__css:r}))};d&&(L.displayName=\"StepperSeparator\");const R=t=>{const s=i();/*#__PURE__*/return e.createElement(a.p,v({},t,{__css:s.title,className:u(\"saas-stepper__title\",t.className)}))};d&&(R.displayName=\"StepperStepTitle\");const $=t=>{const s=i();/*#__PURE__*/return e.createElement(a.div,v({__css:s.completed},t,{className:u(\"saas-stepper__completed\",t.className)}))};d&&($.displayName=\"StepperCompleted\");export{I as Stepper,$ as StepperCompleted,j as StepperContent,z as StepperIcon,h as StepperProvider,L as StepperSeparator,F as StepperStep,R as StepperStepTitle,w as StepperSteps,E as useNext,C as usePrev,x as useStep,y as useStepper,N as useStepperContext};\n//# sourceMappingURL=index.modern.js.map\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler } from 'react-hook-form'\nimport { createContext } from '@chakra-ui/react-utils'\nimport {\n useStepper,\n useStep,\n UseStepperProps,\n UseStepperReturn,\n} from '@saas-ui/stepper'\n\nexport interface StepState {\n name: string\n schema?: any\n resolver?: any\n isActive?: boolean\n isCompleted?: boolean\n}\n\nexport interface StepFormContext extends UseStepperReturn {\n updateStep(state: StepState): void\n steps: Record<string, StepState>\n}\n\nexport const [StepFormProvider, useStepFormContext] =\n createContext<StepFormContext>({\n name: 'StepFormContext',\n errorMessage:\n 'useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`',\n })\n\nimport { FormProps } from './form'\n\nexport interface UseStepFormProps<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperProps,\n FormProps<TFieldValues> {}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n) {\n const stepper = useStepper(props)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n const step = steps[activeStep]\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n nextStep()\n },\n [activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(\n (props) => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n },\n [steps, onSubmitStep, activeStep]\n )\n\n const updateStep = React.useCallback(\n (step) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport type UseStepFormReturn = ReturnType<typeof useStepForm>\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport {\n chakra,\n HTMLChakraProps,\n useMultiStyleConfig,\n StylesProvider,\n} from '@chakra-ui/system'\n\nimport { callAllHandlers, runIfFn, cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n StepperProvider,\n StepperSteps,\n StepperStepsProps,\n StepperStep,\n useStepperContext,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form, FormProps } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues>,\n FormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, onSubmit, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps(props)}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const styles = useMultiStyleConfig('Stepper', props)\n\n const { children } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n return (\n <StylesProvider value={styles}>\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StylesProvider>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n HTMLChakraProps<'div'> {}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, ...rest } = props\n const step = useFormStep({ name, schema, resolver })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n"],"names":["DisplayField","_ref","name","label","props","React","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","getValues","useFormContext","inputTypes","defaultInputType","BaseField","help","variant","hideLabel","children","controlProps","formState","error","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","InputComponent","getInput","withControlledInput","rules","inputProps","control","Controller","render","_ref3","field","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","isControlled","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","getFieldResolver","FormLayoutItem","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","columns","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","id","key","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","_resolver$getNestedFi","i","nestedFieldProps","Fields","_ref2","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","DisplayIf","isExact","condition","useWatch","disabled","exact","StepperProvider","useStepperContext","errorMessage","useStepper","step","activeIndex","setIndex","useState","stepsRef","useRef","onUpdate","Date","now","registerStep","newSteps","current","indexOf","push","setStep","activeStep","isFirstStep","isLastStep","isCompleted","nextStep","prevStep","unregisterStep","useStep","isActive","StepFormProvider","useStepFormContext","useStepForm","stepper","steps","updateSteps","onSubmitStep","async","data","then","updateStep","getFormProps","useFormStep","StepForm","ctx","runIfFn","FormStepper","useMultiStyleConfig","elements","FormStep","StepperStep","title","StylesProvider","StepperSteps","className","cx","__DEV__","PrevButton","callAllHandlers","NextButton"],"mappings":"wmDAgBaA,GAA4CC,QAACC,KACxDA,EADwDC,MAExDA,KAEGC,uBAEH,OACEC,gBAACC,EAAgBF,EACdD,eAAQE,gBAACE,GAAUC,QAASN,GAAOC,GAAqB,kBACzDE,gBAACI,GAAKC,SAAS,mBACbL,g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,GAAcC,EAAc7B,EAAcpN,GAC7C0G,GACJqK,UAAWC,EAAG,yBAA0B/Q,EAAM8Q,eAKhDE,IACFG,GAAWlO,YAAc"}
@@ -0,0 +1,2 @@
1
+ export * from './yup-resolver';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../yup/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,gBAAgB,CAAA"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sources":["../../yup/src/yup.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '../../src/field'\n\nexport { yupResolver }\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\ntype Options = {\n min?: number\n max?: number\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["getType","field","spec","meta","_field$spec$meta","type","getArrayOption","name","tests","test","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","schemaFields","fields","innerType","options","min","max","push","label","getNestedSchema","path","reach","yupFieldResolver","getFields","getNestedFields","schemaOptions","resolverOptions","resolver","yupResolver","fieldResolver"],"mappings":"oXAQA,IAAMA,EAAU,SAACC,SACf,YAAIA,EAAMC,KAAKC,OAAXC,EAAiBC,KACnB,OAAOJ,EAAMC,KAAKC,KAAKE,KAGzB,OAAQJ,EAAMI,MACZ,IAAK,QACH,MAAO,QACT,IAAK,SACH,MAAO,SACT,IAAK,SACH,MAAO,SACT,IAAK,OACH,MAAO,OAET,QACE,MAAO,SASPC,EAAiB,SAACL,EAAYM,GAClC,srBAAmBN,EAAMO,sBAAO,OAArBC,UACT,YAAIA,EAAKC,UAALC,EAAcC,OAAOL,GAAO,OAAOE,EAAKC,QAAQE,OAAOL,KAUlDM,EAAsB,SAACC,GAClC,IAEIC,EAFEC,EAAS,GAUf,IAAK,IAAMT,KALTQ,EAFkB,UAAhBD,EAAOT,KAEMS,EAAOG,UAAUD,OAEjBF,EAAOE,OAGS,CAC/B,IAAMf,EAAQc,EAAaR,GAErBW,EAAmB,GACN,UAAfjB,EAAMI,OACRa,EAAQC,IAAMb,EAAeL,EAAO,OACpCiB,EAAQE,IAAMd,EAAeL,EAAO,QAGtCe,EAAOK,QACLd,KAAAA,EACAe,MAAOrB,EAAMC,KAAKoB,OAASf,EAC3BF,KAAML,EAAQC,IACXiB,IAGP,OAAOF,GAGIO,EAAkB,SAACT,EAAyBU,GACvD,OAAOC,QAAMX,EAAQU,IAGVE,EAAmB,SAACZ,GAC/B,MAAO,CACLa,qBACE,OAAOd,EAAoBC,IAE7Bc,yBAAgBrB,GACd,OAAOM,EAAoBU,EAAgBT,EAAQP,4MAKlC,SACrBO,EACAe,EACAC,GAEA,gBAHAD,IAAAA,EAAgB,aAChBC,IAAAA,EAAkB,IAEX,CACLhB,OAAAA,EACAiB,SAAUC,cAAYlB,EAAQe,EAAeC,GAC7CG,cAAeP,EAAiBZ"}
1
+ {"version":3,"file":"index.js","sources":["../../yup/src/yup-resolver.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { yupResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["getType","field","spec","meta","_field$spec$meta","type","getArrayOption","name","tests","test","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","schemaFields","fields","innerType","options","min","max","push","label","getNestedSchema","path","reach","yupFieldResolver","getFields","getNestedFields","schemaOptions","resolverOptions","resolver","yupResolver","fieldResolver"],"mappings":"oXAaA,IAAMA,EAAU,SAACC,SACf,YAAIA,EAAMC,KAAKC,OAAXC,EAAiBC,KACnB,OAAOJ,EAAMC,KAAKC,KAAKE,KAGzB,OAAQJ,EAAMI,MACZ,IAAK,QACH,MAAO,QACT,IAAK,SACH,MAAO,SACT,IAAK,SACH,MAAO,SACT,IAAK,OACH,MAAO,OAET,QACE,MAAO,SAIPC,EAAiB,SAACL,EAAYM,GAClC,srBAAmBN,EAAMO,sBAAO,OAArBC,UACT,YAAIA,EAAKC,UAALC,EAAcC,OAAOL,GAAO,OAAOE,EAAKC,QAAQE,OAAOL,KAUlDM,EAAsB,SAACC,GAClC,IAEIC,EAFEC,EAAS,GAUf,IAAK,IAAMT,KALTQ,EAFkB,UAAhBD,EAAOT,KAEMS,EAAOG,UAAUD,OAEjBF,EAAOE,OAGS,CAC/B,IAAMf,EAAQc,EAAaR,GAErBW,EAAmB,GACN,UAAfjB,EAAMI,OACRa,EAAQC,IAAMb,EAAeL,EAAO,OACpCiB,EAAQE,IAAMd,EAAeL,EAAO,QAGtCe,EAAOK,QACLd,KAAAA,EACAe,MAAOrB,EAAMC,KAAKoB,OAASf,EAC3BF,KAAML,EAAQC,IACXiB,IAGP,OAAOF,GAGIO,EAAkB,SAACT,EAAyBU,GACvD,OAAOC,QAAMX,EAAQU,IAGVE,EAAmB,SAACZ,GAC/B,MAAO,CACLa,qBACE,OAAOd,EAAoBC,IAE7Bc,yBAAgBrB,GACd,OAAOM,EAAoBU,EAAgBT,EAAQP,4MAKlC,SACrBO,EACAe,EACAC,GAEA,gBAHAD,IAAAA,EAAgB,aAChBC,IAAAA,EAAkB,IAEX,CACLhB,OAAAA,EACAiB,SAAUC,cAAYlB,EAAQe,EAAeC,GAC7CG,cAAeP,EAAiBZ"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.modern.js","sources":["../../yup/src/yup.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '../../src/field'\n\nexport { yupResolver }\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\ntype Options = {\n min?: number\n max?: number\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["getType","field","spec","meta","_field$spec$meta","type","getArrayOption","name","test","tests","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","fields","schemaFields","innerType","options","min","max","push","label","getNestedSchema","path","reach","yupFieldResolver","getFields","getNestedFields","yupForm","schemaOptions","resolverOptions","resolver","yupResolver","fieldResolver"],"mappings":"mVAQA,MAAMA,EAAWC,UACf,YAAIA,EAAMC,KAAKC,OAAXC,EAAiBC,KACnB,OAAOJ,EAAMC,KAAKC,KAAKE,KAGzB,OAAQJ,EAAMI,MACZ,IAAK,QACH,MAAO,QACT,IAAK,SACH,MAAO,SACT,IAAK,SACH,MAAO,SACT,IAAK,OACH,MAAO,OAET,QACE,MAAO,SASPC,EAAiB,CAACL,EAAYM,KAClC,IAAK,MAAMC,KAAQP,EAAMQ,MAAO,OAC9B,YAAID,EAAKE,UAALC,EAAcC,OAAOL,GAAO,OAAOC,EAAKE,QAAQE,OAAOL,KAUlDM,EAAuBC,IAClC,MAAMC,EAAS,GAEf,IAAIC,EAAoC,GAGtCA,EAFkB,UAAhBF,EAAOT,KAEMS,EAAOG,UAAUF,OAEjBD,EAAOC,OAGxB,IAAK,MAAMR,KAAQS,EAAc,CAC/B,MAAMf,EAAQe,EAAaT,GAErBW,EAAmB,GACN,UAAfjB,EAAMI,OACRa,EAAQC,IAAMb,EAAeL,EAAO,OACpCiB,EAAQE,IAAMd,EAAeL,EAAO,QAGtCc,EAAOM,QACLd,KAAAA,EACAe,MAAOrB,EAAMC,KAAKoB,OAASf,EAC3BF,KAAML,EAAQC,IACXiB,IAGP,OAAOH,GAGIQ,EAAkB,CAACT,EAAyBU,IAChDC,EAAMX,EAAQU,GAGVE,EAAoBZ,IACxB,CACLa,UAAS,IACAd,EAAoBC,GAE7Bc,gBAAgBrB,GACPM,EAAoBU,EAAgBT,EAAQP,MAK5CsB,EAAU,CACrBf,EACAgB,EAAgB,GAChBC,EAAkB,MAEX,CACLjB,OAAAA,EACAkB,SAAUC,EAAYnB,EAAQgB,EAAeC,GAC7CG,cAAeR,EAAiBZ"}
1
+ {"version":3,"file":"index.modern.js","sources":["../../yup/src/yup-resolver.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { yupResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["getType","field","spec","meta","_field$spec$meta","type","getArrayOption","name","test","tests","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","fields","schemaFields","innerType","options","min","max","push","label","getNestedSchema","path","reach","yupFieldResolver","getFields","getNestedFields","yupForm","schemaOptions","resolverOptions","resolver","yupResolver","fieldResolver"],"mappings":"mVAaA,MAAMA,EAAWC,UACf,YAAIA,EAAMC,KAAKC,OAAXC,EAAiBC,KACnB,OAAOJ,EAAMC,KAAKC,KAAKE,KAGzB,OAAQJ,EAAMI,MACZ,IAAK,QACH,MAAO,QACT,IAAK,SACH,MAAO,SACT,IAAK,SACH,MAAO,SACT,IAAK,OACH,MAAO,OAET,QACE,MAAO,SAIPC,EAAiB,CAACL,EAAYM,KAClC,IAAK,MAAMC,KAAQP,EAAMQ,MAAO,OAC9B,YAAID,EAAKE,UAALC,EAAcC,OAAOL,GAAO,OAAOC,EAAKE,QAAQE,OAAOL,KAUlDM,EAAuBC,IAClC,MAAMC,EAAS,GAEf,IAAIC,EAAoC,GAGtCA,EAFkB,UAAhBF,EAAOT,KAEMS,EAAOG,UAAUF,OAEjBD,EAAOC,OAGxB,IAAK,MAAMR,KAAQS,EAAc,CAC/B,MAAMf,EAAQe,EAAaT,GAErBW,EAAmB,GACN,UAAfjB,EAAMI,OACRa,EAAQC,IAAMb,EAAeL,EAAO,OACpCiB,EAAQE,IAAMd,EAAeL,EAAO,QAGtCc,EAAOM,QACLd,KAAAA,EACAe,MAAOrB,EAAMC,KAAKoB,OAASf,EAC3BF,KAAML,EAAQC,IACXiB,IAGP,OAAOH,GAGIQ,EAAkB,CAACT,EAAyBU,IAChDC,EAAMX,EAAQU,GAGVE,EAAoBZ,IACxB,CACLa,UAAS,IACAd,EAAoBC,GAE7Bc,gBAAgBrB,GACPM,EAAoBU,EAAgBT,EAAQP,MAK5CsB,EAAU,CACrBf,EACAgB,EAAgB,GAChBC,EAAkB,MAEX,CACLjB,OAAAA,EACAkB,SAAUC,EAAYnB,EAAQgB,EAAeC,GAC7CG,cAAeR,EAAiBZ"}
@@ -0,0 +1,29 @@
1
+ import { AnyObjectSchema } from 'yup';
2
+ import { yupResolver } from '@hookform/resolvers/yup';
3
+ import { FieldProps } from '@saas-ui/forms';
4
+ export { yupResolver };
5
+ export declare type Options = {
6
+ min?: number;
7
+ max?: number;
8
+ };
9
+ /**
10
+ * A helper function to render forms automatically based on a Yup schema
11
+ *
12
+ * @param schema The Yup schema
13
+ * @returns {FieldProps[]}
14
+ */
15
+ export declare const getFieldsFromSchema: (schema: AnyObjectSchema) => FieldProps[];
16
+ export declare const getNestedSchema: (schema: AnyObjectSchema, path: string) => any;
17
+ export declare const yupFieldResolver: (schema: AnyObjectSchema) => {
18
+ getFields(): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
19
+ getNestedFields(name: string): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
20
+ };
21
+ export declare const yupForm: (schema: AnyObjectSchema, schemaOptions?: {}, resolverOptions?: {}) => {
22
+ schema: AnyObjectSchema;
23
+ resolver: <TFieldValues extends import("@saas-ui/forms").FieldValues, TContext>(values: import("react-hook-form").UnpackNestedValue<TFieldValues>, context: TContext | undefined, options: import("react-hook-form").ResolverOptions<TFieldValues>) => Promise<import("react-hook-form").ResolverResult<TFieldValues>>;
24
+ fieldResolver: {
25
+ getFields(): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
26
+ getNestedFields(name: string): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
27
+ };
28
+ };
29
+ //# sourceMappingURL=yup-resolver.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"yup-resolver.d.ts","sourceRoot":"","sources":["../../yup/src/yup-resolver.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,eAAe,EAAE,MAAM,KAAK,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAA;AAE3C,OAAO,EAAE,WAAW,EAAE,CAAA;AAEtB,oBAAY,OAAO,GAAG;IACpB,GAAG,CAAC,EAAE,MAAM,CAAA;IACZ,GAAG,CAAC,EAAE,MAAM,CAAA;CACb,CAAA;AA6BD;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,+BAA8B,UAAU,EA4BvE,CAAA;AAED,eAAO,MAAM,eAAe,kCAAmC,MAAM,QAEpE,CAAA;AAED,eAAO,MAAM,gBAAgB;;0BAKH,MAAM;CAI/B,CAAA;AAED,eAAO,MAAM,OAAO;;;;;8BANM,MAAM;;CAgB/B,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saas-ui/forms",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Theme and components agnostic SaasProvider",
5
5
  "source": "src/index.ts",
6
6
  "exports": {
@@ -14,6 +14,16 @@
14
14
  "./yup": {
15
15
  "require": "./dist/yup/index.js",
16
16
  "default": "./dist/yup/index.modern.js"
17
+ },
18
+ "./yup/src": {
19
+ "default": "./yup/src/index.ts"
20
+ },
21
+ "./zod": {
22
+ "require": "./dist/zod/index.js",
23
+ "default": "./dist/zod/index.modern.js"
24
+ },
25
+ "./zod/src": {
26
+ "default": "./zod/src/index.ts"
17
27
  }
18
28
  },
19
29
  "main": "./dist/index.js",
@@ -73,7 +83,7 @@
73
83
  "@saas-ui/button": "0.4.0",
74
84
  "@saas-ui/input-right-button": "0.3.1",
75
85
  "@saas-ui/number-input": "0.3.0",
76
- "@saas-ui/password-input": "0.3.1",
86
+ "@saas-ui/password-input": "0.3.2",
77
87
  "@saas-ui/pin-input": "0.3.0",
78
88
  "@saas-ui/radio": "0.3.0",
79
89
  "@saas-ui/react-utils": "0.1.0",
package/yup/package.json CHANGED
@@ -6,14 +6,18 @@
6
6
  "source": "./src/index.ts",
7
7
  "exports": {
8
8
  ".": {
9
+ "development": "./src/index.ts",
9
10
  "require": "./../dist/yup/index.js",
10
11
  "types": "./../dist/yup/src/index.d.ts",
11
12
  "default": "./../dist/yup/index.modern.js"
13
+ },
14
+ "./src": {
15
+ "default": "./src/index.ts"
12
16
  }
13
17
  },
14
18
  "main": "../dist/yup/index.js",
15
19
  "module": "../dist/yup/index.modern.js",
16
- "types": "../dist/yup/src/index.d.ts",
20
+ "types": "../dist/yup/index.d.ts",
17
21
  "author": "Eelco Wiersma <eelco@appulse.nl>",
18
22
  "license": "MIT",
19
23
  "peerDependencies": {
@@ -1,2 +0,0 @@
1
- export * from './yup';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../yup/src/index.ts"],"names":[],"mappings":"AAAA,cAAc,OAAO,CAAA"}
@@ -1,25 +0,0 @@
1
- import { AnyObjectSchema } from 'yup';
2
- import { yupResolver } from '@hookform/resolvers/yup';
3
- import { FieldProps } from '../../src/field';
4
- export { yupResolver };
5
- /**
6
- * A helper function to render forms automatically based on a Yup schema
7
- *
8
- * @param schema The Yup schema
9
- * @returns {FieldProps[]}
10
- */
11
- export declare const getFieldsFromSchema: (schema: AnyObjectSchema) => FieldProps[];
12
- export declare const getNestedSchema: (schema: AnyObjectSchema, path: string) => any;
13
- export declare const yupFieldResolver: (schema: AnyObjectSchema) => {
14
- getFields(): FieldProps<import("react-hook-form").FieldValues, string>[];
15
- getNestedFields(name: string): FieldProps<import("react-hook-form").FieldValues, string>[];
16
- };
17
- export declare const yupForm: (schema: AnyObjectSchema, schemaOptions?: {}, resolverOptions?: {}) => {
18
- schema: AnyObjectSchema;
19
- resolver: <TFieldValues extends import("react-hook-form").FieldValues, TContext>(values: import("react-hook-form").UnpackNestedValue<TFieldValues>, context: TContext | undefined, options: import("react-hook-form").ResolverOptions<TFieldValues>) => Promise<import("react-hook-form").ResolverResult<TFieldValues>>;
20
- fieldResolver: {
21
- getFields(): FieldProps<import("react-hook-form").FieldValues, string>[];
22
- getNestedFields(name: string): FieldProps<import("react-hook-form").FieldValues, string>[];
23
- };
24
- };
25
- //# sourceMappingURL=yup.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"yup.d.ts","sourceRoot":"","sources":["../../../yup/src/yup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAS,eAAe,EAAE,MAAM,KAAK,CAAA;AAC5C,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAA;AAErD,OAAO,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAA;AAE5C,OAAO,EAAE,WAAW,EAAE,CAAA;AAkCtB;;;;;GAKG;AACH,eAAO,MAAM,mBAAmB,+BAA8B,UAAU,EA4BvE,CAAA;AAED,eAAO,MAAM,eAAe,kCAAmC,MAAM,QAEpE,CAAA;AAED,eAAO,MAAM,gBAAgB;;0BAKH,MAAM;CAI/B,CAAA;AAED,eAAO,MAAM,OAAO;;;;;8BANM,MAAM;;CAgB/B,CAAA"}