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.mjs CHANGED
@@ -4,12 +4,12 @@ import { Box, useTheme, FormControl, Typography, FormHelperText, TextField, Inpu
4
4
  import { DatePicker } from '@mui/x-date-pickers/DatePicker';
5
5
  import { LocalizationProvider } from '@mui/x-date-pickers/LocalizationProvider';
6
6
  import { AdapterDayjs } from '@mui/x-date-pickers/AdapterDayjs';
7
- import { Dayjs } from 'dayjs';
7
+ import CalendarMonthIcon from '@mui/icons-material/CalendarMonth';
8
8
  import _19, { get } from 'lodash';
9
9
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
10
10
  import { DateTimePicker } from '@mui/x-date-pickers/DateTimePicker';
11
11
  import Autocomplete3 from '@mui/material/Autocomplete';
12
- import Typography10 from '@mui/material/Typography';
12
+ import Typography9 from '@mui/material/Typography';
13
13
  import { Icon } from '@iconify/react';
14
14
  import Select from '@mui/material/Select';
15
15
  import PhoneInput from 'react-phone-input-2';
@@ -43,129 +43,35 @@ var AppDatePicker = forwardRef(
43
43
  ({
44
44
  name,
45
45
  label,
46
- required = false,
47
46
  disabled = false,
48
- variant = "outlined",
49
- showIcon = true,
50
47
  format = "DD/MM/YYYY",
51
48
  sx,
52
- formControlSx,
53
49
  textFieldSx,
54
- labelSx,
55
- inputSx,
56
- errorSx,
57
- iconSx,
58
- onChange: externalOnChange,
59
- onBlur: externalOnBlur,
60
50
  ...otherProps
61
51
  }, ref) => {
62
52
  const { values, setFieldValue, touched, errors, setFieldTouched } = useFormikContext();
63
53
  const fieldValue = _19.get(values, name);
64
54
  const fieldError = _19.get(errors, name);
65
55
  const isTouched = _19.get(touched, name);
66
- const handleChange = (newValue, context) => {
56
+ const handleChange = (newValue) => {
67
57
  setFieldValue(name, newValue);
68
- if (externalOnChange) {
69
- externalOnChange(newValue, context);
70
- }
71
- };
72
- const handleBlur = (event) => {
73
- setFieldTouched(name, true);
74
- if (externalOnBlur) {
75
- externalOnBlur(event);
76
- }
77
58
  };
78
59
  return /* @__PURE__ */ jsx(LocalizationProvider, { dateAdapter: AdapterDayjs, children: /* @__PURE__ */ jsx(Box, { sx, ref, children: /* @__PURE__ */ jsx(
79
60
  DatePicker,
80
61
  {
81
62
  label,
82
- value: fieldValue ? fieldValue instanceof Dayjs ? fieldValue : null : null,
63
+ value: fieldValue,
83
64
  onChange: handleChange,
84
65
  format,
85
66
  disabled,
86
67
  slotProps: {
87
68
  textField: {
69
+ variant: "outlined",
88
70
  fullWidth: true,
89
- variant,
90
71
  error: isTouched && Boolean(fieldError),
91
72
  helperText: isTouched && fieldError ? fieldError : void 0,
92
- onBlur: handleBlur,
93
- sx: [
94
- {
95
- "& .MuiOutlinedInput-root": {
96
- backgroundColor: "background.paper",
97
- "&.Mui-focused": {
98
- "& .MuiOutlinedInput-notchedOutline": {
99
- borderColor: "primary.main"
100
- }
101
- },
102
- "&.Mui-error": {
103
- backgroundColor: "error.lighter",
104
- "& .MuiOutlinedInput-input": {
105
- color: "error.main"
106
- }
107
- },
108
- "&.Mui-disabled": {
109
- backgroundColor: "action.disabledBackground",
110
- "& .MuiOutlinedInput-notchedOutline": {
111
- borderColor: "action.disabled"
112
- }
113
- },
114
- ...inputSx
115
- },
116
- "& .MuiOutlinedInput-notchedOutline": {
117
- borderColor: isTouched && fieldError ? "error.main" : "divider"
118
- },
119
- "&:hover .MuiOutlinedInput-notchedOutline": {
120
- borderColor: isTouched && fieldError ? "error.main" : "primary.main"
121
- },
122
- ...textFieldSx
123
- }
124
- ],
125
- FormHelperTextProps: {
126
- sx: [
127
- {
128
- color: "error.main",
129
- mx: 0,
130
- mt: 0.5,
131
- ...errorSx
132
- }
133
- ]
134
- },
135
- InputLabelProps: {
136
- sx: [
137
- {
138
- color: "text.secondary",
139
- "&.Mui-focused": {
140
- color: "primary.main"
141
- },
142
- "&.Mui-error": {
143
- color: "error.main"
144
- },
145
- ...labelSx
146
- }
147
- ]
148
- },
149
- InputProps: {
150
- endAdornment: showIcon ? /* @__PURE__ */ jsx(
151
- Box,
152
- {
153
- component: "span",
154
- sx: [
155
- {
156
- color: "text.secondary",
157
- "&:hover": {
158
- color: "primary.main"
159
- },
160
- "&.Mui-disabled": {
161
- color: "action.disabled"
162
- },
163
- ...iconSx
164
- }
165
- ]
166
- }
167
- ) : null
168
- }
73
+ sx: textFieldSx,
74
+ openPickerIcon: CalendarMonthIcon
169
75
  }
170
76
  },
171
77
  ...otherProps
@@ -1095,7 +1001,7 @@ var AppCheckBox = ({
1095
1001
  }, ...Array.isArray(sx) ? sx : [sx]],
1096
1002
  children: [
1097
1003
  label && /* @__PURE__ */ jsx(
1098
- Typography10,
1004
+ Typography9,
1099
1005
  {
1100
1006
  variant: "subtitle2",
1101
1007
  gutterBottom: true,
@@ -1172,7 +1078,7 @@ var AppCheckBox = ({
1172
1078
  }
1173
1079
  ),
1174
1080
  /* @__PURE__ */ jsx(
1175
- Typography10,
1081
+ Typography9,
1176
1082
  {
1177
1083
  variant: "body2",
1178
1084
  sx: [{
@@ -1191,7 +1097,7 @@ var AppCheckBox = ({
1191
1097
  }
1192
1098
  ),
1193
1099
  isTouched && fieldError && /* @__PURE__ */ jsx(
1194
- Typography10,
1100
+ Typography9,
1195
1101
  {
1196
1102
  variant: "caption",
1197
1103
  sx: [{
@@ -1807,206 +1713,208 @@ var AppRadioGroup = forwardRef(({
1807
1713
  });
1808
1714
  AppRadioGroup.displayName = "AppRadioGroup";
1809
1715
  var AppRadioGroup_default = AppRadioGroup;
1810
- var AppRating = forwardRef(({
1811
- name,
1812
- label,
1813
- required = false,
1814
- readOnly = false,
1815
- disabled = false,
1816
- max = 5,
1817
- precision = 1,
1818
- size = "medium",
1819
- emptyIcon,
1820
- icon,
1821
- IconContainerComponent,
1822
- getLabelText,
1823
- onChange: externalOnChange,
1824
- onChangeActive,
1825
- sx,
1826
- labelSx,
1827
- ratingSx,
1828
- errorSx,
1829
- helperTextSx,
1830
- showHelperText = false,
1831
- helperText,
1832
- labelComponent: LabelComponent = Typography,
1833
- ratingComponent: RatingComponent = Rating,
1834
- errorComponent: ErrorComponent = Typography,
1835
- helperTextComponent: HelperTextComponent = FormHelperText,
1836
- labelProps = {},
1837
- ratingProps = {},
1838
- errorProps = {},
1839
- helperTextProps = {},
1840
- className = "",
1841
- labelClassName = "",
1842
- ratingClassName = "",
1843
- errorClassName = "",
1844
- helperTextClassName = "",
1845
- ...otherProps
1846
- }, ref) => {
1847
- useTheme();
1848
- const { errors, touched, setFieldValue, values, setFieldTouched } = useFormikContext();
1849
- const val = _19.get(values, name);
1850
- const fieldError = _19.get(errors, name);
1851
- const isTouched = _19.get(touched, name);
1852
- const hasError = Boolean(fieldError) && isTouched;
1853
- const handleChange = (event, newValue) => {
1854
- setFieldValue(name, newValue);
1855
- setFieldTouched(name, true, false);
1856
- if (externalOnChange) {
1857
- externalOnChange(event, newValue);
1858
- }
1859
- };
1860
- const handleBlur = () => {
1861
- setFieldTouched(name, true, true);
1862
- };
1863
- return /* @__PURE__ */ jsxs(
1864
- Box,
1865
- {
1866
- ref,
1867
- className: `app-rating ${className}`,
1868
- sx: [
1869
- {
1870
- display: "flex",
1871
- flexDirection: "column",
1872
- width: "100%",
1873
- "&:hover": {
1874
- "& .MuiRating-iconEmpty": {
1875
- color: "primary.light"
1876
- }
1877
- }
1878
- },
1879
- ...Array.isArray(sx) ? sx : [sx]
1880
- ],
1881
- ...otherProps,
1882
- children: [
1883
- /* @__PURE__ */ jsxs(
1884
- Stack,
1716
+ var AppRating = forwardRef(
1717
+ ({
1718
+ name,
1719
+ label,
1720
+ required = false,
1721
+ readOnly = false,
1722
+ disabled = false,
1723
+ max = 5,
1724
+ precision = 1,
1725
+ size = "medium",
1726
+ emptyIcon,
1727
+ icon,
1728
+ IconContainerComponent,
1729
+ getLabelText,
1730
+ onChange: externalOnChange,
1731
+ onChangeActive,
1732
+ sx,
1733
+ labelSx,
1734
+ ratingSx,
1735
+ errorSx,
1736
+ helperTextSx,
1737
+ showHelperText = false,
1738
+ helperText,
1739
+ labelComponent: LabelComponent = Typography,
1740
+ ratingComponent: RatingComponent = Rating,
1741
+ errorComponent: ErrorComponent = Typography,
1742
+ helperTextComponent: HelperTextComponent = FormHelperText,
1743
+ labelProps = {},
1744
+ ratingProps = {},
1745
+ errorProps = {},
1746
+ helperTextProps = {},
1747
+ className = "",
1748
+ labelClassName = "",
1749
+ ratingClassName = "",
1750
+ errorClassName = "",
1751
+ helperTextClassName = "",
1752
+ ...otherProps
1753
+ }, ref) => {
1754
+ useTheme();
1755
+ const { errors, touched, setFieldValue, values, setFieldTouched } = useFormikContext();
1756
+ const val = _19.get(values, name);
1757
+ const fieldError = _19.get(errors, name);
1758
+ const isTouched = _19.get(touched, name);
1759
+ const hasError = Boolean(fieldError) && isTouched;
1760
+ const handleChange = (event, newValue) => {
1761
+ setFieldValue(name, newValue);
1762
+ setFieldTouched(name, true, false);
1763
+ if (externalOnChange) {
1764
+ externalOnChange(event, newValue);
1765
+ }
1766
+ };
1767
+ const handleBlur = () => {
1768
+ setFieldTouched(name, true, true);
1769
+ };
1770
+ return /* @__PURE__ */ jsxs(
1771
+ Box,
1772
+ {
1773
+ ref,
1774
+ className: `app-rating ${className}`,
1775
+ sx: [
1885
1776
  {
1886
- direction: "row",
1887
- alignItems: "center",
1888
- spacing: 1,
1889
- sx: {
1890
- "&.Mui-disabled": {
1891
- opacity: 0.5,
1892
- cursor: "not-allowed"
1777
+ display: "flex",
1778
+ flexDirection: "column",
1779
+ width: "100%",
1780
+ "&:hover": {
1781
+ "& .MuiRating-iconEmpty": {
1782
+ color: "primary.light"
1893
1783
  }
1894
- },
1895
- className: disabled ? "Mui-disabled" : "",
1896
- children: [
1897
- label && /* @__PURE__ */ jsxs(
1898
- LabelComponent,
1899
- {
1900
- variant: "body2",
1901
- color: hasError ? "error" : "text.primary",
1902
- className: `app-rating-label ${labelClassName}`,
1903
- sx: [
1904
- {
1905
- margin: 0,
1906
- fontWeight: 500,
1907
- ...disabled && {
1908
- color: "text.disabled"
1909
- }
1910
- },
1911
- ...Array.isArray(labelSx) ? labelSx : [labelSx]
1912
- ],
1913
- ...labelProps,
1914
- children: [
1915
- label,
1916
- required && /* @__PURE__ */ jsx(
1917
- Box,
1918
- {
1919
- component: "span",
1920
- sx: {
1921
- color: "error.main",
1922
- ml: 0.5
1923
- },
1924
- children: "*"
1925
- }
1926
- )
1927
- ]
1784
+ }
1785
+ },
1786
+ ...Array.isArray(sx) ? sx : [sx]
1787
+ ],
1788
+ ...otherProps,
1789
+ children: [
1790
+ /* @__PURE__ */ jsxs(
1791
+ Stack,
1792
+ {
1793
+ direction: "row",
1794
+ alignItems: "center",
1795
+ spacing: 1,
1796
+ sx: {
1797
+ "&.Mui-disabled": {
1798
+ opacity: 0.5,
1799
+ cursor: "not-allowed"
1928
1800
  }
1929
- ),
1930
- /* @__PURE__ */ jsx(
1931
- Box,
1932
- {
1933
- onBlur: handleBlur,
1934
- sx: [
1935
- {
1936
- display: "inline-flex",
1937
- "& .MuiRating-icon": {
1938
- color: "primary.main"
1939
- },
1940
- "& .MuiRating-iconEmpty": {
1941
- color: "action.disabled"
1942
- },
1943
- "& .MuiRating-iconFilled": {
1944
- color: "primary.main"
1945
- },
1946
- "& .MuiRating-iconHover": {
1947
- color: "primary.dark"
1948
- },
1949
- "&.Mui-disabled": {
1950
- opacity: 0.5,
1951
- cursor: "not-allowed"
1801
+ },
1802
+ className: disabled ? "Mui-disabled" : "",
1803
+ children: [
1804
+ label && /* @__PURE__ */ jsxs(
1805
+ LabelComponent,
1806
+ {
1807
+ variant: "body2",
1808
+ color: hasError ? "error" : "text.primary",
1809
+ className: `app-rating-label ${labelClassName}`,
1810
+ sx: [
1811
+ {
1812
+ margin: 0,
1813
+ fontWeight: 500,
1814
+ ...disabled && {
1815
+ color: "text.disabled"
1816
+ }
1952
1817
  },
1953
- ...hasError && {
1818
+ ...Array.isArray(labelSx) ? labelSx : [labelSx]
1819
+ ],
1820
+ ...labelProps,
1821
+ children: [
1822
+ label,
1823
+ required && /* @__PURE__ */ jsx(
1824
+ Box,
1825
+ {
1826
+ component: "span",
1827
+ sx: {
1828
+ color: "error.main",
1829
+ ml: 0.5
1830
+ },
1831
+ children: "*"
1832
+ }
1833
+ )
1834
+ ]
1835
+ }
1836
+ ),
1837
+ /* @__PURE__ */ jsx(
1838
+ Box,
1839
+ {
1840
+ onBlur: handleBlur,
1841
+ sx: [
1842
+ {
1843
+ display: "inline-flex",
1954
1844
  "& .MuiRating-icon": {
1955
- color: "error.main"
1845
+ color: "primary.main"
1846
+ },
1847
+ "& .MuiRating-iconEmpty": {
1848
+ color: "action.disabled"
1849
+ },
1850
+ "& .MuiRating-iconFilled": {
1851
+ color: "primary.main"
1852
+ },
1853
+ "& .MuiRating-iconHover": {
1854
+ color: "primary.dark"
1855
+ },
1856
+ "&.Mui-disabled": {
1857
+ opacity: 0.5,
1858
+ cursor: "not-allowed"
1859
+ },
1860
+ ...hasError && {
1861
+ "& .MuiRating-icon": {
1862
+ color: "error.main"
1863
+ }
1956
1864
  }
1865
+ },
1866
+ ...Array.isArray(ratingSx) ? ratingSx : [ratingSx]
1867
+ ],
1868
+ className: `app-rating-stars ${ratingClassName} ${disabled ? "Mui-disabled" : ""}`,
1869
+ children: /* @__PURE__ */ jsx(
1870
+ RatingComponent,
1871
+ {
1872
+ value: val != null ? val : null,
1873
+ onChange: handleChange,
1874
+ onChangeActive,
1875
+ max,
1876
+ precision,
1877
+ size,
1878
+ readOnly,
1879
+ disabled,
1880
+ emptyIcon,
1881
+ icon,
1882
+ IconContainerComponent,
1883
+ getLabelText,
1884
+ className: ratingClassName,
1885
+ ...ratingProps
1957
1886
  }
1958
- },
1959
- ...Array.isArray(ratingSx) ? ratingSx : [ratingSx]
1960
- ],
1961
- className: `app-rating-stars ${ratingClassName} ${disabled ? "Mui-disabled" : ""}`,
1962
- children: /* @__PURE__ */ jsx(
1963
- RatingComponent,
1964
- {
1965
- value: val != null ? val : null,
1966
- onChange: handleChange,
1967
- onChangeActive,
1968
- max,
1969
- precision,
1970
- size,
1971
- readOnly,
1972
- disabled,
1973
- emptyIcon,
1974
- icon,
1975
- IconContainerComponent,
1976
- getLabelText,
1977
- className: ratingClassName,
1978
- ...ratingProps
1979
- }
1980
- )
1887
+ )
1888
+ }
1889
+ )
1890
+ ]
1891
+ }
1892
+ ),
1893
+ (showHelperText || hasError) && /* @__PURE__ */ jsx(
1894
+ HelperTextComponent,
1895
+ {
1896
+ error: hasError,
1897
+ sx: [
1898
+ {
1899
+ mx: 0,
1900
+ mt: 0.5,
1901
+ ...hasError && {
1902
+ color: "error.main",
1903
+ ...errorSx
1904
+ },
1905
+ ...helperTextSx
1981
1906
  }
1982
- )
1983
- ]
1984
- }
1985
- ),
1986
- (showHelperText || hasError) && /* @__PURE__ */ jsx(
1987
- HelperTextComponent,
1988
- {
1989
- error: hasError,
1990
- sx: [
1991
- {
1992
- mx: 0,
1993
- mt: 0.5,
1994
- ...hasError && {
1995
- color: "error.main",
1996
- ...errorSx
1997
- },
1998
- ...helperTextSx
1999
- }
2000
- ],
2001
- className: `app-rating-helper-text ${helperTextClassName} ${hasError ? "Mui-error" : ""}`,
2002
- ...helperTextProps,
2003
- children: hasError ? fieldError : helperText
2004
- }
2005
- )
2006
- ]
2007
- }
2008
- );
2009
- });
1907
+ ],
1908
+ className: `app-rating-helper-text ${helperTextClassName} ${hasError ? "Mui-error" : ""}`,
1909
+ ...helperTextProps,
1910
+ children: hasError ? fieldError : helperText
1911
+ }
1912
+ )
1913
+ ]
1914
+ }
1915
+ );
1916
+ }
1917
+ );
2010
1918
  AppRating.displayName = "AppRating";
2011
1919
  var AppRating_default = AppRating;
2012
1920
 
@@ -13766,16 +13674,7 @@ function Upload({
13766
13674
  },
13767
13675
  children: [
13768
13676
  /* @__PURE__ */ jsx("input", { ...getInputProps() }),
13769
- /* @__PURE__ */ jsx(
13770
- Placeholder,
13771
- {
13772
- sx: {
13773
- ...hasFile && {
13774
- opacity: 0
13775
- }
13776
- }
13777
- }
13778
- ),
13677
+ hasFile ? null : /* @__PURE__ */ jsx(Placeholder, {}),
13779
13678
  hasFile && /* @__PURE__ */ jsx(SingleFilePreview, { file })
13780
13679
  ]
13781
13680
  }
@@ -13928,15 +13827,22 @@ var AppUploadFile = ({ name, ...rest }) => {
13928
13827
  setFieldValue(name, "", true);
13929
13828
  }
13930
13829
  },
13931
- onRemove: (e) => {
13932
- const afterFilter = val.filter((file) => {
13933
- var _a2;
13934
- if ((_a2 = file.file) != null ? _a2 : false) {
13935
- return !_19.isEqual(e, file.file);
13936
- }
13937
- return !_19.isEqual(e, file);
13938
- });
13939
- setFieldValue(name, afterFilter, true);
13830
+ onRemove: (fileToRemove) => {
13831
+ if (rest.multiple) {
13832
+ const currentFiles = Array.isArray(val) ? val : [];
13833
+ const updatedFiles = currentFiles.filter((f) => {
13834
+ if (f.file && f.file === fileToRemove)
13835
+ return false;
13836
+ if (f === fileToRemove)
13837
+ return false;
13838
+ if (f.preview === fileToRemove)
13839
+ return false;
13840
+ return true;
13841
+ });
13842
+ setFieldValue(name, updatedFiles, true);
13843
+ } else {
13844
+ setFieldValue(name, null, true);
13845
+ }
13940
13846
  }
13941
13847
  }
13942
13848
  ),