From 8ccffaa97dd21d711f53182c2f3dacf8b656ed6c Mon Sep 17 00:00:00 2001 From: Igor Kulikov Date: Mon, 23 Nov 2026 16:53:35 +0200 Subject: [PATCH] fix: hiding a Home card shows the platform's toast with Undo, styled as the design's dark message; the platform's toast can carry an action in place of Close --- .../core/notification/notification.models.ts | 5 +- .../home/components/home-card.component.ts | 19 ++++--- .../home/components/home-toast.scss | 49 +++++++++++++++++++ .../components/snack-bar-component.html | 11 +++-- .../app/shared/components/toast.directive.ts | 4 +- 5 files changed, 76 insertions(+), 12 deletions(-) create mode 100644 ui-ngx/src/app/modules/home/pages/home-links/home/components/home-toast.scss diff --git a/ui-ngx/src/app/core/notification/notification.models.ts b/ui-ngx/src/app/core/notification/notification.models.ts index cd8428cd75..75c81dce74 100644 --- a/ui-ngx/src/app/core/notification/notification.models.ts +++ b/ui-ngx/src/app/core/notification/notification.models.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 export interface NotificationState { notification: NotificationMessage; hideNotification: HideNotification; @@ -19,6 +20,8 @@ export class NotificationMessage { verticalPosition?: NotificationVerticalPosition; panelClass?: string | string[]; modern?: boolean; + actionLabel?: string; + onAction?: () => void; } export class HideNotification { diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts index 911741e6f5..d677b4606a 100644 --- a/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-card.component.ts @@ -2,7 +2,7 @@ // SPDX-License-Identifier: BUSL-1.1 import { ChangeDetectionStrategy, Component, inject, input } from '@angular/core'; import { Store } from '@ngrx/store'; -import { MatSnackBar } from '@angular/material/snack-bar'; +import { ToastNotificationService } from '@core/services/toast-notification.service'; import { TranslateService } from '@ngx-translate/core'; import { AppState } from '@core/core.state'; import { ActionPreferencesUpdateHomeCards } from '@core/auth/auth.actions'; @@ -41,7 +41,7 @@ const UNDO_MS = 6000; `, - styleUrls: ['./home-card.component.scss'], + styleUrls: ['./home-card.component.scss', './home-toast.scss'], standalone: false, changeDetection: ChangeDetectionStrategy.OnPush }) @@ -54,17 +54,22 @@ export class HomeCardComponent { expanded = input(false); private store = inject(Store); - private snackBar = inject(MatSnackBar); private translate = inject(TranslateService); + private toast = inject(ToastNotificationService); hide(): void { const id = this.card().id; const name = this.translate.instant(this.card().name); this.store.dispatch(new ActionPreferencesUpdateHomeCards({[id]: false})); - this.snackBar.open(this.translate.instant('home.customize.hidden', {name}), this.translate.instant('home.customize.undo'), { + this.toast.dispatchNotification({ + message: this.translate.instant('home.customize.hidden', {name}), + type: 'info', duration: UNDO_MS, - horizontalPosition: 'end', - verticalPosition: 'bottom' - }).onAction().subscribe(() => this.store.dispatch(new ActionPreferencesUpdateHomeCards({[id]: true}))); + horizontalPosition: 'right', + verticalPosition: 'bottom', + panelClass: 'tb-home-toast', + actionLabel: this.translate.instant('home.customize.undo'), + onAction: () => this.store.dispatch(new ActionPreferencesUpdateHomeCards({[id]: true})) + }); } } diff --git a/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-toast.scss b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-toast.scss new file mode 100644 index 0000000000..5b903a528e --- /dev/null +++ b/ui-ngx/src/app/modules/home/pages/home-links/home/components/home-toast.scss @@ -0,0 +1,49 @@ +// SPDX-FileCopyrightText: Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: BUSL-1.1 +::ng-deep .mat-mdc-snack-bar-container.tb-home-toast.tb-home-toast { + .tb-toast.tb-toast.tb-toast { + gap: 4px; + box-sizing: border-box; + max-width: min(480px, calc(100vw - 16px)); + margin: 8px; + padding: 6px 6px 6px 16px; + border-radius: 4px; + background: #323232; + box-shadow: 0 3px 5px -1px rgba(0, 0, 0, 0.2), 0 6px 10px 0 rgba(0, 0, 0, 0.14), 0 1px 18px 0 rgba(0, 0, 0, 0.12); + font: 400 14px/20px var(--tb-font, Roboto, sans-serif); + letter-spacing: .25px; + color: rgba(255, 255, 255, 0.92); + } + + .tb-toast .toast-text.toast-text { + flex: 1 1 auto; + min-width: 0; + padding: 4px 8px 4px 0; + font: inherit; + letter-spacing: inherit; + color: inherit; + } + + .tb-toast .mat-mdc-button.mat-mdc-button-base.mat-mdc-button-base { + --mat-button-text-label-text-color: rgba(255, 255, 255, 0.92); + --mdc-text-button-label-text-color: rgba(255, 255, 255, 0.92); + flex: none; + min-width: 0; + height: 32px; + margin: 0; + padding: 0 10px; + border-radius: 4px; + font: 500 14px/32px var(--tb-font, Roboto, sans-serif); + letter-spacing: 0.03125em; + color: rgba(255, 255, 255, 0.92); + + &:hover { + background: rgba(255, 255, 255, 0.08); + } + + &:focus-visible { + outline: 2px solid #fff; + outline-offset: -2px; + } + } +} diff --git a/ui-ngx/src/app/shared/components/snack-bar-component.html b/ui-ngx/src/app/shared/components/snack-bar-component.html index bdb36678a4..2d6d1d6be8 100644 --- a/ui-ngx/src/app/shared/components/snack-bar-component.html +++ b/ui-ngx/src/app/shared/components/snack-bar-component.html @@ -1,7 +1,8 @@
@if (!notification.modern) {
- + } @else {
- + @if (notification.actionLabel) { + + } @else { + + }
}
diff --git a/ui-ngx/src/app/shared/components/toast.directive.ts b/ui-ngx/src/app/shared/components/toast.directive.ts index 34a0f616f0..f7072b3d8a 100644 --- a/ui-ngx/src/app/shared/components/toast.directive.ts +++ b/ui-ngx/src/app/shared/components/toast.directive.ts @@ -1,5 +1,6 @@ // SPDX-FileCopyrightText: Copyright The ThingsBoard Authors -// SPDX-License-Identifier: Apache-2.0 +// SPDX-FileCopyrightText: Modifications Copyright ThingsBoard, Inc. +// SPDX-License-Identifier: Apache-2.0 AND BUSL-1.1 import { AfterViewInit, ChangeDetectorRef, Component, ComponentRef, @@ -347,6 +348,7 @@ export class TbSnackBarComponent implements AfterViewInit, OnDestroy { action(event: MouseEvent): void { event.stopPropagation(); + this.notification.onAction?.(); if (this.snackBarRef) { this.snackBarRef.dismissWithAction(); } else {