formik-form-components 0.2.12 → 0.2.13
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/index.d.ts +9 -6
- package/dist/index.js +48 -20
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +48 -20
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.mjs
CHANGED
|
@@ -918,6 +918,8 @@ function AppAutoComplete({
|
|
|
918
918
|
variant = "outlined",
|
|
919
919
|
label,
|
|
920
920
|
options = [],
|
|
921
|
+
value: propValue,
|
|
922
|
+
onChange: propOnChange,
|
|
921
923
|
sx,
|
|
922
924
|
formControlSx,
|
|
923
925
|
textFieldSx,
|
|
@@ -927,7 +929,8 @@ function AppAutoComplete({
|
|
|
927
929
|
const { errors, touched, getFieldProps, values, setFieldValue } = useFormikContext();
|
|
928
930
|
const fieldError = _19.get(errors, name);
|
|
929
931
|
const isTouched = _19.get(touched, name);
|
|
930
|
-
const
|
|
932
|
+
const formikValue = _19.get(values, name);
|
|
933
|
+
const val = propValue !== void 0 ? propValue : formikValue || [];
|
|
931
934
|
return /* @__PURE__ */ jsxs(FormControl, { fullWidth: true, variant: "filled", sx: formControlSx, children: [
|
|
932
935
|
/* @__PURE__ */ jsx(
|
|
933
936
|
Autocomplete,
|
|
@@ -937,10 +940,23 @@ function AppAutoComplete({
|
|
|
937
940
|
id: "tags-filled",
|
|
938
941
|
options,
|
|
939
942
|
freeSolo: true,
|
|
940
|
-
renderTags: (value, getTagProps) => value.map((option, index) => /* @__PURE__ */ createElement(
|
|
943
|
+
renderTags: (value, getTagProps) => value.map((option, index) => /* @__PURE__ */ createElement(
|
|
944
|
+
Chip,
|
|
945
|
+
{
|
|
946
|
+
variant: "outlined",
|
|
947
|
+
label: option,
|
|
948
|
+
...getTagProps({ index }),
|
|
949
|
+
key: index,
|
|
950
|
+
sx: chipSx
|
|
951
|
+
}
|
|
952
|
+
)),
|
|
941
953
|
value: val,
|
|
942
|
-
onChange: (event, newValue) => {
|
|
943
|
-
|
|
954
|
+
onChange: (event, newValue, reason, details) => {
|
|
955
|
+
if (propOnChange) {
|
|
956
|
+
propOnChange(event, newValue, reason, details);
|
|
957
|
+
} else {
|
|
958
|
+
setFieldValue(name, newValue, true);
|
|
959
|
+
}
|
|
944
960
|
},
|
|
945
961
|
renderInput: (params) => /* @__PURE__ */ jsx(
|
|
946
962
|
TextField,
|
|
@@ -13807,7 +13823,7 @@ var AppUploadFile = ({
|
|
|
13807
13823
|
dropZoneSx,
|
|
13808
13824
|
...rest
|
|
13809
13825
|
}) => {
|
|
13810
|
-
var _a, _b
|
|
13826
|
+
var _a, _b;
|
|
13811
13827
|
const { errors, touched, setFieldValue, values } = useFormikContext();
|
|
13812
13828
|
const fieldError = _19.get(errors, name);
|
|
13813
13829
|
const isTouched = _19.get(touched, name);
|
|
@@ -13817,16 +13833,26 @@ var AppUploadFile = ({
|
|
|
13817
13833
|
} else if (!((_b = rest.multiple) != null ? _b : false) && _19.isArray(val)) {
|
|
13818
13834
|
val = val[0];
|
|
13819
13835
|
}
|
|
13820
|
-
const
|
|
13836
|
+
const formatValue = (val2) => {
|
|
13837
|
+
if (rest.multiple) {
|
|
13838
|
+
return (Array.isArray(val2) ? val2 : []).map((item) => ({
|
|
13839
|
+
...(item == null ? void 0 : item.file) ? item : { file: item, preview: item == null ? void 0 : item.preview }
|
|
13840
|
+
}));
|
|
13841
|
+
}
|
|
13842
|
+
return (val2 == null ? void 0 : val2.file) ? val2 : val2 ? { file: val2, preview: val2.preview } : null;
|
|
13843
|
+
};
|
|
13844
|
+
const formattedValue = formatValue(val);
|
|
13845
|
+
const currentFiles = Array.isArray(val) ? val : [];
|
|
13846
|
+
const isMaxFilesReached = rest.maxFiles !== null && rest.maxFiles !== void 0 && currentFiles.length >= rest.maxFiles;
|
|
13821
13847
|
return /* @__PURE__ */ jsxs(Box, { sx, children: [
|
|
13822
13848
|
/* @__PURE__ */ jsx(
|
|
13823
13849
|
Upload,
|
|
13824
13850
|
{
|
|
13825
13851
|
...rest,
|
|
13826
|
-
file:
|
|
13827
|
-
files:
|
|
13852
|
+
file: rest.multiple ? void 0 : formattedValue,
|
|
13853
|
+
files: rest.multiple ? formattedValue : void 0,
|
|
13828
13854
|
error: Boolean(fieldError) && isTouched,
|
|
13829
|
-
disabled:
|
|
13855
|
+
disabled: isMaxFilesReached,
|
|
13830
13856
|
sx: [{
|
|
13831
13857
|
"& .MuiDropzoneArea-root": {
|
|
13832
13858
|
minHeight: 200,
|
|
@@ -13856,7 +13882,7 @@ var AppUploadFile = ({
|
|
|
13856
13882
|
};
|
|
13857
13883
|
})
|
|
13858
13884
|
);
|
|
13859
|
-
const currentValue = Array.isArray(
|
|
13885
|
+
const currentValue = Array.isArray(val) ? [...val] : [];
|
|
13860
13886
|
if (rest.multiple === true) {
|
|
13861
13887
|
if (currentValue.length >= ((_a2 = rest.maxFiles) != null ? _a2 : Infinity))
|
|
13862
13888
|
return;
|
|
@@ -13871,18 +13897,20 @@ var AppUploadFile = ({
|
|
|
13871
13897
|
if ((_a2 = rest.multiple) != null ? _a2 : false) {
|
|
13872
13898
|
setFieldValue(name, [], true);
|
|
13873
13899
|
} else {
|
|
13874
|
-
setFieldValue(name,
|
|
13900
|
+
setFieldValue(name, null, true);
|
|
13875
13901
|
}
|
|
13876
13902
|
},
|
|
13877
|
-
onRemove: (
|
|
13878
|
-
|
|
13879
|
-
|
|
13880
|
-
|
|
13881
|
-
|
|
13882
|
-
|
|
13883
|
-
|
|
13884
|
-
|
|
13885
|
-
|
|
13903
|
+
onRemove: (fileToRemove) => {
|
|
13904
|
+
if (rest.multiple) {
|
|
13905
|
+
const currentFiles2 = Array.isArray(val) ? [...val] : [];
|
|
13906
|
+
const filteredFiles = currentFiles2.filter((file) => {
|
|
13907
|
+
const fileObj = (file == null ? void 0 : file.file) ? file.file : file;
|
|
13908
|
+
return !_19.isEqual(fileObj, fileToRemove);
|
|
13909
|
+
});
|
|
13910
|
+
setFieldValue(name, filteredFiles, true);
|
|
13911
|
+
} else {
|
|
13912
|
+
setFieldValue(name, null, true);
|
|
13913
|
+
}
|
|
13886
13914
|
}
|
|
13887
13915
|
}
|
|
13888
13916
|
),
|