mui-rff
Version:
Set of modern wrapper components to facilitate using Material UI with React Final Form
2 lines • 9.81 kB
JavaScript
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});var e=Object.create,t=Object.defineProperty,n=Object.getOwnPropertyDescriptor,r=Object.getOwnPropertyNames,i=Object.getPrototypeOf,a=Object.prototype.hasOwnProperty,o=(e,i,o,s)=>{if(i&&typeof i==`object`||typeof i==`function`)for(var c=r(i),l=0,u=c.length,d;l<u;l++)d=c[l],!a.call(e,d)&&d!==o&&t(e,d,{get:(e=>i[e]).bind(null,d),enumerable:!(s=n(i,d))||s.enumerable});return e},s=(n,r,a)=>(a=n==null?{}:e(i(n)),o(r||!n||!n.__esModule?t(a,`default`,{value:n,enumerable:!0}):a,n));let c=require(`@mui/material/Autocomplete`);c=s(c);let l=require(`@mui/material/TextField`);l=s(l);let u=require(`react-final-form`),d=require(`@mui/material`),f=require(`react/jsx-runtime`),p=require(`@mui/x-date-pickers`);function m({showError:e,meta:t,formHelperTextProps:n,helperText:r}){return e?(0,f.jsx)(d.FormHelperText,{...n,children:t.error||t.submitError}):r?(0,f.jsx)(d.FormHelperText,{...n,children:r}):null}var h={subscription:{error:!0,submitError:!0,dirtySinceLastSubmit:!0,touched:!0,modified:!0}},g=e=>(0,u.useField)(e,h),_=({meta:{submitError:e,dirtySinceLastSubmit:t,error:n,touched:r,modified:i}})=>!!((e&&!t||n)&&(r||i)),v=({meta:{submitError:e,dirtySinceLastSubmit:t,error:n,touched:r}})=>!!((e&&!t||n)&&r);function y({name:e,fieldProps:t,showError:n=_,...r}){return(0,f.jsx)(u.Field,{name:e,render:e=>(0,f.jsx)(b,{fieldRenderProps:e,showError:n,...r}),...t})}function b(e){let{fieldRenderProps:{input:{name:t,value:n,onChange:r,onFocus:i,onBlur:a},meta:o},options:s,label:u,required:d,multiple:p,textFieldProps:m,getOptionValue:h,showError:g,onChange:_,...v}=e;function y(e){return h?p?e?e.map(h):null:e?h(e):null:e}let{helperText:b,...x}=v,{variant:S,onFocus:C,onBlur:w,slotProps:T,...E}=m||{},D;if(!h)D=n;else if(n)for(let e of s){let t=h(e);if(p){D||=[];for(let r of n)r===t&&D.push(e)}else n===t&&(D=e)}let O=(e,t,n,i)=>{r(y(t)),_&&_(e,t,n,i)},{error:k,submitError:A}=o,j=g({meta:o}),M=typeof T?.input==`object`?T.input:void 0;return(0,f.jsx)(c.default,{multiple:p,onChange:O,options:s,renderInput:e=>{let{InputLabelProps:n,InputProps:r,inputProps:o,...s}=e;return(0,f.jsx)(l.default,{error:j,helperText:j?k||A:b,label:u,name:t,onBlur:e=>{w?.(e),a(e)},onFocus:e=>{C?.(e),i(e)},required:d,variant:S,...s,...E,fullWidth:!0,slotProps:{...T,htmlInput:{...o,...T?.htmlInput},input:{...r,...M,...M?.startAdornment&&{startAdornment:(0,f.jsxs)(f.Fragment,{children:[M.startAdornment,r?.startAdornment]})},...M?.endAdornment&&{endAdornment:(0,f.jsxs)(f.Fragment,{children:[r?.endAdornment,M.endAdornment]})}},inputLabel:{...n,...T?.inputLabel}}})},value:D||(p?[]:null),...x})}function x(e){let{required:t,label:n,data:r,name:i,helperText:a,fieldProps:o,formControlProps:s,formGroupProps:c,formLabelProps:l,formControlLabelProps:p,formHelperTextProps:h,showError:v=_,...y}=e,b=Array.isArray(r)?r:[r],x=!Array.isArray(r),S=g(i),C=v(S);return(0,f.jsxs)(d.FormControl,{error:C,required:t,...s,children:[n?(0,f.jsx)(d.FormLabel,{...l,children:n}):null,(0,f.jsx)(d.FormGroup,{...c,children:b.map(e=>(0,f.jsx)(d.FormControlLabel,{control:(0,f.jsx)(u.Field,{name:i,render:({input:{name:n,value:r,onChange:i,checked:a,onBlur:o,onFocus:s,...c}})=>(0,f.jsx)(d.Checkbox,{checked:a,disabled:e.disabled,indeterminate:e.indeterminate,name:n,onChange:i,slotProps:{input:{required:t,onBlur:o,onFocus:s,...c}},value:r,...y}),type:`checkbox`,...o}),disabled:e.disabled,label:e.label,name:i,value:x?void 0:e.value,...p},`${i}${e.label}`))}),(0,f.jsx)(m,{formHelperTextProps:h,helperText:a,meta:S.meta,showError:C})]})}function S(e){let{name:t,fieldProps:n,...r}=e;return(0,f.jsx)(u.Field,{name:t,render:e=>(0,f.jsx)(C,{...e,...r}),...n})}function C(e){let{input:{name:t,onChange:n,value:r,...i},meta:a,showError:o=_,...s}=e,{error:c,submitError:l}=a,u=o({meta:a}),{helperText:d,textFieldProps:m,slotProps:h,required:g,...v}=s;return(0,f.jsx)(p.DatePicker,{onChange:n,value:r===``?null:r,...v,slotProps:{...h,textField:{...m,helperText:u?c||l:d,inputProps:{onBlur:e=>{i.onBlur(e)},onFocus:e=>{i.onFocus(e)}},error:u,fullWidth:!0,name:t,onChange:n,value:r===``?null:r,required:g}}})}function w(e){let{name:t,fieldProps:n,...r}=e;return(0,f.jsx)(u.Field,{name:t,render:e=>(0,f.jsx)(T,{...e,...r}),...n})}function T(e){let{input:{name:t,onChange:n,value:r,...i},meta:a,showError:o=_,...s}=e,{error:c,submitError:l}=a,u=o({meta:a}),{helperText:d,textFieldProps:m,slotProps:h,required:g,...v}=s;return(0,f.jsx)(p.DateTimePicker,{onChange:n,value:r===``?null:r,...v,slotProps:{...h,textField:{...m,helperText:u?c||l:d,inputProps:{onBlur:e=>{i.onBlur(e)},onFocus:e=>{i.onFocus(e)}},error:u,fullWidth:!0,name:t,onChange:n,value:r===``?null:r,required:g}}})}function E(){return(0,f.jsx)(u.FormSpy,{subscription:{values:!0},children:({values:e})=>(0,f.jsx)(`pre`,{children:JSON.stringify(e,void 0,2)})})}function D(e){let{name:t,data:n,label:r,required:i,helperText:a,formLabelProps:o,formControlLabelProps:s,fieldProps:c,formControlProps:l,radioGroupProps:p,formHelperTextProps:h,showError:v=_,...y}=e,b=g(t),x=v(b);return(0,f.jsxs)(d.FormControl,{error:x,required:i,...l,children:[!!r&&(0,f.jsx)(d.FormLabel,{...o,children:r}),(0,f.jsx)(d.RadioGroup,{...p,children:n.map(e=>(0,f.jsx)(d.FormControlLabel,{control:(0,f.jsx)(u.Field,{name:t,render:({input:{name:t,value:n,onChange:r,checked:a,onBlur:o,onFocus:s,...c}})=>(0,f.jsx)(d.Radio,{checked:a,disabled:e.disabled,name:t,onChange:r,required:i,slotProps:{input:{required:i,onBlur:o,onFocus:s,...c}},value:n,...y}),type:`radio`,...c}),disabled:e.disabled,label:e.label,name:t,value:e.value,...s},`${t}${e.label}`))}),(0,f.jsx)(m,{formHelperTextProps:h,helperText:a,meta:b.meta,showError:x})]})}function O(e){let{name:t,label:n,data:r,children:i,required:a,multiple:o,helperText:s,fieldProps:c,inputLabelProps:l,formControlProps:p,formHelperTextProps:h,menuItemProps:v,showError:y=_,...b}=e;if(!(r||i))throw Error(`Please specify either children or data as an attribute.`);let{variant:x}=b,S=g(t),C=y(S);return(0,f.jsx)(u.Field,{name:t,render:({input:{name:e,value:c,onChange:u,...g}})=>{let _=o&&!c?[]:c,y=`select-input-${t}`;return(0,f.jsxs)(d.FormControl,{error:C,fullWidth:!0,required:a,variant:x,...p,children:[!!n&&(0,f.jsx)(d.InputLabel,{id:y,...l,children:n}),(0,f.jsx)(d.Select,{inputProps:{required:a,...g},label:n,labelId:y,multiple:o,name:e,onChange:u,value:_,...b,children:r?r.map(e=>(0,f.jsx)(d.MenuItem,{disabled:e.disabled,value:e.value,...v,children:e.label},`${e.value}${e.label}`)):i}),(0,f.jsx)(m,{formHelperTextProps:h,helperText:s,meta:S.meta,showError:C})]})},...c})}function k(e){let{name:t,data:n,label:r,required:i,helperText:a,fieldProps:o,formControlProps:s,formGroupProps:c,formLabelProps:l,formControlLabelProps:p,formHelperTextProps:h,showError:v=_,...y}=e,b=Array.isArray(n)?n:[n],x=!Array.isArray(n),S=g(t),C=v(S);return(0,f.jsxs)(d.FormControl,{error:C,required:i,...s,children:[r?(0,f.jsx)(d.FormLabel,{...l,children:r}):null,(0,f.jsx)(d.FormGroup,{...c,children:b.map(e=>(0,f.jsx)(d.FormControlLabel,{control:(0,f.jsx)(u.Field,{name:t,render:({input:{name:t,value:n,onChange:r,checked:a,...o}})=>(0,f.jsx)(d.Switch,{checked:a,disabled:e.disabled,name:t,onChange:r,required:i,slotProps:{input:{required:i,...o}},value:n,...y}),type:`checkbox`,...o}),disabled:e.disabled,label:e.label,name:t,value:x?void 0:e.value,...p},`${t}${e.label}`))}),(0,f.jsx)(m,{formHelperTextProps:h,helperText:a,meta:S.meta,showError:C})]})}function A({name:e,type:t,fieldProps:n,showError:r=_,fullWidth:i=!0,...a}){return(0,f.jsx)(u.Field,{name:e,type:t,...n,render:t=>(0,f.jsx)(j,{fieldRenderProps:t,fullWidth:i,name:e,showError:r,...a})})}function j({fieldRenderProps:{input:{value:e,type:t,onChange:n,onBlur:r,onFocus:i,...a},meta:o},helperText:s,showError:c,slotProps:l,...u}){let{error:p,submitError:m}=o,h=c({meta:o});return(0,f.jsx)(d.TextField,{error:h,helperText:h?p||m:s,onBlur:r,onChange:n,onFocus:i,slotProps:{...l,htmlInput:{...a,...l?.htmlInput}},type:t,value:e,...u})}function M(e){let{name:t,fieldProps:n,...r}=e;return(0,f.jsx)(u.Field,{name:t,render:e=>(0,f.jsx)(N,{...e,...r}),...n})}function N(e){let{input:{name:t,onChange:n,value:r,...i},meta:a,showError:o=_,...s}=e,{error:c,submitError:l}=a,u=o({meta:a}),{helperText:d,textFieldProps:m,required:h,...g}=s;return(0,f.jsx)(p.TimePicker,{onChange:n,value:r===``?null:r,...g,slotProps:{textField:{...m,helperText:u?c||l:d,inputProps:{onBlur:e=>{i.onBlur(e)},onFocus:e=>{i.onFocus(e)}},error:u,fullWidth:!0,name:t,onChange:n,value:r===``?null:r,required:h}}})}var P=/[,[\].]+?/;function F(e,t,n){let r=String.prototype.split.call(t,P).filter(Boolean).reduce((e,t)=>e==null?e:e[t],e);return r===void 0||r===e?n:r}function I(e,t,n){return new Object(e)===e?(Array.isArray(t)||(t=t.toString().match(/[^.[\]]+/g)||[]),t.slice(0,-1).reduce((e,n,r)=>new Object(e[n])===e[n]?e[n]:e[n]=Math.abs(t[r+1])>>0==+t[r+1]?[]:{},e)[t.at(-1)]=n,e):e}function L(e,t){return e.inner.reduce((e,n)=>{let{path:r,message:i}=n,a=t===void 0?i:t(n);if(r&&F(e,r)){let t=F(e,r);t.push(a),I(e,r,t)}else I(e,r,[a]);return e},{})}function R(e,t){return async n=>{try{return await e.validate(n,{abortEarly:!1}),{}}catch(e){return L(e,t)}}}function z(e,t){return n=>{try{return e.validateSync(n,{abortEarly:!1}),{}}catch(e){return L(e,t)}}}function B(e){let t=e.fields;return Object.keys(t).reduce((e,n)=>(t[n].fields?e[n]=B(t[n]):e[n]=!t[n].spec.optional,e),{})}exports.Autocomplete=y,exports.Checkboxes=x,exports.DatePicker=S,exports.DateTimePicker=w,exports.Debug=E,exports.ErrorMessage=m,exports.Radios=D,exports.Select=O,exports.Switches=k,exports.TextField=A,exports.TimePicker=M,exports.makeRequired=B,exports.makeValidate=R,exports.makeValidateSync=z,exports.showErrorOnBlur=v,exports.showErrorOnChange=_,exports.useFieldForErrors=g;
//# sourceMappingURL=mui-rff.cjs.js.map