@etsoo/react 1.4.0 → 1.4.1
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/mu/NotifierMU.js +23 -6
- package/package.json +9 -9
- package/src/mu/NotifierMU.tsx +36 -5
package/lib/mu/NotifierMU.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { NotificationAlign, NotificationMessageType, NotificationType } from '@etsoo/notificationbase';
|
|
2
|
-
import { Alert, AlertTitle, Backdrop, Box, Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Fade, Slider, Snackbar, styled, Switch, TextField } from '@mui/material';
|
|
2
|
+
import { Alert, AlertTitle, Backdrop, Box, Button, CircularProgress, Dialog, DialogActions, DialogContent, DialogContentText, DialogTitle, Fade, Slider, Snackbar, styled, Switch, TextField, Typography } from '@mui/material';
|
|
3
3
|
import { Error, Info, Help, Warning, Done } from '@mui/icons-material';
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import { Labels } from '../app/Labels';
|
|
@@ -120,14 +120,21 @@ export class NotificationMU extends NotificationReact {
|
|
|
120
120
|
const labels = Labels.NotificationMU;
|
|
121
121
|
const title = (_a = this.title) !== null && _a !== void 0 ? _a : labels.promptTitle;
|
|
122
122
|
const { cancelLabel = labels.promptCancel, okLabel = labels.promptOK, inputs, type, fullScreen, fullWidth = true, maxWidth, primaryButton, ...rest } = (_b = this.inputProps) !== null && _b !== void 0 ? _b : {};
|
|
123
|
+
const inputRef = React.createRef();
|
|
124
|
+
const errorRef = React.createRef();
|
|
125
|
+
const setError = (error) => {
|
|
126
|
+
if (errorRef.current == null)
|
|
127
|
+
return;
|
|
128
|
+
errorRef.current.innerText = error !== null && error !== void 0 ? error : '';
|
|
129
|
+
};
|
|
123
130
|
const handleSubmit = async (event) => {
|
|
124
131
|
// Result
|
|
125
132
|
let result = undefined;
|
|
133
|
+
const input = inputRef.current;
|
|
126
134
|
if (this.onReturn) {
|
|
127
135
|
// Inputs case, no HTMLForm set to value, set the current form
|
|
128
136
|
if (inputs && value == null)
|
|
129
137
|
value = event.currentTarget.form;
|
|
130
|
-
const input = inputRef.current;
|
|
131
138
|
if (input) {
|
|
132
139
|
if (type === 'date') {
|
|
133
140
|
const dateValue = input.valueAsDate;
|
|
@@ -165,12 +172,21 @@ export class NotificationMU extends NotificationReact {
|
|
|
165
172
|
// Get the value
|
|
166
173
|
// returns false to prevent default dismiss
|
|
167
174
|
const v = await result;
|
|
168
|
-
if (v === false)
|
|
175
|
+
if (v === false) {
|
|
176
|
+
input === null || input === void 0 ? void 0 : input.focus();
|
|
169
177
|
return;
|
|
178
|
+
}
|
|
179
|
+
if (Array.isArray(v)) {
|
|
180
|
+
if (!v[0]) {
|
|
181
|
+
const error = v[1];
|
|
182
|
+
setError(error);
|
|
183
|
+
input === null || input === void 0 ? void 0 : input.focus();
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
}
|
|
170
187
|
this.dismiss();
|
|
171
188
|
};
|
|
172
189
|
let localInputs;
|
|
173
|
-
let inputRef = React.createRef();
|
|
174
190
|
let value = undefined;
|
|
175
191
|
if (inputs == null) {
|
|
176
192
|
if (type === 'switch') {
|
|
@@ -180,7 +196,7 @@ export class NotificationMU extends NotificationReact {
|
|
|
180
196
|
localInputs = React.createElement(Slider, { onChange: (_e, v) => (value = v) });
|
|
181
197
|
}
|
|
182
198
|
else {
|
|
183
|
-
localInputs = (React.createElement(TextField, { inputRef: inputRef, autoFocus: true, margin: "dense", fullWidth: true, type: type, required: true, ...rest }));
|
|
199
|
+
localInputs = (React.createElement(TextField, { inputRef: inputRef, onChange: () => setError(undefined), autoFocus: true, margin: "dense", fullWidth: true, type: type, required: true, ...rest }));
|
|
184
200
|
}
|
|
185
201
|
}
|
|
186
202
|
else {
|
|
@@ -193,7 +209,8 @@ export class NotificationMU extends NotificationReact {
|
|
|
193
209
|
React.createElement("span", { className: "dialogTitle" }, title)),
|
|
194
210
|
React.createElement(DialogContent, null,
|
|
195
211
|
React.createElement(DialogContentText, null, this.content),
|
|
196
|
-
localInputs
|
|
212
|
+
localInputs,
|
|
213
|
+
React.createElement(Typography, { variant: "caption", display: "block", ref: errorRef, color: (theme) => theme.palette.error.main })),
|
|
197
214
|
React.createElement(DialogActions, null,
|
|
198
215
|
React.createElement(Button, { color: "secondary", onClick: () => {
|
|
199
216
|
if (this.onReturn)
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@etsoo/react",
|
|
3
|
-
"version": "1.4.
|
|
3
|
+
"version": "1.4.1",
|
|
4
4
|
"description": "TypeScript ReactJs framework",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"types": "lib/index.d.ts",
|
|
@@ -50,8 +50,8 @@
|
|
|
50
50
|
"@emotion/react": "^11.7.1",
|
|
51
51
|
"@emotion/style": "^0.8.0",
|
|
52
52
|
"@emotion/styled": "^11.6.0",
|
|
53
|
-
"@etsoo/appscript": "^1.2.
|
|
54
|
-
"@etsoo/notificationbase": "^1.0.
|
|
53
|
+
"@etsoo/appscript": "^1.2.12",
|
|
54
|
+
"@etsoo/notificationbase": "^1.0.96",
|
|
55
55
|
"@etsoo/shared": "^1.0.97",
|
|
56
56
|
"@mui/icons-material": "^5.2.5",
|
|
57
57
|
"@mui/material": "^5.2.6",
|
|
@@ -76,12 +76,12 @@
|
|
|
76
76
|
"react-window": "^1.8.6"
|
|
77
77
|
},
|
|
78
78
|
"devDependencies": {
|
|
79
|
-
"@babel/cli": "^7.16.
|
|
80
|
-
"@babel/core": "^7.16.
|
|
81
|
-
"@babel/plugin-transform-runtime": "^7.16.
|
|
82
|
-
"@babel/preset-env": "^7.16.
|
|
83
|
-
"@babel/runtime-corejs3": "^7.16.
|
|
84
|
-
"@types/jest": "^27.0
|
|
79
|
+
"@babel/cli": "^7.16.7",
|
|
80
|
+
"@babel/core": "^7.16.7",
|
|
81
|
+
"@babel/plugin-transform-runtime": "^7.16.7",
|
|
82
|
+
"@babel/preset-env": "^7.16.7",
|
|
83
|
+
"@babel/runtime-corejs3": "^7.16.7",
|
|
84
|
+
"@types/jest": "^27.4.0",
|
|
85
85
|
"@types/react-test-renderer": "^17.0.1",
|
|
86
86
|
"@typescript-eslint/eslint-plugin": "^5.8.1",
|
|
87
87
|
"@typescript-eslint/parser": "^5.8.1",
|
package/src/mu/NotifierMU.tsx
CHANGED
|
@@ -25,7 +25,8 @@ import {
|
|
|
25
25
|
Snackbar,
|
|
26
26
|
styled,
|
|
27
27
|
Switch,
|
|
28
|
-
TextField
|
|
28
|
+
TextField,
|
|
29
|
+
Typography
|
|
29
30
|
} from '@mui/material';
|
|
30
31
|
import { Error, Info, Help, Warning, Done } from '@mui/icons-material';
|
|
31
32
|
import React from 'react';
|
|
@@ -238,18 +239,31 @@ export class NotificationMU extends NotificationReact {
|
|
|
238
239
|
...rest
|
|
239
240
|
} = this.inputProps ?? {};
|
|
240
241
|
|
|
242
|
+
const inputRef = React.createRef<HTMLInputElement>();
|
|
243
|
+
const errorRef = React.createRef<HTMLSpanElement>();
|
|
244
|
+
|
|
245
|
+
const setError = (error?: string) => {
|
|
246
|
+
if (errorRef.current == null) return;
|
|
247
|
+
errorRef.current.innerText = error ?? '';
|
|
248
|
+
};
|
|
249
|
+
|
|
241
250
|
const handleSubmit = async (
|
|
242
251
|
event: React.MouseEvent<HTMLButtonElement>
|
|
243
252
|
) => {
|
|
244
253
|
// Result
|
|
245
|
-
let result:
|
|
254
|
+
let result:
|
|
255
|
+
| boolean
|
|
256
|
+
| [boolean, string | undefined]
|
|
257
|
+
| void
|
|
258
|
+
| PromiseLike<boolean | [boolean, string | undefined] | void> =
|
|
246
259
|
undefined;
|
|
247
260
|
|
|
261
|
+
const input = inputRef.current;
|
|
262
|
+
|
|
248
263
|
if (this.onReturn) {
|
|
249
264
|
// Inputs case, no HTMLForm set to value, set the current form
|
|
250
265
|
if (inputs && value == null) value = event.currentTarget.form;
|
|
251
266
|
|
|
252
|
-
const input = inputRef.current;
|
|
253
267
|
if (input) {
|
|
254
268
|
if (type === 'date') {
|
|
255
269
|
const dateValue = input.valueAsDate;
|
|
@@ -284,13 +298,23 @@ export class NotificationMU extends NotificationReact {
|
|
|
284
298
|
// Get the value
|
|
285
299
|
// returns false to prevent default dismiss
|
|
286
300
|
const v = await result;
|
|
287
|
-
if (v === false)
|
|
301
|
+
if (v === false) {
|
|
302
|
+
input?.focus();
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
if (Array.isArray(v)) {
|
|
306
|
+
if (!v[0]) {
|
|
307
|
+
const error = v[1];
|
|
308
|
+
setError(error);
|
|
309
|
+
input?.focus();
|
|
310
|
+
return;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
288
313
|
|
|
289
314
|
this.dismiss();
|
|
290
315
|
};
|
|
291
316
|
|
|
292
317
|
let localInputs: React.ReactNode;
|
|
293
|
-
let inputRef = React.createRef<HTMLInputElement>();
|
|
294
318
|
let value: any = undefined;
|
|
295
319
|
|
|
296
320
|
if (inputs == null) {
|
|
@@ -310,6 +334,7 @@ export class NotificationMU extends NotificationReact {
|
|
|
310
334
|
localInputs = (
|
|
311
335
|
<TextField
|
|
312
336
|
inputRef={inputRef}
|
|
337
|
+
onChange={() => setError(undefined)}
|
|
313
338
|
autoFocus
|
|
314
339
|
margin="dense"
|
|
315
340
|
fullWidth
|
|
@@ -341,6 +366,12 @@ export class NotificationMU extends NotificationReact {
|
|
|
341
366
|
<DialogContent>
|
|
342
367
|
<DialogContentText>{this.content}</DialogContentText>
|
|
343
368
|
{localInputs}
|
|
369
|
+
<Typography
|
|
370
|
+
variant="caption"
|
|
371
|
+
display="block"
|
|
372
|
+
ref={errorRef}
|
|
373
|
+
color={(theme) => theme.palette.error.main}
|
|
374
|
+
/>
|
|
344
375
|
</DialogContent>
|
|
345
376
|
<DialogActions>
|
|
346
377
|
<Button
|