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 CHANGED
@@ -1,7 +1,7 @@
1
1
  import * as React$1 from 'react';
2
- import React__default, { ReactElement, ReactNode, ElementType, SetStateAction } from 'react';
2
+ import React__default, { ReactElement, ReactNode, SyntheticEvent, ElementType, SetStateAction } from 'react';
3
3
  import { FormikValues, FormikConfig, FormikProps } from 'formik';
4
- import { SxProps, Theme, SelectProps as SelectProps$1, StandardTextFieldProps, SelectChangeEvent, RadioGroupProps, AutocompleteRenderInputParams, AutocompleteRenderOptionState, AutocompleteRenderGroupParams, CheckboxProps, ChipProps, AutocompleteProps, BoxProps } from '@mui/material';
4
+ import { SxProps, Theme, AutocompleteProps, AutocompleteChangeReason, AutocompleteChangeDetails, TextFieldProps, SelectChangeEvent, RadioGroupProps, AutocompleteRenderInputParams, AutocompleteRenderOptionState, AutocompleteRenderGroupParams, CheckboxProps, ChipProps, BoxProps } from '@mui/material';
5
5
  import { Theme as Theme$1 } from '@mui/material/styles';
6
6
  import { SelectProps, SelectChangeEvent as SelectChangeEvent$1 } from '@mui/material/Select';
7
7
  import * as react_jsx_runtime from 'react/jsx-runtime';
@@ -219,25 +219,28 @@ interface FormProps<T> extends FormikConfig<T> {
219
219
  }
220
220
  declare const Form: <T extends FormikValues>({ children, className, ...props }: FormProps<T>) => ReactElement;
221
221
 
