@saas-ui/forms 1.4.1 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +25 -0
- package/ajv/package.json +3 -2
- package/dist/ajv/index.js +1 -84
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/index.modern.mjs +2 -0
- package/dist/ajv/index.modern.mjs.map +1 -0
- package/dist/auto-form.d.ts +1 -1
- package/dist/field.d.ts +2 -2
- package/dist/field.d.ts.map +1 -1
- package/dist/form.d.ts +7 -7
- package/dist/form.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +2 -0
- package/dist/index.modern.mjs.map +1 -0
- package/dist/layout.d.ts +1 -0
- package/dist/layout.d.ts.map +1 -1
- package/dist/step-form.d.ts +1 -1
- package/dist/use-array-field.d.ts +8 -8
- package/dist/yup/index.js.map +1 -1
- package/dist/yup/{index.modern.js → index.modern.mjs} +1 -1
- package/dist/yup/index.modern.mjs.map +1 -0
- package/dist/yup/yup-resolver.d.ts +1 -1
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/{index.modern.js → index.modern.mjs} +1 -1
- package/dist/zod/index.modern.mjs.map +1 -0
- package/dist/zod/zod-resolver.d.ts +1 -1
- package/package.json +21 -21
- package/src/field.tsx +2 -2
- package/src/form.tsx +26 -14
- package/yup/package.json +2 -2
- package/zod/package.json +2 -2
- package/dist/ajv/index.modern.js +0 -85
- package/dist/ajv/index.modern.js.map +0 -1
- package/dist/index.modern.js +0 -2
- package/dist/index.modern.js.map +0 -1
- package/dist/yup/index.modern.js.map +0 -1
- package/dist/zod/index.modern.js.map +0 -1
@@ -0,0 +1,2 @@
|
|
1
|
+
import*as e from"react";import{__DEV__ as t,callAllHandlers as l,get as a,cx as r,runIfFn as n}from"@chakra-ui/utils";import{useFormContext as s,Controller as i,get as o,useForm as m,FormProvider as c,useFieldArray as d,useWatch as u}from"react-hook-form";export{Controller,FormProvider,appendErrors,useController,useFieldArray,useForm,useFormContext,useFormState,useWatch}from"react-hook-form";import{FormControl as p,FormLabel as f,Text as h,forwardRef as b,Input as y,InputGroup as E,Switch as v,Checkbox as g,HStack as F,PinInput as N,Box as C,FormHelperText as x,FormErrorMessage as S,useMergeRefs as k,Textarea as R,PinInputField as V,chakra as L,useTheme as w,SimpleGrid as A,useStyleConfig as I}from"@chakra-ui/react";import{NumberInput as B}from"@saas-ui/number-input";import{PasswordInput as D}from"@saas-ui/password-input";import{RadioInput as O}from"@saas-ui/radio";import{Select as j,NativeSelect as M}from"@saas-ui/select";import{forwardRef as U,chakra as _}from"@chakra-ui/system";import{MinusIcon as z,AddIcon as P}from"@chakra-ui/icons";import{IconButton as $,Button as q}from"@saas-ui/button";import{createContext as H}from"@chakra-ui/react-utils";import{useStepper as T,useStep as G,StepperProvider as W,useStepperContext as J,StepperStep as K,StepperContainer as Q,StepperSteps as X}from"@saas-ui/stepper";export*from"@saas-ui/input-right-button";function Y(){return Y=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var l=arguments[t];for(var a in l)Object.prototype.hasOwnProperty.call(l,a)&&(e[a]=l[a])}return e},Y.apply(this,arguments)}function Z(e,t){if(null==e)return{};var l,a,r={},n=Object.keys(e);for(a=0;a<n.length;a++)t.indexOf(l=n[a])>=0||(r[l]=e[l]);return r}const ee=["name","label","placeholder"],te=t=>{let{name:l,label:a}=t,r=Z(t,ee);/*#__PURE__*/return e.createElement(p,r,a?/*#__PURE__*/e.createElement(f,{htmlFor:l},a):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(le,{name:l})))};t&&(te.displayName="DisplayField");const le=({name:e})=>{const{getValues:t}=s();return t(e)||null};t&&(le.displayName="FormValue");const ae=["name","label","help","hideLabel","children"],re=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules"],ne=["name","rules"],se=["ref"],ie=["name","rules"],oe=["ref"],me=["type","leftAddon","rightAddon","size"],ce=["type","value"],de=["label","type"],ue=["pinLength","pinType","spacing"],pe={},fe="text",he=t=>{const{name:l,label:a,help:r,hideLabel:n,children:i}=t,m=Z(t,ae),{formState:c}=s(),d=((e,t)=>o(t.errors,e))(l,c);/*#__PURE__*/return e.createElement(p,Y({},m,{isInvalid:!!d}),a&&!n?/*#__PURE__*/e.createElement(f,null,a):null,/*#__PURE__*/e.createElement(C,null,i,!r||null!=d&&d.message?null:/*#__PURE__*/e.createElement(x,null,r),(null==d?void 0:d.message)&&/*#__PURE__*/e.createElement(S,null,null==d?void 0:d.message)))};t&&(he.displayName="BaseField");const be=e.forwardRef((t,l)=>{const{type:a=fe}=t,r=(e=>pe[e]||pe[fe])(a);/*#__PURE__*/return e.createElement(r,Y({ref:l},t))}),ye=t=>b((a,r)=>{let{name:n,rules:o}=a,m=Z(a,ne);const{control:c}=s();/*#__PURE__*/return e.createElement(i,{name:n,control:c,rules:o,render:a=>{let{field:{ref:n}}=a,s=Z(a.field,se);/*#__PURE__*/return e.createElement(t,Y({},s,m,{onChange:l(m.onChange,s.onChange),onBlur:l(m.onBlur,s.onBlur),ref:k(r,n)}))}})}),Ee=t=>b((a,r)=>{let{name:n,rules:i}=a,o=Z(a,ie);const{register:m}=s(),c=m(n,i),{ref:d}=c,u=Z(c,oe);/*#__PURE__*/return e.createElement(t,Y({},u,o,{onChange:l(o.onChange,u.onChange),onBlur:l(o.onBlur,u.onBlur),ref:k(r,d)}))}),ve=(t,l,a)=>{let r;r=null!=a&&a.isControlled?ye(l):Ee(l);const n=((t,{displayName:l,hideLabel:a,BaseField:r})=>{const n=b((l,n)=>{const{id:s,name:i,label:o,help:m,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,rules:f}=l,h=Z(l,re),b=Y({required:p},f);/*#__PURE__*/return e.createElement(r,{id:s,name:i,label:o,help:m,hideLabel:a,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p},/*#__PURE__*/e.createElement(t,Y({ref:n,id:s,name:i,label:a?o:void 0,rules:b},h)))});return n.displayName=l,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==a?void 0:a.hideLabel,BaseField:(null==a?void 0:a.BaseField)||he});return pe[t]=n,n},ge=ve("text",b((t,l)=>{let{type:a="text",leftAddon:r,rightAddon:n,size:s}=t,i=Z(t,me);const o=/*#__PURE__*/e.createElement(y,Y({type:a,size:s},i,{ref:l}));return r||n?/*#__PURE__*/e.createElement(E,{size:s},r,o,n):o})),Fe=ve("number",B,{isControlled:!0}),Ne=ve("password",b((t,l)=>/*#__PURE__*/e.createElement(D,Y({ref:l},t)))),Ce=ve("textarea",R),xe=ve("switch",b((t,l)=>{let{value:a}=t,r=Z(t,ce);/*#__PURE__*/return e.createElement(v,Y({isChecked:!!a},r,{ref:l}))}),{isControlled:!0}),Se=ve("select",j,{isControlled:!0}),ke=ve("checkbox",b((t,l)=>{let{label:a}=t,r=Z(t,de);/*#__PURE__*/return e.createElement(g,Y({ref:l},r),a)}),{hideLabel:!0}),Re=ve("radio",O,{isControlled:!0}),Ve=ve("native-select",M,{isControlled:!0}),Le=ve("pin",b((t,l)=>{const{pinLength:a=4,pinType:r,spacing:n}=t,s=Z(t,ue),i=[];for(let t=0;t<a;t++)i.push(/*#__PURE__*/e.createElement(V,{key:t,ref:l}));/*#__PURE__*/return e.createElement(F,{spacing:n},/*#__PURE__*/e.createElement(N,Y({},s,{type:r}),i))}),{isControlled:!0}),we=["items","label","title"],Ae=e=>e&&Object.entries(e).map(([e,t])=>{let{label:l,title:a}=t;return Y({},Z(t,we),{name:e,label:l||a})}),Ie=e=>({getFields:()=>Ae(e),getNestedFields:t=>{var l;const r=a(e,t);return r?"object"===(null==(l=r.items)?void 0:l.type)?Ae(r.items.properties):"object"===r.type?Ae(r.properties):[r.items]:[]}}),Be=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onChange","onSubmit","onError","formRef","children"],De=b((t,l)=>{const{mode:a="all",resolver:s,reValidateMode:i,shouldFocusError:o,shouldUnregister:d,shouldUseNativeValidation:u,criteriaMode:p,delayError:f,schema:h,defaultValues:b,onChange:y,onSubmit:E,onError:v,formRef:g,children:F}=t,N=Z(t,Be),C={mode:a,resolver:s,defaultValues:b,reValidateMode:i,shouldFocusError:o,shouldUnregister:d,shouldUseNativeValidation:u,criteriaMode:p,delayError:f};h&&!s&&(C.resolver=null==De.getResolver?void 0:De.getResolver(h));const x=m(C),{handleSubmit:S}=x;return e.useImperativeHandle(l,()=>x,[l,x]),e.useEffect(()=>{let e;return y&&(e=x.watch(y)),()=>{var t;return null==(t=e)?void 0:t.unsubscribe()}},[x,y]),/*#__PURE__*/e.createElement(c,x,/*#__PURE__*/e.createElement(L.form,Y({ref:g,onSubmit:S(E,v)},N,{className:r("saas-form",t.className)}),n(F,x)))});De.getFieldResolver=Ie,t&&(De.displayName="Form");const Oe=["children"],je=({children:t})=>/*#__PURE__*/e.createElement(L.div,null,t);t&&(je.displayName="FormLayoutItem");const Me=t=>{var l,a,n;let{children:s}=t,i=Z(t,Oe);const o=Y({},null!=(l=null==(a=w().components)||null==(n=a.FormLayout)?void 0:n.defaultProps)?l:{spacing:4},i);/*#__PURE__*/return e.createElement(A,Y({},o,{className:r("saas-form__layout",i.className)}),e.Children.map(s,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(je,null,t):t))};t&&(Me.displayName="FormLayout");const Ue=(t,l)=>e.Children.map(l,l=>e.isValidElement(l)&&l.props.name?e.cloneElement(l,Y({},l.props,{name:`${t}.${l.props.name}`})):l),[_e,ze]=H({name:"ArrayFieldContext"}),[Pe,$e]=H({name:"ArrayFieldRowContext"}),qe=({name:e,defaultValue:t={},keyName:l,min:a,max:r})=>{const{control:n}=s();return Y({},d({control:n,name:e,keyName:l}),{name:e,defaultValue:t,min:a,max:r})},He=({index:t})=>{const{clearErrors:l}=s(),{name:a,remove:r,fields:n}=ze();return e.useEffect(()=>{l(a)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${a}.${t}`,remove:e.useCallback(()=>{l(a),r(t)},[t])}},Te=()=>{const{isFirst:e,remove:t}=$e(),{min:l,fields:a}=ze();return{onClick:()=>t(),isDisabled:e&&!!(l&&a.length<=l)}},Ge=()=>{const{append:e,defaultValue:t,max:l,fields:a}=ze();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(l&&a.length>=l)}},We=["children","index"],Je=["children"],Ke=["children"],Qe=["name","defaultValue","keyName","min","max","children"],Xe=t=>{let{children:l,index:a}=t,r=Z(t,We);/*#__PURE__*/return e.createElement(Ze,{index:a},/*#__PURE__*/e.createElement(Ye,r,l),/*#__PURE__*/e.createElement(et,null))};t&&(Xe.displayName="ArrayFieldRow");const Ye=t=>{let{children:l}=t,a=Z(t,Je);const{name:r}=$e();/*#__PURE__*/return e.createElement(Me,Y({flex:"1",mr:"2"},a),Ue(r,l))};t&&(Ye.displayName="ArrayFieldRowFields");const Ze=({children:t,index:l})=>{const a=He({index:l});/*#__PURE__*/return e.createElement(Pe,{value:a},/*#__PURE__*/e.createElement(_.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))};t&&(Ze.displayName="ArrayFieldRowContainer");const et=t=>/*#__PURE__*/e.createElement($,Y({icon:/*#__PURE__*/e.createElement(z,null),"aria-label":"Remove row"},Te(),t));t&&(et.displayName="ArrayFieldRemoveButton");const tt=t=>/*#__PURE__*/e.createElement($,Y({icon:/*#__PURE__*/e.createElement(P,null),"aria-label":"Add row",float:"right"},Ge(),t));t&&(tt.displayName="ArrayFieldAddButton");const lt=U((t,l)=>{const{children:a}=t,r=Z(t,Ke);/*#__PURE__*/return e.createElement(rt,Y({ref:l},r),/*#__PURE__*/e.createElement(at,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},l)=>/*#__PURE__*/e.createElement(Xe,{key:t,index:l},a)))),/*#__PURE__*/e.createElement(tt,null))});t&&(lt.displayName="ArrayField");const at=({children:e})=>{const{fields:t}=ze();return e(t)};t&&(at.displayName="ArrayFieldRows");const rt=e.forwardRef((t,l)=>{let{name:a,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=Z(t,Qe);const c=qe({name:a,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(l,()=>c,[l,c]),/*#__PURE__*/e.createElement(_e,{value:c},/*#__PURE__*/e.createElement(he,Y({name:a},m),o))});t&&(rt.displayName="ArrayFieldContainer");const nt=["name","label","hideLabel","children","columns","spacing"],st=t=>{const l=I("FormLegend");/*#__PURE__*/return e.createElement(f,Y({as:"legend",sx:l},t))},it=t=>{const{name:l,label:a,hideLabel:r,children:n,columns:s,spacing:i}=t,o=Z(t,nt);/*#__PURE__*/return e.createElement(p,Y({name:l,as:"fieldset"},o),/*#__PURE__*/e.createElement(st,{display:r?"none":"block"},a),/*#__PURE__*/e.createElement(Me,{columns:s,gridGap:i},Ue(l,n)))};t&&(it.displayName="ObjectField");const ot=["name","type"],mt=["schema","fieldResolver","focusFirstField"],ct=["name","type","defaultValue"],dt=(t,l)=>{var a;return null==(a=t.getNestedFields(l))?void 0:a.map((t,l)=>{let{name:a,type:r}=t,n=Z(t,ot);/*#__PURE__*/return e.createElement(be,Y({key:a||l,name:a,type:r},n))})},ut=t=>{let{schema:l,fieldResolver:a,focusFirstField:r}=t,n=Z(t,mt);const i=e.useMemo(()=>a||De.getFieldResolver(l),[l,a]),o=e.useMemo(()=>i.getFields(),[i]),m=s();return e.useEffect(()=>{var e;r&&null!=(e=o[0])&&e.name&&m.setFocus(o[0].name)},[l,a,r]),/*#__PURE__*/e.createElement(Me,n,o.map(t=>{let{name:l,type:a}=t,r=Z(t,ct);return"array"===a?/*#__PURE__*/e.createElement(lt,Y({key:l,name:l},r),dt(i,l)):"object"===a?/*#__PURE__*/e.createElement(it,Y({key:l,name:l},r),dt(i,l)):/*#__PURE__*/e.createElement(be,Y({key:l,name:l,type:a},r))}))};t&&(ut.displayName="Fields");const pt=["children","disableIfUntouched","disableIfInvalid","isDisabled","isLoading"],ft=e.forwardRef((t,l)=>{const{children:a,disableIfUntouched:r,disableIfInvalid:n,isDisabled:i,isLoading:o}=t,m=Z(t,pt),{formState:c}=s();/*#__PURE__*/return e.createElement(q,Y({},m,{ref:l,variant:"primary",type:"submit",isLoading:c.isSubmitting||o,isDisabled:r&&!c.isDirty||n&&!c.isValid||i}),a)});ft.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(ft.displayName="SubmitButton");const ht=["schema","submitLabel","fieldResolver","children"],bt=b((t,l)=>{const{schema:a,submitLabel:r="Submit",fieldResolver:n,children:s}=t,i=Z(t,ht);/*#__PURE__*/return e.createElement(De,Y({},i,{schema:a,ref:l}),/*#__PURE__*/e.createElement(Me,null,/*#__PURE__*/e.createElement(ut,{schema:a,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(ft,null,r),s))});t&&(bt.displayName="AutoForm");const yt=({children:e,name:t,defaultValue:l,isDisabled:a,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:l,disabled:a,exact:r}),s())?e:null;t&&(yt.displayName="DisplayIf");const Et=["onChange"],[vt,gt]=H({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function Ft(t){const l=Z(t,Et),a=T(l),{activeStep:r,isLastStep:n,nextStep:s}=a,[i,o]=e.useState({}),m=e.useCallback(async e=>{try{const l=i[r];if(n)return await(null==t.onSubmit?void 0:t.onSubmit(e)),d(Y({},l,{isCompleted:!0})),void s();await(null==l.onSubmit?void 0:l.onSubmit(e,a)),s()}catch(e){}},[i,r,n]),c=e.useCallback(()=>{const e=i[r];return{onSubmit:m,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[i,m,r]),d=e.useCallback(e=>{o(t=>Y({},t,{[e.name]:e}))},[i]);return Y({getFormProps:c,updateStep:d,steps:i},a)}function Nt(t){const{name:l,schema:a,resolver:r,onSubmit:n}=t,s=G({name:l}),{steps:i,updateStep:o}=gt();return e.useEffect(()=>{o({name:l,schema:a,resolver:r,onSubmit:n})},[l,a]),Y({},s,i[l]||{name:l,schema:a})}const Ct=["children"],xt=["getFormProps"],St=["children","orientation","variant","colorScheme","size"],kt=["name","schema","resolver","children","className","onSubmit"],Rt=["label","submitLabel"],Vt=e.forwardRef((t,l)=>{const{children:a}=t,r=Z(t,Ct),s=Ft(t),{getFormProps:i}=s,o=Z(s,xt),m=e.useMemo(()=>o,[o]);/*#__PURE__*/return e.createElement(W,{value:m},/*#__PURE__*/e.createElement(vt,{value:m},/*#__PURE__*/e.createElement(De,Y({ref:l},r,i()),n(a,s))))}),Lt=t=>{const{activeIndex:l,setIndex:a}=J(),{children:r,orientation:n,variant:s,colorScheme:i,size:o}=t,m=Z(t,St),c=e.Children.map(r,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===wt){const{isCompleted:l}=Nt(t.props);/*#__PURE__*/return e.createElement(K,Y({name:t.props.name,title:t.props.title,isCompleted:l},m),t.props.children)}return t}),d=e.useCallback(e=>{a(e)},[]);/*#__PURE__*/return e.createElement(Q,{orientation:n,step:l,variant:s,colorScheme:i,size:o,onChange:d},/*#__PURE__*/e.createElement(X,Y({mb:"4"},t),c))},wt=t=>{const{name:l,schema:a,resolver:n,children:s,className:i,onSubmit:o}=t,m=Z(t,kt),c=Nt({name:l,schema:a,resolver:n,onSubmit:o}),{isActive:d}=c;return d?/*#__PURE__*/e.createElement(_.div,Y({},m,{className:r("saas-form__step",i)}),s):null};t&&(wt.displayName="FormStep");const At=t=>{const{isFirstStep:a,isCompleted:n,prevStep:s}=J();/*#__PURE__*/return e.createElement(q,Y({isDisabled:a||n,label:"Back"},t,{className:r("saas-form__prev-button",t.className),onClick:l(t.onClick,s)}))};t&&(At.displayName="PrevButton");const It=t=>{const{label:l="Next",submitLabel:a="Complete"}=t,n=Z(t,Rt),{isLastStep:s,isCompleted:i}=J();/*#__PURE__*/return e.createElement(ft,Y({},n,{isDisabled:i,className:r("saas-form__next-button",t.className)}),s||i?a:l)};t&&(It.displayName="NextButton");const Bt=e=>{const{name:t,defaultValue:l,isDisabled:a,isExact:r}=e,n=s(),i=u({name:t,defaultValue:l,disabled:a,exact:r});return e.children(i,n)||null};export{lt as ArrayField,tt as ArrayFieldAddButton,rt as ArrayFieldContainer,_e as ArrayFieldProvider,et as ArrayFieldRemoveButton,Xe as ArrayFieldRow,Ze as ArrayFieldRowContainer,Ye as ArrayFieldRowFields,Pe as ArrayFieldRowProvider,at as ArrayFieldRows,bt as AutoForm,he as BaseField,ke as CheckboxField,te as DisplayField,yt as DisplayIf,be as Field,ut as Fields,De as Form,Me as FormLayout,st as FormLegend,wt as FormStep,Lt as FormStepper,le as FormValue,ge as InputField,Ve as NativeSelectField,It as NextButton,Fe as NumberInputField,it as ObjectField,Ne as PasswordInputField,Le as PinField,At as PrevButton,Re as RadioField,Se as SelectField,Vt as StepForm,vt as StepFormProvider,ft as SubmitButton,xe as SwitchField,Ce as TextareaField,Bt as WatchField,Ie as objectFieldResolver,ve as registerFieldType,qe as useArrayField,Ge as useArrayFieldAddButton,ze as useArrayFieldContext,Te as useArrayFieldRemoveButton,He as useArrayFieldRow,$e as useArrayFieldRowContext,Nt as useFormStep,Ft as useStepForm,gt as useStepFormContext,ye as withControlledInput,Ee as withUncontrolledInput};
|
2
|
+
//# sourceMappingURL=index.modern.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.modern.mjs","sources":["../src/display-field.tsx","../src/field.tsx","../src/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../src/use-step-form.tsx","../src/step-form.tsx","../src/watch-field.tsx"],"sourcesContent":["import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">\n <FormValue name={name} />\n </Text>\n </FormControl>\n )\n}\n\nif (__DEV__) {\n DisplayField.displayName = 'DisplayField'\n}\n\nexport const FormValue: React.FC<{ name: string }> = ({ name }) => {\n const { getValues } = useFormContext()\n return getValues(name) || null\n}\n\nif (__DEV__) {\n FormValue.displayName = 'FormValue'\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n InputGroup,\n InputProps,\n TextareaProps,\n SwitchProps,\n CheckboxProps,\n PinInputField,\n HStack,\n PinInput,\n UsePinInputProps,\n SystemProps,\n} from '@chakra-ui/react'\nimport { __DEV__, FocusableElement, callAllHandlers } from '@chakra-ui/utils'\n\nimport { NumberInput, NumberInputProps } from '@saas-ui/number-input'\nimport { PasswordInput, PasswordInputProps } from '@saas-ui/password-input'\nimport { RadioInput, RadioInputProps } from '@saas-ui/radio'\n\nimport {\n Select,\n SelectProps,\n NativeSelect,\n NativeSelectProps,\n} from '@saas-ui/select'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n */\n type?: string\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<string, React.FC<any>> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, hideLabel, children, ...controlProps } = props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? <FormLabel>{label}</FormLabel> : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\n\nif (__DEV__) {\n BaseField.displayName = 'BaseField'\n}\n\nexport type As<Props = any> = React.ElementType<Props>\n\nexport type PropsOf<T extends As> = React.ComponentPropsWithoutRef<T> & {\n type?: FieldTypes\n}\n\n/**\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n */\nexport const Field = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> | FieldTypeProps,\n ref: React.ForwardedRef<FocusableElement>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as (<TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> &\n FieldTypeProps & {\n ref?: React.ForwardedRef<FocusableElement>\n }\n) => React.ReactElement) & {\n displayName?: string\n}\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef((props, ref) => {\n const {\n id,\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n id={id}\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n >\n <InputComponent\n ref={ref}\n id={id}\n name={name}\n label={hideLabel ? label : undefined} // Only pass down the label when it should be inline.\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: React.FC<any>) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n onChange={callAllHandlers(inputProps.onChange, field.onChange)}\n onBlur={callAllHandlers(inputProps.onBlur, field.onBlur)}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: React.FC<any>) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n onChange={callAllHandlers(inputProps.onChange, field.onChange)}\n onBlur={callAllHandlers(inputProps.onBlur, field.onBlur)}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for the checkbox field.\n */\nexport const registerFieldType = <T extends object>(\n type: string,\n component: React.FC<T>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n }) as React.FC<T & FieldProps>\n\n inputTypes[type] = Field\n\n return Field\n}\n\nexport interface InputFieldProps extends InputProps {\n type?: string\n leftAddon?: React.ReactNode\n rightAddon?: React.ReactNode\n}\n\nexport const InputField = registerFieldType<InputFieldProps>(\n 'text',\n forwardRef(({ type = 'text', leftAddon, rightAddon, size, ...rest }, ref) => {\n const input = <Input type={type} size={size} {...rest} ref={ref} />\n if (leftAddon || rightAddon) {\n return (\n <InputGroup size={size}>\n {leftAddon}\n {input}\n {rightAddon}\n </InputGroup>\n )\n }\n return input\n })\n)\n\nexport interface NumberInputFieldProps extends NumberInputProps {\n type: 'number'\n}\n\nexport const NumberInputField = registerFieldType<NumberInputFieldProps>(\n 'number',\n NumberInput,\n {\n isControlled: true,\n }\n)\n\nexport const PasswordInputField = registerFieldType<PasswordInputProps>(\n 'password',\n forwardRef((props, ref) => <PasswordInput ref={ref} {...props} />)\n)\n\nexport const TextareaField = registerFieldType<TextareaProps>(\n 'textarea',\n Textarea\n)\n\nexport const SwitchField = registerFieldType<SwitchProps>(\n 'switch',\n forwardRef(({ type, value, ...rest }, ref) => {\n return <Switch isChecked={!!value} {...rest} ref={ref} />\n }),\n {\n isControlled: true,\n }\n)\n\nexport const SelectField = registerFieldType<SelectProps>('select', Select, {\n isControlled: true,\n})\n\nexport const CheckboxField = registerFieldType<CheckboxProps>(\n 'checkbox',\n forwardRef(({ label, type, ...props }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\n\nexport const RadioField = registerFieldType<RadioInputProps>(\n 'radio',\n RadioInput,\n {\n isControlled: true,\n }\n)\n\nexport const NativeSelectField = registerFieldType<NativeSelectProps>(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n\nexport interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {\n pinLength?: number\n pinType?: 'alphanumeric' | 'number'\n spacing?: SystemProps['margin']\n}\n\nexport const PinField = registerFieldType<PinFieldProps>(\n 'pin',\n forwardRef((props, ref) => {\n const { pinLength = 4, pinType, spacing, ...inputProps } = props\n\n const inputs: React.ReactNode[] = []\n for (let i = 0; i < pinLength; i++) {\n inputs.push(<PinInputField key={i} ref={ref} />)\n }\n\n return (\n <HStack spacing={spacing}>\n <PinInput {...inputProps} type={pinType}>\n {inputs}\n </PinInput>\n </HStack>\n )\n }),\n {\n isControlled: true,\n }\n)\n\nconst fieldTypes = {\n text: InputField,\n email: InputField,\n url: InputField,\n phone: InputField,\n number: NumberInputField,\n password: PasswordInputField,\n textarea: TextareaField,\n switch: SwitchField,\n checkbox: CheckboxField,\n radio: RadioField,\n pin: PinField,\n select: SelectField,\n 'native-select': NativeSelectField,\n}\n\ntype FieldTypes = typeof fieldTypes\n\ntype FieldType<Props = any> = React.ElementType<Props>\n\ntype TypeProps<P extends FieldType, T> = React.ComponentPropsWithoutRef<P> & {\n type: T\n}\n\ntype FieldTypeProps =\n | {\n [Property in keyof FieldTypes]: TypeProps<FieldTypes[Property], Property>\n }[keyof FieldTypes]\n | { type?: string }\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema): FieldProps[] =>\n schema &&\n Object.entries(schema).map(([name, { items, label, title, ...field }]) => {\n return {\n ...field,\n name,\n label: label || title, // json schema compatibility\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\nimport { cx, MaybeFunction, runIfFn, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n ResolverOptions,\n ResolverResult,\n ChangeHandler,\n WatchObserver,\n UnpackNestedValue,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\nimport { MaybeRenderProp } from '@chakra-ui/react-utils'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<\n TFieldValues extends FieldValues = FieldValues,\n TContext extends object = object\n> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * Triggers when any of the field change.\n */\n onChange?: WatchObserver<TFieldValues>\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.RefObject<HTMLFormElement>\n /**\n * The form children, can be a render prop or a ReactNode.\n */\n children?: MaybeRenderProp<UseFormReturn<TFieldValues, TContext>>\n}\n\n// @todo Figure out how to pass down FieldValues to all Field components, if at all possible.\n\nexport interface FormProps<\n TFieldValues extends FieldValues = FieldValues,\n TContext extends object = object\n> extends UseFormProps<TFieldValues, TContext>,\n Omit<\n HTMLChakraProps<'form'>,\n 'children' | 'onChange' | 'onSubmit' | 'onError'\n >,\n FormOptions<TFieldValues, TContext> {}\n\nexport const Form = forwardRef(\n <\n TFieldValues extends FieldValues = FieldValues,\n TContext extends object = object\n >(\n props: FormProps<TFieldValues, TContext>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues, TContext>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onChange,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.<TFieldValues, TContext>(schema)\n }\n\n const methods = useForm<TFieldValues, TContext>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n React.useEffect(() => {\n let subscription: any\n if (onChange) {\n subscription = methods.watch(onChange)\n }\n return () => subscription?.unsubscribe()\n }, [methods, onChange])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n className={cx('saas-form', props.className)}\n >\n {runIfFn(children, methods)}\n </chakra.form>\n </FormProvider>\n )\n }\n) as (<TFieldValues extends FieldValues, TContext extends object = object>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n displayName?: string\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nif (__DEV__) {\n Form.displayName = 'Form'\n}\n\nexport type GetResolver = <\n TFieldValues extends FieldValues,\n TContext extends object\n>(\n schema: any\n) => (\n values: UnpackNestedValue<TFieldValues>,\n context: TContext | undefined,\n options: ResolverOptions<TFieldValues>\n) => Promise<ResolverResult<TFieldValues>>\n\nexport type GetFieldResolver = (schema: any) => FieldResolver\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\nif (__DEV__) {\n FormLayoutItem.displayName = 'FormLayoutItem'\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid\n {...gridProps}\n className={cx('saas-form__layout', props.className)}\n >\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n\nif (__DEV__) {\n FormLayout.displayName = 'FormLayout'\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses a different 'id' field\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue, forwardRef } from '@chakra-ui/system'\nimport { __DEV__ } from '@chakra-ui/utils'\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout, FormLayoutProps } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n UseArrayFieldReturn,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps extends FormLayoutProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n /**\n * The fields\n */\n children: React.ReactNode\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n ...rowFieldsProps\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields {...rowFieldsProps}>{children}</ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRow.displayName = 'ArrayFieldRow'\n}\n\nexport interface ArrayFieldRowFieldsProps extends FormLayoutProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The fields\n */\n children: React.ReactNode\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout flex=\"1\" mr=\"2\" {...layoutProps}>\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRowFields.displayName = 'ArrayFieldRowFields'\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nif (__DEV__) {\n ArrayFieldRowContainer.displayName = 'ArrayFieldRowContainer'\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nif (__DEV__) {\n ArrayFieldRemoveButton.displayName = 'ArrayFieldRemoveButton'\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nif (__DEV__) {\n ArrayFieldAddButton.displayName = 'ArrayFieldAddButton'\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField = forwardRef(\n (props: ArrayFieldProps, ref: React.ForwardedRef<UseArrayFieldReturn>) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer ref={ref} {...containerProps}>\n <ArrayFieldRows>\n {(fields: ArrayField[]) => (\n <>\n {fields.map(({ id }, index: number) => (\n <ArrayFieldRow key={id} index={index}>\n {children}\n </ArrayFieldRow>\n ))}\n </>\n )}\n </ArrayFieldRows>\n <ArrayFieldAddButton />\n </ArrayFieldContainer>\n )\n }\n) as ((\n props: ArrayFieldProps & {\n ref?: React.ForwardedRef<UseArrayFieldReturn>\n }\n) => React.ReactElement) & {\n displayName: string\n}\n\nif (__DEV__) {\n ArrayField.displayName = 'ArrayField'\n}\n\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nif (__DEV__) {\n ArrayFieldRows.displayName = 'ArrayFieldRows'\n}\n\nexport const ArrayFieldContainer = React.forwardRef(\n (\n {\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n }: ArrayFieldProps,\n ref: React.ForwardedRef<UseArrayFieldReturn>\n ) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n // This exposes the useArrayField api through the forwarded ref\n React.useImperativeHandle(ref, () => context, [ref, context])\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n }\n)\n\nif (__DEV__) {\n ArrayFieldContainer.displayName = 'ArrayFieldContainer'\n}\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyleConfig,\n} from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyleConfig('FormLegend')\n return <FormLabel as=\"legend\" sx={styles} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n\nif (__DEV__) {\n ObjectField.displayName = 'ObjectField'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form } from './form'\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\nimport { FieldResolver } from './field-resolver'\nimport { useFormContext } from 'react-hook-form'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n focusFirstField?: boolean\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n focusFirstField,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n const fields = React.useMemo(() => resolver.getFields(), [resolver])\n\n const form = useFormContext()\n\n React.useEffect(() => {\n if (focusFirstField && fields[0]?.name) {\n form.setFocus(fields[0].name)\n }\n }, [schema, fieldResolver, focusFirstField])\n\n return (\n <FormLayout {...props}>\n {fields.map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n\nif (__DEV__) {\n Fields.displayName = 'Fields'\n}\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { __DEV__ } from '@chakra-ui/utils'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = React.forwardRef<\n HTMLButtonElement,\n SubmitButtonProps\n>((props, ref) => {\n const {\n children,\n disableIfUntouched,\n disableIfInvalid,\n isDisabled: isDisabledProp,\n isLoading,\n ...rest\n } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid) ||\n isDisabledProp\n\n return (\n <Button\n {...rest}\n ref={ref}\n variant=\"primary\"\n type=\"submit\"\n isLoading={formState.isSubmitting || isLoading}\n isDisabled={isDisabled}\n >\n {children}\n </Button>\n )\n})\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n\nif (__DEV__) {\n SubmitButton.displayName = 'SubmitButton'\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\nimport { __DEV__ } from '@chakra-ui/utils'\n\nimport { Form, FormProps } from './form'\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\nimport { FieldResolver } from '.'\n\ninterface AutoFormOptions {\n /**\n * The submit button label.\n * Pass `null` to render no submit button.\n */\n submitLabel?: React.ReactNode\n /**\n * The schema.\n * Supports object schema, Zod, Yup or Ajv (JSON Schema).\n * @see https://www.saas-ui.dev/docs/forms/auto-form\n */\n schema: any\n /**\n * The field resolver.\n */\n fieldResolver?: any\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema' | 'children'>,\n AutoFormOptions {\n children?: React.ReactNode\n}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n schema,\n submitLabel = 'Submit',\n fieldResolver,\n children,\n ...rest\n } = props\n\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} fieldResolver={fieldResolver} />}\n {submitLabel && <SubmitButton>{submitLabel}</SubmitButton>}\n {children}\n </FormLayout>\n </Form>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n displayName?: string\n getFieldResolver?: (schema: any) => FieldResolver\n}\n\nif (__DEV__) {\n AutoForm.displayName = 'AutoForm'\n}\n","import * as React from 'react'\nimport { __DEV__ } from '@chakra-ui/utils'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<\n TFieldValues extends FieldValues = FieldValues\n> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n\nif (__DEV__) {\n DisplayIf.displayName = 'DisplayIf'\n}\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler } from 'react-hook-form'\nimport { createContext, MaybeRenderProp } from '@chakra-ui/react-utils'\nimport {\n useStepper,\n useStep,\n UseStepperProps,\n UseStepperReturn,\n} from '@saas-ui/stepper'\n\nexport interface StepState {\n name: string\n schema?: any\n resolver?: any\n isActive?: boolean\n isCompleted?: boolean\n onSubmit?: FormStepSubmitHandler\n}\n\nexport type FormStepSubmitHandler<\n TFieldValues extends FieldValues = FieldValues\n> = (data: TFieldValues, stepper: UseStepperReturn) => Promise<void>\n\nexport interface StepFormContext extends UseStepperReturn {\n updateStep(state: StepState): void\n steps: Record<string, StepState>\n}\n\nexport const [StepFormProvider, useStepFormContext] =\n createContext<StepFormContext>({\n name: 'StepFormContext',\n errorMessage:\n 'useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`',\n })\n\nimport { FormProps } from './form'\n\nexport interface UseStepFormProps<\n TFieldValues extends FieldValues = FieldValues\n> extends Omit<UseStepperProps, 'onChange'>,\n Omit<FormProps<TFieldValues>, 'children'> {\n children: MaybeRenderProp<UseStepFormReturn<TFieldValues>>\n}\n\nexport interface UseStepFormReturn<\n TFieldValues extends FieldValues = FieldValues\n> extends UseStepperReturn {\n getFormProps(): {\n onSubmit: SubmitHandler<TFieldValues>\n schema?: any\n resolver?: any\n }\n updateStep(step: any): void\n steps: Record<string, any>\n}\n\nexport function useStepForm<TFieldValues extends FieldValues = FieldValues>(\n props: UseStepFormProps<TFieldValues>\n): UseStepFormReturn<TFieldValues> {\n const { onChange, ...rest } = props\n const stepper = useStepper(rest)\n\n const { activeStep, isLastStep, nextStep } = stepper\n\n const [steps, updateSteps] = React.useState<Record<string, StepState>>({})\n\n const onSubmitStep: SubmitHandler<TFieldValues> = React.useCallback(\n async (data) => {\n try {\n const step = steps[activeStep]\n\n if (isLastStep) {\n await props.onSubmit?.(data)\n\n updateStep({\n ...step,\n isCompleted: true,\n })\n\n nextStep() // show completed step\n return\n }\n\n await step.onSubmit?.(data, stepper)\n\n nextStep()\n } catch (e) {\n // Step submission failed.\n }\n },\n [steps, activeStep, isLastStep]\n )\n\n const getFormProps = React.useCallback(() => {\n const step = steps[activeStep]\n return {\n onSubmit: onSubmitStep,\n schema: step?.schema,\n resolver: step?.resolver,\n }\n }, [steps, onSubmitStep, activeStep])\n\n const updateStep = React.useCallback(\n (step: StepState) => {\n updateSteps((steps) => {\n return {\n ...steps,\n [step.name]: step,\n }\n })\n },\n [steps]\n )\n\n return {\n getFormProps,\n updateStep,\n steps,\n ...stepper,\n }\n}\n\nexport interface UseFormStepProps {\n name: string\n schema?: any\n resolver?: any\n onSubmit?: FormStepSubmitHandler\n}\n\nexport function useFormStep(props: UseFormStepProps): StepState {\n const { name, schema, resolver, onSubmit } = props\n const step = useStep({ name })\n\n const { steps, updateStep } = useStepFormContext()\n\n React.useEffect(() => {\n updateStep({ name, schema, resolver, onSubmit })\n }, [name, schema])\n\n return {\n ...step,\n ...(steps[name] || { name, schema }),\n }\n}\n","import * as React from 'react'\n\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\n\nimport { chakra, HTMLChakraProps, ThemingProps } from '@chakra-ui/system'\n\nimport { callAllHandlers, runIfFn, cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n StepperProvider,\n StepperSteps,\n StepperStepsProps,\n StepperStep,\n useStepperContext,\n StepperContainer,\n StepperProps,\n} from '@saas-ui/stepper'\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { Form } from './form'\nimport { SubmitButton } from './submit-button'\n\nimport {\n useStepForm,\n useFormStep,\n StepFormProvider,\n UseStepFormProps,\n FormStepSubmitHandler,\n} from './use-step-form'\n\nexport interface StepFormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseStepFormProps<TFieldValues> {}\n\nexport const StepForm = React.forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: StepFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { children, ...rest } = props\n\n const stepper = useStepForm<TFieldValues>(props)\n\n const { getFormProps, ...ctx } = stepper\n\n const context = React.useMemo(() => ctx, [ctx])\n\n return (\n <StepperProvider value={context}>\n <StepFormProvider value={context}>\n <Form ref={ref} {...rest} {...getFormProps()}>\n {runIfFn(children, stepper)}\n </Form>\n </StepFormProvider>\n </StepperProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: StepFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n\nexport interface FormStepOptions {\n /**\n * The step name\n */\n name: string\n /**\n * Schema\n */\n schema?: any\n /**\n * Hook Form Resolver\n */\n resolver?: any\n}\n\nexport interface FormStepperProps\n extends StepperStepsProps,\n ThemingProps<'Stepper'> {}\n\nexport const FormStepper: React.FC<FormStepperProps> = (props) => {\n const { activeIndex, setIndex } = useStepperContext()\n\n const { children, orientation, variant, colorScheme, size, ...rest } = props\n\n const elements = React.Children.map(children, (child) => {\n if (\n React.isValidElement<FormStepProps>(child) &&\n child?.type === FormStep\n ) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n {...rest}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n const onChange = React.useCallback((i: number) => {\n setIndex(i)\n }, [])\n\n return (\n <StepperContainer\n orientation={orientation}\n step={activeIndex}\n variant={variant}\n colorScheme={colorScheme}\n size={size}\n onChange={onChange}\n >\n <StepperSteps mb=\"4\" {...props}>\n {elements}\n </StepperSteps>\n </StepperContainer>\n )\n}\n\nexport interface FormStepProps\n extends FormStepOptions,\n Omit<HTMLChakraProps<'div'>, 'onSubmit'> {\n onSubmit?: FormStepSubmitHandler\n}\n\nexport const FormStep: React.FC<FormStepProps> = (props) => {\n const { name, schema, resolver, children, className, onSubmit, ...rest } =\n props\n const step = useFormStep({ name, schema, resolver, onSubmit })\n\n const { isActive } = step\n\n return isActive ? (\n <chakra.div {...rest} className={cx('saas-form__step', className)}>\n {children}\n </chakra.div>\n ) : null\n}\n\nif (__DEV__) {\n FormStep.displayName = 'FormStep'\n}\n\nexport const PrevButton: React.FC<ButtonProps> = (props) => {\n const { isFirstStep, isCompleted, prevStep } = useStepperContext()\n\n return (\n <Button\n isDisabled={isFirstStep || isCompleted}\n label=\"Back\"\n {...props}\n className={cx('saas-form__prev-button', props.className)}\n onClick={callAllHandlers(props.onClick, prevStep)}\n />\n )\n}\n\nif (__DEV__) {\n PrevButton.displayName = 'PrevButton'\n}\n\nexport interface NextButtonProps extends ButtonProps {\n submitLabel?: string\n}\n\nexport const NextButton: React.FC<NextButtonProps> = (props) => {\n const { label = 'Next', submitLabel = 'Complete', ...rest } = props\n const { isLastStep, isCompleted } = useStepperContext()\n\n return (\n <SubmitButton\n {...rest}\n isDisabled={isCompleted}\n className={cx('saas-form__next-button', props.className)}\n >\n {isLastStep || isCompleted ? submitLabel : label}\n </SubmitButton>\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n","import {\n FieldValues,\n useFormContext,\n UseFormReturn,\n useWatch,\n} from 'react-hook-form'\n\nexport interface WatchFieldProps<\n Value = unknown,\n TFieldValues extends FieldValues = FieldValues\n> {\n name: string\n defaultValue?: Value\n isDisabled?: boolean\n isExact?: boolean\n children: (\n value: Value,\n form: UseFormReturn<TFieldValues>\n ) => React.ReactElement | void\n}\n\nexport const WatchField = <\n Value = unknown,\n TFieldValues extends FieldValues = FieldValues\n>(\n props: WatchFieldProps<Value, TFieldValues>\n) => {\n const { name, defaultValue, isDisabled, isExact } = props\n const form = useFormContext<TFieldValues>()\n\n const field = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n\n return props.children(field, form) || null\n}\n"],"names":["DisplayField","_ref","name","label","props","_objectWithoutPropertiesLoose","_excluded","React","createElement","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","getValues","useFormContext","_excluded2","_excluded3","_excluded4","_excluded5","_excluded6","_excluded7","_excluded8","_excluded9","_excluded10","inputTypes","defaultInputType","BaseField","help","hideLabel","children","controlProps","formState","error","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","InputComponent","getInput","_extends","withControlledInput","_ref2","rules","inputProps","control","Controller","render","_ref3","field","onChange","callAllHandlers","onBlur","useMergeRefs","withUncontrolledInput","_ref4","register","_register","component","options","isControlled","id","isDisabled","isReadOnly","isRequired","inputRules","required","undefined","createField","split","map","part","charAt","toUpperCase","slice","join","registerFieldType","leftAddon","rightAddon","size","_ref5","rest","input","Input","InputGroup","NumberInput","PasswordInputField","PasswordInput","TextareaField","Textarea","SwitchField","_ref6","value","Switch","isChecked","SelectField","Select","_ref7","Checkbox","RadioField","RadioInput","NativeSelectField","NativeSelect","pinLength","pinType","spacing","i","inputs","push","PinInputField","key","HStack","PinInput","mapFields","schema","Object","entries","title","objectFieldResolver","getFields","getNestedFields","_field$items","items","properties","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","useEffect","subscription","watch","_subscription","unsubscribe","FormProvider","chakra","className","cx","runIfFn","getFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","defaultProps","theme","useTheme","components","SimpleGrid","gridProps","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","min","max","context","useFieldArray","useArrayFieldRow","index","clearErrors","remove","fields","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","rowFieldsProps","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","mr","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","Fragment","fieldProps","FormLegend","styles","useStyleConfig","as","sx","ObjectField","columns","gridGap","_resolver$getNestedFi","nestedFieldProps","fieldResolver","focusFirstField","useMemo","_fields$","setFocus","Fields","disableIfUntouched","disableIfInvalid","isDisabledProp","isLoading","Button","variant","isSubmitting","isDirty","isValid","SubmitButton","AutoForm","submitLabel","DisplayIf","isExact","condition","useWatch","disabled","exact","StepFormProvider","useStepFormContext","errorMessage","useStepForm","stepper","useStepper","activeStep","isLastStep","nextStep","steps","updateSteps","useState","onSubmitStep","async","step","data","updateStep","isCompleted","e","getFormProps","useStep","StepForm","ctx","StepperProvider","FormStepper","activeIndex","setIndex","useStepperContext","orientation","colorScheme","elements","FormStep","useFormStep","StepperStep","StepperContainer","StepperSteps","isActive","PrevButton","isFirstStep","prevStep","NextButton","WatchField"],"mappings":"uuDAiBaA,GAA4CC,QAACC,KACxDA,EAAIC,MACJA,GAGDF,EADIG,EAAKC,EAAAJ,EAAAK,iBAER,OACEC,EAAAC,cAACC,EAAgBL,EACdD,eAAQI,EAACC,cAAAE,EAAU,CAAAC,QAAST,GAAOC,GAAqB,kBACzDI,EAACC,cAAAI,GAAKC,SAAS,mBACbN,EAACC,cAAAM,GAAU,CAAAZ,KAAMA,KAErB,EAIAa,IACFf,GAAagB,YAAc,gBAGhBF,MAAAA,GAAw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EACJ,CAAAnB,WAAYoN,EACZ5H,UAAWC,EAAG,yBAA0B9J,EAAM6J,aAE7CkH,GAAcU,EAAcxB,EAAclQ,EAAK,EAKlDY,IACFqS,GAAWpS,YAAc,cCvKdqS,MAAUA,GAIrBjT,IAEA,MAAMF,KAAEA,EAAI0L,aAAEA,EAAYnH,WAAEA,EAAU8L,QAAEA,GAAYnQ,EAC9CgJ,EAAOlI,IAEF0C,EAAG6M,EAAS,CACrBvQ,OACA0L,eACA8E,SAAUjM,EACVkM,MAAOJ,IAGT,OAAOnQ,EAAM6B,SAAS2B,EAAOwF,IAAS"}
|
package/dist/layout.d.ts
CHANGED
package/dist/layout.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.tsx"],"names":[],"mappings":"AAEA,OAAO,EAAsB,eAAe,EAAY,MAAM,kBAAkB,CAAA;AAGhF,MAAM,MAAM,eAAe,GAAG,eAAe,CAAA;AAc7C;;;;;GAKG;AACH,eAAO,MAAM,UAAU;6BAA4B,eAAe;;CAyBjE,CAAA"}
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.tsx"],"names":[],"mappings":";AAEA,OAAO,EAAsB,eAAe,EAAY,MAAM,kBAAkB,CAAA;AAGhF,MAAM,MAAM,eAAe,GAAG,eAAe,CAAA;AAc7C;;;;;GAKG;AACH,eAAO,MAAM,UAAU;6BAA4B,eAAe;;CAyBjE,CAAA"}
|
package/dist/step-form.d.ts
CHANGED
@@ -7,7 +7,7 @@ import { UseStepFormProps, FormStepSubmitHandler } from './use-step-form';
|
|
7
7
|
export interface StepFormProps<TFieldValues extends FieldValues = FieldValues> extends UseStepFormProps<TFieldValues> {
|
8
8
|
}
|
9
9
|
export declare const StepForm: <TFieldValues extends FieldValues>(props: StepFormProps<TFieldValues> & {
|
10
|
-
ref?: React.ForwardedRef<UseFormReturn<TFieldValues,
|
10
|
+
ref?: React.ForwardedRef<UseFormReturn<TFieldValues, object>> | undefined;
|
11
11
|
}) => React.ReactElement;
|
12
12
|
export interface FormStepOptions {
|
13
13
|
/**
|
@@ -64,14 +64,14 @@ export declare const useArrayField: ({ name, defaultValue, keyName, min, max, }:
|
|
64
64
|
defaultValue: Record<string, any>;
|
65
65
|
min: number | undefined;
|
66
66
|
max: number | undefined;
|
67
|
-
swap:
|
68
|
-
move:
|
69
|
-
prepend:
|
70
|
-
append:
|
71
|
-
remove:
|
72
|
-
insert:
|
73
|
-
update:
|
74
|
-
replace:
|
67
|
+
swap: (indexA: number, indexB: number) => void;
|
68
|
+
move: (indexA: number, indexB: number) => void;
|
69
|
+
prepend: (value: Partial<unknown> | Partial<unknown>[], options?: import("react-hook-form").FieldArrayMethodProps | undefined) => void;
|
70
|
+
append: (value: Partial<unknown> | Partial<unknown>[], options?: import("react-hook-form").FieldArrayMethodProps | undefined) => void;
|
71
|
+
remove: (index?: number | number[] | undefined) => void;
|
72
|
+
insert: (index: number, value: Partial<unknown> | Partial<unknown>[], options?: import("react-hook-form").FieldArrayMethodProps | undefined) => void;
|
73
|
+
update: (index: number, value: Partial<unknown>) => void;
|
74
|
+
replace: (value: Partial<unknown> | Partial<unknown>[]) => void;
|
75
75
|
fields: Record<string, string>[];
|
76
76
|
};
|
77
77
|
export interface UseArrayFieldRowProps {
|
package/dist/yup/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../yup/src/yup-resolver.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { yupResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["getType","field","_field$spec$meta","spec","meta","type","
|
1
|
+
{"version":3,"file":"index.js","sources":["../../yup/src/yup-resolver.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { yupResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["getType","field","_field$spec$meta","spec","meta","type","name","_iterator","_createForOfIteratorHelperLoose","tests","test","OPTIONS","_test$OPTIONS","params","schema","schemaFields","innerType","fields","options","min","getArrayOption","max","push","_extends","label","getNestedSchema","path","reach","yupFieldResolver","getFields","getFieldsFromSchema","getNestedFields","schemaOptions","resolverOptions","resolver","yupResolver","fieldResolver"],"mappings":"wYAaA,IAAaA,EAAG,SAACC,GAAc,IAAAC,EAC7B,GAAI,OAAAD,EAAAA,EAAME,KAAKC,OA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"@hookform/resolvers/yup";export{yupResolver}from"@hookform/resolvers/yup";function t(){return t=Object.assign?Object.assign.bind():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"}},s=(e,r)=>{for(const a of e.tests){var t;if(null!=(t=a.OPTIONS)&&t.params[r])return a.OPTIONS.params[r]}},n=e=>{const r=[];let n={};n="array"===e.type?e.innerType.fields:e.fields;for(const e in n){const o=n[e],p={};"array"===o.type&&(p.min=s(o,"min"),p.max=s(o,"max")),r.push(t({name:e,label:o.spec.label||e,type:a(o)},p))}return r},o=(r,t)=>e(r,t),p=e=>({getFields:()=>n(e),getNestedFields:r=>n(o(e,r))}),l=(e,t={},a={})=>({schema:e,resolver:r(e,t,a),fieldResolver:p(e)});export{n as getFieldsFromSchema,o as getNestedSchema,p as yupFieldResolver,l as yupForm};
|
2
|
-
//# sourceMappingURL=index.modern.
|
2
|
+
//# sourceMappingURL=index.modern.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.modern.mjs","sources":["../../yup/src/yup-resolver.ts"],"sourcesContent":["import { reach, AnyObjectSchema } from 'yup'\nimport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { yupResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\n// @TODO get proper typings for the schema fields\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: AnyObjectSchema): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: AnyObjectSchema, path: string) => {\n return reach(schema, path)\n}\n\nexport const yupFieldResolver = (schema: AnyObjectSchema) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const yupForm = (\n schema: AnyObjectSchema,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: yupResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: yupFieldResolver(schema),\n }\n}\n"],"names":["field","_field$spec$meta","spec","meta","type","getArrayOption","name","test","tests","_test$OPTIONS","OPTIONS","params","schema","fields","schemaFields","innerType","options","min","max","push","label","getType","getNestedSchema","path","reach","yupFieldResolver","getFields","getFieldsFromSchema","getNestedFields","yupForm","schemaOptions","resolverOptions","resolver","yupResolver","fieldResolver"],"mappings":"uWAaA,QAAiBA,IACf,IAAAC,EAAA,GAAI,OAAJA,EAAID,EAAME,KAAKC,OAAXF,EAAiBG,KACnB,OAAOJ,EAAME,KAAKC,KAAKC,KAGzB,OAAQJ,EAAMI,MACZ,IAAK,QACH,MAAO,QACT,IAAK,SACH,MAAO,SACT,IAAK,SACH,MAAO,SACT,IAAK,OACH,MAAO,OAET,QACE,MAAO,OAAM,EAICC,EAAG,CAACL,EAAYM,KAClC,IAAK,MAAUC,OAAUC,MAAO,CAAA,IAAAC,EAC9B,GAAI,SAAAF,EAAKG,UAALD,EAAcE,OAAOL,GAAO,OAAWC,EAACG,QAAQC,OAAOL,EAC5D,KASiCM,IAClC,MAAYC,EAAG,GAEf,IAAgBC,EAAwB,GAGtCA,EAFkB,UAAhBF,EAAOR,KAEMQ,EAAOG,UAAUF,OAEjBD,EAAOC,OAGxB,IAAK,MAAMP,KAAoBQ,EAAE,CAC/B,MAAMd,EAAQc,EAAaR,KAEF,CAAE,EACR,UAAfN,EAAMI,OACRY,EAAQC,IAAMZ,EAAeL,EAAO,OACpCgB,EAAQE,IAAMb,EAAeL,EAAO,QAGtCa,EAAOM,KACLb,EAAAA,CAAAA,OACAc,MAAOpB,EAAME,KAAKkB,OAASd,EAC3BF,KAAMiB,EAAQrB,IACXgB,GAEN,CACD,OACFH,GAE4BS,EAAG,CAACV,EAAyBW,IAC3CC,EAACZ,EAAQW,GAGME,EAAIb,IACxB,CACLc,UAAS,IACmBC,EAACf,GAE7BgB,gBAAgBtB,GACPqB,EAAoBL,EAAgBV,EAAQN,MAKrCuB,EAAG,CACrBjB,EACAkB,EAAgB,CAAE,EAClBC,EAAkB,CAAA,KAEX,CACLnB,SACAoB,SAAUC,EAAYrB,EAAQkB,EAAeC,GAC7CG,cAAeT,EAAiBb"}
|
@@ -20,7 +20,7 @@ export declare const yupFieldResolver: (schema: AnyObjectSchema) => {
|
|
20
20
|
};
|
21
21
|
export declare const yupForm: (schema: AnyObjectSchema, schemaOptions?: {}, resolverOptions?: {}) => {
|
22
22
|
schema: AnyObjectSchema;
|
23
|
-
resolver: <TFieldValues extends import("@saas-ui/forms").FieldValues, TContext>(values: TFieldValues
|
23
|
+
resolver: <TFieldValues extends import("@saas-ui/forms").FieldValues, TContext>(values: import("@saas-ui/forms").UnpackNestedValue<TFieldValues>, context: TContext | undefined, options: import("@saas-ui/forms").ResolverOptions<TFieldValues>) => Promise<import("@saas-ui/forms").ResolverResult<TFieldValues>>;
|
24
24
|
fieldResolver: {
|
25
25
|
getFields(): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
26
26
|
getNestedFields(name: string): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
package/dist/zod/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const zodForm = <T extends z.ZodTypeAny>(\n schema: T,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: zodResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: zodFieldResolver(schema),\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: string\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"names":["getType","field","_def","typeName","getArrayOption","name","_field$_def$name","value","getFieldsFromSchema","schema","fields","schemaFields","type","shape","options","min","max","meta","description","zodParseMeta","push","label","getNestedSchema","path","get","zodFieldResolver","getFields","getNestedFields","JSON","parse","e","schemaOptions","resolverOptions","resolver","zodResolver","fieldResolver","stringify"],"mappings":"2SAYA,IAAMA,EAAU,SAACC,GACf,OAAQA,EAAMC,KAAKC,UACjB,IAAK,WACH,MAAO,QACT,IAAK,YACH,MAAO,SACT,IAAK,YACH,MAAO,SACT,IAAK,UACH,MAAO,OAET,QACE,MAAO,
|
1
|
+
{"version":3,"file":"index.js","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const zodForm = <T extends z.ZodTypeAny>(\n schema: T,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: zodResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: zodFieldResolver(schema),\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: string\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"names":["getType","field","_def","typeName","getArrayOption","name","_field$_def$name","value","getFieldsFromSchema","schema","fields","schemaFields","type","shape","options","min","max","meta","description","zodParseMeta","push","label","getNestedSchema","path","get","zodFieldResolver","getFields","getNestedFields","JSON","parse","e","schemaOptions","resolverOptions","resolver","zodResolver","fieldResolver","stringify"],"mappings":"2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B,SACrBR,EACAsB,EACAC,GAEA,YAHa,IAAbD,IAAAA,EAAgB,CAAA,QACD,IAAfC,IAAAA,EAAkB,CAAA,GAEX,CACLvB,OAAAA,EACAwB,SAAUC,EAAAA,YAAYzB,EAAQsB,EAAeC,GAC7CG,cAAeV,EAAiBhB,GAEpC,kBAOuB,SAACQ,GACtB,OAAWW,KAACQ,UAAUnB,EACxB"}
|
@@ -1,2 +1,2 @@
|
|
1
1
|
import{zodResolver as e}from"@hookform/resolvers/zod";export{zodResolver}from"@hookform/resolvers/zod";import{get as r}from"@chakra-ui/utils";function t(){return t=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var o in t)Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o])}return e},t.apply(this,arguments)}const o=e=>{switch(e._def.typeName){case"ZodArray":return"array";case"ZodObject":return"object";case"ZodNumber":return"number";case"ZodDate":return"date";default:return"text"}},n=(e,r)=>{var t;return null==(t=e._def[r])?void 0:t.value},a=e=>{const r=[];let a={};if("ZodArray"===e._def.typeName)a=e._def.type.shape;else{if("ZodObject"!==e._def.typeName)return r;a=e._def.shape()}for(const e in a){const s=a[e],d={};"ZodArray"===s._def.typeName&&(d.min=n(s,"minLength"),d.max=n(s,"maxLength"));const i=s.description&&c(s.description);r.push(t({name:e,label:(null==i?void 0:i.label)||s.description||e,type:(null==i?void 0:i.type)||o(s)},d))}return r},s=(e,t)=>r(e._def.shape(),t),d=e=>({getFields:()=>a(e),getNestedFields:r=>a(s(e,r))}),i=(r,t={},o={})=>({schema:r,resolver:e(r,t,o),fieldResolver:d(r)}),l=e=>JSON.stringify(e),c=e=>{try{return JSON.parse(e)}catch(r){return e}};export{a as getFieldsFromSchema,s as getNestedSchema,d as zodFieldResolver,i as zodForm,l as zodMeta,c as zodParseMeta};
|
2
|
-
//# sourceMappingURL=index.modern.
|
2
|
+
//# sourceMappingURL=index.modern.mjs.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"index.modern.mjs","sources":["../../zod/src/zod-resolver.ts"],"sourcesContent":["import * as z from 'zod'\nimport { zodResolver } from '@hookform/resolvers/zod'\nimport { get } from '@chakra-ui/utils'\nimport { FieldProps } from '@saas-ui/forms'\n\nexport { zodResolver }\n\nexport type Options = {\n min?: number\n max?: number\n}\n\nconst getType = (field: z.ZodTypeAny) => {\n switch (field._def.typeName) {\n case 'ZodArray':\n return 'array'\n case 'ZodObject':\n return 'object'\n case 'ZodNumber':\n return 'number'\n case 'ZodDate':\n return 'date'\n case 'ZodString':\n default:\n return 'text'\n }\n}\n\nconst getArrayOption = (field: any, name: string) => {\n return field._def[name]?.value\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (schema: z.ZodTypeAny): FieldProps[] => {\n const fields: FieldProps[] = []\n\n let schemaFields: Record<string, any> = {}\n if (schema._def.typeName === 'ZodArray') {\n schemaFields = schema._def.type.shape\n } else if (schema._def.typeName === 'ZodObject') {\n schemaFields = schema._def.shape()\n } else {\n return fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field._def.typeName === 'ZodArray') {\n options.min = getArrayOption(field, 'minLength')\n options.max = getArrayOption(field, 'maxLength')\n }\n\n const meta = field.description && zodParseMeta(field.description)\n\n fields.push({\n name,\n label: meta?.label || field.description || name,\n type: meta?.type || getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: z.ZodTypeAny, path: string) => {\n return get(schema._def.shape(), path)\n}\n\nexport const zodFieldResolver = <T extends z.ZodTypeAny>(schema: T) => {\n return {\n getFields() {\n return getFieldsFromSchema(schema)\n },\n getNestedFields(name: string) {\n return getFieldsFromSchema(getNestedSchema(schema, name))\n },\n }\n}\n\nexport const zodForm = <T extends z.ZodTypeAny>(\n schema: T,\n schemaOptions = {},\n resolverOptions = {}\n) => {\n return {\n schema,\n resolver: zodResolver(schema, schemaOptions, resolverOptions),\n fieldResolver: zodFieldResolver(schema),\n }\n}\n\nexport interface ZodMeta {\n label: string\n type?: string\n}\n\nexport const zodMeta = (meta: ZodMeta) => {\n return JSON.stringify(meta)\n}\n\nexport const zodParseMeta = (meta: string) => {\n try {\n return JSON.parse(meta)\n } catch (e) {\n return meta\n }\n}\n"],"names":["field","_def","typeName","name","_field$_def$name","value","schema","schemaFields","type","shape","options","min","getArrayOption","max","meta","description","zodParseMeta","fields","push","label","getType","path","zodFieldResolver","getFields","getFieldsFromSchema","getNestedFields","getNestedSchema","schemaOptions","resolverOptions","resolver","zodResolver","fieldResolver","zodMeta","JSON","stringify","parse","e"],"mappings":"kXAYA,QAAiBA,IACf,OAAQA,EAAMC,KAAKC,UACjB,IAAK,WACH,MAAO,QACT,IAAK,YACH,MAAO,SACT,IAAK,YACH,MAAO,SACT,IAAK,UACH,MAAO,OAET,QACE,MAAO,OAAM,IAII,CAACF,EAAYG,KAClC,IAAAC,EAAA,OAAuB,OAAvBA,EAAOJ,EAAMC,KAAKE,SAAK,EAAhBC,EAAkBC,SASSC,IAClC,QAA6B,GAE7B,IAAIC,EAAoC,CAAE,EAC1C,GAA6B,aAAzBD,EAAOL,KAAKC,SACdK,EAAeD,EAAOL,KAAKO,KAAKC,UACvBH,IAAyB,cAAzBA,EAAOL,KAAKC,SAGrB,SAFAK,EAAeD,EAAOL,KAAKQ,OAG5B,CAED,IAAK,MAAMN,KAAQI,EAAc,CAC/B,QAAcA,EAAaJ,GAErBO,EAAmB,CAAA,EACG,aAAxBV,EAAMC,KAAKC,WACbQ,EAAQC,IAAMC,EAAeZ,EAAO,aACpCU,EAAQG,IAAMD,EAAeZ,EAAO,cAGtC,MAAMc,EAAOd,EAAMe,aAAeC,EAAahB,EAAMe,aAErDE,EAAOC,QACLf,OACAgB,OAAW,MAAJL,OAAI,EAAJA,EAAMK,QAASnB,EAAMe,aAAeZ,EAC3CK,YAAMM,SAAAA,EAAMN,OAAQY,EAAQpB,IACzBU,GAEN,CACD,OACFO,KAE+B,CAACX,EAAsBe,MACzCf,EAAOL,KAAKQ,QAASY,GAGrBC,EAA4ChB,IAChD,CACLiB,UAAS,IACmBC,EAAClB,GAE7BmB,gBAAgBtB,KACauB,EAAgBpB,EAAQH,QAKlC,CACrBG,EACAqB,EAAgB,CAAE,EAClBC,EAAkB,CAAA,KAEX,CACLtB,SACAuB,SAAUC,EAAYxB,EAAQqB,EAAeC,GAC7CG,cAAeT,EAAiBhB,KAShB0B,EAAIlB,GACXmB,KAACC,UAAUpB,GAGCE,EAAIF,IAC3B,IACE,YAAYqB,MAAMrB,EAGnB,CAFC,MAAOsB,GACP,OACDtB,CAAA"}
|
@@ -20,7 +20,7 @@ export declare const zodFieldResolver: <T extends z.ZodTypeAny>(schema: T) => {
|
|
20
20
|
};
|
21
21
|
export declare const zodForm: <T extends z.ZodTypeAny>(schema: T, schemaOptions?: {}, resolverOptions?: {}) => {
|
22
22
|
schema: T;
|
23
|
-
resolver: <TFieldValues extends import("@saas-ui/forms").FieldValues, TContext>(values: TFieldValues
|
23
|
+
resolver: <TFieldValues extends import("@saas-ui/forms").FieldValues, TContext>(values: import("@saas-ui/forms").UnpackNestedValue<TFieldValues>, context: TContext | undefined, options: import("@saas-ui/forms").ResolverOptions<TFieldValues>) => Promise<import("@saas-ui/forms").ResolverResult<TFieldValues>>;
|
24
24
|
fieldResolver: {
|
25
25
|
getFields(): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
26
26
|
getNestedFields(name: string): FieldProps<import("@saas-ui/forms").FieldValues, string>[];
|
package/package.json
CHANGED
@@ -1,40 +1,40 @@
|
|
1
1
|
{
|
2
2
|
"name": "@saas-ui/forms",
|
3
|
-
"version": "1.
|
3
|
+
"version": "1.5.0",
|
4
4
|
"description": "Fully functional forms for Chakra UI.",
|
5
5
|
"source": "src/index.ts",
|
6
6
|
"exports": {
|
7
7
|
".": {
|
8
8
|
"require": "./dist/index.js",
|
9
|
-
"import": "./dist/index.modern.
|
9
|
+
"import": "./dist/index.modern.mjs"
|
10
10
|
},
|
11
11
|
"./src": {
|
12
12
|
"default": "./src/index.ts"
|
13
13
|
},
|
14
14
|
"./yup": {
|
15
15
|
"require": "./dist/yup/index.js",
|
16
|
-
"import": "./dist/yup/index.modern.
|
16
|
+
"import": "./dist/yup/index.modern.mjs"
|
17
17
|
},
|
18
18
|
"./yup/src": {
|
19
19
|
"default": "./yup/src/index.ts"
|
20
20
|
},
|
21
21
|
"./zod": {
|
22
22
|
"require": "./dist/zod/index.js",
|
23
|
-
"import": "./dist/zod/index.modern.
|
23
|
+
"import": "./dist/zod/index.modern.mjs"
|
24
24
|
},
|
25
25
|
"./zod/src": {
|
26
26
|
"default": "./zod/src/index.ts"
|
27
27
|
},
|
28
28
|
"./ajv": {
|
29
29
|
"require": "./dist/ajv/index.js",
|
30
|
-
"import": "./dist/ajv/index.modern.
|
30
|
+
"import": "./dist/ajv/index.modern.mjs"
|
31
31
|
},
|
32
32
|
"./ajv/src": {
|
33
33
|
"default": "./ajv/src/index.ts"
|
34
34
|
}
|
35
35
|
},
|
36
36
|
"main": "./dist/index.js",
|
37
|
-
"module": "./dist/index.modern.
|
37
|
+
"module": "./dist/index.modern.mjs",
|
38
38
|
"types": "./dist/index.d.ts",
|
39
39
|
"scripts": {
|
40
40
|
"clean": "rimraf --no-glob ./dist",
|
@@ -89,24 +89,24 @@
|
|
89
89
|
"url": "https://storybook.saas-ui.dev"
|
90
90
|
},
|
91
91
|
"dependencies": {
|
92
|
-
"@chakra-ui/icons": "^2.0.
|
93
|
-
"@chakra-ui/react-utils": "^2.0.
|
94
|
-
"@chakra-ui/utils": "^2.0.
|
92
|
+
"@chakra-ui/icons": "^2.0.16",
|
93
|
+
"@chakra-ui/react-utils": "^2.0.11",
|
94
|
+
"@chakra-ui/utils": "^2.0.14",
|
95
95
|
"@hookform/resolvers": "^2.9.10",
|
96
|
-
"@saas-ui/button": "1.
|
97
|
-
"@saas-ui/input-right-button": "1.
|
98
|
-
"@saas-ui/number-input": "1.
|
99
|
-
"@saas-ui/password-input": "1.
|
100
|
-
"@saas-ui/pin-input": "1.
|
101
|
-
"@saas-ui/radio": "1.
|
102
|
-
"@saas-ui/react-utils": "1.
|
103
|
-
"@saas-ui/select": "1.
|
104
|
-
"@saas-ui/stepper": "1.
|
105
|
-
"react-hook-form": "^7.
|
96
|
+
"@saas-ui/button": "1.4.0",
|
97
|
+
"@saas-ui/input-right-button": "1.4.0",
|
98
|
+
"@saas-ui/number-input": "1.4.0",
|
99
|
+
"@saas-ui/password-input": "1.4.0",
|
100
|
+
"@saas-ui/pin-input": "1.4.0",
|
101
|
+
"@saas-ui/radio": "1.4.0",
|
102
|
+
"@saas-ui/react-utils": "1.2.0",
|
103
|
+
"@saas-ui/select": "1.4.0",
|
104
|
+
"@saas-ui/stepper": "1.4.0",
|
105
|
+
"react-hook-form": "^7.42.1"
|
106
106
|
},
|
107
107
|
"peerDependencies": {
|
108
|
-
"@chakra-ui/react": ">=2.
|
109
|
-
"@chakra-ui/system": ">=2.
|
108
|
+
"@chakra-ui/react": ">=2.4.6",
|
109
|
+
"@chakra-ui/system": ">=2.3.8",
|
110
110
|
"react": ">=18.0.0"
|
111
111
|
},
|
112
112
|
"devDependencies": {
|
package/src/field.tsx
CHANGED
@@ -381,8 +381,8 @@ export const TextareaField = registerFieldType<TextareaProps>(
|
|
381
381
|
|
382
382
|
export const SwitchField = registerFieldType<SwitchProps>(
|
383
383
|
'switch',
|
384
|
-
forwardRef(({ type, ...rest }, ref) => {
|
385
|
-
return <Switch {...rest} ref={ref} />
|
384
|
+
forwardRef(({ type, value, ...rest }, ref) => {
|
385
|
+
return <Switch isChecked={!!value} {...rest} ref={ref} />
|
386
386
|
}),
|
387
387
|
{
|
388
388
|
isControlled: true,
|
package/src/form.tsx
CHANGED
@@ -15,13 +15,17 @@ import {
|
|
15
15
|
ResolverResult,
|
16
16
|
ChangeHandler,
|
17
17
|
WatchObserver,
|
18
|
+
UnpackNestedValue,
|
18
19
|
} from 'react-hook-form'
|
19
20
|
import { objectFieldResolver, FieldResolver } from './field-resolver'
|
20
21
|
import { MaybeRenderProp } from '@chakra-ui/react-utils'
|
21
22
|
|
22
23
|
export type { UseFormReturn, FieldValues, SubmitHandler }
|
23
24
|
|
24
|
-
interface FormOptions<
|
25
|
+
interface FormOptions<
|
26
|
+
TFieldValues extends FieldValues = FieldValues,
|
27
|
+
TContext extends object = object
|
28
|
+
> {
|
25
29
|
/**
|
26
30
|
* The form schema, currently supports Yup schema only.
|
27
31
|
*/
|
@@ -45,23 +49,28 @@ interface FormOptions<TFieldValues extends FieldValues = FieldValues> {
|
|
45
49
|
/**
|
46
50
|
* The form children, can be a render prop or a ReactNode.
|
47
51
|
*/
|
48
|
-
children?: MaybeRenderProp<UseFormReturn<TFieldValues>>
|
52
|
+
children?: MaybeRenderProp<UseFormReturn<TFieldValues, TContext>>
|
49
53
|
}
|
50
54
|
|
51
55
|
// @todo Figure out how to pass down FieldValues to all Field components, if at all possible.
|
52
56
|
|
53
|
-
export interface FormProps<
|
54
|
-
extends
|
57
|
+
export interface FormProps<
|
58
|
+
TFieldValues extends FieldValues = FieldValues,
|
59
|
+
TContext extends object = object
|
60
|
+
> extends UseFormProps<TFieldValues, TContext>,
|
55
61
|
Omit<
|
56
62
|
HTMLChakraProps<'form'>,
|
57
63
|
'children' | 'onChange' | 'onSubmit' | 'onError'
|
58
64
|
>,
|
59
|
-
FormOptions<TFieldValues> {}
|
65
|
+
FormOptions<TFieldValues, TContext> {}
|
60
66
|
|
61
67
|
export const Form = forwardRef(
|
62
|
-
<
|
63
|
-
|
64
|
-
|
68
|
+
<
|
69
|
+
TFieldValues extends FieldValues = FieldValues,
|
70
|
+
TContext extends object = object
|
71
|
+
>(
|
72
|
+
props: FormProps<TFieldValues, TContext>,
|
73
|
+
ref: React.ForwardedRef<UseFormReturn<TFieldValues, TContext>>
|
65
74
|
) => {
|
66
75
|
const {
|
67
76
|
mode = 'all',
|
@@ -95,10 +104,10 @@ export const Form = forwardRef(
|
|
95
104
|
}
|
96
105
|
|
97
106
|
if (schema && !resolver) {
|
98
|
-
form.resolver = Form.getResolver
|
107
|
+
form.resolver = Form.getResolver?.<TFieldValues, TContext>(schema)
|
99
108
|
}
|
100
109
|
|
101
|
-
const methods = useForm<TFieldValues>(form)
|
110
|
+
const methods = useForm<TFieldValues, TContext>(form)
|
102
111
|
const { handleSubmit } = methods
|
103
112
|
|
104
113
|
// This exposes the useForm api through the forwarded ref
|
@@ -125,7 +134,7 @@ export const Form = forwardRef(
|
|
125
134
|
</FormProvider>
|
126
135
|
)
|
127
136
|
}
|
128
|
-
) as (<TFieldValues extends FieldValues>(
|
137
|
+
) as (<TFieldValues extends FieldValues, TContext extends object = object>(
|
129
138
|
props: FormProps<TFieldValues> & {
|
130
139
|
ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>
|
131
140
|
}
|
@@ -141,10 +150,13 @@ if (__DEV__) {
|
|
141
150
|
Form.displayName = 'Form'
|
142
151
|
}
|
143
152
|
|
144
|
-
export type GetResolver =
|
153
|
+
export type GetResolver = <
|
154
|
+
TFieldValues extends FieldValues,
|
155
|
+
TContext extends object
|
156
|
+
>(
|
145
157
|
schema: any
|
146
|
-
) =>
|
147
|
-
values: TFieldValues
|
158
|
+
) => (
|
159
|
+
values: UnpackNestedValue<TFieldValues>,
|
148
160
|
context: TContext | undefined,
|
149
161
|
options: ResolverOptions<TFieldValues>
|
150
162
|
) => Promise<ResolverResult<TFieldValues>>
|
package/yup/package.json
CHANGED
@@ -6,7 +6,7 @@
|
|
6
6
|
"exports": {
|
7
7
|
".": {
|
8
8
|
"require": "./../dist/yup/index.js",
|
9
|
-
"import": "./../dist/yup/index.modern.
|
9
|
+
"import": "./../dist/yup/index.modern.mjs"
|
10
10
|
},
|
11
11
|
"./src": {
|
12
12
|
"default": "./src/index.ts"
|
@@ -14,7 +14,7 @@
|
|
14
14
|
},
|
15
15
|
"source": "./src/index.ts",
|
16
16
|
"main": "../dist/yup/index.js",
|
17
|
-
"module": "../dist/yup/index.modern.
|
17
|
+
"module": "../dist/yup/index.modern.mjs",
|
18
18
|
"types": "../dist/yup/index.d.ts",
|
19
19
|
"author": "Eelco Wiersma <eelco@appulse.nl>",
|
20
20
|
"license": "MIT",
|