@justeattakeaway/pie-notification 0.4.0 → 0.5.0
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/custom-elements.json +263 -0
- package/dist/index.d.ts +108 -1
- package/dist/index.js +169 -79
- package/dist/react.d.ts +116 -2
- package/dist/react.js +26 -10
- package/package.json +1 -1
- package/src/defs.ts +63 -0
- package/src/index.ts +133 -11
- package/src/notification.scss +27 -1
- package/src/react.ts +15 -3
package/dist/index.js
CHANGED
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { unsafeCSS as
|
|
2
|
-
import { html as
|
|
3
|
-
import { validPropertyValues as
|
|
4
|
-
import { property as
|
|
1
|
+
import { unsafeCSS as _, LitElement as N, nothing as a } from "lit";
|
|
2
|
+
import { html as l, unsafeStatic as O } from "lit/static-html.js";
|
|
3
|
+
import { validPropertyValues as m, defineCustomElement as x, dispatchCustomEvent as u } from "@justeattakeaway/pie-webc-core";
|
|
4
|
+
import { property as s, queryAssignedElements as E, state as g } from "lit/decorators.js";
|
|
5
5
|
import "@justeattakeaway/pie-icon-button";
|
|
6
6
|
import "@justeattakeaway/pie-icons-webc/IconClose";
|
|
7
7
|
import "@justeattakeaway/pie-icons-webc/IconInfoCircle";
|
|
8
8
|
import "@justeattakeaway/pie-icons-webc/IconAlertCircle";
|
|
9
9
|
import "@justeattakeaway/pie-icons-webc/IconAlertTriangle";
|
|
10
10
|
import "@justeattakeaway/pie-icons-webc/IconCheckCircle";
|
|
11
|
-
|
|
11
|
+
import "@justeattakeaway/pie-button";
|
|
12
|
+
const k = ["neutral", "neutral-alternative", "info", "success", "warning", "error"], A = ["h2", "h3", "h4", "h5", "h6"], o = "pie-notification", h = "c-notification", z = `${o}-close`, S = `${o}-open`, V = `${o}-leading-action-click`, w = `${o}-supporting-action-click`, T = `*,*:after,*:before{box-sizing:inherit}.c-notification{--notification-border-radius: var(--dt-radius-rounded-c);--notification-background-color: var(--dt-color-container-subtle);--notification-direction: column;--notification-icon-size-override: 22px;--notification-heading-font-size: calc(var(--dt-font-size-20) * 1px);--notification-heading-line-height: calc(var(--dt-font-size-20-line-height) * 1px);--notification-font-size: calc(var(--dt-font-size-16) * 1px);--notification-line-height: calc(var(--dt-font-size-16-line-height) * 1px);--notification-icon-fill: var(--dt-color-content-default);padding:var(--dt-spacing-d);border-radius:var(--notification-border-radius);background-color:var(--notification-background-color);position:relative;display:flex;flex-direction:var(--notification-direction);gap:var(--dt-spacing-d);font-size:var(--notification-font-size);line-height:var(--notification-line-height)}.c-notification h1,.c-notification h2,.c-notification h3,.c-notification h4,.c-notification h5,.c-notification h6{margin:0;font-size:var(--notification-heading-font-size);line-height:var(--notification-heading-line-height)}.c-notification[isCompact]{--notification-direction: row}.c-notification[variant=neutral-alternative]{--notification-background-color: var(--dt-color-container-default)}.c-notification[variant=info]{--notification-background-color: var(--dt-color-support-info-02);--notification-icon-fill: var(--dt-color-blue)}.c-notification[variant=success]{--notification-background-color: var(--dt-color-support-positive-02)}.c-notification[variant=warning]{--notification-background-color: var(--dt-color-support-warning-02)}.c-notification[variant=error]{--notification-background-color: var(--dt-color-support-error-02);--notification-icon-fill: var(--dt-color-red)}.c-notification-content-section{display:flex;flex-direction:row}.c-notification-content-section article[hasGutter]{padding-inline-end:var(--dt-spacing-e)}.c-notification-content-section .has-icon{display:block ruby;margin-inline-end:var(--dt-spacing-c)}.c-notification-heading-icon{padding-block-start:var(--dt-spacing-a);color:var(--notification-icon-fill)}.c-notification-icon-close{position:absolute;inset-block-start:var(--dt-spacing-b);inset-inline-end:var(--dt-spacing-b)}.c-notification-footer{display:flex;flex-direction:row;justify-content:flex-end;gap:var(--dt-spacing-d)}.c-notification-footer[isCompact]{align-self:flex-end}@media (max-width: 640px){.c-notification-footer[isStacked]{flex-direction:column}}
|
|
12
13
|
`;
|
|
13
|
-
var
|
|
14
|
-
for (var
|
|
15
|
-
(
|
|
16
|
-
return c &&
|
|
14
|
+
var B = Object.defineProperty, D = Object.getOwnPropertyDescriptor, e = (f, t, i, c) => {
|
|
15
|
+
for (var r = c > 1 ? void 0 : c ? D(t, i) : t, d = f.length - 1, p; d >= 0; d--)
|
|
16
|
+
(p = f[d]) && (r = (c ? p(t, i, r) : p(r)) || r);
|
|
17
|
+
return c && r && B(t, i, r), r;
|
|
17
18
|
};
|
|
18
|
-
|
|
19
|
-
class n extends $ {
|
|
19
|
+
class n extends N {
|
|
20
20
|
constructor() {
|
|
21
|
-
super(...arguments), this.isOpen = !0, this.variant = "neutral", this.isCompact = !1, this.headingLevel = "h2", this.hideIcon = !1, this.hideCloseIcon = !1, this._hasExternalIcon = !1, this._hasIconClass = !1;
|
|
21
|
+
super(...arguments), this.isOpen = !0, this.variant = "neutral", this.isDismissible = !0, this.isCompact = !1, this.headingLevel = "h2", this.hideIcon = !1, this.hideCloseIcon = !1, this.hasStackedActions = !1, this._hasExternalIcon = !1, this._hasIconClass = !1, this._hasContentGutter = !1;
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
24
|
* Lifecycle method executed after component renders.
|
|
@@ -30,8 +30,16 @@ class n extends $ {
|
|
|
30
30
|
* Lifecycle method executed when component is about to update.
|
|
31
31
|
* It update icon properties if variant has changes.
|
|
32
32
|
*/
|
|
33
|
-
willUpdate(
|
|
34
|
-
|
|
33
|
+
willUpdate(t) {
|
|
34
|
+
t.has("variant") && this.updateIconProperties();
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Lifecycle method executed when component is updated.
|
|
38
|
+
* It dispatches an event if notification is opened.
|
|
39
|
+
* It applies a gutter if there's no heading content in order to avoid the close button overlap the content.
|
|
40
|
+
*/
|
|
41
|
+
updated(t) {
|
|
42
|
+
t.has("isOpen") && this.isOpen && u(this, S, { targetNotification: this }), (t.has("heading") || t.has("isDismissible") || t.has("isCompact")) && (this._hasContentGutter = (this.heading === "" || this.heading === void 0) && this.isDismissible && !this.isCompact);
|
|
35
43
|
}
|
|
36
44
|
/**
|
|
37
45
|
* Method responsible to check if an external icon has been provided.
|
|
@@ -48,9 +56,12 @@ class n extends $ {
|
|
|
48
56
|
*
|
|
49
57
|
* @private
|
|
50
58
|
*/
|
|
51
|
-
renderFooter() {
|
|
52
|
-
return
|
|
53
|
-
<footer class="${
|
|
59
|
+
renderFooter(t, i) {
|
|
60
|
+
return l`
|
|
61
|
+
<footer class="${h}-footer" data-test-id="${o}-footer" ?isCompact="${this.isCompact}" ?isStacked="${this.hasStackedActions && !this.isCompact}">
|
|
62
|
+
${i ? this.renderActionButton(i, "supporting") : a}
|
|
63
|
+
${t ? this.renderActionButton(t, "leading") : a}
|
|
64
|
+
</footer>
|
|
54
65
|
`;
|
|
55
66
|
}
|
|
56
67
|
/**
|
|
@@ -62,10 +73,10 @@ class n extends $ {
|
|
|
62
73
|
*
|
|
63
74
|
* @private
|
|
64
75
|
*/
|
|
65
|
-
renderNotificationHeading(
|
|
66
|
-
return
|
|
67
|
-
<header class="${
|
|
68
|
-
<${
|
|
76
|
+
renderNotificationHeading(t, i) {
|
|
77
|
+
return l`
|
|
78
|
+
<header class="${h}-header" data-test-id="${o}-header">
|
|
79
|
+
<${i} class="${h}-heading" data-test-id="${o}-heading">${t}</${i}>
|
|
69
80
|
</header>
|
|
70
81
|
`;
|
|
71
82
|
}
|
|
@@ -76,8 +87,8 @@ class n extends $ {
|
|
|
76
87
|
*
|
|
77
88
|
* @private
|
|
78
89
|
*/
|
|
79
|
-
variantHasDefaultIcon(
|
|
80
|
-
return ["info", "success", "warning", "error"].includes(
|
|
90
|
+
variantHasDefaultIcon(t) {
|
|
91
|
+
return ["info", "success", "warning", "error"].includes(t);
|
|
81
92
|
}
|
|
82
93
|
/**
|
|
83
94
|
* Util method that returns an icon from a variant that has default icon.
|
|
@@ -86,18 +97,18 @@ class n extends $ {
|
|
|
86
97
|
*
|
|
87
98
|
* @private
|
|
88
99
|
*/
|
|
89
|
-
getDefaultVariantIcon(
|
|
90
|
-
switch (
|
|
100
|
+
getDefaultVariantIcon(t) {
|
|
101
|
+
switch (t) {
|
|
91
102
|
case "info":
|
|
92
|
-
return
|
|
103
|
+
return l`<icon-info-circle size="s" data-test-id="${o}-heading-icon-info"></icon-info-circle>`;
|
|
93
104
|
case "success":
|
|
94
|
-
return
|
|
105
|
+
return l`<icon-check-circle size="s" data-test-id="${o}-heading-icon-success"></icon-check-circle>`;
|
|
95
106
|
case "warning":
|
|
96
|
-
return
|
|
107
|
+
return l`<icon-alert-triangle size="s" data-test-id="${o}-heading-icon-warning"></icon-alert-triangle>`;
|
|
97
108
|
case "error":
|
|
98
|
-
return
|
|
109
|
+
return l`<icon-alert-circle size="s" data-test-id="${o}-heading-icon-error"></icon-alert-circle>`;
|
|
99
110
|
default:
|
|
100
|
-
return
|
|
111
|
+
return a;
|
|
101
112
|
}
|
|
102
113
|
}
|
|
103
114
|
/**
|
|
@@ -108,8 +119,8 @@ class n extends $ {
|
|
|
108
119
|
*
|
|
109
120
|
* @private
|
|
110
121
|
*/
|
|
111
|
-
renderIconVariant(
|
|
112
|
-
return this.variantHasDefaultIcon(
|
|
122
|
+
renderIconVariant(t) {
|
|
123
|
+
return this.variantHasDefaultIcon(t) ? this.getDefaultVariantIcon(t) : a;
|
|
113
124
|
}
|
|
114
125
|
/**
|
|
115
126
|
* Template for the heading icon area.
|
|
@@ -121,10 +132,10 @@ class n extends $ {
|
|
|
121
132
|
*
|
|
122
133
|
* @private
|
|
123
134
|
*/
|
|
124
|
-
renderIcon(
|
|
125
|
-
return
|
|
126
|
-
<div data-test-id="${o}-icon-area" class="${c ? "has-icon " : ""}${
|
|
127
|
-
${
|
|
135
|
+
renderIcon(t, i, c) {
|
|
136
|
+
return l`
|
|
137
|
+
<div data-test-id="${o}-icon-area" class="${c ? "has-icon " : ""}${h}-heading-icon">
|
|
138
|
+
${i ? a : this.renderIconVariant(t)}
|
|
128
139
|
<slot name="icon"></slot>
|
|
129
140
|
</div>
|
|
130
141
|
`;
|
|
@@ -136,78 +147,157 @@ class n extends $ {
|
|
|
136
147
|
* @private
|
|
137
148
|
*/
|
|
138
149
|
renderCloseButton() {
|
|
139
|
-
return
|
|
150
|
+
return l`
|
|
140
151
|
<pie-icon-button
|
|
141
152
|
variant="ghost-secondary"
|
|
142
153
|
size="small"
|
|
143
|
-
class="${
|
|
154
|
+
class="${h}-icon-close"
|
|
144
155
|
data-test-id="${o}-icon-close"
|
|
156
|
+
@click="${this.handleCloseButton}"
|
|
145
157
|
>
|
|
146
158
|
<icon-close></icon-close>
|
|
147
159
|
</pie-icon-button>`;
|
|
148
160
|
}
|
|
161
|
+
/**
|
|
162
|
+
* It handles the action when user clicks in the close button.
|
|
163
|
+
* Also triggers an event when is executed.
|
|
164
|
+
*
|
|
165
|
+
* @private
|
|
166
|
+
*/
|
|
167
|
+
handleCloseButton() {
|
|
168
|
+
this.closeNotificationComponent(), u(this, z, { targetNotification: this });
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Util method responsible to close the component.
|
|
172
|
+
*
|
|
173
|
+
* @private
|
|
174
|
+
*/
|
|
175
|
+
closeNotificationComponent() {
|
|
176
|
+
this.isOpen = !1;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* It handle the action button action.
|
|
180
|
+
* Also triggers an event according to its `actionType`.
|
|
181
|
+
*
|
|
182
|
+
* @param {'leading' | 'supporting'} actionType
|
|
183
|
+
*
|
|
184
|
+
* @private
|
|
185
|
+
*/
|
|
186
|
+
handleActionClick(t) {
|
|
187
|
+
u(this, t === "leading" ? V : w, { targetNotification: this });
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Render the action button depending on action type and its action.
|
|
191
|
+
*
|
|
192
|
+
* @param {ActionProps} action - The action properties.
|
|
193
|
+
* @param {'leading' | 'supporting'} actionType - The type of the action.
|
|
194
|
+
*
|
|
195
|
+
* @returns {TemplateResult | typeof nothing} - The rendered action button or nothing if the action text is not defined.
|
|
196
|
+
* @private
|
|
197
|
+
*/
|
|
198
|
+
renderActionButton(t, i) {
|
|
199
|
+
const { text: c, ariaLabel: r } = t;
|
|
200
|
+
return c ? l`
|
|
201
|
+
<pie-button
|
|
202
|
+
variant="${i === "leading" ? "primary" : "ghost"}"
|
|
203
|
+
size="small-productive"
|
|
204
|
+
aria-label="${r || a}"
|
|
205
|
+
@click="${() => this.handleActionClick(i)}"
|
|
206
|
+
data-test-id="${o}-${i}-action"
|
|
207
|
+
?isFullWidth="${this.hasStackedActions}"
|
|
208
|
+
type="button">
|
|
209
|
+
${c}
|
|
210
|
+
</pie-button>
|
|
211
|
+
` : a;
|
|
212
|
+
}
|
|
149
213
|
render() {
|
|
150
214
|
const {
|
|
151
|
-
variant:
|
|
152
|
-
heading:
|
|
215
|
+
variant: t,
|
|
216
|
+
heading: i,
|
|
153
217
|
headingLevel: c,
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
218
|
+
isDismissible: r,
|
|
219
|
+
isCompact: d,
|
|
220
|
+
_hasExternalIcon: p,
|
|
221
|
+
hideIcon: C,
|
|
222
|
+
_hasIconClass: $,
|
|
223
|
+
leadingAction: v,
|
|
224
|
+
supportingAction: I,
|
|
225
|
+
isOpen: b,
|
|
226
|
+
_hasContentGutter: y
|
|
158
227
|
} = this;
|
|
159
|
-
return
|
|
160
|
-
<div data-test-id="${o}" class="${
|
|
161
|
-
${
|
|
228
|
+
return b ? l`
|
|
229
|
+
<div data-test-id="${o}" class="${h}" variant="${t}" ?isCompact="${d}">
|
|
230
|
+
${r && !d ? this.renderCloseButton() : a}
|
|
162
231
|
|
|
163
|
-
<section class="${
|
|
164
|
-
${
|
|
165
|
-
<article>
|
|
166
|
-
${
|
|
232
|
+
<section class="${h}-content-section">
|
|
233
|
+
${C ? a : this.renderIcon(t, p, $)}
|
|
234
|
+
<article ?hasGutter="${y}">
|
|
235
|
+
${i ? this.renderNotificationHeading(i, O(c)) : a}
|
|
167
236
|
<slot></slot>
|
|
168
237
|
</article>
|
|
169
238
|
</section>
|
|
170
239
|
|
|
171
|
-
${this.renderFooter()}
|
|
172
|
-
</div
|
|
240
|
+
${v ? this.renderFooter(v, I) : a}
|
|
241
|
+
</div>` : a;
|
|
173
242
|
}
|
|
174
243
|
}
|
|
175
|
-
n.styles =
|
|
176
|
-
|
|
177
|
-
|
|
244
|
+
n.styles = _(T);
|
|
245
|
+
e([
|
|
246
|
+
s({ type: Boolean })
|
|
178
247
|
], n.prototype, "isOpen", 2);
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
248
|
+
e([
|
|
249
|
+
s(),
|
|
250
|
+
m(o, k, "neutral")
|
|
182
251
|
], n.prototype, "variant", 2);
|
|
183
|
-
|
|
184
|
-
|
|
252
|
+
e([
|
|
253
|
+
s({ type: Boolean })
|
|
254
|
+
], n.prototype, "isDismissible", 2);
|
|
255
|
+
e([
|
|
256
|
+
s({ type: Boolean })
|
|
185
257
|
], n.prototype, "isCompact", 2);
|
|
186
|
-
|
|
187
|
-
|
|
258
|
+
e([
|
|
259
|
+
s({ type: String })
|
|
188
260
|
], n.prototype, "heading", 2);
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
261
|
+
e([
|
|
262
|
+
s(),
|
|
263
|
+
m(o, A, "h2")
|
|
192
264
|
], n.prototype, "headingLevel", 2);
|
|
193
|
-
|
|
194
|
-
|
|
265
|
+
e([
|
|
266
|
+
s({ type: Boolean })
|
|
195
267
|
], n.prototype, "hideIcon", 2);
|
|
196
|
-
|
|
197
|
-
|
|
268
|
+
e([
|
|
269
|
+
s({ type: Boolean })
|
|
198
270
|
], n.prototype, "hideCloseIcon", 2);
|
|
199
|
-
|
|
200
|
-
|
|
271
|
+
e([
|
|
272
|
+
s({ type: Object })
|
|
273
|
+
], n.prototype, "leadingAction", 2);
|
|
274
|
+
e([
|
|
275
|
+
s({ type: Object })
|
|
276
|
+
], n.prototype, "supportingAction", 2);
|
|
277
|
+
e([
|
|
278
|
+
s({ type: Boolean })
|
|
279
|
+
], n.prototype, "hasStackedActions", 2);
|
|
280
|
+
e([
|
|
281
|
+
E({ slot: "icon" })
|
|
201
282
|
], n.prototype, "_iconSlot", 2);
|
|
202
|
-
|
|
203
|
-
|
|
283
|
+
e([
|
|
284
|
+
g()
|
|
204
285
|
], n.prototype, "_hasExternalIcon", 2);
|
|
205
|
-
|
|
206
|
-
|
|
286
|
+
e([
|
|
287
|
+
g()
|
|
207
288
|
], n.prototype, "_hasIconClass", 2);
|
|
208
|
-
|
|
289
|
+
e([
|
|
290
|
+
g()
|
|
291
|
+
], n.prototype, "_hasContentGutter", 2);
|
|
292
|
+
x(o, n);
|
|
209
293
|
export {
|
|
294
|
+
z as ON_NOTIFICATION_CLOSE_EVENT,
|
|
295
|
+
V as ON_NOTIFICATION_LEADING_ACTION_CLICK_EVENT,
|
|
296
|
+
S as ON_NOTIFICATION_OPEN_EVENT,
|
|
297
|
+
w as ON_NOTIFICATION_SUPPORTING_ACTION_CLICK_EVENT,
|
|
210
298
|
n as PieNotification,
|
|
211
|
-
|
|
212
|
-
|
|
299
|
+
h as componentClass,
|
|
300
|
+
o as componentSelector,
|
|
301
|
+
A as headingLevels,
|
|
302
|
+
k as variants
|
|
213
303
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -1,9 +1,25 @@
|
|
|
1
1
|
import type { CSSResult } from 'lit';
|
|
2
2
|
import type { LitElement } from 'lit';
|
|
3
|
+
import type { nothing } from 'lit';
|
|
3
4
|
import type { PropertyValues } from 'lit';
|
|
4
5
|
import * as React_2 from 'react';
|
|
5
6
|
import type { TemplateResult } from 'lit';
|
|
6
7
|
|
|
8
|
+
export declare type ActionProps = {
|
|
9
|
+
/**
|
|
10
|
+
* The text to display inside the button.
|
|
11
|
+
*/
|
|
12
|
+
text: string;
|
|
13
|
+
/**
|
|
14
|
+
* The ARIA label for the button.
|
|
15
|
+
*/
|
|
16
|
+
ariaLabel?: string;
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
export declare const componentClass = "c-notification";
|
|
20
|
+
|
|
21
|
+
export declare const componentSelector = "pie-notification";
|
|
22
|
+
|
|
7
23
|
export declare const headingLevels: readonly ["h2", "h3", "h4", "h5", "h6"];
|
|
8
24
|
|
|
9
25
|
export declare interface NotificationProps {
|
|
@@ -11,6 +27,10 @@ export declare interface NotificationProps {
|
|
|
11
27
|
* Set the variant of the notification.
|
|
12
28
|
*/
|
|
13
29
|
variant?: typeof variants[number];
|
|
30
|
+
/**
|
|
31
|
+
* When true, allows dismissing the notification by clicking on the close button.
|
|
32
|
+
*/
|
|
33
|
+
isDismissible?: boolean;
|
|
14
34
|
/**
|
|
15
35
|
* When true, the footer aligns to the header and icons which makes the component compact.
|
|
16
36
|
*/
|
|
@@ -31,24 +51,73 @@ export declare interface NotificationProps {
|
|
|
31
51
|
* When true, the notification is set to be open and visible.
|
|
32
52
|
*/
|
|
33
53
|
isOpen?: boolean;
|
|
54
|
+
/**
|
|
55
|
+
* The leading action for the notification.
|
|
56
|
+
*/
|
|
57
|
+
leadingAction?: ActionProps;
|
|
58
|
+
/**
|
|
59
|
+
* The supporting action for the notification.
|
|
60
|
+
*/
|
|
61
|
+
supportingAction?: ActionProps;
|
|
62
|
+
/**
|
|
63
|
+
* When true, the notification will stack the action buttons on narrow screens.
|
|
64
|
+
*/
|
|
65
|
+
hasStackedActions?: boolean;
|
|
34
66
|
}
|
|
35
67
|
|
|
36
|
-
|
|
68
|
+
/**
|
|
69
|
+
* Event name for when the notification is closed.
|
|
70
|
+
*
|
|
71
|
+
* @constant
|
|
72
|
+
*/
|
|
73
|
+
export declare const ON_NOTIFICATION_CLOSE_EVENT: string;
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* Event name for when the notification leading action is clicked.
|
|
77
|
+
*
|
|
78
|
+
* @constant
|
|
79
|
+
*/
|
|
80
|
+
export declare const ON_NOTIFICATION_LEADING_ACTION_CLICK_EVENT: string;
|
|
81
|
+
|
|
82
|
+
/**
|
|
83
|
+
* Event name for when the notification is opened.
|
|
84
|
+
*
|
|
85
|
+
* @constant
|
|
86
|
+
*/
|
|
87
|
+
export declare const ON_NOTIFICATION_OPEN_EVENT: string;
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Event name for when the notification supporting action is clicked.
|
|
91
|
+
*
|
|
92
|
+
* @constant
|
|
93
|
+
*/
|
|
94
|
+
export declare const ON_NOTIFICATION_SUPPORTING_ACTION_CLICK_EVENT: string;
|
|
95
|
+
|
|
96
|
+
export declare const PieNotification: React_2.ForwardRefExoticComponent<NotificationProps & React_2.RefAttributes<PieNotification_2> & PieNotificationEvents & ReactBaseType>;
|
|
37
97
|
|
|
38
98
|
/**
|
|
39
99
|
* @tagname pie-notification
|
|
100
|
+
* @event {CustomEvent} pie-notification-leading-action-click - When the notification leading action is clicked.
|
|
101
|
+
* @event {CustomEvent} pie-notification-supporting-action-click - When the notification supporting action is clicked.
|
|
102
|
+
* @event {CustomEvent} pie-notification-close - When the notification is closed.
|
|
103
|
+
* @event {CustomEvent} pie-notification-open - When the notification is opened.
|
|
40
104
|
*/
|
|
41
105
|
declare class PieNotification_2 extends LitElement implements NotificationProps {
|
|
42
106
|
isOpen: boolean;
|
|
43
107
|
variant: NonNullable<NotificationProps['variant']>;
|
|
108
|
+
isDismissible: boolean;
|
|
44
109
|
isCompact: boolean;
|
|
45
110
|
heading: string;
|
|
46
111
|
headingLevel: NonNullable<NotificationProps['headingLevel']>;
|
|
47
112
|
hideIcon: boolean;
|
|
48
113
|
hideCloseIcon: boolean;
|
|
114
|
+
leadingAction: NotificationProps['leadingAction'];
|
|
115
|
+
supportingAction: NotificationProps['supportingAction'];
|
|
116
|
+
hasStackedActions: boolean;
|
|
49
117
|
_iconSlot: Array<HTMLElement>;
|
|
50
118
|
protected _hasExternalIcon: boolean;
|
|
51
119
|
protected _hasIconClass: boolean;
|
|
120
|
+
protected _hasContentGutter: boolean;
|
|
52
121
|
static styles: CSSResult;
|
|
53
122
|
/**
|
|
54
123
|
* Lifecycle method executed after component renders.
|
|
@@ -59,6 +128,12 @@ declare class PieNotification_2 extends LitElement implements NotificationProps
|
|
|
59
128
|
* It update icon properties if variant has changes.
|
|
60
129
|
*/
|
|
61
130
|
protected willUpdate(_changedProperties: PropertyValues<this>): void;
|
|
131
|
+
/**
|
|
132
|
+
* Lifecycle method executed when component is updated.
|
|
133
|
+
* It dispatches an event if notification is opened.
|
|
134
|
+
* It applies a gutter if there's no heading content in order to avoid the close button overlap the content.
|
|
135
|
+
*/
|
|
136
|
+
protected updated(_changedProperties: PropertyValues<this>): void;
|
|
62
137
|
/**
|
|
63
138
|
* Method responsible to check if an external icon has been provided.
|
|
64
139
|
* It reads from icon slot if there is an external icon as well check if variant has default icon.
|
|
@@ -126,9 +201,48 @@ declare class PieNotification_2 extends LitElement implements NotificationProps
|
|
|
126
201
|
* @private
|
|
127
202
|
*/
|
|
128
203
|
private renderCloseButton;
|
|
129
|
-
|
|
204
|
+
/**
|
|
205
|
+
* It handles the action when user clicks in the close button.
|
|
206
|
+
* Also triggers an event when is executed.
|
|
207
|
+
*
|
|
208
|
+
* @private
|
|
209
|
+
*/
|
|
210
|
+
private handleCloseButton;
|
|
211
|
+
/**
|
|
212
|
+
* Util method responsible to close the component.
|
|
213
|
+
*
|
|
214
|
+
* @private
|
|
215
|
+
*/
|
|
216
|
+
private closeNotificationComponent;
|
|
217
|
+
/**
|
|
218
|
+
* It handle the action button action.
|
|
219
|
+
* Also triggers an event according to its `actionType`.
|
|
220
|
+
*
|
|
221
|
+
* @param {'leading' | 'supporting'} actionType
|
|
222
|
+
*
|
|
223
|
+
* @private
|
|
224
|
+
*/
|
|
225
|
+
private handleActionClick;
|
|
226
|
+
/**
|
|
227
|
+
* Render the action button depending on action type and its action.
|
|
228
|
+
*
|
|
229
|
+
* @param {ActionProps} action - The action properties.
|
|
230
|
+
* @param {'leading' | 'supporting'} actionType - The type of the action.
|
|
231
|
+
*
|
|
232
|
+
* @returns {TemplateResult | typeof nothing} - The rendered action button or nothing if the action text is not defined.
|
|
233
|
+
* @private
|
|
234
|
+
*/
|
|
235
|
+
private renderActionButton;
|
|
236
|
+
render(): typeof nothing | TemplateResult;
|
|
130
237
|
}
|
|
131
238
|
|
|
239
|
+
declare type PieNotificationEvents = {
|
|
240
|
+
onPieNotificationLeadingActionClick?: (event: CustomEvent) => void;
|
|
241
|
+
onPieNotificationSupportingActionClick?: (event: CustomEvent) => void;
|
|
242
|
+
onPieNotificationClose?: (event: CustomEvent) => void;
|
|
243
|
+
onPieNotificationOpen?: (event: CustomEvent) => void;
|
|
244
|
+
};
|
|
245
|
+
|
|
132
246
|
declare type ReactBaseType = React_2.HTMLAttributes<HTMLDivElement>;
|
|
133
247
|
|
|
134
248
|
export declare const variants: readonly ["neutral", "neutral-alternative", "info", "success", "warning", "error"];
|
package/dist/react.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as i from "react";
|
|
2
|
-
import { createComponent as
|
|
3
|
-
import { PieNotification as
|
|
4
|
-
import { headingLevels as
|
|
2
|
+
import { createComponent as o } from "@lit/react";
|
|
3
|
+
import { PieNotification as t } from "./index.js";
|
|
4
|
+
import { ON_NOTIFICATION_CLOSE_EVENT as E, ON_NOTIFICATION_LEADING_ACTION_CLICK_EVENT as A, ON_NOTIFICATION_OPEN_EVENT as g, ON_NOTIFICATION_SUPPORTING_ACTION_CLICK_EVENT as L, componentClass as d, componentSelector as k, headingLevels as F, variants as S } from "./index.js";
|
|
5
5
|
import "lit";
|
|
6
6
|
import "lit/static-html.js";
|
|
7
7
|
import "@justeattakeaway/pie-webc-core";
|
|
@@ -12,15 +12,31 @@ import "@justeattakeaway/pie-icons-webc/IconInfoCircle";
|
|
|
12
12
|
import "@justeattakeaway/pie-icons-webc/IconAlertCircle";
|
|
13
13
|
import "@justeattakeaway/pie-icons-webc/IconAlertTriangle";
|
|
14
14
|
import "@justeattakeaway/pie-icons-webc/IconCheckCircle";
|
|
15
|
-
|
|
15
|
+
import "@justeattakeaway/pie-button";
|
|
16
|
+
const n = o({
|
|
16
17
|
displayName: "PieNotification",
|
|
17
|
-
elementClass:
|
|
18
|
+
elementClass: t,
|
|
18
19
|
react: i,
|
|
19
20
|
tagName: "pie-notification",
|
|
20
|
-
events: {
|
|
21
|
-
|
|
21
|
+
events: {
|
|
22
|
+
onPieNotificationLeadingActionClick: "pie-notification-leading-action-click",
|
|
23
|
+
// When the notification leading action is clicked.
|
|
24
|
+
onPieNotificationSupportingActionClick: "pie-notification-supporting-action-click",
|
|
25
|
+
// When the notification supporting action is clicked.
|
|
26
|
+
onPieNotificationClose: "pie-notification-close",
|
|
27
|
+
// When the notification is closed.
|
|
28
|
+
onPieNotificationOpen: "pie-notification-open"
|
|
29
|
+
// When the notification is opened.
|
|
30
|
+
}
|
|
31
|
+
}), T = n;
|
|
22
32
|
export {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
33
|
+
E as ON_NOTIFICATION_CLOSE_EVENT,
|
|
34
|
+
A as ON_NOTIFICATION_LEADING_ACTION_CLICK_EVENT,
|
|
35
|
+
g as ON_NOTIFICATION_OPEN_EVENT,
|
|
36
|
+
L as ON_NOTIFICATION_SUPPORTING_ACTION_CLICK_EVENT,
|
|
37
|
+
T as PieNotification,
|
|
38
|
+
d as componentClass,
|
|
39
|
+
k as componentSelector,
|
|
40
|
+
F as headingLevels,
|
|
41
|
+
S as variants
|
|
26
42
|
};
|
package/package.json
CHANGED
package/src/defs.ts
CHANGED
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
export const variants = ['neutral', 'neutral-alternative', 'info', 'success', 'warning', 'error'] as const;
|
|
2
2
|
export const headingLevels = ['h2', 'h3', 'h4', 'h5', 'h6'] as const;
|
|
3
3
|
|
|
4
|
+
export type ActionProps = {
|
|
5
|
+
/**
|
|
6
|
+
* The text to display inside the button.
|
|
7
|
+
*/
|
|
8
|
+
text: string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The ARIA label for the button.
|
|
12
|
+
*/
|
|
13
|
+
ariaLabel?: string;
|
|
14
|
+
};
|
|
15
|
+
|
|
4
16
|
export interface NotificationProps {
|
|
5
17
|
/**
|
|
6
18
|
* Set the variant of the notification.
|
|
7
19
|
*/
|
|
8
20
|
variant?: typeof variants[number];
|
|
9
21
|
|
|
22
|
+
/**
|
|
23
|
+
* When true, allows dismissing the notification by clicking on the close button.
|
|
24
|
+
*/
|
|
25
|
+
isDismissible?: boolean;
|
|
26
|
+
|
|
10
27
|
/**
|
|
11
28
|
* When true, the footer aligns to the header and icons which makes the component compact.
|
|
12
29
|
*/
|
|
@@ -31,4 +48,50 @@ export interface NotificationProps {
|
|
|
31
48
|
* When true, the notification is set to be open and visible.
|
|
32
49
|
*/
|
|
33
50
|
isOpen?: boolean;
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* The leading action for the notification.
|
|
54
|
+
*/
|
|
55
|
+
leadingAction?: ActionProps;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The supporting action for the notification.
|
|
59
|
+
*/
|
|
60
|
+
supportingAction?: ActionProps;
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* When true, the notification will stack the action buttons on narrow screens.
|
|
64
|
+
*/
|
|
65
|
+
hasStackedActions?: boolean;
|
|
34
66
|
}
|
|
67
|
+
|
|
68
|
+
export const componentSelector = 'pie-notification';
|
|
69
|
+
export const componentClass = 'c-notification';
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Event name for when the notification is closed.
|
|
73
|
+
*
|
|
74
|
+
* @constant
|
|
75
|
+
*/
|
|
76
|
+
export const ON_NOTIFICATION_CLOSE_EVENT = `${componentSelector}-close`;
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Event name for when the notification is opened.
|
|
80
|
+
*
|
|
81
|
+
* @constant
|
|
82
|
+
*/
|
|
83
|
+
export const ON_NOTIFICATION_OPEN_EVENT = `${componentSelector}-open`;
|
|
84
|
+
|
|
85
|
+
/**
|
|
86
|
+
* Event name for when the notification leading action is clicked.
|
|
87
|
+
*
|
|
88
|
+
* @constant
|
|
89
|
+
*/
|
|
90
|
+
export const ON_NOTIFICATION_LEADING_ACTION_CLICK_EVENT = `${componentSelector}-leading-action-click`;
|
|
91
|
+
|
|
92
|
+
/**
|
|
93
|
+
* Event name for when the notification supporting action is clicked.
|
|
94
|
+
*
|
|
95
|
+
* @constant
|
|
96
|
+
*/
|
|
97
|
+
export const ON_NOTIFICATION_SUPPORTING_ACTION_CLICK_EVENT = `${componentSelector}-supporting-action-click`;
|