@su-labs/notifications 22.0.0 → 22.1.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/CHANGELOG.md
ADDED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project will be documented in this file.
|
|
4
|
+
|
|
5
|
+
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
|
+
|
|
8
|
+
## [22.1.1] - 2026-11-05
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- Package homepage now points to the website with a live demo
|
|
12
|
+
|
|
13
|
+
### Fixed
|
|
14
|
+
- Notifications without `cssClass` rendered empty under Angular 22 (`NgClass` no longer accepts `undefined`); classes are now bound directly and `CommonModule` is no longer imported
|
|
15
|
+
|
|
16
|
+
## [22.1.0] - 2026-11-05
|
|
17
|
+
|
|
18
|
+
### Changed
|
|
19
|
+
- Notification logic moved to the framework-agnostic `@su-labs/core/notifications`; `SuNotificationService` is now an Angular wrapper around `SuNotificationController` with the same public API
|
|
20
|
+
- Added `@su-labs/core` as a dependency
|
|
21
|
+
- README links to the `@su-labs/core` installation guides for non-Angular projects
|
|
22
|
+
|
|
23
|
+
### Fixed
|
|
24
|
+
- Auto-close timers are cancelled when a notification is dismissed or the service is destroyed
|
|
25
|
+
- Repair table of contents links in README.md
|
package/README.md
CHANGED
|
@@ -13,20 +13,22 @@
|
|
|
13
13
|
|
|
14
14
|
A highly customizable Angular notification library built with modern practices, including reactive Signals. Easily display different types of notifications with various positions, custom icons, and optional auto-closing behavior.
|
|
15
15
|
|
|
16
|
+
> **Not using Angular?** The same notification logic is available for React, Svelte, vanilla JavaScript and Node in [`@su-labs/core`](https://www.npmjs.com/package/@su-labs/core). See the [installation guides](https://github.com/Greezaaa/settings-utils-lib/blob/main/docs/README.md).
|
|
17
|
+
|
|
16
18
|
## Table of Contents
|
|
17
19
|
|
|
18
|
-
- [Why Use This Library?](
|
|
20
|
+
- [Why Use This Library?](#why-use-this-library)
|
|
19
21
|
- [Features](#features)
|
|
20
22
|
- [Installation](#installation)
|
|
21
|
-
- [Quick Start](
|
|
23
|
+
- [Quick Start](#quick-start)
|
|
22
24
|
- [Usage](#usage)
|
|
23
|
-
- [API Reference](
|
|
25
|
+
- [API Reference](#api-reference)
|
|
24
26
|
- [Configuration Options](#configuration-options)
|
|
25
27
|
- [How It Works](#how-it-works)
|
|
26
|
-
- [Browser Compatibility](
|
|
27
|
-
- [Related Libraries](
|
|
28
|
-
- [Troubleshooting](
|
|
29
|
-
- [Support](
|
|
28
|
+
- [Browser Compatibility](#browser-compatibility)
|
|
29
|
+
- [Related Libraries](#related-libraries)
|
|
30
|
+
- [Troubleshooting](#troubleshooting)
|
|
31
|
+
- [Support](#support)
|
|
30
32
|
- [Contributing](#contributing)
|
|
31
33
|
- [License](#license)
|
|
32
34
|
|
|
@@ -1,35 +1,33 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
2
|
import { ChangeDetectionStrategy, Component, Injectable, inject, signal } from "@angular/core";
|
|
3
|
-
import
|
|
4
|
-
import { CommonModule } from "@angular/common";
|
|
3
|
+
import { SuNotificationController, isSuNotificationImageIcon } from "@su-labs/core/notifications";
|
|
5
4
|
import { DomSanitizer } from "@angular/platform-browser";
|
|
6
5
|
var SuNotificationService = class SuNotificationService {
|
|
7
|
-
|
|
6
|
+
controller = new SuNotificationController();
|
|
7
|
+
_notifications = signal(this.controller.notifications.get(), ...ngDevMode ? [{ debugName: "_notifications" }] : /* istanbul ignore next */ []);
|
|
8
8
|
notifications = this._notifications.asReadonly();
|
|
9
|
-
|
|
9
|
+
unsubscribe = this.controller.notifications.subscribe((list) => this._notifications.set(list));
|
|
10
|
+
get position() {
|
|
11
|
+
return this.controller.position.get();
|
|
12
|
+
}
|
|
13
|
+
set position(position) {
|
|
14
|
+
this.controller.configure({ position });
|
|
15
|
+
}
|
|
10
16
|
configure(cfg) {
|
|
11
|
-
|
|
17
|
+
this.controller.configure(cfg);
|
|
12
18
|
}
|
|
13
19
|
show(options) {
|
|
14
|
-
|
|
15
|
-
const notification = {
|
|
16
|
-
id,
|
|
17
|
-
type: options.type,
|
|
18
|
-
message: options.message,
|
|
19
|
-
duration: options.duration ?? 3e3,
|
|
20
|
-
autoClose: options.autoClose ?? true,
|
|
21
|
-
cssClass: options.cssClass,
|
|
22
|
-
icon: options.icon ?? true
|
|
23
|
-
};
|
|
24
|
-
this._notifications.update((list) => [...list, notification]);
|
|
25
|
-
if (notification.autoClose) setTimeout(() => this.dismiss(id), notification.duration);
|
|
26
|
-
return id;
|
|
20
|
+
return this.controller.show(options);
|
|
27
21
|
}
|
|
28
22
|
dismiss(id) {
|
|
29
|
-
this.
|
|
23
|
+
this.controller.dismiss(id);
|
|
30
24
|
}
|
|
31
25
|
clearAll() {
|
|
32
|
-
this.
|
|
26
|
+
this.controller.clearAll();
|
|
27
|
+
}
|
|
28
|
+
ngOnDestroy() {
|
|
29
|
+
this.unsubscribe();
|
|
30
|
+
this.controller.destroy();
|
|
33
31
|
}
|
|
34
32
|
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
35
33
|
minVersion: "12.0.0",
|
|
@@ -65,7 +63,7 @@ var SuNotificationComponent = class SuNotificationComponent {
|
|
|
65
63
|
this.service.dismiss(id);
|
|
66
64
|
}
|
|
67
65
|
isImage(icon) {
|
|
68
|
-
return
|
|
66
|
+
return isSuNotificationImageIcon(icon);
|
|
69
67
|
}
|
|
70
68
|
getSanitizedIcon(icon) {
|
|
71
69
|
return this.sanitizer.bypassSecurityTrustHtml(icon);
|
|
@@ -85,17 +83,8 @@ var SuNotificationComponent = class SuNotificationComponent {
|
|
|
85
83
|
isStandalone: true,
|
|
86
84
|
selector: "su-lib-notifications",
|
|
87
85
|
ngImport: i0,
|
|
88
|
-
template: "<div class=\"notification-container
|
|
86
|
+
template: "<div class=\"notification-container {{ service.position }}\">\n @for (notification of notifications(); track notification.id) {\n <div class=\"notification {{ notification.type }} {{ notification.cssClass ?? '' }}\">\n\n <div class=\"icon-container\">\n @if (notification.icon) {\n @if (isImage(notification.icon!)) {\n <img [src]=\"notification.icon\" alt=\"icon\" />\n } @else if (typeof notification.icon === 'string') {\n <span [innerHTML]=\"getSanitizedIcon(notification.icon)\"></span>\n }\n <!-- if icon === true, render default SVG via switch -->\n @else {\n @switch (notification.type) {\n @case('success') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n }\n @case('info') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"12\" y1=\"16\" x2=\"12\" y2=\"12\" />\n <line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"8\" />\n </svg>\n }\n @case('warning') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z\" />\n <line x1=\"12\" y1=\"9\" x2=\"12\" y2=\"13\" />\n <line x1=\"12\" y1=\"17\" x2=\"12\" y2=\"17\" />\n </svg>\n }\n @case('error') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"15\" y1=\"9\" x2=\"9\" y2=\"15\" />\n <line x1=\"9\" y1=\"9\" x2=\"15\" y2=\"15\" />\n </svg>\n }\n }\n }\n }\n </div>\n\n <span class=\"message\">{{ notification.message }}</span>\n\n <button class=\"close\" (click)=\"dismiss(notification.id)\" type=\"button\">×</button>\n </div>\n }\n</div>\n\n\n",
|
|
89
87
|
styles: [".notification-container{position:fixed;pointer-events:none;display:flex;gap:var(--su-notification-container-gap, 1.2rem);width:var(--su-notification-width, max-content);max-width:var(--su-notification-max-width, min(100% - 2rem, 300px));z-index:999999}.notification-container.top-right{align-items:flex-end;flex-direction:column;top:var(--su-notification-container-position, 1rem);right:var(--su-notification-container-position, 1rem)}.notification-container.top-left{align-items:flex-start;flex-direction:column;top:var(--su-notification-container-position, 1rem);left:var(--su-notification-container-position, 1rem)}.notification-container.bottom-right{align-items:flex-end;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);right:var(--su-notification-container-position, 1rem)}.notification-container.bottom-left{align-items:flex-start;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);left:var(--su-notification-container-position, 1rem)}.notification-container.top-center{align-items:center;flex-direction:column;top:var(--su-notification-container-position, 1rem);left:50%;translate:-50% 0}.notification-container.bottom-center{align-items:center;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);left:50%;translate:-50% 0}.notification{position:relative;pointer-events:auto;background-color:var(--su-notification-background-color, #fff);color:var(--su-notification-text-color, #333);padding-block:var(--su-notification-padding-block, 1rem);padding-inline:var(--su-notification-padding-inline, 1.25rem);box-shadow:0 4px 8px var(--su-notification-box-shadow, rgba(0, 0, 0, .15));display:flex;align-items:center;gap:1rem;transition:transform .2s ease,opacity .2s ease}.notification.success{border-left:4px solid var(--su-notification-success-border-color, #4caf50)}.notification.info{border-left:4px solid var(--su-notification-info-border-color, #2196f3)}.notification.warning{border-left:4px solid var(--su-notification-warning-border-color, #ff9800)}.notification.error{border-left:4px solid var(--su-notification-error-border-color, #f44336)}.notification.custom{border-left:4px solid var(--su-notification-custom-border-color, #9c27b0)}.notification .icon-container{display:flex;align-items:center;justify-content:center;width:var(--su-notification-icon-width, 24px);height:var(--su-notification-icon-height, var(--su-notification-icon-width, 24px));color:var(--su-notification-icon-color, currentColor)}.notification .icon-container .icon{width:100%;height:100%}.notification .message{flex:1}.notification .close{position:absolute;width:var(--su-notification-close-btn-size, 20px);height:var(--su-notification-close-btn-size, 20px);top:calc(var(--su-notification-close-btn-size, 20px) * -.5);right:calc(var(--su-notification-close-btn-size, 20px) * -.5);background:var(--su-notification-close-btn-background-color, var(--su-notification-background-color, #fff));color:var(--su-notification-close-btn-text-color, var(--su-notification-text-color, #333));border:1px solid var(--su-notification-close-btn-border-color, rgba(0, 0, 0, 0));border-radius:var(--su-notification-close-btn-border-radius, 50%);box-shadow:0 4px 8px var(--su-notification-box-shadow, rgba(0, 0, 0, .15));font-size:var(--su-notification-close-btn-font-size, 1rem);display:flex;justify-content:center;align-items:center;line-height:1;cursor:pointer}.notification .close:hover{background:var(--su-notification-close-btn-hover-background, rgba(51, 51, 51, .5));color:var(--su-notification-close-btn-hover-color, #fff)}\n"],
|
|
90
|
-
dependencies: [{
|
|
91
|
-
kind: "ngmodule",
|
|
92
|
-
type: CommonModule
|
|
93
|
-
}, {
|
|
94
|
-
kind: "directive",
|
|
95
|
-
type: i1.NgClass,
|
|
96
|
-
selector: "[ngClass]",
|
|
97
|
-
inputs: ["class", "ngClass"]
|
|
98
|
-
}],
|
|
99
88
|
changeDetection: i0.ChangeDetectionStrategy.Eager
|
|
100
89
|
});
|
|
101
90
|
};
|
|
@@ -109,9 +98,8 @@ i0.ɵɵngDeclareClassMetadata({
|
|
|
109
98
|
args: [{
|
|
110
99
|
selector: "su-lib-notifications",
|
|
111
100
|
standalone: true,
|
|
112
|
-
imports: [CommonModule],
|
|
113
101
|
changeDetection: ChangeDetectionStrategy.Eager,
|
|
114
|
-
template: "<div class=\"notification-container
|
|
102
|
+
template: "<div class=\"notification-container {{ service.position }}\">\n @for (notification of notifications(); track notification.id) {\n <div class=\"notification {{ notification.type }} {{ notification.cssClass ?? '' }}\">\n\n <div class=\"icon-container\">\n @if (notification.icon) {\n @if (isImage(notification.icon!)) {\n <img [src]=\"notification.icon\" alt=\"icon\" />\n } @else if (typeof notification.icon === 'string') {\n <span [innerHTML]=\"getSanitizedIcon(notification.icon)\"></span>\n }\n <!-- if icon === true, render default SVG via switch -->\n @else {\n @switch (notification.type) {\n @case('success') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n }\n @case('info') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"12\" y1=\"16\" x2=\"12\" y2=\"12\" />\n <line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"8\" />\n </svg>\n }\n @case('warning') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z\" />\n <line x1=\"12\" y1=\"9\" x2=\"12\" y2=\"13\" />\n <line x1=\"12\" y1=\"17\" x2=\"12\" y2=\"17\" />\n </svg>\n }\n @case('error') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"15\" y1=\"9\" x2=\"9\" y2=\"15\" />\n <line x1=\"9\" y1=\"9\" x2=\"15\" y2=\"15\" />\n </svg>\n }\n }\n }\n }\n </div>\n\n <span class=\"message\">{{ notification.message }}</span>\n\n <button class=\"close\" (click)=\"dismiss(notification.id)\" type=\"button\">×</button>\n </div>\n }\n</div>\n\n\n",
|
|
115
103
|
styles: [".notification-container{position:fixed;pointer-events:none;display:flex;gap:var(--su-notification-container-gap, 1.2rem);width:var(--su-notification-width, max-content);max-width:var(--su-notification-max-width, min(100% - 2rem, 300px));z-index:999999}.notification-container.top-right{align-items:flex-end;flex-direction:column;top:var(--su-notification-container-position, 1rem);right:var(--su-notification-container-position, 1rem)}.notification-container.top-left{align-items:flex-start;flex-direction:column;top:var(--su-notification-container-position, 1rem);left:var(--su-notification-container-position, 1rem)}.notification-container.bottom-right{align-items:flex-end;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);right:var(--su-notification-container-position, 1rem)}.notification-container.bottom-left{align-items:flex-start;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);left:var(--su-notification-container-position, 1rem)}.notification-container.top-center{align-items:center;flex-direction:column;top:var(--su-notification-container-position, 1rem);left:50%;translate:-50% 0}.notification-container.bottom-center{align-items:center;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);left:50%;translate:-50% 0}.notification{position:relative;pointer-events:auto;background-color:var(--su-notification-background-color, #fff);color:var(--su-notification-text-color, #333);padding-block:var(--su-notification-padding-block, 1rem);padding-inline:var(--su-notification-padding-inline, 1.25rem);box-shadow:0 4px 8px var(--su-notification-box-shadow, rgba(0, 0, 0, .15));display:flex;align-items:center;gap:1rem;transition:transform .2s ease,opacity .2s ease}.notification.success{border-left:4px solid var(--su-notification-success-border-color, #4caf50)}.notification.info{border-left:4px solid var(--su-notification-info-border-color, #2196f3)}.notification.warning{border-left:4px solid var(--su-notification-warning-border-color, #ff9800)}.notification.error{border-left:4px solid var(--su-notification-error-border-color, #f44336)}.notification.custom{border-left:4px solid var(--su-notification-custom-border-color, #9c27b0)}.notification .icon-container{display:flex;align-items:center;justify-content:center;width:var(--su-notification-icon-width, 24px);height:var(--su-notification-icon-height, var(--su-notification-icon-width, 24px));color:var(--su-notification-icon-color, currentColor)}.notification .icon-container .icon{width:100%;height:100%}.notification .message{flex:1}.notification .close{position:absolute;width:var(--su-notification-close-btn-size, 20px);height:var(--su-notification-close-btn-size, 20px);top:calc(var(--su-notification-close-btn-size, 20px) * -.5);right:calc(var(--su-notification-close-btn-size, 20px) * -.5);background:var(--su-notification-close-btn-background-color, var(--su-notification-background-color, #fff));color:var(--su-notification-close-btn-text-color, var(--su-notification-text-color, #333));border:1px solid var(--su-notification-close-btn-border-color, rgba(0, 0, 0, 0));border-radius:var(--su-notification-close-btn-border-radius, 50%);box-shadow:0 4px 8px var(--su-notification-box-shadow, rgba(0, 0, 0, .15));font-size:var(--su-notification-close-btn-font-size, 1rem);display:flex;justify-content:center;align-items:center;line-height:1;cursor:pointer}.notification .close:hover{background:var(--su-notification-close-btn-hover-background, rgba(51, 51, 51, .5));color:var(--su-notification-close-btn-hover-color, #fff)}\n"]
|
|
116
104
|
}]
|
|
117
105
|
}]
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"su-labs-notifications.mjs","names":[],"sources":["../../../../projects/su-labs/notifications/src/lib/notification.service.ts","../../../../projects/su-labs/notifications/src/lib/notification.component.ts","../../../../projects/su-labs/notifications/src/lib/notification.component.html"],"sourcesContent":["import { Injectable, signal } from '@angular/core';\nimport {\n SuNotification,\n SuNotificationOptions,\n SuNotificationPosition,\n} from '
|
|
1
|
+
{"version":3,"file":"su-labs-notifications.mjs","names":[],"sources":["../../../../projects/su-labs/notifications/src/lib/notification.service.ts","../../../../projects/su-labs/notifications/src/lib/notification.component.ts","../../../../projects/su-labs/notifications/src/lib/notification.component.html"],"sourcesContent":["import { Injectable, OnDestroy, signal } from '@angular/core';\nimport {\n SuNotification,\n SuNotificationConfig,\n SuNotificationController,\n SuNotificationOptions,\n SuNotificationPosition,\n} from '@su-labs/core/notifications';\n\n/**\n * Angular service for managing notifications.\n *\n * Thin wrapper around the framework-agnostic `SuNotificationController` from\n * `@su-labs/core/notifications` that exposes the notifications as an Angular signal.\n */\n@Injectable({ providedIn: 'root' })\nexport class SuNotificationService implements OnDestroy {\n /** Framework-agnostic notification logic */\n private readonly controller = new SuNotificationController();\n\n /** Internal signal holding the list of notifications, kept in sync with the controller */\n private readonly _notifications = signal<SuNotification[]>(this.controller.notifications.get());\n\n /**\n * Read-only access to the notifications list.\n * Can be used in templates for reactive updates.\n */\n readonly notifications = this._notifications.asReadonly();\n\n /** Stops syncing the controller's notifications into the signal */\n private readonly unsubscribe = this.controller.notifications.subscribe((list) => this._notifications.set(list));\n\n /**\n * Position where notifications appear on the screen.\n * Can also be set via the `configure` method.\n * @default 'top-right'\n */\n get position(): SuNotificationPosition {\n return this.controller.position.get();\n }\n\n set position(position: SuNotificationPosition) {\n this.controller.configure({ position });\n }\n\n /**\n * Configure the notification service.\n * @param cfg Configuration object\n * @param cfg.position Optional position to display notifications.\n */\n configure(cfg: SuNotificationConfig): void {\n this.controller.configure(cfg);\n }\n\n /**\n * Show a new notification.\n * @param options Options to configure the notification.\n * @returns The unique ID of the notification.\n */\n show(options: SuNotificationOptions): string {\n return this.controller.show(options);\n }\n\n /**\n * Dismiss a specific notification by its ID.\n * @param id ID of the notification to remove.\n */\n dismiss(id: string): void {\n this.controller.dismiss(id);\n }\n\n /**\n * Clear all notifications immediately.\n */\n clearAll(): void {\n this.controller.clearAll();\n }\n\n /** Angular lifecycle hook for service destruction */\n ngOnDestroy(): void {\n this.unsubscribe();\n this.controller.destroy();\n }\n}\n","import { Component, inject, ChangeDetectionStrategy } from '@angular/core';\nimport { SuNotificationService } from './notification.service';\nimport { DomSanitizer, SafeHtml } from '@angular/platform-browser';\nimport { isSuNotificationImageIcon } from '@su-labs/core/notifications';\n\n/**\n * Component to display notifications on the screen.\n *\n * Uses `SuNotificationService` to manage and render notifications.\n */\n@Component({\n selector: 'su-lib-notifications',\n standalone: true,\n templateUrl: './notification.component.html',\n changeDetection: ChangeDetectionStrategy.Eager,\n styleUrls: ['./notification.component.scss'],\n})\nexport class SuNotificationComponent {\n /** Injected notification service */\n service = inject(SuNotificationService);\n\n /** Read-only signal of the current notifications */\n notifications = this.service.notifications;\n\n /** Angular sanitizer to safely render inline SVG strings */\n private sanitizer = inject(DomSanitizer);\n\n /**\n * Dismiss a notification by its ID.\n * Delegates to the service.\n * @param id ID of the notification to dismiss\n */\n dismiss(id: string): void {\n this.service.dismiss(id);\n }\n\n /**\n * Checks if the provided `icon` value should be rendered as an image (`<img>`).\n * Inline SVG strings are rendered with `[innerHTML]` instead.\n * See `isSuNotificationImageIcon` in `@su-labs/core/notifications` for the rules.\n *\n * @param icon The icon value from the notification (boolean or string)\n * @returns `true` if the icon is an image path or URL\n */\n isImage(icon: string | boolean): boolean {\n return isSuNotificationImageIcon(icon);\n }\n\n /**\n * Sanitizes an inline SVG string so it can be safely rendered with [innerHTML].\n *\n * @param icon Inline SVG string\n * @returns SafeHtml object that can be bound to [innerHTML]\n */\n getSanitizedIcon(icon: string): SafeHtml {\n return this.sanitizer.bypassSecurityTrustHtml(icon);\n }\n}\n","<div class=\"notification-container {{ service.position }}\">\n\t@for (notification of notifications(); track notification.id) {\n\t<div class=\"notification {{ notification.type }} {{ notification.cssClass ?? '' }}\">\n\n\t\t<div class=\"icon-container\">\n\t\t\t@if (notification.icon) {\n\t\t\t\t@if (isImage(notification.icon!)) {\n\t\t\t\t\t<img [src]=\"notification.icon\" alt=\"icon\" />\n\t\t\t\t} @else if (typeof notification.icon === 'string') {\n\t\t\t\t\t<span [innerHTML]=\"getSanitizedIcon(notification.icon)\"></span>\n\t\t\t\t}\n\t\t\t<!-- if icon === true, render default SVG via switch -->\n\t\t\t\t@else {\n\t\t\t\t\t@switch (notification.type) {\n\t\t\t\t\t@case('success') {\n\t\t\t\t\t\t<svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n\t\t\t\t\t\t\tstroke-linecap=\"round\" stroke-linejoin=\"round\">\n\t\t\t\t\t\t\t<path d=\"M20 6L9 17l-5-5\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t}\n\t\t\t\t\t@case('info') {\n\t\t\t\t\t\t<svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n\t\t\t\t\t\t\tstroke-linecap=\"round\" stroke-linejoin=\"round\">\n\t\t\t\t\t\t\t<circle cx=\"12\" cy=\"12\" r=\"10\" />\n\t\t\t\t\t\t\t<line x1=\"12\" y1=\"16\" x2=\"12\" y2=\"12\" />\n\t\t\t\t\t\t\t<line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"8\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t}\n\t\t\t\t\t@case('warning') {\n\t\t\t\t\t\t<svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n\t\t\t\t\t\t\tstroke-linecap=\"round\" stroke-linejoin=\"round\">\n\t\t\t\t\t\t\t<path d=\"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z\" />\n\t\t\t\t\t\t\t<line x1=\"12\" y1=\"9\" x2=\"12\" y2=\"13\" />\n\t\t\t\t\t\t\t<line x1=\"12\" y1=\"17\" x2=\"12\" y2=\"17\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t}\n\t\t\t\t\t@case('error') {\n\t\t\t\t\t\t<svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n\t\t\t\t\t\t\tstroke-linecap=\"round\" stroke-linejoin=\"round\">\n\t\t\t\t\t\t\t<circle cx=\"12\" cy=\"12\" r=\"10\" />\n\t\t\t\t\t\t\t<line x1=\"15\" y1=\"9\" x2=\"9\" y2=\"15\" />\n\t\t\t\t\t\t\t<line x1=\"9\" y1=\"9\" x2=\"15\" y2=\"15\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t</div>\n\n\t\t<span class=\"message\">{{ notification.message }}</span>\n\n\t\t<button class=\"close\" (click)=\"dismiss(notification.id)\" type=\"button\">×</button>\n\t</div>\n\t}\n</div>\n\n\n"],"mappings":";;;;AAgBA,IAAa,wBAAb,MAAa,sBAAqB;CAEf,aAAa,IAAI,yBAAwB;CAGzC,iBAAiB,OAAyB,KAAK,WAAW,cAAc,IAAG,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,iBAAA,CAAA,+BAAA,CAAA,CAAA;CAMtF,gBAAgB,KAAK,eAAe,WAAU;CAGtC,cAAc,KAAK,WAAW,cAAc,WAAW,SAAS,KAAK,eAAe,IAAI,IAAI,CAAC;CAO9G,IAAI,WAAQ;EACV,OAAO,KAAK,WAAW,SAAS,IAAG;CACrC;CAEA,IAAI,SAAS,UAAgC;EAC3C,KAAK,WAAW,UAAU,EAAE,SAAQ,CAAE;CACxC;CAOA,UAAU,KAAyB;EACjC,KAAK,WAAW,UAAU,GAAG;CAC/B;CAOA,KAAK,SAA8B;EACjC,OAAO,KAAK,WAAW,KAAK,OAAO;CACrC;CAMA,QAAQ,IAAU;EAChB,KAAK,WAAW,QAAQ,EAAE;CAC5B;CAKA,WAAQ;EACN,KAAK,WAAW,SAAQ;CAC1B;CAGA,cAAW;EACT,KAAK,YAAW;EAChB,KAAK,WAAW,QAAO;CACzB;CAlEW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAqB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAArB,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAqB,YADR;CAAM,CAAA;;AACnB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAqB,YAAA,CAAA;EADjC,MAAA;EAAW,MAAA,CAAA,EAAE,YAAY,OAAM,CAAE;;;ACElC,IAAa,0BAAb,MAAa,wBAAuB;CAElC,UAAU,OAAO,qBAAqB;CAGtC,gBAAgB,KAAK,QAAQ;CAGrB,YAAY,OAAO,YAAY;CAOvC,QAAQ,IAAU;EAChB,KAAK,QAAQ,QAAQ,EAAE;CACzB;CAUA,QAAQ,MAAsB;EAC5B,OAAO,0BAA0B,IAAI;CACvC;CAQA,iBAAiB,MAAY;EAC3B,OAAO,KAAK,UAAU,wBAAwB,IAAI;CACpD;CAvCW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAuB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAvB,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAuB,cAAA;EAAA,UAAA;EAAA,UAAA;EAAA,UCjBpC;EAyDA,QAAA,CAAA,ohHAAA;EAAA,iBAAA,GAAA,wBAAA;CAAA,CAAA;;ADxCa,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAuB,YAAA,CAAA;EAPnC,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAsB,YACpB;GAAI,iBAEC,wBAAwB;GAAK,UAAA;GAAA,QAAA,CAAA,ohHAAA;EAAA,CAAA"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@su-labs/notifications",
|
|
3
|
-
"version": "22.
|
|
3
|
+
"version": "22.1.1",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"angular",
|
|
6
6
|
"notifications",
|
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"snack-bar",
|
|
18
18
|
"library"
|
|
19
19
|
],
|
|
20
|
-
"homepage": "https://github.
|
|
20
|
+
"homepage": "https://greezaaa.github.io/settings-utils-lib/notifications/",
|
|
21
21
|
"author": {
|
|
22
22
|
"name": "Yevheniy Alekseyev",
|
|
23
23
|
"email": "yev.alekseyev@gmail.com",
|
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
"@angular/core": "^22.0.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
|
+
"@su-labs/core": "^1.0.0",
|
|
39
40
|
"tslib": "^2.3.0"
|
|
40
41
|
},
|
|
41
42
|
"sideEffects": false,
|
|
@@ -1,92 +1,44 @@
|
|
|
1
1
|
import * as i0 from "@angular/core";
|
|
2
|
+
import { OnDestroy } from "@angular/core";
|
|
3
|
+
import { SuNotification, SuNotification as SuNotification$1, SuNotificationConfig, SuNotificationConfig as SuNotificationConfig$1, SuNotificationOptions, SuNotificationOptions as SuNotificationOptions$1, SuNotificationPosition, SuNotificationPosition as SuNotificationPosition$1, SuNotificationType } from "@su-labs/core/notifications";
|
|
2
4
|
import { SafeHtml } from "@angular/platform-browser";
|
|
3
5
|
/**
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
export type SuNotificationType = 'info' | 'success' | 'warning' | 'error' | 'custom';
|
|
7
|
-
/**
|
|
8
|
-
* Options for configuring a notification.
|
|
9
|
-
*/
|
|
10
|
-
export interface SuNotificationOptions {
|
|
11
|
-
/**
|
|
12
|
-
* The type of notification. Determines styling and default icon.
|
|
13
|
-
*/
|
|
14
|
-
type: SuNotificationType;
|
|
15
|
-
/**
|
|
16
|
-
* The main message text to display in the notification.
|
|
17
|
-
*/
|
|
18
|
-
message: string;
|
|
19
|
-
/**
|
|
20
|
-
* Duration in milliseconds before the notification automatically closes.
|
|
21
|
-
* @default 3000
|
|
22
|
-
*/
|
|
23
|
-
duration?: number;
|
|
24
|
-
/**
|
|
25
|
-
* Whether the notification should automatically close after the duration.
|
|
26
|
-
* @default true
|
|
27
|
-
*/
|
|
28
|
-
autoClose?: boolean;
|
|
29
|
-
/**
|
|
30
|
-
* Additional CSS class(es) to apply to the notification for custom styling.
|
|
31
|
-
*/
|
|
32
|
-
cssClass?: string;
|
|
33
|
-
/**
|
|
34
|
-
* Icon configuration for the notification:
|
|
35
|
-
* - `false`: no icon
|
|
36
|
-
* - `true`: default icon for the given type
|
|
37
|
-
* - `string`: custom SVG markup or URL for the icon
|
|
38
|
-
*/
|
|
39
|
-
icon?: boolean | string;
|
|
40
|
-
}
|
|
41
|
-
/**
|
|
42
|
-
* A notification instance with a unique identifier.
|
|
43
|
-
*/
|
|
44
|
-
export interface SuNotification extends SuNotificationOptions {
|
|
45
|
-
/**
|
|
46
|
-
* Unique identifier for the notification instance.
|
|
47
|
-
*/
|
|
48
|
-
id: string;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Possible positions for displaying notifications on the screen.
|
|
52
|
-
*/
|
|
53
|
-
export type SuNotificationPosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
|
|
54
|
-
/**
|
|
55
|
-
* Service for managing notifications.
|
|
6
|
+
* Angular service for managing notifications.
|
|
56
7
|
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
8
|
+
* Thin wrapper around the framework-agnostic `SuNotificationController` from
|
|
9
|
+
* `@su-labs/core/notifications` that exposes the notifications as an Angular signal.
|
|
59
10
|
*/
|
|
60
|
-
export declare class SuNotificationService {
|
|
61
|
-
/**
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
private _notifications;
|
|
11
|
+
export declare class SuNotificationService implements OnDestroy {
|
|
12
|
+
/** Framework-agnostic notification logic */
|
|
13
|
+
private readonly controller;
|
|
14
|
+
/** Internal signal holding the list of notifications, kept in sync with the controller */
|
|
15
|
+
private readonly _notifications;
|
|
65
16
|
/**
|
|
66
17
|
* Read-only access to the notifications list.
|
|
67
18
|
* Can be used in templates for reactive updates.
|
|
68
19
|
*/
|
|
69
|
-
notifications: import("@angular/core").Signal<SuNotification[]>;
|
|
20
|
+
readonly notifications: import("@angular/core").Signal<SuNotification$1[]>;
|
|
21
|
+
/** Stops syncing the controller's notifications into the signal */
|
|
22
|
+
private readonly unsubscribe;
|
|
70
23
|
/**
|
|
71
|
-
*
|
|
72
|
-
* Can be
|
|
24
|
+
* Position where notifications appear on the screen.
|
|
25
|
+
* Can also be set via the `configure` method.
|
|
73
26
|
* @default 'top-right'
|
|
74
27
|
*/
|
|
75
|
-
position: SuNotificationPosition;
|
|
28
|
+
get position(): SuNotificationPosition$1;
|
|
29
|
+
set position(position: SuNotificationPosition$1);
|
|
76
30
|
/**
|
|
77
31
|
* Configure the notification service.
|
|
78
32
|
* @param cfg Configuration object
|
|
79
33
|
* @param cfg.position Optional position to display notifications.
|
|
80
34
|
*/
|
|
81
|
-
configure(cfg:
|
|
82
|
-
position?: SuNotificationPosition;
|
|
83
|
-
}): void;
|
|
35
|
+
configure(cfg: SuNotificationConfig$1): void;
|
|
84
36
|
/**
|
|
85
37
|
* Show a new notification.
|
|
86
38
|
* @param options Options to configure the notification.
|
|
87
39
|
* @returns The unique ID of the notification.
|
|
88
40
|
*/
|
|
89
|
-
show(options: SuNotificationOptions): string;
|
|
41
|
+
show(options: SuNotificationOptions$1): string;
|
|
90
42
|
/**
|
|
91
43
|
* Dismiss a specific notification by its ID.
|
|
92
44
|
* @param id ID of the notification to remove.
|
|
@@ -96,6 +48,8 @@ export declare class SuNotificationService {
|
|
|
96
48
|
* Clear all notifications immediately.
|
|
97
49
|
*/
|
|
98
50
|
clearAll(): void;
|
|
51
|
+
/** Angular lifecycle hook for service destruction */
|
|
52
|
+
ngOnDestroy(): void;
|
|
99
53
|
static ɵfac: i0.ɵɵFactoryDeclaration<SuNotificationService, never>;
|
|
100
54
|
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
101
55
|
}
|
|
@@ -119,17 +73,11 @@ export declare class SuNotificationComponent {
|
|
|
119
73
|
dismiss(id: string): void;
|
|
120
74
|
/**
|
|
121
75
|
* Checks if the provided `icon` value should be rendered as an image (`<img>`).
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
* - Local or relative paths (starting with `/`)
|
|
125
|
-
* - URLs (starting with `http`)
|
|
126
|
-
* - File paths ending with `.png`, `.jpg`, or `.svg`
|
|
127
|
-
*
|
|
128
|
-
* Inline SVG strings (e.g., `<svg>...</svg>`) are **not** treated as images and
|
|
129
|
-
* should be rendered with `[innerHTML]`.
|
|
76
|
+
* Inline SVG strings are rendered with `[innerHTML]` instead.
|
|
77
|
+
* See `isSuNotificationImageIcon` in `@su-labs/core/notifications` for the rules.
|
|
130
78
|
*
|
|
131
79
|
* @param icon The icon value from the notification (boolean or string)
|
|
132
|
-
* @returns `true` if the icon is an image path or URL
|
|
80
|
+
* @returns `true` if the icon is an image path or URL
|
|
133
81
|
*/
|
|
134
82
|
isImage(icon: string | boolean): boolean;
|
|
135
83
|
/**
|
|
@@ -141,4 +89,5 @@ export declare class SuNotificationComponent {
|
|
|
141
89
|
getSanitizedIcon(icon: string): SafeHtml;
|
|
142
90
|
static ɵfac: i0.ɵɵFactoryDeclaration<SuNotificationComponent, never>;
|
|
143
91
|
static ɵcmp: i0.ɵɵComponentDeclaration<SuNotificationComponent, "su-lib-notifications", never, {}, {}, never, never, true, never>;
|
|
144
|
-
}
|
|
92
|
+
}
|
|
93
|
+
export type { SuNotification, SuNotificationConfig, SuNotificationOptions, SuNotificationPosition, SuNotificationType };
|