@etsoo/notificationbase 1.1.51 → 1.1.53
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/.github/workflows/main.yml +6 -5
- package/README.md +25 -23
- package/__tests__/Notification.ts +81 -81
- package/__tests__/tsconfig.json +15 -15
- package/babel.config.json +8 -8
- package/lib/cjs/Notification.d.ts +1 -1
- package/lib/cjs/NotificationContainer.d.ts +1 -1
- package/lib/cjs/NotificationContainer.js +1 -1
- package/lib/cjs/index.d.ts +2 -2
- package/lib/mjs/Notification.d.ts +1 -1
- package/lib/mjs/Notification.js +1 -1
- package/lib/mjs/NotificationContainer.d.ts +1 -1
- package/lib/mjs/NotificationContainer.js +2 -2
- package/lib/mjs/index.d.ts +2 -2
- package/lib/mjs/index.js +2 -2
- package/package.json +7 -7
- package/src/Notification.ts +349 -349
- package/src/NotificationContainer.ts +569 -572
- package/src/index.ts +2 -2
- package/tsconfig.cjs.json +15 -15
- package/tsconfig.json +15 -15
- package/.eslintignore +0 -3
- package/.eslintrc.json +0 -29
- package/.prettierignore +0 -5
- package/.prettierrc +0 -6
package/src/Notification.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import { DataTypes, Utils } from
|
|
1
|
+
import { DataTypes, Utils } from "@etsoo/shared";
|
|
2
2
|
|
|
3
3
|
// https://devimalplanet.com/typescript-how-to-extend-one-enum-from-another
|
|
4
4
|
// Number index keys are still there
|
|
5
5
|
const { MiddleLeft, MiddleRight, ...alignItems } = DataTypes.PlacementEnum;
|
|
6
6
|
const newItems = {
|
|
7
|
-
|
|
7
|
+
...alignItems
|
|
8
8
|
};
|
|
9
9
|
delete newItems[MiddleLeft];
|
|
10
10
|
delete newItems[MiddleRight];
|
|
@@ -13,41 +13,41 @@ delete newItems[MiddleRight];
|
|
|
13
13
|
* Display align
|
|
14
14
|
*/
|
|
15
15
|
export const NotificationAlign = {
|
|
16
|
-
|
|
16
|
+
...newItems
|
|
17
17
|
};
|
|
18
18
|
export type NotificationAlign = Exclude<
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
DataTypes.PlacementEnum,
|
|
20
|
+
DataTypes.PlacementEnum.MiddleLeft | DataTypes.PlacementEnum.MiddleRight
|
|
21
21
|
>;
|
|
22
22
|
|
|
23
23
|
/**
|
|
24
24
|
* Modal types
|
|
25
25
|
*/
|
|
26
26
|
export enum NotificationModalType {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
Loading = 0,
|
|
28
|
+
Confirm = 1,
|
|
29
|
+
Prompt = 2,
|
|
30
|
+
Error = 3, // Alert
|
|
31
|
+
Popup = 6
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
/**
|
|
35
35
|
* Message types
|
|
36
36
|
*/
|
|
37
37
|
export enum NotificationMessageType {
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
38
|
+
Default = 10, // No default then refer to Info
|
|
39
|
+
Success = 11,
|
|
40
|
+
Warning = 12,
|
|
41
|
+
Info = 13,
|
|
42
|
+
Danger = 14 // Error
|
|
43
43
|
}
|
|
44
44
|
|
|
45
45
|
/**
|
|
46
46
|
* Merged type definition below together
|
|
47
47
|
*/
|
|
48
48
|
export const NotificationType = {
|
|
49
|
-
|
|
50
|
-
|
|
49
|
+
...NotificationModalType,
|
|
50
|
+
...NotificationMessageType
|
|
51
51
|
};
|
|
52
52
|
|
|
53
53
|
/**
|
|
@@ -64,14 +64,14 @@ export type NotificationContent<UI> = string | UI;
|
|
|
64
64
|
* On dismiss callback
|
|
65
65
|
*/
|
|
66
66
|
export interface NotificationDismiss {
|
|
67
|
-
|
|
67
|
+
(): void;
|
|
68
68
|
}
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* Notification reander setup
|
|
72
72
|
*/
|
|
73
73
|
export interface NotifictionRenderSetup {
|
|
74
|
-
|
|
74
|
+
(options: any): any;
|
|
75
75
|
}
|
|
76
76
|
|
|
77
77
|
/**
|
|
@@ -81,47 +81,47 @@ export interface NotifictionRenderSetup {
|
|
|
81
81
|
* return string is the error message to show
|
|
82
82
|
*/
|
|
83
83
|
export interface NotificationReturn<T> {
|
|
84
|
-
|
|
84
|
+
(value: T): boolean | string | void | PromiseLike<boolean | string | void>;
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
/**
|
|
88
88
|
* Notification message parameters
|
|
89
89
|
*/
|
|
90
90
|
export interface NotificationParameters {
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
91
|
+
/**
|
|
92
|
+
* Display align
|
|
93
|
+
*/
|
|
94
|
+
align?: NotificationAlign;
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Callback
|
|
98
|
+
*/
|
|
99
|
+
callback?: NotificationReturn<void>;
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* Show as modal
|
|
103
|
+
*/
|
|
104
|
+
modal?: boolean;
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* Time span to dismiss
|
|
108
|
+
*/
|
|
109
|
+
timespan?: number;
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Add to the top
|
|
113
|
+
*/
|
|
114
|
+
top?: boolean;
|
|
115
115
|
}
|
|
116
116
|
|
|
117
117
|
/**
|
|
118
118
|
* Notification props supported for calls
|
|
119
119
|
*/
|
|
120
120
|
export type NotificationCallProps = {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
/**
|
|
122
|
+
* Input component properties
|
|
123
|
+
*/
|
|
124
|
+
inputProps?: DataTypes.StringRecord;
|
|
125
125
|
};
|
|
126
126
|
|
|
127
127
|
/**
|
|
@@ -133,131 +133,131 @@ export type NotificationRenderProps = DataTypes.StringRecord;
|
|
|
133
133
|
* Notification base interface
|
|
134
134
|
*/
|
|
135
135
|
export interface INotificaseBase<UI, C extends NotificationCallProps = {}> {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
136
|
+
/**
|
|
137
|
+
* Display align
|
|
138
|
+
*/
|
|
139
|
+
readonly align?: NotificationAlign;
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Content
|
|
143
|
+
*/
|
|
144
|
+
readonly content: NotificationContent<UI>;
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Input or control properties
|
|
148
|
+
*/
|
|
149
|
+
inputProps?: C;
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* On dismiss handling
|
|
153
|
+
*/
|
|
154
|
+
onDismiss?: NotificationDismiss;
|
|
155
|
+
|
|
156
|
+
/**
|
|
157
|
+
* On return value
|
|
158
|
+
*/
|
|
159
|
+
onReturn?: NotificationReturn<any>;
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Show the icon or hide it
|
|
163
|
+
*/
|
|
164
|
+
showIcon?: boolean;
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Seconds to auto dismiss
|
|
168
|
+
*/
|
|
169
|
+
timespan?: number;
|
|
170
|
+
|
|
171
|
+
/**
|
|
172
|
+
* Render setup / callback
|
|
173
|
+
* Add more properties
|
|
174
|
+
*/
|
|
175
|
+
renderSetup?: NotifictionRenderSetup;
|
|
176
|
+
|
|
177
|
+
/**
|
|
178
|
+
* Title
|
|
179
|
+
*/
|
|
180
|
+
readonly title?: NotificationContent<UI>;
|
|
181
|
+
|
|
182
|
+
/**
|
|
183
|
+
* Type
|
|
184
|
+
*/
|
|
185
|
+
readonly type: NotificationType;
|
|
186
186
|
}
|
|
187
187
|
|
|
188
188
|
/**
|
|
189
189
|
* Notification interface
|
|
190
190
|
*/
|
|
191
191
|
export interface INotification<UI, C extends NotificationCallProps>
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
192
|
+
extends INotificaseBase<UI, C> {
|
|
193
|
+
/**
|
|
194
|
+
* Display align
|
|
195
|
+
*/
|
|
196
|
+
readonly align: NotificationAlign;
|
|
197
|
+
|
|
198
|
+
/**
|
|
199
|
+
* Seconds to auto dismiss
|
|
200
|
+
*/
|
|
201
|
+
timespan: number;
|
|
202
|
+
|
|
203
|
+
/**
|
|
204
|
+
* Unique id
|
|
205
|
+
*/
|
|
206
|
+
readonly id: string;
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Display as modal
|
|
210
|
+
*/
|
|
211
|
+
modal: boolean;
|
|
212
|
+
|
|
213
|
+
/**
|
|
214
|
+
* Is open or not
|
|
215
|
+
*/
|
|
216
|
+
readonly open: boolean;
|
|
217
|
+
|
|
218
|
+
/**
|
|
219
|
+
* Reference
|
|
220
|
+
*/
|
|
221
|
+
ref?: any;
|
|
222
|
+
|
|
223
|
+
/**
|
|
224
|
+
* Content
|
|
225
|
+
*/
|
|
226
|
+
readonly content: NotificationContent<UI>;
|
|
227
|
+
|
|
228
|
+
/**
|
|
229
|
+
* Title
|
|
230
|
+
*/
|
|
231
|
+
readonly title?: NotificationContent<UI>;
|
|
232
|
+
|
|
233
|
+
/**
|
|
234
|
+
* Dismiss it
|
|
235
|
+
* @param delaySeconds Delay seconds
|
|
236
|
+
* @param noTrigger No onReturn trigger
|
|
237
|
+
* @returns Is delayed or not
|
|
238
|
+
*/
|
|
239
|
+
dismiss(delaySeconds?: number, noTrigger?: boolean): boolean;
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Dispose it
|
|
243
|
+
*/
|
|
244
|
+
dispose(): void;
|
|
245
|
+
|
|
246
|
+
/**
|
|
247
|
+
* Render method
|
|
248
|
+
* @param props Props
|
|
249
|
+
* @param className Style class name
|
|
250
|
+
* @param options Other options
|
|
251
|
+
*/
|
|
252
|
+
render(props: NotificationRenderProps, className?: string): UI | undefined;
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* Return value
|
|
256
|
+
* Dismiss first, then run callback
|
|
257
|
+
* @param value
|
|
258
|
+
* @returns
|
|
259
|
+
*/
|
|
260
|
+
returnValue(value: any): Promise<void>;
|
|
261
261
|
}
|
|
262
262
|
|
|
263
263
|
/**
|
|
@@ -265,197 +265,197 @@ export interface INotification<UI, C extends NotificationCallProps>
|
|
|
265
265
|
* Generic parameter UI presents UI element type
|
|
266
266
|
*/
|
|
267
267
|
export abstract class Notification<UI, C extends NotificationCallProps>
|
|
268
|
-
|
|
268
|
+
implements INotification<UI, C>
|
|
269
269
|
{
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
270
|
+
/**
|
|
271
|
+
* Display align
|
|
272
|
+
*/
|
|
273
|
+
readonly align: NotificationAlign;
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Content
|
|
277
|
+
*/
|
|
278
|
+
readonly content: NotificationContent<UI>;
|
|
279
|
+
|
|
280
|
+
/**
|
|
281
|
+
* Dismiss timeout seed
|
|
282
|
+
*/
|
|
283
|
+
private dismissSeed: number = 0;
|
|
284
|
+
|
|
285
|
+
/**
|
|
286
|
+
* Unique id
|
|
287
|
+
*/
|
|
288
|
+
readonly id: string;
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* Input or control properties
|
|
292
|
+
*/
|
|
293
|
+
inputProps?: C;
|
|
294
|
+
|
|
295
|
+
/**
|
|
296
|
+
* Display as modal
|
|
297
|
+
*/
|
|
298
|
+
modal: boolean;
|
|
299
|
+
|
|
300
|
+
/**
|
|
301
|
+
* On dismiss handling
|
|
302
|
+
*/
|
|
303
|
+
onDismiss?: NotificationDismiss;
|
|
304
|
+
|
|
305
|
+
/**
|
|
306
|
+
* On return value
|
|
307
|
+
*/
|
|
308
|
+
onReturn?: NotificationReturn<unknown>;
|
|
309
|
+
|
|
310
|
+
private _open: boolean = true;
|
|
311
|
+
/**
|
|
312
|
+
* Is open or not
|
|
313
|
+
*/
|
|
314
|
+
get open(): boolean {
|
|
315
|
+
return this._open;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
/**
|
|
319
|
+
* Reference
|
|
320
|
+
*/
|
|
321
|
+
ref?: any;
|
|
322
|
+
|
|
323
|
+
/**
|
|
324
|
+
* Render setup / callback
|
|
325
|
+
*/
|
|
326
|
+
renderSetup?: NotifictionRenderSetup;
|
|
327
|
+
|
|
328
|
+
/**
|
|
329
|
+
* Show the icon or hide it
|
|
330
|
+
*/
|
|
331
|
+
showIcon?: boolean;
|
|
332
|
+
|
|
333
|
+
/**
|
|
334
|
+
* Seconds to auto dismiss
|
|
335
|
+
*/
|
|
336
|
+
timespan: number;
|
|
337
|
+
|
|
338
|
+
/**
|
|
339
|
+
* Title
|
|
340
|
+
*/
|
|
341
|
+
readonly title?: NotificationContent<UI>;
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* Type
|
|
345
|
+
*/
|
|
346
|
+
readonly type: NotificationType;
|
|
347
|
+
|
|
348
|
+
/**
|
|
349
|
+
* Constructor
|
|
350
|
+
* @param type Type
|
|
351
|
+
* @param content Content
|
|
352
|
+
* @param title Title
|
|
353
|
+
* @param align Align
|
|
354
|
+
* @param timespan Timespan
|
|
355
|
+
*/
|
|
356
|
+
constructor(
|
|
357
|
+
type: NotificationType,
|
|
358
|
+
content: NotificationContent<UI>,
|
|
359
|
+
title?: NotificationContent<UI>,
|
|
360
|
+
align?: NotificationAlign,
|
|
361
|
+
timespan?: number
|
|
362
|
+
) {
|
|
363
|
+
this.id = Utils.newGUID();
|
|
364
|
+
|
|
365
|
+
this.type = type;
|
|
366
|
+
this.content = content;
|
|
367
|
+
this.title = title;
|
|
368
|
+
|
|
369
|
+
// Modal type
|
|
370
|
+
this.modal = type in NotificationModalType;
|
|
371
|
+
|
|
372
|
+
// Align, only available for none modal
|
|
373
|
+
if (this.modal) this.align = NotificationAlign.Unknown;
|
|
374
|
+
else if (align != null) this.align = align;
|
|
375
|
+
// Message align default to top left
|
|
376
|
+
else if (type in NotificationMessageType)
|
|
377
|
+
this.align = NotificationAlign.TopLeft;
|
|
378
|
+
else this.align = NotificationAlign.Center;
|
|
379
|
+
|
|
380
|
+
// Display as modal will lasts otherwise 5 seconds to dismiss it
|
|
381
|
+
this.timespan = timespan ?? (this.modal ? 0 : 5);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
/**
|
|
385
|
+
* Dismiss it
|
|
386
|
+
* @param delaySeconds Delay seconds
|
|
387
|
+
* @param noTrigger No onReturn trigger
|
|
388
|
+
* @returns Is delayed or not
|
|
389
|
+
*/
|
|
390
|
+
dismiss(delaySeconds: number = 0, noTrigger: boolean = false): boolean {
|
|
391
|
+
// If it's closed, return
|
|
392
|
+
if (!this._open) return false;
|
|
393
|
+
|
|
394
|
+
if (delaySeconds > 0) {
|
|
395
|
+
this.removeTimeout();
|
|
396
|
+
this.dismissSeed = window.setTimeout(
|
|
397
|
+
this.dismiss.bind(this),
|
|
398
|
+
delaySeconds * 1000,
|
|
399
|
+
0 // force to dismiss
|
|
400
|
+
);
|
|
401
|
+
return true;
|
|
316
402
|
}
|
|
317
403
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
/**
|
|
324
|
-
* Render setup / callback
|
|
325
|
-
*/
|
|
326
|
-
renderSetup?: NotifictionRenderSetup;
|
|
327
|
-
|
|
328
|
-
/**
|
|
329
|
-
* Show the icon or hide it
|
|
330
|
-
*/
|
|
331
|
-
showIcon?: boolean;
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Seconds to auto dismiss
|
|
335
|
-
*/
|
|
336
|
-
timespan: number;
|
|
337
|
-
|
|
338
|
-
/**
|
|
339
|
-
* Title
|
|
340
|
-
*/
|
|
341
|
-
readonly title?: NotificationContent<UI>;
|
|
342
|
-
|
|
343
|
-
/**
|
|
344
|
-
* Type
|
|
345
|
-
*/
|
|
346
|
-
readonly type: NotificationType;
|
|
347
|
-
|
|
348
|
-
/**
|
|
349
|
-
* Constructor
|
|
350
|
-
* @param type Type
|
|
351
|
-
* @param content Content
|
|
352
|
-
* @param title Title
|
|
353
|
-
* @param align Align
|
|
354
|
-
* @param timespan Timespan
|
|
355
|
-
*/
|
|
356
|
-
constructor(
|
|
357
|
-
type: NotificationType,
|
|
358
|
-
content: NotificationContent<UI>,
|
|
359
|
-
title?: NotificationContent<UI>,
|
|
360
|
-
align?: NotificationAlign,
|
|
361
|
-
timespan?: number
|
|
404
|
+
// For message, call onReturn
|
|
405
|
+
if (
|
|
406
|
+
!noTrigger &&
|
|
407
|
+
this.onReturn != null &&
|
|
408
|
+
this.type in NotificationMessageType
|
|
362
409
|
) {
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
this.type = type;
|
|
366
|
-
this.content = content;
|
|
367
|
-
this.title = title;
|
|
410
|
+
this.onReturn(undefined);
|
|
411
|
+
}
|
|
368
412
|
|
|
369
|
-
|
|
370
|
-
|
|
413
|
+
// Indicate closed
|
|
414
|
+
this._open = false;
|
|
371
415
|
|
|
372
|
-
|
|
373
|
-
if (this.modal) this.align = NotificationAlign.Unknown;
|
|
374
|
-
else if (align != null) this.align = align;
|
|
375
|
-
// Message align default to top left
|
|
376
|
-
else if (type in NotificationMessageType)
|
|
377
|
-
this.align = NotificationAlign.TopLeft;
|
|
378
|
-
else this.align = NotificationAlign.Center;
|
|
416
|
+
if (this.onDismiss) this.onDismiss();
|
|
379
417
|
|
|
380
|
-
|
|
381
|
-
this.timespan = timespan ?? (this.modal ? 0 : 5);
|
|
382
|
-
}
|
|
418
|
+
this.dispose();
|
|
383
419
|
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
* @param delaySeconds Delay seconds
|
|
387
|
-
* @param noTrigger No onReturn trigger
|
|
388
|
-
* @returns Is delayed or not
|
|
389
|
-
*/
|
|
390
|
-
dismiss(delaySeconds: number = 0, noTrigger: boolean = false): boolean {
|
|
391
|
-
// If it's closed, return
|
|
392
|
-
if (!this._open) return false;
|
|
393
|
-
|
|
394
|
-
if (delaySeconds > 0) {
|
|
395
|
-
this.removeTimeout();
|
|
396
|
-
this.dismissSeed = window.setTimeout(
|
|
397
|
-
this.dismiss.bind(this),
|
|
398
|
-
delaySeconds * 1000,
|
|
399
|
-
0 // force to dismiss
|
|
400
|
-
);
|
|
401
|
-
return true;
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
// For message, call onReturn
|
|
405
|
-
if (
|
|
406
|
-
!noTrigger &&
|
|
407
|
-
this.onReturn != null &&
|
|
408
|
-
this.type in NotificationMessageType
|
|
409
|
-
) {
|
|
410
|
-
this.onReturn(undefined);
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
// Indicate closed
|
|
414
|
-
this._open = false;
|
|
415
|
-
|
|
416
|
-
if (this.onDismiss) this.onDismiss();
|
|
417
|
-
|
|
418
|
-
this.dispose();
|
|
419
|
-
|
|
420
|
-
return false;
|
|
421
|
-
}
|
|
420
|
+
return false;
|
|
421
|
+
}
|
|
422
422
|
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
}
|
|
423
|
+
// Remove possible dismiss timeout
|
|
424
|
+
private removeTimeout() {
|
|
425
|
+
if (this.dismissSeed > 0) {
|
|
426
|
+
clearTimeout(this.dismissSeed);
|
|
427
|
+
this.dismissSeed = 0;
|
|
429
428
|
}
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
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
|
-
this.dismiss(0, true);
|
|
429
|
+
}
|
|
430
|
+
|
|
431
|
+
/**
|
|
432
|
+
* Dispose it
|
|
433
|
+
*/
|
|
434
|
+
dispose() {
|
|
435
|
+
this.removeTimeout();
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* Render method
|
|
440
|
+
* @param props Props, provider's UI props
|
|
441
|
+
* @param className Style class name
|
|
442
|
+
*/
|
|
443
|
+
abstract render(
|
|
444
|
+
props: NotificationRenderProps,
|
|
445
|
+
className?: string
|
|
446
|
+
): UI | undefined;
|
|
447
|
+
|
|
448
|
+
/**
|
|
449
|
+
* Return value
|
|
450
|
+
* Dismiss first, then run callback
|
|
451
|
+
* @param value
|
|
452
|
+
* @returns
|
|
453
|
+
*/
|
|
454
|
+
async returnValue(value: any) {
|
|
455
|
+
if (this.onReturn) {
|
|
456
|
+
const result = await this.onReturn(value);
|
|
457
|
+
if (result === false) return;
|
|
460
458
|
}
|
|
459
|
+
this.dismiss(0, true);
|
|
460
|
+
}
|
|
461
461
|
}
|