@su-labs/notifications 21.0.4 → 22.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/README.md +183 -3
- package/fesm2022/su-labs-notifications.mjs +120 -148
- package/fesm2022/su-labs-notifications.mjs.map +1 -1
- package/package.json +7 -6
- package/types/su-labs-notifications.d.ts +118 -125
package/README.md
CHANGED
|
@@ -1,7 +1,47 @@
|
|
|
1
1
|
# Notifications
|
|
2
2
|
|
|
3
|
+
`@su-labs/notifications`
|
|
4
|
+
|
|
5
|
+

|
|
6
|
+

|
|
7
|
+

|
|
8
|
+

|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+

|
|
13
|
+
|
|
3
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.
|
|
4
15
|
|
|
16
|
+
## Table of Contents
|
|
17
|
+
|
|
18
|
+
- [Why Use This Library?](#-why-use-this-library)
|
|
19
|
+
- [Features](#features)
|
|
20
|
+
- [Installation](#installation)
|
|
21
|
+
- [Quick Start](#-quick-start)
|
|
22
|
+
- [Usage](#usage)
|
|
23
|
+
- [API Reference](#-api-reference)
|
|
24
|
+
- [Configuration Options](#configuration-options)
|
|
25
|
+
- [How It Works](#how-it-works)
|
|
26
|
+
- [Browser Compatibility](#-browser-compatibility)
|
|
27
|
+
- [Related Libraries](#-related-libraries)
|
|
28
|
+
- [Troubleshooting](#-troubleshooting)
|
|
29
|
+
- [Support](#-support)
|
|
30
|
+
- [Contributing](#contributing)
|
|
31
|
+
- [License](#license)
|
|
32
|
+
|
|
33
|
+
## Why Use This Library?
|
|
34
|
+
|
|
35
|
+
- **Lightweight** - Minimal bundle size
|
|
36
|
+
- **Reactive** - Built with Angular Signals
|
|
37
|
+
- **Customizable** - Multiple themes and positions
|
|
38
|
+
- **Icon Support** - Default SVG or custom icons
|
|
39
|
+
- **Auto-dismiss** - Configurable duration
|
|
40
|
+
- **Type-Safe** - Full TypeScript support
|
|
41
|
+
- **Zero Dependencies** - No bloat
|
|
42
|
+
- **Well Tested** - Comprehensive test coverage
|
|
43
|
+
- **Well Documented** - Clear examples and API docs
|
|
44
|
+
|
|
5
45
|
## Features
|
|
6
46
|
|
|
7
47
|
- **Reactive Core:** Built on Angular Signals for optimal performance and reactive updates.
|
|
@@ -26,7 +66,37 @@ npm install @su-labs/notifications
|
|
|
26
66
|
This library requires the following peer dependencies:
|
|
27
67
|
|
|
28
68
|
```sh
|
|
29
|
-
npm install @angular/common
|
|
69
|
+
npm install @angular/common@^22 @angular/core@^22
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
## Quick Start
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
// 1. Install
|
|
76
|
+
npm install @su-labs/notifications
|
|
77
|
+
|
|
78
|
+
// 2. Add component to your app template
|
|
79
|
+
// app.component.html
|
|
80
|
+
<su-notifications></su-notifications>
|
|
81
|
+
<router-outlet></router-outlet>
|
|
82
|
+
|
|
83
|
+
// 3. Show notifications from any component
|
|
84
|
+
import { Component, inject } from '@angular/core';
|
|
85
|
+
import { SuNotificationService } from '@su-labs/notifications';
|
|
86
|
+
|
|
87
|
+
@Component({
|
|
88
|
+
template: `<button (click)="showSuccess()">Show Success</button>`
|
|
89
|
+
})
|
|
90
|
+
export class AppComponent {
|
|
91
|
+
notificationService = inject(SuNotificationService);
|
|
92
|
+
|
|
93
|
+
showSuccess() {
|
|
94
|
+
this.notificationService.show({
|
|
95
|
+
type: 'success',
|
|
96
|
+
message: 'Operation completed!'
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
}
|
|
30
100
|
```
|
|
31
101
|
|
|
32
102
|
## Usage
|
|
@@ -84,7 +154,7 @@ export class MyExampleComponent {
|
|
|
84
154
|
this.notificationService.show({
|
|
85
155
|
type: 'info',
|
|
86
156
|
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"
|
|
157
|
+
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"><polygon points="13 2 3 14 12 14 11 22 21 10 12 10 13 2"></polygon></svg>`
|
|
88
158
|
});
|
|
89
159
|
}
|
|
90
160
|
}
|
|
@@ -94,7 +164,6 @@ export class MyExampleComponent {
|
|
|
94
164
|
|
|
95
165
|
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
166
|
|
|
97
|
-
|
|
98
167
|
```ts
|
|
99
168
|
// src/app/app.config.ts
|
|
100
169
|
import { ApplicationConfig, inject, provideAppInitializer } from '@angular/core';
|
|
@@ -111,6 +180,69 @@ export const appConfig: ApplicationConfig = {
|
|
|
111
180
|
};
|
|
112
181
|
```
|
|
113
182
|
|
|
183
|
+
## API Reference
|
|
184
|
+
|
|
185
|
+
### Service (SuNotificationService)
|
|
186
|
+
|
|
187
|
+
#### Properties
|
|
188
|
+
|
|
189
|
+
| Property | Type | Description |
|
|
190
|
+
|----------|------|-------------|
|
|
191
|
+
| `position` | `NotificationPosition` |
|
|
192
|
+
|
|
193
|
+
#### Methods
|
|
194
|
+
|
|
195
|
+
| Method | Parameters | Description |
|
|
196
|
+
|--------|------------|-------------|
|
|
197
|
+
| `show(config)` | `NotificationConfig` | Display a new notification |
|
|
198
|
+
| `dismiss(id)` | `string` | Manually dismiss a notification |
|
|
199
|
+
|
|
200
|
+
### Types
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
type NotificationType = 'info' | 'success' | 'warning' | 'error' | 'custom';
|
|
204
|
+
|
|
205
|
+
type NotificationPosition =
|
|
206
|
+
| 'top-right'
|
|
207
|
+
| 'top-left'
|
|
208
|
+
| 'bottom-right'
|
|
209
|
+
| 'bottom-left'
|
|
210
|
+
| 'top-center'
|
|
211
|
+
| 'bottom-center';
|
|
212
|
+
|
|
213
|
+
interface NotificationConfig {
|
|
214
|
+
type: NotificationType;
|
|
215
|
+
message: string;
|
|
216
|
+
duration?: number; // Default: 3000ms
|
|
217
|
+
autoClose?: boolean; // Default: true
|
|
218
|
+
cssClass?: string; // Custom CSS class
|
|
219
|
+
icon?: string; // Custom SVG string or image URL
|
|
220
|
+
}
|
|
221
|
+
```
|
|
222
|
+
|
|
223
|
+
## Configuration Options
|
|
224
|
+
|
|
225
|
+
### Notification Types
|
|
226
|
+
|
|
227
|
+
| Type | Description |
|
|
228
|
+
|------|-------------|
|
|
229
|
+
| `info` | Informational message |
|
|
230
|
+
| `success` | Success message |
|
|
231
|
+
| `warning` | Warning message |
|
|
232
|
+
| `error` | Error message |
|
|
233
|
+
| `custom` | Custom styled message |
|
|
234
|
+
|
|
235
|
+
### Positions
|
|
236
|
+
|
|
237
|
+
| Position | Description |
|
|
238
|
+
|----------|-------------|
|
|
239
|
+
| `top-right` | Top right corner (default) |
|
|
240
|
+
| `top-left` | Top left corner |
|
|
241
|
+
| `top-center` | Top center |
|
|
242
|
+
| `bottom-right` | Bottom right corner |
|
|
243
|
+
| `bottom-left` | Bottom left corner |
|
|
244
|
+
| `bottom-center` | Bottom center |
|
|
245
|
+
|
|
114
246
|
## How It Works
|
|
115
247
|
|
|
116
248
|
The library consists of a stateless service (`SuNotificationService`) and a presentational component (`SuNotificationComponent`).
|
|
@@ -119,6 +251,54 @@ The service manages a list of notifications using a private Signal. When you cal
|
|
|
119
251
|
|
|
120
252
|
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
253
|
|
|
254
|
+
## Browser Compatibility
|
|
255
|
+
|
|
256
|
+
Works in all modern browsers that support:
|
|
257
|
+
- CSS Flexbox
|
|
258
|
+
- CSS Animations
|
|
259
|
+
- Angular 22+
|
|
260
|
+
- ES2022+
|
|
261
|
+
|
|
262
|
+
| Browser | Version |
|
|
263
|
+
|---------|---------|
|
|
264
|
+
| Chrome | ≥ 90 |
|
|
265
|
+
| Firefox | ≥ 88 |
|
|
266
|
+
| Safari | ≥ 14 |
|
|
267
|
+
| Edge | ≥ 90 |
|
|
268
|
+
|
|
269
|
+
## Related Libraries
|
|
270
|
+
|
|
271
|
+
Part of the **@su-labs** suite:
|
|
272
|
+
|
|
273
|
+
- [@su-labs/visit-tracker](https://www.npmjs.com/package/@su-labs/visit-tracker) - User visit tracking
|
|
274
|
+
- [@su-labs/theme](https://www.npmjs.com/package/@su-labs/theme) - Theme management with dark mode support
|
|
275
|
+
- [@su-labs/scroll-spy](https://www.npmjs.com/package/@su-labs/scroll-spy) - Scroll position tracking
|
|
276
|
+
- [@su-labs/font-size](https://www.npmjs.com/package/@su-labs/font-size) - Accessible font size controls
|
|
277
|
+
|
|
278
|
+
## Troubleshooting
|
|
279
|
+
|
|
280
|
+
### Notifications not showing?
|
|
281
|
+
|
|
282
|
+
Make sure you've added `<su-notifications></su-notifications>` to your root component template.
|
|
283
|
+
|
|
284
|
+
### Icons not displaying?
|
|
285
|
+
|
|
286
|
+
If using custom icons, ensure the SVG string is valid. For security, Angular sanitizes HTML by default.
|
|
287
|
+
|
|
288
|
+
### Position not changing?
|
|
289
|
+
|
|
290
|
+
Set the position property during app initialization using `provideAppInitializer`.
|
|
291
|
+
|
|
292
|
+
### TypeScript errors?
|
|
293
|
+
|
|
294
|
+
Ensure you have Angular 22+ and TypeScript 6.0+ installed.
|
|
295
|
+
|
|
296
|
+
## Support
|
|
297
|
+
|
|
298
|
+
- Found a bug? [Open an issue](https://github.com/Greezaaa/settings-utils-lib/issues)
|
|
299
|
+
- Have a feature request? [Start a discussion](https://github.com/Greezaaa/settings-utils-lib/discussions)
|
|
300
|
+
- Like this library? [Give it a star!](https://github.com/Greezaaa/settings-utils-lib)
|
|
301
|
+
|
|
122
302
|
## Contributing
|
|
123
303
|
|
|
124
304
|
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).
|
|
@@ -1,149 +1,121 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import {
|
|
3
|
-
import * as i1 from
|
|
4
|
-
import { CommonModule } from
|
|
5
|
-
import { DomSanitizer } from
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
icon.endsWith('.svg') ||
|
|
120
|
-
icon.startsWith('http') ||
|
|
121
|
-
icon.startsWith('/')));
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Sanitizes an inline SVG string so it can be safely rendered with [innerHTML].
|
|
125
|
-
*
|
|
126
|
-
* @param icon Inline SVG string
|
|
127
|
-
* @returns SafeHtml object that can be bound to [innerHTML]
|
|
128
|
-
*/
|
|
129
|
-
getSanitizedIcon(icon) {
|
|
130
|
-
return this.sanitizer.bypassSecurityTrustHtml(icon);
|
|
131
|
-
}
|
|
132
|
-
static ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: SuNotificationComponent, deps: [], target: i0.ɵɵFactoryTarget.Component });
|
|
133
|
-
static ɵcmp = i0.ɵɵngDeclareComponent({ minVersion: "17.0.0", version: "21.1.2", 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"] }] });
|
|
134
|
-
}
|
|
135
|
-
i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "21.1.2", ngImport: i0, type: SuNotificationComponent, decorators: [{
|
|
136
|
-
type: Component,
|
|
137
|
-
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"] }]
|
|
138
|
-
}] });
|
|
139
|
-
|
|
140
|
-
/*
|
|
141
|
-
* Public API Surface of notifications
|
|
142
|
-
*/
|
|
143
|
-
|
|
144
|
-
/**
|
|
145
|
-
* Generated bundle index. Do not edit.
|
|
146
|
-
*/
|
|
147
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { ChangeDetectionStrategy, Component, Injectable, inject, signal } from "@angular/core";
|
|
3
|
+
import * as i1 from "@angular/common";
|
|
4
|
+
import { CommonModule } from "@angular/common";
|
|
5
|
+
import { DomSanitizer } from "@angular/platform-browser";
|
|
6
|
+
var SuNotificationService = class SuNotificationService {
|
|
7
|
+
_notifications = signal([], ...ngDevMode ? [{ debugName: "_notifications" }] : /* istanbul ignore next */ []);
|
|
8
|
+
notifications = this._notifications.asReadonly();
|
|
9
|
+
position = "top-right";
|
|
10
|
+
configure(cfg) {
|
|
11
|
+
if (cfg.position) this.position = cfg.position;
|
|
12
|
+
}
|
|
13
|
+
show(options) {
|
|
14
|
+
const id = crypto.randomUUID();
|
|
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;
|
|
27
|
+
}
|
|
28
|
+
dismiss(id) {
|
|
29
|
+
this._notifications.update((list) => list.filter((n) => n.id !== id));
|
|
30
|
+
}
|
|
31
|
+
clearAll() {
|
|
32
|
+
this._notifications.set([]);
|
|
33
|
+
}
|
|
34
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
35
|
+
minVersion: "12.0.0",
|
|
36
|
+
version: "22.2.4",
|
|
37
|
+
ngImport: i0,
|
|
38
|
+
type: SuNotificationService,
|
|
39
|
+
deps: [],
|
|
40
|
+
target: i0.ɵɵFactoryTarget.Injectable
|
|
41
|
+
});
|
|
42
|
+
static ɵprov = i0.ɵɵngDeclareInjectable({
|
|
43
|
+
minVersion: "12.0.0",
|
|
44
|
+
version: "22.2.4",
|
|
45
|
+
ngImport: i0,
|
|
46
|
+
type: SuNotificationService,
|
|
47
|
+
providedIn: "root"
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
51
|
+
minVersion: "12.0.0",
|
|
52
|
+
version: "22.2.4",
|
|
53
|
+
ngImport: i0,
|
|
54
|
+
type: SuNotificationService,
|
|
55
|
+
decorators: [{
|
|
56
|
+
type: Injectable,
|
|
57
|
+
args: [{ providedIn: "root" }]
|
|
58
|
+
}]
|
|
59
|
+
});
|
|
60
|
+
var SuNotificationComponent = class SuNotificationComponent {
|
|
61
|
+
service = inject(SuNotificationService);
|
|
62
|
+
notifications = this.service.notifications;
|
|
63
|
+
sanitizer = inject(DomSanitizer);
|
|
64
|
+
dismiss(id) {
|
|
65
|
+
this.service.dismiss(id);
|
|
66
|
+
}
|
|
67
|
+
isImage(icon) {
|
|
68
|
+
return typeof icon === "string" && (icon.endsWith(".png") || icon.endsWith(".jpg") || icon.endsWith(".svg") || icon.startsWith("http") || icon.startsWith("/"));
|
|
69
|
+
}
|
|
70
|
+
getSanitizedIcon(icon) {
|
|
71
|
+
return this.sanitizer.bypassSecurityTrustHtml(icon);
|
|
72
|
+
}
|
|
73
|
+
static ɵfac = i0.ɵɵngDeclareFactory({
|
|
74
|
+
minVersion: "12.0.0",
|
|
75
|
+
version: "22.2.4",
|
|
76
|
+
ngImport: i0,
|
|
77
|
+
type: SuNotificationComponent,
|
|
78
|
+
deps: [],
|
|
79
|
+
target: i0.ɵɵFactoryTarget.Component
|
|
80
|
+
});
|
|
81
|
+
static ɵcmp = i0.ɵɵngDeclareComponent({
|
|
82
|
+
minVersion: "17.0.0",
|
|
83
|
+
version: "22.2.4",
|
|
84
|
+
type: SuNotificationComponent,
|
|
85
|
+
isStandalone: true,
|
|
86
|
+
selector: "su-lib-notifications",
|
|
87
|
+
ngImport: i0,
|
|
88
|
+
template: "<div class=\"notification-container\" [ngClass]=\"[service.position]\">\n @for (notification of notifications(); track notification.id) {\n <div class=\"notification\" [ngClass]=\"[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
|
+
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
|
+
changeDetection: i0.ChangeDetectionStrategy.Eager
|
|
100
|
+
});
|
|
101
|
+
};
|
|
102
|
+
i0.ɵɵngDeclareClassMetadata({
|
|
103
|
+
minVersion: "12.0.0",
|
|
104
|
+
version: "22.2.4",
|
|
105
|
+
ngImport: i0,
|
|
106
|
+
type: SuNotificationComponent,
|
|
107
|
+
decorators: [{
|
|
108
|
+
type: Component,
|
|
109
|
+
args: [{
|
|
110
|
+
selector: "su-lib-notifications",
|
|
111
|
+
standalone: true,
|
|
112
|
+
imports: [CommonModule],
|
|
113
|
+
changeDetection: ChangeDetectionStrategy.Eager,
|
|
114
|
+
template: "<div class=\"notification-container\" [ngClass]=\"[service.position]\">\n @for (notification of notifications(); track notification.id) {\n <div class=\"notification\" [ngClass]=\"[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
|
+
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
|
+
}]
|
|
117
|
+
}]
|
|
118
|
+
});
|
|
148
119
|
export { SuNotificationComponent, SuNotificationService };
|
|
149
|
-
|
|
120
|
+
|
|
121
|
+
//# sourceMappingURL=su-labs-notifications.mjs.map
|
|
@@ -1 +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/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","/*\n * Public API Surface of notifications\n */\n\nexport * from './lib/notification.component';\nexport * from './lib/notification.service';\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;IAChD;AAEA;;;;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,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,CAAC,GAAG,IAAI,EAAE,YAAY,CAAC,CAAC;AAE7D,QAAA,IAAI,YAAY,CAAC,SAAS,EAAE;AAC1B,YAAA,UAAU,CAAC,MAAM,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC,EAAE,YAAY,CAAC,QAAQ,CAAC;QAC3D;AAEA,QAAA,OAAO,EAAE;IACX;AAEA;;;AAGG;AACH,IAAA,OAAO,CAAC,EAAU,EAAA;QAChB,IAAI,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC;IACvE;AAEA;;AAEG;IACH,QAAQ,GAAA;AACN,QAAA,IAAI,CAAC,cAAc,CAAC,GAAG,CAAC,EAAE,CAAC;IAC7B;uGAnEW,qBAAqB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,UAAA,EAAA,CAAA;AAArB,IAAA,OAAA,KAAA,GAAA,EAAA,CAAA,qBAAA,CAAA,EAAA,UAAA,EAAA,QAAA,EAAA,OAAA,EAAA,QAAA,EAAA,QAAA,EAAA,EAAA,EAAA,IAAA,EAAA,qBAAqB,cADR,MAAM,EAAA,CAAA;;2FACnB,qBAAqB,EAAA,UAAA,EAAA,CAAA;kBADjC,UAAU;mBAAC,EAAE,UAAU,EAAE,MAAM,EAAE;;;ACRlC;;;;AAIG;MAQU,uBAAuB,CAAA;;AAElC,IAAA,OAAO,GAAG,MAAM,CAAC,qBAAqB,CAAC;;AAGvC,IAAA,aAAa,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa;;AAGlC,IAAA,SAAS,GAAG,MAAM,CAAC,YAAY,CAAC;AAExC;;;;AAIG;AACH,IAAA,OAAO,CAAC,EAAU,EAAA;AAChB,QAAA,IAAI,CAAC,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC;IAC1B;AAEA;;;;;;;;;;;;;AAaG;AACH,IAAA,OAAO,CAAC,IAAsB,EAAA;AAC5B,QAAA,QACE,OAAO,IAAI,KAAK,QAAQ;AACxB,aAAC,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AACpB,gBAAA,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AACrB,gBAAA,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC;AACrB,gBAAA,IAAI,CAAC,UAAU,CAAC,MAAM,CAAC;AACvB,gBAAA,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC;IAE3B;AAEA;;;;;AAKG;AACH,IAAA,gBAAgB,CAAC,IAAY,EAAA;QAC3B,OAAO,IAAI,CAAC,SAAS,CAAC,uBAAuB,CAAC,IAAI,CAAC;IACrD;uGApDW,uBAAuB,EAAA,IAAA,EAAA,EAAA,EAAA,MAAA,EAAA,EAAA,CAAA,eAAA,CAAA,SAAA,EAAA,CAAA;2FAAvB,uBAAuB,EAAA,YAAA,EAAA,IAAA,EAAA,QAAA,EAAA,sBAAA,EAAA,QAAA,EAAA,EAAA,EAAA,QAAA,ECjBpC,ilFAyDA,EAAA,MAAA,EAAA,CAAA,ohHAAA,CAAA,EAAA,YAAA,EAAA,CAAA,EAAA,IAAA,EAAA,UAAA,EAAA,IAAA,ED5CY,YAAY,EAAA,EAAA,EAAA,IAAA,EAAA,WAAA,EAAA,IAAA,EAAA,EAAA,CAAA,OAAA,EAAA,QAAA,EAAA,WAAA,EAAA,MAAA,EAAA,CAAA,OAAA,EAAA,SAAA,CAAA,EAAA,CAAA,EAAA,CAAA;;2FAIX,uBAAuB,EAAA,UAAA,EAAA,CAAA;kBAPnC,SAAS;AACE,YAAA,IAAA,EAAA,CAAA,EAAA,QAAA,EAAA,sBAAsB,EAAA,UAAA,EACpB,IAAI,EAAA,OAAA,EACP,CAAC,YAAY,CAAC,EAAA,QAAA,EAAA,ilFAAA,EAAA,MAAA,EAAA,CAAA,ohHAAA,CAAA,EAAA;;;AEbzB;;AAEG;;ACFH;;AAEG;;;;"}
|
|
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 './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, ChangeDetectionStrategy } 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 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 *\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"],"mappings":";;;;;AAcA,IAAa,wBAAb,MAAa,sBAAqB;CAIxB,iBAAiB,OAAyB,CAAA,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,iBAAA,CAAA,+BAAA,CAAA,CAAA;CAMrD,gBAAgB,KAAK,eAAe,WAAU;CAO9C,WAAmC;CAOnC,UAAU,KAA0C;EAClD,IAAI,IAAI,UAAU,KAAK,WAAW,IAAI;CACxC;CAOA,KAAK,SAA8B;EACjC,MAAM,KAAK,OAAO,WAAU;EAC5B,MAAM,eAA+B;GACnC;GACA,MAAM,QAAQ;GACd,SAAS,QAAQ;GACjB,UAAU,QAAQ,YAAY;GAC9B,WAAW,QAAQ,aAAa;GAChC,UAAU,QAAQ;GAClB,MAAM,QAAQ,QAAQ;EACvB;EAED,KAAK,eAAe,QAAQ,SAAS,CAAC,GAAG,MAAM,YAAY,CAAC;EAE5D,IAAI,aAAa,WACf,iBAAiB,KAAK,QAAQ,EAAE,GAAG,aAAa,QAAQ;EAG1D,OAAO;CACT;CAMA,QAAQ,IAAU;EAChB,KAAK,eAAe,QAAQ,SAAS,KAAK,QAAQ,MAAM,EAAE,OAAO,EAAE,CAAC;CACtE;CAKA,WAAQ;EACN,KAAK,eAAe,IAAI,CAAA,CAAE;CAC5B;CAnEW,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;;;ACKlC,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;CAgBA,QAAQ,MAAsB;EAC5B,OACE,OAAO,SAAS,aACf,KAAK,SAAS,MAAM,KACnB,KAAK,SAAS,MAAM,KACpB,KAAK,SAAS,MAAM,KACpB,KAAK,WAAW,MAAM,KACtB,KAAK,WAAW,GAAG;CAEzB;CAQA,iBAAiB,MAAY;EAC3B,OAAO,KAAK,UAAU,wBAAwB,IAAI;CACpD;CApDW,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,UClBpC;EAyDA,QAAA,CAAA,ohHAAA;EAAA,cAAA,CAAA;GAAA,MAAA;GAAA,MD5CY;EAAY,GAAA;GAAA,MAAA;GAAA,MAAA,GAAA;GAAA,UAAA;GAAA,QAAA,CAAA,SAAA,SAAA;EAAA,CAAA;EAAA,iBAAA,GAAA,wBAAA;CAAA,CAAA;;AAKX,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAuB,YAAA,CAAA;EARnC,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAsB,YACpB;GAAI,SACP,CAAC,YAAY;GAAC,iBAEN,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": "
|
|
3
|
+
"version": "22.0.0",
|
|
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.com/Greezaaa/settings-utils-lib/tree/main/projects/su-labs/
|
|
20
|
+
"homepage": "https://github.com/Greezaaa/settings-utils-lib/tree/main/projects/su-labs/notifications#readme",
|
|
21
21
|
"author": {
|
|
22
22
|
"name": "Yevheniy Alekseyev",
|
|
23
23
|
"email": "yev.alekseyev@gmail.com",
|
|
@@ -26,14 +26,14 @@
|
|
|
26
26
|
"repository": {
|
|
27
27
|
"type": "git",
|
|
28
28
|
"url": "https://github.com/Greezaaa/settings-utils-lib.git",
|
|
29
|
-
"directory": "projects/su-labs/
|
|
29
|
+
"directory": "projects/su-labs/notifications"
|
|
30
30
|
},
|
|
31
31
|
"bugs": {
|
|
32
32
|
"url": "https://github.com/Greezaaa/settings-utils-lib/issues"
|
|
33
33
|
},
|
|
34
34
|
"peerDependencies": {
|
|
35
|
-
"@angular/common": "^
|
|
36
|
-
"@angular/core": "^
|
|
35
|
+
"@angular/common": "^22.0.0",
|
|
36
|
+
"@angular/core": "^22.0.0"
|
|
37
37
|
},
|
|
38
38
|
"dependencies": {
|
|
39
39
|
"tslib": "^2.3.0"
|
|
@@ -50,5 +50,6 @@
|
|
|
50
50
|
"types": "./types/su-labs-notifications.d.ts",
|
|
51
51
|
"default": "./fesm2022/su-labs-notifications.mjs"
|
|
52
52
|
}
|
|
53
|
-
}
|
|
53
|
+
},
|
|
54
|
+
"type": "module"
|
|
54
55
|
}
|
|
@@ -1,151 +1,144 @@
|
|
|
1
|
-
import * as i0 from
|
|
2
|
-
import
|
|
3
|
-
import { SafeHtml } from '@angular/platform-browser';
|
|
4
|
-
|
|
1
|
+
import * as i0 from "@angular/core";
|
|
2
|
+
import { SafeHtml } from "@angular/platform-browser";
|
|
5
3
|
/**
|
|
6
4
|
* Represents the type of a notification.
|
|
7
5
|
*/
|
|
8
|
-
type SuNotificationType = 'info' | 'success' | 'warning' | 'error' | 'custom';
|
|
6
|
+
export type SuNotificationType = 'info' | 'success' | 'warning' | 'error' | 'custom';
|
|
9
7
|
/**
|
|
10
8
|
* Options for configuring a notification.
|
|
11
9
|
*/
|
|
12
|
-
interface SuNotificationOptions {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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;
|
|
42
40
|
}
|
|
43
41
|
/**
|
|
44
42
|
* A notification instance with a unique identifier.
|
|
45
43
|
*/
|
|
46
|
-
interface SuNotification extends SuNotificationOptions {
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
44
|
+
export interface SuNotification extends SuNotificationOptions {
|
|
45
|
+
/**
|
|
46
|
+
* Unique identifier for the notification instance.
|
|
47
|
+
*/
|
|
48
|
+
id: string;
|
|
51
49
|
}
|
|
52
50
|
/**
|
|
53
51
|
* Possible positions for displaying notifications on the screen.
|
|
54
52
|
*/
|
|
55
|
-
type SuNotificationPosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
|
|
56
|
-
|
|
53
|
+
export type SuNotificationPosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center';
|
|
57
54
|
/**
|
|
58
55
|
* Service for managing notifications.
|
|
59
56
|
*
|
|
60
57
|
* Provides methods to show, dismiss, and clear notifications.
|
|
61
58
|
* Notifications are reactive signals, making them easy to bind in templates.
|
|
62
59
|
*/
|
|
63
|
-
declare class SuNotificationService {
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
60
|
+
export declare class SuNotificationService {
|
|
61
|
+
/**
|
|
62
|
+
* Internal signal holding the list of notifications.
|
|
63
|
+
*/
|
|
64
|
+
private _notifications;
|
|
65
|
+
/**
|
|
66
|
+
* Read-only access to the notifications list.
|
|
67
|
+
* Can be used in templates for reactive updates.
|
|
68
|
+
*/
|
|
69
|
+
notifications: import("@angular/core").Signal<SuNotification[]>;
|
|
70
|
+
/**
|
|
71
|
+
* Default position where notifications will appear on the screen.
|
|
72
|
+
* Can be configured via `configure` method.
|
|
73
|
+
* @default 'top-right'
|
|
74
|
+
*/
|
|
75
|
+
position: SuNotificationPosition;
|
|
76
|
+
/**
|
|
77
|
+
* Configure the notification service.
|
|
78
|
+
* @param cfg Configuration object
|
|
79
|
+
* @param cfg.position Optional position to display notifications.
|
|
80
|
+
*/
|
|
81
|
+
configure(cfg: {
|
|
82
|
+
position?: SuNotificationPosition;
|
|
83
|
+
}): void;
|
|
84
|
+
/**
|
|
85
|
+
* Show a new notification.
|
|
86
|
+
* @param options Options to configure the notification.
|
|
87
|
+
* @returns The unique ID of the notification.
|
|
88
|
+
*/
|
|
89
|
+
show(options: SuNotificationOptions): string;
|
|
90
|
+
/**
|
|
91
|
+
* Dismiss a specific notification by its ID.
|
|
92
|
+
* @param id ID of the notification to remove.
|
|
93
|
+
*/
|
|
94
|
+
dismiss(id: string): void;
|
|
95
|
+
/**
|
|
96
|
+
* Clear all notifications immediately.
|
|
97
|
+
*/
|
|
98
|
+
clearAll(): void;
|
|
99
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SuNotificationService, never>;
|
|
100
|
+
static ɵprov: i0.ɵɵInjectableDeclaration<any>;
|
|
104
101
|
}
|
|
105
|
-
|
|
106
102
|
/**
|
|
107
103
|
* Component to display notifications on the screen.
|
|
108
104
|
*
|
|
109
105
|
* Uses `SuNotificationService` to manage and render notifications.
|
|
110
106
|
*/
|
|
111
|
-
declare class SuNotificationComponent {
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
}
|
|
149
|
-
|
|
150
|
-
export { SuNotificationComponent, SuNotificationService };
|
|
151
|
-
export type { SuNotification, SuNotificationOptions, SuNotificationPosition, SuNotificationType };
|
|
107
|
+
export declare class SuNotificationComponent {
|
|
108
|
+
/** Injected notification service */
|
|
109
|
+
service: SuNotificationService;
|
|
110
|
+
/** Read-only signal of the current notifications */
|
|
111
|
+
notifications: import("@angular/core").Signal<import("@su-labs/notifications").SuNotification[]>;
|
|
112
|
+
/** Angular sanitizer to safely render inline SVG strings */
|
|
113
|
+
private sanitizer;
|
|
114
|
+
/**
|
|
115
|
+
* Dismiss a notification by its ID.
|
|
116
|
+
* Delegates to the service.
|
|
117
|
+
* @param id ID of the notification to dismiss
|
|
118
|
+
*/
|
|
119
|
+
dismiss(id: string): void;
|
|
120
|
+
/**
|
|
121
|
+
* Checks if the provided `icon` value should be rendered as an image (`<img>`).
|
|
122
|
+
*
|
|
123
|
+
* Determines whether the `icon` is a string pointing to an image file:
|
|
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]`.
|
|
130
|
+
*
|
|
131
|
+
* @param icon The icon value from the notification (boolean or string)
|
|
132
|
+
* @returns `true` if the icon is an image path or URL, `false` for inline SVGs or `false`
|
|
133
|
+
*/
|
|
134
|
+
isImage(icon: string | boolean): boolean;
|
|
135
|
+
/**
|
|
136
|
+
* Sanitizes an inline SVG string so it can be safely rendered with [innerHTML].
|
|
137
|
+
*
|
|
138
|
+
* @param icon Inline SVG string
|
|
139
|
+
* @returns SafeHtml object that can be bound to [innerHTML]
|
|
140
|
+
*/
|
|
141
|
+
getSanitizedIcon(icon: string): SafeHtml;
|
|
142
|
+
static ɵfac: i0.ɵɵFactoryDeclaration<SuNotificationComponent, never>;
|
|
143
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<SuNotificationComponent, "su-lib-notifications", never, {}, {}, never, never, true, never>;
|
|
144
|
+
}
|