222
- interface Props$5 extends Omit<SelectProps$1, 'name' | 'label' | 'value' | 'onChange' | 'variant'> {
222
+ interface Props$5 extends Omit<AutocompleteProps<string, true, boolean, false, 'div'>, 'renderInput' | 'onChange' | 'value' | 'multiple' | 'freeSolo'> {
223
223
  name: string;
224
224
  freeSolo?: boolean;
225
225
  label?: string;
226
226
  placeholder?: string;
227
227
  options: string[];
228
+ value?: string[];
229
+ onChange?: (event: SyntheticEvent, value: string[], reason: AutocompleteChangeReason, details?: AutocompleteChangeDetails<string>) => void;
228
230
  /** Variant of the input field */
229
- variant?: 'outlined' | 'filled' | 'standard';
231
+ variant?: "outlined" | "filled" | "standard";
230
232
  sx?: SxProps<Theme$1>;
231
233
  formControlSx?: SxProps<Theme$1>;
232
234
  textFieldSx?: SxProps<Theme$1>;
233
235
  chipSx?: SxProps<Theme$1>;
234
236
  errorSx?: SxProps<Theme$1>;
235
237
  }
236
- declare function AppAutoComplete({ placeholder, name, variant, label, options, sx, formControlSx, textFieldSx, chipSx, errorSx }: Props$5): React.JSX.Element;
238
+ declare function AppAutoComplete({ placeholder, name, variant, label, options, value: propValue, onChange: propOnChange, sx, formControlSx, textFieldSx, chipSx, errorSx, }: Props$5): React.JSX.Element;
237
239
 
238
240
  interface CheckboxOption {
239
241
  label: string;
240
242
  name: string;
243
+ value: string | boolean | number;
241
244
  disabled?: boolean;
242
245
  }
243
246
  interface Props$4 {
@@ -270,7 +273,7 @@ interface Props$4 {
270
273
  }
271
274
  declare const AppCheckBox: ({ name, option, label, required, disabled, row, sx, checkboxSx, labelSx, errorSx, containerSx, iconSx, checkedSx, ...rest }: Props$4) => react_jsx_runtime.JSX.Element;
272
275
 
273
- interface Props$3 extends Omit<StandardTextFieldProps, 'variant'> {
276
+ interface Props$3 extends Omit<TextFieldProps, 'variant'> {
274
277
  name: string;
275
278
  label: ReactNode;
276
279
  tagUser?: string;
package/dist/index.js CHANGED
@@ -945,6 +945,8 @@ function AppAutoComplete({
945
945
  variant = "outlined",
946
946
  label,
947
947
  options = [],
948
+ value: propValue,
949
+ onChange: propOnChange,
948
950
  sx,
949
951
  formControlSx,
950
952
  textFieldSx,
@@ -954,7 +956,8 @@ function AppAutoComplete({
954
956
  const { errors, touched, getFieldProps, values, setFieldValue } = formik.useFormikContext();
955
957
  const fieldError = _19__default.default.get(errors, name);
956
958
  const isTouched = _19__default.default.get(touched, name);
957
- const val = _19__default.default.get(values, name);
959
+ const formikValue = _19__default.default.get(values, name);
960
+ const val = propValue !== void 0 ? propValue : formikValue || [];
958
961
  return /* @__PURE__ */ jsxRuntime.jsxs(material.FormControl, { fullWidth: true, variant: "filled", sx: formControlSx, children: [
959
962
  /* @__PURE__ */ jsxRuntime.jsx(
960
963
  material.Autocomplete,
@@ -964,10 +967,23 @@ function AppAutoComplete({
964
967
  id: "tags-filled",
965
968
  options,
966
969
  freeSolo: true,
967
- renderTags: (value, getTagProps) => value.map((option, index) => /* @__PURE__ */ react.createElement(material.Chip, { variant: "outlined", label: option, ...getTagProps({ index }), key: index, sx: chipSx })),
970
+ renderTags: (value, getTagProps) => value.map((option, index) => /* @__PURE__ */ react.createElement(
971
+ material.Chip,
972
+ {
973
+ variant: "outlined",
974
+ label: option,
975
+ ...getTagProps({ index }),
976
+ key: index,
977
+ sx: chipSx
978
+ }
979
+ )),
968
980
  value: val,
969
- onChange: (event, newValue) => {
970
- setFieldValue(name, newValue, true);
981
+ onChange: (event, newValue, reason, details) => {
982
+ if (propOnChange) {
983
+ propOnChange(event, newValue, reason, details);
984
+ } else {
985
+ setFieldValue(name, newValue, true);
986
+ }
971
987
  },
972
988
  renderInput: (params) => /* @__PURE__ */ jsxRuntime.jsx(
973
989
  material.TextField,
@@ -13834,7 +13850,7 @@ var AppUploadFile = ({
13834
13850
  dropZoneSx,
13835
13851
  ...rest
13836
13852
  }) => {
13837
- var _a, _b, _c, _d, _e;
13853
+ var _a, _b;
13838
13854
  const { errors, touched, setFieldValue, values } = formik.useFormikContext();
13839
13855
  const fieldError = _19__default.default.get(errors, name);
13840
13856
  const isTouched = _19__default.default.get(touched, name);
@@ -13844,16 +13860,26 @@ var AppUploadFile = ({
13844
13860
  } else if (!((_b = rest.multiple) != null ? _b : false) && _19__default.default.isArray(val)) {
13845
13861
  val = val[0];
13846
13862
  }
13847
- const value = ((_c = rest.multiple) != null ? _c : false) ? (val != null ? val : []).map((__) => (__ == null ? void 0 : __.file) ? __ == null ? void 0 : __.file : __) : val;
13863
+ const formatValue = (val2) => {
13864
+ if (rest.multiple) {
13865
+ return (Array.isArray(val2) ? val2 : []).map((item) => ({
13866
+ ...(item == null ? void 0 : item.file) ? item : { file: item, preview: item == null ? void 0 : item.preview }
13867
+ }));
13868
+ }
13869
+ return (val2 == null ? void 0 : val2.file) ? val2 : val2 ? { file: val2, preview: val2.preview } : null;
13870
+ };
13871
+ const formattedValue = formatValue(val);
13872
+ const currentFiles = Array.isArray(val) ? val : [];
13873
+ const isMaxFilesReached = rest.maxFiles !== null && rest.maxFiles !== void 0 && currentFiles.length >= rest.maxFiles;
13848
13874
  return /* @__PURE__ */ jsxRuntime.jsxs(material.Box, { sx, children: [
13849
13875
  /* @__PURE__ */ jsxRuntime.jsx(
13850
13876
  Upload,
13851
13877
  {
13852
13878
  ...rest,
13853
- file: ((_d = rest.multiple) != null ? _d : false) ? void 0 : value,
13854
- files: ((_e = rest.multiple) != null ? _e : false) ? value : void 0,
13879
+ file: rest.multiple ? void 0 : formattedValue,
13880
+ files: rest.multiple ? formattedValue : void 0,
13855
13881
  error: Boolean(fieldError) && isTouched,
13856
- disabled: (rest == null ? void 0 : rest.maxFiles) !== null && (rest == null ? void 0 : rest.maxFiles) !== void 0 && (value == null ? void 0 : value.length) >= (rest == null ? void 0 : rest.maxFiles),
13882
+ disabled: isMaxFilesReached,
13857
13883
  sx: [{
13858
13884
  "& .MuiDropzoneArea-root": {
13859
13885
  minHeight: 200,
@@ -13883,7 +13909,7 @@ var AppUploadFile = ({
13883
13909
  };
13884
13910
  })
13885
13911
  );
13886
- const currentValue = Array.isArray(value) ? value : [];
13912
+ const currentValue = Array.isArray(val) ? [...val] : [];
13887
13913
  if (rest.multiple === true) {
13888
13914
  if (currentValue.length >= ((_a2 = rest.maxFiles) != null ? _a2 : Infinity))
13889
13915
  return;
@@ -13898,18 +13924,20 @@ var AppUploadFile = ({
13898
13924
  if ((_a2 = rest.multiple) != null ? _a2 : false) {
13899
13925
  setFieldValue(name, [], true);
13900
13926
  } else {
13901
- setFieldValue(name, "", true);
13927
+ setFieldValue(name, null, true);
13902
13928
  }
13903
13929
  },
13904
- onRemove: (e) => {
13905
- const afterFilter = val.filter((file) => {
13906
- var _a2;
13907
- if ((_a2 = file.file) != null ? _a2 : false) {
13908
- return !_19__default.default.isEqual(e, file.file);
13909
- }
13910
- return !_19__default.default.isEqual(e, file);
13911
- });
13912
- setFieldValue(name, afterFilter, true);
13930
+ onRemove: (fileToRemove) => {
13931
+ if (rest.multiple) {
13932
+ const currentFiles2 = Array.isArray(val) ? [...val] : [];
13933
+ const filteredFiles = currentFiles2.filter((file) => {
13934
+ const fileObj = (file == null ? void 0 : file.file) ? file.file : file;
13935
+ return !_19__default.default.isEqual(fileObj, fileToRemove);
13936
+ });
13937
+ setFieldValue(name, filteredFiles, true);
13938
+ } else {
13939
+ setFieldValue(name, null, true);
13940
+ }
13913
13941
  }
13914
13942
  }
13915
13943
  ),