@justeattakeaway/pie-notification 0.7.0 → 0.9.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 +3 -112
- package/dist/index.d.ts +8 -47
- package/dist/index.js +77 -133
- package/dist/react.d.ts +8 -47
- package/package.json +4 -4
- package/src/defs.ts +6 -5
- package/src/index.ts +28 -94
- package/src/notification.scss +19 -15
package/custom-elements.json
CHANGED
|
@@ -217,7 +217,7 @@
|
|
|
217
217
|
"kind": "field",
|
|
218
218
|
"name": "heading",
|
|
219
219
|
"type": {
|
|
220
|
-
"text": "string"
|
|
220
|
+
"text": "string | undefined"
|
|
221
221
|
},
|
|
222
222
|
"privacy": "public",
|
|
223
223
|
"attribute": "heading"
|
|
@@ -277,49 +277,10 @@
|
|
|
277
277
|
"text": "Array<HTMLElement>"
|
|
278
278
|
}
|
|
279
279
|
},
|
|
280
|
-
{
|
|
281
|
-
"kind": "field",
|
|
282
|
-
"name": "_hasExternalIcon",
|
|
283
|
-
"type": {
|
|
284
|
-
"text": "boolean"
|
|
285
|
-
},
|
|
286
|
-
"privacy": "protected",
|
|
287
|
-
"default": "false"
|
|
288
|
-
},
|
|
289
|
-
{
|
|
290
|
-
"kind": "field",
|
|
291
|
-
"name": "_hasIconClass",
|
|
292
|
-
"type": {
|
|
293
|
-
"text": "boolean"
|
|
294
|
-
},
|
|
295
|
-
"privacy": "protected",
|
|
296
|
-
"default": "false"
|
|
297
|
-
},
|
|
298
|
-
{
|
|
299
|
-
"kind": "method",
|
|
300
|
-
"name": "updateIconProperties",
|
|
301
|
-
"privacy": "private",
|
|
302
|
-
"description": "Method responsible to check if an external icon has been provided.\nIt reads from icon slot if there is an external icon as well check if variant has default icon."
|
|
303
|
-
},
|
|
304
280
|
{
|
|
305
281
|
"kind": "method",
|
|
306
282
|
"name": "renderFooter",
|
|
307
283
|
"privacy": "private",
|
|
308
|
-
"parameters": [
|
|
309
|
-
{
|
|
310
|
-
"name": "leadingAction",
|
|
311
|
-
"type": {
|
|
312
|
-
"text": "ActionProps"
|
|
313
|
-
}
|
|
314
|
-
},
|
|
315
|
-
{
|
|
316
|
-
"name": "supportingAction",
|
|
317
|
-
"optional": true,
|
|
318
|
-
"type": {
|
|
319
|
-
"text": "ActionProps"
|
|
320
|
-
}
|
|
321
|
-
}
|
|
322
|
-
],
|
|
323
284
|
"description": "Template for the footer area\nCalled within the main render function."
|
|
324
285
|
},
|
|
325
286
|
{
|
|
@@ -331,64 +292,14 @@
|
|
|
331
292
|
"text": "TemplateResult"
|
|
332
293
|
}
|
|
333
294
|
},
|
|
334
|
-
"parameters": [
|
|
335
|
-
{
|
|
336
|
-
"name": "heading",
|
|
337
|
-
"type": {
|
|
338
|
-
"text": "NotificationProps['heading']"
|
|
339
|
-
}
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
"name": "headingTag",
|
|
343
|
-
"type": {
|
|
344
|
-
"text": "StaticValue"
|
|
345
|
-
}
|
|
346
|
-
}
|
|
347
|
-
],
|
|
348
295
|
"description": "Template for the header area\nCalled within the main render function."
|
|
349
296
|
},
|
|
350
|
-
{
|
|
351
|
-
"kind": "method",
|
|
352
|
-
"name": "variantHasDefaultIcon",
|
|
353
|
-
"privacy": "private",
|
|
354
|
-
"parameters": [
|
|
355
|
-
{
|
|
356
|
-
"name": "variant",
|
|
357
|
-
"type": {
|
|
358
|
-
"text": "NonNullable<NotificationProps['variant']>"
|
|
359
|
-
}
|
|
360
|
-
}
|
|
361
|
-
],
|
|
362
|
-
"description": "Util method that returns a boolean if variant has a default icon."
|
|
363
|
-
},
|
|
364
297
|
{
|
|
365
298
|
"kind": "method",
|
|
366
299
|
"name": "getDefaultVariantIcon",
|
|
367
300
|
"privacy": "private",
|
|
368
|
-
"parameters": [
|
|
369
|
-
{
|
|
370
|
-
"name": "variant",
|
|
371
|
-
"type": {
|
|
372
|
-
"text": "NonNullable<NotificationProps['variant']>"
|
|
373
|
-
}
|
|
374
|
-
}
|
|
375
|
-
],
|
|
376
301
|
"description": "Util method that returns an icon from a variant that has default icon."
|
|
377
302
|
},
|
|
378
|
-
{
|
|
379
|
-
"kind": "method",
|
|
380
|
-
"name": "renderIconVariant",
|
|
381
|
-
"privacy": "private",
|
|
382
|
-
"parameters": [
|
|
383
|
-
{
|
|
384
|
-
"name": "variant",
|
|
385
|
-
"type": {
|
|
386
|
-
"text": "NonNullable<NotificationProps['variant']>"
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
],
|
|
390
|
-
"description": "Util method that returns a template with a default icon according to the chosen variant.\nCalled within the renderIcon method."
|
|
391
|
-
},
|
|
392
303
|
{
|
|
393
304
|
"kind": "method",
|
|
394
305
|
"name": "renderIcon",
|
|
@@ -398,27 +309,7 @@
|
|
|
398
309
|
"text": "TemplateResult | typeof nothing"
|
|
399
310
|
}
|
|
400
311
|
},
|
|
401
|
-
"
|
|
402
|
-
{
|
|
403
|
-
"name": "variant",
|
|
404
|
-
"type": {
|
|
405
|
-
"text": "NonNullable<NotificationProps['variant']>"
|
|
406
|
-
}
|
|
407
|
-
},
|
|
408
|
-
{
|
|
409
|
-
"name": "hasExternalIcon",
|
|
410
|
-
"type": {
|
|
411
|
-
"text": "boolean"
|
|
412
|
-
}
|
|
413
|
-
},
|
|
414
|
-
{
|
|
415
|
-
"name": "hasIconClass",
|
|
416
|
-
"type": {
|
|
417
|
-
"text": "boolean"
|
|
418
|
-
}
|
|
419
|
-
}
|
|
420
|
-
],
|
|
421
|
-
"description": "Template for the heading icon area.\nIt can return an icon provided externally via named slot or it can return an default icon according to the chosen variant.\nCalled within the main render function."
|
|
312
|
+
"description": "Template for the heading icon area.\nIt can return an icon provided externally via named slot or it can return a default icon according to the chosen variant if defined.\nCalled within the main render function."
|
|
422
313
|
},
|
|
423
314
|
{
|
|
424
315
|
"kind": "method",
|
|
@@ -545,7 +436,7 @@
|
|
|
545
436
|
{
|
|
546
437
|
"name": "heading",
|
|
547
438
|
"type": {
|
|
548
|
-
"text": "string"
|
|
439
|
+
"text": "string | undefined"
|
|
549
440
|
},
|
|
550
441
|
"fieldName": "heading"
|
|
551
442
|
},
|
package/dist/index.d.ts
CHANGED
|
@@ -33,11 +33,11 @@ export declare const headingLevels: readonly ["h2", "h3", "h4", "h5", "h6"];
|
|
|
33
33
|
|
|
34
34
|
export declare interface NotificationProps {
|
|
35
35
|
/**
|
|
36
|
-
*
|
|
36
|
+
* Sets the variant of the notification.
|
|
37
37
|
*/
|
|
38
38
|
variant?: typeof variants[number];
|
|
39
39
|
/**
|
|
40
|
-
*
|
|
40
|
+
* Defines the proper styles, whether the component appears within the content or at the top of the interface
|
|
41
41
|
*/
|
|
42
42
|
position?: typeof positions[number];
|
|
43
43
|
/**
|
|
@@ -45,7 +45,7 @@ export declare interface NotificationProps {
|
|
|
45
45
|
*/
|
|
46
46
|
isDismissible?: boolean;
|
|
47
47
|
/**
|
|
48
|
-
* When true, the footer
|
|
48
|
+
* When true, aligns the footer with the header and icons, making the component compact.
|
|
49
49
|
*/
|
|
50
50
|
isCompact?: boolean;
|
|
51
51
|
/**
|
|
@@ -57,7 +57,7 @@ export declare interface NotificationProps {
|
|
|
57
57
|
*/
|
|
58
58
|
headingLevel?: typeof headingLevels[number];
|
|
59
59
|
/**
|
|
60
|
-
*
|
|
60
|
+
* When true, the icon will be hidden.
|
|
61
61
|
*/
|
|
62
62
|
hideIcon?: boolean;
|
|
63
63
|
/**
|
|
@@ -70,10 +70,11 @@ export declare interface NotificationProps {
|
|
|
70
70
|
leadingAction?: ActionProps;
|
|
71
71
|
/**
|
|
72
72
|
* The supporting action for the notification.
|
|
73
|
+
* Will only render if `leadingAction` is passed
|
|
73
74
|
*/
|
|
74
75
|
supportingAction?: ActionProps;
|
|
75
76
|
/**
|
|
76
|
-
* When true,
|
|
77
|
+
* When true, action buttons will stack on narrow screens.
|
|
77
78
|
*/
|
|
78
79
|
hasStackedActions?: boolean;
|
|
79
80
|
/**
|
|
@@ -124,7 +125,7 @@ export declare class PieNotification extends LitElement implements NotificationP
|
|
|
124
125
|
position: NonNullable<NotificationProps['position']>;
|
|
125
126
|
isDismissible: boolean;
|
|
126
127
|
isCompact: boolean;
|
|
127
|
-
heading
|
|
128
|
+
heading?: string;
|
|
128
129
|
headingLevel: NonNullable<NotificationProps['headingLevel']>;
|
|
129
130
|
hideIcon: boolean;
|
|
130
131
|
leadingAction: NotificationProps['leadingAction'];
|
|
@@ -132,27 +133,12 @@ export declare class PieNotification extends LitElement implements NotificationP
|
|
|
132
133
|
hasStackedActions: boolean;
|
|
133
134
|
aria: NotificationProps['aria'];
|
|
134
135
|
_iconSlot: Array<HTMLElement>;
|
|
135
|
-
protected _hasExternalIcon: boolean;
|
|
136
|
-
protected _hasIconClass: boolean;
|
|
137
136
|
static styles: CSSResult;
|
|
138
|
-
/**
|
|
139
|
-
* Lifecycle method executed when component is about to update.
|
|
140
|
-
* It update icon properties if variant has changes.
|
|
141
|
-
*/
|
|
142
|
-
protected willUpdate(_changedProperties: PropertyValues<this>): void;
|
|
143
137
|
/**
|
|
144
138
|
* Lifecycle method executed when component is updated.
|
|
145
139
|
* It dispatches an event if notification is opened.
|
|
146
|
-
* It applies a gutter if there's no heading content in order to avoid the close button overlap the content.
|
|
147
140
|
*/
|
|
148
141
|
protected updated(_changedProperties: PropertyValues<this>): void;
|
|
149
|
-
/**
|
|
150
|
-
* Method responsible to check if an external icon has been provided.
|
|
151
|
-
* It reads from icon slot if there is an external icon as well check if variant has default icon.
|
|
152
|
-
*
|
|
153
|
-
* @private
|
|
154
|
-
*/
|
|
155
|
-
private updateIconProperties;
|
|
156
142
|
/**
|
|
157
143
|
* Template for the footer area
|
|
158
144
|
* Called within the main render function.
|
|
@@ -164,45 +150,20 @@ export declare class PieNotification extends LitElement implements NotificationP
|
|
|
164
150
|
* Template for the header area
|
|
165
151
|
* Called within the main render function.
|
|
166
152
|
*
|
|
167
|
-
* @param {NotificationProps['heading']} heading
|
|
168
|
-
* @param {StaticValue} headingTag
|
|
169
|
-
*
|
|
170
153
|
* @private
|
|
171
154
|
*/
|
|
172
155
|
private renderNotificationHeading;
|
|
173
|
-
/**
|
|
174
|
-
* Util method that returns a boolean if variant has a default icon.
|
|
175
|
-
*
|
|
176
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
177
|
-
*
|
|
178
|
-
* @private
|
|
179
|
-
*/
|
|
180
|
-
private variantHasDefaultIcon;
|
|
181
156
|
/**
|
|
182
157
|
* Util method that returns an icon from a variant that has default icon.
|
|
183
158
|
*
|
|
184
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
185
|
-
*
|
|
186
159
|
* @private
|
|
187
160
|
*/
|
|
188
161
|
private getDefaultVariantIcon;
|
|
189
|
-
/**
|
|
190
|
-
* Util method that returns a template with a default icon according to the chosen variant.
|
|
191
|
-
* Called within the renderIcon method.
|
|
192
|
-
*
|
|
193
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
194
|
-
*
|
|
195
|
-
* @private
|
|
196
|
-
*/
|
|
197
|
-
private renderIconVariant;
|
|
198
162
|
/**
|
|
199
163
|
* Template for the heading icon area.
|
|
200
|
-
* It can return an icon provided externally via named slot or it can return
|
|
164
|
+
* It can return an icon provided externally via named slot or it can return a default icon according to the chosen variant if defined.
|
|
201
165
|
* Called within the main render function.
|
|
202
166
|
*
|
|
203
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
204
|
-
* @param {boolean} hasExternalIcon
|
|
205
|
-
*
|
|
206
167
|
* @private
|
|
207
168
|
*/
|
|
208
169
|
private renderIcon;
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { unsafeCSS as
|
|
2
|
-
import { html as d, unsafeStatic as
|
|
3
|
-
import { validPropertyValues as
|
|
4
|
-
import { property as r, queryAssignedElements as
|
|
5
|
-
import { ifDefined as
|
|
1
|
+
import { unsafeCSS as O, LitElement as x, nothing as c } from "lit";
|
|
2
|
+
import { html as d, unsafeStatic as N } from "lit/static-html.js";
|
|
3
|
+
import { validPropertyValues as b, defineCustomElement as I, dispatchCustomEvent as m } from "@justeattakeaway/pie-webc-core";
|
|
4
|
+
import { property as r, queryAssignedElements as _ } from "lit/decorators.js";
|
|
5
|
+
import { ifDefined as y } from "lit/directives/if-defined.js";
|
|
6
6
|
import "@justeattakeaway/pie-button";
|
|
7
7
|
import "@justeattakeaway/pie-icon-button";
|
|
8
8
|
import "@justeattakeaway/pie-icons-webc/dist/IconAlertCircle.js";
|
|
@@ -10,7 +10,7 @@ import "@justeattakeaway/pie-icons-webc/dist/IconAlertTriangle.js";
|
|
|
10
10
|
import "@justeattakeaway/pie-icons-webc/dist/IconCheckCircle.js";
|
|
11
11
|
import "@justeattakeaway/pie-icons-webc/dist/IconClose.js";
|
|
12
12
|
import "@justeattakeaway/pie-icons-webc/dist/IconInfoCircle.js";
|
|
13
|
-
const
|
|
13
|
+
const k = ["neutral", "neutral-alternative", "info", "success", "warning", "error"], w = ["h2", "h3", "h4", "h5", "h6"], A = ["inline-content", "full-width"], t = "pie-notification", h = "c-notification", E = `${t}-close`, z = `${t}-open`, S = `${t}-leading-action-click`, T = `${t}-supporting-action-click`, l = {
|
|
14
14
|
isOpen: !0,
|
|
15
15
|
variant: "neutral",
|
|
16
16
|
position: "inline-content",
|
|
@@ -19,40 +19,23 @@ const S = ["neutral", "neutral-alternative", "info", "success", "warning", "erro
|
|
|
19
19
|
headingLevel: "h2",
|
|
20
20
|
hideIcon: !1,
|
|
21
21
|
hasStackedActions: !1
|
|
22
|
-
},
|
|
22
|
+
}, B = `*,*: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-heading-font-size: calc(var(--dt-font-heading-s-size--narrow) * 1px);--notification-heading-line-height: calc(var(--dt-font-heading-s-line-height--narrow) * 1px);--notification-font-size: calc(var(--dt-font-body-l-size) * 1px);--notification-line-height: calc(var(--dt-font-body-l-line-height) * 1px);--notification-close-icon-offset: var(--dt-spacing-b);--notification-icon-fill: var(--dt-color-content-default);--notification-icon-offset: 2px;--icon-size-override: 24px;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[isCompact]{--notification-direction: row}.c-notification[position=full-width]{--notification-border-radius: var(--dt-radius-rounded-none)}.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);--notification-icon-fill: var(--dt-color-content-positive)}.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-support-error)}.c-notification-heading{margin:0;margin-block-end:var(--dt-spacing-a);font-size:var(--notification-heading-font-size);line-height:var(--notification-heading-line-height)}@media (min-width: 768px){.c-notification-heading{--notification-heading-font-size: calc(var(--dt-font-heading-s-size--wide) * 1px);--notification-heading-line-height: calc(var(--dt-font-heading-s-line-height--wide) * 1px)}}.c-notification-content-section{display:flex;flex-direction:row;gap:var(--dt-spacing-c)}.c-notification-content-section[isDismissible]{max-width:calc(100% - var(--notification-close-icon-offset) - 40px)}.c-notification-icon-close{position:absolute;inset-block-start:var(--notification-close-icon-offset);inset-inline-end:var(--notification-close-icon-offset)}.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: 768px){.c-notification-footer[isStacked]{flex-direction:column-reverse}}.icon,::slotted([slot=icon]){display:inline-flex;color:var(--notification-icon-fill);margin-block-start:var(--notification-icon-offset)}@media (max-width: 768px){.icon,::slotted([slot=icon]){margin-block-start:0}}
|
|
23
23
|
`;
|
|
24
|
-
var
|
|
25
|
-
for (var s =
|
|
26
|
-
(p =
|
|
27
|
-
return
|
|
24
|
+
var D = Object.defineProperty, L = Object.getOwnPropertyDescriptor, a = (g, i, o, e) => {
|
|
25
|
+
for (var s = e > 1 ? void 0 : e ? L(i, o) : i, f = g.length - 1, p; f >= 0; f--)
|
|
26
|
+
(p = g[f]) && (s = (e ? p(i, o, s) : p(s)) || s);
|
|
27
|
+
return e && s && D(i, o, s), s;
|
|
28
28
|
};
|
|
29
|
-
class n extends
|
|
29
|
+
class n extends x {
|
|
30
30
|
constructor() {
|
|
31
|
-
super(...arguments), this.isOpen = l.isOpen, this.variant = l.variant, this.position = l.position, this.isDismissible = l.isDismissible, this.isCompact = l.isCompact, this.headingLevel = l.headingLevel, this.hideIcon = l.hideIcon, this.hasStackedActions = l.hasStackedActions
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Lifecycle method executed when component is about to update.
|
|
35
|
-
* It update icon properties if variant has changes.
|
|
36
|
-
*/
|
|
37
|
-
willUpdate(i) {
|
|
38
|
-
i.has("variant") && this.updateIconProperties();
|
|
31
|
+
super(...arguments), this.isOpen = l.isOpen, this.variant = l.variant, this.position = l.position, this.isDismissible = l.isDismissible, this.isCompact = l.isCompact, this.headingLevel = l.headingLevel, this.hideIcon = l.hideIcon, this.hasStackedActions = l.hasStackedActions;
|
|
39
32
|
}
|
|
40
33
|
/**
|
|
41
34
|
* Lifecycle method executed when component is updated.
|
|
42
35
|
* It dispatches an event if notification is opened.
|
|
43
|
-
* It applies a gutter if there's no heading content in order to avoid the close button overlap the content.
|
|
44
36
|
*/
|
|
45
37
|
updated(i) {
|
|
46
|
-
i.has("isOpen") && this.isOpen &&
|
|
47
|
-
}
|
|
48
|
-
/**
|
|
49
|
-
* Method responsible to check if an external icon has been provided.
|
|
50
|
-
* It reads from icon slot if there is an external icon as well check if variant has default icon.
|
|
51
|
-
*
|
|
52
|
-
* @private
|
|
53
|
-
*/
|
|
54
|
-
updateIconProperties() {
|
|
55
|
-
this._hasExternalIcon = this._iconSlot.length > 0, this._hasIconClass = this._hasExternalIcon || this.variantHasDefaultIcon(this.variant);
|
|
38
|
+
i.has("isOpen") && this.isOpen && m(this, z, { targetNotification: this });
|
|
56
39
|
}
|
|
57
40
|
/**
|
|
58
41
|
* Template for the footer area
|
|
@@ -60,7 +43,8 @@ class n extends k {
|
|
|
60
43
|
*
|
|
61
44
|
* @private
|
|
62
45
|
*/
|
|
63
|
-
renderFooter(
|
|
46
|
+
renderFooter() {
|
|
47
|
+
const { leadingAction: i, supportingAction: o } = this;
|
|
64
48
|
return d`
|
|
65
49
|
<footer class="${h}-footer" data-test-id="${t}-footer" ?isCompact="${this.isCompact}" ?isStacked="${this.hasStackedActions && !this.isCompact}">
|
|
66
50
|
${o ? this.renderActionButton(o, "supporting") : c}
|
|
@@ -72,77 +56,48 @@ class n extends k {
|
|
|
72
56
|
* Template for the header area
|
|
73
57
|
* Called within the main render function.
|
|
74
58
|
*
|
|
75
|
-
* @param {NotificationProps['heading']} heading
|
|
76
|
-
* @param {StaticValue} headingTag
|
|
77
|
-
*
|
|
78
59
|
* @private
|
|
79
60
|
*/
|
|
80
|
-
renderNotificationHeading(
|
|
81
|
-
|
|
61
|
+
renderNotificationHeading() {
|
|
62
|
+
const { heading: i, headingLevel: o } = this, e = N(o);
|
|
63
|
+
return d`<${e}
|
|
82
64
|
id="${t}-heading"
|
|
83
65
|
class="${h}-heading"
|
|
84
66
|
data-test-id="${t}-heading">
|
|
85
67
|
${i}
|
|
86
|
-
</${
|
|
87
|
-
}
|
|
88
|
-
/**
|
|
89
|
-
* Util method that returns a boolean if variant has a default icon.
|
|
90
|
-
*
|
|
91
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
92
|
-
*
|
|
93
|
-
* @private
|
|
94
|
-
*/
|
|
95
|
-
variantHasDefaultIcon(i) {
|
|
96
|
-
return ["info", "success", "warning", "error"].includes(i);
|
|
68
|
+
</${e}>`;
|
|
97
69
|
}
|
|
98
70
|
/**
|
|
99
71
|
* Util method that returns an icon from a variant that has default icon.
|
|
100
72
|
*
|
|
101
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
102
|
-
*
|
|
103
73
|
* @private
|
|
104
74
|
*/
|
|
105
|
-
getDefaultVariantIcon(
|
|
106
|
-
switch (
|
|
75
|
+
getDefaultVariantIcon() {
|
|
76
|
+
switch (this.variant) {
|
|
107
77
|
case "info":
|
|
108
|
-
return d`<icon-info-circle size="m" data-test-id="${t}-heading-icon-info"></icon-info-circle>`;
|
|
78
|
+
return d`<icon-info-circle class="icon" size="m" data-test-id="${t}-heading-icon-info"></icon-info-circle>`;
|
|
109
79
|
case "success":
|
|
110
|
-
return d`<icon-check-circle size="m" data-test-id="${t}-heading-icon-success"></icon-check-circle>`;
|
|
80
|
+
return d`<icon-check-circle class="icon" size="m" data-test-id="${t}-heading-icon-success"></icon-check-circle>`;
|
|
111
81
|
case "warning":
|
|
112
|
-
return d`<icon-alert-triangle size="m" data-test-id="${t}-heading-icon-warning"></icon-alert-triangle>`;
|
|
82
|
+
return d`<icon-alert-triangle class="icon" size="m" data-test-id="${t}-heading-icon-warning"></icon-alert-triangle>`;
|
|
113
83
|
case "error":
|
|
114
|
-
return d`<icon-alert-circle size="m" data-test-id="${t}-heading-icon-error"></icon-alert-circle>`;
|
|
84
|
+
return d`<icon-alert-circle class="icon" size="m" data-test-id="${t}-heading-icon-error"></icon-alert-circle>`;
|
|
115
85
|
default:
|
|
116
86
|
return c;
|
|
117
87
|
}
|
|
118
88
|
}
|
|
119
|
-
/**
|
|
120
|
-
* Util method that returns a template with a default icon according to the chosen variant.
|
|
121
|
-
* Called within the renderIcon method.
|
|
122
|
-
*
|
|
123
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
124
|
-
*
|
|
125
|
-
* @private
|
|
126
|
-
*/
|
|
127
|
-
renderIconVariant(i) {
|
|
128
|
-
return this.variantHasDefaultIcon(i) ? this.getDefaultVariantIcon(i) : c;
|
|
129
|
-
}
|
|
130
89
|
/**
|
|
131
90
|
* Template for the heading icon area.
|
|
132
|
-
* It can return an icon provided externally via named slot or it can return
|
|
91
|
+
* It can return an icon provided externally via named slot or it can return a default icon according to the chosen variant if defined.
|
|
133
92
|
* Called within the main render function.
|
|
134
93
|
*
|
|
135
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
136
|
-
* @param {boolean} hasExternalIcon
|
|
137
|
-
*
|
|
138
94
|
* @private
|
|
139
95
|
*/
|
|
140
|
-
renderIcon(
|
|
96
|
+
renderIcon() {
|
|
97
|
+
const i = this._iconSlot.length > 0;
|
|
141
98
|
return d`
|
|
142
|
-
|
|
143
|
-
${o ? c : this.renderIconVariant(i)}
|
|
99
|
+
${i ? c : this.getDefaultVariantIcon()}
|
|
144
100
|
<slot name="icon"></slot>
|
|
145
|
-
</div>
|
|
146
101
|
`;
|
|
147
102
|
}
|
|
148
103
|
/**
|
|
@@ -160,8 +115,7 @@ class n extends k {
|
|
|
160
115
|
class="${h}-icon-close"
|
|
161
116
|
data-test-id="${t}-icon-close"
|
|
162
117
|
@click="${this.handleCloseButton}"
|
|
163
|
-
aria-label="${
|
|
164
|
-
>
|
|
118
|
+
aria-label="${y((i = this.aria) == null ? void 0 : i.close)}">
|
|
165
119
|
<icon-close></icon-close>
|
|
166
120
|
</pie-icon-button>`;
|
|
167
121
|
}
|
|
@@ -172,7 +126,7 @@ class n extends k {
|
|
|
172
126
|
* @private
|
|
173
127
|
*/
|
|
174
128
|
handleCloseButton() {
|
|
175
|
-
this.closeNotificationComponent(),
|
|
129
|
+
this.closeNotificationComponent(), m(this, E, { targetNotification: this });
|
|
176
130
|
}
|
|
177
131
|
/**
|
|
178
132
|
* Util method responsible to close the component.
|
|
@@ -191,7 +145,7 @@ class n extends k {
|
|
|
191
145
|
* @private
|
|
192
146
|
*/
|
|
193
147
|
handleActionClick(i) {
|
|
194
|
-
|
|
148
|
+
m(this, i === "leading" ? S : T, { targetNotification: this });
|
|
195
149
|
}
|
|
196
150
|
/**
|
|
197
151
|
* Render the action button depending on action type and its action.
|
|
@@ -203,8 +157,8 @@ class n extends k {
|
|
|
203
157
|
* @private
|
|
204
158
|
*/
|
|
205
159
|
renderActionButton(i, o) {
|
|
206
|
-
const { text:
|
|
207
|
-
return
|
|
160
|
+
const { text: e, ariaLabel: s } = i;
|
|
161
|
+
return e ? d`
|
|
208
162
|
<pie-button
|
|
209
163
|
variant="${o === "leading" ? "primary" : "ghost"}"
|
|
210
164
|
size="small-productive"
|
|
@@ -213,7 +167,7 @@ class n extends k {
|
|
|
213
167
|
data-test-id="${t}-${o}-action"
|
|
214
168
|
?isFullWidth="${this.hasStackedActions}"
|
|
215
169
|
type="button">
|
|
216
|
-
${
|
|
170
|
+
${e}
|
|
217
171
|
</pie-button>
|
|
218
172
|
` : c;
|
|
219
173
|
}
|
|
@@ -221,106 +175,96 @@ class n extends k {
|
|
|
221
175
|
const {
|
|
222
176
|
variant: i,
|
|
223
177
|
position: o,
|
|
224
|
-
heading:
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
leadingAction: b,
|
|
232
|
-
supportingAction: N,
|
|
233
|
-
isOpen: x,
|
|
234
|
-
aria: g
|
|
178
|
+
heading: e,
|
|
179
|
+
isDismissible: s,
|
|
180
|
+
isCompact: f,
|
|
181
|
+
hideIcon: p,
|
|
182
|
+
leadingAction: u,
|
|
183
|
+
isOpen: C,
|
|
184
|
+
aria: v
|
|
235
185
|
} = this;
|
|
236
|
-
if (!
|
|
186
|
+
if (!C)
|
|
237
187
|
return c;
|
|
238
|
-
const $ =
|
|
188
|
+
const $ = s && !f;
|
|
239
189
|
return d`
|
|
240
190
|
<div
|
|
241
191
|
data-test-id="${t}"
|
|
242
192
|
class="${h}"
|
|
243
193
|
variant="${i}"
|
|
244
194
|
position="${o}"
|
|
245
|
-
?isCompact="${
|
|
195
|
+
?isCompact="${f}"
|
|
246
196
|
role="region"
|
|
247
197
|
aria-live="${i === "error" ? "assertive" : "polite"}"
|
|
248
|
-
aria-labelledby="${
|
|
249
|
-
aria-label="${!
|
|
198
|
+
aria-labelledby="${e ? `${t}-heading` : c}"
|
|
199
|
+
aria-label="${!e && y(v == null ? void 0 : v.label)}">
|
|
250
200
|
${$ ? this.renderCloseButton() : c}
|
|
251
201
|
|
|
252
202
|
<section class="${h}-content-section" ?isDismissible="${$}">
|
|
253
|
-
${
|
|
203
|
+
${p ? c : this.renderIcon()}
|
|
254
204
|
<article>
|
|
255
|
-
${
|
|
205
|
+
${e ? this.renderNotificationHeading() : c}
|
|
256
206
|
<slot></slot>
|
|
257
207
|
</article>
|
|
258
208
|
</section>
|
|
259
209
|
|
|
260
|
-
${
|
|
210
|
+
${u != null && u.text ? this.renderFooter() : c}
|
|
261
211
|
</div>`;
|
|
262
212
|
}
|
|
263
213
|
}
|
|
264
|
-
n.styles =
|
|
265
|
-
|
|
214
|
+
n.styles = O(B);
|
|
215
|
+
a([
|
|
266
216
|
r({ type: Boolean })
|
|
267
217
|
], n.prototype, "isOpen", 2);
|
|
268
|
-
|
|
218
|
+
a([
|
|
269
219
|
r(),
|
|
270
|
-
|
|
220
|
+
b(t, k, l.variant)
|
|
271
221
|
], n.prototype, "variant", 2);
|
|
272
|
-
|
|
222
|
+
a([
|
|
273
223
|
r(),
|
|
274
|
-
|
|
224
|
+
b(t, A, l.position)
|
|
275
225
|
], n.prototype, "position", 2);
|
|
276
|
-
|
|
226
|
+
a([
|
|
277
227
|
r({ type: Boolean })
|
|
278
228
|
], n.prototype, "isDismissible", 2);
|
|
279
|
-
|
|
229
|
+
a([
|
|
280
230
|
r({ type: Boolean })
|
|
281
231
|
], n.prototype, "isCompact", 2);
|
|
282
|
-
|
|
232
|
+
a([
|
|
283
233
|
r({ type: String })
|
|
284
234
|
], n.prototype, "heading", 2);
|
|
285
|
-
|
|
235
|
+
a([
|
|
286
236
|
r(),
|
|
287
|
-
|
|
237
|
+
b(t, w, l.headingLevel)
|
|
288
238
|
], n.prototype, "headingLevel", 2);
|
|
289
|
-
|
|
239
|
+
a([
|
|
290
240
|
r({ type: Boolean })
|
|
291
241
|
], n.prototype, "hideIcon", 2);
|
|
292
|
-
|
|
242
|
+
a([
|
|
293
243
|
r({ type: Object })
|
|
294
244
|
], n.prototype, "leadingAction", 2);
|
|
295
|
-
|
|
245
|
+
a([
|
|
296
246
|
r({ type: Object })
|
|
297
247
|
], n.prototype, "supportingAction", 2);
|
|
298
|
-
|
|
248
|
+
a([
|
|
299
249
|
r({ type: Boolean })
|
|
300
250
|
], n.prototype, "hasStackedActions", 2);
|
|
301
|
-
|
|
251
|
+
a([
|
|
302
252
|
r({ type: Object })
|
|
303
253
|
], n.prototype, "aria", 2);
|
|
304
|
-
|
|
305
|
-
|
|
254
|
+
a([
|
|
255
|
+
_({ slot: "icon" })
|
|
306
256
|
], n.prototype, "_iconSlot", 2);
|
|
307
|
-
|
|
308
|
-
C()
|
|
309
|
-
], n.prototype, "_hasExternalIcon", 2);
|
|
310
|
-
e([
|
|
311
|
-
C()
|
|
312
|
-
], n.prototype, "_hasIconClass", 2);
|
|
313
|
-
A(t, n);
|
|
257
|
+
I(t, n);
|
|
314
258
|
export {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
259
|
+
E as ON_NOTIFICATION_CLOSE_EVENT,
|
|
260
|
+
S as ON_NOTIFICATION_LEADING_ACTION_CLICK_EVENT,
|
|
261
|
+
z as ON_NOTIFICATION_OPEN_EVENT,
|
|
262
|
+
T as ON_NOTIFICATION_SUPPORTING_ACTION_CLICK_EVENT,
|
|
319
263
|
n as PieNotification,
|
|
320
264
|
h as componentClass,
|
|
321
265
|
t as componentSelector,
|
|
322
266
|
l as defaultProps,
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
267
|
+
w as headingLevels,
|
|
268
|
+
A as positions,
|
|
269
|
+
k as variants
|
|
326
270
|
};
|
package/dist/react.d.ts
CHANGED
|
@@ -34,11 +34,11 @@ export declare const headingLevels: readonly ["h2", "h3", "h4", "h5", "h6"];
|
|
|
34
34
|
|
|
35
35
|
export declare interface NotificationProps {
|
|
36
36
|
/**
|
|
37
|
-
*
|
|
37
|
+
* Sets the variant of the notification.
|
|
38
38
|
*/
|
|
39
39
|
variant?: typeof variants[number];
|
|
40
40
|
/**
|
|
41
|
-
*
|
|
41
|
+
* Defines the proper styles, whether the component appears within the content or at the top of the interface
|
|
42
42
|
*/
|
|
43
43
|
position?: typeof positions[number];
|
|
44
44
|
/**
|
|
@@ -46,7 +46,7 @@ export declare interface NotificationProps {
|
|
|
46
46
|
*/
|
|
47
47
|
isDismissible?: boolean;
|
|
48
48
|
/**
|
|
49
|
-
* When true, the footer
|
|
49
|
+
* When true, aligns the footer with the header and icons, making the component compact.
|
|
50
50
|
*/
|
|
51
51
|
isCompact?: boolean;
|
|
52
52
|
/**
|
|
@@ -58,7 +58,7 @@ export declare interface NotificationProps {
|
|
|
58
58
|
*/
|
|
59
59
|
headingLevel?: typeof headingLevels[number];
|
|
60
60
|
/**
|
|
61
|
-
*
|
|
61
|
+
* When true, the icon will be hidden.
|
|
62
62
|
*/
|
|
63
63
|
hideIcon?: boolean;
|
|
64
64
|
/**
|
|
@@ -71,10 +71,11 @@ export declare interface NotificationProps {
|
|
|
71
71
|
leadingAction?: ActionProps;
|
|
72
72
|
/**
|
|
73
73
|
* The supporting action for the notification.
|
|
74
|
+
* Will only render if `leadingAction` is passed
|
|
74
75
|
*/
|
|
75
76
|
supportingAction?: ActionProps;
|
|
76
77
|
/**
|
|
77
|
-
* When true,
|
|
78
|
+
* When true, action buttons will stack on narrow screens.
|
|
78
79
|
*/
|
|
79
80
|
hasStackedActions?: boolean;
|
|
80
81
|
/**
|
|
@@ -127,7 +128,7 @@ declare class PieNotification_2 extends LitElement implements NotificationProps
|
|
|
127
128
|
position: NonNullable<NotificationProps['position']>;
|
|
128
129
|
isDismissible: boolean;
|
|
129
130
|
isCompact: boolean;
|
|
130
|
-
heading
|
|
131
|
+
heading?: string;
|
|
131
132
|
headingLevel: NonNullable<NotificationProps['headingLevel']>;
|
|
132
133
|
hideIcon: boolean;
|
|
133
134
|
leadingAction: NotificationProps['leadingAction'];
|
|
@@ -135,27 +136,12 @@ declare class PieNotification_2 extends LitElement implements NotificationProps
|
|
|
135
136
|
hasStackedActions: boolean;
|
|
136
137
|
aria: NotificationProps['aria'];
|
|
137
138
|
_iconSlot: Array<HTMLElement>;
|
|
138
|
-
protected _hasExternalIcon: boolean;
|
|
139
|
-
protected _hasIconClass: boolean;
|
|
140
139
|
static styles: CSSResult;
|
|
141
|
-
/**
|
|
142
|
-
* Lifecycle method executed when component is about to update.
|
|
143
|
-
* It update icon properties if variant has changes.
|
|
144
|
-
*/
|
|
145
|
-
protected willUpdate(_changedProperties: PropertyValues<this>): void;
|
|
146
140
|
/**
|
|
147
141
|
* Lifecycle method executed when component is updated.
|
|
148
142
|
* It dispatches an event if notification is opened.
|
|
149
|
-
* It applies a gutter if there's no heading content in order to avoid the close button overlap the content.
|
|
150
143
|
*/
|
|
151
144
|
protected updated(_changedProperties: PropertyValues<this>): void;
|
|
152
|
-
/**
|
|
153
|
-
* Method responsible to check if an external icon has been provided.
|
|
154
|
-
* It reads from icon slot if there is an external icon as well check if variant has default icon.
|
|
155
|
-
*
|
|
156
|
-
* @private
|
|
157
|
-
*/
|
|
158
|
-
private updateIconProperties;
|
|
159
145
|
/**
|
|
160
146
|
* Template for the footer area
|
|
161
147
|
* Called within the main render function.
|
|
@@ -167,45 +153,20 @@ declare class PieNotification_2 extends LitElement implements NotificationProps
|
|
|
167
153
|
* Template for the header area
|
|
168
154
|
* Called within the main render function.
|
|
169
155
|
*
|
|
170
|
-
* @param {NotificationProps['heading']} heading
|
|
171
|
-
* @param {StaticValue} headingTag
|
|
172
|
-
*
|
|
173
156
|
* @private
|
|
174
157
|
*/
|
|
175
158
|
private renderNotificationHeading;
|
|
176
|
-
/**
|
|
177
|
-
* Util method that returns a boolean if variant has a default icon.
|
|
178
|
-
*
|
|
179
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
180
|
-
*
|
|
181
|
-
* @private
|
|
182
|
-
*/
|
|
183
|
-
private variantHasDefaultIcon;
|
|
184
159
|
/**
|
|
185
160
|
* Util method that returns an icon from a variant that has default icon.
|
|
186
161
|
*
|
|
187
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
188
|
-
*
|
|
189
162
|
* @private
|
|
190
163
|
*/
|
|
191
164
|
private getDefaultVariantIcon;
|
|
192
|
-
/**
|
|
193
|
-
* Util method that returns a template with a default icon according to the chosen variant.
|
|
194
|
-
* Called within the renderIcon method.
|
|
195
|
-
*
|
|
196
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
197
|
-
*
|
|
198
|
-
* @private
|
|
199
|
-
*/
|
|
200
|
-
private renderIconVariant;
|
|
201
165
|
/**
|
|
202
166
|
* Template for the heading icon area.
|
|
203
|
-
* It can return an icon provided externally via named slot or it can return
|
|
167
|
+
* It can return an icon provided externally via named slot or it can return a default icon according to the chosen variant if defined.
|
|
204
168
|
* Called within the main render function.
|
|
205
169
|
*
|
|
206
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
207
|
-
* @param {boolean} hasExternalIcon
|
|
208
|
-
*
|
|
209
170
|
* @private
|
|
210
171
|
*/
|
|
211
172
|
private renderIcon;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@justeattakeaway/pie-notification",
|
|
3
3
|
"description": "PIE Design System Notification built using Web Components",
|
|
4
|
-
"version": "0.
|
|
4
|
+
"version": "0.9.0",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"module": "dist/index.js",
|
|
@@ -37,12 +37,12 @@
|
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@custom-elements-manifest/analyzer": "0.9.0",
|
|
39
39
|
"@justeattakeaway/pie-components-config": "0.16.0",
|
|
40
|
-
"@justeattakeaway/pie-wrapper-react": "0.14.
|
|
40
|
+
"@justeattakeaway/pie-wrapper-react": "0.14.1",
|
|
41
41
|
"cem-plugin-module-file-extensions": "0.0.5"
|
|
42
42
|
},
|
|
43
43
|
"dependencies": {
|
|
44
|
-
"@justeattakeaway/pie-icon-button": "0.28.
|
|
45
|
-
"@justeattakeaway/pie-icons-webc": "0.24.
|
|
44
|
+
"@justeattakeaway/pie-icon-button": "0.28.7",
|
|
45
|
+
"@justeattakeaway/pie-icons-webc": "0.24.1",
|
|
46
46
|
"@justeattakeaway/pie-webc-core": "0.23.0"
|
|
47
47
|
},
|
|
48
48
|
"volta": {
|
package/src/defs.ts
CHANGED
|
@@ -23,12 +23,12 @@ export type ActionProps = {
|
|
|
23
23
|
|
|
24
24
|
export interface NotificationProps {
|
|
25
25
|
/**
|
|
26
|
-
*
|
|
26
|
+
* Sets the variant of the notification.
|
|
27
27
|
*/
|
|
28
28
|
variant?: typeof variants[number];
|
|
29
29
|
|
|
30
30
|
/**
|
|
31
|
-
*
|
|
31
|
+
* Defines the proper styles, whether the component appears within the content or at the top of the interface
|
|
32
32
|
*/
|
|
33
33
|
position?: typeof positions[number];
|
|
34
34
|
|
|
@@ -38,7 +38,7 @@ export interface NotificationProps {
|
|
|
38
38
|
isDismissible?: boolean;
|
|
39
39
|
|
|
40
40
|
/**
|
|
41
|
-
* When true, the footer
|
|
41
|
+
* When true, aligns the footer with the header and icons, making the component compact.
|
|
42
42
|
*/
|
|
43
43
|
isCompact?: boolean;
|
|
44
44
|
|
|
@@ -53,7 +53,7 @@ export interface NotificationProps {
|
|
|
53
53
|
headingLevel?: typeof headingLevels[number];
|
|
54
54
|
|
|
55
55
|
/**
|
|
56
|
-
*
|
|
56
|
+
* When true, the icon will be hidden.
|
|
57
57
|
*/
|
|
58
58
|
hideIcon?: boolean;
|
|
59
59
|
|
|
@@ -69,11 +69,12 @@ export interface NotificationProps {
|
|
|
69
69
|
|
|
70
70
|
/**
|
|
71
71
|
* The supporting action for the notification.
|
|
72
|
+
* Will only render if `leadingAction` is passed
|
|
72
73
|
*/
|
|
73
74
|
supportingAction?: ActionProps;
|
|
74
75
|
|
|
75
76
|
/**
|
|
76
|
-
* When true,
|
|
77
|
+
* When true, action buttons will stack on narrow screens.
|
|
77
78
|
*/
|
|
78
79
|
hasStackedActions?: boolean;
|
|
79
80
|
|
package/src/index.ts
CHANGED
|
@@ -5,9 +5,9 @@ import {
|
|
|
5
5
|
type TemplateResult,
|
|
6
6
|
type PropertyValues,
|
|
7
7
|
} from 'lit';
|
|
8
|
-
import {
|
|
8
|
+
import { html, unsafeStatic } from 'lit/static-html.js';
|
|
9
9
|
import { defineCustomElement, validPropertyValues, dispatchCustomEvent } from '@justeattakeaway/pie-webc-core';
|
|
10
|
-
import { property, queryAssignedElements
|
|
10
|
+
import { property, queryAssignedElements } from 'lit/decorators.js';
|
|
11
11
|
import { ifDefined } from 'lit/directives/if-defined.js';
|
|
12
12
|
import {
|
|
13
13
|
type NotificationProps,
|
|
@@ -62,7 +62,7 @@ export class PieNotification extends LitElement implements NotificationProps {
|
|
|
62
62
|
public isCompact = defaultProps.isCompact;
|
|
63
63
|
|
|
64
64
|
@property({ type: String })
|
|
65
|
-
public heading
|
|
65
|
+
public heading?: string;
|
|
66
66
|
|
|
67
67
|
@property()
|
|
68
68
|
@validPropertyValues(componentSelector, headingLevels, defaultProps.headingLevel)
|
|
@@ -72,10 +72,10 @@ export class PieNotification extends LitElement implements NotificationProps {
|
|
|
72
72
|
public hideIcon = defaultProps.hideIcon;
|
|
73
73
|
|
|
74
74
|
@property({ type: Object })
|
|
75
|
-
public leadingAction
|
|
75
|
+
public leadingAction: NotificationProps['leadingAction'];
|
|
76
76
|
|
|
77
77
|
@property({ type: Object })
|
|
78
|
-
public supportingAction
|
|
78
|
+
public supportingAction: NotificationProps['supportingAction'];
|
|
79
79
|
|
|
80
80
|
@property({ type: Boolean })
|
|
81
81
|
public hasStackedActions = defaultProps.hasStackedActions;
|
|
@@ -85,29 +85,12 @@ export class PieNotification extends LitElement implements NotificationProps {
|
|
|
85
85
|
|
|
86
86
|
@queryAssignedElements({ slot: 'icon' }) _iconSlot!: Array<HTMLElement>;
|
|
87
87
|
|
|
88
|
-
@state()
|
|
89
|
-
protected _hasExternalIcon = false;
|
|
90
|
-
|
|
91
|
-
@state()
|
|
92
|
-
protected _hasIconClass = false;
|
|
93
|
-
|
|
94
88
|
// Renders a `CSSResult` generated from SCSS by Vite
|
|
95
89
|
static styles = unsafeCSS(styles);
|
|
96
90
|
|
|
97
|
-
/**
|
|
98
|
-
* Lifecycle method executed when component is about to update.
|
|
99
|
-
* It update icon properties if variant has changes.
|
|
100
|
-
*/
|
|
101
|
-
protected willUpdate (_changedProperties: PropertyValues<this>): void {
|
|
102
|
-
if (_changedProperties.has('variant')) {
|
|
103
|
-
this.updateIconProperties();
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
91
|
/**
|
|
108
92
|
* Lifecycle method executed when component is updated.
|
|
109
93
|
* It dispatches an event if notification is opened.
|
|
110
|
-
* It applies a gutter if there's no heading content in order to avoid the close button overlap the content.
|
|
111
94
|
*/
|
|
112
95
|
protected updated (_changedProperties: PropertyValues<this>): void {
|
|
113
96
|
if (_changedProperties.has('isOpen') && this.isOpen) {
|
|
@@ -115,24 +98,14 @@ export class PieNotification extends LitElement implements NotificationProps {
|
|
|
115
98
|
}
|
|
116
99
|
}
|
|
117
100
|
|
|
118
|
-
/**
|
|
119
|
-
* Method responsible to check if an external icon has been provided.
|
|
120
|
-
* It reads from icon slot if there is an external icon as well check if variant has default icon.
|
|
121
|
-
*
|
|
122
|
-
* @private
|
|
123
|
-
*/
|
|
124
|
-
private updateIconProperties () {
|
|
125
|
-
this._hasExternalIcon = this._iconSlot.length > 0;
|
|
126
|
-
this._hasIconClass = this._hasExternalIcon || this.variantHasDefaultIcon(this.variant);
|
|
127
|
-
}
|
|
128
|
-
|
|
129
101
|
/**
|
|
130
102
|
* Template for the footer area
|
|
131
103
|
* Called within the main render function.
|
|
132
104
|
*
|
|
133
105
|
* @private
|
|
134
106
|
*/
|
|
135
|
-
private renderFooter (
|
|
107
|
+
private renderFooter () {
|
|
108
|
+
const { leadingAction, supportingAction } = this;
|
|
136
109
|
return html`
|
|
137
110
|
<footer class="${componentClass}-footer" data-test-id="${componentSelector}-footer" ?isCompact="${this.isCompact}" ?isStacked="${this.hasStackedActions && !this.isCompact}">
|
|
138
111
|
${supportingAction ? this.renderActionButton(supportingAction, 'supporting') : nothing}
|
|
@@ -145,87 +118,53 @@ export class PieNotification extends LitElement implements NotificationProps {
|
|
|
145
118
|
* Template for the header area
|
|
146
119
|
* Called within the main render function.
|
|
147
120
|
*
|
|
148
|
-
* @param {NotificationProps['heading']} heading
|
|
149
|
-
* @param {StaticValue} headingTag
|
|
150
|
-
*
|
|
151
121
|
* @private
|
|
152
122
|
*/
|
|
153
|
-
private renderNotificationHeading (
|
|
154
|
-
|
|
123
|
+
private renderNotificationHeading (): TemplateResult {
|
|
124
|
+
const { heading, headingLevel } = this;
|
|
125
|
+
const tag = unsafeStatic(headingLevel);
|
|
126
|
+
|
|
127
|
+
return html`<${tag}
|
|
155
128
|
id="${componentSelector}-heading"
|
|
156
129
|
class="${componentClass}-heading"
|
|
157
130
|
data-test-id="${componentSelector}-heading">
|
|
158
131
|
${heading}
|
|
159
|
-
</${
|
|
160
|
-
}
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* Util method that returns a boolean if variant has a default icon.
|
|
164
|
-
*
|
|
165
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
166
|
-
*
|
|
167
|
-
* @private
|
|
168
|
-
*/
|
|
169
|
-
private variantHasDefaultIcon (variant: NonNullable<NotificationProps['variant']>) {
|
|
170
|
-
const validVariants = ['info', 'success', 'warning', 'error'];
|
|
171
|
-
|
|
172
|
-
return validVariants.includes(variant);
|
|
132
|
+
</${tag}>`;
|
|
173
133
|
}
|
|
174
134
|
|
|
175
135
|
/**
|
|
176
136
|
* Util method that returns an icon from a variant that has default icon.
|
|
177
137
|
*
|
|
178
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
179
|
-
*
|
|
180
138
|
* @private
|
|
181
139
|
*/
|
|
182
|
-
private getDefaultVariantIcon (
|
|
183
|
-
switch (variant) {
|
|
140
|
+
private getDefaultVariantIcon () {
|
|
141
|
+
switch (this.variant) {
|
|
184
142
|
case 'info':
|
|
185
|
-
return html`<icon-info-circle size="m" data-test-id="${componentSelector}-heading-icon-info"></icon-info-circle>`;
|
|
143
|
+
return html`<icon-info-circle class="icon" size="m" data-test-id="${componentSelector}-heading-icon-info"></icon-info-circle>`;
|
|
186
144
|
case 'success':
|
|
187
|
-
return html`<icon-check-circle size="m" data-test-id="${componentSelector}-heading-icon-success"></icon-check-circle>`;
|
|
145
|
+
return html`<icon-check-circle class="icon" size="m" data-test-id="${componentSelector}-heading-icon-success"></icon-check-circle>`;
|
|
188
146
|
case 'warning':
|
|
189
|
-
return html`<icon-alert-triangle size="m" data-test-id="${componentSelector}-heading-icon-warning"></icon-alert-triangle>`;
|
|
147
|
+
return html`<icon-alert-triangle class="icon" size="m" data-test-id="${componentSelector}-heading-icon-warning"></icon-alert-triangle>`;
|
|
190
148
|
case 'error':
|
|
191
|
-
return html`<icon-alert-circle size="m" data-test-id="${componentSelector}-heading-icon-error"></icon-alert-circle>`;
|
|
149
|
+
return html`<icon-alert-circle class="icon" size="m" data-test-id="${componentSelector}-heading-icon-error"></icon-alert-circle>`;
|
|
192
150
|
default:
|
|
193
151
|
return nothing as never;
|
|
194
152
|
}
|
|
195
153
|
}
|
|
196
154
|
|
|
197
|
-
/**
|
|
198
|
-
* Util method that returns a template with a default icon according to the chosen variant.
|
|
199
|
-
* Called within the renderIcon method.
|
|
200
|
-
*
|
|
201
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
202
|
-
*
|
|
203
|
-
* @private
|
|
204
|
-
*/
|
|
205
|
-
private renderIconVariant (variant: NonNullable<NotificationProps['variant']>) {
|
|
206
|
-
if (this.variantHasDefaultIcon(variant)) {
|
|
207
|
-
return this.getDefaultVariantIcon(variant);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return nothing;
|
|
211
|
-
}
|
|
212
|
-
|
|
213
155
|
/**
|
|
214
156
|
* Template for the heading icon area.
|
|
215
|
-
* It can return an icon provided externally via named slot or it can return
|
|
157
|
+
* It can return an icon provided externally via named slot or it can return a default icon according to the chosen variant if defined.
|
|
216
158
|
* Called within the main render function.
|
|
217
159
|
*
|
|
218
|
-
* @param {NonNullable<NotificationProps['variant']>} variant
|
|
219
|
-
* @param {boolean} hasExternalIcon
|
|
220
|
-
*
|
|
221
160
|
* @private
|
|
222
161
|
*/
|
|
223
|
-
private renderIcon (
|
|
162
|
+
private renderIcon (): TemplateResult | typeof nothing {
|
|
163
|
+
const hasExternalIcon = this._iconSlot.length > 0;
|
|
164
|
+
|
|
224
165
|
return html`
|
|
225
|
-
|
|
226
|
-
${!hasExternalIcon ? this.renderIconVariant(variant) : nothing}
|
|
166
|
+
${!hasExternalIcon ? this.getDefaultVariantIcon() : nothing}
|
|
227
167
|
<slot name="icon"></slot>
|
|
228
|
-
</div>
|
|
229
168
|
`;
|
|
230
169
|
}
|
|
231
170
|
|
|
@@ -243,8 +182,7 @@ export class PieNotification extends LitElement implements NotificationProps {
|
|
|
243
182
|
class="${componentClass}-icon-close"
|
|
244
183
|
data-test-id="${componentSelector}-icon-close"
|
|
245
184
|
@click="${this.handleCloseButton}"
|
|
246
|
-
aria-label="${ifDefined(this.aria?.close)}"
|
|
247
|
-
>
|
|
185
|
+
aria-label="${ifDefined(this.aria?.close)}">
|
|
248
186
|
<icon-close></icon-close>
|
|
249
187
|
</pie-icon-button>`;
|
|
250
188
|
}
|
|
@@ -320,14 +258,10 @@ export class PieNotification extends LitElement implements NotificationProps {
|
|
|
320
258
|
variant,
|
|
321
259
|
position,
|
|
322
260
|
heading,
|
|
323
|
-
headingLevel,
|
|
324
261
|
isDismissible,
|
|
325
262
|
isCompact,
|
|
326
|
-
_hasExternalIcon,
|
|
327
263
|
hideIcon,
|
|
328
|
-
_hasIconClass,
|
|
329
264
|
leadingAction,
|
|
330
|
-
supportingAction,
|
|
331
265
|
isOpen,
|
|
332
266
|
aria,
|
|
333
267
|
} = this;
|
|
@@ -352,14 +286,14 @@ export class PieNotification extends LitElement implements NotificationProps {
|
|
|
352
286
|
${showCloseButton ? this.renderCloseButton() : nothing}
|
|
353
287
|
|
|
354
288
|
<section class="${componentClass}-content-section" ?isDismissible="${showCloseButton}">
|
|
355
|
-
${!hideIcon ? this.renderIcon(
|
|
289
|
+
${!hideIcon ? this.renderIcon() : nothing}
|
|
356
290
|
<article>
|
|
357
|
-
${heading ? this.renderNotificationHeading(
|
|
291
|
+
${heading ? this.renderNotificationHeading() : nothing}
|
|
358
292
|
<slot></slot>
|
|
359
293
|
</article>
|
|
360
294
|
</section>
|
|
361
295
|
|
|
362
|
-
${leadingAction ? this.renderFooter(
|
|
296
|
+
${leadingAction?.text ? this.renderFooter() : nothing}
|
|
363
297
|
</div>`;
|
|
364
298
|
}
|
|
365
299
|
}
|
package/src/notification.scss
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
@use '@justeattakeaway/pie-css/scss' as p;
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
$breakpoint-wide: 768px;
|
|
3
|
+
$breakpoint-wide: 768px;
|
|
5
4
|
|
|
5
|
+
.c-notification {
|
|
6
6
|
--notification-border-radius: var(--dt-radius-rounded-c);
|
|
7
7
|
--notification-background-color: var(--dt-color-container-subtle);
|
|
8
8
|
--notification-direction: column;
|
|
@@ -10,9 +10,10 @@
|
|
|
10
10
|
--notification-heading-line-height: #{p.line-height(--dt-font-heading-s-line-height--narrow)};
|
|
11
11
|
--notification-font-size: #{p.font-size(--dt-font-body-l-size)};
|
|
12
12
|
--notification-line-height: #{p.line-height(--dt-font-body-l-line-height)};
|
|
13
|
-
--notification-icon-fill: var(--dt-color-content-default);
|
|
14
13
|
--notification-close-icon-offset: var(--dt-spacing-b);
|
|
15
|
-
--notification-
|
|
14
|
+
--notification-icon-fill: var(--dt-color-content-default);
|
|
15
|
+
--notification-icon-offset: 2px;
|
|
16
|
+
--icon-size-override: 24px;
|
|
16
17
|
|
|
17
18
|
padding: var(--dt-spacing-d);
|
|
18
19
|
border-radius: var(--notification-border-radius);
|
|
@@ -43,6 +44,7 @@
|
|
|
43
44
|
|
|
44
45
|
&[variant='success'] {
|
|
45
46
|
--notification-background-color: var(--dt-color-support-positive-02);
|
|
47
|
+
--notification-icon-fill: var(--dt-color-content-positive);
|
|
46
48
|
}
|
|
47
49
|
|
|
48
50
|
&[variant='warning'] {
|
|
@@ -51,7 +53,7 @@
|
|
|
51
53
|
|
|
52
54
|
&[variant='error'] {
|
|
53
55
|
--notification-background-color: var(--dt-color-support-error-02);
|
|
54
|
-
--notification-icon-fill: var(--dt-color-
|
|
56
|
+
--notification-icon-fill: var(--dt-color-support-error);
|
|
55
57
|
}
|
|
56
58
|
|
|
57
59
|
|
|
@@ -70,22 +72,13 @@
|
|
|
70
72
|
&-content-section {
|
|
71
73
|
display: flex;
|
|
72
74
|
flex-direction: row;
|
|
73
|
-
|
|
74
|
-
.has-icon {
|
|
75
|
-
display: block ruby; // This is a hack to avoid the icon overlap the text in Firefox
|
|
76
|
-
margin-inline-end: var(--dt-spacing-c);
|
|
77
|
-
}
|
|
75
|
+
gap: var(--dt-spacing-c);
|
|
78
76
|
|
|
79
77
|
&[isDismissible] {
|
|
80
78
|
max-width: calc(100% - var(--notification-close-icon-offset) - 40px); // 40px is the size of the medium icon button
|
|
81
79
|
}
|
|
82
80
|
}
|
|
83
81
|
|
|
84
|
-
&-heading-icon {
|
|
85
|
-
padding-block-start: var(--notification-heading-icon-offset);
|
|
86
|
-
color: var(--notification-icon-fill);
|
|
87
|
-
}
|
|
88
|
-
|
|
89
82
|
&-icon-close {
|
|
90
83
|
position: absolute;
|
|
91
84
|
inset-block-start: var(--notification-close-icon-offset);
|
|
@@ -109,3 +102,14 @@
|
|
|
109
102
|
}
|
|
110
103
|
}
|
|
111
104
|
}
|
|
105
|
+
|
|
106
|
+
.icon,
|
|
107
|
+
::slotted([slot="icon"]) {
|
|
108
|
+
display: inline-flex;
|
|
109
|
+
color: var(--notification-icon-fill);
|
|
110
|
+
margin-block-start: var(--notification-icon-offset);
|
|
111
|
+
|
|
112
|
+
@media (max-width: $breakpoint-wide) {
|
|
113
|
+
margin-block-start: 0;
|
|
114
|
+
}
|
|
115
|
+
}
|