@justeattakeaway/pie-toast-provider 1.2.3 → 1.3.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/README.md +1 -0
- package/custom-elements.json +204 -8
- package/dist/index.d.ts +63 -6
- package/dist/index.js +201 -117
- package/dist/react.d.ts +63 -6
- package/dist/react.js +4 -3
- package/package.json +5 -5
- package/src/defs.ts +16 -0
- package/src/index.ts +180 -51
- package/src/toast-provider.scss +27 -1
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ Ideally, you should install the component using the **`@justeattakeaway/pie-webc
|
|
|
37
37
|
|----------|---------|---------------------------------------------------------------------------------------------------|---------|
|
|
38
38
|
| options | `{}` | Default options for all toasts; accepts all toast [props](https://webc.pie.design/?path=/story/components-toast). | `{}` |
|
|
39
39
|
| position | `"default"`, `"bottom-left"`, `"bottom-right"`, `"bottom-center"` | Sets the position of the toast provider. When set to `default`, the toasts will be positioned at bottom-left for RTL languages and bottom-right for LTR languages. | `default` |
|
|
40
|
+
| isStacked | `true`, `false` | When true, up to 3 toasts are displayed at the same time in a vertical stack. When false, a single toast is displayed at a time and the rest wait in the queue. | `false` |
|
|
40
41
|
|
|
41
42
|
### Slots
|
|
42
43
|
This component does not have any slots. All content is controlled through properties.
|
package/custom-elements.json
CHANGED
|
@@ -34,7 +34,7 @@
|
|
|
34
34
|
"type": {
|
|
35
35
|
"text": "DefaultProps"
|
|
36
36
|
},
|
|
37
|
-
"default": "{ options: {}, position: 'default', }"
|
|
37
|
+
"default": "{ options: {}, position: 'default', isStacked: false, }"
|
|
38
38
|
},
|
|
39
39
|
{
|
|
40
40
|
"kind": "variable",
|
|
@@ -44,6 +44,15 @@
|
|
|
44
44
|
},
|
|
45
45
|
"default": "'pie-toast-provider-queue-update'",
|
|
46
46
|
"description": "Event name for when the toast provider queue is updated."
|
|
47
|
+
},
|
|
48
|
+
{
|
|
49
|
+
"kind": "variable",
|
|
50
|
+
"name": "MAX_VISIBLE_TOASTS",
|
|
51
|
+
"type": {
|
|
52
|
+
"text": "number"
|
|
53
|
+
},
|
|
54
|
+
"default": "3",
|
|
55
|
+
"description": "The most toasts the provider will display at once when `isStacked` is true.\n\nWith `isStacked` false (the default) a single toast is displayed regardless of this value."
|
|
47
56
|
}
|
|
48
57
|
],
|
|
49
58
|
"exports": [
|
|
@@ -78,6 +87,14 @@
|
|
|
78
87
|
"name": "ON_TOAST_PROVIDER_QUEUE_UPDATE_EVENT",
|
|
79
88
|
"module": "src/defs.js"
|
|
80
89
|
}
|
|
90
|
+
},
|
|
91
|
+
{
|
|
92
|
+
"kind": "js",
|
|
93
|
+
"name": "MAX_VISIBLE_TOASTS",
|
|
94
|
+
"declaration": {
|
|
95
|
+
"name": "MAX_VISIBLE_TOASTS",
|
|
96
|
+
"module": "src/defs.js"
|
|
97
|
+
}
|
|
81
98
|
}
|
|
82
99
|
]
|
|
83
100
|
},
|
|
@@ -102,6 +119,12 @@
|
|
|
102
119
|
"privacy": "public",
|
|
103
120
|
"attribute": "position"
|
|
104
121
|
},
|
|
122
|
+
{
|
|
123
|
+
"kind": "field",
|
|
124
|
+
"name": "isStacked",
|
|
125
|
+
"privacy": "public",
|
|
126
|
+
"attribute": "isStacked"
|
|
127
|
+
},
|
|
105
128
|
{
|
|
106
129
|
"kind": "field",
|
|
107
130
|
"name": "_toasts",
|
|
@@ -113,12 +136,100 @@
|
|
|
113
136
|
},
|
|
114
137
|
{
|
|
115
138
|
"kind": "field",
|
|
116
|
-
"name": "
|
|
139
|
+
"name": "_visibleToasts",
|
|
117
140
|
"type": {
|
|
118
|
-
"text": "ExtendedToastProps
|
|
141
|
+
"text": "ExtendedToastProps[]"
|
|
119
142
|
},
|
|
120
143
|
"privacy": "private",
|
|
121
|
-
"default": "
|
|
144
|
+
"default": "[]"
|
|
145
|
+
},
|
|
146
|
+
{
|
|
147
|
+
"kind": "field",
|
|
148
|
+
"name": "_dismissingToasts",
|
|
149
|
+
"type": {
|
|
150
|
+
"text": "ExtendedToastProps[]"
|
|
151
|
+
},
|
|
152
|
+
"privacy": "private",
|
|
153
|
+
"default": "[]"
|
|
154
|
+
},
|
|
155
|
+
{
|
|
156
|
+
"kind": "field",
|
|
157
|
+
"name": "_collapsingToasts",
|
|
158
|
+
"type": {
|
|
159
|
+
"text": "ExtendedToastProps[]"
|
|
160
|
+
},
|
|
161
|
+
"privacy": "private",
|
|
162
|
+
"default": "[]"
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
"kind": "field",
|
|
166
|
+
"name": "_announcements",
|
|
167
|
+
"type": {
|
|
168
|
+
"text": "ExtendedToastProps[]"
|
|
169
|
+
},
|
|
170
|
+
"privacy": "private",
|
|
171
|
+
"default": "[]",
|
|
172
|
+
"description": "Messages currently held in the live regions, in the order they became visible.\n\nThe toast objects themselves are reused as entries: they are unique per `createToast`, which\ngives `repeat` a stable key and lets the entries be pruned by identity when a toast leaves."
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
"kind": "field",
|
|
176
|
+
"name": "_motionFallbacks",
|
|
177
|
+
"privacy": "private",
|
|
178
|
+
"default": "new Map<ExtendedToastProps, ReturnType<typeof setTimeout>>()",
|
|
179
|
+
"description": "Pending MOTION_FALLBACK_MS timers, keyed by the toast they will advance."
|
|
180
|
+
},
|
|
181
|
+
{
|
|
182
|
+
"kind": "method",
|
|
183
|
+
"name": "_scheduleMotionFallback",
|
|
184
|
+
"privacy": "private",
|
|
185
|
+
"return": {
|
|
186
|
+
"type": {
|
|
187
|
+
"text": "void"
|
|
188
|
+
}
|
|
189
|
+
},
|
|
190
|
+
"parameters": [
|
|
191
|
+
{
|
|
192
|
+
"name": "toast",
|
|
193
|
+
"type": {
|
|
194
|
+
"text": "ExtendedToastProps"
|
|
195
|
+
}
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
"name": "advance",
|
|
199
|
+
"type": {
|
|
200
|
+
"text": "() => void"
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
],
|
|
204
|
+
"description": "Replaces any pending fallback for `toast` with one that runs `advance`.\n\nEach phase supersedes the previous phase's fallback, so a toast only ever has one timer."
|
|
205
|
+
},
|
|
206
|
+
{
|
|
207
|
+
"kind": "method",
|
|
208
|
+
"name": "_clearMotionFallback",
|
|
209
|
+
"privacy": "private",
|
|
210
|
+
"return": {
|
|
211
|
+
"type": {
|
|
212
|
+
"text": "void"
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
"parameters": [
|
|
216
|
+
{
|
|
217
|
+
"name": "toast",
|
|
218
|
+
"type": {
|
|
219
|
+
"text": "ExtendedToastProps"
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
]
|
|
223
|
+
},
|
|
224
|
+
{
|
|
225
|
+
"kind": "method",
|
|
226
|
+
"name": "_clearMotionFallbacks",
|
|
227
|
+
"privacy": "private",
|
|
228
|
+
"return": {
|
|
229
|
+
"type": {
|
|
230
|
+
"text": "void"
|
|
231
|
+
}
|
|
232
|
+
}
|
|
122
233
|
},
|
|
123
234
|
{
|
|
124
235
|
"kind": "method",
|
|
@@ -163,13 +274,94 @@
|
|
|
163
274
|
"kind": "method",
|
|
164
275
|
"name": "_dismissToast",
|
|
165
276
|
"privacy": "private",
|
|
166
|
-
"
|
|
277
|
+
"parameters": [
|
|
278
|
+
{
|
|
279
|
+
"name": "toast",
|
|
280
|
+
"type": {
|
|
281
|
+
"text": "ExtendedToastProps"
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
],
|
|
285
|
+
"description": "Starts the slide-out animation for the dismissed toast."
|
|
286
|
+
},
|
|
287
|
+
{
|
|
288
|
+
"kind": "method",
|
|
289
|
+
"name": "_handleToastOpen",
|
|
290
|
+
"privacy": "private",
|
|
291
|
+
"parameters": [
|
|
292
|
+
{
|
|
293
|
+
"name": "toast",
|
|
294
|
+
"type": {
|
|
295
|
+
"text": "ExtendedToastProps"
|
|
296
|
+
}
|
|
297
|
+
}
|
|
298
|
+
],
|
|
299
|
+
"description": "Forwards the toast's open event to the consumer.\n\n`isOpen` is bound with the `live` directive, so a toast that sets `isOpen` to false while\ndismissing is reopened on the next render in order to keep it visible for the slide-out\nanimation. That reopen dispatches a second `pie-toast-open`, which is not a real open, so it\nis not forwarded."
|
|
300
|
+
},
|
|
301
|
+
{
|
|
302
|
+
"kind": "method",
|
|
303
|
+
"name": "_getToastClass",
|
|
304
|
+
"privacy": "private",
|
|
305
|
+
"return": {
|
|
306
|
+
"type": {
|
|
307
|
+
"text": "string"
|
|
308
|
+
}
|
|
309
|
+
},
|
|
310
|
+
"parameters": [
|
|
311
|
+
{
|
|
312
|
+
"name": "toast",
|
|
313
|
+
"type": {
|
|
314
|
+
"text": "ExtendedToastProps"
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
]
|
|
318
|
+
},
|
|
319
|
+
{
|
|
320
|
+
"kind": "method",
|
|
321
|
+
"name": "_getToastDuration",
|
|
322
|
+
"privacy": "private",
|
|
323
|
+
"parameters": [
|
|
324
|
+
{
|
|
325
|
+
"name": "toast",
|
|
326
|
+
"type": {
|
|
327
|
+
"text": "ExtendedToastProps"
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
]
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
"kind": "method",
|
|
334
|
+
"name": "_finalizeDismiss",
|
|
335
|
+
"privacy": "private",
|
|
336
|
+
"parameters": [
|
|
337
|
+
{
|
|
338
|
+
"name": "toast",
|
|
339
|
+
"type": {
|
|
340
|
+
"text": "ExtendedToastProps"
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
],
|
|
344
|
+
"description": "Starts the height-collapse phase after the slide-out animation ends."
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
"kind": "method",
|
|
348
|
+
"name": "_finalizeCollapse",
|
|
349
|
+
"privacy": "private",
|
|
350
|
+
"parameters": [
|
|
351
|
+
{
|
|
352
|
+
"name": "toast",
|
|
353
|
+
"type": {
|
|
354
|
+
"text": "ExtendedToastProps"
|
|
355
|
+
}
|
|
356
|
+
}
|
|
357
|
+
],
|
|
358
|
+
"description": "Called after the collapse transition ends. Removes the toast from DOM and promotes the next queued toast."
|
|
167
359
|
},
|
|
168
360
|
{
|
|
169
361
|
"kind": "method",
|
|
170
362
|
"name": "_showNextToast",
|
|
171
363
|
"privacy": "private",
|
|
172
|
-
"description": "
|
|
364
|
+
"description": "Fills the visible slots from the queue.\n\nThe loop only ever adds toasts, so turning `isStacked` off while several are on screen\ndoes not remove any: the extras stay until they dismiss normally, then the provider\nsettles back to one at a time."
|
|
173
365
|
},
|
|
174
366
|
{
|
|
175
367
|
"kind": "method",
|
|
@@ -184,13 +376,13 @@
|
|
|
184
376
|
"description": "The toast props to display."
|
|
185
377
|
}
|
|
186
378
|
],
|
|
187
|
-
"description": "Adds a new toast to the queue
|
|
379
|
+
"description": "Adds a new toast to the queue (sorted by priority) and fills visible slots."
|
|
188
380
|
},
|
|
189
381
|
{
|
|
190
382
|
"kind": "method",
|
|
191
383
|
"name": "clearToasts",
|
|
192
384
|
"privacy": "public",
|
|
193
|
-
"description": "
|
|
385
|
+
"description": "Clears all toasts from the queue and dismisses all visible toasts."
|
|
194
386
|
}
|
|
195
387
|
],
|
|
196
388
|
"events": [
|
|
@@ -210,6 +402,10 @@
|
|
|
210
402
|
{
|
|
211
403
|
"name": "position",
|
|
212
404
|
"fieldName": "position"
|
|
405
|
+
},
|
|
406
|
+
{
|
|
407
|
+
"name": "isStacked",
|
|
408
|
+
"fieldName": "isStacked"
|
|
213
409
|
}
|
|
214
410
|
],
|
|
215
411
|
"superclass": {
|
package/dist/index.d.ts
CHANGED
|
@@ -29,6 +29,15 @@ export declare interface ExtendedToastProps extends ToastProps {
|
|
|
29
29
|
onPieToastLeadingActionClick?: (event: Event) => void;
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
/**
|
|
33
|
+
* The most toasts the provider will display at once when `isStacked` is true.
|
|
34
|
+
*
|
|
35
|
+
* With `isStacked` false (the default) a single toast is displayed regardless of this value.
|
|
36
|
+
*
|
|
37
|
+
* @constant
|
|
38
|
+
*/
|
|
39
|
+
export declare const MAX_VISIBLE_TOASTS = 3;
|
|
40
|
+
|
|
32
41
|
/**
|
|
33
42
|
* Event name for when the toast provider queue is updated.
|
|
34
43
|
*
|
|
@@ -43,8 +52,29 @@ export declare const ON_TOAST_PROVIDER_QUEUE_UPDATE_EVENT = "pie-toast-provider-
|
|
|
43
52
|
export declare class PieToastProvider extends PieElement implements ToastProviderProps {
|
|
44
53
|
options: Partial<ExtendedToastProps>;
|
|
45
54
|
position: "default" | "bottom-left" | "bottom-right" | "bottom-center";
|
|
55
|
+
isStacked: boolean;
|
|
46
56
|
private _toasts;
|
|
47
|
-
private
|
|
57
|
+
private _visibleToasts;
|
|
58
|
+
private _dismissingToasts;
|
|
59
|
+
private _collapsingToasts;
|
|
60
|
+
/**
|
|
61
|
+
* Messages currently held in the live regions, in the order they became visible.
|
|
62
|
+
*
|
|
63
|
+
* The toast objects themselves are reused as entries: they are unique per `createToast`, which
|
|
64
|
+
* gives `repeat` a stable key and lets the entries be pruned by identity when a toast leaves.
|
|
65
|
+
*/
|
|
66
|
+
private _announcements;
|
|
67
|
+
/** Pending {@link MOTION_FALLBACK_MS} timers, keyed by the toast they will advance. */
|
|
68
|
+
private _motionFallbacks;
|
|
69
|
+
disconnectedCallback(): void;
|
|
70
|
+
/**
|
|
71
|
+
* Replaces any pending fallback for `toast` with one that runs `advance`.
|
|
72
|
+
*
|
|
73
|
+
* Each phase supersedes the previous phase's fallback, so a toast only ever has one timer.
|
|
74
|
+
*/
|
|
75
|
+
private _scheduleMotionFallback;
|
|
76
|
+
private _clearMotionFallback;
|
|
77
|
+
private _clearMotionFallbacks;
|
|
48
78
|
updated(changedProperties: PropertyValues<this>): void;
|
|
49
79
|
private _dispatchQueueUpdateEvent;
|
|
50
80
|
/**
|
|
@@ -55,21 +85,43 @@ export declare class PieToastProvider extends PieElement implements ToastProvide
|
|
|
55
85
|
*/
|
|
56
86
|
private getPriority;
|
|
57
87
|
/**
|
|
58
|
-
*
|
|
88
|
+
* Starts the slide-out animation for the dismissed toast.
|
|
59
89
|
*/
|
|
60
90
|
private _dismissToast;
|
|
61
91
|
/**
|
|
62
|
-
*
|
|
92
|
+
* Forwards the toast's open event to the consumer.
|
|
93
|
+
*
|
|
94
|
+
* `isOpen` is bound with the `live` directive, so a toast that sets `isOpen` to false while
|
|
95
|
+
* dismissing is reopened on the next render in order to keep it visible for the slide-out
|
|
96
|
+
* animation. That reopen dispatches a second `pie-toast-open`, which is not a real open, so it
|
|
97
|
+
* is not forwarded.
|
|
98
|
+
*/
|
|
99
|
+
private _handleToastOpen;
|
|
100
|
+
private _getToastClass;
|
|
101
|
+
private _getToastDuration;
|
|
102
|
+
/**
|
|
103
|
+
* Starts the height-collapse phase after the slide-out animation ends.
|
|
104
|
+
*/
|
|
105
|
+
private _finalizeDismiss;
|
|
106
|
+
/**
|
|
107
|
+
* Called after the collapse transition ends. Removes the toast from DOM and promotes the next queued toast.
|
|
108
|
+
*/
|
|
109
|
+
private _finalizeCollapse;
|
|
110
|
+
/**
|
|
111
|
+
* Fills the visible slots from the queue.
|
|
112
|
+
*
|
|
113
|
+
* The loop only ever adds toasts, so turning `isStacked` off while several are on screen
|
|
114
|
+
* does not remove any: the extras stay until they dismiss normally, then the provider
|
|
115
|
+
* settles back to one at a time.
|
|
63
116
|
*/
|
|
64
117
|
private _showNextToast;
|
|
65
118
|
/**
|
|
66
|
-
* Adds a new toast to the queue
|
|
119
|
+
* Adds a new toast to the queue (sorted by priority) and fills visible slots.
|
|
67
120
|
* @param {ToastProps} toast - The toast props to display.
|
|
68
121
|
*/
|
|
69
122
|
createToast(toast: ExtendedToastProps): void;
|
|
70
123
|
/**
|
|
71
|
-
*
|
|
72
|
-
* Clears all toasts from the queue and dismisses the currently visible toast.
|
|
124
|
+
* Clears all toasts from the queue and dismisses all visible toasts.
|
|
73
125
|
*/
|
|
74
126
|
clearToasts(): void;
|
|
75
127
|
render(): TemplateResult<1>;
|
|
@@ -112,6 +164,11 @@ export declare interface ToastProviderProps {
|
|
|
112
164
|
* When set to `default`, the toasts will be positioned at bottom-left for RTL languages and bottom-right for LTR languages.
|
|
113
165
|
*/
|
|
114
166
|
position?: typeof positions[number];
|
|
167
|
+
/**
|
|
168
|
+
* When true, up to 3 toasts are displayed at the same time in a vertical stack. When false,
|
|
169
|
+
* a single toast is displayed at a time and the rest wait in the queue.
|
|
170
|
+
*/
|
|
171
|
+
isStacked?: boolean;
|
|
115
172
|
}
|
|
116
173
|
|
|
117
174
|
export { }
|