@justeattakeaway/pie-toast-provider 1.1.8 → 1.2.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/dist/index.js +39 -31
- package/package.json +5 -5
- package/src/index.ts +16 -2
- package/src/toast-provider.scss +4 -0
package/dist/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { LitElement as _, unsafeCSS as
|
|
1
|
+
import { LitElement as _, unsafeCSS as b, nothing as y, html as u } from "lit";
|
|
2
2
|
import { property as h, state as g } from "lit/decorators.js";
|
|
3
|
-
import { ifDefined as
|
|
3
|
+
import { ifDefined as T } from "lit/directives/if-defined.js";
|
|
4
4
|
import { classMap as f } from "lit/directives/class-map.js";
|
|
5
5
|
import { validPropertyValues as P, safeCustomElement as $, dispatchCustomEvent as x } from "@justeattakeaway/pie-webc-core";
|
|
6
6
|
import { defaultProps as m } from "@justeattakeaway/pie-toast";
|
|
@@ -9,9 +9,9 @@ const l = class l extends _ {
|
|
|
9
9
|
this.getAttribute("v") || this.setAttribute("v", l.v);
|
|
10
10
|
}
|
|
11
11
|
};
|
|
12
|
-
l.v = "1.1
|
|
12
|
+
l.v = "1.2.1";
|
|
13
13
|
let d = l;
|
|
14
|
-
const
|
|
14
|
+
const w = "*,*:after,*:before{box-sizing:inherit}:root{--pie-animation-slide-translate-start: -100%}.pie-animation--slide-in{animation:pie-animation-slide-in var(--dt-motion-timing-200) var(--dt-motion-easing-out)}.pie-animation--slide-out{animation:pie-animation-slide-out var(--dt-motion-timing-100) var(--dt-motion-easing-in)}@keyframes pie-animation-slide-in{0%{transform:translate(var(--pie-animation-slide-translate-start))}to{transform:translate(0)}}@keyframes pie-animation-slide-out{0%{transform:translate(0)}to{transform:translate(var(--pie-animation-slide-translate-start))}}:host{--toast-provider-z-index: var(--dt-z-index-toast);--toast-provider-position: fixed;--toast-provider-offset: var(--dt-spacing-d)}@media(min-width:769px){:host{--toast-provider-offset: var(--dt-spacing-e)}}.c-toast-provider{position:var(--toast-provider-position);z-index:var(--toast-provider-z-index)}.c-toast-provider-announcer{position:absolute;display:block;height:1px;width:1px;border:0;padding:0;margin:-1px;overflow:hidden;white-space:nowrap;clip:rect(0,0,0,0);clip-path:inset(50%)}.c-toast-provider-announcer *{overflow:hidden}.c-toast-provider.c-toast-provider--default{inset-inline-start:var(--toast-provider-offset);inset-block-end:var(--toast-provider-offset)}.c-toast-provider.c-toast-provider--default:dir(rtl){--pie-animation-slide-translate-start: 100%}.c-toast-provider.c-toast-provider--bottom-left{--pie-animation-slide-translate-start: -100%;left:var(--toast-provider-offset);bottom:var(--toast-provider-offset)}.c-toast-provider.c-toast-provider--bottom-right{--pie-animation-slide-translate-start: 100%;right:var(--toast-provider-offset);bottom:var(--toast-provider-offset)}.c-toast-provider.c-toast-provider--bottom-center{--pie-animation-slide-translate-start: 0, 100%;left:50%;bottom:var(--toast-provider-offset);transform:translate(-50%)}", A = {
|
|
15
15
|
"error-actionable": 1,
|
|
16
16
|
error: 2,
|
|
17
17
|
"warning-actionable": 3,
|
|
@@ -35,13 +35,13 @@ const A = "*,*:after,*:before{box-sizing:inherit}:root{--pie-animation-slide-tra
|
|
|
35
35
|
for (; t; ) {
|
|
36
36
|
const e = t.parentElement;
|
|
37
37
|
if (e) {
|
|
38
|
-
const
|
|
39
|
-
if (
|
|
38
|
+
const i = e.querySelector(":scope > pie-toast-provider");
|
|
39
|
+
if (i) return i;
|
|
40
40
|
}
|
|
41
41
|
t = e;
|
|
42
42
|
}
|
|
43
|
-
const
|
|
44
|
-
return
|
|
43
|
+
const s = document.querySelectorAll("pie-toast-provider");
|
|
44
|
+
return s.length === 0 ? (console.error("No pie-toast-provider found in the DOM. Add a <pie-toast-provider> element to your page or at the root of your application."), null) : s.length > 1 ? (console.error("Multiple pie-toast-provider elements found. Use the `providerId` option to target a specific provider."), null) : s[0];
|
|
45
45
|
},
|
|
46
46
|
create(o) {
|
|
47
47
|
const t = this._getToastProvider(o.providerId);
|
|
@@ -52,10 +52,10 @@ const A = "*,*:after,*:before{box-sizing:inherit}:root{--pie-animation-slide-tra
|
|
|
52
52
|
t && t.clearToasts();
|
|
53
53
|
}
|
|
54
54
|
};
|
|
55
|
-
var D = Object.defineProperty, S = Object.getOwnPropertyDescriptor,
|
|
56
|
-
for (var
|
|
57
|
-
(
|
|
58
|
-
return e &&
|
|
55
|
+
var D = Object.defineProperty, S = Object.getOwnPropertyDescriptor, p = (o, t, s, e) => {
|
|
56
|
+
for (var i = e > 1 ? void 0 : e ? S(t, s) : t, a = o.length - 1, n; a >= 0; a--)
|
|
57
|
+
(n = o[a]) && (i = (e ? n(t, s, i) : n(i)) || i);
|
|
58
|
+
return e && i && D(t, s, i), i;
|
|
59
59
|
};
|
|
60
60
|
const C = "pie-toast-provider";
|
|
61
61
|
let r = class extends d {
|
|
@@ -79,8 +79,8 @@ let r = class extends d {
|
|
|
79
79
|
* @returns {number} - The priority based on the variant and action.
|
|
80
80
|
*/
|
|
81
81
|
getPriority(o = m.variant, t = !1) {
|
|
82
|
-
const
|
|
83
|
-
return
|
|
82
|
+
const s = `${o}${t ? "-actionable" : ""}`;
|
|
83
|
+
return A[s];
|
|
84
84
|
}
|
|
85
85
|
/**
|
|
86
86
|
* Handles the dismissal of the current toast and displays the next one in the queue (if any).
|
|
@@ -107,10 +107,10 @@ let r = class extends d {
|
|
|
107
107
|
*/
|
|
108
108
|
createToast(o) {
|
|
109
109
|
const t = { ...m, ...this.options, ...o };
|
|
110
|
-
this._toasts = [...this._toasts, t].sort((
|
|
111
|
-
var
|
|
112
|
-
const
|
|
113
|
-
return this.getPriority(
|
|
110
|
+
this._toasts = [...this._toasts, t].sort((s, e) => {
|
|
111
|
+
var n, v;
|
|
112
|
+
const i = this.getPriority(e.variant, !!((n = e.leadingAction) != null && n.text));
|
|
113
|
+
return this.getPriority(s.variant, !!((v = s.leadingAction) != null && v.text)) - i;
|
|
114
114
|
}), this._currentToast || this._showNextToast();
|
|
115
115
|
}
|
|
116
116
|
/**
|
|
@@ -124,27 +124,35 @@ let r = class extends d {
|
|
|
124
124
|
const {
|
|
125
125
|
position: o,
|
|
126
126
|
_currentToast: t
|
|
127
|
-
} = this,
|
|
127
|
+
} = this, s = {
|
|
128
128
|
"c-toast-provider": !0,
|
|
129
129
|
[`c-toast-provider--${o}`]: !0
|
|
130
130
|
}, e = {
|
|
131
131
|
"pie-animation--slide-in": !!t,
|
|
132
132
|
"pie-animation--slide-out": t === null
|
|
133
|
-
};
|
|
133
|
+
}, i = (t == null ? void 0 : t.variant) === "error", a = { ...t == null ? void 0 : t.aria, live: "off" };
|
|
134
134
|
return u`
|
|
135
|
-
<div
|
|
136
|
-
class=${f(
|
|
135
|
+
<div
|
|
136
|
+
class=${f(s)}
|
|
137
137
|
data-test-id="pie-toast-provider">
|
|
138
|
+
<div
|
|
139
|
+
class="c-toast-provider-announcer is-visuallyHidden"
|
|
140
|
+
role="${i ? "alert" : "status"}"
|
|
141
|
+
aria-live="${i ? "assertive" : "polite"}"
|
|
142
|
+
aria-atomic="true"
|
|
143
|
+
data-test-id="pie-toast-provider-announcer">
|
|
144
|
+
${(t == null ? void 0 : t.message) ?? ""}
|
|
145
|
+
</div>
|
|
138
146
|
${t && u`
|
|
139
147
|
<pie-toast
|
|
140
148
|
class=${f(e)}
|
|
141
149
|
message="${t.message}"
|
|
142
|
-
variant="${
|
|
150
|
+
variant="${T(t.variant)}"
|
|
143
151
|
?isStrong="${t.isStrong}"
|
|
144
152
|
?isDismissible="${t.isDismissible}"
|
|
145
153
|
?isMultiline="${t.isMultiline}"
|
|
146
154
|
.leadingAction="${t.leadingAction}"
|
|
147
|
-
.aria="${
|
|
155
|
+
.aria="${a}"
|
|
148
156
|
.duration="${typeof t.duration > "u" ? y : t.duration}"
|
|
149
157
|
@pie-toast-close="${this._dismissToast}"
|
|
150
158
|
@pie-toast-open="${t.onPieToastOpen}"
|
|
@@ -155,26 +163,26 @@ let r = class extends d {
|
|
|
155
163
|
`;
|
|
156
164
|
}
|
|
157
165
|
};
|
|
158
|
-
r.styles =
|
|
159
|
-
|
|
166
|
+
r.styles = b(w);
|
|
167
|
+
p([
|
|
160
168
|
h({ type: Object })
|
|
161
169
|
], r.prototype, "options", 2);
|
|
162
|
-
|
|
170
|
+
p([
|
|
163
171
|
h({ type: String }),
|
|
164
172
|
P(C, E, c.position)
|
|
165
173
|
], r.prototype, "position", 2);
|
|
166
|
-
|
|
174
|
+
p([
|
|
167
175
|
g()
|
|
168
176
|
], r.prototype, "_toasts", 2);
|
|
169
|
-
|
|
177
|
+
p([
|
|
170
178
|
g()
|
|
171
179
|
], r.prototype, "_currentToast", 2);
|
|
172
|
-
r =
|
|
180
|
+
r = p([
|
|
173
181
|
$("pie-toast-provider")
|
|
174
182
|
], r);
|
|
175
183
|
export {
|
|
176
184
|
O as ON_TOAST_PROVIDER_QUEUE_UPDATE_EVENT,
|
|
177
|
-
|
|
185
|
+
A as PRIORITY_ORDER,
|
|
178
186
|
r as PieToastProvider,
|
|
179
187
|
c as defaultProps,
|
|
180
188
|
E as positions,
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-toast-provider",
|
|
3
3
|
"description": "PIE Design System Toast Provider built using Web Components",
|
|
4
|
-
"version": "1.1
|
|
4
|
+
"version": "1.2.1",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "https://github.com/justeattakeaway/pie",
|
|
@@ -41,13 +41,13 @@
|
|
|
41
41
|
"author": "Just Eat Takeaway.com - Design System Team",
|
|
42
42
|
"license": "Apache-2.0",
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@justeattakeaway/pie-components-config": "0.21.
|
|
45
|
-
"@justeattakeaway/pie-css": "1.
|
|
44
|
+
"@justeattakeaway/pie-components-config": "0.21.4",
|
|
45
|
+
"@justeattakeaway/pie-css": "1.7.0",
|
|
46
46
|
"@justeattakeaway/pie-monorepo-utils": "0.9.9"
|
|
47
47
|
},
|
|
48
48
|
"dependencies": {
|
|
49
|
-
"@justeattakeaway/pie-toast": "1.1
|
|
50
|
-
"@justeattakeaway/pie-webc-core": "
|
|
49
|
+
"@justeattakeaway/pie-toast": "1.2.1",
|
|
50
|
+
"@justeattakeaway/pie-webc-core": "20.0.0"
|
|
51
51
|
},
|
|
52
52
|
"customElements": "custom-elements.json",
|
|
53
53
|
"sideEffects": [
|
package/src/index.ts
CHANGED
|
@@ -140,10 +140,24 @@ export class PieToastProvider extends PieElement implements ToastProviderProps {
|
|
|
140
140
|
'pie-animation--slide-out': _currentToast === null,
|
|
141
141
|
};
|
|
142
142
|
|
|
143
|
+
const isError = _currentToast?.variant === 'error';
|
|
144
|
+
|
|
145
|
+
// The provider owns the announcement, so the rendered toast's own live region is disabled
|
|
146
|
+
// (`aria-live: off`) to prevent the message being announced twice.
|
|
147
|
+
const toastAria = { ..._currentToast?.aria, live: 'off' as const };
|
|
148
|
+
|
|
143
149
|
return html`
|
|
144
|
-
<div
|
|
150
|
+
<div
|
|
145
151
|
class=${classMap(classes)}
|
|
146
152
|
data-test-id="pie-toast-provider">
|
|
153
|
+
<div
|
|
154
|
+
class="c-toast-provider-announcer is-visuallyHidden"
|
|
155
|
+
role="${isError ? 'alert' : 'status'}"
|
|
156
|
+
aria-live="${isError ? 'assertive' : 'polite'}"
|
|
157
|
+
aria-atomic="true"
|
|
158
|
+
data-test-id="pie-toast-provider-announcer">
|
|
159
|
+
${_currentToast?.message ?? ''}
|
|
160
|
+
</div>
|
|
147
161
|
${_currentToast &&
|
|
148
162
|
html`
|
|
149
163
|
<pie-toast
|
|
@@ -154,7 +168,7 @@ export class PieToastProvider extends PieElement implements ToastProviderProps {
|
|
|
154
168
|
?isDismissible="${_currentToast.isDismissible}"
|
|
155
169
|
?isMultiline="${_currentToast.isMultiline}"
|
|
156
170
|
.leadingAction="${_currentToast.leadingAction}"
|
|
157
|
-
.aria="${
|
|
171
|
+
.aria="${toastAria}"
|
|
158
172
|
.duration="${typeof _currentToast.duration === 'undefined' ? nothing : _currentToast.duration}"
|
|
159
173
|
@pie-toast-close="${this._dismissToast}"
|
|
160
174
|
@pie-toast-open="${_currentToast.onPieToastOpen}"
|
package/src/toast-provider.scss
CHANGED
|
@@ -16,6 +16,10 @@
|
|
|
16
16
|
position: var(--toast-provider-position);
|
|
17
17
|
z-index: var(--toast-provider-z-index);
|
|
18
18
|
|
|
19
|
+
&-announcer {
|
|
20
|
+
@include p.visually-hidden;
|
|
21
|
+
}
|
|
22
|
+
|
|
19
23
|
&.c-toast-provider--default {
|
|
20
24
|
inset-inline-start: var(--toast-provider-offset);
|
|
21
25
|
inset-block-end: var(--toast-provider-offset);
|