@saas-ui/forms 1.0.0-rc.10 → 1.0.0-rc.11
Sign up to get free protection for your applications and to get access to all the features.
- package/CHANGELOG.md +16 -0
- package/dist/ajv/index.js +103 -96
- package/dist/ajv/index.js.map +1 -1
- package/dist/ajv/index.modern.mjs +101 -94
- package/dist/ajv/index.modern.mjs.map +1 -1
- package/dist/field.d.ts +1 -1
- package/dist/field.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.modern.mjs +1 -1
- package/dist/index.modern.mjs.map +1 -1
- package/dist/step-form.d.ts.map +1 -1
- package/dist/submit-button.d.ts +2 -1
- package/dist/submit-button.d.ts.map +1 -1
- package/dist/zod/index.js.map +1 -1
- package/dist/zod/index.modern.mjs.map +1 -1
- package/dist/zod/zod-resolver.d.ts +2 -2
- package/dist/zod/zod-resolver.d.ts.map +1 -1
- package/package.json +10 -10
- package/src/auto-form.tsx +2 -2
- package/src/field.tsx +1 -5
- package/src/step-form.tsx +4 -3
- package/src/submit-button.tsx +32 -24
package/dist/field.d.ts
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
import * as React from 'react';
|
2
2
|
import { RegisterOptions, FieldValues, FieldPath } from 'react-hook-form';
|
3
3
|
import { FormControlProps, InputProps, TextareaProps, SwitchProps, CheckboxProps, UsePinInputProps, SystemProps } from '@chakra-ui/react';
|
4
|
+
import { FocusableElement } from '@chakra-ui/utils';
|
4
5
|
import { NumberInputProps } from '@saas-ui/number-input';
|
5
6
|
import { PasswordInputProps } from '@saas-ui/password-input';
|
6
7
|
import { RadioInputProps } from '@saas-ui/radio';
|
7
8
|
import { SelectProps, NativeSelectProps } from '@saas-ui/select';
|
8
|
-
import { FocusableElement } from '@chakra-ui/utils';
|
9
9
|
export interface Option {
|
10
10
|
value: string;
|
11
11
|
label?: string;
|
package/dist/field.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.tsx"],"names":[],"mappings":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Ac,GACf;KACG,QAAQ,IAAI,MAAM,UAAU,GAAG,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC,EAAE,QAAQ,CAAC;CAC1E,CAAC,MAAM,UAAU,CAAC,GACnB;IAAE,IAAI,CAAC,EAAE,MAAM,CAAA;CAAE,CAAA"}
|
package/dist/index.js
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
var e=require("react"),r=require("@chakra-ui/utils"),t=require("react-hook-form"),n=require("@chakra-ui/react"),a=require("@saas-ui/number-input"),l=require("@saas-ui/password-input"),i=require("@saas-ui/radio"),o=require("@saas-ui/select"),s=require("@chakra-ui/system"),u=require("@chakra-ui/icons"),d=require("@saas-ui/button"),c=require("@chakra-ui/react-utils"),m=require("@saas-ui/stepper"),p=require("@saas-ui/input-right-button");function f(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var v=/*#__PURE__*/f(e);function h(){return h=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},h.apply(this,arguments)}function x(e,r){if(null==e)return{};var t,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)r.indexOf(t=l[n])>=0||(a[t]=e[t]);return a}var y=["name","label","placeholder"],b=function(e){var r=e.name,t=e.label,a=x(e,y);/*#__PURE__*/return v.createElement(n.FormControl,a,t?/*#__PURE__*/v.createElement(n.FormLabel,{htmlFor:r},t):null,/*#__PURE__*/v.createElement(n.Text,{fontSize:"md"},/*#__PURE__*/v.createElement(F,{name:r})))};r.__DEV__&&(b.displayName="DisplayField");var F=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null};r.__DEV__&&(F.displayName="FormValue");var E=["name","label","help","variant","hideLabel","children"],_=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","isOptional","rules","variant"],S=["name","rules"],C=["ref"],g=["name","rules"],N=["ref"],R=["type","leftAddon","rightAddon","size"],V=["type"],w=["label","type"],A=["pinLength","pinType","spacing"],k={},D=function(e){var r=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=x(e,E),d=function(e,r){return t.get(r.errors,e)}(r,t.useFormContext().formState);/*#__PURE__*/return v.createElement(n.FormControl,h({variant:i},u,{isInvalid:!!d}),a&&!o?/*#__PURE__*/v.createElement(n.FormLabel,{variant:i},a):null,/*#__PURE__*/v.createElement(n.Box,null,s,!l||null!=d&&d.message?null:/*#__PURE__*/v.createElement(n.FormHelperText,null,l),(null==d?void 0:d.message)&&/*#__PURE__*/v.createElement(n.FormErrorMessage,null,null==d?void 0:d.message)))};r.__DEV__&&(D.displayName="BaseField");var I=v.forwardRef(function(e,r){var t=e.type;/*#__PURE__*/return v.createElement(k[void 0===t?"text":t]||k.text,h({ref:r},e))}),L=function(e){return n.forwardRef(function(r,a){var l=r.name,i=r.rules,o=x(r,S),s=t.useFormContext();/*#__PURE__*/return v.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(r){var t=r.field,l=t.ref,i=x(t,C);/*#__PURE__*/return v.createElement(e,h({},i,o,{ref:n.useMergeRefs(a,l)}))}})})},P=function(e){return n.forwardRef(function(r,a){var l=r.name,i=r.rules,o=x(r,g),s=(0,t.useFormContext().register)(l,i),u=s.ref,d=x(s,N);/*#__PURE__*/return v.createElement(e,h({},d,o,{ref:n.useMergeRefs(a,u)}))})},B=function(e,r,t){var a=function(e,r){var t=r.displayName,a=r.hideLabel,l=r.BaseField,i=n.forwardRef(function(r,t){var n=r.id,i=r.name,o=r.label,s=r.help,u=r.isDisabled,d=r.isInvalid,c=r.isReadOnly,m=r.isRequired,p=r.isOptional,f=r.rules,y=r.variant,b=x(r,_),F=h({required:m},f);/*#__PURE__*/return v.createElement(l,{id:n,name:i,label:o,help:s,hideLabel:a,isDisabled:u,isInvalid:d,isReadOnly:c,isRequired:m,isOptional:p,variant:y},/*#__PURE__*/v.createElement(e,h({ref:t,id:n,name:i,label:a?o:void 0,rules:F},b)))});return i.displayName=t,i}(null!=t&&t.isControlled?L(r):P(r),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==t?void 0:t.hideLabel,BaseField:(null==t?void 0:t.BaseField)||D});return k[e]=a,a},O=B("text",n.forwardRef(function(e,r){var t=e.type,a=void 0===t?"text":t,l=e.leftAddon,i=e.rightAddon,o=e.size,s=x(e,R),u=/*#__PURE__*/v.createElement(n.Input,h({type:a,size:o},s,{ref:r}));return l||i?/*#__PURE__*/v.createElement(n.InputGroup,{size:o},l,u,i):u})),j=B("number",a.NumberInput,{isControlled:!0}),q=B("password",n.forwardRef(function(e,r){/*#__PURE__*/return v.createElement(l.PasswordInput,h({ref:r},e))})),M=B("textarea",n.Textarea),U=B("switch",n.forwardRef(function(e,r){var t=x(e,V);/*#__PURE__*/return v.createElement(n.Switch,h({},t,{ref:r}))}),{isControlled:!0}),T=B("select",o.Select,{isControlled:!0}),z=B("checkbox",n.forwardRef(function(e,r){var t=e.label,a=x(e,w);/*#__PURE__*/return v.createElement(n.Checkbox,h({ref:r},a),t)}),{hideLabel:!0}),H=B("radio",i.RadioInput,{isControlled:!0}),G=B("native-select",o.NativeSelect,{isControlled:!0}),W=B("pin",n.forwardRef(function(e,r){for(var t=e.pinLength,a=void 0===t?4:t,l=e.pinType,i=e.spacing,o=x(e,A),s=[],u=0;u<a;u++)s.push(/*#__PURE__*/v.createElement(n.PinInputField,{key:u,ref:r}));/*#__PURE__*/return v.createElement(n.HStack,{spacing:i},/*#__PURE__*/v.createElement(n.PinInput,h({},o,{type:l}),s))}),{isControlled:!0}),J=["items"],K=function(e){return e&&Object.entries(e).map(function(e){var r=e[0];return h({},x(e[1],J),{name:r})})},Q=function(e){return{getFields:function(){return K(e)},getNestedFields:function(t){var n,a=r.get(e,t);return a?"object"===(null==(n=a.items)?void 0:n.type)?K(a.items.properties):"object"===a.type?K(a.properties):[a.items]:[]}}},X=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Y=n.forwardRef(function(e,a){var l=e.mode,i=void 0===l?"all":l,o=e.resolver,s=e.reValidateMode,u=e.shouldFocusError,d=e.shouldUnregister,c=e.shouldUseNativeValidation,m=e.criteriaMode,p=e.delayError,f=e.schema,y=e.defaultValues,b=e.onSubmit,F=e.onError,E=e.formRef,_=e.children,S=x(e,X),C={mode:i,resolver:o,defaultValues:y,reValidateMode:s,shouldFocusError:u,shouldUnregister:d,shouldUseNativeValidation:c,criteriaMode:m,delayError:p};f&&!o&&(C.resolver=null==Y.getResolver?void 0:Y.getResolver(f));var g=t.useForm(C),N=g.handleSubmit;return v.useImperativeHandle(a,function(){return g},[a,g]),/*#__PURE__*/v.createElement(t.FormProvider,g,/*#__PURE__*/v.createElement(n.chakra.form,h({ref:E,onSubmit:N(b,F)},S,{className:r.cx("saas-form",e.className)}),_))});Y.getFieldResolver=Q,r.__DEV__&&(Y.displayName="Form");var Z=["children"],$=function(e){/*#__PURE__*/return v.createElement(n.chakra.div,null,e.children)};r.__DEV__&&($.displayName="FormLayoutItem");var ee=function(e){var t,a,l,i=e.children,o=x(e,Z),s=h({},null!=(t=null==(a=n.useTheme().components)||null==(l=a.FormLayout)?void 0:l.defaultProps)?t:{spacing:4},o);/*#__PURE__*/return v.createElement(n.SimpleGrid,h({},s,{className:r.cx("saas-form__layout",o.className)}),v.Children.map(i,function(e){return v.isValidElement(e)?/*#__PURE__*/v.createElement($,null,e):e}))};r.__DEV__&&(ee.displayName="FormLayout");var re=function(e,r){return v.Children.map(r,function(r){return v.isValidElement(r)&&r.props.name?v.cloneElement(r,h({},r.props,{name:e+"."+r.props.name})):r})},te=c.createContext({name:"ArrayFieldContext"}),ne=te[0],ae=te[1],le=c.createContext({name:"ArrayFieldRowContext"}),ie=le[0],oe=le[1],se=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,s=t.useFormContext();return h({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},ue=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=ae(),l=a.name,i=a.remove,o=a.fields;return v.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:v.useCallback(function(){n(l),i(r)},[r])}},de=function(){var e=oe(),r=e.isFirst,t=e.remove,n=ae(),a=n.min;return{onClick:function(){return t()},isDisabled:r&&!!(a&&n.fields.length<=a)}},ce=function(){var e=ae(),r=e.append,t=e.defaultValue,n=e.max;return{onClick:function(){return r(t,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},me=["children","index"],pe=["children"],fe=["children"],ve=["name","defaultValue","keyName","min","max","children"],he=function(e){var r=e.children,t=e.index,n=x(e,me);/*#__PURE__*/return v.createElement(ye,{index:t},/*#__PURE__*/v.createElement(xe,n,r),/*#__PURE__*/v.createElement(be,null))};r.__DEV__&&(he.displayName="ArrayFieldRow");var xe=function(e){var r=e.children,t=x(e,pe),n=oe().name;/*#__PURE__*/return v.createElement(ee,h({flex:"1",mr:"2"},t),re(n,r))};r.__DEV__&&(xe.displayName="ArrayFieldRowFields");var ye=function(e){var r=e.children,t=ue({index:e.index});/*#__PURE__*/return v.createElement(ie,{value:t},/*#__PURE__*/v.createElement(s.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))};r.__DEV__&&(ye.displayName="ArrayFieldRowContainer");var be=function(e){/*#__PURE__*/return v.createElement(d.IconButton,h({icon:/*#__PURE__*/v.createElement(u.MinusIcon,null),"aria-label":"Remove row"},de(),e))};r.__DEV__&&(be.displayName="ArrayFieldRemoveButton");var Fe=function(e){/*#__PURE__*/return v.createElement(d.IconButton,h({icon:/*#__PURE__*/v.createElement(u.AddIcon,null),"aria-label":"Add row",float:"right"},ce(),e))};r.__DEV__&&(Fe.displayName="ArrayFieldAddButton");var Ee=s.forwardRef(function(e,r){var t=e.children,n=x(e,fe);/*#__PURE__*/return v.createElement(Se,h({ref:r},n),/*#__PURE__*/v.createElement(_e,null,function(e){/*#__PURE__*/return v.createElement(v.Fragment,null,e.map(function(e,r){/*#__PURE__*/return v.createElement(he,{key:e.id,index:r},t)}))}),/*#__PURE__*/v.createElement(Fe,null))});r.__DEV__&&(Ee.displayName="ArrayField");var _e=function(e){return(0,e.children)(ae().fields)};r.__DEV__&&(_e.displayName="ArrayFieldRows");var Se=v.forwardRef(function(e,r){var t=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=x(e,ve),u=se({name:t,defaultValue:n,keyName:a,min:l,max:i});return v.useImperativeHandle(r,function(){return u},[r,u]),/*#__PURE__*/v.createElement(ne,{value:u},/*#__PURE__*/v.createElement(D,h({name:t},s),o))});r.__DEV__&&(Se.displayName="ArrayFieldContainer");var Ce=["name","label","hideLabel","children","columns","spacing"],ge=function(e){var r=n.useStyleConfig("FormLegend");/*#__PURE__*/return v.createElement(n.FormLabel,h({as:"legend",sx:r},e))},Ne=function(e){var r=e.name,t=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=x(e,Ce);/*#__PURE__*/return v.createElement(n.FormControl,h({name:r,as:"fieldset"},s),/*#__PURE__*/v.createElement(ge,{display:a?"none":"block"},t),/*#__PURE__*/v.createElement(ee,{columns:i,gridGap:o},re(r,l)))};r.__DEV__&&(Ne.displayName="ObjectField");var Re=["name","type"],Ve=["schema","fieldResolver"],we=["name","type","defaultValue"],Ae=function(e,r){var t;return null==(t=e.getNestedFields(r))?void 0:t.map(function(e,r){var t=e.name,n=e.type,a=x(e,Re);/*#__PURE__*/return v.createElement(I,h({key:t||r,name:t,type:n},a))})},ke=function(e){var r=e.schema,t=e.fieldResolver,n=x(e,Ve),a=v.useMemo(function(){return t||Y.getFieldResolver(r)},[r,t]);/*#__PURE__*/return v.createElement(ee,n,a.getFields().map(function(e){var r=e.name,t=e.type,n=x(e,we);return"array"===t?/*#__PURE__*/v.createElement(Ee,h({key:r,name:r},n),Ae(a,r)):"object"===t?/*#__PURE__*/v.createElement(Ne,h({key:r,name:r},n),Ae(a,r)):/*#__PURE__*/v.createElement(I,h({key:r,name:r,type:t},n))}))};r.__DEV__&&(ke.displayName="Fields");var De=["children","disableIfUntouched","disableIfInvalid"],Ie=s.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=x(e,De),o=t.useFormContext().formState;/*#__PURE__*/return v.createElement(d.Button,h({type:"submit",isLoading:o.isSubmitting,colorScheme:"primary",ref:r,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});Ie.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},r.__DEV__&&(Ie.displayName="SubmitButton");var Le=["schema","submitLabel","fieldResolver","children"],Pe=n.forwardRef(function(e,r){var t=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=e.children,o=x(e,Le);/*#__PURE__*/return v.createElement(Y,h({},o,{schema:t,ref:r}),/*#__PURE__*/v.createElement(ee,null,/*#__PURE__*/v.createElement(ke,{schema:t,fieldResolver:l}),a&&/*#__PURE__*/v.createElement(Ie,{label:a}),i))});r.__DEV__&&(Pe.displayName="AutoForm");var Be=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null};r.__DEV__&&(Be.displayName="DisplayIf");var Oe=["onChange"],je=c.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),qe=je[0],Me=je[1];function Ue(e){var r=x(e,Oe),t=m.useStepper(r),n=t.activeStep,a=t.isLastStep,l=t.nextStep,i=v.useState({}),o=i[0],s=i[1],u=v.useCallback(function(r){try{var i=o[n];if(a)return Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(r).then(function(){c(h({},i,{isCompleted:!0}))}).then(l));var s=function(e,n){try{var a=Promise.resolve(null==i.onSubmit?void 0:i.onSubmit(r,t)).then(function(){l()})}catch(e){return}return a&&a.then?a.then(void 0,function(){}):a}();return Promise.resolve(s&&s.then?s.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[o,n,a]),d=v.useCallback(function(){var e=o[n];return{onSubmit:u,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[o,u,n]),c=v.useCallback(function(e){s(function(r){var t;return h({},r,((t={})[e.name]=e,t))})},[o]);return h({getFormProps:d,updateStep:c,steps:o},t)}function Te(e){var r=e.name,t=e.schema,n=e.resolver,a=e.onSubmit,l=m.useStep({name:r}),i=Me(),o=i.steps,s=i.updateStep;return v.useEffect(function(){s({name:r,schema:t,resolver:n,onSubmit:a})},[r,t]),h({},l,o[r]||{name:r,schema:t})}var ze=["children"],He=["getFormProps"],Ge=["name","schema","resolver","children","className","onSubmit"],We=["label","submitLabel"],Je=v.forwardRef(function(e,t){var n=e.children,a=x(e,ze),l=Ue(e),i=l.getFormProps,o=x(l,He),s=v.useMemo(function(){return o},[o]);/*#__PURE__*/return v.createElement(m.StepperProvider,{value:s},/*#__PURE__*/v.createElement(qe,{value:s},/*#__PURE__*/v.createElement(Y,h({ref:t},a,i()),r.runIfFn(n,l))))}),Ke=function(e){var t=e.name,n=e.schema,a=e.resolver,l=e.children,i=e.className,o=e.onSubmit,u=x(e,Ge);return Te({name:t,schema:n,resolver:a,onSubmit:o}).isActive?/*#__PURE__*/v.createElement(s.chakra.div,h({},u,{className:r.cx("saas-form__step",i)}),l):null};r.__DEV__&&(Ke.displayName="FormStep");var Qe=function(e){var t=m.useStepperContext(),n=t.prevStep;/*#__PURE__*/return v.createElement(d.Button,h({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:r.cx("saas-form__prev-button",e.className),onClick:r.callAllHandlers(e.onClick,n)}))};r.__DEV__&&(Qe.displayName="PrevButton");var Xe=function(e){var t=e.label,n=void 0===t?"Next":t,a=e.submitLabel,l=void 0===a?"Complete":a,i=x(e,We),o=m.useStepperContext(),s=o.isCompleted;/*#__PURE__*/return v.createElement(Ie,h({isDisabled:s,label:o.isLastStep||s?l:n},i,{className:r.cx("saas-form__next-button",e.className)}))};r.__DEV__&&(Xe.displayName="NextButton"),exports.ArrayField=Ee,exports.ArrayFieldAddButton=Fe,exports.ArrayFieldContainer=Se,exports.ArrayFieldProvider=ne,exports.ArrayFieldRemoveButton=be,exports.ArrayFieldRow=he,exports.ArrayFieldRowContainer=ye,exports.ArrayFieldRowFields=xe,exports.ArrayFieldRowProvider=ie,exports.ArrayFieldRows=_e,exports.AutoForm=Pe,exports.BaseField=D,exports.CheckboxField=z,exports.DisplayField=b,exports.DisplayIf=Be,exports.Field=I,exports.Fields=ke,exports.Form=Y,exports.FormLayout=ee,exports.FormLegend=ge,exports.FormStep=Ke,exports.FormStepper=function(e){var r=m.useStepperContext(),t=r.activeIndex,n=r.setIndex,a=e.orientation,l=v.Children.map(e.children,function(e){if(v.isValidElement(e)&&(null==e?void 0:e.type)===Ke){var r=Te(e.props);/*#__PURE__*/return v.createElement(m.StepperStep,{name:e.props.name,title:e.props.title,isCompleted:r.isCompleted},e.props.children)}return e}),i=v.useCallback(function(e){n(e)},[]);/*#__PURE__*/return v.createElement(m.StepperContainer,{orientation:a,step:t,onChange:i},/*#__PURE__*/v.createElement(m.StepperSteps,h({mb:"4"},e),l))},exports.FormValue=F,exports.InputField=O,exports.NativeSelectField=G,exports.NextButton=Xe,exports.NumberInputField=j,exports.ObjectField=Ne,exports.PasswordInputField=q,exports.PinField=W,exports.PrevButton=Qe,exports.RadioField=H,exports.SelectField=T,exports.StepForm=Je,exports.StepFormProvider=qe,exports.SubmitButton=Ie,exports.SwitchField=U,exports.TextareaField=M,exports.objectFieldResolver=Q,exports.registerFieldType=B,exports.useArrayField=se,exports.useArrayFieldAddButton=ce,exports.useArrayFieldContext=ae,exports.useArrayFieldRemoveButton=de,exports.useArrayFieldRow=ue,exports.useArrayFieldRowContext=oe,exports.useFormStep=Te,exports.useStepForm=Ue,exports.useStepFormContext=Me,exports.withControlledInput=L,exports.withUncontrolledInput=P,Object.keys(p).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return p[e]}})});
|
1
|
+
var e=require("react"),r=require("@chakra-ui/utils"),t=require("react-hook-form"),n=require("@chakra-ui/react"),a=require("@saas-ui/number-input"),l=require("@saas-ui/password-input"),i=require("@saas-ui/radio"),o=require("@saas-ui/select"),s=require("@chakra-ui/system"),u=require("@chakra-ui/icons"),d=require("@saas-ui/button"),c=require("@chakra-ui/react-utils"),m=require("@saas-ui/stepper"),p=require("@saas-ui/input-right-button");function f(e){if(e&&e.__esModule)return e;var r=Object.create(null);return e&&Object.keys(e).forEach(function(t){if("default"!==t){var n=Object.getOwnPropertyDescriptor(e,t);Object.defineProperty(r,t,n.get?n:{enumerable:!0,get:function(){return e[t]}})}}),r.default=e,r}var v=/*#__PURE__*/f(e);function h(){return h=Object.assign?Object.assign.bind():function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},h.apply(this,arguments)}function x(e,r){if(null==e)return{};var t,n,a={},l=Object.keys(e);for(n=0;n<l.length;n++)r.indexOf(t=l[n])>=0||(a[t]=e[t]);return a}var y=["name","label","placeholder"],b=function(e){var r=e.name,t=e.label,a=x(e,y);/*#__PURE__*/return v.createElement(n.FormControl,a,t?/*#__PURE__*/v.createElement(n.FormLabel,{htmlFor:r},t):null,/*#__PURE__*/v.createElement(n.Text,{fontSize:"md"},/*#__PURE__*/v.createElement(F,{name:r})))};r.__DEV__&&(b.displayName="DisplayField");var F=function(e){var r=e.name;return(0,t.useFormContext().getValues)(r)||null};r.__DEV__&&(F.displayName="FormValue");var E=["name","label","help","variant","hideLabel","children"],_=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],g=["name","rules"],S=["ref"],C=["name","rules"],N=["ref"],R=["type","leftAddon","rightAddon","size"],V=["type"],w=["label","type"],A=["pinLength","pinType","spacing"],D={},k=function(e){var r=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,s=e.children,u=x(e,E),d=function(e,r){return t.get(r.errors,e)}(r,t.useFormContext().formState);/*#__PURE__*/return v.createElement(n.FormControl,h({variant:i},u,{isInvalid:!!d}),a&&!o?/*#__PURE__*/v.createElement(n.FormLabel,{variant:i},a):null,/*#__PURE__*/v.createElement(n.Box,null,s,!l||null!=d&&d.message?null:/*#__PURE__*/v.createElement(n.FormHelperText,null,l),(null==d?void 0:d.message)&&/*#__PURE__*/v.createElement(n.FormErrorMessage,null,null==d?void 0:d.message)))};r.__DEV__&&(k.displayName="BaseField");var I=v.forwardRef(function(e,r){var t=e.type;/*#__PURE__*/return v.createElement(D[void 0===t?"text":t]||D.text,h({ref:r},e))}),L=function(e){return n.forwardRef(function(r,a){var l=r.name,i=r.rules,o=x(r,g),s=t.useFormContext();/*#__PURE__*/return v.createElement(t.Controller,{name:l,control:s.control,rules:i,render:function(r){var t=r.field,l=t.ref,i=x(t,S);/*#__PURE__*/return v.createElement(e,h({},i,o,{ref:n.useMergeRefs(a,l)}))}})})},P=function(e){return n.forwardRef(function(r,a){var l=r.name,i=r.rules,o=x(r,C),s=(0,t.useFormContext().register)(l,i),u=s.ref,d=x(s,N);/*#__PURE__*/return v.createElement(e,h({},d,o,{ref:n.useMergeRefs(a,u)}))})},B=function(e,r,t){var a=function(e,r){var t=r.displayName,a=r.hideLabel,l=r.BaseField,i=n.forwardRef(function(r,t){var n=r.id,i=r.name,o=r.label,s=r.help,u=r.isDisabled,d=r.isInvalid,c=r.isReadOnly,m=r.isRequired,p=r.rules,f=r.variant,y=x(r,_),b=h({required:m},p);/*#__PURE__*/return v.createElement(l,{id:n,name:i,label:o,help:s,hideLabel:a,isDisabled:u,isInvalid:d,isReadOnly:c,isRequired:m,variant:f},/*#__PURE__*/v.createElement(e,h({ref:t,id:n,name:i,label:a?o:void 0,rules:b},y)))});return i.displayName=t,i}(null!=t&&t.isControlled?L(r):P(r),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==t?void 0:t.hideLabel,BaseField:(null==t?void 0:t.BaseField)||k});return D[e]=a,a},O=B("text",n.forwardRef(function(e,r){var t=e.type,a=void 0===t?"text":t,l=e.leftAddon,i=e.rightAddon,o=e.size,s=x(e,R),u=/*#__PURE__*/v.createElement(n.Input,h({type:a,size:o},s,{ref:r}));return l||i?/*#__PURE__*/v.createElement(n.InputGroup,{size:o},l,u,i):u})),j=B("number",a.NumberInput,{isControlled:!0}),q=B("password",n.forwardRef(function(e,r){/*#__PURE__*/return v.createElement(l.PasswordInput,h({ref:r},e))})),M=B("textarea",n.Textarea),U=B("switch",n.forwardRef(function(e,r){var t=x(e,V);/*#__PURE__*/return v.createElement(n.Switch,h({},t,{ref:r}))}),{isControlled:!0}),T=B("select",o.Select,{isControlled:!0}),z=B("checkbox",n.forwardRef(function(e,r){var t=e.label,a=x(e,w);/*#__PURE__*/return v.createElement(n.Checkbox,h({ref:r},a),t)}),{hideLabel:!0}),H=B("radio",i.RadioInput,{isControlled:!0}),G=B("native-select",o.NativeSelect,{isControlled:!0}),W=B("pin",n.forwardRef(function(e,r){for(var t=e.pinLength,a=void 0===t?4:t,l=e.pinType,i=e.spacing,o=x(e,A),s=[],u=0;u<a;u++)s.push(/*#__PURE__*/v.createElement(n.PinInputField,{key:u,ref:r}));/*#__PURE__*/return v.createElement(n.HStack,{spacing:i},/*#__PURE__*/v.createElement(n.PinInput,h({},o,{type:l}),s))}),{isControlled:!0}),J=["items"],K=function(e){return e&&Object.entries(e).map(function(e){var r=e[0];return h({},x(e[1],J),{name:r})})},Q=function(e){return{getFields:function(){return K(e)},getNestedFields:function(t){var n,a=r.get(e,t);return a?"object"===(null==(n=a.items)?void 0:n.type)?K(a.items.properties):"object"===a.type?K(a.properties):[a.items]:[]}}},X=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Y=n.forwardRef(function(e,a){var l=e.mode,i=void 0===l?"all":l,o=e.resolver,s=e.reValidateMode,u=e.shouldFocusError,d=e.shouldUnregister,c=e.shouldUseNativeValidation,m=e.criteriaMode,p=e.delayError,f=e.schema,y=e.defaultValues,b=e.onSubmit,F=e.onError,E=e.formRef,_=e.children,g=x(e,X),S={mode:i,resolver:o,defaultValues:y,reValidateMode:s,shouldFocusError:u,shouldUnregister:d,shouldUseNativeValidation:c,criteriaMode:m,delayError:p};f&&!o&&(S.resolver=null==Y.getResolver?void 0:Y.getResolver(f));var C=t.useForm(S),N=C.handleSubmit;return v.useImperativeHandle(a,function(){return C},[a,C]),/*#__PURE__*/v.createElement(t.FormProvider,C,/*#__PURE__*/v.createElement(n.chakra.form,h({ref:E,onSubmit:N(b,F)},g,{className:r.cx("saas-form",e.className)}),_))});Y.getFieldResolver=Q,r.__DEV__&&(Y.displayName="Form");var Z=["children"],$=function(e){/*#__PURE__*/return v.createElement(n.chakra.div,null,e.children)};r.__DEV__&&($.displayName="FormLayoutItem");var ee=function(e){var t,a,l,i=e.children,o=x(e,Z),s=h({},null!=(t=null==(a=n.useTheme().components)||null==(l=a.FormLayout)?void 0:l.defaultProps)?t:{spacing:4},o);/*#__PURE__*/return v.createElement(n.SimpleGrid,h({},s,{className:r.cx("saas-form__layout",o.className)}),v.Children.map(i,function(e){return v.isValidElement(e)?/*#__PURE__*/v.createElement($,null,e):e}))};r.__DEV__&&(ee.displayName="FormLayout");var re=function(e,r){return v.Children.map(r,function(r){return v.isValidElement(r)&&r.props.name?v.cloneElement(r,h({},r.props,{name:e+"."+r.props.name})):r})},te=c.createContext({name:"ArrayFieldContext"}),ne=te[0],ae=te[1],le=c.createContext({name:"ArrayFieldRowContext"}),ie=le[0],oe=le[1],se=function(e){var r=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,s=t.useFormContext();return h({},t.useFieldArray({control:s.control,name:r,keyName:l}),{name:r,defaultValue:a,min:i,max:o})},ue=function(e){var r=e.index,n=t.useFormContext().clearErrors,a=ae(),l=a.name,i=a.remove,o=a.fields;return v.useEffect(function(){n(l)},[]),{index:r,isFirst:0===r,isLast:r===o.length-1,name:l+"."+r,remove:v.useCallback(function(){n(l),i(r)},[r])}},de=function(){var e=oe(),r=e.isFirst,t=e.remove,n=ae(),a=n.min;return{onClick:function(){return t()},isDisabled:r&&!!(a&&n.fields.length<=a)}},ce=function(){var e=ae(),r=e.append,t=e.defaultValue,n=e.max;return{onClick:function(){return r(t,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},me=["children","index"],pe=["children"],fe=["children"],ve=["name","defaultValue","keyName","min","max","children"],he=function(e){var r=e.children,t=e.index,n=x(e,me);/*#__PURE__*/return v.createElement(ye,{index:t},/*#__PURE__*/v.createElement(xe,n,r),/*#__PURE__*/v.createElement(be,null))};r.__DEV__&&(he.displayName="ArrayFieldRow");var xe=function(e){var r=e.children,t=x(e,pe),n=oe().name;/*#__PURE__*/return v.createElement(ee,h({flex:"1",mr:"2"},t),re(n,r))};r.__DEV__&&(xe.displayName="ArrayFieldRowFields");var ye=function(e){var r=e.children,t=ue({index:e.index});/*#__PURE__*/return v.createElement(ie,{value:t},/*#__PURE__*/v.createElement(s.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))};r.__DEV__&&(ye.displayName="ArrayFieldRowContainer");var be=function(e){/*#__PURE__*/return v.createElement(d.IconButton,h({icon:/*#__PURE__*/v.createElement(u.MinusIcon,null),"aria-label":"Remove row"},de(),e))};r.__DEV__&&(be.displayName="ArrayFieldRemoveButton");var Fe=function(e){/*#__PURE__*/return v.createElement(d.IconButton,h({icon:/*#__PURE__*/v.createElement(u.AddIcon,null),"aria-label":"Add row",float:"right"},ce(),e))};r.__DEV__&&(Fe.displayName="ArrayFieldAddButton");var Ee=s.forwardRef(function(e,r){var t=e.children,n=x(e,fe);/*#__PURE__*/return v.createElement(ge,h({ref:r},n),/*#__PURE__*/v.createElement(_e,null,function(e){/*#__PURE__*/return v.createElement(v.Fragment,null,e.map(function(e,r){/*#__PURE__*/return v.createElement(he,{key:e.id,index:r},t)}))}),/*#__PURE__*/v.createElement(Fe,null))});r.__DEV__&&(Ee.displayName="ArrayField");var _e=function(e){return(0,e.children)(ae().fields)};r.__DEV__&&(_e.displayName="ArrayFieldRows");var ge=v.forwardRef(function(e,r){var t=e.name,n=e.defaultValue,a=e.keyName,l=e.min,i=e.max,o=e.children,s=x(e,ve),u=se({name:t,defaultValue:n,keyName:a,min:l,max:i});return v.useImperativeHandle(r,function(){return u},[r,u]),/*#__PURE__*/v.createElement(ne,{value:u},/*#__PURE__*/v.createElement(k,h({name:t},s),o))});r.__DEV__&&(ge.displayName="ArrayFieldContainer");var Se=["name","label","hideLabel","children","columns","spacing"],Ce=function(e){var r=n.useStyleConfig("FormLegend");/*#__PURE__*/return v.createElement(n.FormLabel,h({as:"legend",sx:r},e))},Ne=function(e){var r=e.name,t=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,s=x(e,Se);/*#__PURE__*/return v.createElement(n.FormControl,h({name:r,as:"fieldset"},s),/*#__PURE__*/v.createElement(Ce,{display:a?"none":"block"},t),/*#__PURE__*/v.createElement(ee,{columns:i,gridGap:o},re(r,l)))};r.__DEV__&&(Ne.displayName="ObjectField");var Re=["name","type"],Ve=["schema","fieldResolver"],we=["name","type","defaultValue"],Ae=function(e,r){var t;return null==(t=e.getNestedFields(r))?void 0:t.map(function(e,r){var t=e.name,n=e.type,a=x(e,Re);/*#__PURE__*/return v.createElement(I,h({key:t||r,name:t,type:n},a))})},De=function(e){var r=e.schema,t=e.fieldResolver,n=x(e,Ve),a=v.useMemo(function(){return t||Y.getFieldResolver(r)},[r,t]);/*#__PURE__*/return v.createElement(ee,n,a.getFields().map(function(e){var r=e.name,t=e.type,n=x(e,we);return"array"===t?/*#__PURE__*/v.createElement(Ee,h({key:r,name:r},n),Ae(a,r)):"object"===t?/*#__PURE__*/v.createElement(Ne,h({key:r,name:r},n),Ae(a,r)):/*#__PURE__*/v.createElement(I,h({key:r,name:r,type:t},n))}))};r.__DEV__&&(De.displayName="Fields");var ke=["children","disableIfUntouched","disableIfInvalid","isDisabled","isLoading"],Ie=v.forwardRef(function(e,r){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=e.isDisabled,o=e.isLoading,s=x(e,ke),u=t.useFormContext().formState;/*#__PURE__*/return v.createElement(d.Button,h({},s,{ref:r,variant:"primary",type:"submit",isLoading:u.isSubmitting||o,isDisabled:a&&!u.isDirty||l&&!u.isValid||i}),n)});Ie.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},r.__DEV__&&(Ie.displayName="SubmitButton");var Le=["schema","submitLabel","fieldResolver","children"],Pe=n.forwardRef(function(e,r){var t=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=e.fieldResolver,i=e.children,o=x(e,Le);/*#__PURE__*/return v.createElement(Y,h({},o,{schema:t,ref:r}),/*#__PURE__*/v.createElement(ee,null,/*#__PURE__*/v.createElement(De,{schema:t,fieldResolver:l}),a&&/*#__PURE__*/v.createElement(Ie,null,a),i))});r.__DEV__&&(Pe.displayName="AutoForm");var Be=function(e){var r=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(t.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),t.useFormContext())?r:null};r.__DEV__&&(Be.displayName="DisplayIf");var Oe=["onChange"],je=c.createContext({name:"StepFormContext",errorMessage:"useStepFormContext: `context` is undefined. Seems you forgot to wrap step form components in `<StepForm />`"}),qe=je[0],Me=je[1];function Ue(e){var r=x(e,Oe),t=m.useStepper(r),n=t.activeStep,a=t.isLastStep,l=t.nextStep,i=v.useState({}),o=i[0],s=i[1],u=v.useCallback(function(r){try{var i=o[n];if(a)return Promise.resolve(null==e.onSubmit?void 0:e.onSubmit(r).then(function(){c(h({},i,{isCompleted:!0}))}).then(l));var s=function(e,n){try{var a=Promise.resolve(null==i.onSubmit?void 0:i.onSubmit(r,t)).then(function(){l()})}catch(e){return}return a&&a.then?a.then(void 0,function(){}):a}();return Promise.resolve(s&&s.then?s.then(function(){}):void 0)}catch(e){return Promise.reject(e)}},[o,n,a]),d=v.useCallback(function(){var e=o[n];return{onSubmit:u,schema:null==e?void 0:e.schema,resolver:null==e?void 0:e.resolver}},[o,u,n]),c=v.useCallback(function(e){s(function(r){var t;return h({},r,((t={})[e.name]=e,t))})},[o]);return h({getFormProps:d,updateStep:c,steps:o},t)}function Te(e){var r=e.name,t=e.schema,n=e.resolver,a=e.onSubmit,l=m.useStep({name:r}),i=Me(),o=i.steps,s=i.updateStep;return v.useEffect(function(){s({name:r,schema:t,resolver:n,onSubmit:a})},[r,t]),h({},l,o[r]||{name:r,schema:t})}var ze=["children"],He=["getFormProps"],Ge=["name","schema","resolver","children","className","onSubmit"],We=["label","submitLabel"],Je=v.forwardRef(function(e,t){var n=e.children,a=x(e,ze),l=Ue(e),i=l.getFormProps,o=x(l,He),s=v.useMemo(function(){return o},[o]);/*#__PURE__*/return v.createElement(m.StepperProvider,{value:s},/*#__PURE__*/v.createElement(qe,{value:s},/*#__PURE__*/v.createElement(Y,h({ref:t},a,i()),r.runIfFn(n,l))))}),Ke=function(e){var t=e.name,n=e.schema,a=e.resolver,l=e.children,i=e.className,o=e.onSubmit,u=x(e,Ge);return Te({name:t,schema:n,resolver:a,onSubmit:o}).isActive?/*#__PURE__*/v.createElement(s.chakra.div,h({},u,{className:r.cx("saas-form__step",i)}),l):null};r.__DEV__&&(Ke.displayName="FormStep");var Qe=function(e){var t=m.useStepperContext(),n=t.prevStep;/*#__PURE__*/return v.createElement(d.Button,h({isDisabled:t.isFirstStep||t.isCompleted,label:"Back"},e,{className:r.cx("saas-form__prev-button",e.className),onClick:r.callAllHandlers(e.onClick,n)}))};r.__DEV__&&(Qe.displayName="PrevButton");var Xe=function(e){var t=e.label,n=void 0===t?"Next":t,a=e.submitLabel,l=void 0===a?"Complete":a,i=x(e,We),o=m.useStepperContext(),s=o.isLastStep,u=o.isCompleted;/*#__PURE__*/return v.createElement(Ie,h({},i,{isDisabled:u,className:r.cx("saas-form__next-button",e.className)}),s||u?l:n)};r.__DEV__&&(Xe.displayName="NextButton"),exports.ArrayField=Ee,exports.ArrayFieldAddButton=Fe,exports.ArrayFieldContainer=ge,exports.ArrayFieldProvider=ne,exports.ArrayFieldRemoveButton=be,exports.ArrayFieldRow=he,exports.ArrayFieldRowContainer=ye,exports.ArrayFieldRowFields=xe,exports.ArrayFieldRowProvider=ie,exports.ArrayFieldRows=_e,exports.AutoForm=Pe,exports.BaseField=k,exports.CheckboxField=z,exports.DisplayField=b,exports.DisplayIf=Be,exports.Field=I,exports.Fields=De,exports.Form=Y,exports.FormLayout=ee,exports.FormLegend=Ce,exports.FormStep=Ke,exports.FormStepper=function(e){var r=m.useStepperContext(),t=r.activeIndex,n=r.setIndex,a=e.orientation,l=v.Children.map(e.children,function(e){if(v.isValidElement(e)&&(null==e?void 0:e.type)===Ke){var r=Te(e.props);/*#__PURE__*/return v.createElement(m.StepperStep,{name:e.props.name,title:e.props.title,isCompleted:r.isCompleted},e.props.children)}return e}),i=v.useCallback(function(e){n(e)},[]);/*#__PURE__*/return v.createElement(m.StepperContainer,{orientation:a,step:t,onChange:i},/*#__PURE__*/v.createElement(m.StepperSteps,h({mb:"4"},e),l))},exports.FormValue=F,exports.InputField=O,exports.NativeSelectField=G,exports.NextButton=Xe,exports.NumberInputField=j,exports.ObjectField=Ne,exports.PasswordInputField=q,exports.PinField=W,exports.PrevButton=Qe,exports.RadioField=H,exports.SelectField=T,exports.StepForm=Je,exports.StepFormProvider=qe,exports.SubmitButton=Ie,exports.SwitchField=U,exports.TextareaField=M,exports.objectFieldResolver=Q,exports.registerFieldType=B,exports.useArrayField=se,exports.useArrayFieldAddButton=ce,exports.useArrayFieldContext=ae,exports.useArrayFieldRemoveButton=de,exports.useArrayFieldRow=ue,exports.useArrayFieldRowContext=oe,exports.useFormStep=Te,exports.useStepForm=Ue,exports.useStepFormContext=Me,exports.withControlledInput=L,exports.withUncontrolledInput=P,Object.keys(p).forEach(function(e){"default"===e||exports.hasOwnProperty(e)||Object.defineProperty(exports,e,{enumerable:!0,get:function(){return p[e]}})});
|
2
2
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../src/use-step-form.tsx","../src/step-form.tsx"],"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 PinInputProps,\n PinInputField,\n HStack,\n PinInput,\n UsePinInputProps,\n SystemProps,\n} from '@chakra-ui/react'\nimport { __DEV__ } 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'\nimport { FocusableElement } from '@chakra-ui/utils'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport 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, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\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 isOptional,\n rules,\n variant,\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 isOptional={isOptional}\n variant={variant}\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 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 ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for the checkbox field.\n */\nexport const registerFieldType = <T extends object>(\n type: string,\n component: React.FC<T>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n }) as React.FC<T & FieldProps>\n\n inputTypes[type] = Field\n\n return Field\n}\n\nexport interface InputFieldProps extends InputProps {\n type?: string\n leftAddon?: React.ReactNode\n rightAddon?: React.ReactNode\n}\n\nexport const InputField = registerFieldType<InputFieldProps>(\n 'text',\n forwardRef(({ type = 'text', leftAddon, rightAddon, size, ...rest }, ref) => {\n const input = <Input type={type} size={size} {...rest} ref={ref} />\n if (leftAddon || rightAddon) {\n return (\n <InputGroup size={size}>\n {leftAddon}\n {input}\n {rightAddon}\n </InputGroup>\n )\n }\n return input\n })\n)\n\nexport interface NumberInputFieldProps extends NumberInputProps {\n type: 'number'\n}\n\nexport const NumberInputField = registerFieldType<NumberInputFieldProps>(\n 'number',\n NumberInput,\n {\n isControlled: true,\n }\n)\n\nexport const PasswordInputField = registerFieldType<PasswordInputProps>(\n 'password',\n forwardRef((props, ref) => <PasswordInput ref={ref} {...props} />)\n)\n\nexport const TextareaField = registerFieldType<TextareaProps>(\n 'textarea',\n Textarea\n)\n\nexport const SwitchField = registerFieldType<SwitchProps>(\n 'switch',\n forwardRef(({ type, ...rest }, ref) => {\n return <Switch {...rest} ref={ref} />\n }),\n {\n isControlled: true,\n }\n)\n\nexport const SelectField = registerFieldType<SelectProps>('select', Select, {\n isControlled: true,\n})\n\nexport const CheckboxField = registerFieldType<CheckboxProps>(\n 'checkbox',\n forwardRef(({ label, type, ...props }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\n\nexport const RadioField = registerFieldType<RadioInputProps>(\n 'radio',\n RadioInput,\n {\n isControlled: true,\n }\n)\n\nexport const NativeSelectField = registerFieldType<NativeSelectProps>(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n\nexport interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {\n pinLength?: number\n pinType?: 'alphanumeric' | 'number'\n spacing?: SystemProps['margin']\n}\n\nexport const PinField = registerFieldType<PinFieldProps>(\n 'pin',\n forwardRef((props, ref) => {\n const { pinLength = 4, pinType, spacing, ...inputProps } = props\n\n const inputs: React.ReactNode[] = []\n for (let i = 0; i < pinLength; i++) {\n inputs.push(<PinInputField key={i} ref={ref} />)\n }\n\n return (\n <HStack spacing={spacing}>\n <PinInput {...inputProps} type={pinType}>\n {inputs}\n </PinInput>\n </HStack>\n )\n }),\n {\n isControlled: true,\n }\n)\n\nconst fieldTypes = {\n text: InputField,\n email: InputField,\n url: InputField,\n phone: InputField,\n number: NumberInputField,\n password: PasswordInputField,\n textarea: TextareaField,\n switch: SwitchField,\n checkbox: CheckboxField,\n radio: RadioField,\n pin: PinField,\n select: SelectField,\n 'native-select': NativeSelectField,\n}\n\ntype FieldTypes = typeof fieldTypes\n\ntype FieldType<Props = any> = React.ElementType<Props>\n\ntype TypeProps<P extends FieldType, T> = React.ComponentPropsWithoutRef<P> & {\n type: T\n}\n\ntype FieldTypeProps =\n | {\n [Property in keyof FieldTypes]: TypeProps<FieldTypes[Property], Property>\n }[keyof FieldTypes]\n | { type?: string }\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema): FieldProps[] =>\n schema &&\n Object.entries(schema).map(([name, { items, ...field }]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n className={cx('saas-form', props.className)}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n displayName?: string\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nif (__DEV__) {\n Form.displayName = 'Form'\n}\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: 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'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n\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 { forwardRef } from '@chakra-ui/system'\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 = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n colorScheme=\"primary\"\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n\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, SubmitButtonProps } 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, Yup or Zod.\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'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\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 label={submitLabel} />}\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<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n\nif (__DEV__) {\n DisplayIf.displayName = 'DisplayIf'\n}\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler, UnpackNestedValue } 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> = (\n data: UnpackNestedValue<TFieldValues>,\n stepper: UseStepperReturn\n) => 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 const step = steps[activeStep]\n\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n try {\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 } 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} 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 const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const { activeIndex, setIndex } = useStepperContext()\n\n const { children, orientation } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n const onChange = React.useCallback((i: number) => {\n setIndex(i)\n }, [])\n\n return (\n <StepperContainer\n orientation={orientation}\n step={activeIndex}\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 isDisabled={isCompleted}\n label={isLastStep || isCompleted ? submitLabel : label}\n {...rest}\n className={cx('saas-form__next-button', props.className)}\n />\n )\n}\n\nif (__DEV__) {\n NextButton.displayName = 'NextButton'\n}\n"],"names":["_excluded","DisplayField","_ref","name","label","props","React","createElement","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","_ref2","getValues","useFormContext","_excluded2","_excluded3","_excluded4","_excluded5","_excluded6","_excluded7","_excluded8","_excluded9","_excluded10","inputTypes","BaseField","help","variant","hideLabel","children","controlProps","error","formState","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","defaultInputType","_props$type","withControlledInput","InputComponent","rules","_ref3","inputProps","_objectWithoutPropertiesLoose","_useFormContext2","Controller","control","render","field","_ref4$field","useMergeRefs","withUncontrolledInput","_ref5","_register","register","_extends","registerFieldType","component","options","id","isDisabled","isReadOnly","isRequired","isOptional","required","undefined","inputRules","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","_ref6$type","_ref6","leftAddon","rightAddon","size","rest","input","Input","InputGroup","NumberInputField","NumberInput","PasswordInputField","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","_ref8","Checkbox","RadioField","RadioInput","NativeSelectField","NativeSelect","PinField","pinLength","_props$pinLength","pinType","spacing","inputs","i","push","PinInputField","key","HStack","PinInput","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","_field$items","items","properties","Form","mode","_props$mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","gridProps","theme","useTheme","components","defaultProps","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","_createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","_ref$defaultValue","defaultValue","keyName","min","max","context","useFieldArray","useArrayFieldRow","index","clearErrors","_useArrayFieldContext","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","_useArrayFieldRowCont","_useArrayFieldContext2","onClick","append","_useArrayFieldContext3","shouldFocus","ArrayFieldRow","rowFieldsProps","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","mr","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","useArrayFieldAddButton","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","Fragment","_ref4","fieldProps","FormLegend","styles","useStyleConfig","as","sx","columns","gridGap","ObjectField","_resolver$getNestedFi","nestedFieldProps","Fields","fieldResolver","useMemo","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","colorScheme","isDirty","isValid","SubmitButton","AutoForm","_props$submitLabel","submitLabel","DisplayIf","condition","_ref$condition","useWatch","disabled","exact","isExact","errorMessage","StepFormProvider","useStepFormContext","onChange","stepper","useStepper","activeStep","isLastStep","nextStep","_React$useState","useState","steps","updateSteps","onSubmitStep","data","step","Promise","resolve","then","updateStep","isCompleted","_temp2","_catch","e","reject","getFormProps","_extends2","useStep","_useStepFormContext","useStepForm","ctx","StepperProvider","runIfFn","FormStep","useFormStep","isActive","PrevButton","_useStepperContext2","useStepperContext","prevStep","isFirstStep","callAllHandlers","NextButton","_props$label","activeIndex","_useStepperContext","setIndex","orientation","elements","_useFormStep","StepperStep","title","StepperContainer","StepperSteps"],"mappings":"okCAAA,IAAAA,EAAA,CAAA,OAAA,QAAA,eAiByBC,EAAgC,SAAAC,GACvDC,IAAAA,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,MAEGC,sBAEH,OACEC,EAAAC,cAACC,EAADA,YAAiBH,EACdD,eAAQE,EAACC,cAAAE,EAADA,UAAW,CAAAC,QAASP,GAAOC,GAAqB,kBACzDE,EAAAC,cAACI,EAADA,KAAA,CAAMC,SAAS,mBACbN,EAACC,cAAAM,EAAU,CAAAV,KAAMA,OAMrBW,EAAAA,UACFb,EAAac,YAAc,gBAGhBF,MAAwC,SAAAG,GAAGb,IAAAA,EAAAA,EAAAA,KAEtD,OAAOc,EADeC,EAAcA,iBAA5BD,WACSd,IAAS,MAGxBW,EAAAA,UACFD,EAAUE,YAAc,aC3C1B,IAAAf,EAAA,CAAA,OAAA,QAAA,OAAA,UAAA,YAAA,YAAAmB,EAAA,CAAA,KAAA,OAAA,QAAA,OAAA,aAAA,YAAA,aAAA,aAAA,aAAA,QAAA,WAAAC,EAAA,CAAA,OAAA,SAAAC,EAAA,CAAA,OAAAC,EAAA,CAAA,OAAA,SAAAC,EAAA,CAAA,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MALImR,EAAAA,YAKiBa,EAAc5B,EAAcpQ,GAC7C2F,EACJ,CAAAgE,UAAWC,EAAAA,GAAG,yBAA0B3J,EAAM0J,eAKhDjJ,YACF4S,GAAW3S,YAAc,wiBAnG6B,SAACV,GACvD,IAAkCiT,EAAAA,EAAAA,oBAA1BM,EAARC,EAAQD,YAAaE,EAAAA,EAAAA,SAEHC,EAAgB1T,EAAhB0T,YAEJC,EAAG1T,EAAMwK,SAAS3F,IAFE9E,EAA1B4B,SAEsC,SAAC8I,GAC7C,GAAIzK,EAAM0K,eAAeD,WAAUA,OAAAA,EAAAA,EAAO/H,QAASiQ,GAAU,CAC3D,IAAAgB,EAAwBf,GAAYnI,EAAM1K,oBAC1C,OACEC,EAACC,cAAA2T,EAADA,aACE/T,KAAM4K,EAAM1K,MAAMF,KAClBgU,MAAOpJ,EAAM1K,MAAM8T,MACnB/B,YALJ6B,EAAQ7B,aAOHrH,EAAM1K,MAAM4B,UAInB,OACD8I,IAEaoG,EAAG7Q,EAAMqM,YAAY,SAAClF,GAClCqM,EAASrM,IACR,iBAEH,OACEnH,EAAAC,cAAC6T,EAADA,iBAAA,CACEL,YAAaA,EACbhC,KAAM6B,EACNzC,SAAUA,gBAEV7Q,EAACC,cAAA8T,EAADA,aAAcjQ,EAAA,CAAA6J,GAAG,KAAQ5N,GACtB2T"}
|
1
|
+
{"version":3,"file":"index.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/field-resolver.ts","../src/form.tsx","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx","../src/use-step-form.tsx","../src/step-form.tsx"],"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 } 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, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\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 variant,\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 variant={variant}\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 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 ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for the checkbox field.\n */\nexport const registerFieldType = <T extends object>(\n type: string,\n component: React.FC<T>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n }) as React.FC<T & FieldProps>\n\n inputTypes[type] = Field\n\n return Field\n}\n\nexport interface InputFieldProps extends InputProps {\n type?: string\n leftAddon?: React.ReactNode\n rightAddon?: React.ReactNode\n}\n\nexport const InputField = registerFieldType<InputFieldProps>(\n 'text',\n forwardRef(({ type = 'text', leftAddon, rightAddon, size, ...rest }, ref) => {\n const input = <Input type={type} size={size} {...rest} ref={ref} />\n if (leftAddon || rightAddon) {\n return (\n <InputGroup size={size}>\n {leftAddon}\n {input}\n {rightAddon}\n </InputGroup>\n )\n }\n return input\n })\n)\n\nexport interface NumberInputFieldProps extends NumberInputProps {\n type: 'number'\n}\n\nexport const NumberInputField = registerFieldType<NumberInputFieldProps>(\n 'number',\n NumberInput,\n {\n isControlled: true,\n }\n)\n\nexport const PasswordInputField = registerFieldType<PasswordInputProps>(\n 'password',\n forwardRef((props, ref) => <PasswordInput ref={ref} {...props} />)\n)\n\nexport const TextareaField = registerFieldType<TextareaProps>(\n 'textarea',\n Textarea\n)\n\nexport const SwitchField = registerFieldType<SwitchProps>(\n 'switch',\n forwardRef(({ type, ...rest }, ref) => {\n return <Switch {...rest} ref={ref} />\n }),\n {\n isControlled: true,\n }\n)\n\nexport const SelectField = registerFieldType<SelectProps>('select', Select, {\n isControlled: true,\n})\n\nexport const CheckboxField = registerFieldType<CheckboxProps>(\n 'checkbox',\n forwardRef(({ label, type, ...props }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\n\nexport const RadioField = registerFieldType<RadioInputProps>(\n 'radio',\n RadioInput,\n {\n isControlled: true,\n }\n)\n\nexport const NativeSelectField = registerFieldType<NativeSelectProps>(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n\nexport interface PinFieldProps extends Omit<UsePinInputProps, 'type'> {\n pinLength?: number\n pinType?: 'alphanumeric' | 'number'\n spacing?: SystemProps['margin']\n}\n\nexport const PinField = registerFieldType<PinFieldProps>(\n 'pin',\n forwardRef((props, ref) => {\n const { pinLength = 4, pinType, spacing, ...inputProps } = props\n\n const inputs: React.ReactNode[] = []\n for (let i = 0; i < pinLength; i++) {\n inputs.push(<PinInputField key={i} ref={ref} />)\n }\n\n return (\n <HStack spacing={spacing}>\n <PinInput {...inputProps} type={pinType}>\n {inputs}\n </PinInput>\n </HStack>\n )\n }),\n {\n isControlled: true,\n }\n)\n\nconst fieldTypes = {\n text: InputField,\n email: InputField,\n url: InputField,\n phone: InputField,\n number: NumberInputField,\n password: PasswordInputField,\n textarea: TextareaField,\n switch: SwitchField,\n checkbox: CheckboxField,\n radio: RadioField,\n pin: PinField,\n select: SelectField,\n 'native-select': NativeSelectField,\n}\n\ntype FieldTypes = typeof fieldTypes\n\ntype FieldType<Props = any> = React.ElementType<Props>\n\ntype TypeProps<P extends FieldType, T> = React.ComponentPropsWithoutRef<P> & {\n type: T\n}\n\ntype FieldTypeProps =\n | {\n [Property in keyof FieldTypes]: TypeProps<FieldTypes[Property], Property>\n }[keyof FieldTypes]\n | { type?: string }\n","import { FieldProps } from './field'\n\nimport { get } from '@chakra-ui/utils'\n\nexport type FieldResolver = {\n getFields(): FieldProps[]\n getNestedFields(name: string): FieldProps[]\n}\n\ninterface SchemaField extends FieldProps {\n items?: SchemaField[]\n properties?: Record<string, SchemaField>\n}\n\nexport type ObjectSchema = Record<string, SchemaField>\n\nconst mapFields = (schema: ObjectSchema): FieldProps[] =>\n schema &&\n Object.entries(schema).map(([name, { items, ...field }]) => {\n return {\n ...field,\n name,\n }\n })\n\nexport const objectFieldResolver = (schema: ObjectSchema): FieldResolver => {\n const getFields = () => {\n return mapFields(schema)\n }\n const getNestedFields = (name: string) => {\n const field = get(schema, name)\n\n if (!field) return []\n\n if (field.items?.type === 'object') {\n return mapFields(field.items.properties)\n } else if (field.type === 'object') {\n return mapFields(field.properties)\n }\n return [field.items]\n }\n\n return { getFields, getNestedFields }\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\nimport { cx, __DEV__ } from '@chakra-ui/utils'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n UnpackNestedValue,\n ResolverOptions,\n ResolverResult,\n} from 'react-hook-form'\nimport { objectFieldResolver, FieldResolver } from './field-resolver'\n\nexport type { UseFormReturn, FieldValues, SubmitHandler }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n if (schema && !resolver) {\n form.resolver = Form.getResolver?.(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwarded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n className={cx('saas-form', props.className)}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as (<TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement) & {\n displayName?: string\n getResolver?: GetResolver\n getFieldResolver: GetFieldResolver\n}\n\nForm.getFieldResolver = objectFieldResolver\n\nif (__DEV__) {\n Form.displayName = 'Form'\n}\n\nexport type GetResolver = (\n schema: any\n) => <TFieldValues extends FieldValues, TContext>(\n values: 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'\n\nexport interface FieldsProps {\n schema: any\n fieldResolver?: FieldResolver\n}\n\nconst mapNestedFields = (resolver: FieldResolver, name: string) => {\n return resolver\n .getNestedFields(name)\n ?.map(\n ({ name, type, ...nestedFieldProps }: FieldProps, i): React.ReactNode => (\n <Field key={name || i} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({\n schema,\n fieldResolver,\n ...props\n}) => {\n const resolver = React.useMemo(\n () => fieldResolver || Form.getFieldResolver(schema),\n [schema, fieldResolver]\n )\n\n return (\n <FormLayout {...props}>\n {resolver\n .getFields()\n .map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField key={name} name={name} {...fieldProps}>\n {mapNestedFields(resolver, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n\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, Yup or Zod.\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'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\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<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n\nif (__DEV__) {\n DisplayIf.displayName = 'DisplayIf'\n}\n","import * as React from 'react'\nimport { FieldValues, SubmitHandler, UnpackNestedValue } 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> = (\n data: UnpackNestedValue<TFieldValues>,\n stepper: UseStepperReturn\n) => 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 const step = steps[activeStep]\n\n if (isLastStep) {\n return props\n .onSubmit?.(data)\n .then(() => {\n updateStep({\n ...step,\n isCompleted: true,\n })\n })\n .then(nextStep) // Show completed step\n }\n\n try {\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 } 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} 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 const FormStepper: React.FC<StepperStepsProps> = (props) => {\n const { activeIndex, setIndex } = useStepperContext()\n\n const { children, orientation } = props\n\n const elements = React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child?.type === FormStep) {\n const { isCompleted } = useFormStep(child.props) // Register this step\n return (\n <StepperStep\n name={child.props.name}\n title={child.props.title}\n isCompleted={isCompleted}\n >\n {child.props.children}\n </StepperStep>\n )\n }\n return child\n })\n\n const onChange = React.useCallback((i: number) => {\n setIndex(i)\n }, [])\n\n return (\n <StepperContainer\n orientation={orientation}\n step={activeIndex}\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"],"names":["_excluded","DisplayField","_ref","name","label","props","React","createElement","FormControl","FormLabel","htmlFor","Text","fontSize","FormValue","__DEV__","displayName","_ref2","getValues","useFormContext","_excluded2","_excluded3","_excluded4","_excluded5","_excluded6","_excluded7","_excluded8","_excluded9","_excluded10","inputTypes","help","variant","hideLabel","children","controlProps","formState","get","errors","getError","_extends","isInvalid","error","Box","message","FormHelperText","FormErrorMessage","BaseField","Field","forwardRef","ref","_props$type","type","defaultInputType","withControlledInput","InputComponent","rules","_ref3","inputProps","_objectWithoutPropertiesLoose","_useFormContext2","Controller","control","render","field","_ref4$field","useMergeRefs","withUncontrolledInput","_ref5","_register","register","component","options","id","isDisabled","isReadOnly","isRequired","inputRules","required","undefined","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","registerFieldType","_ref6","_ref6$type","leftAddon","rightAddon","size","rest","input","Input","InputGroup","NumberInputField","NumberInput","PasswordInputField","PasswordInput","Textarea","SwitchField","_ref7","Switch","SelectField","Select","CheckboxField","_ref8","Checkbox","RadioField","RadioInput","NativeSelectField","NativeSelect","pinLength","_props$pinLength","pinType","spacing","inputs","i","push","PinInputField","key","HStack","PinInput","mapFields","schema","Object","entries","objectFieldResolver","getFields","getNestedFields","_field$items","items","properties","Form","mode","_props$mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","form","getResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","chakra","className","cx","getFieldResolver","FormLayoutItem","div","FormLayout","_theme$components$For","_theme$components","_theme$components$For2","gridProps","theme","useTheme","components","defaultProps","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","_createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","_ref$defaultValue","defaultValue","keyName","min","max","context","useFieldArray","useArrayFieldRow","index","clearErrors","_useArrayFieldContext","remove","fields","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","_useArrayFieldRowCont","_useArrayFieldContext2","onClick","append","_useArrayFieldContext3","shouldFocus","ArrayFieldRow","rowFieldsProps","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","mr","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","useArrayFieldAddButton","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","Fragment","_ref4","fieldProps","FormLegend","styles","useStyleConfig","as","sx","columns","gridGap","ObjectField","_resolver$getNestedFi","nestedFieldProps","Fields","fieldResolver","useMemo","SubmitButton","disableIfUntouched","disableIfInvalid","isDisabledProp","isLoading","Button","isSubmitting","isDirty","isValid","AutoForm","submitLabel","_props$submitLabel","DisplayIf","condition","_ref$condition","useWatch","disabled","exact","isExact","errorMessage","StepFormProvider","useStepFormContext","onChange","stepper","useStepper","activeStep","isLastStep","nextStep","_React$useState","useState","steps","updateSteps","onSubmitStep","data","step","Promise","resolve","then","updateStep","isCompleted","_temp2","_catch","e","reject","getFormProps","_extends2","useStep","_useStepFormContext","useStepForm","ctx","StepperProvider","runIfFn","FormStep","useFormStep","isActive","PrevButton","_useStepperContext2","useStepperContext","prevStep","isFirstStep","callAllHandlers","NextButton","_props$label","_useStepperContext3","_useStepperContext","activeIndex","setIndex","orientation","elements","StepperStep","title","StepperContainer","StepperSteps"],"mappings":"okCAAA,IAAAA,EAAA,CAAA,OAAA,QAAA,eAiByBC,EAAgC,SAAAC,GACvDC,IAAAA,EAAAA,EAAAA,KACAC,EAAAA,EAAAA,MAEGC,sBAEH,OACEC,EAAAC,cAACC,EAADA,YAAiBH,EACdD,eAAQE,EAACC,cAAAE,EAADA,UAAW,CAAAC,QAASP,GAAOC,GAAqB,kBACzDE,EAAAC,cAACI,EAADA,KAAA,CAAMC,SAAS,mBACbN,EAACC,cAAAM,EAAU,CAAAV,KAAMA,OAMrBW,EAAAA,UACFb,EAAac,YAAc,gBAGhBF,MAAwC,SAAAG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2 +1,2 @@
|
|
1
|
-
import*as e from"react";import{__DEV__ as t,get as a,cx as l,runIfFn as r,callAllHandlers as n}from"@chakra-ui/utils";import{useFormContext as s,get as i,Controller as o,useForm as m,FormProvider as c,useFieldArray as d,useWatch as u}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 x,FormHelperText as S,FormErrorMessage as C,useMergeRefs as k,Textarea as R,PinInputField as V,chakra as L,useTheme as I,SimpleGrid as w,useStyleConfig as A}from"@chakra-ui/react";import{NumberInput as O}from"@saas-ui/number-input";import{PasswordInput as D}from"@saas-ui/password-input";import{RadioInput as j}from"@saas-ui/radio";import{Select as B,NativeSelect as U}from"@saas-ui/select";import{forwardRef as _,chakra as M}from"@chakra-ui/system";import{MinusIcon as P,AddIcon as z}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 J,useStepperContext as K,StepperStep as Q,StepperContainer as W,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 a=arguments[t];for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(e[l]=a[l])}return e},Y.apply(this,arguments)}function Z(e,t){if(null==e)return{};var a,l,r={},n=Object.keys(e);for(l=0;l<n.length;l++)t.indexOf(a=n[l])>=0||(r[a]=e[a]);return r}const ee=["name","label","placeholder"],te=t=>{let{name:a,label:l}=t,r=Z(t,ee);/*#__PURE__*/return e.createElement(p,r,l?/*#__PURE__*/e.createElement(f,{htmlFor:a},l):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(ae,{name:a})))};t&&(te.displayName="DisplayField");const ae=({name:e})=>{const{getValues:t}=s();return t(e)||null};t&&(ae.displayName="FormValue");const le=["name","label","help","variant","hideLabel","children"],re=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","isOptional","rules","variant"],ne=["name","rules"],se=["ref"],ie=["name","rules"],oe=["ref"],me=["type","leftAddon","rightAddon","size"],ce=["type"],de=["label","type"],ue=["pinLength","pinType","spacing"],pe={},fe="text",he=t=>{const{name:a,label:l,help:r,variant:n,hideLabel:o,children:m}=t,c=Z(t,le),{formState:d}=s(),u=((e,t)=>i(t.errors,e))(a,d);/*#__PURE__*/return e.createElement(p,Y({variant:n},c,{isInvalid:!!u}),l&&!o?/*#__PURE__*/e.createElement(f,{variant:n},l):null,/*#__PURE__*/e.createElement(x,null,m,!r||null!=u&&u.message?null:/*#__PURE__*/e.createElement(S,null,r),(null==u?void 0:u.message)&&/*#__PURE__*/e.createElement(C,null,null==u?void 0:u.message)))};t&&(he.displayName="BaseField");const be=e.forwardRef((t,a)=>{const{type:l=fe}=t,r=(e=>pe[e]||pe[fe])(l);/*#__PURE__*/return e.createElement(r,Y({ref:a},t))}),ye=t=>b((a,l)=>{let{name:r,rules:n}=a,i=Z(a,ne);const{control:m}=s();/*#__PURE__*/return e.createElement(o,{name:r,control:m,rules:n,render:a=>{let{field:{ref:r}}=a,n=Z(a.field,se);/*#__PURE__*/return e.createElement(t,Y({},n,i,{ref:k(l,r)}))}})}),Ee=t=>b((a,l)=>{let{name:r,rules:n}=a,i=Z(a,ie);const{register:o}=s(),m=o(r,n),{ref:c}=m,d=Z(m,oe);/*#__PURE__*/return e.createElement(t,Y({},d,i,{ref:k(l,c)}))}),ve=(t,a,l)=>{let r;r=null!=l&&l.isControlled?ye(a):Ee(a);const n=((t,{displayName:a,hideLabel:l,BaseField:r})=>{const n=b((a,n)=>{const{id:s,name:i,label:o,help:m,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,isOptional:f,rules:h,variant:b}=a,y=Z(a,re),E=Y({required:p},h);/*#__PURE__*/return e.createElement(r,{id:s,name:i,label:o,help:m,hideLabel:l,isDisabled:c,isInvalid:d,isReadOnly:u,isRequired:p,isOptional:f,variant:b},/*#__PURE__*/e.createElement(t,Y({ref:n,id:s,name:i,label:l?o:void 0,rules:E},y)))});return n.displayName=a,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==l?void 0:l.hideLabel,BaseField:(null==l?void 0:l.BaseField)||he});return pe[t]=n,n},ge=ve("text",b((t,a)=>{let{type:l="text",leftAddon:r,rightAddon:n,size:s}=t,i=Z(t,me);const o=/*#__PURE__*/e.createElement(y,Y({type:l,size:s},i,{ref:a}));return r||n?/*#__PURE__*/e.createElement(E,{size:s},r,o,n):o})),Fe=ve("number",O,{isControlled:!0}),Ne=ve("password",b((t,a)=>/*#__PURE__*/e.createElement(D,Y({ref:a},t)))),xe=ve("textarea",R),Se=ve("switch",b((t,a)=>{let l=Z(t,ce);/*#__PURE__*/return e.createElement(v,Y({},l,{ref:a}))}),{isControlled:!0}),Ce=ve("select",B,{isControlled:!0}),ke=ve("checkbox",b((t,a)=>{let{label:l}=t,r=Z(t,de);/*#__PURE__*/return e.createElement(g,Y({ref:a},r),l)}),{hideLabel:!0}),Re=ve("radio",j,{isControlled:!0}),Ve=ve("native-select",U,{isControlled:!0}),Le=ve("pin",b((t,a)=>{const{pinLength:l=4,pinType:r,spacing:n}=t,s=Z(t,ue),i=[];for(let t=0;t<l;t++)i.push(/*#__PURE__*/e.createElement(V,{key:t,ref:a}));/*#__PURE__*/return e.createElement(F,{spacing:n},/*#__PURE__*/e.createElement(N,Y({},s,{type:r}),i))}),{isControlled:!0}),Ie=["items"],we=e=>e&&Object.entries(e).map(([e,t])=>Y({},Z(t,Ie),{name:e})),Ae=e=>({getFields:()=>we(e),getNestedFields:t=>{var l;const r=a(e,t);return r?"object"===(null==(l=r.items)?void 0:l.type)?we(r.items.properties):"object"===r.type?we(r.properties):[r.items]:[]}}),Oe=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],De=b((t,a)=>{const{mode:r="all",resolver:n,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:d,criteriaMode:u,delayError:p,schema:f,defaultValues:h,onSubmit:b,onError:y,formRef:E,children:v}=t,g=Z(t,Oe),F={mode:r,resolver:n,defaultValues:h,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:d,criteriaMode:u,delayError:p};f&&!n&&(F.resolver=null==De.getResolver?void 0:De.getResolver(f));const N=m(F),{handleSubmit:x}=N;return e.useImperativeHandle(a,()=>N,[a,N]),/*#__PURE__*/e.createElement(c,N,/*#__PURE__*/e.createElement(L.form,Y({ref:E,onSubmit:x(b,y)},g,{className:l("saas-form",t.className)}),v))});De.getFieldResolver=Ae,t&&(De.displayName="Form");const je=["children"],Be=({children:t})=>/*#__PURE__*/e.createElement(L.div,null,t);t&&(Be.displayName="FormLayoutItem");const Ue=t=>{var a,r,n;let{children:s}=t,i=Z(t,je);const o=Y({},null!=(a=null==(r=I().components)||null==(n=r.FormLayout)?void 0:n.defaultProps)?a:{spacing:4},i);/*#__PURE__*/return e.createElement(w,Y({},o,{className:l("saas-form__layout",i.className)}),e.Children.map(s,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(Be,null,t):t))};t&&(Ue.displayName="FormLayout");const _e=(t,a)=>e.Children.map(a,a=>e.isValidElement(a)&&a.props.name?e.cloneElement(a,Y({},a.props,{name:`${t}.${a.props.name}`})):a),[Me,Pe]=H({name:"ArrayFieldContext"}),[ze,$e]=H({name:"ArrayFieldRowContext"}),qe=({name:e,defaultValue:t={},keyName:a,min:l,max:r})=>{const{control:n}=s();return Y({},d({control:n,name:e,keyName:a}),{name:e,defaultValue:t,min:l,max:r})},He=({index:t})=>{const{clearErrors:a}=s(),{name:l,remove:r,fields:n}=Pe();return e.useEffect(()=>{a(l)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${l}.${t}`,remove:e.useCallback(()=>{a(l),r(t)},[t])}},Te=()=>{const{isFirst:e,remove:t}=$e(),{min:a,fields:l}=Pe();return{onClick:()=>t(),isDisabled:e&&!!(a&&l.length<=a)}},Ge=()=>{const{append:e,defaultValue:t,max:a,fields:l}=Pe();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(a&&l.length>=a)}},Je=["children","index"],Ke=["children"],Qe=["children"],We=["name","defaultValue","keyName","min","max","children"],Xe=t=>{let{children:a,index:l}=t,r=Z(t,Je);/*#__PURE__*/return e.createElement(Ze,{index:l},/*#__PURE__*/e.createElement(Ye,r,a),/*#__PURE__*/e.createElement(et,null))};t&&(Xe.displayName="ArrayFieldRow");const Ye=t=>{let{children:a}=t,l=Z(t,Ke);const{name:r}=$e();/*#__PURE__*/return e.createElement(Ue,Y({flex:"1",mr:"2"},l),_e(r,a))};t&&(Ye.displayName="ArrayFieldRowFields");const Ze=({children:t,index:a})=>{const l=He({index:a});/*#__PURE__*/return e.createElement(ze,{value:l},/*#__PURE__*/e.createElement(M.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(P,null),"aria-label":"Remove row"},Te(),t));t&&(et.displayName="ArrayFieldRemoveButton");const tt=t=>/*#__PURE__*/e.createElement($,Y({icon:/*#__PURE__*/e.createElement(z,null),"aria-label":"Add row",float:"right"},Ge(),t));t&&(tt.displayName="ArrayFieldAddButton");const at=_((t,a)=>{const{children:l}=t,r=Z(t,Qe);/*#__PURE__*/return e.createElement(rt,Y({ref:a},r),/*#__PURE__*/e.createElement(lt,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},a)=>/*#__PURE__*/e.createElement(Xe,{key:t,index:a},l)))),/*#__PURE__*/e.createElement(tt,null))});t&&(at.displayName="ArrayField");const lt=({children:e})=>{const{fields:t}=Pe();return e(t)};t&&(lt.displayName="ArrayFieldRows");const rt=e.forwardRef((t,a)=>{let{name:l,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=Z(t,We);const c=qe({name:l,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(a,()=>c,[a,c]),/*#__PURE__*/e.createElement(Me,{value:c},/*#__PURE__*/e.createElement(he,Y({name:l},m),o))});t&&(rt.displayName="ArrayFieldContainer");const nt=["name","label","hideLabel","children","columns","spacing"],st=t=>{const a=A("FormLegend");/*#__PURE__*/return e.createElement(f,Y({as:"legend",sx:a},t))},it=t=>{const{name:a,label:l,hideLabel:r,children:n,columns:s,spacing:i}=t,o=Z(t,nt);/*#__PURE__*/return e.createElement(p,Y({name:a,as:"fieldset"},o),/*#__PURE__*/e.createElement(st,{display:r?"none":"block"},l),/*#__PURE__*/e.createElement(Ue,{columns:s,gridGap:i},_e(a,n)))};t&&(it.displayName="ObjectField");const ot=["name","type"],mt=["schema","fieldResolver"],ct=["name","type","defaultValue"],dt=(t,a)=>{var l;return null==(l=t.getNestedFields(a))?void 0:l.map((t,a)=>{let{name:l,type:r}=t,n=Z(t,ot);/*#__PURE__*/return e.createElement(be,Y({key:l||a,name:l,type:r},n))})},ut=t=>{let{schema:a,fieldResolver:l}=t,r=Z(t,mt);const n=e.useMemo(()=>l||De.getFieldResolver(a),[a,l]);/*#__PURE__*/return e.createElement(Ue,r,n.getFields().map(t=>{let{name:a,type:l}=t,r=Z(t,ct);return"array"===l?/*#__PURE__*/e.createElement(at,Y({key:a,name:a},r),dt(n,a)):"object"===l?/*#__PURE__*/e.createElement(it,Y({key:a,name:a},r),dt(n,a)):/*#__PURE__*/e.createElement(be,Y({key:a,name:a,type:l},r))}))};t&&(ut.displayName="Fields");const pt=["children","disableIfUntouched","disableIfInvalid"],ft=_((t,a)=>{const{children:l,disableIfUntouched:r,disableIfInvalid:n}=t,i=Z(t,pt),{formState:o}=s();/*#__PURE__*/return e.createElement(q,Y({type:"submit",isLoading:o.isSubmitting,colorScheme:"primary",ref:a,isDisabled:r&&!o.isDirty||n&&!o.isValid},i),l)});ft.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(ft.displayName="SubmitButton");const ht=["schema","submitLabel","fieldResolver","children"],bt=b((t,a)=>{const{schema:l,submitLabel:r="Submit",fieldResolver:n,children:s}=t,i=Z(t,ht);/*#__PURE__*/return e.createElement(De,Y({},i,{schema:l,ref:a}),/*#__PURE__*/e.createElement(Ue,null,/*#__PURE__*/e.createElement(ut,{schema:l,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(ft,{label:r}),s))});t&&(bt.displayName="AutoForm");const yt=({children:e,name:t,defaultValue:a,isDisabled:l,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:a,disabled:l,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 a=Z(t,Et),l=T(a),{activeStep:r,isLastStep:n,nextStep:s}=l,[i,o]=e.useState({}),m=e.useCallback(async e=>{const a=i[r];if(n)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{d(Y({},a,{isCompleted:!0}))}).then(s);try{await(null==a.onSubmit?void 0:a.onSubmit(e,l)),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},l)}function Nt(t){const{name:a,schema:l,resolver:r,onSubmit:n}=t,s=G({name:a}),{steps:i,updateStep:o}=gt();return e.useEffect(()=>{o({name:a,schema:l,resolver:r,onSubmit:n})},[a,l]),Y({},s,i[a]||{name:a,schema:l})}const xt=["children"],St=["getFormProps"],Ct=["name","schema","resolver","children","className","onSubmit"],kt=["label","submitLabel"],Rt=e.forwardRef((t,a)=>{const{children:l}=t,n=Z(t,xt),s=Ft(t),{getFormProps:i}=s,o=Z(s,St),m=e.useMemo(()=>o,[o]);/*#__PURE__*/return e.createElement(J,{value:m},/*#__PURE__*/e.createElement(vt,{value:m},/*#__PURE__*/e.createElement(De,Y({ref:a},n,i()),r(l,s))))}),Vt=t=>{const{activeIndex:a,setIndex:l}=K(),{children:r,orientation:n}=t,s=e.Children.map(r,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===Lt){const{isCompleted:a}=Nt(t.props);/*#__PURE__*/return e.createElement(Q,{name:t.props.name,title:t.props.title,isCompleted:a},t.props.children)}return t}),i=e.useCallback(e=>{l(e)},[]);/*#__PURE__*/return e.createElement(W,{orientation:n,step:a,onChange:i},/*#__PURE__*/e.createElement(X,Y({mb:"4"},t),s))},Lt=t=>{const{name:a,schema:r,resolver:n,children:s,className:i,onSubmit:o}=t,m=Z(t,Ct),c=Nt({name:a,schema:r,resolver:n,onSubmit:o}),{isActive:d}=c;return d?/*#__PURE__*/e.createElement(M.div,Y({},m,{className:l("saas-form__step",i)}),s):null};t&&(Lt.displayName="FormStep");const It=t=>{const{isFirstStep:a,isCompleted:r,prevStep:s}=K();/*#__PURE__*/return e.createElement(q,Y({isDisabled:a||r,label:"Back"},t,{className:l("saas-form__prev-button",t.className),onClick:n(t.onClick,s)}))};t&&(It.displayName="PrevButton");const wt=t=>{const{label:a="Next",submitLabel:r="Complete"}=t,n=Z(t,kt),{isLastStep:s,isCompleted:i}=K();/*#__PURE__*/return e.createElement(ft,Y({isDisabled:i,label:s||i?r:a},n,{className:l("saas-form__next-button",t.className)}))};t&&(wt.displayName="NextButton");export{at as ArrayField,tt as ArrayFieldAddButton,rt as ArrayFieldContainer,Me as ArrayFieldProvider,et as ArrayFieldRemoveButton,Xe as ArrayFieldRow,Ze as ArrayFieldRowContainer,Ye as ArrayFieldRowFields,ze as ArrayFieldRowProvider,lt 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,Ue as FormLayout,st as FormLegend,Lt as FormStep,Vt as FormStepper,ae as FormValue,ge as InputField,Ve as NativeSelectField,wt as NextButton,Fe as NumberInputField,it as ObjectField,Ne as PasswordInputField,Le as PinField,It as PrevButton,Re as RadioField,Ce as SelectField,Rt as StepForm,vt as StepFormProvider,ft as SubmitButton,Se as SwitchField,xe as TextareaField,Ae as objectFieldResolver,ve as registerFieldType,qe as useArrayField,Ge as useArrayFieldAddButton,Pe as useArrayFieldContext,Te as useArrayFieldRemoveButton,He as useArrayFieldRow,$e as useArrayFieldRowContext,Nt as useFormStep,Ft as useStepForm,gt as useStepFormContext,ye as withControlledInput,Ee as withUncontrolledInput};
|
1
|
+
import*as e from"react";import{__DEV__ as t,get as a,cx as l,runIfFn as r,callAllHandlers as n}from"@chakra-ui/utils";import{useFormContext as s,get as i,Controller as o,useForm as m,FormProvider as d,useFieldArray as c,useWatch as u}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 x,FormHelperText as S,FormErrorMessage as C,useMergeRefs as k,Textarea as R,PinInputField as L,chakra as V,useTheme as w,SimpleGrid as I,useStyleConfig as A}from"@chakra-ui/react";import{NumberInput as D}from"@saas-ui/number-input";import{PasswordInput as O}from"@saas-ui/password-input";import{RadioInput as j}from"@saas-ui/radio";import{Select as B,NativeSelect as U}from"@saas-ui/select";import{forwardRef as _,chakra as M}from"@chakra-ui/system";import{MinusIcon as P,AddIcon as z}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 J,useStepperContext as K,StepperStep as Q,StepperContainer as W,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 a=arguments[t];for(var l in a)Object.prototype.hasOwnProperty.call(a,l)&&(e[l]=a[l])}return e},Y.apply(this,arguments)}function Z(e,t){if(null==e)return{};var a,l,r={},n=Object.keys(e);for(l=0;l<n.length;l++)t.indexOf(a=n[l])>=0||(r[a]=e[a]);return r}const ee=["name","label","placeholder"],te=t=>{let{name:a,label:l}=t,r=Z(t,ee);/*#__PURE__*/return e.createElement(p,r,l?/*#__PURE__*/e.createElement(f,{htmlFor:a},l):null,/*#__PURE__*/e.createElement(h,{fontSize:"md"},/*#__PURE__*/e.createElement(ae,{name:a})))};t&&(te.displayName="DisplayField");const ae=({name:e})=>{const{getValues:t}=s();return t(e)||null};t&&(ae.displayName="FormValue");const le=["name","label","help","variant","hideLabel","children"],re=["id","name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],ne=["name","rules"],se=["ref"],ie=["name","rules"],oe=["ref"],me=["type","leftAddon","rightAddon","size"],de=["type"],ce=["label","type"],ue=["pinLength","pinType","spacing"],pe={},fe="text",he=t=>{const{name:a,label:l,help:r,variant:n,hideLabel:o,children:m}=t,d=Z(t,le),{formState:c}=s(),u=((e,t)=>i(t.errors,e))(a,c);/*#__PURE__*/return e.createElement(p,Y({variant:n},d,{isInvalid:!!u}),l&&!o?/*#__PURE__*/e.createElement(f,{variant:n},l):null,/*#__PURE__*/e.createElement(x,null,m,!r||null!=u&&u.message?null:/*#__PURE__*/e.createElement(S,null,r),(null==u?void 0:u.message)&&/*#__PURE__*/e.createElement(C,null,null==u?void 0:u.message)))};t&&(he.displayName="BaseField");const be=e.forwardRef((t,a)=>{const{type:l=fe}=t,r=(e=>pe[e]||pe[fe])(l);/*#__PURE__*/return e.createElement(r,Y({ref:a},t))}),ye=t=>b((a,l)=>{let{name:r,rules:n}=a,i=Z(a,ne);const{control:m}=s();/*#__PURE__*/return e.createElement(o,{name:r,control:m,rules:n,render:a=>{let{field:{ref:r}}=a,n=Z(a.field,se);/*#__PURE__*/return e.createElement(t,Y({},n,i,{ref:k(l,r)}))}})}),Ee=t=>b((a,l)=>{let{name:r,rules:n}=a,i=Z(a,ie);const{register:o}=s(),m=o(r,n),{ref:d}=m,c=Z(m,oe);/*#__PURE__*/return e.createElement(t,Y({},c,i,{ref:k(l,d)}))}),ve=(t,a,l)=>{let r;r=null!=l&&l.isControlled?ye(a):Ee(a);const n=((t,{displayName:a,hideLabel:l,BaseField:r})=>{const n=b((a,n)=>{const{id:s,name:i,label:o,help:m,isDisabled:d,isInvalid:c,isReadOnly:u,isRequired:p,rules:f,variant:h}=a,b=Z(a,re),y=Y({required:p},f);/*#__PURE__*/return e.createElement(r,{id:s,name:i,label:o,help:m,hideLabel:l,isDisabled:d,isInvalid:c,isReadOnly:u,isRequired:p,variant:h},/*#__PURE__*/e.createElement(t,Y({ref:n,id:s,name:i,label:l?o:void 0,rules:y},b)))});return n.displayName=a,n})(r,{displayName:`${t.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==l?void 0:l.hideLabel,BaseField:(null==l?void 0:l.BaseField)||he});return pe[t]=n,n},ge=ve("text",b((t,a)=>{let{type:l="text",leftAddon:r,rightAddon:n,size:s}=t,i=Z(t,me);const o=/*#__PURE__*/e.createElement(y,Y({type:l,size:s},i,{ref:a}));return r||n?/*#__PURE__*/e.createElement(E,{size:s},r,o,n):o})),Fe=ve("number",D,{isControlled:!0}),Ne=ve("password",b((t,a)=>/*#__PURE__*/e.createElement(O,Y({ref:a},t)))),xe=ve("textarea",R),Se=ve("switch",b((t,a)=>{let l=Z(t,de);/*#__PURE__*/return e.createElement(v,Y({},l,{ref:a}))}),{isControlled:!0}),Ce=ve("select",B,{isControlled:!0}),ke=ve("checkbox",b((t,a)=>{let{label:l}=t,r=Z(t,ce);/*#__PURE__*/return e.createElement(g,Y({ref:a},r),l)}),{hideLabel:!0}),Re=ve("radio",j,{isControlled:!0}),Le=ve("native-select",U,{isControlled:!0}),Ve=ve("pin",b((t,a)=>{const{pinLength:l=4,pinType:r,spacing:n}=t,s=Z(t,ue),i=[];for(let t=0;t<l;t++)i.push(/*#__PURE__*/e.createElement(L,{key:t,ref:a}));/*#__PURE__*/return e.createElement(F,{spacing:n},/*#__PURE__*/e.createElement(N,Y({},s,{type:r}),i))}),{isControlled:!0}),we=["items"],Ie=e=>e&&Object.entries(e).map(([e,t])=>Y({},Z(t,we),{name:e})),Ae=e=>({getFields:()=>Ie(e),getNestedFields:t=>{var l;const r=a(e,t);return r?"object"===(null==(l=r.items)?void 0:l.type)?Ie(r.items.properties):"object"===r.type?Ie(r.properties):[r.items]:[]}}),De=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Oe=b((t,a)=>{const{mode:r="all",resolver:n,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:c,criteriaMode:u,delayError:p,schema:f,defaultValues:h,onSubmit:b,onError:y,formRef:E,children:v}=t,g=Z(t,De),F={mode:r,resolver:n,defaultValues:h,reValidateMode:s,shouldFocusError:i,shouldUnregister:o,shouldUseNativeValidation:c,criteriaMode:u,delayError:p};f&&!n&&(F.resolver=null==Oe.getResolver?void 0:Oe.getResolver(f));const N=m(F),{handleSubmit:x}=N;return e.useImperativeHandle(a,()=>N,[a,N]),/*#__PURE__*/e.createElement(d,N,/*#__PURE__*/e.createElement(V.form,Y({ref:E,onSubmit:x(b,y)},g,{className:l("saas-form",t.className)}),v))});Oe.getFieldResolver=Ae,t&&(Oe.displayName="Form");const je=["children"],Be=({children:t})=>/*#__PURE__*/e.createElement(V.div,null,t);t&&(Be.displayName="FormLayoutItem");const Ue=t=>{var a,r,n;let{children:s}=t,i=Z(t,je);const o=Y({},null!=(a=null==(r=w().components)||null==(n=r.FormLayout)?void 0:n.defaultProps)?a:{spacing:4},i);/*#__PURE__*/return e.createElement(I,Y({},o,{className:l("saas-form__layout",i.className)}),e.Children.map(s,t=>e.isValidElement(t)?/*#__PURE__*/e.createElement(Be,null,t):t))};t&&(Ue.displayName="FormLayout");const _e=(t,a)=>e.Children.map(a,a=>e.isValidElement(a)&&a.props.name?e.cloneElement(a,Y({},a.props,{name:`${t}.${a.props.name}`})):a),[Me,Pe]=H({name:"ArrayFieldContext"}),[ze,$e]=H({name:"ArrayFieldRowContext"}),qe=({name:e,defaultValue:t={},keyName:a,min:l,max:r})=>{const{control:n}=s();return Y({},c({control:n,name:e,keyName:a}),{name:e,defaultValue:t,min:l,max:r})},He=({index:t})=>{const{clearErrors:a}=s(),{name:l,remove:r,fields:n}=Pe();return e.useEffect(()=>{a(l)},[]),{index:t,isFirst:0===t,isLast:t===n.length-1,name:`${l}.${t}`,remove:e.useCallback(()=>{a(l),r(t)},[t])}},Te=()=>{const{isFirst:e,remove:t}=$e(),{min:a,fields:l}=Pe();return{onClick:()=>t(),isDisabled:e&&!!(a&&l.length<=a)}},Ge=()=>{const{append:e,defaultValue:t,max:a,fields:l}=Pe();return{onClick:()=>e(t,{shouldFocus:!1}),isDisabled:!!(a&&l.length>=a)}},Je=["children","index"],Ke=["children"],Qe=["children"],We=["name","defaultValue","keyName","min","max","children"],Xe=t=>{let{children:a,index:l}=t,r=Z(t,Je);/*#__PURE__*/return e.createElement(Ze,{index:l},/*#__PURE__*/e.createElement(Ye,r,a),/*#__PURE__*/e.createElement(et,null))};t&&(Xe.displayName="ArrayFieldRow");const Ye=t=>{let{children:a}=t,l=Z(t,Ke);const{name:r}=$e();/*#__PURE__*/return e.createElement(Ue,Y({flex:"1",mr:"2"},l),_e(r,a))};t&&(Ye.displayName="ArrayFieldRowFields");const Ze=({children:t,index:a})=>{const l=He({index:a});/*#__PURE__*/return e.createElement(ze,{value:l},/*#__PURE__*/e.createElement(M.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(P,null),"aria-label":"Remove row"},Te(),t));t&&(et.displayName="ArrayFieldRemoveButton");const tt=t=>/*#__PURE__*/e.createElement($,Y({icon:/*#__PURE__*/e.createElement(z,null),"aria-label":"Add row",float:"right"},Ge(),t));t&&(tt.displayName="ArrayFieldAddButton");const at=_((t,a)=>{const{children:l}=t,r=Z(t,Qe);/*#__PURE__*/return e.createElement(rt,Y({ref:a},r),/*#__PURE__*/e.createElement(lt,null,t=>/*#__PURE__*/e.createElement(e.Fragment,null,t.map(({id:t},a)=>/*#__PURE__*/e.createElement(Xe,{key:t,index:a},l)))),/*#__PURE__*/e.createElement(tt,null))});t&&(at.displayName="ArrayField");const lt=({children:e})=>{const{fields:t}=Pe();return e(t)};t&&(lt.displayName="ArrayFieldRows");const rt=e.forwardRef((t,a)=>{let{name:l,defaultValue:r,keyName:n,min:s,max:i,children:o}=t,m=Z(t,We);const d=qe({name:l,defaultValue:r,keyName:n,min:s,max:i});return e.useImperativeHandle(a,()=>d,[a,d]),/*#__PURE__*/e.createElement(Me,{value:d},/*#__PURE__*/e.createElement(he,Y({name:l},m),o))});t&&(rt.displayName="ArrayFieldContainer");const nt=["name","label","hideLabel","children","columns","spacing"],st=t=>{const a=A("FormLegend");/*#__PURE__*/return e.createElement(f,Y({as:"legend",sx:a},t))},it=t=>{const{name:a,label:l,hideLabel:r,children:n,columns:s,spacing:i}=t,o=Z(t,nt);/*#__PURE__*/return e.createElement(p,Y({name:a,as:"fieldset"},o),/*#__PURE__*/e.createElement(st,{display:r?"none":"block"},l),/*#__PURE__*/e.createElement(Ue,{columns:s,gridGap:i},_e(a,n)))};t&&(it.displayName="ObjectField");const ot=["name","type"],mt=["schema","fieldResolver"],dt=["name","type","defaultValue"],ct=(t,a)=>{var l;return null==(l=t.getNestedFields(a))?void 0:l.map((t,a)=>{let{name:l,type:r}=t,n=Z(t,ot);/*#__PURE__*/return e.createElement(be,Y({key:l||a,name:l,type:r},n))})},ut=t=>{let{schema:a,fieldResolver:l}=t,r=Z(t,mt);const n=e.useMemo(()=>l||Oe.getFieldResolver(a),[a,l]);/*#__PURE__*/return e.createElement(Ue,r,n.getFields().map(t=>{let{name:a,type:l}=t,r=Z(t,dt);return"array"===l?/*#__PURE__*/e.createElement(at,Y({key:a,name:a},r),ct(n,a)):"object"===l?/*#__PURE__*/e.createElement(it,Y({key:a,name:a},r),ct(n,a)):/*#__PURE__*/e.createElement(be,Y({key:a,name:a,type:l},r))}))};t&&(ut.displayName="Fields");const pt=["children","disableIfUntouched","disableIfInvalid","isDisabled","isLoading"],ft=e.forwardRef((t,a)=>{const{children:l,disableIfUntouched:r,disableIfInvalid:n,isDisabled:i,isLoading:o}=t,m=Z(t,pt),{formState:d}=s();/*#__PURE__*/return e.createElement(q,Y({},m,{ref:a,variant:"primary",type:"submit",isLoading:d.isSubmitting||o,isDisabled:r&&!d.isDirty||n&&!d.isValid||i}),l)});ft.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1},t&&(ft.displayName="SubmitButton");const ht=["schema","submitLabel","fieldResolver","children"],bt=b((t,a)=>{const{schema:l,submitLabel:r="Submit",fieldResolver:n,children:s}=t,i=Z(t,ht);/*#__PURE__*/return e.createElement(Oe,Y({},i,{schema:l,ref:a}),/*#__PURE__*/e.createElement(Ue,null,/*#__PURE__*/e.createElement(ut,{schema:l,fieldResolver:n}),r&&/*#__PURE__*/e.createElement(ft,null,r),s))});t&&(bt.displayName="AutoForm");const yt=({children:e,name:t,defaultValue:a,isDisabled:l,isExact:r,condition:n=(e=>!!e)})=>n(u({name:t,defaultValue:a,disabled:l,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 a=Z(t,Et),l=T(a),{activeStep:r,isLastStep:n,nextStep:s}=l,[i,o]=e.useState({}),m=e.useCallback(async e=>{const a=i[r];if(n)return null==t.onSubmit?void 0:t.onSubmit(e).then(()=>{c(Y({},a,{isCompleted:!0}))}).then(s);try{await(null==a.onSubmit?void 0:a.onSubmit(e,l)),s()}catch(e){}},[i,r,n]),d=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]),c=e.useCallback(e=>{o(t=>Y({},t,{[e.name]:e}))},[i]);return Y({getFormProps:d,updateStep:c,steps:i},l)}function Nt(t){const{name:a,schema:l,resolver:r,onSubmit:n}=t,s=G({name:a}),{steps:i,updateStep:o}=gt();return e.useEffect(()=>{o({name:a,schema:l,resolver:r,onSubmit:n})},[a,l]),Y({},s,i[a]||{name:a,schema:l})}const xt=["children"],St=["getFormProps"],Ct=["name","schema","resolver","children","className","onSubmit"],kt=["label","submitLabel"],Rt=e.forwardRef((t,a)=>{const{children:l}=t,n=Z(t,xt),s=Ft(t),{getFormProps:i}=s,o=Z(s,St),m=e.useMemo(()=>o,[o]);/*#__PURE__*/return e.createElement(J,{value:m},/*#__PURE__*/e.createElement(vt,{value:m},/*#__PURE__*/e.createElement(Oe,Y({ref:a},n,i()),r(l,s))))}),Lt=t=>{const{activeIndex:a,setIndex:l}=K(),{children:r,orientation:n}=t,s=e.Children.map(r,t=>{if(e.isValidElement(t)&&(null==t?void 0:t.type)===Vt){const{isCompleted:a}=Nt(t.props);/*#__PURE__*/return e.createElement(Q,{name:t.props.name,title:t.props.title,isCompleted:a},t.props.children)}return t}),i=e.useCallback(e=>{l(e)},[]);/*#__PURE__*/return e.createElement(W,{orientation:n,step:a,onChange:i},/*#__PURE__*/e.createElement(X,Y({mb:"4"},t),s))},Vt=t=>{const{name:a,schema:r,resolver:n,children:s,className:i,onSubmit:o}=t,m=Z(t,Ct),d=Nt({name:a,schema:r,resolver:n,onSubmit:o}),{isActive:c}=d;return c?/*#__PURE__*/e.createElement(M.div,Y({},m,{className:l("saas-form__step",i)}),s):null};t&&(Vt.displayName="FormStep");const wt=t=>{const{isFirstStep:a,isCompleted:r,prevStep:s}=K();/*#__PURE__*/return e.createElement(q,Y({isDisabled:a||r,label:"Back"},t,{className:l("saas-form__prev-button",t.className),onClick:n(t.onClick,s)}))};t&&(wt.displayName="PrevButton");const It=t=>{const{label:a="Next",submitLabel:r="Complete"}=t,n=Z(t,kt),{isLastStep:s,isCompleted:i}=K();/*#__PURE__*/return e.createElement(ft,Y({},n,{isDisabled:i,className:l("saas-form__next-button",t.className)}),s||i?r:a)};t&&(It.displayName="NextButton");export{at as ArrayField,tt as ArrayFieldAddButton,rt as ArrayFieldContainer,Me as ArrayFieldProvider,et as ArrayFieldRemoveButton,Xe as ArrayFieldRow,Ze as ArrayFieldRowContainer,Ye as ArrayFieldRowFields,ze as ArrayFieldRowProvider,lt as ArrayFieldRows,bt as AutoForm,he as BaseField,ke as CheckboxField,te as DisplayField,yt as DisplayIf,be as Field,ut as Fields,Oe as Form,Ue as FormLayout,st as FormLegend,Vt as FormStep,Lt as FormStepper,ae as FormValue,ge as InputField,Le as NativeSelectField,It as NextButton,Fe as NumberInputField,it as ObjectField,Ne as PasswordInputField,Ve as PinField,wt as PrevButton,Re as RadioField,Ce as SelectField,Rt as StepForm,vt as StepFormProvider,ft as SubmitButton,Se as SwitchField,xe as TextareaField,Ae as objectFieldResolver,ve as registerFieldType,qe as useArrayField,Ge as useArrayFieldAddButton,Pe as useArrayFieldContext,Te as useArrayFieldRemoveButton,He as useArrayFieldRow,$e as useArrayFieldRowContext,Nt as useFormStep,Ft as useStepForm,gt as useStepFormContext,ye as withControlledInput,Ee as withUncontrolledInput};
|
2
2
|
//# sourceMappingURL=index.modern.mjs.map
|