@etsoo/materialui 1.0.36 → 1.0.38

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/lib/NotifierMU.js CHANGED
@@ -55,6 +55,7 @@ export class NotificationMU extends NotificationReact {
55
55
  // Callback
56
56
  const callback = async (_event) => {
57
57
  await this.returnValue(undefined);
58
+ return true;
58
59
  };
59
60
  return (React.createElement(Dialog, { key: this.id, open: this.open, PaperComponent: DraggablePaperComponent, className: className, fullWidth: fullWidth, maxWidth: maxWidth, fullScreen: fullScreen },
60
61
  React.createElement(IconDialogTitle, { className: "draggable-dialog-title" },
@@ -71,7 +72,10 @@ export class NotificationMU extends NotificationReact {
71
72
  const labels = Labels.NotificationMU;
72
73
  const title = (_a = this.title) !== null && _a !== void 0 ? _a : labels.confirmTitle;
73
74
  const { buttons, okLabel = labels.confirmYes, cancelLabel = labels.confirmNo, cancelButton = true, inputs, fullScreen, fullWidth = true, maxWidth, primaryButton } = (_b = this.inputProps) !== null && _b !== void 0 ? _b : {};
74
- const callback = async (_event, value) => await this.returnValue(value);
75
+ const callback = async (_event, value) => {
76
+ await this.returnValue(value);
77
+ return true;
78
+ };
75
79
  return (React.createElement(Dialog, { key: this.id, open: this.open, PaperComponent: DraggablePaperComponent, className: className, fullWidth: fullWidth, maxWidth: maxWidth, fullScreen: fullScreen },
76
80
  React.createElement(IconDialogTitle, { className: "draggable-dialog-title" },
77
81
  React.createElement(Help, { color: "action" }),
@@ -134,7 +138,7 @@ export class NotificationMU extends NotificationReact {
134
138
  const dateValue = input.valueAsDate;
135
139
  if (dateValue == null && input.required) {
136
140
  input.focus();
137
- return;
141
+ return false;
138
142
  }
139
143
  result = this.onReturn(dateValue);
140
144
  }
@@ -142,7 +146,7 @@ export class NotificationMU extends NotificationReact {
142
146
  const numberValue = input.valueAsNumber;
143
147
  if (isNaN(numberValue) && input.required) {
144
148
  input.focus();
145
- return;
149
+ return false;
146
150
  }
147
151
  result = this.onReturn(numberValue);
148
152
  }
@@ -154,7 +158,7 @@ export class NotificationMU extends NotificationReact {
154
158
  const textValue = input.value.trim();
155
159
  if (textValue === '' && input.required) {
156
160
  input.focus();
157
- return;
161
+ return false;
158
162
  }
159
163
  result = this.onReturn(textValue);
160
164
  }
@@ -168,14 +172,15 @@ export class NotificationMU extends NotificationReact {
168
172
  const v = await result;
169
173
  if (v === false) {
170
174
  input === null || input === void 0 ? void 0 : input.focus();
171
- return;
175
+ return false;
172
176
  }
173
177
  if (typeof v === 'string') {
174
178
  setError(v);
175
179
  input === null || input === void 0 ? void 0 : input.focus();
176
- return;
180
+ return false;
177
181
  }
178
182
  this.dismiss();
183
+ return true;
179
184
  };
180
185
  let localInputs;
181
186
  let value = undefined;
@@ -1,6 +1,16 @@
1
- /// <reference types="react" />
2
1
  import { DataTypes, IdDefaultType, LabelDefaultType, ListType } from '@etsoo/shared';
3
2
  import { FormControlProps } from '@mui/material';
3
+ import React from 'react';
4
+ /**
5
+ * OptionGroup methods ref
6
+ */
7
+ export interface OptionGroupRef {
8
+ /**
9
+ * Disable specific items with their ids
10
+ * @param ids Ids
11
+ */
12
+ disable(ids: unknown[]): void;
13
+ }
4
14
  /**
5
15
  * OptionGroup props
6
16
  */
@@ -25,6 +35,10 @@ export declare type OptionGroupProps<T extends object, D extends DataTypes.Keys<
25
35
  * Label field
26
36
  */
27
37
  labelField?: L;
38
+ /**
39
+ * Methods
40
+ */
41
+ mRef?: React.Ref<OptionGroupRef>;
28
42
  /**
29
43
  * Multiple choose item
30
44
  */
@@ -8,7 +8,7 @@ import React from 'react';
8
8
  */
9
9
  export function OptionGroup(props) {
10
10
  // Destruct
11
- const { getOptionLabel, defaultValue, idField = 'id', label, labelField = 'label', multiple = false, name, onValueChange, options, readOnly, row, size, ...rest } = props;
11
+ const { getOptionLabel, defaultValue, idField = 'id', label, labelField = 'label', multiple = false, mRef, name, onValueChange, options, readOnly, row, size, ...rest } = props;
12
12
  // Get option value
13
13
  // D type should be the source id type
14
14
  const getOptionValue = (option) => {
@@ -23,6 +23,8 @@ export function OptionGroup(props) {
23
23
  : Array.isArray(defaultValue)
24
24
  ? defaultValue
25
25
  : [defaultValue]);
26
+ // Disabled ids
27
+ const [disabledIds, setDisabledIds] = React.useState();
26
28
  // Item checked
27
29
  const itemChecked = (option) => {
28
30
  // Value
@@ -31,12 +33,19 @@ export function OptionGroup(props) {
31
33
  return false;
32
34
  return values.includes(value);
33
35
  };
36
+ React.useImperativeHandle(mRef, () => ({
37
+ disable(ids) {
38
+ setDisabledIds(ids);
39
+ }
40
+ }));
34
41
  // First item value
35
42
  const firstOptionValue = getOptionValue(options[0]);
36
43
  // Items
37
44
  const list = options.map((option) => {
45
+ // Value
46
+ const ov = getOptionValue(option);
38
47
  // Control
39
- const control = multiple ? (React.createElement(Checkbox, { name: name, readOnly: readOnly, size: size, checked: itemChecked(option), onChange: (event) => {
48
+ const control = multiple ? (React.createElement(Checkbox, { name: name, readOnly: readOnly, size: size, checked: itemChecked(option), disabled: disabledIds === null || disabledIds === void 0 ? void 0 : disabledIds.includes(ov), onChange: (event) => {
40
49
  if (firstOptionValue == null)
41
50
  return;
42
51
  const typeValue = Utils.parseString(event.target.value, firstOptionValue);
@@ -55,7 +64,7 @@ export function OptionGroup(props) {
55
64
  if (onValueChange)
56
65
  onValueChange(changedValues);
57
66
  setValues(changedValues);
58
- } })) : (React.createElement(Radio, { size: size, readOnly: readOnly }));
67
+ } })) : (React.createElement(Radio, { disabled: disabledIds === null || disabledIds === void 0 ? void 0 : disabledIds.includes(ov), size: size, readOnly: readOnly }));
59
68
  // Label
60
69
  const label = getOptionLabel == null
61
70
  ? `${option[labelField]}`
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@etsoo/materialui",
3
- "version": "1.0.36",
3
+ "version": "1.0.38",
4
4
  "description": "TypeScript Material-UI Implementation",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -53,7 +53,7 @@
53
53
  "@emotion/styled": "^11.10.4",
54
54
  "@etsoo/appscript": "^1.3.0",
55
55
  "@etsoo/notificationbase": "^1.1.11",
56
- "@etsoo/react": "^1.6.10",
56
+ "@etsoo/react": "^1.6.11",
57
57
  "@etsoo/shared": "^1.1.58",
58
58
  "@mui/icons-material": "^5.10.6",
59
59
  "@mui/material": "^5.10.7",
@@ -100,6 +100,7 @@ export class NotificationMU extends NotificationReact {
100
100
  _event: React.MouseEvent<HTMLButtonElement>
101
101
  ) => {
102
102
  await this.returnValue(undefined);
103
+ return true;
103
104
  };
104
105
 
105
106
  return (
@@ -158,7 +159,10 @@ export class NotificationMU extends NotificationReact {
158
159
  const callback = async (
159
160
  _event: React.MouseEvent<HTMLButtonElement>,
160
161
  value: boolean
161
- ) => await this.returnValue(value);
162
+ ) => {
163
+ await this.returnValue(value);
164
+ return true;
165
+ };
162
166
 
163
167
  return (
164
168
  <Dialog
@@ -291,14 +295,14 @@ export class NotificationMU extends NotificationReact {
291
295
  const dateValue = input.valueAsDate;
292
296
  if (dateValue == null && input.required) {
293
297
  input.focus();
294
- return;
298
+ return false;
295
299
  }
296
300
  result = this.onReturn(dateValue);
297
301
  } else if (type === 'number') {
298
302
  const numberValue = input.valueAsNumber;
299
303
  if (isNaN(numberValue) && input.required) {
300
304
  input.focus();
301
- return;
305
+ return false;
302
306
  }
303
307
  result = this.onReturn(numberValue);
304
308
  } else if (type === 'switch') {
@@ -308,7 +312,7 @@ export class NotificationMU extends NotificationReact {
308
312
  const textValue = input.value.trim();
309
313
  if (textValue === '' && input.required) {
310
314
  input.focus();
311
- return;
315
+ return false;
312
316
  }
313
317
  result = this.onReturn(textValue);
314
318
  }
@@ -322,15 +326,16 @@ export class NotificationMU extends NotificationReact {
322
326
  const v = await result;
323
327
  if (v === false) {
324
328
  input?.focus();
325
- return;
329
+ return false;
326
330
  }
327
331
  if (typeof v === 'string') {
328
332
  setError(v);
329
333
  input?.focus();
330
- return;
334
+ return false;
331
335
  }
332
336
 
333
337
  this.dismiss();
338
+ return true;
334
339
  };
335
340
 
336
341
  let localInputs: React.ReactNode;
@@ -17,6 +17,17 @@ import {
17
17
  } from '@mui/material';
18
18
  import React from 'react';
19
19
 
20
+ /**
21
+ * OptionGroup methods ref
22
+ */
23
+ export interface OptionGroupRef {
24
+ /**
25
+ * Disable specific items with their ids
26
+ * @param ids Ids
27
+ */
28
+ disable(ids: unknown[]): void;
29
+ }
30
+
20
31
  /**
21
32
  * OptionGroup props
22
33
  */
@@ -50,6 +61,11 @@ export type OptionGroupProps<
50
61
  */
51
62
  labelField?: L;
52
63
 
64
+ /**
65
+ * Methods
66
+ */
67
+ mRef?: React.Ref<OptionGroupRef>;
68
+
53
69
  /**
54
70
  * Multiple choose item
55
71
  */
@@ -99,6 +115,7 @@ export function OptionGroup<
99
115
  label,
100
116
  labelField = 'label' as L,
101
117
  multiple = false,
118
+ mRef,
102
119
  name,
103
120
  onValueChange,
104
121
  options,
@@ -125,6 +142,9 @@ export function OptionGroup<
125
142
  : [defaultValue]
126
143
  );
127
144
 
145
+ // Disabled ids
146
+ const [disabledIds, setDisabledIds] = React.useState<unknown[]>();
147
+
128
148
  // Item checked
129
149
  const itemChecked = (option: T) => {
130
150
  // Value
@@ -134,11 +154,20 @@ export function OptionGroup<
134
154
  return values.includes(value);
135
155
  };
136
156
 
157
+ React.useImperativeHandle(mRef, () => ({
158
+ disable(ids: unknown[]) {
159
+ setDisabledIds(ids);
160
+ }
161
+ }));
162
+
137
163
  // First item value
138
164
  const firstOptionValue = getOptionValue(options[0]);
139
165
 
140
166
  // Items
141
167
  const list = options.map((option) => {
168
+ // Value
169
+ const ov = getOptionValue(option);
170
+
142
171
  // Control
143
172
  const control = multiple ? (
144
173
  <Checkbox
@@ -146,6 +175,7 @@ export function OptionGroup<
146
175
  readOnly={readOnly}
147
176
  size={size}
148
177
  checked={itemChecked(option)}
178
+ disabled={disabledIds?.includes(ov)}
149
179
  onChange={(event) => {
150
180
  if (firstOptionValue == null) return;
151
181
 
@@ -171,7 +201,11 @@ export function OptionGroup<
171
201
  }}
172
202
  />
173
203
  ) : (
174
- <Radio size={size} readOnly={readOnly} />
204
+ <Radio
205
+ disabled={disabledIds?.includes(ov)}
206
+ size={size}
207
+ readOnly={readOnly}
208
+ />
175
209
  );
176
210
 
177
211
  // Label