@saas-ui/forms 0.5.0 → 0.6.0-next.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,2 +1,2 @@
1
- import*as e from"react";import{useFormContext as t,get as r,Controller as n,useFieldArray as a,useForm as l,FormProvider as i,useWatch as o}from"react-hook-form";import{FormControl as s,FormLabel as c,Text as u,forwardRef as p,Switch as m,Checkbox as d,Box as f,FormHelperText as h,FormErrorMessage as v,useMergeRefs as b,Input as y,Textarea as _,useTheme as g,SimpleGrid as E,chakra as x,useStyles as S,Collapse as j}from"@chakra-ui/react";import{NumberInput as N}from"@saas-ui/number-input";import{PasswordInput as C}from"@saas-ui/password-input";import{RadioInput as O}from"@saas-ui/radio";import{PinInput as w}from"@saas-ui/pin-input";import{Select as A,NativeSelect as k}from"@saas-ui/select";import{reach as F}from"yup";import{yupResolver as I}from"@hookform/resolvers/yup";import{chakra as V,forwardRef as z,useMultiStyleConfig as L,omitThemingProps as D,StylesProvider as P,useStyles as R}from"@chakra-ui/system";import{MinusIcon as U,AddIcon as M,Icon as $,CheckIcon as B}from"@chakra-ui/icons";import{IconButton as T,Button as q}from"@saas-ui/button";import{createContext as G}from"@chakra-ui/react-utils";import{getChildrenOfType as W,getChildOfType as H}from"@saas-ui/react-utils";export*from"@saas-ui/input-right-button";function J(){return J=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},J.apply(this,arguments)}function K(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}const Q=["name","label","placeholder"],X=t=>{let{name:r,label:n}=t,a=K(t,Q);/*#__PURE__*/return e.createElement(s,a,n?/*#__PURE__*/e.createElement(c,{htmlFor:r},n):null,/*#__PURE__*/e.createElement(u,{fontSize:"md"},/*#__PURE__*/e.createElement(Y,{name:r})))},Y=({name:e})=>{const{getValues:r}=t();return r(e)||null},Z=["name","label","help","variant","hideLabel","children"],ee=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],te=["name","rules"],re=["ref"],ne=["name","rules"],ae=["ref"],le=["label"],ie=["label"],oe={},se="text",ce=n=>{const{name:a,label:l,help:i,variant:o,hideLabel:u,children:p}=n,m=K(n,Z),{formState:d}=t(),b=((e,t)=>r(t.errors,e))(a,d);/*#__PURE__*/return e.createElement(s,J({variant:o},m,{isInvalid:!!b}),l&&!u?/*#__PURE__*/e.createElement(c,{variant:o},l):null,/*#__PURE__*/e.createElement(f,null,p,!i||null!=b&&b.message?null:/*#__PURE__*/e.createElement(h,null,i),(null==b?void 0:b.message)&&/*#__PURE__*/e.createElement(v,null,null==b?void 0:b.message)))},ue=p((t,r)=>{const{type:n=se}=t,a=(e=>oe[e]||oe[se])(n);/*#__PURE__*/return e.createElement(a,J({ref:r},t))}),pe=r=>p((a,l)=>{let{name:i,rules:o}=a,s=K(a,te);const{control:c}=t();/*#__PURE__*/return e.createElement(n,{name:i,control:c,rules:o,render:t=>{let{field:{ref:n}}=t,a=K(t.field,re);/*#__PURE__*/return e.createElement(r,J({},a,s,{ref:b(l,n)}))}})}),me=r=>p((n,a)=>{let{name:l,rules:i}=n,o=K(n,ne);const{register:s}=t(),c=s(l,i),{ref:u}=c,p=K(c,ae);/*#__PURE__*/return e.createElement(r,J({},p,o,{ref:b(a,u)}))}),de=(t,r,n)=>{let a;a=null!=n&&n.isControlled?pe(r):me(r);const l=((t,{displayName:r,hideLabel:n,BaseField:a})=>{const l=p((r,l)=>{const{name:i,label:o,help:s,isDisabled:c,isInvalid:u,isReadOnly:p,isRequired:m,rules:d,variant:f}=r,h=K(r,ee),v=J({required:m},d);/*#__PURE__*/return e.createElement(a,{name:i,label:o,help:s,hideLabel:n,isDisabled:c,isInvalid:u,isReadOnly:p,isRequired:m,variant:f},/*#__PURE__*/e.createElement(t,J({ref:l,name:i,label:o,rules:v},h)))});return l.displayName=r,l})(a,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||ce});return oe[t]=l,l},fe=de("text",y),he=de("number",N,{isControlled:!0}),ve=de("password",C),be=de("textarea",_),ye=de("switch",p((t,r)=>{let{label:n}=t,a=K(t,le);/*#__PURE__*/return e.createElement(m,J({ref:r},a),n)}),{isControlled:!0,hideLabel:!0}),_e=de("select",A,{isControlled:!0}),ge=de("checkbox",p((t,r)=>{let{label:n}=t,a=K(t,ie);/*#__PURE__*/return e.createElement(d,J({ref:r},a),n)}),{hideLabel:!0}),Ee=de("radio",O,{isControlled:!0}),xe=de("pin",w,{isControlled:!0}),Se=de("native-select",k,{isControlled:!0}),je=e=>{var t;if(null!=(t=e.spec.meta)&&t.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},Ne=(e,t)=>{for(const n of e.tests){var r;if(null!=(r=n.OPTIONS)&&r.params[t])return n.OPTIONS.params[t]}},Ce=e=>{const t=[];let r={};r="array"===e.type?e.innerType.fields:e.fields;for(const e in r){const n=r[e],a={};"array"===n.type&&(a.min=Ne(n,"min"),a.max=Ne(n,"max")),t.push(J({name:e,label:n.spec.label||e,type:je(n)},a))}return t},Oe=["children"],we=({children:t})=>/*#__PURE__*/e.createElement(x.div,null,t),Ae=t=>{var r,n,a;let{children:l}=t,i=K(t,Oe);const o=J({},null!=(r=null==(n=g().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?r:{spacing:4},i);/*#__PURE__*/return e.createElement(E,o,e.Children.map(l,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(we,null,t):t))},ke=(t,r)=>e.Children.map(r,r=>e.isValidElement(r)&&r.props.name?e.cloneElement(r,J({},r.props,{name:`${t}.${r.props.name}`})):r),[Fe,Ie]=G({name:"ArrayFieldContext"}),[Ve,ze]=G({name:"ArrayFieldRowContext"}),Le=({name:e,defaultValue:r={},keyName:n,min:l,max:i})=>{const{control:o}=t();return J({},a({control:o,name:e,keyName:n}),{name:e,defaultValue:r,min:l,max:i})},De=({index:r})=>{const{clearErrors:n}=t(),{name:a,remove:l,fields:i}=Ie();return e.useEffect(()=>{n(a)},[]),{index:r,isFirst:0===r,isLast:r===i.length-1,name:`${a}.${r}`,remove:e.useCallback(()=>{n(a),l(r)},[r])}},Pe=()=>{const{isFirst:e,remove:t}=ze(),{min:r,fields:n}=Ie();return{onClick:()=>t(),isDisabled:e&&!!(r&&n.length<=r)}},Re=()=>{const{append:e,defaultValue:t,max:r,fields:n}=Ie();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(r&&n.length>=r)}},Ue=["children","columns","spacing"],Me=["children"],$e=["name","defaultValue","keyName","min","max","children"],Be=({children:t,columns:r,spacing:n,index:a})=>/*#__PURE__*/e.createElement(qe,{index:a},/*#__PURE__*/e.createElement(Te,{columns:r,spacing:n},t),/*#__PURE__*/e.createElement(Ge,null)),Te=t=>{let{children:r,columns:n,spacing:a}=t,l=K(t,Ue);const{name:i}=ze();/*#__PURE__*/return e.createElement(Ae,J({flex:"1",columns:n,gridGap:a,mr:"2"},l),ke(i,r))},qe=({children:t,index:r})=>{const n=De({index:r});/*#__PURE__*/return e.createElement(Ve,{value:n},/*#__PURE__*/e.createElement(V.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},Ge=t=>/*#__PURE__*/e.createElement(T,J({icon:/*#__PURE__*/e.createElement(U,null),"aria-label":"Remove row"},Pe(),t)),We=t=>/*#__PURE__*/e.createElement(T,J({icon:/*#__PURE__*/e.createElement(M,null),"aria-label":"Add row",float:"right"},Re(),t)),He=t=>{const{children:r}=t,n=K(t,Me);/*#__PURE__*/return e.createElement(Ke,n,/*#__PURE__*/e.createElement(Je,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},n)=>/*#__PURE__*/e.createElement(Be,{key:t,index:n},r)))),/*#__PURE__*/e.createElement(We,null))},Je=({children:e})=>{const{fields:t}=Ie();return e(t)},Ke=t=>{let{name:r,defaultValue:n,keyName:a,min:l,max:i,children:o}=t,s=K(t,$e);const c=Le({name:r,defaultValue:n,keyName:a,min:l,max:i});/*#__PURE__*/return e.createElement(Fe,{value:c},/*#__PURE__*/e.createElement(ce,J({name:r},s),o))},Qe=["name","label","hideLabel","children","columns","spacing"],Xe=t=>{const r=S();/*#__PURE__*/return e.createElement(c,J({as:"legend",sx:r.legend},t))},Ye=t=>{const{name:r,label:n,hideLabel:a,children:l,columns:i,spacing:o}=t,c=K(t,Qe);/*#__PURE__*/return e.createElement(s,J({name:r,as:"fieldset"},c),/*#__PURE__*/e.createElement(Xe,{display:a?"none":"block"},n),/*#__PURE__*/e.createElement(Ae,{columns:i,gridGap:o},ke(r,l)))},Ze=["name","type"],et=["schema"],tt=["name","type","defaultValue"],rt=(t,r)=>Ce(((e,t)=>F(e,t))(t,r)).map(t=>{let{name:r,type:n}=t,a=K(t,Ze);/*#__PURE__*/return e.createElement(ue,J({key:r,name:r,type:n},a))}),nt=t=>{let{schema:r}=t,n=K(t,et);/*#__PURE__*/return e.createElement(Ae,n,Ce(r).map(t=>{let{name:n,type:a}=t,l=K(t,tt);return"array"===a?/*#__PURE__*/e.createElement(He,J({name:n},l),rt(r,n)):"object"===a?/*#__PURE__*/e.createElement(Ye,J({name:n},l),rt(r,n)):/*#__PURE__*/e.createElement(ue,J({key:n,name:n,type:a},l))}))},at=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],lt=p((t,r)=>{const{mode:n="all",resolver:a,reValidateMode:o,shouldFocusError:s,shouldUnregister:c,shouldUseNativeValidation:u,criteriaMode:p,delayError:m,schema:d,defaultValues:f,onSubmit:h,onError:v,formRef:b,children:y}=t,_=K(t,at),g={mode:n,resolver:a,defaultValues:f,reValidateMode:o,shouldFocusError:s,shouldUnregister:c,shouldUseNativeValidation:u,criteriaMode:p,delayError:m};d&&(g.resolver=I(d));const E=l(g),{handleSubmit:S}=E;return e.useImperativeHandle(r,()=>E,[r,E]),/*#__PURE__*/e.createElement(i,E,/*#__PURE__*/e.createElement(x.form,J({ref:b,onSubmit:S(h,v)},_),y))}),it=["children","disableIfUntouched","disableIfInvalid"],ot=z((r,n)=>{const{children:a,disableIfUntouched:l,disableIfInvalid:i}=r,o=K(r,it),{formState:s}=t();/*#__PURE__*/return e.createElement(q,J({type:"submit",isLoading:s.isSubmitting,isPrimary:!0,ref:n,isDisabled:l&&!s.isDirty||i&&!s.isValid},o),a)});ot.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};const st=["schema","submitLabel"],ct=p((t,r)=>{const{schema:n,submitLabel:a="Submit"}=t,l=K(t,st);/*#__PURE__*/return e.createElement(lt,J({},l,{schema:n,ref:r}),/*#__PURE__*/e.createElement(Ae,null,/*#__PURE__*/e.createElement(nt,{schema:n}),a&&/*#__PURE__*/e.createElement(ot,{label:a})))}),ut=({children:e,name:r,defaultValue:n,isDisabled:a,isExact:l,condition:i=(e=>!!e)})=>i(o({name:r,defaultValue:n,disabled:a,exact:l}),t())?e:null;var pt,mt,dt="undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:{};function ft(e){return"function"==typeof e}pt=function(e,t){var r="__lodash_hash_undefined__",n=9007199254740991,a="[object Arguments]",l="[object Function]",i="[object Object]",o=/^\[object .+?Constructor\]$/,s=/^(?:0|[1-9]\d*)$/,c={};c["[object Float32Array]"]=c["[object Float64Array]"]=c["[object Int8Array]"]=c["[object Int16Array]"]=c["[object Int32Array]"]=c["[object Uint8Array]"]=c["[object Uint8ClampedArray]"]=c["[object Uint16Array]"]=c["[object Uint32Array]"]=!0,c[a]=c["[object Array]"]=c["[object ArrayBuffer]"]=c["[object Boolean]"]=c["[object DataView]"]=c["[object Date]"]=c["[object Error]"]=c[l]=c["[object Map]"]=c["[object Number]"]=c[i]=c["[object RegExp]"]=c["[object Set]"]=c["[object String]"]=c["[object WeakMap]"]=!1;var u="object"==typeof dt&&dt&&dt.Object===Object&&dt,p="object"==typeof self&&self&&self.Object===Object&&self,m=u||p||Function("return this")(),d=t&&!t.nodeType&&t,f=d&&e&&!e.nodeType&&e,h=f&&f.exports===d,v=h&&u.process,b=function(){try{return f&&f.require&&f.require("util").types||v&&v.binding&&v.binding("util")}catch(e){}}(),y=b&&b.isTypedArray;function _(e,t,r){switch(r.length){case 0:return e.call(t);case 1:return e.call(t,r[0]);case 2:return e.call(t,r[0],r[1]);case 3:return e.call(t,r[0],r[1],r[2])}return e.apply(t,r)}var g,E,x,S=Array.prototype,j=Object.prototype,N=m["__core-js_shared__"],C=Function.prototype.toString,O=j.hasOwnProperty,w=(g=/[^.]+$/.exec(N&&N.keys&&N.keys.IE_PROTO||""))?"Symbol(src)_1."+g:"",A=j.toString,k=C.call(Object),F=RegExp("^"+C.call(O).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),I=h?m.Buffer:void 0,V=m.Symbol,z=m.Uint8Array,L=(E=Object.getPrototypeOf,x=Object,function(e){return E(x(e))}),D=Object.create,P=j.propertyIsEnumerable,R=S.splice,U=V?V.toStringTag:void 0,M=function(){try{var e=ie(Object,"defineProperty");return e({},"",{}),e}catch(e){}}(),$=I?I.isBuffer:void 0,B=Math.max,T=Date.now,q=ie(m,"Map"),G=ie(Object,"create"),W=function(){function e(){}return function(t){if(!ye(t))return{};if(D)return D(t);e.prototype=t;var r=new e;return e.prototype=void 0,r}}();function H(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function J(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function K(e){var t=-1,r=null==e?0:e.length;for(this.clear();++t<r;){var n=e[t];this.set(n[0],n[1])}}function Q(e){var t=this.__data__=new J(e);this.size=t.size}function X(e,t,r){(void 0!==r&&!pe(e[t],r)||void 0===r&&!(t in e))&&ee(e,t,r)}function Y(e,t,r){var n=e[t];O.call(e,t)&&pe(n,r)&&(void 0!==r||t in e)||ee(e,t,r)}function Z(e,t){for(var r=e.length;r--;)if(pe(e[r][0],t))return r;return-1}function ee(e,t,r){"__proto__"==t&&M?M(e,t,{configurable:!0,enumerable:!0,value:r,writable:!0}):e[t]=r}function te(e){return null==e?void 0===e?"[object Undefined]":"[object Null]":U&&U in Object(e)?function(e){var t=O.call(e,U),r=e[U];try{e[U]=void 0;var n=!0}catch(e){}var a=A.call(e);return n&&(t?e[U]=r:delete e[U]),a}(e):function(e){return A.call(e)}(e)}function re(e){return _e(e)&&te(e)==a}function ne(e,t,r,n,a){e!==t&&function(e,t,r){for(var n=-1,a=Object(e),l=r(e),i=l.length;i--;){var o=l[++n];if(!1===t(a[o],o))break}}(t,function(l,o){if(a||(a=new Q),ye(l))!function(e,t,r,n,a,l,o){var s=ce(e,r),c=ce(t,r),u=o.get(c);if(u)X(e,r,u);else{var p,m,d,f,h=l?l(s,c,r+"",e,t,o):void 0,v=void 0===h;if(v){var b=de(c),y=!b&&he(c),_=!b&&!y&&ge(c);h=c,b||y||_?de(s)?h=s:_e(f=s)&&fe(f)?h=function(e,t){var r=-1,n=e.length;for(t||(t=Array(n));++r<n;)t[r]=e[r];return t}(s):y?(v=!1,h=c.slice()):_?(v=!1,d=new(m=(p=c).buffer).constructor(m.byteLength),new z(d).set(new z(m)),h=new p.constructor(d,p.byteOffset,p.length)):h=[]:function(e){if(!_e(e)||te(e)!=i)return!1;var t=L(e);if(null===t)return!0;var r=O.call(t,"constructor")&&t.constructor;return"function"==typeof r&&r instanceof r&&C.call(r)==k}(c)||me(c)?(h=s,me(s)?h=function(e){return function(e,t,r,n){var a=!r;r||(r={});for(var l=-1,i=t.length;++l<i;){var o=t[l],s=void 0;void 0===s&&(s=e[o]),a?ee(r,o,s):Y(r,o,s)}return r}(e,Ee(e))}(s):ye(s)&&!ve(s)||(h=function(e){return"function"!=typeof e.constructor||se(e)?{}:W(L(e))}(c))):v=!1}v&&(o.set(c,h),a(h,c,n,l,o),o.delete(c)),X(e,r,h)}}(e,t,o,r,ne,n,a);else{var s=n?n(ce(e,o),l,o+"",e,t,a):void 0;void 0===s&&(s=l),X(e,o,s)}},Ee)}H.prototype.clear=function(){this.__data__=G?G(null):{},this.size=0},H.prototype.delete=function(e){var t=this.has(e)&&delete this.__data__[e];return this.size-=t?1:0,t},H.prototype.get=function(e){var t=this.__data__;if(G){var n=t[e];return n===r?void 0:n}return O.call(t,e)?t[e]:void 0},H.prototype.has=function(e){var t=this.__data__;return G?void 0!==t[e]:O.call(t,e)},H.prototype.set=function(e,t){var n=this.__data__;return this.size+=this.has(e)?0:1,n[e]=G&&void 0===t?r:t,this},J.prototype.clear=function(){this.__data__=[],this.size=0},J.prototype.delete=function(e){var t=this.__data__,r=Z(t,e);return!(r<0||(r==t.length-1?t.pop():R.call(t,r,1),--this.size,0))},J.prototype.get=function(e){var t=this.__data__,r=Z(t,e);return r<0?void 0:t[r][1]},J.prototype.has=function(e){return Z(this.__data__,e)>-1},J.prototype.set=function(e,t){var r=this.__data__,n=Z(r,e);return n<0?(++this.size,r.push([e,t])):r[n][1]=t,this},K.prototype.clear=function(){this.size=0,this.__data__={hash:new H,map:new(q||J),string:new H}},K.prototype.delete=function(e){var t=le(this,e).delete(e);return this.size-=t?1:0,t},K.prototype.get=function(e){return le(this,e).get(e)},K.prototype.has=function(e){return le(this,e).has(e)},K.prototype.set=function(e,t){var r=le(this,e),n=r.size;return r.set(e,t),this.size+=r.size==n?0:1,this},Q.prototype.clear=function(){this.__data__=new J,this.size=0},Q.prototype.delete=function(e){var t=this.__data__,r=t.delete(e);return this.size=t.size,r},Q.prototype.get=function(e){return this.__data__.get(e)},Q.prototype.has=function(e){return this.__data__.has(e)},Q.prototype.set=function(e,t){var r=this.__data__;if(r instanceof J){var n=r.__data__;if(!q||n.length<199)return n.push([e,t]),this.size=++r.size,this;r=this.__data__=new K(n)}return r.set(e,t),this.size=r.size,this};var ae=M?function(e,t){return M(e,"toString",{configurable:!0,enumerable:!1,value:(r=t,function(){return r}),writable:!0});var r}:je;function le(e,t){var r,n,a=e.__data__;return("string"==(n=typeof(r=t))||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==r:null===r)?a["string"==typeof t?"string":"hash"]:a.map}function ie(e,t){var r=function(e,t){return null==e?void 0:e[t]}(e,t);return function(e){return!(!ye(e)||function(e){return!!w&&w in e}(e))&&(ve(e)?F:o).test(function(e){if(null!=e){try{return C.call(e)}catch(e){}try{return e+""}catch(e){}}return""}(e))}(r)?r:void 0}function oe(e,t){var r=typeof e;return!!(t=null==t?n:t)&&("number"==r||"symbol"!=r&&s.test(e))&&e>-1&&e%1==0&&e<t}function se(e){var t=e&&e.constructor;return e===("function"==typeof t&&t.prototype||j)}function ce(e,t){if(("constructor"!==t||"function"!=typeof e[t])&&"__proto__"!=t)return e[t]}var ue=function(e){var t=0,r=0;return function(){var n=T(),a=16-(n-r);if(r=n,a>0){if(++t>=800)return arguments[0]}else t=0;return e.apply(void 0,arguments)}}(ae);function pe(e,t){return e===t||e!=e&&t!=t}var me=re(function(){return arguments}())?re:function(e){return _e(e)&&O.call(e,"callee")&&!P.call(e,"callee")},de=Array.isArray;function fe(e){return null!=e&&be(e.length)&&!ve(e)}var he=$||function(){return!1};function ve(e){if(!ye(e))return!1;var t=te(e);return t==l||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t}function be(e){return"number"==typeof e&&e>-1&&e%1==0&&e<=n}function ye(e){var t=typeof e;return null!=e&&("object"==t||"function"==t)}function _e(e){return null!=e&&"object"==typeof e}var ge=y?function(e){return function(t){return e(t)}}(y):function(e){return _e(e)&&be(e.length)&&!!c[te(e)]};function Ee(e){return fe(e)?function(e,t){var r=de(e),n=!r&&me(e),a=!r&&!n&&he(e),l=!r&&!n&&!a&&ge(e),i=r||n||a||l,o=i?function(e,t){for(var r=-1,n=Array(e);++r<e;)n[r]=t(r);return n}(e.length,String):[],s=o.length;for(var c in e)i&&("length"==c||a&&("offset"==c||"parent"==c)||l&&("buffer"==c||"byteLength"==c||"byteOffset"==c)||oe(c,s))||o.push(c);return o}(e):function(e){if(!ye(e))return function(e){var t=[];if(null!=e)for(var r in Object(e))t.push(r);return t}(e);var t=se(e),r=[];for(var n in e)("constructor"!=n||!t&&O.call(e,n))&&r.push(n);return r}(e)}var xe,Se=(xe=function(e,t,r,n){ne(e,t,r,n)},function(e,t){return ue(function(e,t,r){return t=B(void 0===t?e.length-1:t,0),function(){for(var n=arguments,a=-1,l=B(n.length-t,0),i=Array(l);++a<l;)i[a]=n[t+a];a=-1;for(var o=Array(t+1);++a<t;)o[a]=n[a];return o[t]=r(i),_(e,this,o)}}(e,void 0,je),e+"")}(function(e,t){var r=-1,n=t.length,a=n>1?t[n-1]:void 0,l=n>2?t[2]:void 0;for(a=xe.length>3&&"function"==typeof a?(n--,a):void 0,l&&function(e,t,r){if(!ye(r))return!1;var n=typeof t;return!!("number"==n?fe(r)&&oe(t,r.length):"string"==n&&t in r)&&pe(r[t],e)}(t[0],t[1],l)&&(a=n<3?void 0:a,n=1),e=Object(e);++r<n;){var i=t[r];i&&xe(e,i,r,a)}return e}));function je(e){return e}e.exports=Se},pt(mt={exports:{}},mt.exports);var ht="production"!==process.env.NODE_ENV;process;var vt=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.filter(Boolean).join(" ")};function bt(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return function(e){t.some(function(t){return null==t||t(e),null==e?void 0:e.defaultPrevented})}}Object.freeze(["base","sm","md","lg","xl","2xl"]);var yt="production"!==process.env.NODE_ENV;process;var _t=function(){for(var e=arguments.length,t=new Array(e),r=0;r<e;r++)t[r]=arguments[r];return t.filter(Boolean).join(" ")};function gt(){return gt=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},gt.apply(this,arguments)}function Et(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}Object.freeze(["base","sm","md","lg","xl","2xl"]);const[xt,St]=G({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"});function jt(t){const{step:r}=t,[n,a]=e.useState(-1),l=e.useRef([]),[,i]=e.useState(Date.now()),o=e.useCallback(e=>{const t=[...l.current];-1===t.indexOf(e)&&t.push(e),l.current=t,i(Date.now())},[l,i]),s=e=>{const t=l.current.indexOf(e);-1!==t&&a(t)};return e.useLayoutEffect(()=>{"string"==typeof r?s(r):"number"==typeof r?a(r):-1===n&&a(0)},[r]),{stepsRef:l,activeStep:l.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===l.current.length-1,isCompleted:n>=l.current.length,setIndex:a,setStep:s,nextStep:()=>{a(n+1)},prevStep:()=>{a(n-1)},registerStep:o,unregisterStep:e=>{l.current=l.current.slice(l.current.indexOf(e),1)}}}function Nt(t){const{name:r,isActive:n,isCompleted:a}=t,{registerStep:l,unregisterStep:i,activeStep:o}=St();return e.useEffect(()=>{if(r)return l(r),()=>{i(r)}},[]),{isActive:r?o===r:n,isCompleted:a}}const Ct=["children","orientation"],Ot=["children","orientation","stepComponent"],wt=["children","isOpen"],At=["icon","isActive","isCompleted","className"],kt=["title","icon","isActive","isCompleted"],Ft=["isActive"],It=z((t,r)=>{const n=L("Stepper",t),a=D(t),{children:l,orientation:i}=a,o=Et(a,Ct),s=jt(t),c=gt({display:"flex",flexDirection:"column"},n.container);return e.createElement(P,{value:n},/*#__PURE__*/e.createElement(xt,{value:s},/*#__PURE__*/e.createElement(V.div,gt({ref:r,__css:c},o,{className:_t("saas-stepper__container",t.className)}),/*#__PURE__*/e.createElement(Vt,{orientation:i},l))))});yt&&(It.displayName="Stepper");const Vt=t=>{var r,n;const{children:a,orientation:l,stepComponent:i}=t,o=Et(t,Ot),s=R(),{activeIndex:c}=St(),u=gt({display:"flex",flexDirection:"row",alignItems:"center"},s.steps),p="vertical"===l,m=i||Dt,d=W(a,m),f=d.reduce((t,r,n,a)=>(t.push(/*#__PURE__*/e.createElement(m,gt({key:n},r.props,{icon:r.props.icon||n+1,isActive:c===n,isCompleted:r.props.isCompleted||c>n}))),"vertical"===l&&t.push(/*#__PURE__*/e.createElement(zt,{isOpen:c===n},r.props.children)),n<a.length-1&&t.push(/*#__PURE__*/e.createElement(Pt,{key:`separator-${n}`,isActive:n<c})),t),[]),h=H(a,Ut),v=c>=d.length?h:p?null:null==(r=d[c])||null==(n=r.props)?void 0:n.children;return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(V.div,gt({__css:u},o,{className:_t("saas-stepper__steps",t.className)}),f),v&&/*#__PURE__*/e.createElement(zt,null,v))};yt&&(Vt.displayName="StepperSteps");const zt=t=>{const{children:r,isOpen:n=!0}=t,a=Et(t,wt),l=R();return e.createElement(V.div,gt({__css:l.content},a,{className:_t("saas-stepper__content",t.className)}),/*#__PURE__*/e.createElement(j,{in:n},r))};yt&&(zt.displayName="StepperContent");const Lt=t=>{const{icon:r,isCompleted:n,className:a}=t,l=Et(t,At),i=gt({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},R().icon);let o;return o=n?/*#__PURE__*/e.createElement($,{as:B}):r,/*#__PURE__*/e.createElement(V.div,gt({__css:i},l,{className:_t("saas-stepper__icon",a)}),o)};yt&&(Lt.displayName="StepperIcon");const Dt=t=>{const{title:r,icon:n,isActive:a,isCompleted:l}=t,i=Et(t,kt),o=Nt(t),s=gt({display:"flex",alignItems:"center",flexDirection:"row"},R().step);return e.createElement(V.div,gt({__css:s,"data-active":o.isActive,"data-completed":o.isCompleted},i,{className:_t("saas-stepper__step",t.className)}),/*#__PURE__*/e.createElement(Lt,{icon:n,isActive:a,isCompleted:l}),r&&/*#__PURE__*/e.createElement(Rt,null,r))};yt&&(Dt.displayName="StepperStep");const Pt=t=>{const{isActive:r}=t,n=Et(t,Ft),a=gt({flex:1,borderTopWidth:"1px",mx:2},R().separator);return e.createElement(V.div,gt({"data-active":r},n,{className:_t("saas-stepper__separator",t.className),__css:a}))};yt&&(Pt.displayName="StepperSeparator");const Rt=t=>{const r=R();return e.createElement(V.p,gt({},t,{__css:r.title,className:_t("saas-stepper__title",t.className)}))};yt&&(Rt.displayName="StepperStepTitle");const Ut=t=>{const r=R();return e.createElement(V.div,gt({__css:r.completed},t,{className:_t("saas-stepper__completed",t.className)}))};yt&&(Ut.displayName="StepperCompleted");const[Mt,$t]=G({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function Bt(t){const r=jt(t),{activeStep:n,isLastStep:a,nextStep:l}=r,[i,o]=e.useState({}),s=e.useCallback(async e=>{if(a)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{u(J({},i[n],{isCompleted:!0}))}).then(l);l()},[n,a]),c=e.useCallback(e=>{const t=i[n];return{onSubmit:s,schema:null==t?void 0:t.schema}},[i,s,n]),u=e.useCallback(e=>{o(t=>J({},t,{[e.name]:e}))},[i]);return J({getFormProps:c,updateStep:u,steps:i},r)}function Tt(t){const{name:r,schema:n}=t,a=Nt({name:r}),{steps:l,updateStep:i}=$t();return e.useEffect(()=>{i({name:r,schema:n})},[r,n]),J({},a,l[r]||{})}const qt=["children","onSubmit"],Gt=["getFormProps"],Wt=["name","schema","children","className"],Ht=["label","submitLabel"],Jt=e.forwardRef((t,r)=>{const{children:n}=t,a=K(t,qt),l=Bt(t),{getFormProps:i}=l,o=K(l,Gt),s=e.useMemo(()=>o,[o]);/*#__PURE__*/return e.createElement(xt,{value:s},/*#__PURE__*/e.createElement(Mt,{value:s},/*#__PURE__*/e.createElement(lt,J({ref:r},a,i(t)),function(e){for(var t=arguments.length,r=new Array(t>1?t-1:0),n=1;n<t;n++)r[n-1]=arguments[n];return ft(e)?e.apply(void 0,r):e}(n,l))))}),Kt=t=>{const r=L("Stepper",t),{children:n}=t,a=e.Children.map(n,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===Qt){const{isCompleted:r}=Tt(t.props);/*#__PURE__*/return e.createElement(Dt,{name:t.props.name,title:t.props.title,isCompleted:r},t.props.children)}return t});/*#__PURE__*/return e.createElement(P,{value:r},/*#__PURE__*/e.createElement(Vt,J({mb:"4"},t),a))},Qt=t=>{const{name:r,schema:n,children:a,className:l}=t,i=K(t,Wt),o=Tt({name:r,schema:n}),{isActive:s}=o;return s?/*#__PURE__*/e.createElement(V.div,J({},i,{className:vt("saas-form__step",l)}),a):null};ht&&(Qt.displayName="FormStep");const Xt=t=>{const{isFirstStep:r,isCompleted:n,prevStep:a}=St();/*#__PURE__*/return e.createElement(q,J({isDisabled:r||n,label:"Back"},t,{className:vt("saas-form__prev-button",t.className),onClick:bt(t.onClick,a)}))};ht&&(Xt.displayName="PrevButton");const Yt=t=>{const{label:r="Next",submitLabel:n="Complete"}=t,a=K(t,Ht),{isLastStep:l,isCompleted:i}=St();/*#__PURE__*/return e.createElement(ot,J({isDisabled:i,label:l||i?n:r},a,{className:vt("saas-form__next-button",t.className)}))};ht&&(Yt.displayName="NextButton");export{He as ArrayField,We as ArrayFieldAddButton,Ke as ArrayFieldContainer,Fe as ArrayFieldProvider,Ge as ArrayFieldRemoveButton,Be as ArrayFieldRow,qe as ArrayFieldRowContainer,Te as ArrayFieldRowFields,Ve as ArrayFieldRowProvider,Je as ArrayFieldRows,ct as AutoForm,ce as BaseField,ge as CheckboxField,X as DisplayField,ut as DisplayIf,ue as Field,nt as Fields,lt as Form,Ae as FormLayout,Xe as FormLegend,Qt as FormStep,Kt as FormStepper,Y as FormValue,fe as InputField,Se as NativeSelectField,Yt as NextButton,he as NumberInputField,Ye as ObjectField,ve as PasswordInputFIeld,xe as PinField,Xt as PrevButton,Ee as RadioField,_e as SelectField,Jt as StepForm,Mt as StepFormProvider,ot as SubmitButton,ye as SwitchField,be as TextareaField,de as registerFieldType,Le as useArrayField,Re as useArrayFieldAddButton,Ie as useArrayFieldContext,Pe as useArrayFieldRemoveButton,De as useArrayFieldRow,ze as useArrayFieldRowContext,Tt as useFormStep,Bt as useStepForm,$t as useStepFormContext,pe as withControlledInput,me as withUncontrolledInput};
1
+ import*as e from"react";import{useFormContext as t,get as r,Controller as n,useFieldArray as a,useForm as l,FormProvider as s,useWatch as i}from"react-hook-form";import{FormControl as o,FormLabel as c,Text as m,forwardRef as u,Switch as d,Checkbox as p,Box as f,FormHelperText as h,FormErrorMessage as v,useMergeRefs as E,Input as b,Textarea as y,useTheme as S,SimpleGrid as g,chakra as x,useStyles as N,Collapse as C}from"@chakra-ui/react";import{NumberInput as _}from"@saas-ui/number-input";import{PasswordInput as k}from"@saas-ui/password-input";import{RadioInput as F}from"@saas-ui/radio";import{PinInput as I}from"@saas-ui/pin-input";import{Select as V,NativeSelect as R}from"@saas-ui/select";import{chakra as L,forwardRef as w,useMultiStyleConfig as O,omitThemingProps as A,StylesProvider as D,useStyles as j}from"@chakra-ui/system";import{MinusIcon as M,AddIcon as U,Icon as P,CheckIcon as $}from"@chakra-ui/icons";import{IconButton as B,Button as q}from"@saas-ui/button";import{createContext as z}from"@chakra-ui/react-utils";import{get as G,cx as H,__DEV__ as T,runIfFn as W,callAllHandlers as J}from"@chakra-ui/utils";import{getChildrenOfType as K,getChildOfType as Q}from"@saas-ui/react-utils";export*from"@saas-ui/input-right-button";function X(){return X=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},X.apply(this,arguments)}function Y(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}const Z=["name","label","placeholder"],ee=t=>{let{name:r,label:n}=t,a=Y(t,Z);/*#__PURE__*/return e.createElement(o,a,n?/*#__PURE__*/e.createElement(c,{htmlFor:r},n):null,/*#__PURE__*/e.createElement(m,{fontSize:"md"},/*#__PURE__*/e.createElement(te,{name:r})))},te=({name:e})=>{const{getValues:r}=t();return r(e)||null},re=["name","label","help","variant","hideLabel","children"],ne=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],ae=["name","rules"],le=["ref"],se=["name","rules"],ie=["ref"],oe=["label"],ce=["label"],me={},ue="text",de=n=>{const{name:a,label:l,help:s,variant:i,hideLabel:m,children:u}=n,d=Y(n,re),{formState:p}=t(),E=((e,t)=>r(t.errors,e))(a,p);/*#__PURE__*/return e.createElement(o,X({variant:i},d,{isInvalid:!!E}),l&&!m?/*#__PURE__*/e.createElement(c,{variant:i},l):null,/*#__PURE__*/e.createElement(f,null,u,!s||null!=E&&E.message?null:/*#__PURE__*/e.createElement(h,null,s),(null==E?void 0:E.message)&&/*#__PURE__*/e.createElement(v,null,null==E?void 0:E.message)))},pe=u((t,r)=>{const{type:n=ue}=t,a=(e=>me[e]||me[ue])(n);/*#__PURE__*/return e.createElement(a,X({ref:r},t))}),fe=r=>u((a,l)=>{let{name:s,rules:i}=a,o=Y(a,ae);const{control:c}=t();/*#__PURE__*/return e.createElement(n,{name:s,control:c,rules:i,render:t=>{let{field:{ref:n}}=t,a=Y(t.field,le);/*#__PURE__*/return e.createElement(r,X({},a,o,{ref:E(l,n)}))}})}),he=r=>u((n,a)=>{let{name:l,rules:s}=n,i=Y(n,se);const{register:o}=t(),c=o(l,s),{ref:m}=c,u=Y(c,ie);/*#__PURE__*/return e.createElement(r,X({},u,i,{ref:E(a,m)}))}),ve=(t,r,n)=>{let a;a=null!=n&&n.isControlled?fe(r):he(r);const l=((t,{displayName:r,hideLabel:n,BaseField:a})=>{const l=u((r,l)=>{const{name:s,label:i,help:o,isDisabled:c,isInvalid:m,isReadOnly:u,isRequired:d,rules:p,variant:f}=r,h=Y(r,ne),v=X({required:d},p);/*#__PURE__*/return e.createElement(a,{name:s,label:i,help:o,hideLabel:n,isDisabled:c,isInvalid:m,isReadOnly:u,isRequired:d,variant:f},/*#__PURE__*/e.createElement(t,X({ref:l,name:s,label:i,rules:v},h)))});return l.displayName=r,l})(a,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||de});return me[t]=l,l},Ee=ve("text",b),be=ve("number",_,{isControlled:!0}),ye=ve("password",k),Se=ve("textarea",y),ge=ve("switch",u((t,r)=>{let{label:n}=t,a=Y(t,oe);/*#__PURE__*/return e.createElement(d,X({ref:r},a),n)}),{isControlled:!0,hideLabel:!0}),xe=ve("select",V,{isControlled:!0}),Ne=ve("checkbox",u((t,r)=>{let{label:n}=t,a=Y(t,ce);/*#__PURE__*/return e.createElement(p,X({ref:r},a),n)}),{hideLabel:!0}),Ce=ve("radio",F,{isControlled:!0}),_e=ve("pin",I,{isControlled:!0}),ke=ve("native-select",R,{isControlled:!0}),Fe=["children"],Ie=({children:t})=>/*#__PURE__*/e.createElement(x.div,null,t),Ve=t=>{var r,n,a;let{children:l}=t,s=Y(t,Fe);const i=X({},null!=(r=null==(n=S().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?r:{spacing:4},s);/*#__PURE__*/return e.createElement(g,i,e.Children.map(l,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(Ie,null,t):t))},Re=(t,r)=>e.Children.map(r,r=>e.isValidElement(r)&&r.props.name?e.cloneElement(r,X({},r.props,{name:`${t}.${r.props.name}`})):r),[Le,we]=z({name:"ArrayFieldContext"}),[Oe,Ae]=z({name:"ArrayFieldRowContext"}),De=({name:e,defaultValue:r={},keyName:n,min:l,max:s})=>{const{control:i}=t();return X({},a({control:i,name:e,keyName:n}),{name:e,defaultValue:r,min:l,max:s})},je=({index:r})=>{const{clearErrors:n}=t(),{name:a,remove:l,fields:s}=we();return e.useEffect(()=>{n(a)},[]),{index:r,isFirst:0===r,isLast:r===s.length-1,name:`${a}.${r}`,remove:e.useCallback(()=>{n(a),l(r)},[r])}},Me=()=>{const{isFirst:e,remove:t}=Ae(),{min:r,fields:n}=we();return{onClick:()=>t(),isDisabled:e&&!!(r&&n.length<=r)}},Ue=()=>{const{append:e,defaultValue:t,max:r,fields:n}=we();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(r&&n.length>=r)}},Pe=["children","columns","spacing"],$e=["children"],Be=["name","defaultValue","keyName","min","max","children"],qe=({children:t,columns:r,spacing:n,index:a})=>/*#__PURE__*/e.createElement(Ge,{index:a},/*#__PURE__*/e.createElement(ze,{columns:r,spacing:n},t),/*#__PURE__*/e.createElement(He,null)),ze=t=>{let{children:r,columns:n,spacing:a}=t,l=Y(t,Pe);const{name:s}=Ae();/*#__PURE__*/return e.createElement(Ve,X({flex:"1",columns:n,gridGap:a,mr:"2"},l),Re(s,r))},Ge=({children:t,index:r})=>{const n=je({index:r});/*#__PURE__*/return e.createElement(Oe,{value:n},/*#__PURE__*/e.createElement(L.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},t))},He=t=>/*#__PURE__*/e.createElement(B,X({icon:/*#__PURE__*/e.createElement(M,null),"aria-label":"Remove row"},Me(),t)),Te=t=>/*#__PURE__*/e.createElement(B,X({icon:/*#__PURE__*/e.createElement(U,null),"aria-label":"Add row",float:"right"},Ue(),t)),We=e.forwardRef((t,r)=>{const{children:n}=t,a=Y(t,$e);/*#__PURE__*/return e.createElement(Ke,X({ref:r},a),/*#__PURE__*/e.createElement(Je,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},r)=>/*#__PURE__*/e.createElement(qe,{key:t,index:r},n)))),/*#__PURE__*/e.createElement(Te,null))}),Je=({children:e})=>{const{fields:t}=we();return e(t)},Ke=e.forwardRef((t,r)=>{let{name:n,defaultValue:a,keyName:l,min:s,max:i,children:o}=t,c=Y(t,Be);const m=De({name:n,defaultValue:a,keyName:l,min:s,max:i});return e.useImperativeHandle(r,()=>m,[r,m]),/*#__PURE__*/e.createElement(Le,{value:m},/*#__PURE__*/e.createElement(de,X({name:n},c),o))}),Qe=["name","label","hideLabel","children","columns","spacing"],Xe=t=>{const r=N();/*#__PURE__*/return e.createElement(c,X({as:"legend",sx:r.legend},t))},Ye=t=>{const{name:r,label:n,hideLabel:a,children:l,columns:s,spacing:i}=t,c=Y(t,Qe);/*#__PURE__*/return e.createElement(o,X({name:r,as:"fieldset"},c),/*#__PURE__*/e.createElement(Xe,{display:a?"none":"block"},n),/*#__PURE__*/e.createElement(Ve,{columns:s,gridGap:i},Re(r,l)))},Ze=e=>Object.entries(e).map(([e,t])=>X({name:e},t)),et=e=>({getFields:()=>Ze(e),getNestedFields:t=>{var r;const n=G(e,t);return n?"object"===(null==(r=n.items)?void 0:r.type)?Ze(n.items.properties):"object"===n.type?Ze(n.properties):[n.items]:[]}}),tt=["name","type"],rt=["schema","fieldResolver"],nt=["name","type","defaultValue"],at=(t,r)=>{var n;return null==(n=t.getNestedFields(r))?void 0:n.map((t,r)=>{let{name:n,type:a}=t,l=Y(t,tt);/*#__PURE__*/return e.createElement(pe,X({key:n||r,name:n,type:a},l))})},lt=t=>{let{schema:r,fieldResolver:n}=t,a=Y(t,rt);const l=e.useMemo(()=>n||et(r),[r,n]);/*#__PURE__*/return e.createElement(Ve,a,l.getFields().map(t=>{let{name:r,type:n}=t,a=Y(t,nt);return"array"===n?/*#__PURE__*/e.createElement(We,X({key:r,name:r},a),at(l,r)):"object"===n?/*#__PURE__*/e.createElement(Ye,X({key:r,name:r},a),at(l,r)):/*#__PURE__*/e.createElement(pe,X({key:r,name:r,type:n},a))}))},st=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],it=u((t,r)=>{const{mode:n="all",resolver:a,reValidateMode:i,shouldFocusError:o,shouldUnregister:c,shouldUseNativeValidation:m,criteriaMode:u,delayError:d,defaultValues:p,onSubmit:f,onError:h,formRef:v,children:E}=t,b=Y(t,st),y=l({mode:n,resolver:a,defaultValues:p,reValidateMode:i,shouldFocusError:o,shouldUnregister:c,shouldUseNativeValidation:m,criteriaMode:u,delayError:d}),{handleSubmit:S}=y;return e.useImperativeHandle(r,()=>y,[r,y]),/*#__PURE__*/e.createElement(s,y,/*#__PURE__*/e.createElement(x.form,X({ref:v,onSubmit:S(f,h)},b),E))}),ot=["children","disableIfUntouched","disableIfInvalid"],ct=w((r,n)=>{const{children:a,disableIfUntouched:l,disableIfInvalid:s}=r,i=Y(r,ot),{formState:o}=t();/*#__PURE__*/return e.createElement(q,X({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:n,isDisabled:l&&!o.isDirty||s&&!o.isValid},i),a)});ct.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};const mt=["schema","submitLabel","fieldResolver"],ut=u((t,r)=>{const{schema:n,submitLabel:a="Submit",fieldResolver:l}=t,s=Y(t,mt);/*#__PURE__*/return e.createElement(it,X({},s,{ref:r}),/*#__PURE__*/e.createElement(Ve,null,/*#__PURE__*/e.createElement(lt,{schema:n,fieldResolver:l}),a&&/*#__PURE__*/e.createElement(ct,{label:a})))}),dt=({children:e,name:r,defaultValue:n,isDisabled:a,isExact:l,condition:s=(e=>!!e)})=>s(i({name:r,defaultValue:n,disabled:a,exact:l}),t())?e:null;function pt(){return pt=Object.assign||function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},pt.apply(this,arguments)}function ft(e,t){if(null==e)return{};var r,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)t.indexOf(r=l[n])>=0||(a[r]=e[r]);return a}const[ht,vt]=z({name:"StepperContext",errorMessage:"useStepperContext: `context` is undefined. Seems you forgot to wrap stepper components in `<Stepper />`"});function Et(t){const{step:r}=t,[n,a]=e.useState(-1),l=e.useRef([]),[,s]=e.useState(Date.now()),i=e.useCallback(e=>{const t=[...l.current];-1===t.indexOf(e)&&t.push(e),l.current=t,s(Date.now())},[l,s]),o=e=>{const t=l.current.indexOf(e);-1!==t&&a(t)};return e.useLayoutEffect(()=>{"string"==typeof r?o(r):"number"==typeof r?a(r):-1===n&&a(0)},[r]),{stepsRef:l,activeStep:l.current[n],activeIndex:n,isFirstStep:0===n,isLastStep:n===l.current.length-1,isCompleted:n>=l.current.length,setIndex:a,setStep:o,nextStep:()=>{a(n+1)},prevStep:()=>{a(n-1)},registerStep:i,unregisterStep:e=>{l.current=l.current.slice(l.current.indexOf(e),1)}}}function bt(t){const{name:r,isActive:n,isCompleted:a}=t,{registerStep:l,unregisterStep:s,activeStep:i}=vt();return e.useEffect(()=>{if(r)return l(r),()=>{s(r)}},[]),{isActive:r?i===r:n,isCompleted:a}}const yt=["children","orientation"],St=["children","orientation","stepComponent"],gt=["children","isOpen"],xt=["icon","isActive","isCompleted","className"],Nt=["title","icon","isActive","isCompleted"],Ct=["isActive"],_t=w((t,r)=>{const n=O("Stepper",t),a=A(t),{children:l,orientation:s}=a,i=ft(a,yt),o=Et(t),c=pt({display:"flex",flexDirection:"column"},n.container);return e.createElement(D,{value:n},/*#__PURE__*/e.createElement(ht,{value:o},/*#__PURE__*/e.createElement(L.div,pt({ref:r,__css:c},i,{className:H("saas-stepper__container",t.className)}),/*#__PURE__*/e.createElement(kt,{orientation:s},l))))});T&&(_t.displayName="Stepper");const kt=t=>{var r,n;const{children:a,orientation:l,stepComponent:s}=t,i=ft(t,St),o=j(),{activeIndex:c}=vt(),m=pt({display:"flex",flexDirection:"row",alignItems:"center"},o.steps),u="vertical"===l,d=s||Vt,p=K(a,d),f=p.reduce((t,r,n,a)=>(t.push(/*#__PURE__*/e.createElement(d,pt({key:n},r.props,{icon:r.props.icon||n+1,isActive:c===n,isCompleted:r.props.isCompleted||c>n}))),"vertical"===l&&t.push(/*#__PURE__*/e.createElement(Ft,{key:`content-${n}`,isOpen:c===n},r.props.children)),n<a.length-1&&t.push(/*#__PURE__*/e.createElement(Rt,{key:`separator-${n}`,isActive:n<c})),t),[]),h=Q(a,wt),v=c>=p.length?h:u?null:/*#__PURE__*/e.createElement(Ft,null,null==(r=p[c])||null==(n=r.props)?void 0:n.children);return e.createElement(e.Fragment,null,/*#__PURE__*/e.createElement(L.div,pt({__css:m},i,{className:H("saas-stepper__steps",t.className)}),f),v)};T&&(kt.displayName="StepperSteps");const Ft=t=>{const{children:r,isOpen:n=!0}=t,a=ft(t,gt),l=j();return e.createElement(L.div,pt({__css:l.content},a,{className:H("saas-stepper__content",t.className)}),/*#__PURE__*/e.createElement(C,{in:n},r))};T&&(Ft.displayName="StepperContent");const It=t=>{const{icon:r,isCompleted:n,className:a}=t,l=ft(t,xt),s=pt({display:"flex",alignItems:"center",justifyContent:"center",borderRadius:"full",fontSize:"1em",me:2},j().icon);let i;return i=n?/*#__PURE__*/e.createElement(P,{as:$}):r,/*#__PURE__*/e.createElement(L.div,pt({__css:s},l,{className:H("saas-stepper__icon",a)}),i)};T&&(It.displayName="StepperIcon");const Vt=t=>{const{title:r,icon:n,isActive:a,isCompleted:l}=t,s=ft(t,Nt),i=bt(t),o=pt({display:"flex",alignItems:"center",flexDirection:"row"},j().step);return e.createElement(L.div,pt({__css:o,"data-active":i.isActive,"data-completed":i.isCompleted},s,{className:H("saas-stepper__step",t.className)}),/*#__PURE__*/e.createElement(It,{icon:n,isActive:a,isCompleted:l}),r&&/*#__PURE__*/e.createElement(Lt,null,r))};T&&(Vt.displayName="StepperStep");const Rt=t=>{const{isActive:r}=t,n=ft(t,Ct),a=pt({flex:1,borderTopWidth:"1px",mx:2},j().separator);return e.createElement(L.div,pt({"data-active":r},n,{className:H("saas-stepper__separator",t.className),__css:a}))};T&&(Rt.displayName="StepperSeparator");const Lt=t=>{const r=j();return e.createElement(L.p,pt({},t,{__css:r.title,className:H("saas-stepper__title",t.className)}))};T&&(Lt.displayName="StepperStepTitle");const wt=t=>{const r=j();return e.createElement(L.div,pt({__css:r.completed},t,{className:H("saas-stepper__completed",t.className)}))};T&&(wt.displayName="StepperCompleted");const[Ot,At]=z({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"});function Dt(t){const r=Et(t),{activeStep:n,isLastStep:a,nextStep:l}=r,[s,i]=e.useState({}),o=e.useCallback(async e=>{if(a)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{m(X({},s[n],{isCompleted:!0}))}).then(l);l()},[n,a]),c=e.useCallback(e=>{const t=s[n];return{onSubmit:o,schema:null==t?void 0:t.schema,resolver:null==t?void 0:t.resolver}},[s,o,n]),m=e.useCallback(e=>{i(t=>X({},t,{[e.name]:e}))},[s]);return X({getFormProps:c,updateStep:m,steps:s},r)}function jt(t){const{name:r,schema:n,resolver:a}=t,l=bt({name:r}),{steps:s,updateStep:i}=At();return e.useEffect(()=>{i({name:r,schema:n,resolver:a})},[r,n]),X({},l,s[r]||{name:r,schema:n})}const Mt=["children","onSubmit"],Ut=["getFormProps"],Pt=["name","schema","resolver","children","className"],$t=["label","submitLabel"],Bt=e.forwardRef((t,r)=>{const{children:n}=t,a=Y(t,Mt),l=Dt(t),{getFormProps:s}=l,i=Y(l,Ut),o=e.useMemo(()=>i,[i]);/*#__PURE__*/return e.createElement(ht,{value:o},/*#__PURE__*/e.createElement(Ot,{value:o},/*#__PURE__*/e.createElement(it,X({ref:r},a,s(t)),W(n,l))))}),qt=t=>{const r=O("Stepper",t),{children:n}=t,a=e.Children.map(n,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===zt){const{isCompleted:r}=jt(t.props);/*#__PURE__*/return e.createElement(Vt,{name:t.props.name,title:t.props.title,isCompleted:r},t.props.children)}return t});/*#__PURE__*/return e.createElement(D,{value:r},/*#__PURE__*/e.createElement(kt,X({mb:"4"},t),a))},zt=t=>{const{name:r,schema:n,resolver:a,children:l,className:s}=t,i=Y(t,Pt),o=jt({name:r,schema:n,resolver:a}),{isActive:c}=o;return c?/*#__PURE__*/e.createElement(L.div,X({},i,{className:H("saas-form__step",s)}),l):null};T&&(zt.displayName="FormStep");const Gt=t=>{const{isFirstStep:r,isCompleted:n,prevStep:a}=vt();/*#__PURE__*/return e.createElement(q,X({isDisabled:r||n,label:"Back"},t,{className:H("saas-form__prev-button",t.className),onClick:J(t.onClick,a)}))};T&&(Gt.displayName="PrevButton");const Ht=t=>{const{label:r="Next",submitLabel:n="Complete"}=t,a=Y(t,$t),{isLastStep:l,isCompleted:s}=vt();/*#__PURE__*/return e.createElement(ct,X({isDisabled:s,label:l||s?n:r},a,{className:H("saas-form__next-button",t.className)}))};T&&(Ht.displayName="NextButton");export{We as ArrayField,Te as ArrayFieldAddButton,Ke as ArrayFieldContainer,Le as ArrayFieldProvider,He as ArrayFieldRemoveButton,qe as ArrayFieldRow,Ge as ArrayFieldRowContainer,ze as ArrayFieldRowFields,Oe as ArrayFieldRowProvider,Je as ArrayFieldRows,ut as AutoForm,de as BaseField,Ne as CheckboxField,ee as DisplayField,dt as DisplayIf,pe as Field,lt as Fields,it as Form,Ve as FormLayout,Xe as FormLegend,zt as FormStep,qt as FormStepper,te as FormValue,Ee as InputField,ke as NativeSelectField,Ht as NextButton,be as NumberInputField,Ye as ObjectField,ye as PasswordInputFIeld,_e as PinField,Gt as PrevButton,Ce as RadioField,xe as SelectField,Bt as StepForm,Ot as StepFormProvider,ct as SubmitButton,ge as SwitchField,Se as TextareaField,et as defaultFieldResolver,ve as registerFieldType,De as useArrayField,Ue as useArrayFieldAddButton,we as useArrayFieldContext,Me as useArrayFieldRemoveButton,je as useArrayFieldRow,Ae as useArrayFieldRowContext,jt as useFormStep,Dt as useStepForm,At as useStepFormContext,fe as withControlledInput,he as withUncontrolledInput};
2
2
  //# sourceMappingURL=index.modern.js.map