@etsoo/materialui 1.1.7 → 1.1.9
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/DnDList.js +31 -11
- package/lib/NotifierMU.d.ts +3 -3
- package/lib/NotifierMU.js +68 -55
- package/package.json +4 -4
- package/src/DnDList.tsx +62 -25
- package/src/NotifierMU.tsx +645 -613
package/src/NotifierMU.tsx
CHANGED
|
@@ -1,54 +1,61 @@
|
|
|
1
1
|
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
} from
|
|
7
|
-
import { DataTypes, DomUtils } from
|
|
2
|
+
NotificationAlign,
|
|
3
|
+
NotificationMessageType,
|
|
4
|
+
NotificationRenderProps,
|
|
5
|
+
NotificationType
|
|
6
|
+
} from "@etsoo/notificationbase";
|
|
7
|
+
import { DataTypes, DomUtils } from "@etsoo/shared";
|
|
8
8
|
import {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
import
|
|
9
|
+
Alert,
|
|
10
|
+
AlertColor,
|
|
11
|
+
AlertProps,
|
|
12
|
+
AlertTitle,
|
|
13
|
+
Backdrop,
|
|
14
|
+
Box,
|
|
15
|
+
Button,
|
|
16
|
+
CircularProgress,
|
|
17
|
+
CircularProgressProps,
|
|
18
|
+
Dialog,
|
|
19
|
+
DialogActions,
|
|
20
|
+
DialogContent,
|
|
21
|
+
DialogContentText,
|
|
22
|
+
DialogTitle,
|
|
23
|
+
Fade,
|
|
24
|
+
IconButton,
|
|
25
|
+
Slider,
|
|
26
|
+
Snackbar,
|
|
27
|
+
styled,
|
|
28
|
+
Switch,
|
|
29
|
+
TextField,
|
|
30
|
+
Typography
|
|
31
|
+
} from "@mui/material";
|
|
32
|
+
import { Error, Info, Help, Warning, Done } from "@mui/icons-material";
|
|
33
|
+
import CloseIcon from "@mui/icons-material/Close";
|
|
34
|
+
import React from "react";
|
|
33
35
|
import {
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
} from
|
|
39
|
-
import { DraggablePaperComponent } from
|
|
40
|
-
import { LoadingButton, LoadingButtonProps } from
|
|
41
|
-
import { Labels } from
|
|
36
|
+
INotificationBaseReact,
|
|
37
|
+
INotificationReact,
|
|
38
|
+
NotificationReact,
|
|
39
|
+
NotifierReact
|
|
40
|
+
} from "@etsoo/react";
|
|
41
|
+
import { DraggablePaperComponent } from "./DraggablePaperComponent";
|
|
42
|
+
import { LoadingButton, LoadingButtonProps } from "./LoadingButton";
|
|
43
|
+
import { Labels } from "./app/Labels";
|
|
42
44
|
|
|
43
45
|
// Custom icon dialog title bar
|
|
44
46
|
const IconDialogTitle = styled(DialogTitle)`
|
|
45
|
-
|
|
47
|
+
${({ theme }) => `
|
|
46
48
|
cursor: move;
|
|
47
49
|
display: flex;
|
|
48
50
|
align-items: center;
|
|
49
51
|
& .dialogTitle {
|
|
50
52
|
font-weight: bold;
|
|
51
53
|
font-size: 1.17em;
|
|
54
|
+
flex-grow: 3;
|
|
55
|
+
text-overflow: ellipsis;
|
|
56
|
+
padding-left: ${theme.spacing(1)};
|
|
57
|
+
}
|
|
58
|
+
& .closeButton {
|
|
52
59
|
padding-left: ${theme.spacing(1)};
|
|
53
60
|
}
|
|
54
61
|
`}
|
|
@@ -58,617 +65,642 @@ const IconDialogTitle = styled(DialogTitle)`
|
|
|
58
65
|
* MU notification
|
|
59
66
|
*/
|
|
60
67
|
export class NotificationMU extends NotificationReact {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
const setupProps: LoadingButtonProps = {
|
|
92
|
-
color: 'primary'
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
// Setup callback
|
|
96
|
-
if (this.renderSetup) this.renderSetup(setupProps);
|
|
97
|
-
|
|
98
|
-
// Callback
|
|
99
|
-
const callback = async (
|
|
100
|
-
_event: React.MouseEvent<HTMLButtonElement>
|
|
101
|
-
) => {
|
|
102
|
-
await this.returnValue(undefined);
|
|
103
|
-
return true;
|
|
104
|
-
};
|
|
105
|
-
|
|
106
|
-
return (
|
|
107
|
-
<Dialog
|
|
108
|
-
key={this.id}
|
|
109
|
-
open={this.open}
|
|
110
|
-
PaperComponent={DraggablePaperComponent}
|
|
111
|
-
className={className}
|
|
112
|
-
fullWidth={fullWidth}
|
|
113
|
-
maxWidth={maxWidth}
|
|
114
|
-
fullScreen={fullScreen}
|
|
115
|
-
>
|
|
116
|
-
<IconDialogTitle className="draggable-dialog-title">
|
|
117
|
-
{icon}
|
|
118
|
-
<span className="dialogTitle">{title}</span>
|
|
119
|
-
</IconDialogTitle>
|
|
120
|
-
<DialogContent>
|
|
121
|
-
<DialogContentText>{this.content}</DialogContentText>
|
|
122
|
-
{inputs}
|
|
123
|
-
</DialogContent>
|
|
124
|
-
<DialogActions>
|
|
125
|
-
{buttons ? (
|
|
126
|
-
buttons(this, callback)
|
|
127
|
-
) : (
|
|
128
|
-
<LoadingButton
|
|
129
|
-
{...setupProps}
|
|
130
|
-
onClick={callback}
|
|
131
|
-
autoFocus
|
|
132
|
-
{...primaryButton}
|
|
133
|
-
>
|
|
134
|
-
{okLabel}
|
|
135
|
-
</LoadingButton>
|
|
136
|
-
)}
|
|
137
|
-
</DialogActions>
|
|
138
|
-
</Dialog>
|
|
139
|
-
);
|
|
68
|
+
// Create alert
|
|
69
|
+
private createAlert(_props: NotificationRenderProps, className?: string) {
|
|
70
|
+
const labels = Labels.NotificationMU;
|
|
71
|
+
|
|
72
|
+
const {
|
|
73
|
+
buttons,
|
|
74
|
+
inputs,
|
|
75
|
+
fullScreen,
|
|
76
|
+
fullWidth = true,
|
|
77
|
+
maxWidth,
|
|
78
|
+
okLabel = labels.alertOK,
|
|
79
|
+
primaryButton,
|
|
80
|
+
closable = false
|
|
81
|
+
} = this.inputProps ?? {};
|
|
82
|
+
|
|
83
|
+
let title = this.title;
|
|
84
|
+
let icon: React.ReactNode;
|
|
85
|
+
if (this.type === NotificationMessageType.Success) {
|
|
86
|
+
icon = <Done color="primary" />;
|
|
87
|
+
title ??= labels.success;
|
|
88
|
+
} else if (this.type === NotificationMessageType.Info) {
|
|
89
|
+
icon = <Info />;
|
|
90
|
+
title ??= labels.info;
|
|
91
|
+
} else if (this.type === NotificationMessageType.Warning) {
|
|
92
|
+
icon = <Warning color="secondary" />;
|
|
93
|
+
title ??= labels.warning;
|
|
94
|
+
} else {
|
|
95
|
+
icon = <Error color="error" />;
|
|
96
|
+
title ??= labels.alertTitle;
|
|
140
97
|
}
|
|
141
98
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
const title = this.title ?? labels.confirmTitle;
|
|
146
|
-
|
|
147
|
-
const {
|
|
148
|
-
buttons,
|
|
149
|
-
okLabel = labels.confirmYes,
|
|
150
|
-
cancelLabel = labels.confirmNo,
|
|
151
|
-
cancelButton = true,
|
|
152
|
-
inputs,
|
|
153
|
-
fullScreen,
|
|
154
|
-
fullWidth = true,
|
|
155
|
-
maxWidth,
|
|
156
|
-
primaryButton
|
|
157
|
-
} = this.inputProps ?? {};
|
|
158
|
-
|
|
159
|
-
const callback = async (
|
|
160
|
-
_event: React.MouseEvent<HTMLButtonElement>,
|
|
161
|
-
value: boolean
|
|
162
|
-
) => {
|
|
163
|
-
await this.returnValue(value);
|
|
164
|
-
return true;
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
return (
|
|
168
|
-
<Dialog
|
|
169
|
-
key={this.id}
|
|
170
|
-
open={this.open}
|
|
171
|
-
PaperComponent={DraggablePaperComponent}
|
|
172
|
-
className={className}
|
|
173
|
-
fullWidth={fullWidth}
|
|
174
|
-
maxWidth={maxWidth}
|
|
175
|
-
fullScreen={fullScreen}
|
|
176
|
-
>
|
|
177
|
-
<IconDialogTitle className="draggable-dialog-title">
|
|
178
|
-
<Help color="action" />
|
|
179
|
-
<span className="dialogTitle">{title}</span>
|
|
180
|
-
</IconDialogTitle>
|
|
181
|
-
<DialogContent>
|
|
182
|
-
<DialogContentText>{this.content}</DialogContentText>
|
|
183
|
-
{inputs}
|
|
184
|
-
</DialogContent>
|
|
185
|
-
<DialogActions>
|
|
186
|
-
{buttons ? (
|
|
187
|
-
buttons(this, callback)
|
|
188
|
-
) : (
|
|
189
|
-
<React.Fragment>
|
|
190
|
-
{cancelButton && (
|
|
191
|
-
<LoadingButton
|
|
192
|
-
color="secondary"
|
|
193
|
-
onClick={async (event) =>
|
|
194
|
-
await callback(event, false)
|
|
195
|
-
}
|
|
196
|
-
>
|
|
197
|
-
{cancelLabel}
|
|
198
|
-
</LoadingButton>
|
|
199
|
-
)}
|
|
200
|
-
<LoadingButton
|
|
201
|
-
color="primary"
|
|
202
|
-
onClick={async (event) =>
|
|
203
|
-
await callback(event, true)
|
|
204
|
-
}
|
|
205
|
-
autoFocus
|
|
206
|
-
{...primaryButton}
|
|
207
|
-
>
|
|
208
|
-
{okLabel}
|
|
209
|
-
</LoadingButton>
|
|
210
|
-
</React.Fragment>
|
|
211
|
-
)}
|
|
212
|
-
</DialogActions>
|
|
213
|
-
</Dialog>
|
|
214
|
-
);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
private createMessageColor(): AlertColor {
|
|
218
|
-
if (this.type === NotificationMessageType.Danger) return 'error';
|
|
219
|
-
if (this.type === NotificationMessageType.Success) return 'success';
|
|
220
|
-
if (this.type === NotificationMessageType.Warning) return 'warning';
|
|
221
|
-
return 'info';
|
|
222
|
-
}
|
|
99
|
+
const setupProps: LoadingButtonProps = {
|
|
100
|
+
color: "primary"
|
|
101
|
+
};
|
|
223
102
|
|
|
224
|
-
//
|
|
225
|
-
|
|
226
|
-
if (!this.open) return <React.Fragment key={this.id}></React.Fragment>;
|
|
103
|
+
// Setup callback
|
|
104
|
+
if (this.renderSetup) this.renderSetup(setupProps);
|
|
227
105
|
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
106
|
+
// Callback
|
|
107
|
+
const callback = async (_event: React.MouseEvent<HTMLButtonElement>) => {
|
|
108
|
+
await this.returnValue(undefined);
|
|
109
|
+
return true;
|
|
110
|
+
};
|
|
232
111
|
|
|
233
|
-
|
|
234
|
-
|
|
112
|
+
return (
|
|
113
|
+
<Dialog
|
|
114
|
+
key={this.id}
|
|
115
|
+
open={this.open}
|
|
116
|
+
PaperComponent={DraggablePaperComponent}
|
|
117
|
+
className={className}
|
|
118
|
+
fullWidth={fullWidth}
|
|
119
|
+
maxWidth={maxWidth}
|
|
120
|
+
fullScreen={fullScreen}
|
|
121
|
+
>
|
|
122
|
+
<IconDialogTitle className="draggable-dialog-title">
|
|
123
|
+
{icon}
|
|
124
|
+
<span className="dialogTitle">{title}</span>
|
|
125
|
+
{closable && (
|
|
126
|
+
<IconButton
|
|
127
|
+
className="closeButton"
|
|
128
|
+
size="small"
|
|
129
|
+
onClick={() => this.dismiss()}
|
|
130
|
+
>
|
|
131
|
+
<CloseIcon />
|
|
132
|
+
</IconButton>
|
|
133
|
+
)}
|
|
134
|
+
</IconDialogTitle>
|
|
135
|
+
<DialogContent>
|
|
136
|
+
<DialogContentText>{this.content}</DialogContentText>
|
|
137
|
+
{inputs}
|
|
138
|
+
</DialogContent>
|
|
139
|
+
<DialogActions>
|
|
140
|
+
{buttons ? (
|
|
141
|
+
buttons(this, callback)
|
|
142
|
+
) : (
|
|
143
|
+
<LoadingButton
|
|
144
|
+
{...setupProps}
|
|
145
|
+
onClick={callback}
|
|
146
|
+
autoFocus
|
|
147
|
+
{...primaryButton}
|
|
148
|
+
>
|
|
149
|
+
{okLabel}
|
|
150
|
+
</LoadingButton>
|
|
151
|
+
)}
|
|
152
|
+
</DialogActions>
|
|
153
|
+
</Dialog>
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
// Create confirm
|
|
158
|
+
private createConfirm(_props: NotificationRenderProps, className?: string) {
|
|
159
|
+
const labels = Labels.NotificationMU;
|
|
160
|
+
const title = this.title ?? labels.confirmTitle;
|
|
161
|
+
|
|
162
|
+
const {
|
|
163
|
+
buttons,
|
|
164
|
+
okLabel = labels.confirmYes,
|
|
165
|
+
cancelLabel = labels.confirmNo,
|
|
166
|
+
cancelButton = true,
|
|
167
|
+
inputs,
|
|
168
|
+
fullScreen,
|
|
169
|
+
fullWidth = true,
|
|
170
|
+
maxWidth,
|
|
171
|
+
primaryButton,
|
|
172
|
+
closable = false
|
|
173
|
+
} = this.inputProps ?? {};
|
|
174
|
+
|
|
175
|
+
const callback = async (
|
|
176
|
+
_event: React.MouseEvent<HTMLButtonElement>,
|
|
177
|
+
value: boolean
|
|
178
|
+
) => {
|
|
179
|
+
await this.returnValue(value);
|
|
180
|
+
return true;
|
|
181
|
+
};
|
|
235
182
|
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
183
|
+
return (
|
|
184
|
+
<Dialog
|
|
185
|
+
key={this.id}
|
|
186
|
+
open={this.open}
|
|
187
|
+
PaperComponent={DraggablePaperComponent}
|
|
188
|
+
className={className}
|
|
189
|
+
fullWidth={fullWidth}
|
|
190
|
+
maxWidth={maxWidth}
|
|
191
|
+
fullScreen={fullScreen}
|
|
192
|
+
>
|
|
193
|
+
<IconDialogTitle className="draggable-dialog-title">
|
|
194
|
+
<Help color="action" />
|
|
195
|
+
<span className="dialogTitle">{title}</span>
|
|
196
|
+
{closable && (
|
|
197
|
+
<IconButton
|
|
198
|
+
className="closeButton"
|
|
199
|
+
size="small"
|
|
200
|
+
onClick={() => this.dismiss()}
|
|
201
|
+
>
|
|
202
|
+
<CloseIcon />
|
|
203
|
+
</IconButton>
|
|
204
|
+
)}
|
|
205
|
+
</IconDialogTitle>
|
|
206
|
+
<DialogContent>
|
|
207
|
+
<DialogContentText>{this.content}</DialogContentText>
|
|
208
|
+
{inputs}
|
|
209
|
+
</DialogContent>
|
|
210
|
+
<DialogActions>
|
|
211
|
+
{buttons ? (
|
|
212
|
+
buttons(this, callback)
|
|
213
|
+
) : (
|
|
214
|
+
<React.Fragment>
|
|
215
|
+
{cancelButton && (
|
|
216
|
+
<LoadingButton
|
|
217
|
+
color="secondary"
|
|
218
|
+
onClick={async (event) => await callback(event, false)}
|
|
242
219
|
>
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
event: React.MouseEvent<HTMLButtonElement>
|
|
279
|
-
) => {
|
|
280
|
-
// Result
|
|
281
|
-
let result:
|
|
282
|
-
| boolean
|
|
283
|
-
| string
|
|
284
|
-
| void
|
|
285
|
-
| PromiseLike<boolean | string | void> = undefined;
|
|
286
|
-
|
|
287
|
-
const input = inputRef.current;
|
|
288
|
-
|
|
289
|
-
if (this.onReturn) {
|
|
290
|
-
// Inputs case, no HTMLForm set to value, set the current form
|
|
291
|
-
if (inputs && value == null) value = event.currentTarget.form;
|
|
292
|
-
|
|
293
|
-
if (input) {
|
|
294
|
-
if (type === 'switch') {
|
|
295
|
-
const boolValue = input.value === 'true';
|
|
296
|
-
result = this.onReturn(boolValue);
|
|
297
|
-
} else {
|
|
298
|
-
const inputValue = DomUtils.getInputValue(input);
|
|
299
|
-
if (
|
|
300
|
-
(inputValue == null || inputValue === '') &&
|
|
301
|
-
input.required
|
|
302
|
-
) {
|
|
303
|
-
input.focus();
|
|
304
|
-
return false;
|
|
305
|
-
}
|
|
306
|
-
result = this.onReturn(inputValue);
|
|
307
|
-
}
|
|
308
|
-
} else if (value != null) {
|
|
309
|
-
result = this.onReturn(value);
|
|
310
|
-
}
|
|
311
|
-
}
|
|
220
|
+
{cancelLabel}
|
|
221
|
+
</LoadingButton>
|
|
222
|
+
)}
|
|
223
|
+
<LoadingButton
|
|
224
|
+
color="primary"
|
|
225
|
+
onClick={async (event) => await callback(event, true)}
|
|
226
|
+
autoFocus
|
|
227
|
+
{...primaryButton}
|
|
228
|
+
>
|
|
229
|
+
{okLabel}
|
|
230
|
+
</LoadingButton>
|
|
231
|
+
</React.Fragment>
|
|
232
|
+
)}
|
|
233
|
+
</DialogActions>
|
|
234
|
+
</Dialog>
|
|
235
|
+
);
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
private createMessageColor(): AlertColor {
|
|
239
|
+
if (this.type === NotificationMessageType.Danger) return "error";
|
|
240
|
+
if (this.type === NotificationMessageType.Success) return "success";
|
|
241
|
+
if (this.type === NotificationMessageType.Warning) return "warning";
|
|
242
|
+
return "info";
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
// Create message
|
|
246
|
+
private createMessage(props: NotificationRenderProps, className?: string) {
|
|
247
|
+
if (!this.open) return <React.Fragment key={this.id}></React.Fragment>;
|
|
248
|
+
|
|
249
|
+
const { closable = false } = props;
|
|
250
|
+
|
|
251
|
+
const setupProps: AlertProps = {
|
|
252
|
+
severity: this.createMessageColor(),
|
|
253
|
+
variant: "filled"
|
|
254
|
+
};
|
|
312
255
|
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
256
|
+
// Setup callback
|
|
257
|
+
if (this.renderSetup) this.renderSetup(setupProps);
|
|
258
|
+
|
|
259
|
+
return (
|
|
260
|
+
<Fade in={true} key={this.id}>
|
|
261
|
+
<Alert
|
|
262
|
+
{...setupProps}
|
|
263
|
+
action={
|
|
264
|
+
closable ? (
|
|
265
|
+
<IconButton size="small" onClick={() => this.dismiss()}>
|
|
266
|
+
<CloseIcon />
|
|
267
|
+
</IconButton>
|
|
268
|
+
) : undefined
|
|
269
|
+
}
|
|
270
|
+
onClose={() => this.dismiss()} // dismiss will trigger the onReturn callback
|
|
271
|
+
className={className}
|
|
272
|
+
>
|
|
273
|
+
{this.title && <AlertTitle>{this.title}</AlertTitle>}
|
|
274
|
+
{this.content}
|
|
275
|
+
</Alert>
|
|
276
|
+
</Fade>
|
|
277
|
+
);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// Create prompt
|
|
281
|
+
private createPrompt(_props: NotificationRenderProps, className?: string) {
|
|
282
|
+
const labels = Labels.NotificationMU;
|
|
283
|
+
const title = this.title ?? labels.promptTitle;
|
|
284
|
+
|
|
285
|
+
const {
|
|
286
|
+
buttons,
|
|
287
|
+
cancelLabel = labels.promptCancel,
|
|
288
|
+
okLabel = labels.promptOK,
|
|
289
|
+
cancelButton = true,
|
|
290
|
+
inputs,
|
|
291
|
+
type,
|
|
292
|
+
fullScreen,
|
|
293
|
+
fullWidth = true,
|
|
294
|
+
maxWidth,
|
|
295
|
+
primaryButton,
|
|
296
|
+
inputProps,
|
|
297
|
+
closable = false
|
|
298
|
+
} = this.inputProps ?? {};
|
|
299
|
+
|
|
300
|
+
const inputRef = React.createRef<HTMLInputElement>();
|
|
301
|
+
const errorRef = React.createRef<HTMLSpanElement>();
|
|
302
|
+
|
|
303
|
+
const setError = (error?: string) => {
|
|
304
|
+
if (errorRef.current == null) return;
|
|
305
|
+
errorRef.current.innerText = error ?? "";
|
|
306
|
+
};
|
|
325
307
|
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
inputRef={inputRef}
|
|
350
|
-
onChange={() => setError(undefined)}
|
|
351
|
-
autoFocus
|
|
352
|
-
margin="dense"
|
|
353
|
-
fullWidth
|
|
354
|
-
type={type}
|
|
355
|
-
required
|
|
356
|
-
{...inputProps}
|
|
357
|
-
/>
|
|
358
|
-
);
|
|
308
|
+
const handleSubmit = async (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
309
|
+
// Result
|
|
310
|
+
let result:
|
|
311
|
+
| boolean
|
|
312
|
+
| string
|
|
313
|
+
| void
|
|
314
|
+
| PromiseLike<boolean | string | void> = undefined;
|
|
315
|
+
|
|
316
|
+
const input = inputRef.current;
|
|
317
|
+
|
|
318
|
+
if (this.onReturn) {
|
|
319
|
+
// Inputs case, no HTMLForm set to value, set the current form
|
|
320
|
+
if (inputs && value == null) value = event.currentTarget.form;
|
|
321
|
+
|
|
322
|
+
if (input) {
|
|
323
|
+
if (type === "switch") {
|
|
324
|
+
const boolValue = input.value === "true";
|
|
325
|
+
result = this.onReturn(boolValue);
|
|
326
|
+
} else {
|
|
327
|
+
const inputValue = DomUtils.getInputValue(input);
|
|
328
|
+
if ((inputValue == null || inputValue === "") && input.required) {
|
|
329
|
+
input.focus();
|
|
330
|
+
return false;
|
|
359
331
|
}
|
|
360
|
-
|
|
361
|
-
|
|
332
|
+
result = this.onReturn(inputValue);
|
|
333
|
+
}
|
|
334
|
+
} else if (value != null) {
|
|
335
|
+
result = this.onReturn(value);
|
|
362
336
|
}
|
|
337
|
+
}
|
|
338
|
+
|
|
339
|
+
// Get the value
|
|
340
|
+
// returns false to prevent default dismiss
|
|
341
|
+
const v = await result;
|
|
342
|
+
if (v === false) {
|
|
343
|
+
input?.focus();
|
|
344
|
+
return false;
|
|
345
|
+
}
|
|
346
|
+
if (typeof v === "string") {
|
|
347
|
+
setError(v);
|
|
348
|
+
input?.focus();
|
|
349
|
+
return false;
|
|
350
|
+
}
|
|
351
|
+
|
|
352
|
+
this.dismiss();
|
|
353
|
+
return true;
|
|
354
|
+
};
|
|
363
355
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
(
|
|
378
|
-
event.currentTarget.elements.namedItem(
|
|
379
|
-
'okButton'
|
|
380
|
-
) as HTMLButtonElement
|
|
381
|
-
)?.click();
|
|
382
|
-
return false;
|
|
383
|
-
}}
|
|
384
|
-
>
|
|
385
|
-
<IconDialogTitle className="draggable-dialog-title">
|
|
386
|
-
<Info color="primary" />
|
|
387
|
-
<span className="dialogTitle">{title}</span>
|
|
388
|
-
</IconDialogTitle>
|
|
389
|
-
<DialogContent>
|
|
390
|
-
<DialogContentText>{this.content}</DialogContentText>
|
|
391
|
-
{localInputs}
|
|
392
|
-
<Typography
|
|
393
|
-
variant="caption"
|
|
394
|
-
display="block"
|
|
395
|
-
ref={errorRef}
|
|
396
|
-
color={(theme) => theme.palette.error.main}
|
|
397
|
-
/>
|
|
398
|
-
</DialogContent>
|
|
399
|
-
<DialogActions>
|
|
400
|
-
{buttons ? (
|
|
401
|
-
buttons(this, handleSubmit)
|
|
402
|
-
) : (
|
|
403
|
-
<React.Fragment>
|
|
404
|
-
{cancelButton && (
|
|
405
|
-
<Button
|
|
406
|
-
color="secondary"
|
|
407
|
-
onClick={() => {
|
|
408
|
-
if (this.onReturn)
|
|
409
|
-
this.onReturn(undefined);
|
|
410
|
-
this.dismiss();
|
|
411
|
-
}}
|
|
412
|
-
>
|
|
413
|
-
{cancelLabel}
|
|
414
|
-
</Button>
|
|
415
|
-
)}
|
|
416
|
-
<LoadingButton
|
|
417
|
-
color="primary"
|
|
418
|
-
autoFocus
|
|
419
|
-
onClick={handleSubmit}
|
|
420
|
-
name="okButton"
|
|
421
|
-
{...primaryButton}
|
|
422
|
-
>
|
|
423
|
-
{okLabel}
|
|
424
|
-
</LoadingButton>
|
|
425
|
-
</React.Fragment>
|
|
426
|
-
)}
|
|
427
|
-
</DialogActions>
|
|
428
|
-
</form>
|
|
429
|
-
</Dialog>
|
|
356
|
+
let localInputs: React.ReactNode;
|
|
357
|
+
let value: any = undefined;
|
|
358
|
+
|
|
359
|
+
if (inputs == null) {
|
|
360
|
+
if (type === "switch") {
|
|
361
|
+
localInputs = (
|
|
362
|
+
<Switch
|
|
363
|
+
inputRef={inputRef}
|
|
364
|
+
{...inputProps}
|
|
365
|
+
value="true"
|
|
366
|
+
autoFocus
|
|
367
|
+
required
|
|
368
|
+
/>
|
|
430
369
|
);
|
|
370
|
+
} else if (type === "slider") {
|
|
371
|
+
localInputs = <Slider onChange={(_e, v) => (value = v)} />;
|
|
372
|
+
} else {
|
|
373
|
+
localInputs = (
|
|
374
|
+
<TextField
|
|
375
|
+
inputRef={inputRef}
|
|
376
|
+
onChange={() => setError(undefined)}
|
|
377
|
+
autoFocus
|
|
378
|
+
margin="dense"
|
|
379
|
+
fullWidth
|
|
380
|
+
type={type}
|
|
381
|
+
required
|
|
382
|
+
{...inputProps}
|
|
383
|
+
/>
|
|
384
|
+
);
|
|
385
|
+
}
|
|
386
|
+
} else {
|
|
387
|
+
localInputs = inputs;
|
|
431
388
|
}
|
|
432
389
|
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
390
|
+
return (
|
|
391
|
+
<Dialog
|
|
392
|
+
key={this.id}
|
|
393
|
+
open={this.open}
|
|
394
|
+
PaperComponent={DraggablePaperComponent}
|
|
395
|
+
className={className}
|
|
396
|
+
fullWidth={fullWidth}
|
|
397
|
+
maxWidth={maxWidth}
|
|
398
|
+
fullScreen={fullScreen}
|
|
399
|
+
>
|
|
400
|
+
<form
|
|
401
|
+
onSubmit={(event) => {
|
|
402
|
+
event.preventDefault();
|
|
403
|
+
(
|
|
404
|
+
event.currentTarget.elements.namedItem(
|
|
405
|
+
"okButton"
|
|
406
|
+
) as HTMLButtonElement
|
|
407
|
+
)?.click();
|
|
408
|
+
return false;
|
|
409
|
+
}}
|
|
410
|
+
>
|
|
411
|
+
<IconDialogTitle className="draggable-dialog-title">
|
|
412
|
+
<Info color="primary" />
|
|
413
|
+
<span className="dialogTitle">{title}</span>
|
|
414
|
+
{closable && (
|
|
415
|
+
<IconButton
|
|
416
|
+
className="closeButton"
|
|
417
|
+
size="small"
|
|
418
|
+
onClick={() => this.dismiss()}
|
|
419
|
+
>
|
|
420
|
+
<CloseIcon />
|
|
421
|
+
</IconButton>
|
|
422
|
+
)}
|
|
423
|
+
</IconDialogTitle>
|
|
424
|
+
<DialogContent>
|
|
425
|
+
<DialogContentText>{this.content}</DialogContentText>
|
|
426
|
+
{localInputs}
|
|
427
|
+
<Typography
|
|
428
|
+
variant="caption"
|
|
429
|
+
display="block"
|
|
430
|
+
ref={errorRef}
|
|
431
|
+
color={(theme) => theme.palette.error.main}
|
|
432
|
+
/>
|
|
433
|
+
</DialogContent>
|
|
434
|
+
<DialogActions>
|
|
435
|
+
{buttons ? (
|
|
436
|
+
buttons(this, handleSubmit)
|
|
437
|
+
) : (
|
|
438
|
+
<React.Fragment>
|
|
439
|
+
{cancelButton && (
|
|
440
|
+
<Button
|
|
441
|
+
color="secondary"
|
|
442
|
+
onClick={() => {
|
|
443
|
+
if (this.onReturn) this.onReturn(undefined);
|
|
444
|
+
this.dismiss();
|
|
469
445
|
}}
|
|
446
|
+
>
|
|
447
|
+
{cancelLabel}
|
|
448
|
+
</Button>
|
|
449
|
+
)}
|
|
450
|
+
<LoadingButton
|
|
451
|
+
color="primary"
|
|
452
|
+
autoFocus
|
|
453
|
+
onClick={handleSubmit}
|
|
454
|
+
name="okButton"
|
|
455
|
+
{...primaryButton}
|
|
470
456
|
>
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
}
|
|
457
|
+
{okLabel}
|
|
458
|
+
</LoadingButton>
|
|
459
|
+
</React.Fragment>
|
|
460
|
+
)}
|
|
461
|
+
</DialogActions>
|
|
462
|
+
</form>
|
|
463
|
+
</Dialog>
|
|
464
|
+
);
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
// Create loading
|
|
468
|
+
private createLoading(_props: NotificationRenderProps, className?: string) {
|
|
469
|
+
// Properties
|
|
470
|
+
const setupProps: CircularProgressProps = { color: "primary" };
|
|
471
|
+
|
|
472
|
+
const labels = Labels.NotificationMU;
|
|
473
|
+
|
|
474
|
+
// Input props
|
|
475
|
+
const { maxWidth = "xs" } = this.inputProps ?? {};
|
|
476
|
+
|
|
477
|
+
// Content
|
|
478
|
+
let content = this.content;
|
|
479
|
+
if (content === "@") content = labels.loading.toString();
|
|
480
|
+
|
|
481
|
+
// Setup callback
|
|
482
|
+
if (this.renderSetup) this.renderSetup(setupProps);
|
|
483
|
+
|
|
484
|
+
return (
|
|
485
|
+
<Backdrop
|
|
486
|
+
key={this.id}
|
|
487
|
+
className={className}
|
|
488
|
+
sx={{
|
|
489
|
+
color: "#fff",
|
|
490
|
+
zIndex: (theme) => theme.zIndex.modal + 1
|
|
491
|
+
}}
|
|
492
|
+
open={this.open}
|
|
493
|
+
>
|
|
494
|
+
<Box
|
|
495
|
+
display="flex"
|
|
496
|
+
flexDirection="column"
|
|
497
|
+
flexWrap="nowrap"
|
|
498
|
+
alignItems="center"
|
|
499
|
+
sx={{
|
|
500
|
+
"& > :not(style) + :not(style)": {
|
|
501
|
+
marginTop: (theme) => theme.spacing(1)
|
|
502
|
+
}
|
|
503
|
+
}}
|
|
504
|
+
>
|
|
505
|
+
<CircularProgress {...setupProps} />
|
|
506
|
+
{content && (
|
|
507
|
+
<Box maxWidth={maxWidth === false ? undefined : maxWidth}>
|
|
508
|
+
{content}
|
|
509
|
+
</Box>
|
|
510
|
+
)}
|
|
511
|
+
</Box>
|
|
512
|
+
</Backdrop>
|
|
513
|
+
);
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
/**
|
|
517
|
+
* Render method
|
|
518
|
+
* @param props Props
|
|
519
|
+
* @param className Style class name
|
|
520
|
+
* @param classes Style classes
|
|
521
|
+
*/
|
|
522
|
+
render(props: NotificationRenderProps, className?: string) {
|
|
523
|
+
// Loading bar
|
|
524
|
+
if (this.type === NotificationType.Loading) {
|
|
525
|
+
return this.createLoading(props, className);
|
|
526
|
+
} else if (this.type === NotificationType.Confirm) {
|
|
527
|
+
return this.createConfirm(props, className);
|
|
528
|
+
} else if (this.type === NotificationType.Prompt) {
|
|
529
|
+
return this.createPrompt(props, className);
|
|
530
|
+
} else if (
|
|
531
|
+
this.type === NotificationType.Error ||
|
|
532
|
+
(this.modal && this.type in NotificationMessageType)
|
|
533
|
+
) {
|
|
534
|
+
// Alert or modal message
|
|
535
|
+
return this.createAlert(props, className);
|
|
536
|
+
} else {
|
|
537
|
+
return this.createMessage(props, className);
|
|
507
538
|
}
|
|
539
|
+
}
|
|
508
540
|
}
|
|
509
541
|
|
|
510
542
|
// Origin constructor generics
|
|
511
543
|
interface origin {
|
|
512
|
-
|
|
513
|
-
|
|
544
|
+
vertical: "top" | "bottom";
|
|
545
|
+
horizontal: DataTypes.HAlign;
|
|
514
546
|
}
|
|
515
547
|
|
|
516
548
|
/**
|
|
517
549
|
* Antd notifier
|
|
518
550
|
*/
|
|
519
551
|
export class NotifierMU extends NotifierReact {
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
552
|
+
/**
|
|
553
|
+
* Create state and return provider
|
|
554
|
+
* @param className Style class name
|
|
555
|
+
* @returns Provider
|
|
556
|
+
*/
|
|
557
|
+
static setup(className = "notifier-mu") {
|
|
558
|
+
// Create an instance
|
|
559
|
+
const instance = new NotifierMU();
|
|
560
|
+
const provider = instance.createProvider(className);
|
|
561
|
+
NotifierReact.updateInstance(instance);
|
|
562
|
+
return provider;
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
// Calculate origin from align property
|
|
566
|
+
private static getOrigin(align: NotificationAlign): origin | undefined {
|
|
567
|
+
if (align === NotificationAlign.TopLeft) {
|
|
568
|
+
return {
|
|
569
|
+
horizontal: "left",
|
|
570
|
+
vertical: "top"
|
|
571
|
+
};
|
|
531
572
|
}
|
|
532
573
|
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
};
|
|
540
|
-
}
|
|
541
|
-
|
|
542
|
-
if (align === NotificationAlign.TopCenter) {
|
|
543
|
-
return {
|
|
544
|
-
horizontal: 'center',
|
|
545
|
-
vertical: 'top'
|
|
546
|
-
};
|
|
547
|
-
}
|
|
548
|
-
|
|
549
|
-
if (align === NotificationAlign.TopRight) {
|
|
550
|
-
return {
|
|
551
|
-
horizontal: 'right',
|
|
552
|
-
vertical: 'top'
|
|
553
|
-
};
|
|
554
|
-
}
|
|
555
|
-
|
|
556
|
-
if (align === NotificationAlign.BottomLeft) {
|
|
557
|
-
return {
|
|
558
|
-
horizontal: 'left',
|
|
559
|
-
vertical: 'bottom'
|
|
560
|
-
};
|
|
561
|
-
}
|
|
562
|
-
|
|
563
|
-
if (align === NotificationAlign.BottomCenter) {
|
|
564
|
-
return {
|
|
565
|
-
horizontal: 'center',
|
|
566
|
-
vertical: 'bottom'
|
|
567
|
-
};
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
if (align === NotificationAlign.BottomRight) {
|
|
571
|
-
return {
|
|
572
|
-
horizontal: 'right',
|
|
573
|
-
vertical: 'bottom'
|
|
574
|
-
};
|
|
575
|
-
}
|
|
574
|
+
if (align === NotificationAlign.TopCenter) {
|
|
575
|
+
return {
|
|
576
|
+
horizontal: "center",
|
|
577
|
+
vertical: "top"
|
|
578
|
+
};
|
|
579
|
+
}
|
|
576
580
|
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
+
if (align === NotificationAlign.TopRight) {
|
|
582
|
+
return {
|
|
583
|
+
horizontal: "right",
|
|
584
|
+
vertical: "top"
|
|
585
|
+
};
|
|
581
586
|
}
|
|
582
587
|
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
protected createContainer = (
|
|
590
|
-
align: NotificationAlign,
|
|
591
|
-
children: React.ReactNode[]
|
|
592
|
-
) => {
|
|
593
|
-
// Each align group, class equal to something similar to 'align-topleft'
|
|
594
|
-
const alignText = NotificationAlign[align].toLowerCase();
|
|
595
|
-
let className = `align-${alignText}`;
|
|
588
|
+
if (align === NotificationAlign.BottomLeft) {
|
|
589
|
+
return {
|
|
590
|
+
horizontal: "left",
|
|
591
|
+
vertical: "bottom"
|
|
592
|
+
};
|
|
593
|
+
}
|
|
596
594
|
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
595
|
+
if (align === NotificationAlign.BottomCenter) {
|
|
596
|
+
return {
|
|
597
|
+
horizontal: "center",
|
|
598
|
+
vertical: "bottom"
|
|
599
|
+
};
|
|
600
|
+
}
|
|
600
601
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
);
|
|
608
|
-
}
|
|
602
|
+
if (align === NotificationAlign.BottomRight) {
|
|
603
|
+
return {
|
|
604
|
+
horizontal: "right",
|
|
605
|
+
vertical: "bottom"
|
|
606
|
+
};
|
|
607
|
+
}
|
|
609
608
|
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
anchorOrigin={NotifierMU.getOrigin(align)}
|
|
614
|
-
className={className}
|
|
615
|
-
key={`layout-${alignText}`}
|
|
616
|
-
sx={
|
|
617
|
-
align === NotificationAlign.Center
|
|
618
|
-
? { position: 'fixed', top: '50%!important' }
|
|
619
|
-
: undefined
|
|
620
|
-
}
|
|
621
|
-
open
|
|
622
|
-
>
|
|
623
|
-
<Box
|
|
624
|
-
display="flex"
|
|
625
|
-
flexDirection="column"
|
|
626
|
-
flexWrap="nowrap"
|
|
627
|
-
key={`box-${alignText}`}
|
|
628
|
-
sx={{
|
|
629
|
-
'& > :not(style) + :not(style)': {
|
|
630
|
-
marginTop: (theme) => theme.spacing(1)
|
|
631
|
-
}
|
|
632
|
-
}}
|
|
633
|
-
>
|
|
634
|
-
{children}
|
|
635
|
-
</Box>
|
|
636
|
-
</Snackbar>
|
|
637
|
-
);
|
|
609
|
+
return {
|
|
610
|
+
horizontal: "center",
|
|
611
|
+
vertical: "top"
|
|
638
612
|
};
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
/**
|
|
616
|
+
* Create align container
|
|
617
|
+
* @param align Align
|
|
618
|
+
* @param children Children
|
|
619
|
+
* @param options Other options
|
|
620
|
+
*/
|
|
621
|
+
protected createContainer = (
|
|
622
|
+
align: NotificationAlign,
|
|
623
|
+
children: React.ReactNode[]
|
|
624
|
+
) => {
|
|
625
|
+
// Each align group, class equal to something similar to 'align-topleft'
|
|
626
|
+
const alignText = NotificationAlign[align].toLowerCase();
|
|
627
|
+
let className = `align-${alignText}`;
|
|
628
|
+
|
|
629
|
+
if (children.length === 0) {
|
|
630
|
+
return <div key={`empty-${alignText}`} className={className} />;
|
|
631
|
+
}
|
|
639
632
|
|
|
640
|
-
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
modal?: boolean
|
|
648
|
-
): INotificationReact {
|
|
649
|
-
// Destruct
|
|
650
|
-
const {
|
|
651
|
-
type,
|
|
652
|
-
content,
|
|
653
|
-
title,
|
|
654
|
-
align,
|
|
655
|
-
timespan = modal ? 0 : undefined,
|
|
656
|
-
...rest
|
|
657
|
-
} = data;
|
|
658
|
-
|
|
659
|
-
// Setup
|
|
660
|
-
const n = new NotificationMU(type, content, title, align, timespan);
|
|
661
|
-
|
|
662
|
-
// Assign other properties
|
|
663
|
-
Object.assign(n, rest);
|
|
664
|
-
|
|
665
|
-
// Is modal
|
|
666
|
-
if (modal != null) n.modal = modal;
|
|
667
|
-
|
|
668
|
-
// Add to the collection
|
|
669
|
-
this.add(n);
|
|
670
|
-
|
|
671
|
-
// Return
|
|
672
|
-
return n;
|
|
633
|
+
if (align === NotificationAlign.Unknown) {
|
|
634
|
+
// div container for style control
|
|
635
|
+
return (
|
|
636
|
+
<div key={`div-${alignText}`} className={className}>
|
|
637
|
+
{children}
|
|
638
|
+
</div>
|
|
639
|
+
);
|
|
673
640
|
}
|
|
641
|
+
|
|
642
|
+
// Use SnackBar for layout
|
|
643
|
+
return (
|
|
644
|
+
<Snackbar
|
|
645
|
+
anchorOrigin={NotifierMU.getOrigin(align)}
|
|
646
|
+
className={className}
|
|
647
|
+
key={`layout-${alignText}`}
|
|
648
|
+
sx={
|
|
649
|
+
align === NotificationAlign.Center
|
|
650
|
+
? { position: "fixed", top: "50%!important" }
|
|
651
|
+
: undefined
|
|
652
|
+
}
|
|
653
|
+
open
|
|
654
|
+
>
|
|
655
|
+
<Box
|
|
656
|
+
display="flex"
|
|
657
|
+
flexDirection="column"
|
|
658
|
+
flexWrap="nowrap"
|
|
659
|
+
key={`box-${alignText}`}
|
|
660
|
+
sx={{
|
|
661
|
+
"& > :not(style) + :not(style)": {
|
|
662
|
+
marginTop: (theme) => theme.spacing(1)
|
|
663
|
+
}
|
|
664
|
+
}}
|
|
665
|
+
>
|
|
666
|
+
{children}
|
|
667
|
+
</Box>
|
|
668
|
+
</Snackbar>
|
|
669
|
+
);
|
|
670
|
+
};
|
|
671
|
+
|
|
672
|
+
/**
|
|
673
|
+
* Add raw definition
|
|
674
|
+
* @param data Notification data definition
|
|
675
|
+
* @param modal Show as modal
|
|
676
|
+
*/
|
|
677
|
+
protected addRaw(
|
|
678
|
+
data: INotificationBaseReact,
|
|
679
|
+
modal?: boolean
|
|
680
|
+
): INotificationReact {
|
|
681
|
+
// Destruct
|
|
682
|
+
const {
|
|
683
|
+
type,
|
|
684
|
+
content,
|
|
685
|
+
title,
|
|
686
|
+
align,
|
|
687
|
+
timespan = modal ? 0 : undefined,
|
|
688
|
+
...rest
|
|
689
|
+
} = data;
|
|
690
|
+
|
|
691
|
+
// Setup
|
|
692
|
+
const n = new NotificationMU(type, content, title, align, timespan);
|
|
693
|
+
|
|
694
|
+
// Assign other properties
|
|
695
|
+
Object.assign(n, rest);
|
|
696
|
+
|
|
697
|
+
// Is modal
|
|
698
|
+
if (modal != null) n.modal = modal;
|
|
699
|
+
|
|
700
|
+
// Add to the collection
|
|
701
|
+
this.add(n);
|
|
702
|
+
|
|
703
|
+
// Return
|
|
704
|
+
return n;
|
|
705
|
+
}
|
|
674
706
|
}
|