@etsoo/materialui 1.6.17 → 1.6.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.
@@ -29,41 +29,29 @@ function ComboBoxMultiple(props) {
29
29
  // Labels
30
30
  const labels = app?.getLabels("noOptions", "loading");
31
31
  // Destruct
32
- const { search = false, autoAddBlankItem = search, idField = "id", idValue, idValues, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputReset, inputVariant, defaultValue, label, labelField = "label", loadData, onLoadData, name, inputAutoComplete = "off", options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, disableCloseOnSelect = true, renderOption = (props, option, { selected }) => ((0, jsx_runtime_1.jsxs)("li", { ...props, children: [(0, jsx_runtime_1.jsx)(Checkbox_1.default, { icon: icon, checkedIcon: checkedIcon, style: { marginRight: 8 }, checked: selected }), `${option[labelField]}`] })), getOptionLabel = (option) => `${option[labelField]}`, getOptionKey = (option) => `${option[idField]}`, sx = { minWidth: "150px" }, noOptionsText = labels?.noOptions, loadingText = labels?.loading, disabled, ...rest } = props;
32
+ const { search = false, autoAddBlankItem = search, idField = "id", idValue, idValues, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputReset, inputVariant, defaultValue, label, labelField = "label", loadData, onLoadData, name, inputAutoComplete = "off", options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, disableCloseOnSelect = true, renderOption = ({ key, ...restProps }, option, { selected }) => ((0, jsx_runtime_1.jsxs)("li", { ...restProps, children: [(0, jsx_runtime_1.jsx)(Checkbox_1.default, { icon: icon, checkedIcon: checkedIcon, style: { marginRight: 8 }, checked: selected }), `${option[labelField]}`] }, key)), getOptionLabel = (option) => `${option[labelField]}`, getOptionKey = (option) => `${option[idField]}`, sx = { minWidth: "150px" }, noOptionsText = labels?.noOptions, loadingText = labels?.loading, disabled, ...rest } = props;
33
33
  // Value input ref
34
34
  const inputRef = react_1.default.createRef();
35
35
  // Options state
36
36
  const [localOptions, setOptions] = react_1.default.useState(options ?? []);
37
37
  const isMounted = react_1.default.useRef(true);
38
- // Local default value
39
- const localValue = idValue != null
40
- ? localOptions.filter((o) => o[idField] === idValue)
41
- : idValues != null
42
- ? localOptions.filter((o) => idValues?.includes(o[idField]))
43
- : defaultValue?.concat() ?? value?.concat();
44
- // State
45
- // null for controlled
46
- const [stateValue, setStateValue] = react_1.default.useState(null);
47
- react_1.default.useEffect(() => {
48
- setStateValue(localValue ?? []);
49
- }, [localValue]);
50
- // When options change
51
- // [options] will cause infinite loop
52
38
  const propertyWay = loadData == null;
53
39
  react_1.default.useEffect(() => {
54
40
  if (propertyWay && options != null) {
55
41
  setOptions(options);
56
- if (stateValue != null) {
57
- if (Array.isArray(stateValue)) {
58
- const newState = stateValue.filter((item) => options.some((option) => option[idField] === item[idField]));
59
- setStateValue(newState);
60
- }
61
- else if (!options.some((option) => option[idField] === stateValue[idField])) {
62
- setStateValue(null);
63
- }
64
- }
65
42
  }
66
43
  }, [options, propertyWay]);
44
+ // State
45
+ // null for controlled
46
+ const [stateValue, setStateValue] = react_1.default.useState(null);
47
+ react_1.default.useEffect(() => {
48
+ const localValue = idValue != null
49
+ ? localOptions.filter((o) => o[idField] === idValue)
50
+ : idValues != null
51
+ ? localOptions.filter((o) => idValues?.includes(o[idField]))
52
+ : (defaultValue?.concat() ?? value?.concat());
53
+ setStateValue(localValue ?? []);
54
+ }, [localOptions, idField, idValue, idValues, defaultValue, value]);
67
55
  // Add readOnly
68
56
  const addReadOnly = (params) => {
69
57
  if (readOnly != null) {
@@ -38,10 +38,11 @@ const FieldCombobox = ({ field, mref, onChange, defaultValue }) => {
38
38
  if (!name) {
39
39
  return ((0, jsx_runtime_1.jsxs)(Typography_1.default, { children: ["No name for FieldCombobox ", JSON.stringify(field)] }));
40
40
  }
41
- return ((0, jsx_runtime_1.jsx)(ComboBoxMultiple_1.ComboBoxMultiple, { label: field.label ?? "", inputHelperText: field.helperText, name: name, options: field.options, fullWidth: true, idValues: ids, onChange: (_event, value) => {
41
+ const { required, inputRequired, ...mainRests } = field.mainSlotProps || {};
42
+ return ((0, jsx_runtime_1.jsx)(ComboBoxMultiple_1.ComboBoxMultiple, { label: field.label ?? "", inputHelperText: field.helperText, name: name, options: field.options, fullWidth: true, idValues: ids, inputRequired: required || inputRequired, onChange: (_event, value) => {
42
43
  const ids = value.map((v) => v.id);
43
44
  setIds(ids);
44
45
  onChange(name, ids);
45
- }, ...field.mainSlotProps }));
46
+ }, ...mainRests }));
46
47
  };
47
48
  exports.FieldCombobox = FieldCombobox;
@@ -23,41 +23,29 @@ export function ComboBoxMultiple(props) {
23
23
  // Labels
24
24
  const labels = app?.getLabels("noOptions", "loading");
25
25
  // Destruct
26
- const { search = false, autoAddBlankItem = search, idField = "id", idValue, idValues, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputReset, inputVariant, defaultValue, label, labelField = "label", loadData, onLoadData, name, inputAutoComplete = "off", options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, disableCloseOnSelect = true, renderOption = (props, option, { selected }) => (_jsxs("li", { ...props, children: [_jsx(Checkbox, { icon: icon, checkedIcon: checkedIcon, style: { marginRight: 8 }, checked: selected }), `${option[labelField]}`] })), getOptionLabel = (option) => `${option[labelField]}`, getOptionKey = (option) => `${option[idField]}`, sx = { minWidth: "150px" }, noOptionsText = labels?.noOptions, loadingText = labels?.loading, disabled, ...rest } = props;
26
+ const { search = false, autoAddBlankItem = search, idField = "id", idValue, idValues, inputError, inputHelperText, inputMargin, inputOnChange, inputRequired, inputReset, inputVariant, defaultValue, label, labelField = "label", loadData, onLoadData, name, inputAutoComplete = "off", options, dataReadonly = true, readOnly, onChange, openOnFocus = true, value, disableCloseOnSelect = true, renderOption = ({ key, ...restProps }, option, { selected }) => (_jsxs("li", { ...restProps, children: [_jsx(Checkbox, { icon: icon, checkedIcon: checkedIcon, style: { marginRight: 8 }, checked: selected }), `${option[labelField]}`] }, key)), getOptionLabel = (option) => `${option[labelField]}`, getOptionKey = (option) => `${option[idField]}`, sx = { minWidth: "150px" }, noOptionsText = labels?.noOptions, loadingText = labels?.loading, disabled, ...rest } = props;
27
27
  // Value input ref
28
28
  const inputRef = React.createRef();
29
29
  // Options state
30
30
  const [localOptions, setOptions] = React.useState(options ?? []);
31
31
  const isMounted = React.useRef(true);
32
- // Local default value
33
- const localValue = idValue != null
34
- ? localOptions.filter((o) => o[idField] === idValue)
35
- : idValues != null
36
- ? localOptions.filter((o) => idValues?.includes(o[idField]))
37
- : defaultValue?.concat() ?? value?.concat();
38
- // State
39
- // null for controlled
40
- const [stateValue, setStateValue] = React.useState(null);
41
- React.useEffect(() => {
42
- setStateValue(localValue ?? []);
43
- }, [localValue]);
44
- // When options change
45
- // [options] will cause infinite loop
46
32
  const propertyWay = loadData == null;
47
33
  React.useEffect(() => {
48
34
  if (propertyWay && options != null) {
49
35
  setOptions(options);
50
- if (stateValue != null) {
51
- if (Array.isArray(stateValue)) {
52
- const newState = stateValue.filter((item) => options.some((option) => option[idField] === item[idField]));
53
- setStateValue(newState);
54
- }
55
- else if (!options.some((option) => option[idField] === stateValue[idField])) {
56
- setStateValue(null);
57
- }
58
- }
59
36
  }
60
37
  }, [options, propertyWay]);
38
+ // State
39
+ // null for controlled
40
+ const [stateValue, setStateValue] = React.useState(null);
41
+ React.useEffect(() => {
42
+ const localValue = idValue != null
43
+ ? localOptions.filter((o) => o[idField] === idValue)
44
+ : idValues != null
45
+ ? localOptions.filter((o) => idValues?.includes(o[idField]))
46
+ : (defaultValue?.concat() ?? value?.concat());
47
+ setStateValue(localValue ?? []);
48
+ }, [localOptions, idField, idValue, idValues, defaultValue, value]);
61
49
  // Add readOnly
62
50
  const addReadOnly = (params) => {
63
51
  if (readOnly != null) {
@@ -32,9 +32,10 @@ export const FieldCombobox = ({ field, mref, onChange, defaultValue }) => {
32
32
  if (!name) {
33
33
  return (_jsxs(Typography, { children: ["No name for FieldCombobox ", JSON.stringify(field)] }));
34
34
  }
35
- return (_jsx(ComboBoxMultiple, { label: field.label ?? "", inputHelperText: field.helperText, name: name, options: field.options, fullWidth: true, idValues: ids, onChange: (_event, value) => {
35
+ const { required, inputRequired, ...mainRests } = field.mainSlotProps || {};
36
+ return (_jsx(ComboBoxMultiple, { label: field.label ?? "", inputHelperText: field.helperText, name: name, options: field.options, fullWidth: true, idValues: ids, inputRequired: required || inputRequired, onChange: (_event, value) => {
36
37
  const ids = value.map((v) => v.id);
37
38
  setIds(ids);
38
39
  onChange(name, ids);
39
- }, ...field.mainSlotProps }));
40
+ }, ...mainRests }));
40
41
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.6.17",
3
+ "version": "1.6.18",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/cjs/index.js",
6
6
  "module": "lib/mjs/index.js",
@@ -110,8 +110,8 @@ export function ComboBoxMultiple<
110
110
  openOnFocus = true,
111
111
  value,
112
112
  disableCloseOnSelect = true,
113
- renderOption = (props, option, { selected }) => (
114
- <li {...props}>
113
+ renderOption = ({ key, ...restProps }, option, { selected }) => (
114
+ <li key={key} {...restProps}>
115
115
  <Checkbox
116
116
  icon={icon}
117
117
  checkedIcon={checkedIcon}
@@ -137,43 +137,27 @@ export function ComboBoxMultiple<
137
137
  const [localOptions, setOptions] = React.useState(options ?? []);
138
138
  const isMounted = React.useRef(true);
139
139
 
140
- // Local default value
141
- const localValue: T[] | null | undefined =
142
- idValue != null
143
- ? localOptions.filter((o) => o[idField] === idValue)
144
- : idValues != null
145
- ? localOptions.filter((o) => idValues?.includes(o[idField]))
146
- : defaultValue?.concat() ?? value?.concat();
140
+ const propertyWay = loadData == null;
141
+ React.useEffect(() => {
142
+ if (propertyWay && options != null) {
143
+ setOptions(options);
144
+ }
145
+ }, [options, propertyWay]);
147
146
 
148
147
  // State
149
148
  // null for controlled
150
149
  const [stateValue, setStateValue] = React.useState<T[] | null>(null);
151
150
 
152
151
  React.useEffect(() => {
153
- setStateValue(localValue ?? []);
154
- }, [localValue]);
152
+ const localValue: T[] | null | undefined =
153
+ idValue != null
154
+ ? localOptions.filter((o) => o[idField] === idValue)
155
+ : idValues != null
156
+ ? localOptions.filter((o) => idValues?.includes(o[idField]))
157
+ : (defaultValue?.concat() ?? value?.concat());
155
158
 
156
- // When options change
157
- // [options] will cause infinite loop
158
- const propertyWay = loadData == null;
159
- React.useEffect(() => {
160
- if (propertyWay && options != null) {
161
- setOptions(options);
162
-
163
- if (stateValue != null) {
164
- if (Array.isArray(stateValue)) {
165
- const newState = stateValue.filter((item) =>
166
- options.some((option) => option[idField] === item[idField])
167
- );
168
- setStateValue(newState);
169
- } else if (
170
- !options.some((option) => option[idField] === stateValue[idField])
171
- ) {
172
- setStateValue(null);
173
- }
174
- }
175
- }
176
- }, [options, propertyWay]);
159
+ setStateValue(localValue ?? []);
160
+ }, [localOptions, idField, idValue, idValues, defaultValue, value]);
177
161
 
178
162
  // Add readOnly
179
163
  const addReadOnly = (params: AutocompleteRenderInputParams) => {
@@ -258,8 +242,8 @@ export function ComboBoxMultiple<
258
242
  stateValue == null
259
243
  ? []
260
244
  : Array.isArray(stateValue)
261
- ? stateValue
262
- : [stateValue]
245
+ ? stateValue
246
+ : [stateValue]
263
247
  }
264
248
  disabled={disabled}
265
249
  disableCloseOnSelect={disableCloseOnSelect}
@@ -44,6 +44,8 @@ export const FieldCombobox: ICustomFieldReact<IdType[]> = ({
44
44
  );
45
45
  }
46
46
 
47
+ const { required, inputRequired, ...mainRests } = field.mainSlotProps || {};
48
+
47
49
  return (
48
50
  <ComboBoxMultiple
49
51
  label={field.label ?? ""}
@@ -52,12 +54,13 @@ export const FieldCombobox: ICustomFieldReact<IdType[]> = ({
52
54
  options={field.options}
53
55
  fullWidth
54
56
  idValues={ids}
57
+ inputRequired={required || inputRequired}
55
58
  onChange={(_event, value) => {
56
59
  const ids = value.map((v) => v.id);
57
60
  setIds(ids);
58
61
  onChange(name, ids);
59
62
  }}
60
- {...field.mainSlotProps}
63
+ {...mainRests}
61
64
  />
62
65
  );
63
66
  };