formik-form-components 0.2.16 → 0.2.18

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.js CHANGED
@@ -6,12 +6,12 @@ var material = require('@mui/material');
6
6
  var DatePicker = require('@mui/x-date-pickers/DatePicker');
7
7
  var LocalizationProvider = require('@mui/x-date-pickers/LocalizationProvider');
8
8
  var AdapterDayjs = require('@mui/x-date-pickers/AdapterDayjs');
9
- var dayjs = require('dayjs');
9
+ var CalendarMonthIcon = require('@mui/icons-material/CalendarMonth');
10
10
  var _19 = require('lodash');
11
11
  var jsxRuntime = require('react/jsx-runtime');
12
12
  var DateTimePicker = require('@mui/x-date-pickers/DateTimePicker');
13
13
  var Autocomplete3 = require('@mui/material/Autocomplete');
14
- var Typography10 = require('@mui/material/Typography');
14
+ var Typography9 = require('@mui/material/Typography');
15
15
  var react$1 = require('@iconify/react');
16
16
  var Select = require('@mui/material/Select');
17
17
  var PhoneInput = require('react-phone-input-2');
@@ -42,9 +42,10 @@ var reactI18next = require('react-i18next');
42
42
 
43
43
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
44
44
 
45
+ var CalendarMonthIcon__default = /*#__PURE__*/_interopDefault(CalendarMonthIcon);
45
46
  var _19__default = /*#__PURE__*/_interopDefault(_19);
46
47
  var Autocomplete3__default = /*#__PURE__*/_interopDefault(Autocomplete3);
47
- var Typography10__default = /*#__PURE__*/_interopDefault(Typography10);
48
+ var Typography9__default = /*#__PURE__*/_interopDefault(Typography9);
48
49
  var Select__default = /*#__PURE__*/_interopDefault(Select);
49
50
  var PhoneInput__default = /*#__PURE__*/_interopDefault(PhoneInput);
50
51
  var StarterKit__default = /*#__PURE__*/_interopDefault(StarterKit);
