@saas-ui/forms 0.5.3 → 0.6.0-next.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,2 @@
1
- import*as e from"react";import{useFormContext as t,get as r,Controller as n,useFieldArray as a,useForm as l,FormProvider as s,useWatch as i}from"react-hook-form";import{FormControl as o,FormLabel as c,Text as m,forwardRef as u,Switch as p,Checkbox as d,Box as f,FormHelperText as h,FormErrorMessage as E,useMergeRefs as b,Input as v,Textarea as y,useTheme as S,SimpleGrid as x,chakra as g,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 I}from"@saas-ui/pin-input";import{Select as O,NativeSelect as V}from"@saas-ui/select";import{reach as w}from"yup";import{yupResolver as L}from"@hookform/resolvers/yup";import{chakra as R,forwardRef as A,useMultiStyleConfig as D,omitThemingProps as j,StylesProvider as P,useStyles as U}from"@chakra-ui/system";import{MinusIcon as M,AddIcon as $,Icon as B,CheckIcon as T}from"@chakra-ui/icons";import{IconButton as q,Button as z}from"@saas-ui/button";import{createContext as G}from"@chakra-ui/react-utils";import{cx as H,__DEV__ as W,runIfFn as J,callAllHandlers as K}from"@chakra-ui/utils";import{getChildrenOfType as Q,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,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}const ee=["name","label","placeholder"],te=t=>{let{name:r,label:n}=t,a=Z(t,ee);/*#__PURE__*/return e.createElement(o,a,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"],ae=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],le=["name","rules"],se=["ref"],ie=["name","rules"],oe=["ref"],ce=["label"],me=["label"],ue={},pe="text",de=n=>{const{name:a,label:l,help:s,variant:i,hideLabel:m,children:u}=n,p=Z(n,ne),{formState:d}=t(),b=((e,t)=>r(t.errors,e))(a,d);/*#__PURE__*/return e.createElement(o,Y({variant:i},p,{isInvalid:!!b}),l&&!m?/*#__PURE__*/e.createElement(c,{variant:i},l):null,/*#__PURE__*/e.createElement(f,null,u,!s||null!=b&&b.message?null:/*#__PURE__*/e.createElement(h,null,s),(null==b?void 0:b.message)&&/*#__PURE__*/e.createElement(E,null,null==b?void 0:b.message)))},fe=u((t,r)=>{const{type:n=pe}=t,a=(e=>ue[e]||ue[pe])(n);/*#__PURE__*/return e.createElement(a,Y({ref:r},t))}),he=r=>u((a,l)=>{let{name:s,rules:i}=a,o=Z(a,le);const{control:c}=t();/*#__PURE__*/return e.createElement(n,{name:s,control:c,rules:i,render:t=>{let{field:{ref:n}}=t,a=Z(t.field,se);/*#__PURE__*/return e.createElement(r,Y({},a,o,{ref:b(l,n)}))}})}),Ee=r=>u((n,a)=>{let{name:l,rules:s}=n,i=Z(n,ie);const{register:o}=t(),c=o(l,s),{ref:m}=c,u=Z(c,oe);/*#__PURE__*/return e.createElement(r,Y({},u,i,{ref:b(a,m)}))}),be=(t,r,n)=>{let a;a=null!=n&&n.isControlled?he(r):Ee(r);const l=((t,{displayName:r,hideLabel:n,BaseField:a})=>{const l=u((r,l)=>{const{name:s,label:i,help:o,isDisabled:c,isInvalid:m,isReadOnly:u,isRequired:p,rules:d,variant:f}=r,h=Z(r,ae),E=Y({required:p},d);/*#__PURE__*/return e.createElement(a,{name:s,label:i,help:o,hideLabel:n,isDisabled:c,isInvalid:m,isReadOnly:u,isRequired:p,variant:f},/*#__PURE__*/e.createElement(t,Y({ref:l,name:s,label:i,rules:E},h)))});return l.displayName=r,l})(a,{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)||de});return ue[t]=l,l},ve=be("text",v),ye=be("number",_,{isControlled:!0}),Se=be("password",k),xe=be("textarea",y),ge=be("switch",u((t,r)=>{let{label:n}=t,a=Z(t,ce);/*#__PURE__*/return e.createElement(p,Y({ref:r},a),n)}),{isControlled:!0,hideLabel:!0}),Ne=be("select",O,{isControlled:!0}),Ce=be("checkbox",u((t,r)=>{let{label:n}=t,a=Z(t,me);/*#__PURE__*/return e.createElement(d,Y({ref:r},a),n)}),{hideLabel:!0}),_e=be("radio",F,{isControlled:!0}),ke=be("pin",I,{isControlled:!0}),Fe=be("native-select",V,{isControlled:!0}),Ie=e=>{var t;if(null!=(t=e.spec.meta)&&t.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},Oe=(e,t)=>{for(const n of e.tests){var r;if(null!=(r=n.OPTIONS)&&r.params[t])return n.OPTIONS.params[t]}},Ve=e=>{const t=[];let r={};r="array"===e.type?e.innerType.fields:e.fields;for(const e in r){const n=r[e],a={};"array"===n.type&&(a.min=Oe(n,"min"),a.max=Oe(n,"max")),t.push(Y({name:e,label:n.spec.label||e,type:Ie(n)},a))}return t},we=["children"],Le=({children:t})=>/*#__PURE__*/e.createElement(g.div,null,t),Re=t=>{var r,n,a;let{children:l}=t,s=Z(t,we);const i=Y({},null!=(r=null==(n=S().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?r:{spacing:4},s);/*#__PURE__*/return e.createElement(x,i,e.Children.map(l,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(Le,null,t):t))},Ae=(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),[De,je]=G({name:"ArrayFieldContext"}),[Pe,Ue]=G({name:"ArrayFieldRowContext"}),Me=({name:e,defaultValue:r={},keyName:n,min:l,max:s})=>{const{control:i}=t();return Y({},a({control:i,name:e,keyName:n}),{name:e,defaultValue:r,min:l,max:s})},$e=({index:r})=>{const{clearErrors:n}=t(),{name:a,remove:l,fields:s}=je();return e.useEffect(()=>{n(a)},[]),{index:r,isFirst:0===r,isLast:r===s.length-1,name:`${a}.${r}`,remove:e.useCallback(()=>{n(a),l(r)},[r])}},Be=()=>{const{isFirst:e,remove:t}=Ue(),{min:r,fields:n}=je();return{onClick:()=>t(),isDisabled:e&&!!(r&&n.length<=r)}},Te=()=>{const{append:e,defaultValue:t,max:r,fields:n}=je();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(r&&n.length>=r)}},qe=["children","columns","spacing"],ze=["children"],Ge=["name","defaultValue","keyName","min","max","children"],He=({children:t,columns:r,spacing:n,index:a})=>/*#__PURE__*/e.createElement(Je,{index:a},/*#__PURE__*/e.createElement(We,{columns:r,spacing:n},t),/*#__PURE__*/e.createElement(Ke,null)),We=t=>{let{children:r,columns:n,spacing:a}=t,l=Z(t,qe);const{name:s}=Ue();/*#__PURE__*/return e.createElement(Re,Y({flex:"1",columns:n,gridGap:a,mr:"2"},l),Ae(s,r))},Je=({children:t,index:r})=>{const n=$e({index:r});/*#__PURE__*/return e.createElement(Pe,{value:n},/*#__PURE__*/e.createElement(R.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},Ke=t=>/*#__PURE__*/e.createElement(q,Y({icon:/*#__PURE__*/e.createElement(M,null),"aria-label":"Remove row"},Be(),t)),Qe=t=>/*#__PURE__*/e.createElement(q,Y({icon:/*#__PURE__*/e.createElement($,null),"aria-label":"Add row",float:"right"},Te(),t)),Xe=e.forwardRef((t,r)=>{const{children:n}=t,a=Z(t,ze);/*#__PURE__*/return e.createElement(Ze,Y({ref:r},a),/*#__PURE__*/e.createElement(Ye,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},r)=>/*#__PURE__*/e.createElement(He,{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:a,keyName:l,min:s,max:i,children:o}=t,c=Z(t,Ge);const m=Me({name:n,defaultValue:a,keyName:l,min:s,max:i});return e.useImperativeHandle(r,()=>m,[r,m]),/*#__PURE__*/e.createElement(De,{value:m},/*#__PURE__*/e.createElement(de,Y({name:n},c),o))}),et=["name","label","hideLabel","children","columns","spacing"],tt=t=>{const r=N();/*#__PURE__*/return e.createElement(c,Y({as:"legend",sx:r.legend},t))},rt=t=>{const{name:r,label:n,hideLabel:a,children:l,columns:s,spacing:i}=t,c=Z(t,et);/*#__PURE__*/return e.createElement(o,Y({name:r,as:"fieldset"},c),/*#__PURE__*/e.createElement(tt,{display:a?"none":"block"},n),/*#__PURE__*/e.createElement(Re,{columns:s,gridGap:i},Ae(r,l)))},nt=["name","type"],at=["schema"],lt=["name","type","defaultValue"],st=(t,r)=>Ve(((e,t)=>w(e,t))(t,r)).map(t=>{let{name:r,type:n}=t,a=Z(t,nt);/*#__PURE__*/return e.createElement(fe,Y({key:r,name:r,type:n},a))}),it=t=>{let{schema:r}=t,n=Z(t,at);/*#__PURE__*/return e.createElement(Re,n,Ve(r).map(t=>{let{name:n,type:a}=t,l=Z(t,lt);return"array"===a?/*#__PURE__*/e.createElement(Xe,Y({name:n},l),st(r,n)):"object"===a?/*#__PURE__*/e.createElement(rt,Y({name:n},l),st(r,n)):/*#__PURE__*/e.createElement(fe,Y({key:n,name:n,type:a},l))}))},ot=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],ct=u((t,r)=>{const{mode:n="all",resolver:a,reValidateMode:i,shouldFocusError:o,shouldUnregister:c,shouldUseNativeValidation:m,criteriaMode:u,delayError:p,schema:d,defaultValues:f,onSubmit:h,onError:E,formRef:b,children:v}=t,y=Z(t,ot),S={mode:n,resolver:a,defaultValues:f,reValidateMode:i,shouldFocusError:o,shouldUnregister:c,shouldUseNativeValidation:m,criteriaMode:u,delayError:p};d&&(S.resolver=L(d));const x=l(S),{handleSubmit:N}=x;return e.useImperativeHandle(r,()=>x,[r,x]),/*#__PURE__*/e.createElement(s,x,/*#__PURE__*/e.createElement(g.form,Y({ref:b,onSubmit:N(h,E)},y),v))}),mt=["children","disableIfUntouched","disableIfInvalid"],ut=A((r,n)=>{const{children:a,disableIfUntouched:l,disableIfInvalid:s}=r,i=Z(r,mt),{formState:o}=t();/*#__PURE__*/return e.createElement(z,Y({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:n,isDisabled:l&&!o.isDirty||s&&!o.isValid},i),a)});ut.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};const pt=["schema","submitLabel"],dt=u((t,r)=>{const{schema:n,submitLabel:a="Submit"}=t,l=Z(t,pt);/*#__PURE__*/return e.createElement(ct,Y({},l,{schema:n,ref:r}),/*#__PURE__*/e.createElement(Re,null,/*#__PURE__*/e.createElement(it,{schema:n}),a&&/*#__PURE__*/e.createElement(ut,{label:a})))}),ft=({children:e,name:r,defaultValue:n,isDisabled:a,isExact:l,condition:s=(e=>!!e)})=>s(i({name:r,defaultValue:n,disabled:a,exact:l}),t())?e:null;function ht(){return ht=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},ht.apply(this,arguments)}function Et(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}const[bt,vt]=G({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"});function yt(t){const{step:r}=t,[n,a]=e.useState(-1),l=e.useRef([]),[,s]=e.useState(Date.now()),i=e.useCallback(e=>{const t=[...l.current];-1===t.indexOf(e)&&t.push(e),l.current=t,s(Date.now())},[l,s]),o=e=>{const t=l.current.indexOf(e);-1!==t&&a(t)};return e.useLayoutEffect(()=>{"string"==typeof r?o(r):"number"==typeof r?a(r):-1===n&&a(0)},[r]),{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:o,nextStep:()=>{a(n+1)},prevStep:()=>{a(n-1)},registerStep:i,unregisterStep:e=>{l.current=l.current.slice(l.current.indexOf(e),1)}}}function St(t){const{name:r,isActive:n,isCompleted:a}=t,{registerStep:l,unregisterStep:s,activeStep:i}=vt();return e.useEffect(()=>{if(r)return l(r),()=>{s(r)}},[]),{isActive:r?i===r:n,isCompleted:a}}const xt=["children","orientation"],gt=["children","orientation","stepComponent"],Nt=["children","isOpen"],Ct=["icon","isActive","isCompleted","className"],_t=["title","icon","isActive","isCompleted"],kt=["isActive"],Ft=A((t,r)=>{const n=D("Stepper",t),a=j(t),{children:l,orientation:s}=a,i=Et(a,xt),o=yt(t),c=ht({display:"flex",flexDirection:"column"},n.container);return e.createElement(P,{value:n},/*#__PURE__*/e.createElement(bt,{value:o},/*#__PURE__*/e.createElement(R.div,ht({ref:r,__css:c},i,{className:H("saas-stepper__container",t.className)}),/*#__PURE__*/e.createElement(It,{orientation:s},l))))});W&&(Ft.displayName="Stepper");const It=t=>{var r,n;const{children:a,orientation:l,stepComponent:s}=t,i=Et(t,gt),o=U(),{activeIndex:c}=vt(),m=ht({display:"flex",flexDirection:"row",alignItems:"center"},o.steps),u="vertical"===l,p=s||wt,d=Q(a,p),f=d.reduce((t,r,n,a)=>(t.push(/*#__PURE__*/e.createElement(p,ht({key:n},r.props,{icon:r.props.icon||n+1,isActive:c===n,isCompleted:r.props.isCompleted||c>n}))),"vertical"===l&&t.push(/*#__PURE__*/e.createElement(Ot,{key:`content-${n}`,isOpen:c===n},r.props.children)),n<a.length-1&&t.push(/*#__PURE__*/e.createElement(Lt,{key:`separator-${n}`,isActive:n<c})),t),[]),h=X(a,At),E=c>=d.length?h:u?null:/*#__PURE__*/e.createElement(Ot,null,null==(r=d[c])||null==(n=r.props)?void 0:n.children);return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(R.div,ht({__css:m},i,{className:H("saas-stepper__steps",t.className)}),f),E)};W&&(It.displayName="StepperSteps");const Ot=t=>{const{children:r,isOpen:n=!0}=t,a=Et(t,Nt),l=U();return e.createElement(R.div,ht({__css:l.content},a,{className:H("saas-stepper__content",t.className)}),/*#__PURE__*/e.createElement(C,{in:n},r))};W&&(Ot.displayName="StepperContent");const Vt=t=>{const{icon:r,isCompleted:n,className:a}=t,l=Et(t,Ct),s=ht({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},U().icon);let i;return i=n?/*#__PURE__*/e.createElement(B,{as:T}):r,/*#__PURE__*/e.createElement(R.div,ht({__css:s},l,{className:H("saas-stepper__icon",a)}),i)};W&&(Vt.displayName="StepperIcon");const wt=t=>{const{title:r,icon:n,isActive:a,isCompleted:l}=t,s=Et(t,_t),i=St(t),o=ht({display:"flex",alignItems:"center",flexDirection:"row"},U().step);return e.createElement(R.div,ht({__css:o,"data-active":i.isActive,"data-completed":i.isCompleted},s,{className:H("saas-stepper__step",t.className)}),/*#__PURE__*/e.createElement(Vt,{icon:n,isActive:a,isCompleted:l}),r&&/*#__PURE__*/e.createElement(Rt,null,r))};W&&(wt.displayName="StepperStep");const Lt=t=>{const{isActive:r}=t,n=Et(t,kt),a=ht({flex:1,borderTopWidth:"1px",mx:2},U().separator);return e.createElement(R.div,ht({"data-active":r},n,{className:H("saas-stepper__separator",t.className),__css:a}))};W&&(Lt.displayName="StepperSeparator");const Rt=t=>{const r=U();return e.createElement(R.p,ht({},t,{__css:r.title,className:H("saas-stepper__title",t.className)}))};W&&(Rt.displayName="StepperStepTitle");const At=t=>{const r=U();return e.createElement(R.div,ht({__css:r.completed},t,{className:H("saas-stepper__completed",t.className)}))};W&&(At.displayName="StepperCompleted");const[Dt,jt]=G({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function Pt(t){const r=yt(t),{activeStep:n,isLastStep:a,nextStep:l}=r,[s,i]=e.useState({}),o=e.useCallback(async e=>{if(a)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{m(Y({},s[n],{isCompleted:!0}))}).then(l);l()},[n,a]),c=e.useCallback(e=>{const t=s[n];return{onSubmit:o,schema:null==t?void 0:t.schema}},[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 Ut(t){const{name:r,schema:n}=t,a=St({name:r}),{steps:l,updateStep:s}=jt();return e.useEffect(()=>{s({name:r,schema:n})},[r,n]),Y({},a,l[r]||{name:r,schema:n})}const Mt=["children","onSubmit"],$t=["getFormProps"],Bt=["name","schema","children","className"],Tt=["label","submitLabel"],qt=e.forwardRef((t,r)=>{const{children:n}=t,a=Z(t,Mt),l=Pt(t),{getFormProps:s}=l,i=Z(l,$t),o=e.useMemo(()=>i,[i]);/*#__PURE__*/return e.createElement(bt,{value:o},/*#__PURE__*/e.createElement(Dt,{value:o},/*#__PURE__*/e.createElement(ct,Y({ref:r},a,s(t)),J(n,l))))}),zt=t=>{const r=D("Stepper",t),{children:n}=t,a=e.Children.map(n,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===Gt){const{isCompleted:r}=Ut(t.props);/*#__PURE__*/return e.createElement(wt,{name:t.props.name,title:t.props.title,isCompleted:r},t.props.children)}return t});/*#__PURE__*/return e.createElement(P,{value:r},/*#__PURE__*/e.createElement(It,Y({mb:"4"},t),a))},Gt=t=>{const{name:r,schema:n,children:a,className:l}=t,s=Z(t,Bt),i=Ut({name:r,schema:n}),{isActive:o}=i;return o?/*#__PURE__*/e.createElement(R.div,Y({},s,{className:H("saas-form__step",l)}),a):null};W&&(Gt.displayName="FormStep");const Ht=t=>{const{isFirstStep:r,isCompleted:n,prevStep:a}=vt();/*#__PURE__*/return e.createElement(z,Y({isDisabled:r||n,label:"Back"},t,{className:H("saas-form__prev-button",t.className),onClick:K(t.onClick,a)}))};W&&(Ht.displayName="PrevButton");const Wt=t=>{const{label:r="Next",submitLabel:n="Complete"}=t,a=Z(t,Tt),{isLastStep:l,isCompleted:s}=vt();/*#__PURE__*/return e.createElement(ut,Y({isDisabled:s,label:l||s?n:r},a,{className:H("saas-form__next-button",t.className)}))};W&&(Wt.displayName="NextButton");export{Xe as ArrayField,Qe as ArrayFieldAddButton,Ze as ArrayFieldContainer,De as ArrayFieldProvider,Ke as ArrayFieldRemoveButton,He as ArrayFieldRow,Je as ArrayFieldRowContainer,We as ArrayFieldRowFields,Pe as ArrayFieldRowProvider,Ye as ArrayFieldRows,dt as AutoForm,de as BaseField,Ce as CheckboxField,te as DisplayField,ft as DisplayIf,fe as Field,it as Fields,ct as Form,Re as FormLayout,tt as FormLegend,Gt as FormStep,zt as FormStepper,re as FormValue,ve as InputField,Fe as NativeSelectField,Wt as NextButton,ye as NumberInputField,rt as ObjectField,Se as PasswordInputFIeld,ke as PinField,Ht as PrevButton,_e as RadioField,Ne as SelectField,qt as StepForm,Dt as StepFormProvider,ut as SubmitButton,ge as SwitchField,xe as TextareaField,be as registerFieldType,Me as useArrayField,Te as useArrayFieldAddButton,je as useArrayFieldContext,Be as useArrayFieldRemoveButton,$e as useArrayFieldRow,Ue as useArrayFieldRowContext,Ut as useFormStep,Pt as useStepForm,jt as useStepFormContext,he as withControlledInput,Ee 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 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=>Object.entries(e).map(([e,t])=>X({name:e},t)),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 defaultFieldResolver,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};
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/resolvers/yup.ts","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/form.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 { SchemaOf, AnySchema, reach } from 'yup'\nexport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '../field'\n\n// @TODO get proper typings for the schema fields\n\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 = (\n schema: SchemaOf<AnySchema>\n): 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: SchemaOf<AnySchema>, path: string) => {\n return reach(schema, path)\n}\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'\nimport { getFieldsFromSchema, getNestedSchema } from './resolvers/yup'\n\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\n\nexport interface FieldsProps {\n schema: any\n}\n\nconst getNestedFields = (schema: any, name: string) => {\n return getFieldsFromSchema(getNestedSchema(schema, name)).map(\n ({ name, type, ...nestedFieldProps }: FieldProps): React.ReactNode => (\n <Field key={name} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({ schema, ...props }) => {\n return (\n <FormLayout {...props}>\n {getFieldsFromSchema(schema).map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField name={name} {...fieldProps}>\n {getNestedFields(schema, 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 { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n} from 'react-hook-form'\n\nimport { yupResolver } from './resolvers/yup'\n\nexport type { UseFormReturn, FieldValues }\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\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\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 // @todo remove yup dependency and just use resolver prop?\n if (schema) {\n form.resolver = yupResolver(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","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'\n\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\n\ninterface AutoFormOptions {\n schema: any\n submitLabel?: false | string\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', ...rest } = props\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","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 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 }\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}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema })\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\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, children, className, ...rest } = props\n const step = useFormStep({ name, schema })\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","getType","spec","meta","_field$spec$meta","getArrayOption","test","tests","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","fields","schemaFields","innerType","min","max","push","FormLayoutItem","chakra","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","useFieldArray","useArrayFieldRow","index","clearErrors","remove","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","useImperativeHandle","FormLegend","styles","useStyles","as","sx","legend","ObjectField","getNestedFields","path","reach","getNestedSchema","nestedFieldProps","Fields","_ref2","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","yupResolver","methods","useForm","handleSubmit","FormProvider","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","setStep","i","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","useMemo","runIfFn","FormStepper","useMultiStyleConfig","elements","FormStep","StepperStep","title","StylesProvider","StepperSteps","className","cx","__DEV__","PrevButton","callAllHandlers","NextButton"],"mappings":"mqDAgBaA,GAA4CC,QAACC,KACxDA,EADwDC,MAExDA,KAEGC,uBAEH,OACEC,gBAACC,EAAgBF,EACdD,eAAQE,gBAACE,GAAUC,QAASN,GAAOC,GAAqB,kBACzDE,gBAACI,GAAKC,SAAS,mBACbL,gBAACM,IAAUT,KAAMA,OAMZS,GAAwC,EAAGT,KAAAA,MACtD,MAAMU,UAAEA,GAAcC,IACtB,OAAOD,EAAUV,IAAS,0PC8EtBY,GAAsC,GAEtCC,GAAmB,OAiBZC,GAAmCZ,IAC9C,MAAMF,KAAEA,EAAFC,MAAQA,EAARc,KAAeA,EAAfC,QAAqBA,EAArBC,UAA8BA,EAA9BC,SAAyCA,GAC7ChB,EAD0DiB,IAC1DjB,OAEIkB,UAAEA,GAAcT,IAEhBU,EAjBS,EAACrB,EAAcoB,IACvBE,EAAIF,EAAUG,OAAQvB,GAgBfwB,CAASxB,EAAMoB,gBAE7B,OACEjB,gBAACC,KAAYY,QAASA,GAAaG,GAAcM,YAAaJ,IAC3DpB,IAAUgB,eACTd,gBAACE,GAAUW,QAASA,GAAUf,GAC5B,kBACJE,gBAACuB,OACER,GACAH,SAASM,GAAAA,EAAOM,QAEb,kBADFxB,gBAACyB,OAAgBb,UAElBM,SAAAA,EAAOM,uBACNxB,gBAAC0B,aA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A,EAAR9E,SAAgBA,EAAhBqQ,UAA0BA,GAAuBrR,EAATuM,IAASvM,MACjDmO,EAAOqC,GAAY,CAAE1Q,KAAAA,EAAMgG,OAAAA,KAE3B6J,SAAEA,GAAaxB,EAErB,OAAOwB,eACL1P,gBAACqG,EAAOC,SAAQgG,GAAM8E,UAAWC,EAAG,kBAAmBD,KACpDrQ,GAED,MAGFuQ,IACFP,GAAS/N,YAAc,YAGZuO,MAAAA,GAAqCxR,IAChD,MAAMoP,YAAEA,EAAFE,YAAeA,EAAfE,SAA4BA,GAAaxB,kBAE/C,OACE/N,gBAACgN,KACC/J,WAAYkM,GAAeE,EAC3BvP,MAAM,QACFC,GACJqR,UAAWC,EAAG,yBAA0BtR,EAAMqR,WAC9C5I,QAASgJ,EAAgBzR,EAAMyI,QAAS+G,OAK1C+B,IACFC,GAAWvO,YAAc,cAOdyO,MAAAA,GAAyC1R,IACpD,MAAMD,MAAEA,EAAQ,OAAVyN,YAAkBA,EAAc,YAAwBxN,EAATuM,IAASvM,OACxDqP,WAAEA,EAAFC,YAAcA,GAAgBtB,kBAEpC,OACE/N,gBAAC6M,MACC5J,WAAYoM,EACZvP,MAAOsP,GAAcC,EAAc9B,EAAczN,GAC7CwM,GACJ8E,UAAWC,EAAG,yBAA0BtR,EAAMqR,eAKhDE,IACFG,GAAWzO,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\n// @todo finalize this\nexport type FormSchema = Record<string, any>\n\nconst mapFields = (schema: FormSchema) =>\n Object.entries(schema).map(([name, field]) => {\n return {\n name,\n ...field,\n }\n })\n\nexport const defaultFieldResolver = (schema: FormSchema): 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 { defaultFieldResolver, 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 = defaultFieldResolver\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","defaultFieldResolver","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,UAAEA,GAAcC,IACtB,OAAOD,EAAUV,IAAS,0PC8EtBY,GAAsC,GAEtCC,GAAmB,OAiBZC,GAAmCZ,IAC9C,MAAMF,KAAEA,EAAFC,MAAQA,EAARc,KAAeA,EAAfC,QAAqBA,EAArBC,UAA8BA,EAA9BC,SAAyCA,GAC7ChB,EAD0DiB,IAC1DjB,OAEIkB,UAAEA,GAAcT,IAEhBU,EAjBS,EAACrB,EAAcoB,IACvBE,EAAIF,EAAUG,OAAQvB,GAgBfwB,CAASxB,EAAMoB,gBAE7B,OACEjB,gBAACC,KAAYY,QAASA,GAAaG,GAAcM,YAAaJ,IAC3DpB,IAAUgB,eACTd,gBAACE,GAAUW,QAASA,GAAUf,GAC5B,kB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A,GAAuB/Q,EAATyG,IAASzG,MAC3D8N,EAAOqC,GAAY,CAAErQ,KAAAA,EAAMsF,OAAAA,EAAQU,SAAAA,KAEnCwJ,SAAEA,GAAaxB,EAErB,OAAOwB,eACLrP,gBAACgH,EAAOG,SAAQX,GAAMsK,UAAWC,EAAG,kBAAmBD,KACpD/P,GAED,MAGFiQ,IACFP,GAASzN,YAAc,YAGZiO,MAAAA,GAAqClR,IAChD,MAAM+O,YAAEA,EAAFE,YAAeA,EAAfE,SAA4BA,GAAaxB,kBAE/C,OACE1N,gBAAC2M,KACC1J,WAAY6L,GAAeE,EAC3BlP,MAAM,QACFC,GACJ+Q,UAAWC,EAAG,yBAA0BhR,EAAM+Q,WAC9CtH,QAAS0H,EAAgBnR,EAAMyJ,QAAS0F,OAK1C8B,IACFC,GAAWjO,YAAc,cAOdmO,MAAAA,GAAyCpR,IACpD,MAAMD,MAAEA,EAAQ,OAAVoN,YAAkBA,EAAc,YAAwBnN,EAATyG,IAASzG,OACxDgP,WAAEA,EAAFC,YAAcA,GAAgBtB,kBAEpC,OACE1N,gBAACwM,MACCvJ,WAAY+L,EACZlP,MAAOiP,GAAcC,EAAc9B,EAAcpN,GAC7C0G,GACJsK,UAAWC,EAAG,yBAA0BhR,EAAM+Q,eAKhDE,IACFG,GAAWnO,YAAc"}
@@ -19,6 +19,10 @@ export interface FormStepOptions {
19
19
  * Schema
20
20
  */
21
21
  schema?: any;
22
+ /**
23
+ * Hook Form Resolver
24
+ */
25
+ resolver?: any;
22
26
  }
23
27
  export declare const FormStepper: React.FC<StepperStepsProps>;
24
28
  export interface FormStepProps extends FormStepOptions, HTMLChakraProps<'div'> {
@@ -1 +1 @@
1
- {"version":3,"file":"step-form.d.ts","sourceRoot":"","sources":["../src/step-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE5D,OAAO,E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AmB,CAAA;AAI1B,OAAO,EAGL,iBAAiB,EAGlB,MAAM,kBAAkB,CAAA;AACzB,OAAO,EAAU,WAAW,EAAE,MAAM,iBAAiB,CAAA;AAErD,OAAO,EAAQ,SAAS,EAAE,MAAM,QAAQ,CAAA;AAGxC,OAAO,EAIL,gBAAgB,EACjB,MAAM,iBAAiB,CAAA;AAExB,MAAM,WAAW,aAAa,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,CAC3E,SAAQ,gBAAgB,CAAC,YAAY,CAAC,EACpC,SAAS,CAAC,YAAY,CAAC;CAAG;AAE9B,eAAO,MAAM,QAAQ;;MA2BhB,MAAM,YAAY,CAAA;AAEvB,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,IAAI,EAAE,MAAM,CAAA;IACZ;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ;;OAEG;IACH,QAAQ,CAAC,EAAE,GAAG,CAAA;CACf;AAED,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,iBAAiB,CA4BnD,CAAA;AAED,MAAM,WAAW,aACf,SAAQ,eAAe,EACrB,eAAe,CAAC,KAAK,CAAC;CAAG;AAE7B,eAAO,MAAM,QAAQ,EAAE,KAAK,CAAC,EAAE,CAAC,aAAa,CAW5C,CAAA;AAMD,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,WAAW,CAY5C,CAAA;AAMD,MAAM,WAAW,eAAgB,SAAQ,WAAW;IAClD,WAAW,CAAC,EAAE,MAAM,CAAA;CACrB;AAED,eAAO,MAAM,UAAU,EAAE,KAAK,CAAC,EAAE,CAAC,eAAe,CAYhD,CAAA"}
@@ -4,6 +4,7 @@ import { UseStepperProps, UseStepperReturn } from '@saas-ui/stepper';
4
4
  export interface StepState {
5
5
  name: string;
6
6
  schema?: any;
7
+ resolver?: any;
7
8
  isActive?: boolean;
8
9
  isCompleted?: boolean;
9
10
  }
@@ -31,6 +32,7 @@ export declare function useStepForm<TFieldValues extends FieldValues = FieldValu
31
32
  getFormProps: (props: any) => {
32
33
  onSubmit: SubmitHandler<TFieldValues>;
33
34
  schema: any;
35
+ resolver: any;
34
36
  };
35
37
  updateStep: (step: any) => void;
36
38
  steps: {};
@@ -39,6 +41,7 @@ export declare type UseStepFormReturn = ReturnType<typeof useStepForm>;
39
41
  export interface UseFormStepProps {
40
42
  name: string;
41
43
  schema?: any;
44
+ resolver?: any;
42
45
  }
43
46
  export declare function useFormStep(props: UseFormStepProps): StepState;
44
47
  //# sourceMappingURL=use-step-form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-step-form.d.ts","sourceRoot":"","sources":["../src/use-step-form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,WAAW,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAA;AAE5D,OAAO,EAGL,eAAe,EACf,gBAAgB,EACjB,MAAM,kBAAkB,CAAA;AAEzB,MAAM,WAAW,SAAS;IACxB,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB,WAAW,CAAC,EAAE,OAAO,CAAA;CACtB;AAED,MAAM,WAAW,eAAgB,SAAQ,gBAAgB;IACvD,UAAU,CAAC,KAAK,EAAE,SAAS,GAAG,IAAI,CAAA;IAClC,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAA;CACjC;AAED,eAAO,MAAO,gBAAgB,mCAAE,kBAAkB,uBAK9C,CAAA;AAEJ,OAAO,EAAE,SAAS,EAAE,MAAM,QAAQ,CAAA;AAElC,MAAM,WAAW,gBAAgB,CAC/B,YAAY,SAAS,WAAW,GAAG,WAAW,CAC9C,SAAQ,eAAe,EACrB,SAAS,CAAC,YAAY,CAAC;CAAG;AAE9B,wBAAgB,WAAW,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,EACxE,KAA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AAC;;;;;;;;;;;;;;;;;;;;EA0DtC;AAED,oBAAY,iBAAiB,GAAG,UAAU,CAAC,OAAO,WAAW,CAAC,CAAA;AAE9D,MAAM,WAAW,gBAAgB;IAC/B,IAAI,EAAE,MAAM,CAAA;IACZ,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ,QAAQ,CAAC,EAAE,GAAG,CAAA;CACf;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,gBAAgB,GAAG,SAAS,CAc9D"}
@@ -0,0 +1,2 @@
1
+ var e=require("yup"),r=require("@hookform/resolvers/yup");function t(){return t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},t.apply(this,arguments)}function n(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}var a=function(e){var r;if(null!=(r=e.spec.meta)&&r.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},o=function(e,r){for(var t,a=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return n(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?n(e,r):void 0}}(e))){t&&(e=t);var a=0;return function(){return a>=e.length?{done:!0}:{done:!1,value:e[a++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.tests);!(t=a()).done;){var o,u=t.value;if(null!=(o=u.OPTIONS)&&o.params[r])return u.OPTIONS.params[r]}},u=function(e){var r,n=[];for(var u in r="array"===e.type?e.innerType.fields:e.fields){var i=r[u],s={};"array"===i.type&&(s.min=o(i,"min"),s.max=o(i,"max")),n.push(t({name:u,label:i.spec.label||u,type:a(i)},s))}return n},i=function(r,t){return e.reach(r,t)},s=function(e){return{getFields:function(){return u(e)},getNestedFields:function(r){return u(i(e,r))}}};Object.defineProperty(exports,"yupResolver",{enumerable:!0,get:function(){return r.yupResolver}}),exports.getFieldsFromSchema=u,exports.getNestedSchema=i,exports.yupFieldResolver=s,exports.yupForm=function(e,t,n){return void 0===t&&(t={}),void 0===n&&(n={}),{schema:e,resolver:r.yupResolver(e,t,n),fieldResolver:s(e)}};
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ import{reach as e}from"yup";import{yupResolver as r}from"@hookform/resolvers/yup";export{yupResolver}from"@hookform/resolvers/yup";function t(){return t=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},t.apply(this,arguments)}const a=e=>{var r;if(null!=(r=e.spec.meta)&&r.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},o=(e,r)=>{for(const a of e.tests){var t;if(null!=(t=a.OPTIONS)&&t.params[r])return a.OPTIONS.params[r]}},s=e=>{const r=[];let s={};s="array"===e.type?e.innerType.fields:e.fields;for(const e in s){const n=s[e],p={};"array"===n.type&&(p.min=o(n,"min"),p.max=o(n,"max")),r.push(t({name:e,label:n.spec.label||e,type:a(n)},p))}return r},n=(r,t)=>e(r,t),p=e=>({getFields:()=>s(e),getNestedFields:r=>s(n(e,r))}),l=(e,t={},a={})=>({schema:e,resolver:r(e,t,a),fieldResolver:p(e)});export{s as getFieldsFromSchema,n as getNestedSchema,p as yupFieldResolver,l as yupForm};
2
+ //# sourceMappingURL=index.modern.js.map
@@ -0,0 +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"}
@@ -0,0 +1,2 @@
1
+ export * from './yup';
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,OAAO,CAAA"}
@@ -0,0 +1,25 @@
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
@@ -0,0 +1 @@
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"}