@flipdish/portal-library 1.0.40 → 1.0.41
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/components/ui/Form/GenericAutocompleteField.cjs.js +1 -1
- package/dist/components/ui/Form/GenericAutocompleteField.cjs.js.map +1 -1
- package/dist/components/ui/Form/GenericAutocompleteField.js +1 -1
- package/dist/components/ui/Form/GenericAutocompleteField.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("react/jsx-runtime"),r=require("@mui/material"),t=require("formik"),
|
|
1
|
+
"use strict";var e=require("react/jsx-runtime"),r=require("@mui/material"),t=require("formik"),o=require("../../custom-hooks/useRenderValidText.cjs.js"),i=require("./FormItemLayout.cjs.js");module.exports=({label:l,fieldName:n,options:a,placeholder:d,getOptionLabel:s,validation:u,onChange:p,onInputChange:h,isOptionEqualToValue:c,onScroll:m,layout:x="horizontal",variant:g="outlined",disabled:j=!1,loading:v=!1,required:b=!1})=>{const q=()=>e.jsx(t.Field,{name:n,validate:u,children:({field:t,form:i})=>{const{errors:u,touched:q,isSubmitting:f}=i,y=u[t.name],F=!!y&&q[t.name],I=o({fieldError:y,showError:F,touched:!!q[t.name],value:t.value});return e.jsx(r.Autocomplete,{options:a,getOptionLabel:s,isOptionEqualToValue:c,onChange:(e,r)=>{i.setFieldValue(n,r),p&&p(e,r)},onInputChange:h,disabled:f||j,fullWidth:!0,loading:v,renderInput:t=>e.jsx(r.TextField,{...t,label:"standard"===g?void 0:l,variant:g,"data-testid":`text-field-${n}`,fullWidth:!0,style:{paddingRight:"horizontal"===x?16:0},placeholder:d||void 0,required:b,error:F,helperText:I,FormHelperTextProps:{children:" ",style:{textAlign:"right"}},InputProps:{...t.InputProps,endAdornment:e.jsxs(e.Fragment,{children:[v&&e.jsx(r.CircularProgress,{color:"inherit",size:25}),t.InputProps.endAdornment]})}}),ListboxProps:{onScroll:m}})}});return"vertical"===x?e.jsxs(e.Fragment,{children:["standard"===g&&e.jsx(r.Typography,{variant:"subtitle1",component:"h3",color:"textPrimary",children:l}),q()]}):e.jsx(i,{label:l,children:q()})};
|
|
2
2
|
//# sourceMappingURL=GenericAutocompleteField.cjs.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericAutocompleteField.cjs.js","sources":["../../../../src/components/ui/Form/GenericAutocompleteField.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { TextFieldProps, Autocomplete, TextField, Typography, CircularProgress } from '@mui/material';\nimport { Field, FieldProps } from 'formik';\nimport { SyntheticEvent } from 'react';\nimport useRenderValidText from '../../custom-hooks/useRenderValidText';\nimport FormItemLayout from './FormItemLayout';\n\ntype Props = {\n label: string;\n fieldName: string;\n options: any[];\n placeholder?: string;\n getOptionLabel?: (option: any) => string;\n validation?: (value: string) => string | undefined;\n onChange?: (e: SyntheticEvent, value: any) => void;\n onInputChange?: (e: SyntheticEvent, value: any) => void;\n isOptionEqualToValue?: (option: any, value: any) => boolean;\n onScroll?: (e: React.UIEvent<HTMLUListElement, UIEvent>) => void;\n layout?: 'horizontal' | 'vertical';\n variant?: TextFieldProps['variant'];\n disabled?: boolean;\n loading?: boolean;\n required?: boolean;\n};\n\nconst GenericAutocompleteField = ({\n label,\n fieldName,\n options,\n placeholder,\n getOptionLabel,\n validation,\n onChange,\n onInputChange,\n isOptionEqualToValue,\n onScroll,\n layout = 'horizontal',\n variant = 'outlined',\n disabled = false,\n loading = false,\n required = false,\n}: Props) => {\n const renderField = () => {\n return (\n <Field name={fieldName} validate={validation}>\n {({ field, form }: FieldProps) => {\n const { errors, touched, isSubmitting } = form;\n const fieldError = errors[field.name] as string | undefined;\n const showError = !!fieldError && (touched[field.name] as boolean | undefined);\n const helperText = useRenderValidText({\n fieldError,\n showError,\n touched: !!touched[field.name],\n value: field.value,\n });\n\n return (\n <Autocomplete\n options={options}\n getOptionLabel={getOptionLabel}\n isOptionEqualToValue={isOptionEqualToValue}\n onChange={(e: SyntheticEvent, value: any) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n form.setFieldValue(fieldName, value);\n if (onChange) {\n onChange(e, value);\n }\n }}\n onInputChange={onInputChange}\n disabled={isSubmitting || disabled}\n fullWidth\n loading={loading}\n renderInput={(params) => (\n <TextField\n {...params}\n label={variant === 'standard' ? undefined : label}\n variant={variant}\n data-testid={`text-field-${fieldName}`}\n fullWidth\n style={{ paddingRight: layout === 'horizontal' ? 16 : 0 }}\n placeholder={placeholder ? placeholder : undefined}\n required={required}\n error={showError}\n helperText={helperText}\n FormHelperTextProps={{\n children: ' ', // reserves line height for error message\n style: { textAlign: 'right' },\n }}\n InputProps={{\n endAdornment: (\n <>\n {loading && <CircularProgress color=\"inherit\" size={25} />}\n {params.InputProps.endAdornment}\n </>\n ),\n }}\n />\n )}\n ListboxProps={{\n onScroll,\n }}\n />\n );\n }}\n </Field>\n );\n };\n\n if (layout === 'vertical') {\n return (\n <>\n {variant === 'standard' && (\n <Typography variant=\"subtitle1\" component=\"h3\" color=\"textPrimary\">\n {label}\n </Typography>\n )}\n {renderField()}\n </>\n );\n }\n\n return <FormItemLayout label={label}>{renderField()}</FormItemLayout>;\n};\n\nexport default GenericAutocompleteField;\n"],"names":["label","fieldName","options","placeholder","getOptionLabel","validation","onChange","onInputChange","isOptionEqualToValue","onScroll","layout","variant","disabled","loading","required","renderField","_jsx","Field","name","validate","children","field","form","errors","touched","isSubmitting","fieldError","showError","helperText","useRenderValidText","value","Autocomplete","e","setFieldValue","fullWidth","renderInput","params","TextField","undefined","style","paddingRight","error","FormHelperTextProps","textAlign","InputProps","endAdornment","_jsxs","jsxs","_Fragment","jsx","CircularProgress","color","size","ListboxProps","Typography","component","FormItemLayout"],"mappings":"6MAyBiC,EAC7BA,QACAC,YACAC,UACAC,cACAC,iBACAC,aACAC,WACAC,gBACAC,uBACAC,WACAC,SAAS,aACTC,UAAU,WACVC,YAAW,EACXC,WAAU,EACVC,YAAW,MAEX,MAAMC,EAAc,IAEZC,MAACC,EAAAA,OAAMC,KAAMjB,EAAWkB,SAAUd,EAAUe,SACvC,EAAGC,QAAOC,WACP,MAAMC,OAAEA,EAAMC,QAAEA,EAAOC,aAAEA,GAAiBH,EACpCI,EAAaH,EAAOF,EAAMH,MAC1BS,IAAcD,GAAeF,EAAQH,EAAMH,MAC3CU,EAAaC,EAAmB,CAClCH,aACAC,YACAH,UAAWA,EAAQH,EAAMH,MACzBY,MAAOT,EAAMS,QAGjB,OACId,MAACe,EAAYA,aAAA,CACT7B,QAASA,EACTE,eAAgBA,EAChBI,qBAAsBA,EACtBF,SAAU,CAAC0B,EAAmBF,KAE1BR,EAAKW,cAAchC,EAAW6B,GAC1BxB,GACAA,EAAS0B,EAAGF,EACf,EAELvB,cAAeA,EACfK,SAAUa,GAAgBb,EAC1BsB,WAAS,EACTrB,QAASA,EACTsB,YAAcC,GACVpB,EAAAA,IAACqB,EAASA,UACF,IAAAD,EACJpC,MAAmB,aAAZW,OAAyB2B,EAAYtC,EAC5CW,QAASA,EAAO,cACH,cAAcV,IAC3BiC,WAAS,EACTK,MAAO,CAAEC,aAAyB,eAAX9B,EAA0B,GAAK,GACtDP,YAAaA,QAA4BmC,EACzCxB,SAAUA,EACV2B,MAAOd,EACPC,WAAYA,EACZc,oBAAqB,CACjBtB,SAAU,IACVmB,MAAO,CAAEI,UAAW,UAExBC,WAAY,
|
|
1
|
+
{"version":3,"file":"GenericAutocompleteField.cjs.js","sources":["../../../../src/components/ui/Form/GenericAutocompleteField.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { TextFieldProps, Autocomplete, TextField, Typography, CircularProgress } from '@mui/material';\nimport { Field, FieldProps } from 'formik';\nimport { SyntheticEvent } from 'react';\nimport useRenderValidText from '../../custom-hooks/useRenderValidText';\nimport FormItemLayout from './FormItemLayout';\n\ntype Props = {\n label: string;\n fieldName: string;\n options: any[];\n placeholder?: string;\n getOptionLabel?: (option: any) => string;\n validation?: (value: string) => string | undefined;\n onChange?: (e: SyntheticEvent, value: any) => void;\n onInputChange?: (e: SyntheticEvent, value: any) => void;\n isOptionEqualToValue?: (option: any, value: any) => boolean;\n onScroll?: (e: React.UIEvent<HTMLUListElement, UIEvent>) => void;\n layout?: 'horizontal' | 'vertical';\n variant?: TextFieldProps['variant'];\n disabled?: boolean;\n loading?: boolean;\n required?: boolean;\n};\n\nconst GenericAutocompleteField = ({\n label,\n fieldName,\n options,\n placeholder,\n getOptionLabel,\n validation,\n onChange,\n onInputChange,\n isOptionEqualToValue,\n onScroll,\n layout = 'horizontal',\n variant = 'outlined',\n disabled = false,\n loading = false,\n required = false,\n}: Props) => {\n const renderField = () => {\n return (\n <Field name={fieldName} validate={validation}>\n {({ field, form }: FieldProps) => {\n const { errors, touched, isSubmitting } = form;\n const fieldError = errors[field.name] as string | undefined;\n const showError = !!fieldError && (touched[field.name] as boolean | undefined);\n const helperText = useRenderValidText({\n fieldError,\n showError,\n touched: !!touched[field.name],\n value: field.value,\n });\n\n return (\n <Autocomplete\n options={options}\n getOptionLabel={getOptionLabel}\n isOptionEqualToValue={isOptionEqualToValue}\n onChange={(e: SyntheticEvent, value: any) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n form.setFieldValue(fieldName, value);\n if (onChange) {\n onChange(e, value);\n }\n }}\n onInputChange={onInputChange}\n disabled={isSubmitting || disabled}\n fullWidth\n loading={loading}\n renderInput={(params) => (\n <TextField\n {...params}\n label={variant === 'standard' ? undefined : label}\n variant={variant}\n data-testid={`text-field-${fieldName}`}\n fullWidth\n style={{ paddingRight: layout === 'horizontal' ? 16 : 0 }}\n placeholder={placeholder ? placeholder : undefined}\n required={required}\n error={showError}\n helperText={helperText}\n FormHelperTextProps={{\n children: ' ', // reserves line height for error message\n style: { textAlign: 'right' },\n }}\n InputProps={{\n ...params.InputProps,\n endAdornment: (\n <>\n {loading && <CircularProgress color=\"inherit\" size={25} />}\n {params.InputProps.endAdornment}\n </>\n ),\n }}\n />\n )}\n ListboxProps={{\n onScroll,\n }}\n />\n );\n }}\n </Field>\n );\n };\n\n if (layout === 'vertical') {\n return (\n <>\n {variant === 'standard' && (\n <Typography variant=\"subtitle1\" component=\"h3\" color=\"textPrimary\">\n {label}\n </Typography>\n )}\n {renderField()}\n </>\n );\n }\n\n return <FormItemLayout label={label}>{renderField()}</FormItemLayout>;\n};\n\nexport default GenericAutocompleteField;\n"],"names":["label","fieldName","options","placeholder","getOptionLabel","validation","onChange","onInputChange","isOptionEqualToValue","onScroll","layout","variant","disabled","loading","required","renderField","_jsx","Field","name","validate","children","field","form","errors","touched","isSubmitting","fieldError","showError","helperText","useRenderValidText","value","Autocomplete","e","setFieldValue","fullWidth","renderInput","params","TextField","undefined","style","paddingRight","error","FormHelperTextProps","textAlign","InputProps","endAdornment","_jsxs","jsxs","_Fragment","jsx","CircularProgress","color","size","ListboxProps","Typography","component","FormItemLayout"],"mappings":"6MAyBiC,EAC7BA,QACAC,YACAC,UACAC,cACAC,iBACAC,aACAC,WACAC,gBACAC,uBACAC,WACAC,SAAS,aACTC,UAAU,WACVC,YAAW,EACXC,WAAU,EACVC,YAAW,MAEX,MAAMC,EAAc,IAEZC,MAACC,EAAAA,OAAMC,KAAMjB,EAAWkB,SAAUd,EAAUe,SACvC,EAAGC,QAAOC,WACP,MAAMC,OAAEA,EAAMC,QAAEA,EAAOC,aAAEA,GAAiBH,EACpCI,EAAaH,EAAOF,EAAMH,MAC1BS,IAAcD,GAAeF,EAAQH,EAAMH,MAC3CU,EAAaC,EAAmB,CAClCH,aACAC,YACAH,UAAWA,EAAQH,EAAMH,MACzBY,MAAOT,EAAMS,QAGjB,OACId,MAACe,EAAYA,aAAA,CACT7B,QAASA,EACTE,eAAgBA,EAChBI,qBAAsBA,EACtBF,SAAU,CAAC0B,EAAmBF,KAE1BR,EAAKW,cAAchC,EAAW6B,GAC1BxB,GACAA,EAAS0B,EAAGF,EACf,EAELvB,cAAeA,EACfK,SAAUa,GAAgBb,EAC1BsB,WAAS,EACTrB,QAASA,EACTsB,YAAcC,GACVpB,EAAAA,IAACqB,EAASA,UACF,IAAAD,EACJpC,MAAmB,aAAZW,OAAyB2B,EAAYtC,EAC5CW,QAASA,EAAO,cACH,cAAcV,IAC3BiC,WAAS,EACTK,MAAO,CAAEC,aAAyB,eAAX9B,EAA0B,GAAK,GACtDP,YAAaA,QAA4BmC,EACzCxB,SAAUA,EACV2B,MAAOd,EACPC,WAAYA,EACZc,oBAAqB,CACjBtB,SAAU,IACVmB,MAAO,CAAEI,UAAW,UAExBC,WAAY,IACLR,EAAOQ,WACVC,aACIC,EACKC,KAAAC,WAAA,CAAA5B,SAAA,CAAAP,GAAWG,EAACiC,IAAAC,mBAAiB,CAAAC,MAAM,UAAUC,KAAM,KACnDhB,EAAOQ,WAAWC,mBAMvCQ,aAAc,CACV5C,aAGV,IAMlB,MAAe,aAAXC,EAEIoC,EAAAC,KAAAC,WAAA,CAAA5B,SAAA,CACiB,aAAZT,GACGK,EAAAiC,IAACK,aAAU,CAAC3C,QAAQ,YAAY4C,UAAU,KAAKJ,MAAM,cAChD/B,SAAApB,IAGRe,OAKNC,EAAAiC,IAACO,EAAc,CAACxD,MAAOA,EAAQoB,SAAAL,KAA+B"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{jsxs as e,Fragment as o,jsx as r}from"react/jsx-runtime";import{Typography as t,Autocomplete as i,TextField as n,CircularProgress as l}from"@mui/material";import{Field as a}from"formik";import d from"../../custom-hooks/useRenderValidText.js";import s from"./FormItemLayout.js";const u=({label:u,fieldName:m,options:p,placeholder:h,getOptionLabel:c,validation:f,onChange:g,onInputChange:b,isOptionEqualToValue:v,onScroll:x,layout:I="horizontal",variant:
|
|
1
|
+
import{jsxs as e,Fragment as o,jsx as r}from"react/jsx-runtime";import{Typography as t,Autocomplete as i,TextField as n,CircularProgress as l}from"@mui/material";import{Field as a}from"formik";import d from"../../custom-hooks/useRenderValidText.js";import s from"./FormItemLayout.js";const u=({label:u,fieldName:m,options:p,placeholder:h,getOptionLabel:c,validation:f,onChange:g,onInputChange:b,isOptionEqualToValue:v,onScroll:x,layout:I="horizontal",variant:P="outlined",disabled:y=!1,loading:T=!1,required:q=!1})=>{const C=()=>r(a,{name:m,validate:f,children:({field:t,form:a})=>{const{errors:s,touched:f,isSubmitting:C}=a,E=s[t.name],L=!!E&&f[t.name],O=d({fieldError:E,showError:L,touched:!!f[t.name],value:t.value});return r(i,{options:p,getOptionLabel:c,isOptionEqualToValue:v,onChange:(e,o)=>{a.setFieldValue(m,o),g&&g(e,o)},onInputChange:b,disabled:C||y,fullWidth:!0,loading:T,renderInput:t=>r(n,{...t,label:"standard"===P?void 0:u,variant:P,"data-testid":`text-field-${m}`,fullWidth:!0,style:{paddingRight:"horizontal"===I?16:0},placeholder:h||void 0,required:q,error:L,helperText:O,FormHelperTextProps:{children:" ",style:{textAlign:"right"}},InputProps:{...t.InputProps,endAdornment:e(o,{children:[T&&r(l,{color:"inherit",size:25}),t.InputProps.endAdornment]})}}),ListboxProps:{onScroll:x}})}});return"vertical"===I?e(o,{children:["standard"===P&&r(t,{variant:"subtitle1",component:"h3",color:"textPrimary",children:u}),C()]}):r(s,{label:u,children:C()})};export{u as default};
|
|
2
2
|
//# sourceMappingURL=GenericAutocompleteField.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenericAutocompleteField.js","sources":["../../../../src/components/ui/Form/GenericAutocompleteField.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { TextFieldProps, Autocomplete, TextField, Typography, CircularProgress } from '@mui/material';\nimport { Field, FieldProps } from 'formik';\nimport { SyntheticEvent } from 'react';\nimport useRenderValidText from '../../custom-hooks/useRenderValidText';\nimport FormItemLayout from './FormItemLayout';\n\ntype Props = {\n label: string;\n fieldName: string;\n options: any[];\n placeholder?: string;\n getOptionLabel?: (option: any) => string;\n validation?: (value: string) => string | undefined;\n onChange?: (e: SyntheticEvent, value: any) => void;\n onInputChange?: (e: SyntheticEvent, value: any) => void;\n isOptionEqualToValue?: (option: any, value: any) => boolean;\n onScroll?: (e: React.UIEvent<HTMLUListElement, UIEvent>) => void;\n layout?: 'horizontal' | 'vertical';\n variant?: TextFieldProps['variant'];\n disabled?: boolean;\n loading?: boolean;\n required?: boolean;\n};\n\nconst GenericAutocompleteField = ({\n label,\n fieldName,\n options,\n placeholder,\n getOptionLabel,\n validation,\n onChange,\n onInputChange,\n isOptionEqualToValue,\n onScroll,\n layout = 'horizontal',\n variant = 'outlined',\n disabled = false,\n loading = false,\n required = false,\n}: Props) => {\n const renderField = () => {\n return (\n <Field name={fieldName} validate={validation}>\n {({ field, form }: FieldProps) => {\n const { errors, touched, isSubmitting } = form;\n const fieldError = errors[field.name] as string | undefined;\n const showError = !!fieldError && (touched[field.name] as boolean | undefined);\n const helperText = useRenderValidText({\n fieldError,\n showError,\n touched: !!touched[field.name],\n value: field.value,\n });\n\n return (\n <Autocomplete\n options={options}\n getOptionLabel={getOptionLabel}\n isOptionEqualToValue={isOptionEqualToValue}\n onChange={(e: SyntheticEvent, value: any) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n form.setFieldValue(fieldName, value);\n if (onChange) {\n onChange(e, value);\n }\n }}\n onInputChange={onInputChange}\n disabled={isSubmitting || disabled}\n fullWidth\n loading={loading}\n renderInput={(params) => (\n <TextField\n {...params}\n label={variant === 'standard' ? undefined : label}\n variant={variant}\n data-testid={`text-field-${fieldName}`}\n fullWidth\n style={{ paddingRight: layout === 'horizontal' ? 16 : 0 }}\n placeholder={placeholder ? placeholder : undefined}\n required={required}\n error={showError}\n helperText={helperText}\n FormHelperTextProps={{\n children: ' ', // reserves line height for error message\n style: { textAlign: 'right' },\n }}\n InputProps={{\n endAdornment: (\n <>\n {loading && <CircularProgress color=\"inherit\" size={25} />}\n {params.InputProps.endAdornment}\n </>\n ),\n }}\n />\n )}\n ListboxProps={{\n onScroll,\n }}\n />\n );\n }}\n </Field>\n );\n };\n\n if (layout === 'vertical') {\n return (\n <>\n {variant === 'standard' && (\n <Typography variant=\"subtitle1\" component=\"h3\" color=\"textPrimary\">\n {label}\n </Typography>\n )}\n {renderField()}\n </>\n );\n }\n\n return <FormItemLayout label={label}>{renderField()}</FormItemLayout>;\n};\n\nexport default GenericAutocompleteField;\n"],"names":["GenericAutocompleteField","label","fieldName","options","placeholder","getOptionLabel","validation","onChange","onInputChange","isOptionEqualToValue","onScroll","layout","variant","disabled","loading","required","renderField","_jsx","Field","name","validate","children","field","form","errors","touched","isSubmitting","fieldError","showError","helperText","useRenderValidText","value","Autocomplete","e","setFieldValue","fullWidth","renderInput","params","TextField","undefined","style","paddingRight","error","FormHelperTextProps","textAlign","InputProps","endAdornment","_jsxs","_Fragment","CircularProgress","color","size","ListboxProps","Typography","component","FormItemLayout"],"mappings":"4RAyBM,MAAAA,EAA2B,EAC7BC,QACAC,YACAC,UACAC,cACAC,iBACAC,aACAC,WACAC,gBACAC,uBACAC,WACAC,SAAS,aACTC,UAAU,WACVC,YAAW,EACXC,WAAU,EACVC,YAAW,MAEX,MAAMC,EAAc,IAEZC,EAACC,GAAMC,KAAMjB,EAAWkB,SAAUd,EAAUe,SACvC,EAAGC,QAAOC,WACP,MAAMC,OAAEA,EAAMC,QAAEA,EAAOC,aAAEA,GAAiBH,EACpCI,EAAaH,EAAOF,EAAMH,MAC1BS,IAAcD,GAAeF,EAAQH,EAAMH,MAC3CU,EAAaC,EAAmB,CAClCH,aACAC,YACAH,UAAWA,EAAQH,EAAMH,MACzBY,MAAOT,EAAMS,QAGjB,OACId,EAACe,EAAY,CACT7B,QAASA,EACTE,eAAgBA,EAChBI,qBAAsBA,EACtBF,SAAU,CAAC0B,EAAmBF,KAE1BR,EAAKW,cAAchC,EAAW6B,GAC1BxB,GACAA,EAAS0B,EAAGF,EACf,EAELvB,cAAeA,EACfK,SAAUa,GAAgBb,EAC1BsB,WAAS,EACTrB,QAASA,EACTsB,YAAcC,GACVpB,EAACqB,EACO,IAAAD,EACJpC,MAAmB,aAAZW,OAAyB2B,EAAYtC,EAC5CW,QAASA,EAAO,cACH,cAAcV,IAC3BiC,WAAS,EACTK,MAAO,CAAEC,aAAyB,eAAX9B,EAA0B,GAAK,GACtDP,YAAaA,QAA4BmC,EACzCxB,SAAUA,EACV2B,MAAOd,EACPC,WAAYA,EACZc,oBAAqB,CACjBtB,SAAU,IACVmB,MAAO,CAAEI,UAAW,UAExBC,WAAY,
|
|
1
|
+
{"version":3,"file":"GenericAutocompleteField.js","sources":["../../../../src/components/ui/Form/GenericAutocompleteField.tsx"],"sourcesContent":["/* eslint-disable @typescript-eslint/no-explicit-any */\nimport { TextFieldProps, Autocomplete, TextField, Typography, CircularProgress } from '@mui/material';\nimport { Field, FieldProps } from 'formik';\nimport { SyntheticEvent } from 'react';\nimport useRenderValidText from '../../custom-hooks/useRenderValidText';\nimport FormItemLayout from './FormItemLayout';\n\ntype Props = {\n label: string;\n fieldName: string;\n options: any[];\n placeholder?: string;\n getOptionLabel?: (option: any) => string;\n validation?: (value: string) => string | undefined;\n onChange?: (e: SyntheticEvent, value: any) => void;\n onInputChange?: (e: SyntheticEvent, value: any) => void;\n isOptionEqualToValue?: (option: any, value: any) => boolean;\n onScroll?: (e: React.UIEvent<HTMLUListElement, UIEvent>) => void;\n layout?: 'horizontal' | 'vertical';\n variant?: TextFieldProps['variant'];\n disabled?: boolean;\n loading?: boolean;\n required?: boolean;\n};\n\nconst GenericAutocompleteField = ({\n label,\n fieldName,\n options,\n placeholder,\n getOptionLabel,\n validation,\n onChange,\n onInputChange,\n isOptionEqualToValue,\n onScroll,\n layout = 'horizontal',\n variant = 'outlined',\n disabled = false,\n loading = false,\n required = false,\n}: Props) => {\n const renderField = () => {\n return (\n <Field name={fieldName} validate={validation}>\n {({ field, form }: FieldProps) => {\n const { errors, touched, isSubmitting } = form;\n const fieldError = errors[field.name] as string | undefined;\n const showError = !!fieldError && (touched[field.name] as boolean | undefined);\n const helperText = useRenderValidText({\n fieldError,\n showError,\n touched: !!touched[field.name],\n value: field.value,\n });\n\n return (\n <Autocomplete\n options={options}\n getOptionLabel={getOptionLabel}\n isOptionEqualToValue={isOptionEqualToValue}\n onChange={(e: SyntheticEvent, value: any) => {\n // eslint-disable-next-line @typescript-eslint/no-floating-promises\n form.setFieldValue(fieldName, value);\n if (onChange) {\n onChange(e, value);\n }\n }}\n onInputChange={onInputChange}\n disabled={isSubmitting || disabled}\n fullWidth\n loading={loading}\n renderInput={(params) => (\n <TextField\n {...params}\n label={variant === 'standard' ? undefined : label}\n variant={variant}\n data-testid={`text-field-${fieldName}`}\n fullWidth\n style={{ paddingRight: layout === 'horizontal' ? 16 : 0 }}\n placeholder={placeholder ? placeholder : undefined}\n required={required}\n error={showError}\n helperText={helperText}\n FormHelperTextProps={{\n children: ' ', // reserves line height for error message\n style: { textAlign: 'right' },\n }}\n InputProps={{\n ...params.InputProps,\n endAdornment: (\n <>\n {loading && <CircularProgress color=\"inherit\" size={25} />}\n {params.InputProps.endAdornment}\n </>\n ),\n }}\n />\n )}\n ListboxProps={{\n onScroll,\n }}\n />\n );\n }}\n </Field>\n );\n };\n\n if (layout === 'vertical') {\n return (\n <>\n {variant === 'standard' && (\n <Typography variant=\"subtitle1\" component=\"h3\" color=\"textPrimary\">\n {label}\n </Typography>\n )}\n {renderField()}\n </>\n );\n }\n\n return <FormItemLayout label={label}>{renderField()}</FormItemLayout>;\n};\n\nexport default GenericAutocompleteField;\n"],"names":["GenericAutocompleteField","label","fieldName","options","placeholder","getOptionLabel","validation","onChange","onInputChange","isOptionEqualToValue","onScroll","layout","variant","disabled","loading","required","renderField","_jsx","Field","name","validate","children","field","form","errors","touched","isSubmitting","fieldError","showError","helperText","useRenderValidText","value","Autocomplete","e","setFieldValue","fullWidth","renderInput","params","TextField","undefined","style","paddingRight","error","FormHelperTextProps","textAlign","InputProps","endAdornment","_jsxs","_Fragment","CircularProgress","color","size","ListboxProps","Typography","component","FormItemLayout"],"mappings":"4RAyBM,MAAAA,EAA2B,EAC7BC,QACAC,YACAC,UACAC,cACAC,iBACAC,aACAC,WACAC,gBACAC,uBACAC,WACAC,SAAS,aACTC,UAAU,WACVC,YAAW,EACXC,WAAU,EACVC,YAAW,MAEX,MAAMC,EAAc,IAEZC,EAACC,GAAMC,KAAMjB,EAAWkB,SAAUd,EAAUe,SACvC,EAAGC,QAAOC,WACP,MAAMC,OAAEA,EAAMC,QAAEA,EAAOC,aAAEA,GAAiBH,EACpCI,EAAaH,EAAOF,EAAMH,MAC1BS,IAAcD,GAAeF,EAAQH,EAAMH,MAC3CU,EAAaC,EAAmB,CAClCH,aACAC,YACAH,UAAWA,EAAQH,EAAMH,MACzBY,MAAOT,EAAMS,QAGjB,OACId,EAACe,EAAY,CACT7B,QAASA,EACTE,eAAgBA,EAChBI,qBAAsBA,EACtBF,SAAU,CAAC0B,EAAmBF,KAE1BR,EAAKW,cAAchC,EAAW6B,GAC1BxB,GACAA,EAAS0B,EAAGF,EACf,EAELvB,cAAeA,EACfK,SAAUa,GAAgBb,EAC1BsB,WAAS,EACTrB,QAASA,EACTsB,YAAcC,GACVpB,EAACqB,EACO,IAAAD,EACJpC,MAAmB,aAAZW,OAAyB2B,EAAYtC,EAC5CW,QAASA,EAAO,cACH,cAAcV,IAC3BiC,WAAS,EACTK,MAAO,CAAEC,aAAyB,eAAX9B,EAA0B,GAAK,GACtDP,YAAaA,QAA4BmC,EACzCxB,SAAUA,EACV2B,MAAOd,EACPC,WAAYA,EACZc,oBAAqB,CACjBtB,SAAU,IACVmB,MAAO,CAAEI,UAAW,UAExBC,WAAY,IACLR,EAAOQ,WACVC,aACIC,EACKC,EAAA,CAAA3B,SAAA,CAAAP,GAAWG,EAACgC,EAAiB,CAAAC,MAAM,UAAUC,KAAM,KACnDd,EAAOQ,WAAWC,mBAMvCM,aAAc,CACV1C,aAGV,IAMlB,MAAe,aAAXC,EAEIoC,EAAAC,EAAA,CAAA3B,SAAA,CACiB,aAAZT,GACGK,EAACoC,EAAU,CAACzC,QAAQ,YAAY0C,UAAU,KAAKJ,MAAM,cAChD7B,SAAApB,IAGRe,OAKNC,EAACsC,EAAc,CAACtD,MAAOA,EAAQoB,SAAAL,KAA+B"}
|