@@ -70,129 +71,35 @@ var AppDatePicker = react.forwardRef(
70
71
  ({
71
72
  name,
72
73
  label,
73
- required = false,
74
74
  disabled = false,
75
- variant = "outlined",
76
- showIcon = true,
77
75
  format = "DD/MM/YYYY",
78
76
  sx,
79
- formControlSx,
80
77
  textFieldSx,
81
- labelSx,
82
- inputSx,
83
- errorSx,
84
- iconSx,
85
- onChange: externalOnChange,
86
- onBlur: externalOnBlur,
87
78
  ...otherProps
88
79
  }, ref) => {
89
80
  const { values, setFieldValue, touched, errors, setFieldTouched } = formik.useFormikContext();
90
81
  const fieldValue = _19__default.default.get(values, name);
91
82
  const fieldError = _19__default.default.get(errors, name);
92
83
  const isTouched = _19__default.default.get(touched, name);
93
- const handleChange = (newValue, context) => {
84
+ const handleChange = (newValue) => {
94
85
  setFieldValue(name, newValue);
95
- if (externalOnChange) {
96
- externalOnChange(newValue, context);
97
- }
98
- };
99
- const handleBlur = (event) => {
100
- setFieldTouched(name, true);
101
- if (externalOnBlur) {
102
- externalOnBlur(event);
103
- }
104
86
  };
105
87
  return /* @__PURE__ */ jsxRuntime.jsx(LocalizationProvider.LocalizationProvider, { dateAdapter: AdapterDayjs.AdapterDayjs, children: /* @__PURE__ */ jsxRuntime.jsx(material.Box, { sx, ref, children: /* @__PURE__ */ jsxRuntime.jsx(
106
88
  DatePicker.DatePicker,
107
89
  {
108
90
  label,
109
- value: fieldValue ? fieldValue instanceof dayjs.Dayjs ? fieldValue : null : null,
91
+ value: fieldValue,
110
92
  onChange: handleChange,
111
93
  format,
112
94
  disabled,
113
95
  slotProps: {
114
96
  textField: {
97
+ variant: "outlined",
115
98
  fullWidth: true,
116
- variant,
117
99
  error: isTouched && Boolean(fieldError),
118
100
  helperText: isTouched && fieldError ? fieldError : void 0,
119
- onBlur: handleBlur,
120
- sx: [
121
- {
122
- "& .MuiOutlinedInput-root": {
123
- backgroundColor: "background.paper",
124
- "&.Mui-focused": {
125
- "& .MuiOutlinedInput-notchedOutline": {
126
- borderColor: "primary.main"
127
- }
128
- },
129
- "&.Mui-error": {
130
- backgroundColor: "error.lighter",
131
- "& .MuiOutlinedInput-input": {
132
- color: "error.main"
133
- }
134
- },
135
- "&.Mui-disabled": {
136
- backgroundColor: "action.disabledBackground",
137
- "& .MuiOutlinedInput-notchedOutline": {
138
- borderColor: "action.disabled"
139
- }
140
- },
141
- ...inputSx
142
- },
143
- "& .MuiOutlinedInput-notchedOutline": {
144
- borderColor: isTouched && fieldError ? "error.main" : "divider"
145
- },
146
- "&:hover .MuiOutlinedInput-notchedOutline": {
147
- borderColor: isTouched && fieldError ? "error.main" : "primary.main"
148
- },
149
- ...textFieldSx
150
- }
151
- ],
152
- FormHelperTextProps: {
153
- sx: [
154
- {
155
- color: "error.main",
156
- mx: 0,
157
- mt: 0.5,
158
- ...errorSx
159
- }
160
- ]
161
- },
162
- InputLabelProps: {
163
- sx: [
164
- {
165
- color: "text.secondary",
166
- "&.Mui-focused": {
167
- color: "primary.main"
168
- },
169
- "&.Mui-error": {
170
- color: "error.main"
171
- },
172
- ...labelSx
173
- }
174
- ]
175
- },
176
- InputProps: {
177
- endAdornment: showIcon ? /* @__PURE__ */ jsxRuntime.jsx(
178
- material.Box,
179
- {
180
- component: "span",
181
- sx: [
182
- {
183
- color: "text.secondary",
184
- "&:hover": {
185
- color: "primary.main"
186
- },
187
- "&.Mui-disabled": {
188
- color: "action.disabled"
189
- },
190
- ...iconSx
191
- }
192
- ]
193
- }
194
- ) : null
195
- }
101
+ sx: textFieldSx,
102
+ openPickerIcon: CalendarMonthIcon__default.default
196
103
  }
197
104
  },
198
105
  ...otherProps
@@ -1122,7 +1029,7 @@ var AppCheckBox = ({
1122
1029
  }, ...Array.isArray(sx) ? sx : [sx]],
1123
1030
  children: [
1124
1031
  label && /* @__PURE__ */ jsxRuntime.jsx(
1125
- Typography10__default.default,
1032
+ Typography9__default.default,
1126
1033
  {
1127
1034
  variant: "subtitle2",
1128
1035
  gutterBottom: true,
@@ -1199,7 +1106,7 @@ var AppCheckBox = ({
1199
1106
  }
1200
1107
  ),
1201
1108
  /* @__PURE__ */ jsxRuntime.jsx(
1202
- Typography10__default.default,
1109
+ Typography9__default.default,
1203
1110
  {
1204
1111
  variant: "body2",
1205
1112
  sx: [{
@@ -1218,7 +1125,7 @@ var AppCheckBox = ({
1218
1125
  }
1219
1126
  ),
1220
1127
  isTouched && fieldError && /* @__PURE__ */ jsxRuntime.jsx(
1221
- Typography10__default.default,
1128
+ Typography9__default.default,
1222
1129
  {
1223
1130
  variant: "caption",
1224
1131
  sx: [{
@@ -1834,206 +1741,208 @@ var AppRadioGroup = react.forwardRef(({
1834
1741
  });
1835
1742
  AppRadioGroup.displayName = "AppRadioGroup";
1836
1743
  var AppRadioGroup_default = AppRadioGroup;
1837
- var AppRating = react.forwardRef(({
1838
- name,
1839
- label,
1840
- required = false,
1841
- readOnly = false,
1842
- disabled = false,
1843
- max = 5,
1844
- precision = 1,
1845
- size = "medium",
1846
- emptyIcon,
1847
- icon,
1848
- IconContainerComponent,
1849
- getLabelText,
1850
- onChange: externalOnChange,
1851
- onChangeActive,
1852
- sx,
1853
- labelSx,
1854
- ratingSx,
1855
- errorSx,
1856
- helperTextSx,
1857
- showHelperText = false,
1858
- helperText,
1859
- labelComponent: LabelComponent = material.Typography,
1860
- ratingComponent: RatingComponent = material.Rating,
1861
- errorComponent: ErrorComponent = material.Typography,
1862
- helperTextComponent: HelperTextComponent = material.FormHelperText,
1863
- labelProps = {},
1864
- ratingProps = {},
1865
- errorProps = {},
1866
- helperTextProps = {},
1867
- className = "",
1868
- labelClassName = "",
1869
- ratingClassName = "",
1870
- errorClassName = "",
1871
- helperTextClassName = "",
1872
- ...otherProps
1873
- }, ref) => {
1874
- material.useTheme();
1875
- const { errors, touched, setFieldValue, values, setFieldTouched } = formik.useFormikContext();
1876
- const val = _19__default.default.get(values, name);
1877
- const fieldError = _19__default.default.get(errors, name);
1878
- const isTouched = _19__default.default.get(touched, name);
1879
- const hasError = Boolean(fieldError) && isTouched;
1880
- const handleChange = (event, newValue) => {
1881
- setFieldValue(name, newValue);
1882
- setFieldTouched(name, true, false);
1883
- if (externalOnChange) {
1884
- externalOnChange(event, newValue);
1885
- }
1886
- };
1887
- const handleBlur = () => {
1888
- setFieldTouched(name, true, true);
1889
- };
1890
- return /* @__PURE__ */ jsxRuntime.jsxs(
1891
- material.Box,
1892
- {
1893
- ref,
1894
- className: `app-rating ${className}`,
1895
- sx: [
1896
- {
1897
- display: "flex",
1898
- flexDirection: "column",
1899
- width: "100%",
1900
- "&:hover": {
1901
- "& .MuiRating-iconEmpty": {
1902
- color: "primary.light"
1903
- }
1904
- }
1905
- },
1906
- ...Array.isArray(sx) ? sx : [sx]
1907
- ],
1908
- ...otherProps,
1909
- children: [
1910
- /* @__PURE__ */ jsxRuntime.jsxs(
1911
- material.Stack,
1744
+ var AppRating = react.forwardRef(
1745
+ ({
1746
+ name,
1747
+ label,
1748
+ required = false,
1749
+ readOnly = false,
1750
+ disabled = false,
1751
+ max = 5,
1752
+ precision = 1,
1753
+ size = "medium",
1754
+ emptyIcon,
1755
+ icon,
1756
+ IconContainerComponent,
1757
+ getLabelText,
1758
+ onChange: externalOnChange,
1759
+ onChangeActive,
1760
+ sx,
1761
+ labelSx,
1762
+ ratingSx,
1763
+ errorSx,
1764
+ helperTextSx,
1765
+ showHelperText = false,
1766
+ helperText,
1767
+ labelComponent: LabelComponent = material.Typography,
1768
+ ratingComponent: RatingComponent = material.Rating,
1769
+ errorComponent: ErrorComponent = material.Typography,
1770
+ helperTextComponent: HelperTextComponent = material.FormHelperText,
1771
+ labelProps = {},
1772
+ ratingProps = {},
1773
+ errorProps = {},
1774
+ helperTextProps = {},
1775
+ className = "",
1776
+ labelClassName = "",
1777
+ ratingClassName = "",
1778
+ errorClassName = "",
1779
+ helperTextClassName = "",
1780
+ ...otherProps
1781
+ }, ref) => {
1782
+ material.useTheme();
1783
+ const { errors, touched, setFieldValue, values, setFieldTouched } = formik.useFormikContext();
1784
+ const val = _19__default.default.get(values, name);
1785
+ const fieldError = _19__default.default.get(errors, name);
1786
+ const isTouched = _19__default.default.get(touched, name);
1787
+ const hasError = Boolean(fieldError) && isTouched;
1788
+ const handleChange = (event, newValue) => {
1789
+ setFieldValue(name, newValue);
1790
+ setFieldTouched(name, true, false);
1791
+ if (externalOnChange) {
1792
+ externalOnChange(event, newValue);
1793
+ }
1794
+ };
1795
+ const handleBlur = () => {
1796
+ setFieldTouched(name, true, true);
1797
+ };
1798
+ return /* @__PURE__ */ jsxRuntime.jsxs(
1799
+ material.Box,
1800
+ {
1801
+ ref,
1802
+ className: `app-rating ${className}`,
1803
+ sx: [
1912
1804
  {
1913
- direction: "row",
1914
- alignItems: "center",
1915
- spacing: 1,
1916
- sx: {
1917
- "&.Mui-disabled": {
1918
- opacity: 0.5,
1919
- cursor: "not-allowed"
1805
+ display: "flex",
1806
+ flexDirection: "column",
1807
+ width: "100%",
1808
+ "&:hover": {
1809
+ "& .MuiRating-iconEmpty": {
1810
+ color: "primary.light"
1920
1811
  }
1921
- },
1922
- className: disabled ? "Mui-disabled" : "",
1923
- children: [
1924
- label && /* @__PURE__ */ jsxRuntime.jsxs(
1925
- LabelComponent,
1926
- {
1927
- variant: "body2",
1928
- color: hasError ? "error" : "text.primary",
1929
- className: `app-rating-label ${labelClassName}`,
1930
- sx: [
1931
- {
1932
- margin: 0,
1933
- fontWeight: 500,
1934
- ...disabled && {
1935
- color: "text.disabled"
1936
- }
1937
- },
1938
- ...Array.isArray(labelSx) ? labelSx : [labelSx]
1939
- ],
1940
- ...labelProps,
1941
- children: [
1942
- label,
1943
- required && /* @__PURE__ */ jsxRuntime.jsx(
1944
- material.Box,
1945
- {
1946
- component: "span",
1947
- sx: {
1948
- color: "error.main",
1949
- ml: 0.5
1950
- },
1951
- children: "*"
1952
- }
1953
- )
1954
- ]
1812
+ }
1813
+ },
1814
+ ...Array.isArray(sx) ? sx : [sx]
1815
+ ],
1816
+ ...otherProps,
1817
+ children: [
1818
+ /* @__PURE__ */ jsxRuntime.jsxs(
1819
+ material.Stack,
1820
+ {
1821
+ direction: "row",
1822
+ alignItems: "center",
1823
+ spacing: 1,
1824
+ sx: {
1825
+ "&.Mui-disabled": {
1826
+ opacity: 0.5,
1827
+ cursor: "not-allowed"
1955
1828
  }
1956
- ),
1957
- /* @__PURE__ */ jsxRuntime.jsx(
1958
- material.Box,
1959
- {
1960
- onBlur: handleBlur,
1961
- sx: [
1962
- {
1963
- display: "inline-flex",
1964
- "& .MuiRating-icon": {
1965
- color: "primary.main"
1966
- },
1967
- "& .MuiRating-iconEmpty": {
1968
- color: "action.disabled"
1969
- },
1970
- "& .MuiRating-iconFilled": {
1971
- color: "primary.main"
1972
- },
1973
- "& .MuiRating-iconHover": {
1974
- color: "primary.dark"
1975
- },
1976
- "&.Mui-disabled": {
1977
- opacity: 0.5,
1978
- cursor: "not-allowed"
1829
+ },
1830
+ className: disabled ? "Mui-disabled" : "",
1831
+ children: [
1832
+ label && /* @__PURE__ */ jsxRuntime.jsxs(
1833
+ LabelComponent,
1834
+ {
1835
+ variant: "body2",
1836
+ color: hasError ? "error" : "text.primary",
1837
+ className: `app-rating-label ${labelClassName}`,
1838
+ sx: [
1839
+ {
1840
+ margin: 0,
1841
+ fontWeight: 500,
1842
+ ...disabled && {
1843
+ color: "text.disabled"
1844
+ }
1979
1845
  },
1980
- ...hasError && {
1846
+ ...Array.isArray(labelSx) ? labelSx : [labelSx]
1847
+ ],
1848
+ ...labelProps,
1849
+ children: [
1850
+ label,
1851
+ required && /* @__PURE__ */ jsxRuntime.jsx(
1852
+ material.Box,
1853
+ {
1854
+ component: "span",
1855
+ sx: {
1856
+ color: "error.main",
1857
+ ml: 0.5
1858
+ },
1859
+ children: "*"
1860
+ }
1861
+ )
1862
+ ]
1863
+ }
1864
+ ),
1865
+ /* @__PURE__ */ jsxRuntime.jsx(
1866
+ material.Box,
1867
+ {
1868
+ onBlur: handleBlur,
1869
+ sx: [
1870
+ {
1871
+ display: "inline-flex",
1981
1872
  "& .MuiRating-icon": {
1982
- color: "error.main"
1873
+ color: "primary.main"
1874
+ },
1875
+ "& .MuiRating-iconEmpty": {
1876
+ color: "action.disabled"
1877
+ },
1878
+ "& .MuiRating-iconFilled": {
1879
+ color: "primary.main"
1880
+ },
1881
+ "& .MuiRating-iconHover": {
1882
+ color: "primary.dark"
1883
+ },
1884
+ "&.Mui-disabled": {
1885
+ opacity: 0.5,
1886
+ cursor: "not-allowed"
1887
+ },
1888
+ ...hasError && {
1889
+ "& .MuiRating-icon": {
1890
+ color: "error.main"
1891
+ }
1983
1892
  }
1893
+ },
1894
+ ...Array.isArray(ratingSx) ? ratingSx : [ratingSx]
1895
+ ],
1896
+ className: `app-rating-stars ${ratingClassName} ${disabled ? "Mui-disabled" : ""}`,
1897
+ children: /* @__PURE__ */ jsxRuntime.jsx(
1898
+ RatingComponent,
1899
+ {
1900
+ value: val != null ? val : null,
1901
+ onChange: handleChange,
1902
+ onChangeActive,
1903
+ max,
1904
+ precision,
1905
+ size,
1906
+ readOnly,
1907
+ disabled,
1908
+ emptyIcon,
1909
+ icon,
1910
+ IconContainerComponent,
1911
+ getLabelText,
1912
+ className: ratingClassName,
1913
+ ...ratingProps
1984
1914
  }
1985
- },
1986
- ...Array.isArray(ratingSx) ? ratingSx : [ratingSx]
1987
- ],
1988
- className: `app-rating-stars ${ratingClassName} ${disabled ? "Mui-disabled" : ""}`,
1989
- children: /* @__PURE__ */ jsxRuntime.jsx(
1990
- RatingComponent,
1991
- {
1992
- value: val != null ? val : null,
1993
- onChange: handleChange,
1994
- onChangeActive,
1995
- max,
1996
- precision,
1997
- size,
1998
- readOnly,
1999
- disabled,
2000
- emptyIcon,
2001
- icon,
2002
- IconContainerComponent,
2003
- getLabelText,
2004
- className: ratingClassName,
2005
- ...ratingProps
2006
- }
2007
- )
1915
+ )
1916
+ }
1917
+ )
1918
+ ]
1919
+ }
1920
+ ),
1921
+ (showHelperText || hasError) && /* @__PURE__ */ jsxRuntime.jsx(
1922
+ HelperTextComponent,
1923
+ {
1924
+ error: hasError,
1925
+ sx: [
1926
+ {
1927
+ mx: 0,
1928
+ mt: 0.5,
1929
+ ...hasError && {
1930
+ color: "error.main",
1931
+ ...errorSx
1932
+ },
1933
+ ...helperTextSx
2008
1934
  }
2009
- )
2010
- ]
2011
- }
2012
- ),
2013
- (showHelperText || hasError) && /* @__PURE__ */ jsxRuntime.jsx(
2014
- HelperTextComponent,
2015
- {
2016
- error: hasError,
2017
- sx: [
2018
- {
2019
- mx: 0,
2020
- mt: 0.5,
2021
- ...hasError && {
2022
- color: "error.main",
2023
- ...errorSx
2024
- },
2025
- ...helperTextSx
2026
- }
2027
- ],
2028
- className: `app-rating-helper-text ${helperTextClassName} ${hasError ? "Mui-error" : ""}`,
2029
- ...helperTextProps,
2030
- children: hasError ? fieldError : helperText
2031
- }
2032
- )
2033
- ]
2034
- }
2035
- );
2036
- });
1935
+ ],
1936
+ className: `app-rating-helper-text ${helperTextClassName} ${hasError ? "Mui-error" : ""}`,
1937
+ ...helperTextProps,
1938
+ children: hasError ? fieldError : helperText
1939
+ }
1940
+ )
1941
+ ]
1942
+ }
1943
+ );
1944
+ }
1945
+ );
2037
1946
  AppRating.displayName = "AppRating";
2038
1947
  var AppRating_default = AppRating;
2039
1948
 
@@ -13793,16 +13702,7 @@ function Upload({
13793
13702
  },
13794
13703
  children: [
13795
13704
  /* @__PURE__ */ jsxRuntime.jsx("input", { ...getInputProps() }),
13796
- /* @__PURE__ */ jsxRuntime.jsx(
13797
- Placeholder,
13798
- {
13799
- sx: {
13800
- ...hasFile && {
13801
- opacity: 0
13802
- }
13803
- }
13804
- }
13805
- ),
13705
+ hasFile ? null : /* @__PURE__ */ jsxRuntime.jsx(Placeholder, {}),
13806
13706
  hasFile && /* @__PURE__ */ jsxRuntime.jsx(SingleFilePreview, { file })
13807
13707
  ]
13808
13708
  }
@@ -13955,15 +13855,22 @@ var AppUploadFile = ({ name, ...rest }) => {
13955
13855
  setFieldValue(name, "", true);
13956
13856
  }
13957
13857
  },
13958
- onRemove: (e) => {
13959
- const afterFilter = val.filter((file) => {
13960
- var _a2;
13961
- if ((_a2 = file.file) != null ? _a2 : false) {
13962
- return !_19__default.default.isEqual(e, file.file);
13963
- }
13964
- return !_19__default.default.isEqual(e, file);
13965
- });
13966
- setFieldValue(name, afterFilter, true);
13858
+ onRemove: (fileToRemove) => {
13859
+ if (rest.multiple) {
13860
+ const currentFiles = Array.isArray(val) ? val : [];
13861
+ const updatedFiles = currentFiles.filter((f) => {
13862
+ if (f.file && f.file === fileToRemove)
13863
+ return false;
13864
+ if (f === fileToRemove)
13865
+ return false;
13866
+ if (f.preview === fileToRemove)
13867
+ return false;
13868
+ return true;
13869
+ });
13870
+ setFieldValue(name, updatedFiles, true);
13871
+ } else {
13872
+ setFieldValue(name, null, true);
13873
+ }
13967
13874
  }
13968
13875
  }
13969
13876
  ),