@saas-ui/forms 0.3.1 → 0.3.4

Sign up to get free protection for your applications and to get access to all the features.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # @saas-ui/forms
2
2
 
3
+ ## 0.3.4
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies [16c82e6]
8
+ - @saas-ui/password-input@0.2.2
9
+
10
+ ## 0.3.3
11
+
12
+ ### Patch Changes
13
+
14
+ - a6842fd: Re-export UseFormReturn
15
+ - d3da8ef: Don't set isRequired when required is true
16
+ - 1ce9ba9: Improved ObjectField semantics and styles
17
+
18
+ ## 0.3.2
19
+
20
+ ### Patch Changes
21
+
22
+ - Updated dependencies [676eefa]
23
+ - @saas-ui/select@0.2.2
24
+
3
25
  ## 0.3.1
4
26
 
5
27
  ### Patch Changes
@@ -1 +1 @@
1
- {"version":3,"file":"field.d.ts","sourceRoot":"","sources":["../src/field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAKL,eAAe,EACf,WAAW,EACX,SAAS,EACV,MAAM,iBAAiB,CAAA;AAExB,OAAO,EAGL,WAAW,EACX,gBAAgB,EASjB,MAAM,kBAAkB,CAAA;AAQzB,MAAM,WAAW,MAAM;IACrB,KAAK,EAAE,MAAM,CAAA;IACb,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAAA;CACvB;AAED,oBAAY,UAAU,GAAG,IAAI,CAC3B,eAAe,EACf,UAAU,GAAG,KAAK,GAAG,KAAK,GAAG,WAAW,GAAG,WAAW,GAAG,SAAS,CACnE,CAAA;AAED,oBAAY,UAAU,GAClB,MAAM,GACN,QAAQ,GACR,UAAU,GACV,UAAU,GACV,QAAQ,GACR,eAAe,GACf,UAAU,GACV,OAAO,GACP,QAAQ,GACR,KAAK,GACL,MAAM,CAAA;AAEV,MAAM,WAAW,UAAU,CACzB,YAAY,SAAS,WAAW,GAAG,WAAW,EAC9C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AO,MAAM,UAAU,kJAErB,CAAA;AACF,eAAO,MAAM,QAAQ,kJAEnB,CAAA;AACF,eAAO,MAAM,iBAAiB,kJAI7B,CAAA"}
package/dist/form.d.ts CHANGED
@@ -1,6 +1,7 @@
1
1
  import * as React from 'react';
2
2
  import { HTMLChakraProps } from '@chakra-ui/react';
3
3
  import { UseFormProps, UseFormReturn, FieldValues, SubmitHandler, SubmitErrorHandler } from 'react-hook-form';
4
+ export type { UseFormReturn };
4
5
  interface FormOptions<TFieldValues extends FieldValues = FieldValues> {
5
6
  /**
6
7
  * The form schema, currently supports Yup schema only.
@@ -28,5 +29,4 @@ export interface FormProps<TFieldValues extends FieldValues = FieldValues> exten
28
29
  export declare const Form: <TFieldValues extends FieldValues>(props: FormProps<TFieldValues> & {
29
30
  ref?: React.ForwardedRef<UseFormReturn<TFieldValues, object>> | undefined;
30
31
  }) => React.ReactElement;
31
- export {};
32
32
  //# sourceMappingURL=form.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,eAAe,EAAc,MAAM,kBAAkB,CAAA;AAEtE,OAAO,EAGL,YAAY,EACZ,aAAa,EACb,WAAW,EACX,aAAa,EACb,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AAIxB,UAAU,WAAW,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW;IAClE;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ;;OAEG;IACH,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,CAAA;IACrC;;OAEG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAA;IAC1C;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAA;CAClD;AAED,MAAM,WAAW,SAAS,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,CACvE,SAAQ,YAAY,CAAC,YAAY,CAAC,EAChC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,EACrD,WAAW,CAAC,YAAY,CAAC;CAAG;AAEhC;;;GAGG;AACH,eAAO,MAAM,IAAI;;MA8DZ,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"form.d.ts","sourceRoot":"","sources":["../src/form.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B,OAAO,EAAU,eAAe,EAAc,MAAM,kBAAkB,CAAA;AAEtE,OAAO,EAGL,YAAY,EACZ,aAAa,EACb,WAAW,EACX,aAAa,EACb,kBAAkB,EACnB,MAAM,iBAAiB,CAAA;AAIxB,YAAY,EAAE,aAAa,EAAE,CAAA;AAE7B,UAAU,WAAW,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW;IAClE;;OAEG;IACH,MAAM,CAAC,EAAE,GAAG,CAAA;IACZ;;OAEG;IACH,QAAQ,EAAE,aAAa,CAAC,YAAY,CAAC,CAAA;IACrC;;OAEG;IACH,OAAO,CAAC,EAAE,kBAAkB,CAAC,YAAY,CAAC,CAAA;IAC1C;;OAEG;IACH,OAAO,CAAC,EAAE,KAAK,CAAC,gBAAgB,CAAC,eAAe,CAAC,CAAA;CAClD;AAED,MAAM,WAAW,SAAS,CAAC,YAAY,SAAS,WAAW,GAAG,WAAW,CACvE,SAAQ,YAAY,CAAC,YAAY,CAAC,EAChC,IAAI,CAAC,eAAe,CAAC,MAAM,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,EACrD,WAAW,CAAC,YAAY,CAAC;CAAG;AAEhC;;;GAGG;AACH,eAAO,MAAM,IAAI;;MA8DZ,MAAM,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -1,2 +1,2 @@
1
- var e=require("react"),r=require("react-hook-form"),t=require("@chakra-ui/react"),n=require("@saas-ui/number-input"),a=require("@saas-ui/password-input"),l=require("@saas-ui/radio"),i=require("@saas-ui/pin-input"),o=require("@saas-ui/select"),u=require("yup"),s=require("@hookform/resolvers/yup"),c=require("@chakra-ui/system"),d=require("@chakra-ui/icons"),m=require("@saas-ui/button"),f=require("@chakra-ui/react-utils"),p=require("@saas-ui/input-right-button");function v(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 h=/*#__PURE__*/v(e);function b(){return b=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},b.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}function y(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}var E=["name","label","placeholder"],F=["name","label","help","variant","hideLabel","children"],g=["name","label","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],w=["name","rules"],C=["ref"],I=["name","rules"],R=["ref"],A=["label"],k=["label"],S={},O=function(e){var n=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,u=e.children,s=x(e,F),c=function(e,t){return r.get(t.errors,e)}(n,r.useFormContext().formState);/*#__PURE__*/return h.createElement(t.FormControl,b({variant:i},s,{isInvalid:!!c}),a&&!o?/*#__PURE__*/h.createElement(t.FormLabel,{variant:i},a):null,/*#__PURE__*/h.createElement(t.Box,null,u,!l||null!=c&&c.message?null:/*#__PURE__*/h.createElement(t.FormHelperText,null,l),(null==c?void 0:c.message)&&/*#__PURE__*/h.createElement(t.FormErrorMessage,null,null==c?void 0:c.message)))},V=t.forwardRef(function(e,r){var t=e.type;/*#__PURE__*/return h.createElement(S[void 0===t?"text":t]||S.text,b({ref:r},e))}),q=function(e){return t.forwardRef(function(n,a){var l=n.name,i=n.rules,o=x(n,w),u=r.useFormContext();/*#__PURE__*/return h.createElement(r.Controller,{name:l,control:u.control,rules:i,render:function(r){var n=r.field,l=n.ref,i=x(n,C);/*#__PURE__*/return h.createElement(e,b({},i,o,{ref:t.useMergeRefs(a,l)}))}})})},j=function(e){return t.forwardRef(function(n,a){var l=n.name,i=n.rules,o=x(n,I),u=(0,r.useFormContext().register)(l,i),s=u.ref,c=x(u,R);/*#__PURE__*/return h.createElement(e,b({},c,o,{ref:t.useMergeRefs(a,s)}))})},N=function(e,r,n){var a=function(e,r){var n=r.displayName,a=r.hideLabel,l=r.BaseField,i=t.forwardRef(function(r,t){var n=r.name,i=r.label,o=r.isDisabled,u=r.isInvalid,s=r.isReadOnly,c=r.isRequired,d=r.rules,m=r.variant,f=x(r,g),p=b({required:c},d);/*#__PURE__*/return h.createElement(l,{name:n,label:i,hideLabel:a,isDisabled:o,isInvalid:u,isReadOnly:s,isRequired:p.required,variant:m},/*#__PURE__*/h.createElement(e,b({ref:t,name:n,label:i,rules:p},f)))});return i.displayName=n,i}(null!=n&&n.isControlled?q(r):j(r),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||O});return S[e]=a,a},P=N("text",t.Input),L=N("number",n.NumberInput,{isControlled:!0}),B=N("password",a.PasswordInput),D=N("textarea",t.Textarea),M=N("switch",t.forwardRef(function(e,r){var n=e.label,a=x(e,A);/*#__PURE__*/return h.createElement(t.Switch,b({ref:r},a),n)}),{isControlled:!0,hideLabel:!0}),U=N("select",o.Select,{isControlled:!0}),T=N("checkbox",t.forwardRef(function(e,r){var n=e.label,a=x(e,k);/*#__PURE__*/return h.createElement(t.Checkbox,b({ref:r},a),n)}),{hideLabel:!0}),_=N("radio",l.RadioInput,{isControlled:!0}),G=N("pin",i.PinInput,{isControlled:!0}),H=N("native-select",o.NativeSelect,{isControlled:!0}),z=function(e){var r;if(null!=(r=e.spec.meta)&&r.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},W=function(e,r){for(var t,n=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return y(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?y(e,r):void 0}}(e))){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.tests);!(t=n()).done;){var a,l=t.value;if(null!=(a=l.OPTIONS)&&a.params[r])return l.OPTIONS.params[r]}},$=function(e){var r,t=[];for(var n in r="array"===e.type?e.innerType.fields:e.fields){var a=r[n],l={};"array"===a.type&&(l.min=W(a,"min"),l.max=W(a,"max")),t.push(b({name:n,label:a.spec.label||n,type:z(a)},l))}return t},J=["children"],K=function(e){/*#__PURE__*/return h.createElement(t.chakra.div,null,e.children)},Q=function(e){var r,n,a,l=e.children,i=x(e,J),o=b({},null!=(r=null==(n=t.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?r:{spacing:4},i);/*#__PURE__*/return h.createElement(t.SimpleGrid,o,h.Children.map(l,function(e){return h.isValidElement(e)?/*#__PURE__*/h.createElement(K,null,e):e}))},X=function(e,r){return h.Children.map(r,function(r){return h.isValidElement(r)&&r.props.name?h.cloneElement(r,b({},r.props,{name:e+"."+r.props.name})):r})},Y=f.createContext({name:"ArrayFieldContext"}),Z=Y[0],ee=Y[1],re=f.createContext({name:"ArrayFieldRowContext"}),te=re[0],ne=re[1],ae=function(e){var t=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,u=r.useFormContext();return b({},r.useFieldArray({control:u.control,name:t,keyName:l}),{name:t,defaultValue:a,min:i,max:o})},le=function(e){var t=e.index,n=r.useFormContext().clearErrors,a=ee(),l=a.name,i=a.remove,o=a.fields;return h.useEffect(function(){n(l)},[]),{index:t,isFirst:0===t,isLast:t===o.length-1,name:l+"."+t,remove:h.useCallback(function(){n(l),i(t)},[t])}},ie=function(){var e=ne(),r=e.isFirst,t=e.remove,n=ee(),a=n.min;return{onClick:function(){return t()},isDisabled:r&&!!(a&&n.fields.length<=a)}},oe=function(){var e=ee(),r=e.append,t=e.defaultValue,n=e.max;return{onClick:function(){return r(t,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},ue=["children","columns","spacing"],se=["children"],ce=["name","defaultValue","keyName","min","max","children"],de=function(e){/*#__PURE__*/return h.createElement(fe,{index:e.index},/*#__PURE__*/h.createElement(me,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/h.createElement(pe,null))},me=function(e){var r=e.children,t=e.columns,n=e.spacing,a=x(e,ue),l=ne().name;/*#__PURE__*/return h.createElement(Q,b({flex:"1",columns:t,gridGap:n,mr:"2"},a),X(l,r))},fe=function(e){var r=e.children,t=le({index:e.index});/*#__PURE__*/return h.createElement(te,{value:t},/*#__PURE__*/h.createElement(c.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))},pe=function(e){/*#__PURE__*/return h.createElement(m.IconButton,b({icon:/*#__PURE__*/h.createElement(d.MinusIcon,null),"aria-label":"Remove row"},ie(),e))},ve=function(e){/*#__PURE__*/return h.createElement(m.IconButton,b({icon:/*#__PURE__*/h.createElement(d.AddIcon,null),"aria-label":"Add row",float:"right"},oe(),e))},he=function(e){var r=e.children,t=x(e,se);/*#__PURE__*/return h.createElement(xe,t,/*#__PURE__*/h.createElement(be,null,function(e){/*#__PURE__*/return h.createElement(h.Fragment,null,e.map(function(e,t){/*#__PURE__*/return h.createElement(de,{key:e.id,index:t},r)}))}),/*#__PURE__*/h.createElement(ve,null))},be=function(e){return(0,e.children)(ee().fields)},xe=function(e){var r=e.name,t=e.defaultValue,n=e.keyName,a=e.min,l=e.max,i=e.children,o=x(e,ce),u=ae({name:r,defaultValue:t,keyName:n,min:a,max:l});/*#__PURE__*/return h.createElement(Z,{value:u},/*#__PURE__*/h.createElement(O,b({name:r},o),i))},ye=["name","children","columns","spacing"],Ee=function(e){var r=e.name,t=e.children,n=e.columns,a=e.spacing,l=x(e,ye);/*#__PURE__*/return h.createElement(O,b({name:r},l),/*#__PURE__*/h.createElement(Q,{columns:n,gridGap:a},X(r,t)))},Fe=["name","type"],ge=["schema"],we=["name","type","defaultValue"],Ce=function(e,r){return $(function(e,r){return u.reach(e,r)}(e,r)).map(function(e){var r=e.name,t=e.type,n=x(e,Fe);/*#__PURE__*/return h.createElement(V,b({key:r,name:r,type:t},n))})},Ie=function(e){var r=e.schema,t=x(e,ge);/*#__PURE__*/return h.createElement(Q,t,$(r).map(function(e){var t=e.name,n=e.type,a=x(e,we);return"array"===n?/*#__PURE__*/h.createElement(he,b({name:t},a),Ce(r,t)):"object"===n?/*#__PURE__*/h.createElement(Ee,b({name:t},a),Ce(r,t)):/*#__PURE__*/h.createElement(V,b({key:t,name:t,type:n},a))}))},Re=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Ae=t.forwardRef(function(e,n){var a=e.mode,l=void 0===a?"all":a,i=e.resolver,o=e.reValidateMode,u=e.shouldFocusError,c=e.shouldUnregister,d=e.shouldUseNativeValidation,m=e.criteriaMode,f=e.delayError,p=e.schema,v=e.defaultValues,y=e.onSubmit,E=e.onError,F=e.formRef,g=e.children,w=x(e,Re),C={mode:l,resolver:i,defaultValues:v,reValidateMode:o,shouldFocusError:u,shouldUnregister:c,shouldUseNativeValidation:d,criteriaMode:m,delayError:f};p&&(C.resolver=s.yupResolver(p));var I=r.useForm(C),R=I.handleSubmit;return h.useImperativeHandle(n,function(){return I},[n,I]),/*#__PURE__*/h.createElement(r.FormProvider,I,/*#__PURE__*/h.createElement(t.chakra.form,b({ref:F,onSubmit:R(y,E)},w),g))}),ke=["children","disableIfUntouched","disableIfInvalid"],Se=c.forwardRef(function(e,t){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=x(e,ke),o=r.useFormContext().formState;/*#__PURE__*/return h.createElement(m.Button,b({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:t,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});Se.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var Oe=["schema","submitLabel"],Ve=t.forwardRef(function(e,r){var t=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=x(e,Oe);/*#__PURE__*/return h.createElement(Ae,b({},l,{schema:t,ref:r}),/*#__PURE__*/h.createElement(Q,null,/*#__PURE__*/h.createElement(Ie,{schema:t}),a&&/*#__PURE__*/h.createElement(Se,{label:a})))});exports.ArrayField=he,exports.ArrayFieldAddButton=ve,exports.ArrayFieldContainer=xe,exports.ArrayFieldProvider=Z,exports.ArrayFieldRemoveButton=pe,exports.ArrayFieldRow=de,exports.ArrayFieldRowContainer=fe,exports.ArrayFieldRowFields=me,exports.ArrayFieldRowProvider=te,exports.ArrayFieldRows=be,exports.AutoForm=Ve,exports.BaseField=O,exports.CheckboxField=T,exports.DisplayField=function(e){var n=e.name,a=e.label,l=x(e,E),i=r.useFormContext().getValues;/*#__PURE__*/return h.createElement(t.FormControl,l,a?/*#__PURE__*/h.createElement(t.FormLabel,{htmlFor:n},a):null,/*#__PURE__*/h.createElement(t.Text,{fontSize:"md"},i(n)))},exports.DisplayIf=function(e){var t=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(r.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),r.useFormContext())?t:null},exports.Field=V,exports.Fields=Ie,exports.Form=Ae,exports.FormLayout=Q,exports.InputField=P,exports.NativeSelectField=H,exports.NumberInputField=L,exports.ObjectField=Ee,exports.PasswordInputFIeld=B,exports.PinField=G,exports.RadioField=_,exports.SelectField=U,exports.SubmitButton=Se,exports.SwitchField=M,exports.TextareaField=D,exports.registerFieldType=N,exports.useArrayField=ae,exports.useArrayFieldAddButton=oe,exports.useArrayFieldContext=ee,exports.useArrayFieldRemoveButton=ie,exports.useArrayFieldRow=le,exports.useArrayFieldRowContext=ne,exports.withControlledInput=q,exports.withUncontrolledInput=j,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("react-hook-form"),t=require("@chakra-ui/react"),n=require("@saas-ui/number-input"),a=require("@saas-ui/password-input"),l=require("@saas-ui/radio"),i=require("@saas-ui/pin-input"),o=require("@saas-ui/select"),u=require("yup"),s=require("@hookform/resolvers/yup"),c=require("@chakra-ui/system"),d=require("@chakra-ui/icons"),m=require("@saas-ui/button"),f=require("@chakra-ui/react-utils"),p=require("@saas-ui/input-right-button");function v(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 h=/*#__PURE__*/v(e);function b(){return b=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&(e[n]=t[n])}return e},b.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}function y(e,r){(null==r||r>e.length)&&(r=e.length);for(var t=0,n=new Array(r);t<r;t++)n[t]=e[t];return n}var F=["name","label","placeholder"],E=["name","label","help","variant","hideLabel","children"],g=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],w=["name","rules"],C=["ref"],I=["name","rules"],R=["ref"],A=["label"],k=["label"],S={},O=function(e){var n=e.name,a=e.label,l=e.help,i=e.variant,o=e.hideLabel,u=e.children,s=x(e,E),c=function(e,t){return r.get(t.errors,e)}(n,r.useFormContext().formState);/*#__PURE__*/return h.createElement(t.FormControl,b({variant:i},s,{isInvalid:!!c}),a&&!o?/*#__PURE__*/h.createElement(t.FormLabel,{variant:i},a):null,/*#__PURE__*/h.createElement(t.Box,null,u,!l||null!=c&&c.message?null:/*#__PURE__*/h.createElement(t.FormHelperText,null,l),(null==c?void 0:c.message)&&/*#__PURE__*/h.createElement(t.FormErrorMessage,null,null==c?void 0:c.message)))},V=t.forwardRef(function(e,r){var t=e.type;/*#__PURE__*/return h.createElement(S[void 0===t?"text":t]||S.text,b({ref:r},e))}),L=function(e){return t.forwardRef(function(n,a){var l=n.name,i=n.rules,o=x(n,w),u=r.useFormContext();/*#__PURE__*/return h.createElement(r.Controller,{name:l,control:u.control,rules:i,render:function(r){var n=r.field,l=n.ref,i=x(n,C);/*#__PURE__*/return h.createElement(e,b({},i,o,{ref:t.useMergeRefs(a,l)}))}})})},q=function(e){return t.forwardRef(function(n,a){var l=n.name,i=n.rules,o=x(n,I),u=(0,r.useFormContext().register)(l,i),s=u.ref,c=x(u,R);/*#__PURE__*/return h.createElement(e,b({},c,o,{ref:t.useMergeRefs(a,s)}))})},j=function(e,r,n){var a=function(e,r){var n=r.displayName,a=r.hideLabel,l=r.BaseField,i=t.forwardRef(function(r,t){var n=r.name,i=r.label,o=r.help,u=r.isDisabled,s=r.isInvalid,c=r.isReadOnly,d=r.isRequired,m=r.rules,f=r.variant,p=x(r,g),v=b({required:d},m);/*#__PURE__*/return h.createElement(l,{name:n,label:i,help:o,hideLabel:a,isDisabled:u,isInvalid:s,isReadOnly:c,isRequired:d,variant:f},/*#__PURE__*/h.createElement(e,b({ref:t,name:n,label:i,rules:v},p)))});return i.displayName=n,i}(null!=n&&n.isControlled?L(r):q(r),{displayName:e.split("-").map(function(e){return e.charAt(0).toUpperCase()+e.slice(1)}).join("")+"Field",hideLabel:null==n?void 0:n.hideLabel,BaseField:(null==n?void 0:n.BaseField)||O});return S[e]=a,a},N=j("text",t.Input),P=j("number",n.NumberInput,{isControlled:!0}),B=j("password",a.PasswordInput),D=j("textarea",t.Textarea),M=j("switch",t.forwardRef(function(e,r){var n=e.label,a=x(e,A);/*#__PURE__*/return h.createElement(t.Switch,b({ref:r},a),n)}),{isControlled:!0,hideLabel:!0}),U=j("select",o.Select,{isControlled:!0}),T=j("checkbox",t.forwardRef(function(e,r){var n=e.label,a=x(e,k);/*#__PURE__*/return h.createElement(t.Checkbox,b({ref:r},a),n)}),{hideLabel:!0}),_=j("radio",l.RadioInput,{isControlled:!0}),G=j("pin",i.PinInput,{isControlled:!0}),H=j("native-select",o.NativeSelect,{isControlled:!0}),z=function(e){var r;if(null!=(r=e.spec.meta)&&r.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},W=function(e,r){for(var t,n=function(e,r){var t="undefined"!=typeof Symbol&&e[Symbol.iterator]||e["@@iterator"];if(t)return(t=t.call(e)).next.bind(t);if(Array.isArray(e)||(t=function(e,r){if(e){if("string"==typeof e)return y(e,r);var t=Object.prototype.toString.call(e).slice(8,-1);return"Object"===t&&e.constructor&&(t=e.constructor.name),"Map"===t||"Set"===t?Array.from(e):"Arguments"===t||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t)?y(e,r):void 0}}(e))){t&&(e=t);var n=0;return function(){return n>=e.length?{done:!0}:{done:!1,value:e[n++]}}}throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}(e.tests);!(t=n()).done;){var a,l=t.value;if(null!=(a=l.OPTIONS)&&a.params[r])return l.OPTIONS.params[r]}},$=function(e){var r,t=[];for(var n in r="array"===e.type?e.innerType.fields:e.fields){var a=r[n],l={};"array"===a.type&&(l.min=W(a,"min"),l.max=W(a,"max")),t.push(b({name:n,label:a.spec.label||n,type:z(a)},l))}return t},J=["children"],K=function(e){/*#__PURE__*/return h.createElement(t.chakra.div,null,e.children)},Q=function(e){var r,n,a,l=e.children,i=x(e,J),o=b({},null!=(r=null==(n=t.useTheme().components)||null==(a=n.FormLayout)?void 0:a.defaultProps)?r:{spacing:4},i);/*#__PURE__*/return h.createElement(t.SimpleGrid,o,h.Children.map(l,function(e){return h.isValidElement(e)?/*#__PURE__*/h.createElement(K,null,e):e}))},X=function(e,r){return h.Children.map(r,function(r){return h.isValidElement(r)&&r.props.name?h.cloneElement(r,b({},r.props,{name:e+"."+r.props.name})):r})},Y=f.createContext({name:"ArrayFieldContext"}),Z=Y[0],ee=Y[1],re=f.createContext({name:"ArrayFieldRowContext"}),te=re[0],ne=re[1],ae=function(e){var t=e.name,n=e.defaultValue,a=void 0===n?{}:n,l=e.keyName,i=e.min,o=e.max,u=r.useFormContext();return b({},r.useFieldArray({control:u.control,name:t,keyName:l}),{name:t,defaultValue:a,min:i,max:o})},le=function(e){var t=e.index,n=r.useFormContext().clearErrors,a=ee(),l=a.name,i=a.remove,o=a.fields;return h.useEffect(function(){n(l)},[]),{index:t,isFirst:0===t,isLast:t===o.length-1,name:l+"."+t,remove:h.useCallback(function(){n(l),i(t)},[t])}},ie=function(){var e=ne(),r=e.isFirst,t=e.remove,n=ee(),a=n.min;return{onClick:function(){return t()},isDisabled:r&&!!(a&&n.fields.length<=a)}},oe=function(){var e=ee(),r=e.append,t=e.defaultValue,n=e.max;return{onClick:function(){return r(t,{shouldFocus:!1})},isDisabled:!!(n&&e.fields.length>=n)}},ue=["children","columns","spacing"],se=["children"],ce=["name","defaultValue","keyName","min","max","children"],de=function(e){/*#__PURE__*/return h.createElement(fe,{index:e.index},/*#__PURE__*/h.createElement(me,{columns:e.columns,spacing:e.spacing},e.children),/*#__PURE__*/h.createElement(pe,null))},me=function(e){var r=e.children,t=e.columns,n=e.spacing,a=x(e,ue),l=ne().name;/*#__PURE__*/return h.createElement(Q,b({flex:"1",columns:t,gridGap:n,mr:"2"},a),X(l,r))},fe=function(e){var r=e.children,t=le({index:e.index});/*#__PURE__*/return h.createElement(te,{value:t},/*#__PURE__*/h.createElement(c.chakra.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))},pe=function(e){/*#__PURE__*/return h.createElement(m.IconButton,b({icon:/*#__PURE__*/h.createElement(d.MinusIcon,null),"aria-label":"Remove row"},ie(),e))},ve=function(e){/*#__PURE__*/return h.createElement(m.IconButton,b({icon:/*#__PURE__*/h.createElement(d.AddIcon,null),"aria-label":"Add row",float:"right"},oe(),e))},he=function(e){var r=e.children,t=x(e,se);/*#__PURE__*/return h.createElement(xe,t,/*#__PURE__*/h.createElement(be,null,function(e){/*#__PURE__*/return h.createElement(h.Fragment,null,e.map(function(e,t){/*#__PURE__*/return h.createElement(de,{key:e.id,index:t},r)}))}),/*#__PURE__*/h.createElement(ve,null))},be=function(e){return(0,e.children)(ee().fields)},xe=function(e){var r=e.name,t=e.defaultValue,n=e.keyName,a=e.min,l=e.max,i=e.children,o=x(e,ce),u=ae({name:r,defaultValue:t,keyName:n,min:a,max:l});/*#__PURE__*/return h.createElement(Z,{value:u},/*#__PURE__*/h.createElement(O,b({name:r},o),i))},ye=["name","label","hideLabel","children","columns","spacing"],Fe=function(e){var r=t.useStyles();/*#__PURE__*/return h.createElement(t.FormLabel,b({as:"legend",sx:r.legend},e))},Ee=function(e){var r=e.name,n=e.label,a=e.hideLabel,l=e.children,i=e.columns,o=e.spacing,u=x(e,ye);/*#__PURE__*/return h.createElement(t.FormControl,b({name:r,as:"fieldset"},u),/*#__PURE__*/h.createElement(Fe,{display:a?"none":"block"},n),/*#__PURE__*/h.createElement(Q,{columns:i,gridGap:o},X(r,l)))},ge=["name","type"],we=["schema"],Ce=["name","type","defaultValue"],Ie=function(e,r){return $(function(e,r){return u.reach(e,r)}(e,r)).map(function(e){var r=e.name,t=e.type,n=x(e,ge);/*#__PURE__*/return h.createElement(V,b({key:r,name:r,type:t},n))})},Re=function(e){var r=e.schema,t=x(e,we);/*#__PURE__*/return h.createElement(Q,t,$(r).map(function(e){var t=e.name,n=e.type,a=x(e,Ce);return"array"===n?/*#__PURE__*/h.createElement(he,b({name:t},a),Ie(r,t)):"object"===n?/*#__PURE__*/h.createElement(Ee,b({name:t},a),Ie(r,t)):/*#__PURE__*/h.createElement(V,b({key:t,name:t,type:n},a))}))},Ae=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],ke=t.forwardRef(function(e,n){var a=e.mode,l=void 0===a?"all":a,i=e.resolver,o=e.reValidateMode,u=e.shouldFocusError,c=e.shouldUnregister,d=e.shouldUseNativeValidation,m=e.criteriaMode,f=e.delayError,p=e.schema,v=e.defaultValues,y=e.onSubmit,F=e.onError,E=e.formRef,g=e.children,w=x(e,Ae),C={mode:l,resolver:i,defaultValues:v,reValidateMode:o,shouldFocusError:u,shouldUnregister:c,shouldUseNativeValidation:d,criteriaMode:m,delayError:f};p&&(C.resolver=s.yupResolver(p));var I=r.useForm(C),R=I.handleSubmit;return h.useImperativeHandle(n,function(){return I},[n,I]),/*#__PURE__*/h.createElement(r.FormProvider,I,/*#__PURE__*/h.createElement(t.chakra.form,b({ref:E,onSubmit:R(y,F)},w),g))}),Se=["children","disableIfUntouched","disableIfInvalid"],Oe=c.forwardRef(function(e,t){var n=e.children,a=e.disableIfUntouched,l=e.disableIfInvalid,i=x(e,Se),o=r.useFormContext().formState;/*#__PURE__*/return h.createElement(m.Button,b({type:"submit",isLoading:o.isSubmitting,isPrimary:!0,ref:t,isDisabled:a&&!o.isDirty||l&&!o.isValid},i),n)});Oe.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};var Ve=["schema","submitLabel"],Le=t.forwardRef(function(e,r){var t=e.schema,n=e.submitLabel,a=void 0===n?"Submit":n,l=x(e,Ve);/*#__PURE__*/return h.createElement(ke,b({},l,{schema:t,ref:r}),/*#__PURE__*/h.createElement(Q,null,/*#__PURE__*/h.createElement(Re,{schema:t}),a&&/*#__PURE__*/h.createElement(Oe,{label:a})))});exports.ArrayField=he,exports.ArrayFieldAddButton=ve,exports.ArrayFieldContainer=xe,exports.ArrayFieldProvider=Z,exports.ArrayFieldRemoveButton=pe,exports.ArrayFieldRow=de,exports.ArrayFieldRowContainer=fe,exports.ArrayFieldRowFields=me,exports.ArrayFieldRowProvider=te,exports.ArrayFieldRows=be,exports.AutoForm=Le,exports.BaseField=O,exports.CheckboxField=T,exports.DisplayField=function(e){var n=e.name,a=e.label,l=x(e,F),i=r.useFormContext().getValues;/*#__PURE__*/return h.createElement(t.FormControl,l,a?/*#__PURE__*/h.createElement(t.FormLabel,{htmlFor:n},a):null,/*#__PURE__*/h.createElement(t.Text,{fontSize:"md"},i(n)))},exports.DisplayIf=function(e){var t=e.children,n=e.condition;return(void 0===n?function(e){return!!e}:n)(r.useWatch({name:e.name,defaultValue:e.defaultValue,disabled:e.isDisabled,exact:e.isExact}),r.useFormContext())?t:null},exports.Field=V,exports.Fields=Re,exports.Form=ke,exports.FormLayout=Q,exports.FormLegend=Fe,exports.InputField=N,exports.NativeSelectField=H,exports.NumberInputField=P,exports.ObjectField=Ee,exports.PasswordInputFIeld=B,exports.PinField=G,exports.RadioField=_,exports.SelectField=U,exports.SubmitButton=Oe,exports.SwitchField=M,exports.TextareaField=D,exports.registerFieldType=j,exports.useArrayField=ae,exports.useArrayFieldAddButton=oe,exports.useArrayFieldContext=ee,exports.useArrayFieldRemoveButton=ie,exports.useArrayFieldRow=le,exports.useArrayFieldRowContext=ne,exports.withControlledInput=L,exports.withUncontrolledInput=q,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/field.tsx","../src/resolvers/yup.ts","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/form.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-field.tsx","../src/display-if.tsx"],"sourcesContent":["import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<typeof FormControl>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<typeof FormControl>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={inputRules.required}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { SchemaOf, AnySchema, reach } from 'yup'\nexport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '../field'\n\n// @TODO get proper typings for the schema fields\n\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\ntype Options = {\n min?: number\n max?: number\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (\n schema: SchemaOf<AnySchema>\n): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: SchemaOf<AnySchema>, path: string) => {\n return reach(schema, path)\n}\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses 'id'\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField: React.FC<ArrayFieldProps> = (props) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer {...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\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer: React.FC<ArrayFieldProps> = ({\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n}) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n}\n","import * as React from 'react'\nimport { ResponsiveValue } from '@chakra-ui/system'\n\nimport { FormLayout } from './layout'\nimport { BaseField, 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 ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, children, columns, spacing, ...fieldProps } = props\n return (\n <BaseField name={name} {...fieldProps}>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </BaseField>\n )\n}\n","import * as React from 'react'\nimport { getFieldsFromSchema, getNestedSchema } from './resolvers/yup'\n\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\n\nexport interface FieldsProps {\n schema: any\n}\n\nconst getNestedFields = (schema: any, name: string) => {\n return getFieldsFromSchema(getNestedSchema(schema, name)).map(\n ({ name, type, ...nestedFieldProps }: FieldProps): React.ReactNode => (\n <Field key={name} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({ schema, ...props }) => {\n return (\n <FormLayout {...props}>\n {getFieldsFromSchema(schema).map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n} from 'react-hook-form'\n\nimport { yupResolver } from './resolvers/yup'\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n // @todo remove yup dependency and just use resolver prop?\n if (schema) {\n form.resolver = yupResolver(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwareded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\n\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\n\ninterface AutoFormOptions {\n schema: any\n submitLabel?: false | string\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', ...rest } = props\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\nimport { 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 const { getValues } = useFormContext()\n\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">{getValues(name)}</Text>\n </FormControl>\n )\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n"],"names":["inputTypes","BaseField","props","name","label","help","variant","hideLabel","children","controlProps","error","formState","get","errors","getError","useFormContext","React","FormControl","isInvalid","FormLabel","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","withControlledInput","InputComponent","rules","inputProps","Controller","control","render","field","_ref","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","getType","spec","meta","_field$spec$meta","getArrayOption","tests","test","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","schemaFields","fields","innerType","min","max","push","FormLayoutItem","chakra","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","useFieldArray","useArrayFieldRow","index","clearErrors","remove","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","id","fieldProps","ObjectField","getNestedFields","path","reach","getNestedSchema","nestedFieldProps","Fields","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","yupResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","getValues","htmlFor","Text","fontSize","condition","useWatch","disabled","exact","isExact"],"mappings":"87CA+GMA,EAAsC,GAmB/BC,EAAkC,SAACC,GAC9C,IAAQC,EACND,EADMC,KAAMC,EACZF,EADYE,MAAOC,EACnBH,EADmBG,KAAMC,EACzBJ,EADyBI,QAASC,EAClCL,EADkCK,UAAWC,EAC7CN,EAD6CM,SAAaC,IAC1DP,KAIIQ,EAjBS,SAACP,EAAcQ,GAC9B,OAAOC,MAAID,EAAUE,OAAQV,GAgBfW,CAASX,EAFDY,mBAAdJ,wBAIR,OACEK,gBAACC,iBAAYX,QAASA,GAAaG,GAAcS,YAAaR,IAC3DN,IAAUG,eACTS,gBAACG,aAAUb,QAASA,GAAUF,GAC5B,kBACJY,gBAACI,WACEZ,GACAH,SAASK,GAAAA,EAAOW,QAEb,kBADFL,gBAACM,sBAAgBjB,UAElBK,SAAAA,EAAOW,uBACNL,gBAACO,8BAAkBb,SAAAA,EAAOW,YAMvBG,EAAQC,aACnB,SACEvB,EAGAwB,GAEA,MAAoCxB,EAA5ByB,kBAGR,OAAOX,gBAjDFhB,aAHgB,WAGIA,EAAU,QAiDZ0B,IAAKA,GAASxB,MAgE5B0B,EAAsB,SAACC,GAClC,OAAOJ,aACL,WAAiCC,OAA9BvB,IAAAA,KAAM2B,IAAAA,MAAUC,WACGhB,gCAEpB,OACEC,gBAACgB,cACC7B,KAAMA,EACN8B,UALIA,QAMJH,MAAOA,EACPI,OAAQ,oBAAGC,MAAcC,IAALV,IAAcS,6BAChCnB,gBAACa,OACKM,EACAJ,GACJL,IAAKW,eAAaX,EAAKU,YASxBE,EAAwB,SAACT,GACpC,OAAOJ,aACL,WAAiCC,OAA9BvB,IAAAA,KAAM2B,IAAAA,MAAUC,YAGeQ,EAFXxB,mBAAbwB,UAEiCpC,EAAM2B,GAAlCM,IAALV,IAAcS,sBAEtB,OACEnB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azF,aAAe,CAC1BrG,MAAO,SACP+L,oBAAoB,EACpBC,kBAAkB,mCCjCPO,GAAWlL,aACtB,SACEvB,EACAwB,GAEA,IAAQ+D,EAA4CvF,EAA5CuF,SAA4CvF,EAApC0M,YAAAA,aAAc,WAAalB,IAASxL,mBACpD,OACEc,gBAAC6J,QAASa,GAAMjG,OAAQA,EAAQ/D,IAAKA,iBACnCV,gBAACmF,oBACEnF,gBAAC4J,IAAOnF,OAAQA,IAChBmH,gBAAe5L,gBAACkL,IAAa9L,MAAOwM,qYCbU,YACvDzM,IAAAA,IAAAA,KACAC,IAAAA,MAEGF,SAEK2M,EAAc9L,mBAAd8L,uBAER,OACE7L,gBAACC,cAAgBf,EACdE,eAAQY,gBAACG,aAAU2L,QAAS3M,GAAOC,GAAqB,kBACzDY,gBAAC+L,QAAKC,SAAS,MAAMH,EAAU1M,wBCVZ,gBACvBK,IAAAA,aAKAyM,UASA,kBATY,SAAC/D,WAAYA,MAEXgE,WAAS,CACrB/M,OAPFA,KAQEoH,eAPFA,aAQE4F,WAPFvK,WAQEwK,QAPFC,UASgBtM,oBACmBP,EAAW"}
1
+ {"version":3,"file":"index.js","sources":["../src/field.tsx","../src/resolvers/yup.ts","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/form.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-field.tsx","../src/display-if.tsx"],"sourcesContent":["import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<typeof FormControl>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<typeof FormControl>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { SchemaOf, AnySchema, reach } from 'yup'\nexport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '../field'\n\n// @TODO get proper typings for the schema fields\n\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\ntype Options = {\n min?: number\n max?: number\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (\n schema: SchemaOf<AnySchema>\n): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: SchemaOf<AnySchema>, path: string) => {\n return reach(schema, path)\n}\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses 'id'\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField: React.FC<ArrayFieldProps> = (props) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer {...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\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer: React.FC<ArrayFieldProps> = ({\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n}) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n}\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyles()\n return <FormLabel as=\"legend\" sx={styles.legend} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n","import * as React from 'react'\nimport { getFieldsFromSchema, getNestedSchema } from './resolvers/yup'\n\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\n\nexport interface FieldsProps {\n schema: any\n}\n\nconst getNestedFields = (schema: any, name: string) => {\n return getFieldsFromSchema(getNestedSchema(schema, name)).map(\n ({ name, type, ...nestedFieldProps }: FieldProps): React.ReactNode => (\n <Field key={name} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({ schema, ...props }) => {\n return (\n <FormLayout {...props}>\n {getFieldsFromSchema(schema).map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n} from 'react-hook-form'\n\nimport { yupResolver } from './resolvers/yup'\n\nexport type { UseFormReturn }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n // @todo remove yup dependency and just use resolver prop?\n if (schema) {\n form.resolver = yupResolver(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwareded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\n\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\n\ninterface AutoFormOptions {\n schema: any\n submitLabel?: false | string\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', ...rest } = props\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\nimport { 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 const { getValues } = useFormContext()\n\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">{getValues(name)}</Text>\n </FormControl>\n )\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n"],"names":["inputTypes","BaseField","props","name","label","help","variant","hideLabel","children","controlProps","error","formState","get","errors","getError","useFormContext","React","FormControl","isInvalid","FormLabel","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","withControlledInput","InputComponent","rules","inputProps","Controller","control","render","field","_ref","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","isControlled","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","getType","spec","meta","_field$spec$meta","getArrayOption","tests","test","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","schemaFields","fields","innerType","min","max","push","FormLayoutItem","chakra","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","createContext","ArrayFieldProvider","useArrayFieldContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","useFieldArray","useArrayFieldRow","index","clearErrors","remove","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","ArrayFieldRowContainer","ArrayFieldRowFields","columns","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","key","id","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","getNestedFields","path","reach","getNestedSchema","nestedFieldProps","Fields","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","yupResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","getValues","htmlFor","Text","fontSize","condition","useWatch","disabled","exact","isExact"],"mappings":"q8CA+GMA,EAAsC,GAmB/BC,EAAkC,SAACC,GAC9C,IAAQC,EACND,EADMC,KAAMC,EACZF,EADYE,MAAOC,EACnBH,EADmBG,KAAMC,EACzBJ,EADyBI,QAASC,EAClCL,EADkCK,UAAWC,EAC7CN,EAD6CM,SAAaC,IAC1DP,KAIIQ,EAjBS,SAACP,EAAcQ,GAC9B,OAAOC,MAAID,EAAUE,OAAQV,GAgBfW,CAASX,EAFDY,mBAA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L,mBACpD,OACEc,gBAACmK,QAASa,GAAMvG,OAAQA,EAAQ/D,IAAKA,iBACnCV,gBAACmF,oBACEnF,gBAACkK,IAAOzF,OAAQA,IAChByH,gBAAelM,gBAACwL,IAAapM,MAAO8M,qYCbU,YACvD/M,IAAAA,IAAAA,KACAC,IAAAA,MAEGF,SAEKiN,EAAcpM,mBAAdoM,uBAER,OACEnM,gBAACC,cAAgBf,EACdE,eAAQY,gBAACG,aAAUiM,QAASjN,GAAOC,GAAqB,kBACzDY,gBAACqM,QAAKC,SAAS,MAAMH,EAAUhN,wBCVZ,gBACvBK,IAAAA,aAKA+M,UASA,kBATY,SAACrE,WAAYA,MAEXsE,WAAS,CACrBrN,OAPFA,KAQEoH,eAPFA,aAQEkG,WAPF7K,WAQE8K,QAPFC,UASgB5M,oBACmBP,EAAW"}
@@ -1,2 +1,2 @@
1
- import*as e from"react";import{useFormContext as r,get as t,Controller as a,useFieldArray as l,useForm as n,FormProvider as i,useWatch as s}from"react-hook-form";import{FormControl as m,FormLabel as o,Text as c,forwardRef as u,Switch as d,Checkbox as f,Box as p,FormHelperText as h,FormErrorMessage as b,useMergeRefs as E,Input as y,Textarea as v,useTheme as x,SimpleGrid as g,chakra as V}from"@chakra-ui/react";import{NumberInput as k}from"@saas-ui/number-input";import{PasswordInput as I}from"@saas-ui/password-input";import{RadioInput as C}from"@saas-ui/radio";import{PinInput as F}from"@saas-ui/pin-input";import{Select as L,NativeSelect as N}from"@saas-ui/select";import{reach as O}from"yup";import{yupResolver as S}from"@hookform/resolvers/yup";import{chakra as w,forwardRef as R}from"@chakra-ui/system";import{MinusIcon as U,AddIcon as D}from"@chakra-ui/icons";import{IconButton as j,Button as M}from"@saas-ui/button";import{createContext as P}from"@chakra-ui/react-utils";export*from"@saas-ui/input-right-button";function q(){return q=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var t=arguments[r];for(var a in t)Object.prototype.hasOwnProperty.call(t,a)&&(e[a]=t[a])}return e},q.apply(this,arguments)}function $(e,r){if(null==e)return{};var t,a,l={},n=Object.keys(e);for(a=0;a<n.length;a++)r.indexOf(t=n[a])>=0||(l[t]=e[t]);return l}const A=["name","label","placeholder"],B=t=>{let{name:a,label:l}=t,n=$(t,A);const{getValues:i}=r();/*#__PURE__*/return e.createElement(m,n,l?/*#__PURE__*/e.createElement(o,{htmlFor:a},l):null,/*#__PURE__*/e.createElement(c,{fontSize:"md"},i(a)))},T=["name","label","help","variant","hideLabel","children"],G=["name","label","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],_=["name","rules"],z=["ref"],H=["name","rules"],J=["ref"],K=["label"],Q=["label"],W={},X="text",Y=a=>{const{name:l,label:n,help:i,variant:s,hideLabel:c,children:u}=a,d=$(a,T),{formState:f}=r(),E=((e,r)=>t(r.errors,e))(l,f);/*#__PURE__*/return e.createElement(m,q({variant:s},d,{isInvalid:!!E}),n&&!c?/*#__PURE__*/e.createElement(o,{variant:s},n):null,/*#__PURE__*/e.createElement(p,null,u,!i||null!=E&&E.message?null:/*#__PURE__*/e.createElement(h,null,i),(null==E?void 0:E.message)&&/*#__PURE__*/e.createElement(b,null,null==E?void 0:E.message)))},Z=u((r,t)=>{const{type:a=X}=r,l=(e=>W[e]||W[X])(a);/*#__PURE__*/return e.createElement(l,q({ref:t},r))}),ee=t=>u((l,n)=>{let{name:i,rules:s}=l,m=$(l,_);const{control:o}=r();/*#__PURE__*/return e.createElement(a,{name:i,control:o,rules:s,render:r=>{let{field:{ref:a}}=r,l=$(r.field,z);/*#__PURE__*/return e.createElement(t,q({},l,m,{ref:E(n,a)}))}})}),re=t=>u((a,l)=>{let{name:n,rules:i}=a,s=$(a,H);const{register:m}=r(),o=m(n,i),{ref:c}=o,u=$(o,J);/*#__PURE__*/return e.createElement(t,q({},u,s,{ref:E(l,c)}))}),te=(r,t,a)=>{let l;l=null!=a&&a.isControlled?ee(t):re(t);const n=((r,{displayName:t,hideLabel:a,BaseField:l})=>{const n=u((t,n)=>{const{name:i,label:s,isDisabled:m,isInvalid:o,isReadOnly:c,isRequired:u,rules:d,variant:f}=t,p=$(t,G),h=q({required:u},d);/*#__PURE__*/return e.createElement(l,{name:i,label:s,hideLabel:a,isDisabled:m,isInvalid:o,isReadOnly:c,isRequired:h.required,variant:f},/*#__PURE__*/e.createElement(r,q({ref:n,name:i,label:s,rules:h},p)))});return n.displayName=t,n})(l,{displayName:`${r.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==a?void 0:a.hideLabel,BaseField:(null==a?void 0:a.BaseField)||Y});return W[r]=n,n},ae=te("text",y),le=te("number",k,{isControlled:!0}),ne=te("password",I),ie=te("textarea",v),se=te("switch",u((r,t)=>{let{label:a}=r,l=$(r,K);/*#__PURE__*/return e.createElement(d,q({ref:t},l),a)}),{isControlled:!0,hideLabel:!0}),me=te("select",L,{isControlled:!0}),oe=te("checkbox",u((r,t)=>{let{label:a}=r,l=$(r,Q);/*#__PURE__*/return e.createElement(f,q({ref:t},l),a)}),{hideLabel:!0}),ce=te("radio",C,{isControlled:!0}),ue=te("pin",F,{isControlled:!0}),de=te("native-select",N,{isControlled:!0}),fe=e=>{var r;if(null!=(r=e.spec.meta)&&r.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},pe=(e,r)=>{for(const a of e.tests){var t;if(null!=(t=a.OPTIONS)&&t.params[r])return a.OPTIONS.params[r]}},he=e=>{const r=[];let t={};t="array"===e.type?e.innerType.fields:e.fields;for(const e in t){const a=t[e],l={};"array"===a.type&&(l.min=pe(a,"min"),l.max=pe(a,"max")),r.push(q({name:e,label:a.spec.label||e,type:fe(a)},l))}return r},be=["children"],Ee=({children:r})=>/*#__PURE__*/e.createElement(V.div,null,r),ye=r=>{var t,a,l;let{children:n}=r,i=$(r,be);const s=q({},null!=(t=null==(a=x().components)||null==(l=a.FormLayout)?void 0:l.defaultProps)?t:{spacing:4},i);/*#__PURE__*/return e.createElement(g,s,e.Children.map(n,r=>e.isValidElement(r)?/*#__PURE__*/e.createElement(Ee,null,r):r))},ve=(r,t)=>e.Children.map(t,t=>e.isValidElement(t)&&t.props.name?e.cloneElement(t,q({},t.props,{name:`${r}.${t.props.name}`})):t),[xe,ge]=P({name:"ArrayFieldContext"}),[Ve,ke]=P({name:"ArrayFieldRowContext"}),Ie=({name:e,defaultValue:t={},keyName:a,min:n,max:i})=>{const{control:s}=r();return q({},l({control:s,name:e,keyName:a}),{name:e,defaultValue:t,min:n,max:i})},Ce=({index:t})=>{const{clearErrors:a}=r(),{name:l,remove:n,fields:i}=ge();return e.useEffect(()=>{a(l)},[]),{index:t,isFirst:0===t,isLast:t===i.length-1,name:`${l}.${t}`,remove:e.useCallback(()=>{a(l),n(t)},[t])}},Fe=()=>{const{isFirst:e,remove:r}=ke(),{min:t,fields:a}=ge();return{onClick:()=>r(),isDisabled:e&&!!(t&&a.length<=t)}},Le=()=>{const{append:e,defaultValue:r,max:t,fields:a}=ge();return{onClick:()=>e(r,{shouldFocus:!1}),isDisabled:!!(t&&a.length>=t)}},Ne=["children","columns","spacing"],Oe=["children"],Se=["name","defaultValue","keyName","min","max","children"],we=({children:r,columns:t,spacing:a,index:l})=>/*#__PURE__*/e.createElement(Ue,{index:l},/*#__PURE__*/e.createElement(Re,{columns:t,spacing:a},r),/*#__PURE__*/e.createElement(De,null)),Re=r=>{let{children:t,columns:a,spacing:l}=r,n=$(r,Ne);const{name:i}=ke();/*#__PURE__*/return e.createElement(ye,q({flex:"1",columns:a,gridGap:l,mr:"2"},n),ve(i,t))},Ue=({children:r,index:t})=>{const a=Ce({index:t});/*#__PURE__*/return e.createElement(Ve,{value:a},/*#__PURE__*/e.createElement(w.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))},De=r=>/*#__PURE__*/e.createElement(j,q({icon:/*#__PURE__*/e.createElement(U,null),"aria-label":"Remove row"},Fe(),r)),je=r=>/*#__PURE__*/e.createElement(j,q({icon:/*#__PURE__*/e.createElement(D,null),"aria-label":"Add row",float:"right"},Le(),r)),Me=r=>{const{children:t}=r,a=$(r,Oe);/*#__PURE__*/return e.createElement(qe,a,/*#__PURE__*/e.createElement(Pe,null,r=>/*#__PURE__*/e.createElement(e.Fragment,null,r.map(({id:r},a)=>/*#__PURE__*/e.createElement(we,{key:r,index:a},t)))),/*#__PURE__*/e.createElement(je,null))},Pe=({children:e})=>{const{fields:r}=ge();return e(r)},qe=r=>{let{name:t,defaultValue:a,keyName:l,min:n,max:i,children:s}=r,m=$(r,Se);const o=Ie({name:t,defaultValue:a,keyName:l,min:n,max:i});/*#__PURE__*/return e.createElement(xe,{value:o},/*#__PURE__*/e.createElement(Y,q({name:t},m),s))},$e=["name","children","columns","spacing"],Ae=r=>{const{name:t,children:a,columns:l,spacing:n}=r,i=$(r,$e);/*#__PURE__*/return e.createElement(Y,q({name:t},i),/*#__PURE__*/e.createElement(ye,{columns:l,gridGap:n},ve(t,a)))},Be=["name","type"],Te=["schema"],Ge=["name","type","defaultValue"],_e=(r,t)=>he(((e,r)=>O(e,r))(r,t)).map(r=>{let{name:t,type:a}=r,l=$(r,Be);/*#__PURE__*/return e.createElement(Z,q({key:t,name:t,type:a},l))}),ze=r=>{let{schema:t}=r,a=$(r,Te);/*#__PURE__*/return e.createElement(ye,a,he(t).map(r=>{let{name:a,type:l}=r,n=$(r,Ge);return"array"===l?/*#__PURE__*/e.createElement(Me,q({name:a},n),_e(t,a)):"object"===l?/*#__PURE__*/e.createElement(Ae,q({name:a},n),_e(t,a)):/*#__PURE__*/e.createElement(Z,q({key:a,name:a,type:l},n))}))},He=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Je=u((r,t)=>{const{mode:a="all",resolver:l,reValidateMode:s,shouldFocusError:m,shouldUnregister:o,shouldUseNativeValidation:c,criteriaMode:u,delayError:d,schema:f,defaultValues:p,onSubmit:h,onError:b,formRef:E,children:y}=r,v=$(r,He),x={mode:a,resolver:l,defaultValues:p,reValidateMode:s,shouldFocusError:m,shouldUnregister:o,shouldUseNativeValidation:c,criteriaMode:u,delayError:d};f&&(x.resolver=S(f));const g=n(x),{handleSubmit:k}=g;return e.useImperativeHandle(t,()=>g,[t,g]),/*#__PURE__*/e.createElement(i,g,/*#__PURE__*/e.createElement(V.form,q({ref:E,onSubmit:k(h,b)},v),y))}),Ke=["children","disableIfUntouched","disableIfInvalid"],Qe=R((t,a)=>{const{children:l,disableIfUntouched:n,disableIfInvalid:i}=t,s=$(t,Ke),{formState:m}=r();/*#__PURE__*/return e.createElement(M,q({type:"submit",isLoading:m.isSubmitting,isPrimary:!0,ref:a,isDisabled:n&&!m.isDirty||i&&!m.isValid},s),l)});Qe.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};const We=["schema","submitLabel"],Xe=u((r,t)=>{const{schema:a,submitLabel:l="Submit"}=r,n=$(r,We);/*#__PURE__*/return e.createElement(Je,q({},n,{schema:a,ref:t}),/*#__PURE__*/e.createElement(ye,null,/*#__PURE__*/e.createElement(ze,{schema:a}),l&&/*#__PURE__*/e.createElement(Qe,{label:l})))}),Ye=({children:e,name:t,defaultValue:a,isDisabled:l,isExact:n,condition:i=(e=>!!e)})=>i(s({name:t,defaultValue:a,disabled:l,exact:n}),r())?e:null;export{Me as ArrayField,je as ArrayFieldAddButton,qe as ArrayFieldContainer,xe as ArrayFieldProvider,De as ArrayFieldRemoveButton,we as ArrayFieldRow,Ue as ArrayFieldRowContainer,Re as ArrayFieldRowFields,Ve as ArrayFieldRowProvider,Pe as ArrayFieldRows,Xe as AutoForm,Y as BaseField,oe as CheckboxField,B as DisplayField,Ye as DisplayIf,Z as Field,ze as Fields,Je as Form,ye as FormLayout,ae as InputField,de as NativeSelectField,le as NumberInputField,Ae as ObjectField,ne as PasswordInputFIeld,ue as PinField,ce as RadioField,me as SelectField,Qe as SubmitButton,se as SwitchField,ie as TextareaField,te as registerFieldType,Ie as useArrayField,Le as useArrayFieldAddButton,ge as useArrayFieldContext,Fe as useArrayFieldRemoveButton,Ce as useArrayFieldRow,ke as useArrayFieldRowContext,ee as withControlledInput,re as withUncontrolledInput};
1
+ import*as e from"react";import{useFormContext as r,get as l,Controller as a,useFieldArray as t,useForm as n,FormProvider as i,useWatch as s}from"react-hook-form";import{FormControl as m,FormLabel as o,Text as c,forwardRef as u,Switch as d,Checkbox as p,Box as f,FormHelperText as h,FormErrorMessage as b,useMergeRefs as E,Input as y,Textarea as v,useTheme as x,SimpleGrid as g,chakra as V,useStyles as k}from"@chakra-ui/react";import{NumberInput as I}from"@saas-ui/number-input";import{PasswordInput as C}from"@saas-ui/password-input";import{RadioInput as F}from"@saas-ui/radio";import{PinInput as L}from"@saas-ui/pin-input";import{Select as N,NativeSelect as O}from"@saas-ui/select";import{reach as S}from"yup";import{yupResolver as w}from"@hookform/resolvers/yup";import{chakra as R,forwardRef as U}from"@chakra-ui/system";import{MinusIcon as D,AddIcon as j}from"@chakra-ui/icons";import{IconButton as M,Button as P}from"@saas-ui/button";import{createContext as $}from"@chakra-ui/react-utils";export*from"@saas-ui/input-right-button";function q(){return q=Object.assign||function(e){for(var r=1;r<arguments.length;r++){var l=arguments[r];for(var a in l)Object.prototype.hasOwnProperty.call(l,a)&&(e[a]=l[a])}return e},q.apply(this,arguments)}function A(e,r){if(null==e)return{};var l,a,t={},n=Object.keys(e);for(a=0;a<n.length;a++)r.indexOf(l=n[a])>=0||(t[l]=e[l]);return t}const B=["name","label","placeholder"],T=l=>{let{name:a,label:t}=l,n=A(l,B);const{getValues:i}=r();/*#__PURE__*/return e.createElement(m,n,t?/*#__PURE__*/e.createElement(o,{htmlFor:a},t):null,/*#__PURE__*/e.createElement(c,{fontSize:"md"},i(a)))},G=["name","label","help","variant","hideLabel","children"],_=["name","label","help","isDisabled","isInvalid","isReadOnly","isRequired","rules","variant"],z=["name","rules"],H=["ref"],J=["name","rules"],K=["ref"],Q=["label"],W=["label"],X={},Y="text",Z=a=>{const{name:t,label:n,help:i,variant:s,hideLabel:c,children:u}=a,d=A(a,G),{formState:p}=r(),E=((e,r)=>l(r.errors,e))(t,p);/*#__PURE__*/return e.createElement(m,q({variant:s},d,{isInvalid:!!E}),n&&!c?/*#__PURE__*/e.createElement(o,{variant:s},n):null,/*#__PURE__*/e.createElement(f,null,u,!i||null!=E&&E.message?null:/*#__PURE__*/e.createElement(h,null,i),(null==E?void 0:E.message)&&/*#__PURE__*/e.createElement(b,null,null==E?void 0:E.message)))},ee=u((r,l)=>{const{type:a=Y}=r,t=(e=>X[e]||X[Y])(a);/*#__PURE__*/return e.createElement(t,q({ref:l},r))}),re=l=>u((t,n)=>{let{name:i,rules:s}=t,m=A(t,z);const{control:o}=r();/*#__PURE__*/return e.createElement(a,{name:i,control:o,rules:s,render:r=>{let{field:{ref:a}}=r,t=A(r.field,H);/*#__PURE__*/return e.createElement(l,q({},t,m,{ref:E(n,a)}))}})}),le=l=>u((a,t)=>{let{name:n,rules:i}=a,s=A(a,J);const{register:m}=r(),o=m(n,i),{ref:c}=o,u=A(o,K);/*#__PURE__*/return e.createElement(l,q({},u,s,{ref:E(t,c)}))}),ae=(r,l,a)=>{let t;t=null!=a&&a.isControlled?re(l):le(l);const n=((r,{displayName:l,hideLabel:a,BaseField:t})=>{const n=u((l,n)=>{const{name:i,label:s,help:m,isDisabled:o,isInvalid:c,isReadOnly:u,isRequired:d,rules:p,variant:f}=l,h=A(l,_),b=q({required:d},p);/*#__PURE__*/return e.createElement(t,{name:i,label:s,help:m,hideLabel:a,isDisabled:o,isInvalid:c,isReadOnly:u,isRequired:d,variant:f},/*#__PURE__*/e.createElement(r,q({ref:n,name:i,label:s,rules:b},h)))});return n.displayName=l,n})(t,{displayName:`${r.split("-").map(e=>e.charAt(0).toUpperCase()+e.slice(1)).join("")}Field`,hideLabel:null==a?void 0:a.hideLabel,BaseField:(null==a?void 0:a.BaseField)||Z});return X[r]=n,n},te=ae("text",y),ne=ae("number",I,{isControlled:!0}),ie=ae("password",C),se=ae("textarea",v),me=ae("switch",u((r,l)=>{let{label:a}=r,t=A(r,Q);/*#__PURE__*/return e.createElement(d,q({ref:l},t),a)}),{isControlled:!0,hideLabel:!0}),oe=ae("select",N,{isControlled:!0}),ce=ae("checkbox",u((r,l)=>{let{label:a}=r,t=A(r,W);/*#__PURE__*/return e.createElement(p,q({ref:l},t),a)}),{hideLabel:!0}),ue=ae("radio",F,{isControlled:!0}),de=ae("pin",L,{isControlled:!0}),pe=ae("native-select",O,{isControlled:!0}),fe=e=>{var r;if(null!=(r=e.spec.meta)&&r.type)return e.spec.meta.type;switch(e.type){case"array":return"array";case"object":return"object";case"number":return"number";case"date":return"date";default:return"text"}},he=(e,r)=>{for(const a of e.tests){var l;if(null!=(l=a.OPTIONS)&&l.params[r])return a.OPTIONS.params[r]}},be=e=>{const r=[];let l={};l="array"===e.type?e.innerType.fields:e.fields;for(const e in l){const a=l[e],t={};"array"===a.type&&(t.min=he(a,"min"),t.max=he(a,"max")),r.push(q({name:e,label:a.spec.label||e,type:fe(a)},t))}return r},Ee=["children"],ye=({children:r})=>/*#__PURE__*/e.createElement(V.div,null,r),ve=r=>{var l,a,t;let{children:n}=r,i=A(r,Ee);const s=q({},null!=(l=null==(a=x().components)||null==(t=a.FormLayout)?void 0:t.defaultProps)?l:{spacing:4},i);/*#__PURE__*/return e.createElement(g,s,e.Children.map(n,r=>e.isValidElement(r)?/*#__PURE__*/e.createElement(ye,null,r):r))},xe=(r,l)=>e.Children.map(l,l=>e.isValidElement(l)&&l.props.name?e.cloneElement(l,q({},l.props,{name:`${r}.${l.props.name}`})):l),[ge,Ve]=$({name:"ArrayFieldContext"}),[ke,Ie]=$({name:"ArrayFieldRowContext"}),Ce=({name:e,defaultValue:l={},keyName:a,min:n,max:i})=>{const{control:s}=r();return q({},t({control:s,name:e,keyName:a}),{name:e,defaultValue:l,min:n,max:i})},Fe=({index:l})=>{const{clearErrors:a}=r(),{name:t,remove:n,fields:i}=Ve();return e.useEffect(()=>{a(t)},[]),{index:l,isFirst:0===l,isLast:l===i.length-1,name:`${t}.${l}`,remove:e.useCallback(()=>{a(t),n(l)},[l])}},Le=()=>{const{isFirst:e,remove:r}=Ie(),{min:l,fields:a}=Ve();return{onClick:()=>r(),isDisabled:e&&!!(l&&a.length<=l)}},Ne=()=>{const{append:e,defaultValue:r,max:l,fields:a}=Ve();return{onClick:()=>e(r,{shouldFocus:!1}),isDisabled:!!(l&&a.length>=l)}},Oe=["children","columns","spacing"],Se=["children"],we=["name","defaultValue","keyName","min","max","children"],Re=({children:r,columns:l,spacing:a,index:t})=>/*#__PURE__*/e.createElement(De,{index:t},/*#__PURE__*/e.createElement(Ue,{columns:l,spacing:a},r),/*#__PURE__*/e.createElement(je,null)),Ue=r=>{let{children:l,columns:a,spacing:t}=r,n=A(r,Oe);const{name:i}=Ie();/*#__PURE__*/return e.createElement(ve,q({flex:"1",columns:a,gridGap:t,mr:"2"},n),xe(i,l))},De=({children:r,index:l})=>{const a=Fe({index:l});/*#__PURE__*/return e.createElement(ke,{value:a},/*#__PURE__*/e.createElement(R.div,{__css:{display:"flex",flexDirection:"row",alignItems:"flex-end",width:"100%",mb:4}},r))},je=r=>/*#__PURE__*/e.createElement(M,q({icon:/*#__PURE__*/e.createElement(D,null),"aria-label":"Remove row"},Le(),r)),Me=r=>/*#__PURE__*/e.createElement(M,q({icon:/*#__PURE__*/e.createElement(j,null),"aria-label":"Add row",float:"right"},Ne(),r)),Pe=r=>{const{children:l}=r,a=A(r,Se);/*#__PURE__*/return e.createElement(qe,a,/*#__PURE__*/e.createElement($e,null,r=>/*#__PURE__*/e.createElement(e.Fragment,null,r.map(({id:r},a)=>/*#__PURE__*/e.createElement(Re,{key:r,index:a},l)))),/*#__PURE__*/e.createElement(Me,null))},$e=({children:e})=>{const{fields:r}=Ve();return e(r)},qe=r=>{let{name:l,defaultValue:a,keyName:t,min:n,max:i,children:s}=r,m=A(r,we);const o=Ce({name:l,defaultValue:a,keyName:t,min:n,max:i});/*#__PURE__*/return e.createElement(ge,{value:o},/*#__PURE__*/e.createElement(Z,q({name:l},m),s))},Ae=["name","label","hideLabel","children","columns","spacing"],Be=r=>{const l=k();/*#__PURE__*/return e.createElement(o,q({as:"legend",sx:l.legend},r))},Te=r=>{const{name:l,label:a,hideLabel:t,children:n,columns:i,spacing:s}=r,o=A(r,Ae);/*#__PURE__*/return e.createElement(m,q({name:l,as:"fieldset"},o),/*#__PURE__*/e.createElement(Be,{display:t?"none":"block"},a),/*#__PURE__*/e.createElement(ve,{columns:i,gridGap:s},xe(l,n)))},Ge=["name","type"],_e=["schema"],ze=["name","type","defaultValue"],He=(r,l)=>be(((e,r)=>S(e,r))(r,l)).map(r=>{let{name:l,type:a}=r,t=A(r,Ge);/*#__PURE__*/return e.createElement(ee,q({key:l,name:l,type:a},t))}),Je=r=>{let{schema:l}=r,a=A(r,_e);/*#__PURE__*/return e.createElement(ve,a,be(l).map(r=>{let{name:a,type:t}=r,n=A(r,ze);return"array"===t?/*#__PURE__*/e.createElement(Pe,q({name:a},n),He(l,a)):"object"===t?/*#__PURE__*/e.createElement(Te,q({name:a},n),He(l,a)):/*#__PURE__*/e.createElement(ee,q({key:a,name:a,type:t},n))}))},Ke=["mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","schema","defaultValues","onSubmit","onError","formRef","children"],Qe=u((r,l)=>{const{mode:a="all",resolver:t,reValidateMode:s,shouldFocusError:m,shouldUnregister:o,shouldUseNativeValidation:c,criteriaMode:u,delayError:d,schema:p,defaultValues:f,onSubmit:h,onError:b,formRef:E,children:y}=r,v=A(r,Ke),x={mode:a,resolver:t,defaultValues:f,reValidateMode:s,shouldFocusError:m,shouldUnregister:o,shouldUseNativeValidation:c,criteriaMode:u,delayError:d};p&&(x.resolver=w(p));const g=n(x),{handleSubmit:k}=g;return e.useImperativeHandle(l,()=>g,[l,g]),/*#__PURE__*/e.createElement(i,g,/*#__PURE__*/e.createElement(V.form,q({ref:E,onSubmit:k(h,b)},v),y))}),We=["children","disableIfUntouched","disableIfInvalid"],Xe=U((l,a)=>{const{children:t,disableIfUntouched:n,disableIfInvalid:i}=l,s=A(l,We),{formState:m}=r();/*#__PURE__*/return e.createElement(P,q({type:"submit",isLoading:m.isSubmitting,isPrimary:!0,ref:a,isDisabled:n&&!m.isDirty||i&&!m.isValid},s),t)});Xe.defaultProps={label:"Submit",disableIfUntouched:!1,disableIfInvalid:!1};const Ye=["schema","submitLabel"],Ze=u((r,l)=>{const{schema:a,submitLabel:t="Submit"}=r,n=A(r,Ye);/*#__PURE__*/return e.createElement(Qe,q({},n,{schema:a,ref:l}),/*#__PURE__*/e.createElement(ve,null,/*#__PURE__*/e.createElement(Je,{schema:a}),t&&/*#__PURE__*/e.createElement(Xe,{label:t})))}),er=({children:e,name:l,defaultValue:a,isDisabled:t,isExact:n,condition:i=(e=>!!e)})=>i(s({name:l,defaultValue:a,disabled:t,exact:n}),r())?e:null;export{Pe as ArrayField,Me as ArrayFieldAddButton,qe as ArrayFieldContainer,ge as ArrayFieldProvider,je as ArrayFieldRemoveButton,Re as ArrayFieldRow,De as ArrayFieldRowContainer,Ue as ArrayFieldRowFields,ke as ArrayFieldRowProvider,$e as ArrayFieldRows,Ze as AutoForm,Z as BaseField,ce as CheckboxField,T as DisplayField,er as DisplayIf,ee as Field,Je as Fields,Qe as Form,ve as FormLayout,Be as FormLegend,te as InputField,pe as NativeSelectField,ne as NumberInputField,Te as ObjectField,ie as PasswordInputFIeld,de as PinField,ue as RadioField,oe as SelectField,Xe as SubmitButton,me as SwitchField,se as TextareaField,ae as registerFieldType,Ce as useArrayField,Ne as useArrayFieldAddButton,Ve as useArrayFieldContext,Le as useArrayFieldRemoveButton,Fe as useArrayFieldRow,Ie as useArrayFieldRowContext,re as withControlledInput,le as withUncontrolledInput};
2
2
  //# sourceMappingURL=index.modern.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.modern.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/resolvers/yup.ts","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/form.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n const { getValues } = useFormContext()\n\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">{getValues(name)}</Text>\n </FormControl>\n )\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<typeof FormControl>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<typeof FormControl>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={inputRules.required}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { SchemaOf, AnySchema, reach } from 'yup'\nexport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '../field'\n\n// @TODO get proper typings for the schema fields\n\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\ntype Options = {\n min?: number\n max?: number\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (\n schema: SchemaOf<AnySchema>\n): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: SchemaOf<AnySchema>, path: string) => {\n return reach(schema, path)\n}\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses 'id'\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField: React.FC<ArrayFieldProps> = (props) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer {...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\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer: React.FC<ArrayFieldProps> = ({\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n}) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n}\n","import * as React from 'react'\nimport { ResponsiveValue } from '@chakra-ui/system'\n\nimport { FormLayout } from './layout'\nimport { BaseField, 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 ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, children, columns, spacing, ...fieldProps } = props\n return (\n <BaseField name={name} {...fieldProps}>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </BaseField>\n )\n}\n","import * as React from 'react'\nimport { getFieldsFromSchema, getNestedSchema } from './resolvers/yup'\n\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\n\nexport interface FieldsProps {\n schema: any\n}\n\nconst getNestedFields = (schema: any, name: string) => {\n return getFieldsFromSchema(getNestedSchema(schema, name)).map(\n ({ name, type, ...nestedFieldProps }: FieldProps): React.ReactNode => (\n <Field key={name} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({ schema, ...props }) => {\n return (\n <FormLayout {...props}>\n {getFieldsFromSchema(schema).map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n} from 'react-hook-form'\n\nimport { yupResolver } from './resolvers/yup'\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n // @todo remove yup dependency and just use resolver prop?\n if (schema) {\n form.resolver = yupResolver(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwareded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\n\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\n\ninterface AutoFormOptions {\n schema: any\n submitLabel?: false | string\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', ...rest } = props\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n"],"names":["DisplayField","_ref","name","label","props","getValues","useFormContext","React","FormControl","FormLabel","htmlFor","Text","fontSize","inputTypes","defaultInputType","BaseField","help","variant","hideLabel","children","controlProps","formState","error","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","InputComponent","getInput","withControlledInput","rules","inputProps","control","Controller","render","_ref3","field","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","isControlled","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","getType","spec","meta","_field$spec$meta","getArrayOption","test","tests","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","fields","schemaFields","innerType","min","max","push","FormLayoutItem","chakra","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","useFieldArray","useArrayFieldRow","index","clearErrors","remove","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","columns","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","id","key","_ref2","fieldProps","ObjectField","getNestedFields","path","reach","getNestedSchema","nestedFieldProps","Fields","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","yupResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","DisplayIf","isExact","condition","useWatch","disabled","exact"],"mappings":"w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BAACuM,KACC5K,KAAK,SACL6K,UAAW1L,EAAU2L,aACrBC,aACAhL,IAAKA,EACLoB,WATDuJ,IAAuBvL,EAAU6L,SACjCL,IAAqBxL,EAAU8L,SAS1BhB,GAEHhL,KAMTwL,GAAa1F,aAAe,CAC1B9G,MAAO,SACPyM,oBAAoB,EACpBC,kBAAkB,qCCjCPO,GAAWpL,EACtB,CACE5B,EACA6B,KAEA,MAAMgE,OAAEA,EAAFoH,YAAUA,EAAc,UAAsBjN,EAAT+L,IAAS/L,mBACpD,OACEG,gBAAC+K,QAASa,GAAMlG,OAAQA,EAAQhE,IAAKA,iBACnC1B,gBAACoG,qBACEpG,gBAAC8K,IAAOpF,OAAQA,IAChBoH,gBAAe9M,gBAACoM,IAAaxM,MAAOkN,QCZlCC,GAAY,EACvBnM,SAAAA,EACAjB,KAAAA,EACA6H,aAAAA,EACA1E,WAAAA,EACAkK,QAAAA,EACAC,UAAAA,EAAa9D,CAAAA,KAAYA,MASlB8D,EAPOC,EAAS,CACrBvN,KAAAA,EACA6H,aAAAA,EACA2F,SAAUrK,EACVsK,MAAOJ,IAEOjN,KACmBa,EAAW"}
1
+ {"version":3,"file":"index.modern.js","sources":["../src/display-field.tsx","../src/field.tsx","../src/resolvers/yup.ts","../src/layout.tsx","../src/utils.ts","../src/use-array-field.tsx","../src/array-field.tsx","../src/object-field.tsx","../src/fields.tsx","../src/form.tsx","../src/submit-button.tsx","../src/auto-form.tsx","../src/display-if.tsx"],"sourcesContent":["import * as React from 'react'\nimport { useFormContext } from 'react-hook-form'\n\nimport {\n Text,\n FormControl,\n FormControlProps,\n FormLabel,\n} from '@chakra-ui/react'\n\nimport { FieldProps } from './field'\n\nexport interface DisplayFieldProps\n extends FormControlProps,\n Omit<FieldProps, 'type' | 'label'> {}\n\nexport const DisplayField: React.FC<DisplayFieldProps> = ({\n name,\n label,\n placeholder,\n ...props\n}) => {\n const { getValues } = useFormContext()\n\n return (\n <FormControl {...props}>\n {label ? <FormLabel htmlFor={name}>{label}</FormLabel> : null}\n <Text fontSize=\"md\">{getValues(name)}</Text>\n </FormControl>\n )\n}\n","import * as React from 'react'\nimport {\n useFormContext,\n FormState,\n Controller,\n get,\n RegisterOptions,\n FieldValues,\n FieldPath,\n} from 'react-hook-form'\n\nimport {\n forwardRef,\n Box,\n FormControl,\n FormControlProps,\n FormLabel,\n FormHelperText,\n FormErrorMessage,\n Input,\n Textarea,\n Checkbox,\n Switch,\n useMergeRefs,\n} from '@chakra-ui/react'\n\nimport { NumberInput } from '@saas-ui/number-input'\nimport { PasswordInput } from '@saas-ui/password-input'\nimport { RadioInput } from '@saas-ui/radio'\nimport { PinInput } from '@saas-ui/pin-input'\nimport { Select, NativeSelect } from '@saas-ui/select'\n\nexport interface Option {\n value: string\n label?: string\n [key: string]: unknown\n}\n\nexport type FieldRules = Pick<\n RegisterOptions,\n 'required' | 'min' | 'max' | 'maxLength' | 'minLength' | 'pattern'\n>\n\nexport type FieldTypes =\n | 'text'\n | 'number'\n | 'password'\n | 'textarea'\n | 'select'\n | 'native-select'\n | 'checkbox'\n | 'radio'\n | 'switch'\n | 'pin'\n | string\n\nexport interface FieldProps<\n TFieldValues extends FieldValues = FieldValues,\n TName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>\n> extends Omit<FormControlProps, 'label' | 'type'> {\n /**\n * The field name\n */\n name: TName\n /**\n * The field label\n */\n label?: string\n /**\n * Hide the field label\n */\n hideLabel?: boolean\n /**\n * Field help text\n */\n help?: string\n /**\n * React hook form rules\n */\n rules?: Omit<\n RegisterOptions<TFieldValues, TName>,\n 'valueAsNumber' | 'valueAsDate' | 'setValueAs' | 'disabled'\n >\n /**\n * Options used for selects and radio fields\n */\n options?: Option[]\n /**\n * The field type\n * Build-in types:\n * - text\n * - number\n * - password\n * - textarea\n * - select\n * - native-select\n * - checkbox\n * - radio\n * - switch\n * - pin\n *\n * Will default to a text field if there is no matching type.\n * @default 'text'\n */\n type?: FieldTypes\n /**\n * The input placeholder\n */\n placeholder?: string\n}\n\nconst inputTypes: Record<FieldTypes, any> = {}\n\nconst defaultInputType = 'text'\n\nconst getInput = (type: string) => {\n return inputTypes[type] || inputTypes[defaultInputType]\n}\n\nconst getError = (name: string, formState: FormState<{ [x: string]: any }>) => {\n return get(formState.errors, name)\n}\n\nconst isTouched = (\n name: string,\n formState: FormState<{ [x: string]: any }>\n) => {\n return get(formState.touchedFields, name)\n}\n\nexport const BaseField: React.FC<FieldProps> = (props) => {\n const { name, label, help, variant, hideLabel, children, ...controlProps } =\n props\n\n const { formState } = useFormContext()\n\n const error = getError(name, formState)\n\n return (\n <FormControl variant={variant} {...controlProps} isInvalid={!!error}>\n {label && !hideLabel ? (\n <FormLabel variant={variant}>{label}</FormLabel>\n ) : null}\n <Box>\n {children}\n {help && !error?.message ? (\n <FormHelperText>{help}</FormHelperText>\n ) : null}\n {error?.message && (\n <FormErrorMessage>{error?.message}</FormErrorMessage>\n )}\n </Box>\n </FormControl>\n )\n}\nexport const Field = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown // Make sure attributes of custom components work. Need to change this to a global typedef at some point.\n },\n ref: React.ForwardedRef<typeof FormControl>\n ) => {\n const { type = defaultInputType } = props\n const InputComponent = getInput(type)\n\n return <InputComponent ref={ref} {...props} />\n }\n) as <TFieldValues extends FieldValues>(\n props: FieldProps<TFieldValues> & {\n [key: string]: unknown\n } & {\n ref?: React.ForwardedRef<typeof FormControl>\n }\n) => React.ReactElement\n\ninterface CreateFieldProps {\n displayName: string\n hideLabel?: boolean\n BaseField: React.FC<any>\n}\n\nconst createField = (\n InputComponent: React.FC<any>,\n { displayName, hideLabel, BaseField }: CreateFieldProps\n) => {\n const Field = forwardRef<FieldProps, typeof FormControl>((props, ref) => {\n const {\n name,\n label,\n help,\n isDisabled,\n isInvalid,\n isReadOnly,\n isRequired,\n rules,\n variant,\n ...inputProps\n } = props\n\n const inputRules = {\n required: isRequired,\n ...rules,\n }\n\n return (\n <BaseField\n name={name}\n label={label}\n help={help}\n hideLabel={hideLabel}\n isDisabled={isDisabled}\n isInvalid={isInvalid}\n isReadOnly={isReadOnly}\n isRequired={isRequired}\n variant={variant}\n >\n <InputComponent\n ref={ref}\n name={name}\n label={label}\n rules={inputRules}\n {...inputProps}\n />\n </BaseField>\n )\n })\n Field.displayName = displayName\n\n return Field\n}\n\nexport const withControlledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { control } = useFormContext()\n\n return (\n <Controller\n name={name}\n control={control}\n rules={rules}\n render={({ field: { ref: _ref, ...field } }) => (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )}\n />\n )\n }\n )\n}\n\nexport const withUncontrolledInput = (InputComponent: any) => {\n return forwardRef<FieldProps, typeof InputComponent>(\n ({ name, rules, ...inputProps }, ref) => {\n const { register } = useFormContext()\n\n const { ref: _ref, ...field } = register(name, rules)\n\n return (\n <InputComponent\n {...field}\n {...inputProps}\n ref={useMergeRefs(ref, _ref)}\n />\n )\n }\n )\n}\n\nexport interface RegisterFieldTypeOptions {\n isControlled?: boolean\n hideLabel?: boolean\n BaseField?: React.FC<any>\n}\n\n/**\n * Register a new field type\n * @param type The name for this field in kebab-case, eg `email` or `array-field`\n * @param component The React component\n * @param options\n * @param options.isControlled Set this to true if this is a controlled field.\n * @param options.hideLabel Hide the field label, for example for checkbox or switch field.\n */\nexport const registerFieldType = (\n type: string,\n component: React.FC<any>,\n options?: RegisterFieldTypeOptions\n) => {\n let InputComponent\n if (options?.isControlled) {\n InputComponent = withControlledInput(component)\n } else {\n InputComponent = withUncontrolledInput(component)\n }\n\n const Field = createField(InputComponent, {\n displayName: `${type\n .split('-')\n .map((part) => part.charAt(0).toUpperCase() + part.slice(1))\n .join('')}Field`,\n hideLabel: options?.hideLabel,\n BaseField: options?.BaseField || BaseField,\n })\n\n inputTypes[type] = Field\n\n return Field\n}\n\n// @todo Consider not registering all fields by default to lower the package size and computations.\n// Not all types may be required in a project.\nexport const InputField = registerFieldType('text', Input)\nexport const NumberInputField = registerFieldType('number', NumberInput, {\n isControlled: true,\n})\nexport const PasswordInputFIeld = registerFieldType('password', PasswordInput)\nexport const TextareaField = registerFieldType('textarea', Textarea)\nexport const SwitchField = registerFieldType(\n 'switch',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Switch ref={ref} {...props}>\n {label}\n </Switch>\n )\n }),\n {\n isControlled: true,\n hideLabel: true,\n }\n)\nexport const SelectField = registerFieldType('select', Select, {\n isControlled: true,\n})\nexport const CheckboxField = registerFieldType(\n 'checkbox',\n forwardRef(({ label, ...props }: { label?: string }, ref) => {\n return (\n <Checkbox ref={ref} {...props}>\n {label}\n </Checkbox>\n )\n }),\n {\n hideLabel: true,\n }\n)\nexport const RadioField = registerFieldType('radio', RadioInput, {\n isControlled: true,\n})\nexport const PinField = registerFieldType('pin', PinInput, {\n isControlled: true,\n})\nexport const NativeSelectField = registerFieldType(\n 'native-select',\n NativeSelect,\n { isControlled: true }\n)\n","import { SchemaOf, AnySchema, reach } from 'yup'\nexport { yupResolver } from '@hookform/resolvers/yup'\n\nimport { FieldProps } from '../field'\n\n// @TODO get proper typings for the schema fields\n\nconst getType = (field: any) => {\n if (field.spec.meta?.type) {\n return field.spec.meta.type\n }\n\n switch (field.type) {\n case 'array':\n return 'array'\n case 'object':\n return 'object'\n case 'number':\n return 'number'\n case 'date':\n return 'date'\n case 'string':\n default:\n return 'text'\n }\n}\n\ntype Options = {\n min?: number\n max?: number\n}\n\nconst getArrayOption = (field: any, name: string) => {\n for (const test of field.tests) {\n if (test.OPTIONS?.params[name]) return test.OPTIONS.params[name]\n }\n}\n\n/**\n * A helper function to render forms automatically based on a Yup schema\n *\n * @param schema The Yup schema\n * @returns {FieldProps[]}\n */\nexport const getFieldsFromSchema = (\n schema: SchemaOf<AnySchema>\n): FieldProps[] => {\n const fields = []\n\n let schemaFields: Record<string, any> = {}\n if (schema.type === 'array') {\n /* @ts-ignore this is actually valid */\n schemaFields = schema.innerType.fields\n } else {\n schemaFields = schema.fields\n }\n\n for (const name in schemaFields) {\n const field = schemaFields[name]\n\n const options: Options = {}\n if (field.type === 'array') {\n options.min = getArrayOption(field, 'min')\n options.max = getArrayOption(field, 'max')\n }\n\n fields.push({\n name,\n label: field.spec.label || name,\n type: getType(field),\n ...options,\n })\n }\n return fields\n}\n\nexport const getNestedSchema = (schema: SchemaOf<AnySchema>, path: string) => {\n return reach(schema, path)\n}\n","import * as React from 'react'\n\nimport { chakra, SimpleGrid, SimpleGridProps, useTheme } from '@chakra-ui/react'\n\nexport type FormLayoutProps = SimpleGridProps\n\ninterface FormLayoutItemProps {\n children: React.ReactNode\n}\n\nconst FormLayoutItem: React.FC<FormLayoutItemProps> = ({ children }) => {\n return <chakra.div>{children}</chakra.div>\n}\n\n/**\n * FormLayout\n *\n * Renders form items in a `SimpleGrid`\n * @see https://chakra-ui.com/docs/layout/simple-grid\n */\nexport const FormLayout = ({ children, ...props }: FormLayoutProps) => {\n const theme = useTheme()\n\n const defaultProps = theme.components?.FormLayout?.defaultProps ?? {\n spacing: 4,\n }\n\n const gridProps = {\n ...defaultProps,\n ...props,\n }\n\n return (\n <SimpleGrid {...gridProps}>\n {React.Children.map(children, (child) => {\n if (React.isValidElement(child)) {\n return <FormLayoutItem>{child}</FormLayoutItem>\n }\n return child\n })}\n </SimpleGrid>\n )\n}\n","import * as React from 'react'\n\nexport const mapNestedFields = (name: string, children: React.ReactNode) => {\n return React.Children.map(children, (child) => {\n if (React.isValidElement(child) && child.props.name) {\n return React.cloneElement(child, {\n ...child.props,\n name: `${name}.${child.props.name}`,\n })\n }\n return child\n })\n}\n","import * as React from 'react'\nimport {\n useFieldArray,\n useFormContext,\n UseFieldArrayReturn,\n} from 'react-hook-form'\n\nimport { createContext } from '@chakra-ui/react-utils'\n\nexport interface UseArrayFieldReturn extends UseFieldArrayReturn {\n /**\n * The array field name\n */\n name: string\n /**\n * The default value for new items\n */\n defaultValue: Record<string, any>\n /**\n * Min amount of items\n */\n min?: number\n /**\n * Max amount of items\n */\n max?: number\n}\n\nexport const [ArrayFieldProvider, useArrayFieldContext] =\n createContext<UseArrayFieldReturn>({\n name: 'ArrayFieldContext',\n })\n\nexport interface UseArrayFieldRowReturn {\n /**\n * Name of the array field including the index, eg 'field.0'\n */\n name: string\n /**\n * The field index\n */\n index: number\n /**\n * Remove this array item\n */\n remove: () => void\n /**\n * True if this is the first item\n */\n isFirst: boolean\n /**\n * True if this is the last item\n */\n isLast: boolean\n}\n\nexport const [ArrayFieldRowProvider, useArrayFieldRowContext] =\n createContext<UseArrayFieldRowReturn>({\n name: 'ArrayFieldRowContext',\n })\n\nexport interface ArrayFieldOptions {\n /**\n * The field name\n */\n name: string\n /**\n * Default value for new values in the array\n */\n defaultValue?: Record<string, any>\n /**\n * Default key name for rows, change this if your data uses 'id'\n * @default \"id\"\n */\n keyName?: string\n min?: number\n max?: number\n}\n\nexport const useArrayField = ({\n name,\n defaultValue = {},\n keyName,\n min,\n max,\n}: ArrayFieldOptions) => {\n const { control } = useFormContext()\n const context = useFieldArray({\n control,\n name,\n keyName,\n })\n\n return {\n ...context,\n name,\n defaultValue,\n min,\n max,\n }\n}\n\nexport interface UseArrayFieldRowProps {\n index: number\n}\n\nexport const useArrayFieldRow = ({ index }: UseArrayFieldRowProps) => {\n const { clearErrors } = useFormContext()\n const { name, remove, fields } = useArrayFieldContext()\n\n React.useEffect(() => {\n // reset errors, to make sure min/max errors reset correctly\n clearErrors(name)\n }, [])\n\n return {\n index,\n isFirst: index === 0,\n isLast: index === fields.length - 1,\n name: `${name}.${index}`,\n remove: React.useCallback(() => {\n clearErrors(name)\n remove(index)\n }, [index]),\n }\n}\n\nexport const useArrayFieldRemoveButton = () => {\n const { isFirst, remove } = useArrayFieldRowContext()\n const { min, fields } = useArrayFieldContext()\n\n const isDisabled = isFirst && !!(min && fields.length <= min)\n\n return {\n onClick: () => remove(),\n isDisabled,\n }\n}\n\nexport const useArrayFieldAddButton = () => {\n const { append, defaultValue, max, fields } = useArrayFieldContext()\n\n const isDisabled = !!(max && fields.length >= max)\n\n return {\n onClick: () =>\n append(defaultValue, {\n shouldFocus: false,\n }),\n isDisabled,\n }\n}\n","import * as React from 'react'\n\nimport { chakra, ResponsiveValue } from '@chakra-ui/system'\n\nimport { AddIcon, MinusIcon } from '@chakra-ui/icons'\nimport { IconButton, ButtonProps } from '@saas-ui/button'\n\nimport { FormLayout } from './layout'\nimport { BaseField, FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nimport {\n useArrayField,\n useArrayFieldRow,\n useArrayFieldContext,\n ArrayFieldProvider,\n ArrayFieldOptions,\n ArrayFieldRowProvider,\n useArrayFieldRowContext,\n useArrayFieldRemoveButton,\n useArrayFieldAddButton,\n} from './use-array-field'\n\ninterface ArrayField {\n id: string\n [key: string]: unknown\n}\n\ninterface ArrayFieldRowProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n /**\n * The array index\n */\n index: number\n}\n\nexport const ArrayFieldRow: React.FC<ArrayFieldRowProps> = ({\n children,\n columns,\n spacing,\n index,\n}) => {\n return (\n <ArrayFieldRowContainer index={index}>\n <ArrayFieldRowFields columns={columns} spacing={spacing}>\n {children}\n </ArrayFieldRowFields>\n <ArrayFieldRemoveButton />\n </ArrayFieldRowContainer>\n )\n}\n\nexport interface ArrayFieldRowFieldsProps {\n /**\n * Amount of field columns\n */\n columns?: ResponsiveValue<number>\n /**\n * Spacing between fields\n */\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const ArrayFieldRowFields: React.FC<ArrayFieldRowFieldsProps> = ({\n children,\n columns,\n spacing,\n ...layoutProps\n}) => {\n const { name } = useArrayFieldRowContext()\n return (\n <FormLayout\n flex=\"1\"\n columns={columns}\n gridGap={spacing}\n mr=\"2\"\n {...layoutProps}\n >\n {mapNestedFields(name, children)}\n </FormLayout>\n )\n}\n\nexport const ArrayFieldRowContainer: React.FC<ArrayFieldRowProps> = ({\n children,\n index,\n}) => {\n const context = useArrayFieldRow({ index })\n\n const styles = {\n display: 'flex',\n flexDirection: 'row',\n alignItems: 'flex-end',\n width: '100%',\n mb: 4,\n }\n\n return (\n <ArrayFieldRowProvider value={context}>\n <chakra.div __css={styles}>{children}</chakra.div>\n </ArrayFieldRowProvider>\n )\n}\n\nexport const ArrayFieldRemoveButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<MinusIcon />}\n aria-label=\"Remove row\"\n {...useArrayFieldRemoveButton()}\n {...props}\n />\n )\n}\n\nexport const ArrayFieldAddButton: React.FC<ButtonProps> = (props) => {\n return (\n <IconButton\n icon={<AddIcon />}\n aria-label=\"Add row\"\n float=\"right\"\n {...useArrayFieldAddButton()}\n {...props}\n />\n )\n}\n\nexport interface ArrayFieldProps\n extends ArrayFieldOptions,\n Omit<FieldProps, 'defaultValue'> {}\n\nexport const ArrayField: React.FC<ArrayFieldProps> = (props) => {\n const { children, ...containerProps } = props\n\n return (\n <ArrayFieldContainer {...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\nexport interface ArrayFieldRowsProps {\n children: (fields: ArrayField[]) => React.ReactElement | null\n}\n\nexport const ArrayFieldRows = ({\n children,\n}: ArrayFieldRowsProps): React.ReactElement | null => {\n const { fields } = useArrayFieldContext()\n return children(fields)\n}\n\nexport const ArrayFieldContainer: React.FC<ArrayFieldProps> = ({\n name,\n defaultValue,\n keyName,\n min,\n max,\n children,\n ...fieldProps\n}) => {\n const context = useArrayField({\n name,\n defaultValue,\n keyName,\n min,\n max,\n })\n\n return (\n <ArrayFieldProvider value={context}>\n <BaseField name={name} {...fieldProps}>\n {children}\n </BaseField>\n </ArrayFieldProvider>\n )\n}\n","import * as React from 'react'\nimport {\n FormControl,\n FormLabel,\n FormLabelProps,\n ResponsiveValue,\n useStyles,\n} from '@chakra-ui/react'\n\nimport { FormLayout } from './layout'\nimport { FieldProps } from './field'\n\nimport { mapNestedFields } from './utils'\n\nexport interface ObjectFieldProps extends FieldProps {\n name: string\n children: React.ReactNode\n columns?: ResponsiveValue<number>\n spacing?: ResponsiveValue<string | number>\n}\n\nexport const FormLegend = (props: FormLabelProps) => {\n const styles = useStyles()\n return <FormLabel as=\"legend\" sx={styles.legend} {...props} />\n}\n\nexport const ObjectField: React.FC<ObjectFieldProps> = (props) => {\n const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =\n props\n\n return (\n <FormControl name={name} as=\"fieldset\" {...fieldProps}>\n <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>\n <FormLayout columns={columns} gridGap={spacing}>\n {mapNestedFields(name, children)}\n </FormLayout>\n </FormControl>\n )\n}\n","import * as React from 'react'\nimport { getFieldsFromSchema, getNestedSchema } from './resolvers/yup'\n\nimport { FormLayout } from './layout'\nimport { Field, FieldProps } from './field'\n\nimport { ArrayField } from './array-field'\nimport { ObjectField } from './object-field'\n\nexport interface FieldsProps {\n schema: any\n}\n\nconst getNestedFields = (schema: any, name: string) => {\n return getFieldsFromSchema(getNestedSchema(schema, name)).map(\n ({ name, type, ...nestedFieldProps }: FieldProps): React.ReactNode => (\n <Field key={name} name={name} type={type} {...nestedFieldProps} />\n )\n )\n}\n\nexport const Fields: React.FC<FieldsProps> = ({ schema, ...props }) => {\n return (\n <FormLayout {...props}>\n {getFieldsFromSchema(schema).map(\n ({\n name,\n type,\n defaultValue,\n ...fieldProps\n }: FieldProps): React.ReactNode => {\n if (type === 'array') {\n return (\n <ArrayField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ArrayField>\n )\n } else if (type === 'object') {\n return (\n <ObjectField name={name} {...fieldProps}>\n {getNestedFields(schema, name)}\n </ObjectField>\n )\n }\n\n return <Field key={name} name={name} type={type} {...fieldProps} />\n }\n )}\n </FormLayout>\n )\n}\n","import * as React from 'react'\n\nimport { chakra, HTMLChakraProps, forwardRef } from '@chakra-ui/react'\n\nimport {\n useForm,\n FormProvider,\n UseFormProps,\n UseFormReturn,\n FieldValues,\n SubmitHandler,\n SubmitErrorHandler,\n} from 'react-hook-form'\n\nimport { yupResolver } from './resolvers/yup'\n\nexport type { UseFormReturn }\n\ninterface FormOptions<TFieldValues extends FieldValues = FieldValues> {\n /**\n * The form schema, currently supports Yup schema only.\n */\n schema?: any\n /**\n * The submit handler.\n */\n onSubmit: SubmitHandler<TFieldValues>\n /**\n * Triggers when there are validation errors.\n */\n onError?: SubmitErrorHandler<TFieldValues>\n /**\n * Ref on the HTMLFormElement.\n */\n formRef?: React.MutableRefObject<HTMLFormElement>\n}\n\nexport interface FormProps<TFieldValues extends FieldValues = FieldValues>\n extends UseFormProps<TFieldValues>,\n Omit<HTMLChakraProps<'form'>, 'onSubmit' | 'onError'>,\n FormOptions<TFieldValues> {}\n\n/**\n * @todo Figure out how to pass down FieldValues to all Field components,\n * if at all possible.\n */\nexport const Form = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: FormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const {\n mode = 'all',\n resolver,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n schema,\n defaultValues,\n onSubmit,\n onError,\n formRef,\n children,\n ...rest\n } = props\n\n const form = {\n mode,\n resolver,\n defaultValues,\n reValidateMode,\n shouldFocusError,\n shouldUnregister,\n shouldUseNativeValidation,\n criteriaMode,\n delayError,\n }\n\n // @todo remove yup dependency and just use resolver prop?\n if (schema) {\n form.resolver = yupResolver(schema)\n }\n\n const methods = useForm<TFieldValues>(form)\n const { handleSubmit } = methods\n\n // This exposes the useForm api through the forwareded ref\n React.useImperativeHandle(ref, () => methods, [ref, methods])\n\n return (\n <FormProvider {...methods}>\n <chakra.form\n ref={formRef}\n onSubmit={handleSubmit(onSubmit, onError)}\n {...rest}\n >\n {children}\n </chakra.form>\n </FormProvider>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: FormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\n\nimport { useFormContext } from 'react-hook-form'\n\nimport { Button, ButtonProps } from '@saas-ui/button'\n\nimport { forwardRef } from '@chakra-ui/system'\n\nexport interface SubmitButtonProps extends ButtonProps {\n /**\n * Disable the submit button if the form is untouched.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfUntouched`\n */\n disableIfUntouched?: boolean\n /**\n * Disable the submit button if the form is invalid.\n *\n * Change the default behavior by updating\n * `SubmitButton.defaultProps.disableIfInvalid`\n */\n disableIfInvalid?: boolean\n}\n\nexport const SubmitButton = forwardRef<SubmitButtonProps, 'button'>(\n (props, ref) => {\n const { children, disableIfUntouched, disableIfInvalid, ...rest } = props\n const { formState } = useFormContext()\n\n const isDisabled =\n (disableIfUntouched && !formState.isDirty) ||\n (disableIfInvalid && !formState.isValid)\n\n return (\n <Button\n type=\"submit\"\n isLoading={formState.isSubmitting}\n isPrimary\n ref={ref}\n isDisabled={isDisabled}\n {...rest}\n >\n {children}\n </Button>\n )\n }\n)\n\nSubmitButton.defaultProps = {\n label: 'Submit',\n disableIfUntouched: false,\n disableIfInvalid: false,\n}\n","import * as React from 'react'\nimport { FieldValues, UseFormReturn } from 'react-hook-form'\nimport { forwardRef } from '@chakra-ui/react'\n\nimport { Form, FormProps } from './form'\n\nimport { FormLayout } from './layout'\nimport { Fields } from './fields'\nimport { SubmitButton } from './submit-button'\n\ninterface AutoFormOptions {\n schema: any\n submitLabel?: false | string\n}\n\nexport interface AutoFormProps<TFieldValues extends FieldValues>\n extends Omit<FormProps<TFieldValues>, 'schema'>,\n AutoFormOptions {}\n\nexport const AutoForm = forwardRef(\n <TFieldValues extends FieldValues = FieldValues>(\n props: AutoFormProps<TFieldValues>,\n ref: React.ForwardedRef<UseFormReturn<TFieldValues>>\n ) => {\n const { schema, submitLabel = 'Submit', ...rest } = props\n return (\n <Form {...rest} schema={schema} ref={ref}>\n <FormLayout>\n {<Fields schema={schema} />}\n {submitLabel && <SubmitButton label={submitLabel} />}\n </FormLayout>\n </Form>\n )\n }\n) as <TFieldValues extends FieldValues>(\n props: AutoFormProps<TFieldValues> & {\n ref?: React.ForwardedRef<UseFormReturn<TFieldValues>>\n }\n) => React.ReactElement\n","import * as React from 'react'\nimport {\n useFormContext,\n useWatch,\n FieldValues,\n UseFormReturn,\n} from 'react-hook-form'\n\nexport interface DisplayIfProps<TFieldValues> {\n children: React.ReactElement\n name: string\n defaultValue?: unknown\n isDisabled?: boolean\n isExact?: boolean\n condition?: (value: unknown, context: UseFormReturn<TFieldValues>) => boolean\n}\n\nexport const DisplayIf = <TFieldValues extends FieldValues = FieldValues>({\n children,\n name,\n defaultValue,\n isDisabled,\n isExact,\n condition = (value) => !!value,\n}: DisplayIfProps<TFieldValues>) => {\n const value = useWatch({\n name,\n defaultValue,\n disabled: isDisabled,\n exact: isExact,\n })\n const context = useFormContext<TFieldValues>()\n return condition(value, context) ? children : null\n}\n"],"names":["DisplayField","_ref","name","label","props","getValues","useFormContext","React","FormControl","FormLabel","htmlFor","Text","fontSize","inputTypes","defaultInputType","BaseField","help","variant","hideLabel","children","controlProps","formState","error","get","errors","getError","isInvalid","Box","message","FormHelperText","FormErrorMessage","Field","forwardRef","ref","type","InputComponent","getInput","withControlledInput","rules","inputProps","control","Controller","render","_ref3","field","useMergeRefs","withUncontrolledInput","register","registerFieldType","component","options","isControlled","displayName","isDisabled","isReadOnly","isRequired","inputRules","required","createField","split","map","part","charAt","toUpperCase","slice","join","InputField","Input","NumberInputField","NumberInput","PasswordInputFIeld","PasswordInput","TextareaField","Textarea","SwitchField","Switch","SelectField","Select","CheckboxField","Checkbox","RadioField","RadioInput","PinField","PinInput","NativeSelectField","NativeSelect","getType","spec","meta","_field$spec$meta","getArrayOption","test","tests","OPTIONS","_test$OPTIONS","params","getFieldsFromSchema","schema","fields","schemaFields","innerType","min","max","push","FormLayoutItem","chakra","div","FormLayout","gridProps","useTheme","components","_theme$components","_theme$components$For2","defaultProps","spacing","SimpleGrid","Children","child","isValidElement","mapNestedFields","cloneElement","ArrayFieldProvider","useArrayFieldContext","createContext","ArrayFieldRowProvider","useArrayFieldRowContext","useArrayField","defaultValue","keyName","useFieldArray","useArrayFieldRow","index","clearErrors","remove","useEffect","isFirst","isLast","length","useCallback","useArrayFieldRemoveButton","onClick","useArrayFieldAddButton","append","shouldFocus","ArrayFieldRow","columns","ArrayFieldRowContainer","ArrayFieldRowFields","ArrayFieldRemoveButton","layoutProps","flex","gridGap","mr","context","value","__css","display","flexDirection","alignItems","width","mb","IconButton","icon","MinusIcon","ArrayFieldAddButton","AddIcon","float","ArrayField","containerProps","ArrayFieldContainer","ArrayFieldRows","id","key","_ref2","fieldProps","FormLegend","styles","useStyles","as","sx","legend","ObjectField","getNestedFields","path","reach","getNestedSchema","nestedFieldProps","Fields","Form","mode","resolver","reValidateMode","shouldFocusError","shouldUnregister","shouldUseNativeValidation","criteriaMode","delayError","defaultValues","onSubmit","onError","formRef","rest","form","yupResolver","methods","useForm","handleSubmit","useImperativeHandle","FormProvider","SubmitButton","disableIfUntouched","disableIfInvalid","Button","isLoading","isSubmitting","isPrimary","isDirty","isValid","AutoForm","submitLabel","DisplayIf","isExact","condition","useWatch","disabled","exact"],"mappings":"u4CAgBaA,EAA4CC,QAACC,KACxDA,EADwDC,MAExDA,KAEGC,SAEH,MAAMC,UAAEA,GAAcC,iBAEtB,OACEC,gBAACC,EAAgBJ,EACdD,eAAQI,gBAACE,GAAUC,QAASR,GAAOC,GAAqB,kBACzDI,gBAACI,GAAKC,SAAS,MAAMP,EAAUH,kPCoF/BW,EAAsC,GAEt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,SACLmL,UAAWhM,EAAUiM,aACrBC,aACAtL,IAAKA,EACLoB,WATD6J,IAAuB7L,EAAUmM,SACjCL,IAAqB9L,EAAUoM,SAS1BhB,GAEHtL,KAMT8L,GAAahG,aAAe,CAC1B9G,MAAO,SACP+M,oBAAoB,EACpBC,kBAAkB,qCCjCPO,GAAW1L,EACtB,CACE5B,EACA6B,KAEA,MAAMgE,OAAEA,EAAF0H,YAAUA,EAAc,UAAsBvN,EAATqM,IAASrM,mBACpD,OACEG,gBAACqL,QAASa,GAAMxG,OAAQA,EAAQhE,IAAKA,iBACnC1B,gBAACoG,qBACEpG,gBAACoL,IAAO1F,OAAQA,IAChB0H,gBAAepN,gBAAC0M,IAAa9M,MAAOwN,QCZlCC,GAAY,EACvBzM,SAAAA,EACAjB,KAAAA,EACA6H,aAAAA,EACA1E,WAAAA,EACAwK,QAAAA,EACAC,UAAAA,EAAapE,CAAAA,KAAYA,MASlBoE,EAPOC,EAAS,CACrB7N,KAAAA,EACA6H,aAAAA,EACAiG,SAAU3K,EACV4K,MAAOJ,IAEOvN,KACmBa,EAAW"}
@@ -1,5 +1,5 @@
1
1
  import * as React from 'react';
2
- import { ResponsiveValue } from '@chakra-ui/system';
2
+ import { FormLabelProps, ResponsiveValue } from '@chakra-ui/react';
3
3
  import { FieldProps } from './field';
4
4
  export interface ObjectFieldProps extends FieldProps {
5
5
  name: string;
@@ -7,5 +7,6 @@ export interface ObjectFieldProps extends FieldProps {
7
7
  columns?: ResponsiveValue<number>;
8
8
  spacing?: ResponsiveValue<string | number>;
9
9
  }
10
+ export declare const FormLegend: (props: FormLabelProps) => JSX.Element;
10
11
  export declare const ObjectField: React.FC<ObjectFieldProps>;
11
12
  //# sourceMappingURL=object-field.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"object-field.d.ts","sourceRoot":"","sources":["../src/object-field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AAGnD,OAAO,EAAa,UAAU,EAAE,MAAM,SAAS,CAAA;AAI/C,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;IACjC,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;CAC3C;AAED,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CASlD,CAAA"}
1
+ {"version":3,"file":"object-field.d.ts","sourceRoot":"","sources":["../src/object-field.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAGL,cAAc,EACd,eAAe,EAEhB,MAAM,kBAAkB,CAAA;AAGzB,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAA;AAIpC,MAAM,WAAW,gBAAiB,SAAQ,UAAU;IAClD,IAAI,EAAE,MAAM,CAAA;IACZ,QAAQ,EAAE,KAAK,CAAC,SAAS,CAAA;IACzB,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,CAAC,CAAA;IACjC,OAAO,CAAC,EAAE,eAAe,CAAC,MAAM,GAAG,MAAM,CAAC,CAAA;CAC3C;AAED,eAAO,MAAM,UAAU,UAAW,cAAc,gBAG/C,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,KAAK,CAAC,EAAE,CAAC,gBAAgB,CAYlD,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@saas-ui/forms",
3
- "version": "0.3.1",
3
+ "version": "0.3.4",
4
4
  "description": "Theme and components agnostic SaasProvider",
5
5
  "source": "src/index.ts",
6
6
  "exports": {
@@ -68,10 +68,10 @@
68
68
  "@saas-ui/button": "0.2.1",
69
69
  "@saas-ui/input-right-button": "0.2.1",
70
70
  "@saas-ui/number-input": "0.2.2",
71
- "@saas-ui/password-input": "0.2.1",
71
+ "@saas-ui/password-input": "0.2.2",
72
72
  "@saas-ui/pin-input": "0.2.1",
73
73
  "@saas-ui/radio": "0.2.1",
74
- "@saas-ui/select": "0.2.1",
74
+ "@saas-ui/select": "0.2.2",
75
75
  "react-hook-form": "^7.22.0"
76
76
  },
77
77
  "peerDependencies": {
package/src/field.tsx CHANGED
@@ -187,6 +187,7 @@ const createField = (
187
187
  const {
188
188
  name,
189
189
  label,
190
+ help,
190
191
  isDisabled,
191
192
  isInvalid,
192
193
  isReadOnly,
@@ -205,11 +206,12 @@ const createField = (
205
206
  <BaseField
206
207
  name={name}
207
208
  label={label}
209
+ help={help}
208
210
  hideLabel={hideLabel}
209
211
  isDisabled={isDisabled}
210
212
  isInvalid={isInvalid}
211
213
  isReadOnly={isReadOnly}
212
- isRequired={inputRules.required}
214
+ isRequired={isRequired}
213
215
  variant={variant}
214
216
  >
215
217
  <InputComponent
package/src/form.tsx CHANGED
@@ -14,6 +14,8 @@ import {
14
14
 
15
15
  import { yupResolver } from './resolvers/yup'
16
16
 
17
+ export type { UseFormReturn }
18
+
17
19
  interface FormOptions<TFieldValues extends FieldValues = FieldValues> {
18
20
  /**
19
21
  * The form schema, currently supports Yup schema only.
@@ -1,8 +1,14 @@
1
1
  import * as React from 'react'
2
- import { ResponsiveValue } from '@chakra-ui/system'
2
+ import {
3
+ FormControl,
4
+ FormLabel,
5
+ FormLabelProps,
6
+ ResponsiveValue,
7
+ useStyles,
8
+ } from '@chakra-ui/react'
3
9
 
4
10
  import { FormLayout } from './layout'
5
- import { BaseField, FieldProps } from './field'
11
+ import { FieldProps } from './field'
6
12
 
7
13
  import { mapNestedFields } from './utils'
8
14
 
@@ -13,13 +19,21 @@ export interface ObjectFieldProps extends FieldProps {
13
19
  spacing?: ResponsiveValue<string | number>
14
20
  }
15
21
 
22
+ export const FormLegend = (props: FormLabelProps) => {
23
+ const styles = useStyles()
24
+ return <FormLabel as="legend" sx={styles.legend} {...props} />
25
+ }
26
+
16
27
  export const ObjectField: React.FC<ObjectFieldProps> = (props) => {
17
- const { name, children, columns, spacing, ...fieldProps } = props
28
+ const { name, label, hideLabel, children, columns, spacing, ...fieldProps } =
29
+ props
30
+
18
31
  return (
19
- <BaseField name={name} {...fieldProps}>
32
+ <FormControl name={name} as="fieldset" {...fieldProps}>
33
+ <FormLegend display={hideLabel ? 'none' : 'block'}>{label}</FormLegend>
20
34
  <FormLayout columns={columns} gridGap={spacing}>
21
35
  {mapNestedFields(name, children)}
22
36
  </FormLayout>
23
- </BaseField>
37
+ </FormControl>
24
38
  )
25
39
  }