@su-labs/notifications 1.0.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/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Yevheniy Alekseyev <yev.alekseyev@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,130 @@
1
+ # Notifications
2
+
3
+ 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.
4
+
5
+ ## Features
6
+
7
+ - **Reactive Core:** Built on Angular Signals for optimal performance and reactive updates.
8
+ - **Multiple Positions:** Notifications can be displayed in six different positions (`top-right`, `top-left`, `bottom-right`, `bottom-left`, `top-center`, `bottom-center`).
9
+ - **Customizable:** Easily change themes, icons, and CSS classes to match your application's design system.
10
+ - **Icon Support:**
11
+ - Default Icons: Render a default SVG icon based on the notification type.
12
+ - Custom Icons: Use a custom SVG string or an image URL as an icon.
13
+ - **Dismissible:** Notifications can be dismissed manually or set to auto-close after a specified duration.
14
+ - **Declarative Usage:** Add a single component to your root template and use the service from anywhere in your application.
15
+
16
+ ## Installation
17
+
18
+ You can install this library via npm:
19
+
20
+ ```sh
21
+ npm install @su-labs/notifications
22
+ ```
23
+
24
+ ## Peer Dependencies
25
+
26
+ This library requires the following peer dependencies:
27
+
28
+ ```sh
29
+ npm install @angular/common@">=20.1.0" @angular/core@">=20.1.0" @angular/platform-browser@">=20.1.0"
30
+ ```
31
+
32
+ ## Usage
33
+
34
+ ### 1. Add the component to your application
35
+
36
+ Add the `<su-notifications></su-notifications>` component to your root `AppComponent` or `index.html` file. This component acts as a container for all notifications.
37
+
38
+ ```html
39
+ <!-- src/app/app.component.html -->
40
+ <su-notifications></su-notifications>
41
+ <router-outlet></router-outlet>
42
+ ```
43
+
44
+ ### 2. Inject the service and show a notification
45
+
46
+ Inject the `SuNotificationService` into any component or service and call its `show()` method to display a new notification.
47
+
48
+ ```ts
49
+ // src/app/my-example.component.ts
50
+ import { Component, inject } from '@angular/core';
51
+ import { SuNotificationService } from '@su-labs/notifications';
52
+ import { CommonModule } from '@angular/common';
53
+
54
+ @Component({
55
+ selector: 'app-my-example',
56
+ standalone: true,
57
+ imports: [CommonModule],
58
+ template: `
59
+ <div class="example-container">
60
+ <button (click)="showSuccess()">Show Success</button>
61
+ <button (click)="showError()">Show Error</button>
62
+ <button (click)="showCustom()">Show Custom Icon</button>
63
+ </div>
64
+ `
65
+ })
66
+ export class MyExampleComponent {
67
+ private readonly notificationService = inject(SuNotificationService);
68
+
69
+ showSuccess(): void {
70
+ this.notificationService.show({
71
+ type: 'success',
72
+ message: 'Your action was successful!'
73
+ });
74
+ }
75
+
76
+ showError(): void {
77
+ this.notificationService.show({
78
+ type: 'error',
79
+ message: 'Something went wrong. Please try again.'
80
+ });
81
+ }
82
+
83
+ showCustom(): void {
84
+ this.notificationService.show({
85
+ type: 'info',
86
+ message: 'This is a custom icon notification.',
87
+ icon: `<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-zap"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"></polygon></svg>`
88
+ });
89
+ }
90
+ }
91
+ ```
92
+
93
+ ### 3. Customize the position
94
+
95
+ You can configure the global position of all notifications by directly setting the position property on the service instance. This is best done during application initialization.
96
+
97
+
98
+ ```ts
99
+ // src/app/app.config.ts
100
+ import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
101
+ import { SuNotificationService } from '@su-labs/notifications';
102
+
103
+ export const appConfig: ApplicationConfig = {
104
+ providers: [
105
+ provideAppInitializer(() => {
106
+ const notificationService = inject(SuNotificationService);
107
+ notificationService.position = 'bottom-left';
108
+ }),
109
+ // other providers
110
+ ],
111
+ };
112
+ ```
113
+
114
+ ## How It Works
115
+
116
+ The library consists of a stateless service (`SuNotificationService`) and a presentational component (`SuNotificationComponent`).
117
+
118
+ The service manages a list of notifications using a private Signal. When you call `service.show()`, it adds a new notification object to the signal's array. The component then reads from this signal and automatically renders a notification for each item in the array. This approach keeps the state management decoupled from the UI, making it highly flexible and testable.
119
+
120
+ The component's icons are rendered using `[innerHTML]` to safely inject SVG markup into the template. Angular's `DomSanitizer` is used to prevent security risks like Cross-Site Scripting (XSS) attacks.
121
+
122
+ ## Contributing
123
+
124
+ If you find any bugs or have feature requests, please open an issue or submit a pull request on our [GitHub repository](https://github.com/Greezaaa/settings-utils-lib.git).
125
+
126
+ To contribute code, please ensure your changes include unit tests to maintain code quality. Please see the main repository's `README.md` for details on the monorepo structure.
127
+
128
+ ## License
129
+
130
+ This project is licensed under the MIT License. See the [LICENSE](https://github.com/Greezaaa/settings-utils-lib/blob/main/projects/su-labs/notifications/LICENSE) file for details.
@@ -0,0 +1,205 @@
1
+ import * as i0 from '@angular/core';
2
+ import { signal, Injectable, inject, Component } from '@angular/core';
3
+ import * as i1 from '@angular/common';
4
+ import { CommonModule } from '@angular/common';
5
+ import { DomSanitizer } from '@angular/platform-browser';
6
+ import { describe, it, expect, vi } from 'vitest';
7
+
8
+ /**
9
+ * Service for managing notifications.
10
+ *
11
+ * Provides methods to show, dismiss, and clear notifications.
12
+ * Notifications are reactive signals, making them easy to bind in templates.
13
+ */
14
+ class SuNotificationService {
15
+ /**
16
+ * Internal signal holding the list of notifications.
17
+ */
18
+ _notifications = signal([], ...(ngDevMode ? [{ debugName: "_notifications" }] : []));
19
+ /**
20
+ * Read-only access to the notifications list.
21
+ * Can be used in templates for reactive updates.
22
+ */
23
+ notifications = this._notifications.asReadonly();
24
+ /**
25
+ * Default position where notifications will appear on the screen.
26
+ * Can be configured via `configure` method.
27
+ * @default 'top-right'
28
+ */
29
+ position = 'top-right';
30
+ /**
31
+ * Configure the notification service.
32
+ * @param cfg Configuration object
33
+ * @param cfg.position Optional position to display notifications.
34
+ */
35
+ configure(cfg) {
36
+ if (cfg.position)
37
+ this.position = cfg.position;
38
+ }
39
+ /**
40
+ * Show a new notification.
41
+ * @param options Options to configure the notification.
42
+ * @returns The unique ID of the notification.
43
+ */
44
+ show(options) {
45
+ const id = crypto.randomUUID();
46
+ const notification = {
47
+ id,
48
+ type: options.type,
49
+ message: options.message,
50
+ duration: options.duration ?? 3000,
51
+ autoClose: options.autoClose ?? true,
52
+ cssClass: options.cssClass,
53
+ icon: options.icon ?? true,
54
+ };
55
+ this._notifications.update((list) => [...list, notification]);
56
+ if (notification.autoClose) {
57
+ setTimeout(() => this.dismiss(id), notification.duration);
58
+ }
59
+ return id;
60
+ }
61
+ /**
62
+ * Dismiss a specific notification by its ID.
63
+ * @param id ID of the notification to remove.
64
+ */
65
+ dismiss(id) {
66
+ this._notifications.update((list) => list.filter((n) => n.id !== id));
67
+ }
68
+ /**
69
+ * Clear all notifications immediately.
70
+ */
71
+ clearAll() {
72
+ this._notifications.set([]);
73
+ }
74
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: SuNotificationService, deps: [], target: i0.ɵɵFactoryTarget.Injectable });
75
+ static ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: SuNotificationService, providedIn: 'root' });
76
+ }
77
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: SuNotificationService, decorators: [{
78
+ type: Injectable,
79
+ args: [{ providedIn: 'root' }]
80
+ }] });
81
+
82
+ /**
83
+ * Component to display notifications on the screen.
84
+ *
85
+ * Uses `SuNotificationService` to manage and render notifications.
86
+ */
87
+ class SuNotificationComponent {
88
+ /** Injected notification service */
89
+ service = inject(SuNotificationService);
90
+ /** Read-only signal of the current notifications */
91
+ notifications = this.service.notifications;
92
+ /** Angular sanitizer to safely render inline SVG strings */
93
+ sanitizer = inject(DomSanitizer);
94
+ /**
95
+ * Dismiss a notification by its ID.
96
+ * Delegates to the service.
97
+ * @param id ID of the notification to dismiss
98
+ */
99
+ dismiss(id) {
100
+ this.service.dismiss(id);
101
+ }
102
+ /**
103
+ * Checks if the provided `icon` value should be rendered as an image (`<img>`).
104
+ *
105
+ * Determines whether the `icon` is a string pointing to an image file:
106
+ * - Local or relative paths (starting with `/`)
107
+ * - URLs (starting with `http`)
108
+ * - File paths ending with `.png`, `.jpg`, or `.svg`
109
+ *
110
+ * Inline SVG strings (e.g., `<svg>...</svg>`) are **not** treated as images and
111
+ * should be rendered with `[innerHTML]`.
112
+ *
113
+ * @param icon The icon value from the notification (boolean or string)
114
+ * @returns `true` if the icon is an image path or URL, `false` for inline SVGs or `false`
115
+ */
116
+ isImage(icon) {
117
+ return (typeof icon === 'string' &&
118
+ (icon.endsWith('.png') ||
119
+ icon.endsWith('.jpg') ||
120
+ icon.endsWith('.svg') ||
121
+ icon.startsWith('http') ||
122
+ icon.startsWith('/')));
123
+ }
124
+ /**
125
+ * Sanitizes an inline SVG string so it can be safely rendered with [innerHTML].
126
+ *
127
+ * @param icon Inline SVG string
128
+ * @returns SafeHtml object that can be bound to [innerHTML]
129
+ */
130
+ getSanitizedIcon(icon) {
131
+ return this.sanitizer.bypassSecurityTrustHtml(icon);
132
+ }
133
+ static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: SuNotificationComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
134
+ static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "20.1.7", type: SuNotificationComponent, isStandalone: true, selector: "su-lib-notifications", ngImport: i0, template: "<div class=\"notification-container\" [ngClass]=\"[service.position]\">\n\t@for (notification of notifications(); track notification.id) {\n\t<div class=\"notification\" [ngClass]=\"[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\">\u00D7</button>\n\t</div>\n\t}\n</div>\n\n\n", 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"], dependencies: [{ kind: "ngmodule", type: CommonModule }, { kind: "directive", type: i1.NgClass, selector: "[ngClass]", inputs: ["class", "ngClass"] }] });
135
+ }
136
+ i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "20.1.7", ngImport: i0, type: SuNotificationComponent, decorators: [{
137
+ type: Component,
138
+ args: [{ selector: 'su-lib-notifications', standalone: true, imports: [CommonModule], template: "<div class=\"notification-container\" [ngClass]=\"[service.position]\">\n\t@for (notification of notifications(); track notification.id) {\n\t<div class=\"notification\" [ngClass]=\"[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\">\u00D7</button>\n\t</div>\n\t}\n</div>\n\n\n", 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"] }]
139
+ }] });
140
+
141
+ describe('SuNotificationService', () => {
142
+ it('should add a notification when show() is called', () => {
143
+ const service = new SuNotificationService();
144
+ const options = {
145
+ message: 'Hello World',
146
+ type: 'success',
147
+ duration: 2000,
148
+ };
149
+ const id = service.show(options);
150
+ const notifications = service.notifications();
151
+ expect(notifications.length).toBe(1);
152
+ expect(notifications[0].id).toBe(id);
153
+ expect(notifications[0].message).toBe('Hello World');
154
+ expect(notifications[0].type).toBe('success');
155
+ });
156
+ it('should allow multiple notifications', () => {
157
+ const service = new SuNotificationService();
158
+ service.show({ message: 'First', type: 'info' });
159
+ service.show({ message: 'Second', type: 'error' });
160
+ const notifications = service.notifications();
161
+ expect(notifications.length).toBe(2);
162
+ expect(notifications.map((n) => n.message)).toEqual(['First', 'Second']);
163
+ });
164
+ it('should dismiss a notification by id', () => {
165
+ const service = new SuNotificationService();
166
+ const id = service.show({ message: 'To be removed', type: 'warning' });
167
+ service.dismiss(id);
168
+ const notifications = service.notifications();
169
+ expect(notifications.find((n) => n.id === id)).toBeUndefined();
170
+ });
171
+ it('should clear all notifications', () => {
172
+ const service = new SuNotificationService();
173
+ service.show({ message: 'One', type: 'info' });
174
+ service.show({ message: 'Two', type: 'error' });
175
+ service.clearAll();
176
+ expect(service.notifications().length).toBe(0);
177
+ });
178
+ it('should auto dismiss notification after duration', async () => {
179
+ vi.useFakeTimers();
180
+ const service = new SuNotificationService();
181
+ const id = service.show({
182
+ message: 'Auto close',
183
+ type: 'info',
184
+ duration: 1000,
185
+ });
186
+ // Initially present
187
+ expect(service.notifications().find((n) => n.id === id)).toBeDefined();
188
+ // Fast forward time
189
+ vi.advanceTimersByTime(1000);
190
+ // Should be removed
191
+ expect(service.notifications().find((n) => n.id === id)).toBeUndefined();
192
+ vi.useRealTimers();
193
+ });
194
+ });
195
+
196
+ /*
197
+ * Public API Surface of notifications
198
+ */
199
+
200
+ /**
201
+ * Generated bundle index. Do not edit.
202
+ */
203
+
204
+ export { SuNotificationComponent, SuNotificationService };
205
+ //# sourceMappingURL=su-labs-notifications.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"su-labs-notifications.mjs","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","../../../../projects/su-labs/notifications/src/lib/notification.service.spec.ts","../../../../projects/su-labs/notifications/src/public-api.ts","../../../../projects/su-labs/notifications/src/su-labs-notifications.ts"],"sourcesContent":["import { Injectable, signal } from '@angular/core';\nimport {\n SuNotification,\n SuNotificationOptions,\n SuNotificationPosition,\n} from './notification.model';\n\n/**\n * Service for managing notifications.\n *\n * Provides methods to show, dismiss, and clear notifications.\n * Notifications are reactive signals, making them easy to bind in templates.\n */\n@Injectable({ providedIn: 'root' })\nexport class SuNotificationService {\n /**\n * Internal signal holding the list of notifications.\n */\n private _notifications = signal<SuNotification[]>([]);\n\n /**\n * Read-only access to the notifications list.\n * Can be used in templates for reactive updates.\n */\n notifications = this._notifications.asReadonly();\n\n /**\n * Default position where notifications will appear on the screen.\n * Can be configured via `configure` method.\n * @default 'top-right'\n */\n position: SuNotificationPosition = 'top-right';\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: { position?: SuNotificationPosition }): void {\n if (cfg.position) this.position = cfg.position;\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 const id = crypto.randomUUID();\n const notification: SuNotification = {\n id,\n type: options.type,\n message: options.message,\n duration: options.duration ?? 3000,\n autoClose: options.autoClose ?? true,\n cssClass: options.cssClass,\n icon: options.icon ?? true,\n };\n\n this._notifications.update((list) => [...list, notification]);\n\n if (notification.autoClose) {\n setTimeout(() => this.dismiss(id), notification.duration);\n }\n\n return id;\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._notifications.update((list) => list.filter((n) => n.id !== id));\n }\n\n /**\n * Clear all notifications immediately.\n */\n clearAll(): void {\n this._notifications.set([]);\n }\n}\n","import { Component, inject } from '@angular/core';\nimport { SuNotificationService } from './notification.service';\nimport { CommonModule } from '@angular/common';\nimport { DomSanitizer, SafeHtml } from '@angular/platform-browser';\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 imports: [CommonModule],\n templateUrl: './notification.component.html',\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 *\n * Determines whether the `icon` is a string pointing to an image file:\n * - Local or relative paths (starting with `/`)\n * - URLs (starting with `http`)\n * - File paths ending with `.png`, `.jpg`, or `.svg`\n *\n * Inline SVG strings (e.g., `<svg>...</svg>`) are **not** treated as images and\n * should be rendered with `[innerHTML]`.\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, `false` for inline SVGs or `false`\n */\n isImage(icon: string | boolean): boolean {\n return (\n typeof icon === 'string' &&\n (icon.endsWith('.png') ||\n icon.endsWith('.jpg') ||\n icon.endsWith('.svg') ||\n icon.startsWith('http') ||\n icon.startsWith('/'))\n );\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\" [ngClass]=\"[service.position]\">\n\t@for (notification of notifications(); track notification.id) {\n\t<div class=\"notification\" [ngClass]=\"[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","import { describe, it, expect, vi } from 'vitest';\nimport { SuNotificationService } from './notification.service';\nimport { SuNotificationOptions } from './notification.model';\n\ndescribe('SuNotificationService', () => {\n it('should add a notification when show() is called', () => {\n const service = new SuNotificationService();\n const options: SuNotificationOptions = {\n message: 'Hello World',\n type: 'success',\n duration: 2000,\n };\n\n const id = service.show(options);\n const notifications = service.notifications();\n\n expect(notifications.length).toBe(1);\n expect(notifications[0].id).toBe(id);\n expect(notifications[0].message).toBe('Hello World');\n expect(notifications[0].type).toBe('success');\n });\n\n it('should allow multiple notifications', () => {\n const service = new SuNotificationService();\n service.show({ message: 'First', type: 'info' });\n service.show({ message: 'Second', type: 'error' });\n\n const notifications = service.notifications();\n expect(notifications.length).toBe(2);\n expect(notifications.map((n) => n.message)).toEqual(['First', 'Second']);\n });\n\n it('should dismiss a notification by id', () => {\n const service = new SuNotificationService();\n const id = service.show({ message: 'To be removed', type: 'warning' });\n\n service.dismiss(id);\n\n const notifications = service.notifications();\n expect(notifications.find((n) => n.id === id)).toBeUndefined();\n });\n\n it('should clear all notifications', () => {\n const service = new SuNotificationService();\n service.show({ message: 'One', type: 'info' });\n service.show({ message: 'Two', type: 'error' });\n\n service.clearAll();\n\n expect(service.notifications().length).toBe(0);\n });\n\n it('should auto dismiss notification after duration', async () => {\n vi.useFakeTimers();\n const service = new SuNotificationService();\n const id = service.show({\n message: 'Auto close',\n type: 'info',\n duration: 1000,\n });\n\n // Initially present\n expect(service.notifications().find((n) => n.id === id)).toBeDefined();\n\n // Fast forward time\n vi.advanceTimersByTime(1000);\n\n // Should be removed\n expect(service.notifications().find((n) => n.id === id)).toBeUndefined();\n vi.useRealTimers();\n });\n});\n","/*\n * Public API Surface of notifications\n */\n\nexport * from './lib/notification.component';\nexport * from './lib/notification.service';\nexport * from './lib/notification.service.spec';\nexport * from './lib/notification.model';\n","/**\n * Generated bundle index. Do not edit.\n */\n\nexport * from './public-api';\n"],"names":[],"mappings":";;;;;;;AAOA;;;;;AAKG;MAEU,qBAAqB,CAAA;AAChC;;AAEG;AACK,IAAA,cAAc,GAAG,MAAM,CAAmB,EAAE,0DAAC;AAErD;;;AAGG;AACH,IAAA,aAAa,GAAG,IAAI,CAAC,cAAc,CAAC,UAAU,EAAE;AAEhD;;;;AAIG;IACH,QAAQ,GAA2B,WAAW;AAE9C;;;;AAIG;AACH,IAAA,SAAS,CAAC,GAA0C,EAAA;QAClD,IAAI,GAAG,CAAC,QAAQ;AAAE,YAAA,IAAI,CAAC,QAAQ,GAAG,GAAG,CAAC,QAAQ;;AAGhD;;;;AAIG;AACH,IAAA,IAAI,CAAC,OAA8B,EAAA;AACjC,QAAA,MAAM,EAAE,GAAG,MAAM,CAAC,UAAU,EAAE;AAC9B,QAAA,MAAM,YAAY,GAAmB;YACnC,EAAE;YACF,IAAI,EAAE,OAAO,CAAC,IAAI;YAClB,OAAO,EAAE,OAAO,CAAC,OAAO;AACxB,YAAA,QAAQ,EAAE,OAAO,CAAC,QAAQ,IAAI,IAAI;AAClC,YAAA,SAAS,EAAE,OAAO,CAAC,SAAS,IAAI,IAAI;YACpC,QAAQ,EAAE,OAAO,CAAC,QAAQ;AAC1B,YAAA,IAAI,EAAE,OAAO,CAAC,IAAI,IAAI,IAAI;SAC3B;AAED,QAAA,IAA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MAAM;AACZ,YAAA,QAAQ,EAAE,IAAI;AACf,SAAA,CAAC;;QAGF,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,WAAW,EAAE;;AAGtE,QAAA,EAAE,CAAC,mBAAmB,CAAC,IAAI,CAAC;;QAG5B,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC,IAAI,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,aAAa,EAAE;QACxE,EAAE,CAAC,aAAa,EAAE;AACpB,KAAC,CAAC;AACJ,CAAC,CAAC;;ACvEF;;AAEG;;ACFH;;AAEG;;;;"}
package/index.d.ts ADDED
@@ -0,0 +1,151 @@
1
+ import * as i0 from '@angular/core';
2
+ import * as _su_labs_notifications from '@su-labs/notifications';
3
+ import { SafeHtml } from '@angular/platform-browser';
4
+
5
+ /**
6
+ * Represents the type of a notification.
7
+ */
8
+ type SuNotificationType = 'info' | 'success' | 'warning' | 'error' | 'custom';
9
+ /**
10
+ * Options for configuring a notification.
11
+ */
12
+ interface SuNotificationOptions {
13
+ /**
14
+ * The type of notification. Determines styling and default icon.
15
+ */
16
+ type: SuNotificationType;
17
+ /**
18
+ * The main message text to display in the notification.
19
+ */
20
+ message: string;
21
+ /**
22
+ * Duration in milliseconds before the notification automatically closes.
23
+ * @default 3000
24
+ */
25
+ duration?: number;
26
+ /**
27
+ * Whether the notification should automatically close after the duration.
28
+ * @default true
29
+ */
30
+ autoClose?: boolean;
31
+ /**
32
+ * Additional CSS class(es) to apply to the notification for custom styling.
33
+ */
34
+ cssClass?: string;
35
+ /**
36
+ * Icon configuration for the notification:
37
+ * - `false`: no icon
38
+ * - `true`: default icon for the given type
39
+ * - `string`: custom SVG markup or URL for the icon
40
+ */
41
+ icon?: boolean | string;
42
+ }
43
+ /**
44
+ * A notification instance with a unique identifier.
45
+ */
46
+ interface SuNotification extends SuNotificationOptions {
47
+ /**
48
+ * Unique identifier for the notification instance.
49
+ */
50
+ id: string;
51
+ }
52
+ /**
53
+ * Possible positions for displaying notifications on the screen.
54
+ */
55
+ type SuNotificationPosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
56
+
57
+ /**
58
+ * Service for managing notifications.
59
+ *
60
+ * Provides methods to show, dismiss, and clear notifications.
61
+ * Notifications are reactive signals, making them easy to bind in templates.
62
+ */
63
+ declare class SuNotificationService {
64
+ /**
65
+ * Internal signal holding the list of notifications.
66
+ */
67
+ private _notifications;
68
+ /**
69
+ * Read-only access to the notifications list.
70
+ * Can be used in templates for reactive updates.
71
+ */
72
+ notifications: i0.Signal<SuNotification[]>;
73
+ /**
74
+ * Default position where notifications will appear on the screen.
75
+ * Can be configured via `configure` method.
76
+ * @default 'top-right'
77
+ */
78
+ position: SuNotificationPosition;
79
+ /**
80
+ * Configure the notification service.
81
+ * @param cfg Configuration object
82
+ * @param cfg.position Optional position to display notifications.
83
+ */
84
+ configure(cfg: {
85
+ position?: SuNotificationPosition;
86
+ }): void;
87
+ /**
88
+ * Show a new notification.
89
+ * @param options Options to configure the notification.
90
+ * @returns The unique ID of the notification.
91
+ */
92
+ show(options: SuNotificationOptions): string;
93
+ /**
94
+ * Dismiss a specific notification by its ID.
95
+ * @param id ID of the notification to remove.
96
+ */
97
+ dismiss(id: string): void;
98
+ /**
99
+ * Clear all notifications immediately.
100
+ */
101
+ clearAll(): void;
102
+ static ɵfac: i0.ɵɵFactoryDeclaration<SuNotificationService, never>;
103
+ static ɵprov: i0.ɵɵInjectableDeclaration<SuNotificationService>;
104
+ }
105
+
106
+ /**
107
+ * Component to display notifications on the screen.
108
+ *
109
+ * Uses `SuNotificationService` to manage and render notifications.
110
+ */
111
+ declare class SuNotificationComponent {
112
+ /** Injected notification service */
113
+ service: SuNotificationService;
114
+ /** Read-only signal of the current notifications */
115
+ notifications: i0.Signal<_su_labs_notifications.SuNotification[]>;
116
+ /** Angular sanitizer to safely render inline SVG strings */
117
+ private sanitizer;
118
+ /**
119
+ * Dismiss a notification by its ID.
120
+ * Delegates to the service.
121
+ * @param id ID of the notification to dismiss
122
+ */
123
+ dismiss(id: string): void;
124
+ /**
125
+ * Checks if the provided `icon` value should be rendered as an image (`<img>`).
126
+ *
127
+ * Determines whether the `icon` is a string pointing to an image file:
128
+ * - Local or relative paths (starting with `/`)
129
+ * - URLs (starting with `http`)
130
+ * - File paths ending with `.png`, `.jpg`, or `.svg`
131
+ *
132
+ * Inline SVG strings (e.g., `<svg>...</svg>`) are **not** treated as images and
133
+ * should be rendered with `[innerHTML]`.
134
+ *
135
+ * @param icon The icon value from the notification (boolean or string)
136
+ * @returns `true` if the icon is an image path or URL, `false` for inline SVGs or `false`
137
+ */
138
+ isImage(icon: string | boolean): boolean;
139
+ /**
140
+ * Sanitizes an inline SVG string so it can be safely rendered with [innerHTML].
141
+ *
142
+ * @param icon Inline SVG string
143
+ * @returns SafeHtml object that can be bound to [innerHTML]
144
+ */
145
+ getSanitizedIcon(icon: string): SafeHtml;
146
+ static ɵfac: i0.ɵɵFactoryDeclaration<SuNotificationComponent, never>;
147
+ static ɵcmp: i0.ɵɵComponentDeclaration<SuNotificationComponent, "su-lib-notifications", never, {}, {}, never, never, true, never>;
148
+ }
149
+
150
+ export { SuNotificationComponent, SuNotificationService };
151
+ export type { SuNotification, SuNotificationOptions, SuNotificationPosition, SuNotificationType };
package/package.json ADDED
@@ -0,0 +1,23 @@
1
+ {
2
+ "name": "@su-labs/notifications",
3
+ "version": "1.0.0",
4
+ "peerDependencies": {
5
+ "@angular/common": "^20.1.0",
6
+ "@angular/core": "^20.1.0"
7
+ },
8
+ "dependencies": {
9
+ "tslib": "^2.3.0"
10
+ },
11
+ "sideEffects": false,
12
+ "module": "fesm2022/su-labs-notifications.mjs",
13
+ "typings": "index.d.ts",
14
+ "exports": {
15
+ "./package.json": {
16
+ "default": "./package.json"
17
+ },
18
+ ".": {
19
+ "types": "./index.d.ts",
20
+ "default": "./fesm2022/su-labs-notifications.mjs"
21
+ }
22
+ }
23
+ }