Skip to content

Commit 5b117a9

Browse files
authored
client: improve snackbar notifications (#725)
1 parent 3b1b7d1 commit 5b117a9

File tree

3 files changed

+66
-28
lines changed

3 files changed

+66
-28
lines changed

client/src/app/shared/notification/notification.component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<div class="app-notification__content" [class]="'app-notification__content--' + data.type">
1+
<div class="app-notification__content">
22
<mat-icon class="app-notification__icon">{{ iconMap[data.type] }}</mat-icon>
33

44
@if (isTemplateRef(data.message)) {
Lines changed: 54 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,54 +1,83 @@
1+
@use '../../app' as app;
2+
13
.app-notification {
24
display: flex;
35
justify-content: space-between;
4-
align-items: center;
6+
align-items: flex-start;
57

68
&__content {
79
display: flex;
810
justify-content: flex-start;
911
align-items: center;
10-
font-size: 1.125rem;
11-
12-
&--info {
13-
color: var(--app-notification-info);
14-
}
15-
16-
&--success {
17-
color: var(--app-notification-success);
18-
}
19-
20-
&--danger {
21-
color: var(--app-notification-danger);
22-
}
2312
}
2413

2514
&__icon {
26-
margin-right: 0.5rem;
15+
margin-right: 0.75rem;
2716
}
2817

2918
&__close {
3019
cursor: pointer;
31-
padding-left: 0.5rem;
20+
padding-left: 0.75rem;
21+
line-height: 0;
3222
transition: opacity 250ms ease;
3323

3424
&:hover {
3525
opacity: 0.8;
3626
}
27+
}
28+
}
3729

38-
mat-icon {
39-
vertical-align: text-bottom;
40-
}
30+
.app-notification-snackbar {
31+
--mdc-snackbar-supporting-text-font: var(--mat-sys-title-medium-font);
32+
--mdc-snackbar-supporting-text-size: var(--mat-sys-title-medium-size);
33+
--mdc-snackbar-supporting-text-line-height: var(--mat-sys-title-medium-line-height);
34+
--mdc-snackbar-supporting-text-weight: var(--mat-sys-title-medium-weight);
35+
36+
&--info {
37+
--mdc-snackbar-container-color: var(--app-notification-info-background-color);
38+
--mdc-snackbar-supporting-text-color: var(--app-notification-info-color);
39+
}
40+
41+
&--success {
42+
--mdc-snackbar-container-color: var(--app-notification-success-background-color);
43+
--mdc-snackbar-supporting-text-color: var(--app-notification-success-color);
44+
}
45+
46+
&--danger {
47+
--mdc-snackbar-container-color: var(--app-notification-danger-background-color);
48+
--mdc-snackbar-supporting-text-color: var(--app-notification-danger-color);
49+
}
50+
}
51+
52+
// Hack:
53+
// Fine adjustment to position snackbar just below header.
54+
// Note that any change in header height must be reported here.
55+
.cdk-overlay-pane:has(.app-notification-snackbar) {
56+
margin-top: 65px !important; // on mobile
57+
58+
@include app.media-breakpoint-up(md) {
59+
margin-top: 73px !important; // on desktop
4160
}
4261
}
4362

4463
:root {
45-
--app-notification-info: rgb(158, 197, 254);
46-
--app-notification-success: rgb(163, 207, 187);
47-
--app-notification-danger: rgb(241, 174, 181);
64+
--app-notification-info-background-color: rgb(207, 226, 255);
65+
--app-notification-info-color: rgb(5, 44, 101);
66+
67+
--app-notification-success-background-color: rgb(209, 231, 221);
68+
--app-notification-success-color: rgb(10, 54, 34);
69+
70+
--app-notification-danger-background-color: rgb(248, 215, 218);
71+
--app-notification-danger-color: rgb(88, 21, 28);
4872
}
4973

5074
.gbl-theme-dark {
51-
--app-notification-info: rgb(13, 110, 253);
52-
--app-notification-success: rgb(25, 135, 84);
53-
--app-notification-danger: rgb(220, 53, 69);
75+
--app-notification-info-background-color: rgb(5, 44, 101);
76+
--app-notification-info-color: rgb(207, 226, 255);
77+
78+
--app-notification-success-background-color: rgb(10, 54, 34);
79+
--app-notification-success-color: rgb(209, 231, 221);
80+
81+
--app-notification-danger-background-color: rgb(88, 21, 28);
82+
--app-notification-danger-color: rgb(248, 215, 218);
5483
}

client/src/app/shared/notification/notification.service.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,20 @@ export class NotificationService {
1212
readonly DURATION = 7000;
1313

1414
show(message: NotificationMessage, type: NotificationType = 'info') {
15-
const data: Notification = { message, type };
16-
return this.matSnackBar.openFromComponent(NotificationComponent, { data, duration: this.DURATION });
15+
return this.matSnackBar.openFromComponent(NotificationComponent, {
16+
data: { message, type } satisfies Notification,
17+
panelClass: this.panelClass(type),
18+
verticalPosition: 'top',
19+
horizontalPosition: 'center',
20+
duration: this.DURATION,
21+
});
1722
}
1823

1924
showError() {
2025
return this.show($localize`:@@Message.ErrorOccured:Une erreur s'est produite.`, 'danger');
2126
}
27+
28+
private panelClass(type: NotificationType) {
29+
return ['app-notification-snackbar', `app-notification-snackbar--${type}`];
30+
}
2231
}

0 commit comments

Comments
 (0)