@su-labs/notifications 22.1.1 → 22.3.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/CHANGELOG.md CHANGED
@@ -5,6 +5,29 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [Unreleased]
9
+
10
+ ## [22.3.0] - 2026-11-07
11
+
12
+ ### Added
13
+ - Links inside the message: pass `message` as a list of text and links (`{ label, onClick, dismiss }`), each link closing the notification unless `dismiss: false`
14
+
15
+ ### Changed
16
+ - Depends on exactly `@su-labs/core` 1.3.0
17
+
18
+ ## [22.2.0] - 2026-11-07
19
+
20
+ ### Added
21
+ - Notifications slide in from their side of the screen and slide out when closed; durations set with `--su-notification-enter-duration` (400ms) and `--su-notification-leave-duration` (300ms), and no motion for visitors who prefer reduced motion
22
+ - `slideFrom` option (`'auto'`, `'left'`, `'right'`, `'top'`, `'bottom'`) to slide in from a chosen direction whatever the position, as `configure({ slideFrom })` or the `slideFrom` property
23
+ - `actions` option: buttons under the message (`label`, `onClick`, `dismiss`), each closing the notification unless `dismiss: false`
24
+
25
+ ### Changed
26
+ - Depends on exactly `@su-labs/core` 1.2.0 (no version range), so every install runs the core it was tested with
27
+
28
+ ### Documentation
29
+ - README lists every CSS variable, including `--su-notification-max-width` for wider notifications
30
+
8
31
  ## [22.1.1] - 2026-11-05
9
32
 
10
33
  ### Changed
package/README.md CHANGED
@@ -24,6 +24,7 @@ A highly customizable Angular notification library built with modern practices,
24
24
  - [Usage](#usage)
25
25
  - [API Reference](#api-reference)
26
26
  - [Configuration Options](#configuration-options)
27
+ - [Styling](#styling)
27
28
  - [How It Works](#how-it-works)
28
29
  - [Browser Compatibility](#browser-compatibility)
29
30
  - [Related Libraries](#related-libraries)
@@ -182,6 +183,12 @@ export const appConfig: ApplicationConfig = {
182
183
  };
183
184
  ```
184
185
 
186
+ Notifications slide in from the side they sit on (from the left here). To slide them in from another direction, whatever the position, set `slideFrom` to `'left'`, `'right'`, `'top'` or `'bottom'` (`'auto'` is the default):
187
+
188
+ ```ts
189
+ notificationService.configure({ position: 'top-right', slideFrom: 'top' });
190
+ ```
191
+
185
192
  ## API Reference
186
193
 
187
194
  ### Service (SuNotificationService)
@@ -214,14 +221,50 @@ type NotificationPosition =
214
221
 
215
222
  interface NotificationConfig {
216
223
  type: NotificationType;
217
- message: string;
224
+ message: string | (string | NotificationAction)[]; // Text, or text and links
218
225
  duration?: number; // Default: 3000ms
219
226
  autoClose?: boolean; // Default: true
220
227
  cssClass?: string; // Custom CSS class
221
228
  icon?: string; // Custom SVG string or image URL
229
+ actions?: NotificationAction[]; // Buttons under the message
230
+ }
231
+
232
+ interface NotificationAction {
233
+ label: string; // Button text
234
+ onClick: () => void; // Called when the button is pressed
235
+ dismiss?: boolean; // Close the notification afterwards (default: true)
222
236
  }
223
237
  ```
224
238
 
239
+ ### Action buttons
240
+
241
+ Give a notification `actions` to show buttons under its message, for example to undo or to open a page. Each button closes the notification after its `onClick` runs, unless it sets `dismiss: false`. Combine with `autoClose: false` to keep the notification until the user answers:
242
+
243
+ ```typescript
244
+ this.notifications.show({
245
+ type: 'info',
246
+ message: 'Photo deleted',
247
+ autoClose: false,
248
+ actions: [
249
+ { label: 'Undo', onClick: () => this.restorePhoto() },
250
+ { label: 'OK', onClick: () => {} },
251
+ ],
252
+ });
253
+ ```
254
+
255
+ ### Links in the message
256
+
257
+ Pass `message` as a list to make part of it a link. Text pieces show as they are; each `{ label, onClick }` piece is a link that runs `onClick`, then closes the notification unless it sets `dismiss: false`:
258
+
259
+ ```typescript
260
+ this.notifications.show({
261
+ type: 'info',
262
+ message: ['New: ', { label: 'Sliding puzzle', onClick: () => this.router.navigateByUrl('/sliding-puzzle') }],
263
+ });
264
+ ```
265
+
266
+ Restyle the links with the `.link` class inside `su-lib-notifications`.
267
+
225
268
  ## Configuration Options
226
269
 
227
270
  ### Notification Types
@@ -245,6 +288,36 @@ interface NotificationConfig {
245
288
  | `bottom-left` | Bottom left corner |
246
289
  | `bottom-center` | Bottom center |
247
290
 
291
+ ## Styling
292
+
293
+ Notifications slide in from the side of the screen they appear on and slide back out when they close (they simply appear and disappear for visitors who prefer reduced motion). Every part of a notification can be restyled with CSS variables, set on `:root` or any parent element. For example, to let long messages use more width:
294
+
295
+ ```css
296
+ :root {
297
+ --su-notification-max-width: min(100% - 2rem, 26rem);
298
+ }
299
+ ```
300
+
301
+ | Variable | Default | Controls |
302
+ |----------|---------|----------|
303
+ | `--su-notification-width` | `max-content` | Width of a notification; by default it fits its text |
304
+ | `--su-notification-max-width` | `min(100% - 2rem, 300px)` | Widest a notification gets before its text wraps |
305
+ | `--su-notification-padding-block` | `1rem` | Space above and below the text |
306
+ | `--su-notification-padding-inline` | `1.25rem` | Space left and right of the text |
307
+ | `--su-notification-container-gap` | `1.2rem` | Space between stacked notifications |
308
+ | `--su-notification-container-position` | `1rem` | Distance from the edges of the screen |
309
+ | `--su-notification-enter-duration` | `400ms` | How long a notification takes to slide in from its side of the screen |
310
+ | `--su-notification-leave-duration` | `300ms` | How long it takes to slide back out when closed |
311
+ | `--su-notification-background-color` | `#fff` | Background |
312
+ | `--su-notification-text-color` | `#333` | Text |
313
+ | `--su-notification-box-shadow` | `rgba(0, 0, 0, 0.15)` | Shadow colour |
314
+ | `--su-notification-info-border-color` | `#2196f3` | Left border of `info` (likewise `success`, `warning`, `error`, `custom`) |
315
+ | `--su-notification-icon-color` | `currentColor` | Icon colour |
316
+ | `--su-notification-icon-width` / `-height` | `24px` | Icon size |
317
+ | `--su-notification-action-border-color` | `currentColor` | Border of action buttons (they take the notification's text colour) |
318
+ | `--su-notification-close-btn-size` | `20px` | Close button size |
319
+ | `--su-notification-close-btn-background-color` | the background | Close button background (also `-text-color`, `-border-color`, `-border-radius`, `-font-size`, `-hover-background`, `-hover-color`) |
320
+
248
321
  ## How It Works
249
322
 
250
323
  The library consists of a stateless service (`SuNotificationService`) and a presentational component (`SuNotificationComponent`).
@@ -13,6 +13,12 @@ var SuNotificationService = class SuNotificationService {
13
13
  set position(position) {
14
14
  this.controller.configure({ position });
15
15
  }
16
+ get slideFrom() {
17
+ return this.controller.slideFrom.get();
18
+ }
19
+ set slideFrom(slideFrom) {
20
+ this.controller.configure({ slideFrom });
21
+ }
16
22
  configure(cfg) {
17
23
  this.controller.configure(cfg);
18
24
  }
@@ -62,6 +68,10 @@ var SuNotificationComponent = class SuNotificationComponent {
62
68
  dismiss(id) {
63
69
  this.service.dismiss(id);
64
70
  }
71
+ runAction(id, action) {
72
+ action.onClick();
73
+ if (action.dismiss !== false) this.service.dismiss(id);
74
+ }
65
75
  isImage(icon) {
66
76
  return isSuNotificationImageIcon(icon);
67
77
  }
@@ -83,8 +93,8 @@ var SuNotificationComponent = class SuNotificationComponent {
83
93
  isStandalone: true,
84
94
  selector: "su-lib-notifications",
85
95
  ngImport: i0,
86
- template: "<div class=\"notification-container {{ service.position }}\">\n @for (notification of notifications(); track notification.id) {\n <div class=\"notification {{ notification.type }} {{ notification.cssClass ?? '' }}\">\n\n <div class=\"icon-container\">\n @if (notification.icon) {\n @if (isImage(notification.icon!)) {\n <img [src]=\"notification.icon\" alt=\"icon\" />\n } @else if (typeof notification.icon === 'string') {\n <span [innerHTML]=\"getSanitizedIcon(notification.icon)\"></span>\n }\n <!-- if icon === true, render default SVG via switch -->\n @else {\n @switch (notification.type) {\n @case('success') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n }\n @case('info') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"12\" y1=\"16\" x2=\"12\" y2=\"12\" />\n <line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"8\" />\n </svg>\n }\n @case('warning') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z\" />\n <line x1=\"12\" y1=\"9\" x2=\"12\" y2=\"13\" />\n <line x1=\"12\" y1=\"17\" x2=\"12\" y2=\"17\" />\n </svg>\n }\n @case('error') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"15\" y1=\"9\" x2=\"9\" y2=\"15\" />\n <line x1=\"9\" y1=\"9\" x2=\"15\" y2=\"15\" />\n </svg>\n }\n }\n }\n }\n </div>\n\n <span class=\"message\">{{ notification.message }}</span>\n\n <button class=\"close\" (click)=\"dismiss(notification.id)\" type=\"button\">×</button>\n </div>\n }\n</div>\n\n\n",
87
- styles: [".notification-container{position:fixed;pointer-events:none;display:flex;gap:var(--su-notification-container-gap, 1.2rem);width:var(--su-notification-width, max-content);max-width:var(--su-notification-max-width, min(100% - 2rem, 300px));z-index:999999}.notification-container.top-right{align-items:flex-end;flex-direction:column;top:var(--su-notification-container-position, 1rem);right:var(--su-notification-container-position, 1rem)}.notification-container.top-left{align-items:flex-start;flex-direction:column;top:var(--su-notification-container-position, 1rem);left:var(--su-notification-container-position, 1rem)}.notification-container.bottom-right{align-items:flex-end;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);right:var(--su-notification-container-position, 1rem)}.notification-container.bottom-left{align-items:flex-start;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);left:var(--su-notification-container-position, 1rem)}.notification-container.top-center{align-items:center;flex-direction:column;top:var(--su-notification-container-position, 1rem);left:50%;translate:-50% 0}.notification-container.bottom-center{align-items:center;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);left:50%;translate:-50% 0}.notification{position:relative;pointer-events:auto;background-color:var(--su-notification-background-color, #fff);color:var(--su-notification-text-color, #333);padding-block:var(--su-notification-padding-block, 1rem);padding-inline:var(--su-notification-padding-inline, 1.25rem);box-shadow:0 4px 8px var(--su-notification-box-shadow, rgba(0, 0, 0, .15));display:flex;align-items:center;gap:1rem;transition:transform .2s ease,opacity .2s ease}.notification.success{border-left:4px solid var(--su-notification-success-border-color, #4caf50)}.notification.info{border-left:4px solid var(--su-notification-info-border-color, #2196f3)}.notification.warning{border-left:4px solid var(--su-notification-warning-border-color, #ff9800)}.notification.error{border-left:4px solid var(--su-notification-error-border-color, #f44336)}.notification.custom{border-left:4px solid var(--su-notification-custom-border-color, #9c27b0)}.notification .icon-container{display:flex;align-items:center;justify-content:center;width:var(--su-notification-icon-width, 24px);height:var(--su-notification-icon-height, var(--su-notification-icon-width, 24px));color:var(--su-notification-icon-color, currentColor)}.notification .icon-container .icon{width:100%;height:100%}.notification .message{flex:1}.notification .close{position:absolute;width:var(--su-notification-close-btn-size, 20px);height:var(--su-notification-close-btn-size, 20px);top:calc(var(--su-notification-close-btn-size, 20px) * -.5);right:calc(var(--su-notification-close-btn-size, 20px) * -.5);background:var(--su-notification-close-btn-background-color, var(--su-notification-background-color, #fff));color:var(--su-notification-close-btn-text-color, var(--su-notification-text-color, #333));border:1px solid var(--su-notification-close-btn-border-color, rgba(0, 0, 0, 0));border-radius:var(--su-notification-close-btn-border-radius, 50%);box-shadow:0 4px 8px var(--su-notification-box-shadow, rgba(0, 0, 0, .15));font-size:var(--su-notification-close-btn-font-size, 1rem);display:flex;justify-content:center;align-items:center;line-height:1;cursor:pointer}.notification .close:hover{background:var(--su-notification-close-btn-hover-background, rgba(51, 51, 51, .5));color:var(--su-notification-close-btn-hover-color, #fff)}\n"],
96
+ template: "<div class=\"notification-container {{ service.position }}\" [attr.data-slide]=\"service.slideFrom\">\n @for (notification of notifications(); track notification.id) {\n <div\n class=\"notification {{ notification.type }} {{ notification.cssClass ?? '' }}\"\n animate.enter=\"su-notification-enter\"\n animate.leave=\"su-notification-leave\"\n >\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 <div class=\"content\">\n <span class=\"message\">\n @if (typeof notification.message === 'string') {\n {{ notification.message }}\n } @else {\n @for (part of notification.message; track $index) {\n @if (typeof part === 'string') {{{ part }}} @else {<button class=\"link\" type=\"button\" (click)=\"runAction(notification.id, part)\">{{ part.label }}</button>}\n }\n }\n </span>\n\n @if (notification.actions?.length) {\n <div class=\"actions\">\n @for (action of notification.actions; track $index) {\n <button class=\"action\" type=\"button\" (click)=\"runAction(notification.id, action)\">{{ action.label }}</button>\n }\n </div>\n }\n </div>\n\n <button class=\"close\" (click)=\"dismiss(notification.id)\" type=\"button\">×</button>\n </div>\n }\n</div>\n\n\n",
97
+ styles: [".notification-container{--_edge: var(--su-notification-container-position, 1rem);--_left: calc(-100% - 2rem) 0;--_right: calc(100% + 2rem) 0;--_top: 0 calc(-100% - 2rem) ;--_bottom: 0 calc(100% + 2rem) ;position:fixed;pointer-events:none;display:flex;flex-direction:column;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[class*=top-]{top:var(--_edge);--_slide: var(--_top)}.notification-container[class*=bottom-]{bottom:var(--_edge);flex-direction:column-reverse;--_slide: var(--_bottom)}.notification-container[class*=-right]{align-items:flex-end;right:var(--_edge);--_slide: var(--_right)}.notification-container[class*=-left]{align-items:flex-start;left:var(--_edge);--_slide: var(--_left)}.notification-container[class*=-center]{align-items:center;left:50%;translate:-50% 0}.notification-container[data-slide=left]{--_slide: var(--_left)}.notification-container[data-slide=right]{--_slide: var(--_right)}.notification-container[data-slide=top]{--_slide: var(--_top)}.notification-container[data-slide=bottom]{--_slide: var(--_bottom)}.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);--_shadow: 0 4px 8px var(--su-notification-box-shadow, rgba(0, 0, 0, .15));box-shadow:var(--_shadow);border-left:4px solid var(--_border);display:flex;align-items:center;gap:1rem}.notification.success{--_border: var(--su-notification-success-border-color, #4caf50)}.notification.info{--_border: var(--su-notification-info-border-color, #2196f3)}.notification.warning{--_border: var(--su-notification-warning-border-color, #ff9800)}.notification.error{--_border: var(--su-notification-error-border-color, #f44336)}.notification.custom{--_border: var(--su-notification-custom-border-color, #9c27b0)}.notification .close{--_size: var(--su-notification-close-btn-size, 20px);position:absolute;width:var(--_size);height:var(--_size);top:calc(var(--_size) / -2);right:calc(var(--_size) / -2);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:var(--_shadow);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)}.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)}.icon{width:100%;height:100%}.content{display:grid;flex:1;gap:.75rem}.actions{display:flex;flex-wrap:wrap;gap:.5rem}.action,.link{background:none;color:inherit;cursor:pointer;font:inherit}.action{border:1px solid var(--su-notification-action-border-color, currentColor);border-radius:6px;padding:.25rem .75rem}.link{border:0;padding:0;text-decoration:underline}.su-notification-enter{animation:su-notification-slide var(--su-notification-enter-duration, .4s) ease-out}.su-notification-leave{animation:su-notification-slide var(--su-notification-leave-duration, .3s) ease-in reverse forwards}@keyframes su-notification-slide{0%{opacity:0;translate:var(--_slide)}}@media(prefers-reduced-motion:reduce){.su-notification-enter,.su-notification-leave{animation:none}}\n"],
88
98
  changeDetection: i0.ChangeDetectionStrategy.Eager
89
99
  });
90
100
  };
@@ -99,8 +109,8 @@ i0.ɵɵngDeclareClassMetadata({
99
109
  selector: "su-lib-notifications",
100
110
  standalone: true,
101
111
  changeDetection: ChangeDetectionStrategy.Eager,
102
- template: "<div class=\"notification-container {{ service.position }}\">\n @for (notification of notifications(); track notification.id) {\n <div class=\"notification {{ notification.type }} {{ notification.cssClass ?? '' }}\">\n\n <div class=\"icon-container\">\n @if (notification.icon) {\n @if (isImage(notification.icon!)) {\n <img [src]=\"notification.icon\" alt=\"icon\" />\n } @else if (typeof notification.icon === 'string') {\n <span [innerHTML]=\"getSanitizedIcon(notification.icon)\"></span>\n }\n <!-- if icon === true, render default SVG via switch -->\n @else {\n @switch (notification.type) {\n @case('success') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M20 6L9 17l-5-5\" />\n </svg>\n }\n @case('info') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"12\" y1=\"16\" x2=\"12\" y2=\"12\" />\n <line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"8\" />\n </svg>\n }\n @case('warning') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <path d=\"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z\" />\n <line x1=\"12\" y1=\"9\" x2=\"12\" y2=\"13\" />\n <line x1=\"12\" y1=\"17\" x2=\"12\" y2=\"17\" />\n </svg>\n }\n @case('error') {\n <svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n stroke-linecap=\"round\" stroke-linejoin=\"round\">\n <circle cx=\"12\" cy=\"12\" r=\"10\" />\n <line x1=\"15\" y1=\"9\" x2=\"9\" y2=\"15\" />\n <line x1=\"9\" y1=\"9\" x2=\"15\" y2=\"15\" />\n </svg>\n }\n }\n }\n }\n </div>\n\n <span class=\"message\">{{ notification.message }}</span>\n\n <button class=\"close\" (click)=\"dismiss(notification.id)\" type=\"button\">×</button>\n </div>\n }\n</div>\n\n\n",
103
- styles: [".notification-container{position:fixed;pointer-events:none;display:flex;gap:var(--su-notification-container-gap, 1.2rem);width:var(--su-notification-width, max-content);max-width:var(--su-notification-max-width, min(100% - 2rem, 300px));z-index:999999}.notification-container.top-right{align-items:flex-end;flex-direction:column;top:var(--su-notification-container-position, 1rem);right:var(--su-notification-container-position, 1rem)}.notification-container.top-left{align-items:flex-start;flex-direction:column;top:var(--su-notification-container-position, 1rem);left:var(--su-notification-container-position, 1rem)}.notification-container.bottom-right{align-items:flex-end;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);right:var(--su-notification-container-position, 1rem)}.notification-container.bottom-left{align-items:flex-start;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);left:var(--su-notification-container-position, 1rem)}.notification-container.top-center{align-items:center;flex-direction:column;top:var(--su-notification-container-position, 1rem);left:50%;translate:-50% 0}.notification-container.bottom-center{align-items:center;flex-direction:column-reverse;bottom:var(--su-notification-container-position, 1rem);left:50%;translate:-50% 0}.notification{position:relative;pointer-events:auto;background-color:var(--su-notification-background-color, #fff);color:var(--su-notification-text-color, #333);padding-block:var(--su-notification-padding-block, 1rem);padding-inline:var(--su-notification-padding-inline, 1.25rem);box-shadow:0 4px 8px var(--su-notification-box-shadow, rgba(0, 0, 0, .15));display:flex;align-items:center;gap:1rem;transition:transform .2s ease,opacity .2s ease}.notification.success{border-left:4px solid var(--su-notification-success-border-color, #4caf50)}.notification.info{border-left:4px solid var(--su-notification-info-border-color, #2196f3)}.notification.warning{border-left:4px solid var(--su-notification-warning-border-color, #ff9800)}.notification.error{border-left:4px solid var(--su-notification-error-border-color, #f44336)}.notification.custom{border-left:4px solid var(--su-notification-custom-border-color, #9c27b0)}.notification .icon-container{display:flex;align-items:center;justify-content:center;width:var(--su-notification-icon-width, 24px);height:var(--su-notification-icon-height, var(--su-notification-icon-width, 24px));color:var(--su-notification-icon-color, currentColor)}.notification .icon-container .icon{width:100%;height:100%}.notification .message{flex:1}.notification .close{position:absolute;width:var(--su-notification-close-btn-size, 20px);height:var(--su-notification-close-btn-size, 20px);top:calc(var(--su-notification-close-btn-size, 20px) * -.5);right:calc(var(--su-notification-close-btn-size, 20px) * -.5);background:var(--su-notification-close-btn-background-color, var(--su-notification-background-color, #fff));color:var(--su-notification-close-btn-text-color, var(--su-notification-text-color, #333));border:1px solid var(--su-notification-close-btn-border-color, rgba(0, 0, 0, 0));border-radius:var(--su-notification-close-btn-border-radius, 50%);box-shadow:0 4px 8px var(--su-notification-box-shadow, rgba(0, 0, 0, .15));font-size:var(--su-notification-close-btn-font-size, 1rem);display:flex;justify-content:center;align-items:center;line-height:1;cursor:pointer}.notification .close:hover{background:var(--su-notification-close-btn-hover-background, rgba(51, 51, 51, .5));color:var(--su-notification-close-btn-hover-color, #fff)}\n"]
112
+ template: "<div class=\"notification-container {{ service.position }}\" [attr.data-slide]=\"service.slideFrom\">\n @for (notification of notifications(); track notification.id) {\n <div\n class=\"notification {{ notification.type }} {{ notification.cssClass ?? '' }}\"\n animate.enter=\"su-notification-enter\"\n animate.leave=\"su-notification-leave\"\n >\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 <div class=\"content\">\n <span class=\"message\">\n @if (typeof notification.message === 'string') {\n {{ notification.message }}\n } @else {\n @for (part of notification.message; track $index) {\n @if (typeof part === 'string') {{{ part }}} @else {<button class=\"link\" type=\"button\" (click)=\"runAction(notification.id, part)\">{{ part.label }}</button>}\n }\n }\n </span>\n\n @if (notification.actions?.length) {\n <div class=\"actions\">\n @for (action of notification.actions; track $index) {\n <button class=\"action\" type=\"button\" (click)=\"runAction(notification.id, action)\">{{ action.label }}</button>\n }\n </div>\n }\n </div>\n\n <button class=\"close\" (click)=\"dismiss(notification.id)\" type=\"button\">×</button>\n </div>\n }\n</div>\n\n\n",
113
+ styles: [".notification-container{--_edge: var(--su-notification-container-position, 1rem);--_left: calc(-100% - 2rem) 0;--_right: calc(100% + 2rem) 0;--_top: 0 calc(-100% - 2rem) ;--_bottom: 0 calc(100% + 2rem) ;position:fixed;pointer-events:none;display:flex;flex-direction:column;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[class*=top-]{top:var(--_edge);--_slide: var(--_top)}.notification-container[class*=bottom-]{bottom:var(--_edge);flex-direction:column-reverse;--_slide: var(--_bottom)}.notification-container[class*=-right]{align-items:flex-end;right:var(--_edge);--_slide: var(--_right)}.notification-container[class*=-left]{align-items:flex-start;left:var(--_edge);--_slide: var(--_left)}.notification-container[class*=-center]{align-items:center;left:50%;translate:-50% 0}.notification-container[data-slide=left]{--_slide: var(--_left)}.notification-container[data-slide=right]{--_slide: var(--_right)}.notification-container[data-slide=top]{--_slide: var(--_top)}.notification-container[data-slide=bottom]{--_slide: var(--_bottom)}.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);--_shadow: 0 4px 8px var(--su-notification-box-shadow, rgba(0, 0, 0, .15));box-shadow:var(--_shadow);border-left:4px solid var(--_border);display:flex;align-items:center;gap:1rem}.notification.success{--_border: var(--su-notification-success-border-color, #4caf50)}.notification.info{--_border: var(--su-notification-info-border-color, #2196f3)}.notification.warning{--_border: var(--su-notification-warning-border-color, #ff9800)}.notification.error{--_border: var(--su-notification-error-border-color, #f44336)}.notification.custom{--_border: var(--su-notification-custom-border-color, #9c27b0)}.notification .close{--_size: var(--su-notification-close-btn-size, 20px);position:absolute;width:var(--_size);height:var(--_size);top:calc(var(--_size) / -2);right:calc(var(--_size) / -2);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:var(--_shadow);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)}.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)}.icon{width:100%;height:100%}.content{display:grid;flex:1;gap:.75rem}.actions{display:flex;flex-wrap:wrap;gap:.5rem}.action,.link{background:none;color:inherit;cursor:pointer;font:inherit}.action{border:1px solid var(--su-notification-action-border-color, currentColor);border-radius:6px;padding:.25rem .75rem}.link{border:0;padding:0;text-decoration:underline}.su-notification-enter{animation:su-notification-slide var(--su-notification-enter-duration, .4s) ease-out}.su-notification-leave{animation:su-notification-slide var(--su-notification-leave-duration, .3s) ease-in reverse forwards}@keyframes su-notification-slide{0%{opacity:0;translate:var(--_slide)}}@media(prefers-reduced-motion:reduce){.su-notification-enter,.su-notification-leave{animation:none}}\n"]
104
114
  }]
105
115
  }]
106
116
  });
@@ -1 +1 @@
1
- {"version":3,"file":"su-labs-notifications.mjs","names":[],"sources":["../../../../projects/su-labs/notifications/src/lib/notification.service.ts","../../../../projects/su-labs/notifications/src/lib/notification.component.ts","../../../../projects/su-labs/notifications/src/lib/notification.component.html"],"sourcesContent":["import { Injectable, OnDestroy, signal } from '@angular/core';\nimport {\n SuNotification,\n SuNotificationConfig,\n SuNotificationController,\n SuNotificationOptions,\n SuNotificationPosition,\n} from '@su-labs/core/notifications';\n\n/**\n * Angular service for managing notifications.\n *\n * Thin wrapper around the framework-agnostic `SuNotificationController` from\n * `@su-labs/core/notifications` that exposes the notifications as an Angular signal.\n */\n@Injectable({ providedIn: 'root' })\nexport class SuNotificationService implements OnDestroy {\n /** Framework-agnostic notification logic */\n private readonly controller = new SuNotificationController();\n\n /** Internal signal holding the list of notifications, kept in sync with the controller */\n private readonly _notifications = signal<SuNotification[]>(this.controller.notifications.get());\n\n /**\n * Read-only access to the notifications list.\n * Can be used in templates for reactive updates.\n */\n readonly notifications = this._notifications.asReadonly();\n\n /** Stops syncing the controller's notifications into the signal */\n private readonly unsubscribe = this.controller.notifications.subscribe((list) => this._notifications.set(list));\n\n /**\n * Position where notifications appear on the screen.\n * Can also be set via the `configure` method.\n * @default 'top-right'\n */\n get position(): SuNotificationPosition {\n return this.controller.position.get();\n }\n\n set position(position: SuNotificationPosition) {\n this.controller.configure({ position });\n }\n\n /**\n * Configure the notification service.\n * @param cfg Configuration object\n * @param cfg.position Optional position to display notifications.\n */\n configure(cfg: SuNotificationConfig): void {\n this.controller.configure(cfg);\n }\n\n /**\n * Show a new notification.\n * @param options Options to configure the notification.\n * @returns The unique ID of the notification.\n */\n show(options: SuNotificationOptions): string {\n return this.controller.show(options);\n }\n\n /**\n * Dismiss a specific notification by its ID.\n * @param id ID of the notification to remove.\n */\n dismiss(id: string): void {\n this.controller.dismiss(id);\n }\n\n /**\n * Clear all notifications immediately.\n */\n clearAll(): void {\n this.controller.clearAll();\n }\n\n /** Angular lifecycle hook for service destruction */\n ngOnDestroy(): void {\n this.unsubscribe();\n this.controller.destroy();\n }\n}\n","import { Component, inject, ChangeDetectionStrategy } from '@angular/core';\nimport { SuNotificationService } from './notification.service';\nimport { DomSanitizer, SafeHtml } from '@angular/platform-browser';\nimport { isSuNotificationImageIcon } from '@su-labs/core/notifications';\n\n/**\n * Component to display notifications on the screen.\n *\n * Uses `SuNotificationService` to manage and render notifications.\n */\n@Component({\n selector: 'su-lib-notifications',\n standalone: true,\n templateUrl: './notification.component.html',\n changeDetection: ChangeDetectionStrategy.Eager,\n styleUrls: ['./notification.component.scss'],\n})\nexport class SuNotificationComponent {\n /** Injected notification service */\n service = inject(SuNotificationService);\n\n /** Read-only signal of the current notifications */\n notifications = this.service.notifications;\n\n /** Angular sanitizer to safely render inline SVG strings */\n private sanitizer = inject(DomSanitizer);\n\n /**\n * Dismiss a notification by its ID.\n * Delegates to the service.\n * @param id ID of the notification to dismiss\n */\n dismiss(id: string): void {\n this.service.dismiss(id);\n }\n\n /**\n * Checks if the provided `icon` value should be rendered as an image (`<img>`).\n * Inline SVG strings are rendered with `[innerHTML]` instead.\n * See `isSuNotificationImageIcon` in `@su-labs/core/notifications` for the rules.\n *\n * @param icon The icon value from the notification (boolean or string)\n * @returns `true` if the icon is an image path or URL\n */\n isImage(icon: string | boolean): boolean {\n return isSuNotificationImageIcon(icon);\n }\n\n /**\n * Sanitizes an inline SVG string so it can be safely rendered with [innerHTML].\n *\n * @param icon Inline SVG string\n * @returns SafeHtml object that can be bound to [innerHTML]\n */\n getSanitizedIcon(icon: string): SafeHtml {\n return this.sanitizer.bypassSecurityTrustHtml(icon);\n }\n}\n","<div class=\"notification-container {{ service.position }}\">\n\t@for (notification of notifications(); track notification.id) {\n\t<div class=\"notification {{ notification.type }} {{ notification.cssClass ?? '' }}\">\n\n\t\t<div class=\"icon-container\">\n\t\t\t@if (notification.icon) {\n\t\t\t\t@if (isImage(notification.icon!)) {\n\t\t\t\t\t<img [src]=\"notification.icon\" alt=\"icon\" />\n\t\t\t\t} @else if (typeof notification.icon === 'string') {\n\t\t\t\t\t<span [innerHTML]=\"getSanitizedIcon(notification.icon)\"></span>\n\t\t\t\t}\n\t\t\t<!-- if icon === true, render default SVG via switch -->\n\t\t\t\t@else {\n\t\t\t\t\t@switch (notification.type) {\n\t\t\t\t\t@case('success') {\n\t\t\t\t\t\t<svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n\t\t\t\t\t\t\tstroke-linecap=\"round\" stroke-linejoin=\"round\">\n\t\t\t\t\t\t\t<path d=\"M20 6L9 17l-5-5\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t}\n\t\t\t\t\t@case('info') {\n\t\t\t\t\t\t<svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n\t\t\t\t\t\t\tstroke-linecap=\"round\" stroke-linejoin=\"round\">\n\t\t\t\t\t\t\t<circle cx=\"12\" cy=\"12\" r=\"10\" />\n\t\t\t\t\t\t\t<line x1=\"12\" y1=\"16\" x2=\"12\" y2=\"12\" />\n\t\t\t\t\t\t\t<line x1=\"12\" y1=\"8\" x2=\"12\" y2=\"8\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t}\n\t\t\t\t\t@case('warning') {\n\t\t\t\t\t\t<svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n\t\t\t\t\t\t\tstroke-linecap=\"round\" stroke-linejoin=\"round\">\n\t\t\t\t\t\t\t<path d=\"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z\" />\n\t\t\t\t\t\t\t<line x1=\"12\" y1=\"9\" x2=\"12\" y2=\"13\" />\n\t\t\t\t\t\t\t<line x1=\"12\" y1=\"17\" x2=\"12\" y2=\"17\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t}\n\t\t\t\t\t@case('error') {\n\t\t\t\t\t\t<svg class=\"icon\" viewBox=\"0 0 24 24\" width=\"24\" height=\"24\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"2\"\n\t\t\t\t\t\t\tstroke-linecap=\"round\" stroke-linejoin=\"round\">\n\t\t\t\t\t\t\t<circle cx=\"12\" cy=\"12\" r=\"10\" />\n\t\t\t\t\t\t\t<line x1=\"15\" y1=\"9\" x2=\"9\" y2=\"15\" />\n\t\t\t\t\t\t\t<line x1=\"9\" y1=\"9\" x2=\"15\" y2=\"15\" />\n\t\t\t\t\t\t</svg>\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t</div>\n\n\t\t<span class=\"message\">{{ notification.message }}</span>\n\n\t\t<button class=\"close\" (click)=\"dismiss(notification.id)\" type=\"button\">×</button>\n\t</div>\n\t}\n</div>\n\n\n"],"mappings":";;;;AAgBA,IAAa,wBAAb,MAAa,sBAAqB;CAEf,aAAa,IAAI,yBAAwB;CAGzC,iBAAiB,OAAyB,KAAK,WAAW,cAAc,IAAG,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,iBAAA,CAAA,+BAAA,CAAA,CAAA;CAMtF,gBAAgB,KAAK,eAAe,WAAU;CAGtC,cAAc,KAAK,WAAW,cAAc,WAAW,SAAS,KAAK,eAAe,IAAI,IAAI,CAAC;CAO9G,IAAI,WAAQ;EACV,OAAO,KAAK,WAAW,SAAS,IAAG;CACrC;CAEA,IAAI,SAAS,UAAgC;EAC3C,KAAK,WAAW,UAAU,EAAE,SAAQ,CAAE;CACxC;CAOA,UAAU,KAAyB;EACjC,KAAK,WAAW,UAAU,GAAG;CAC/B;CAOA,KAAK,SAA8B;EACjC,OAAO,KAAK,WAAW,KAAK,OAAO;CACrC;CAMA,QAAQ,IAAU;EAChB,KAAK,WAAW,QAAQ,EAAE;CAC5B;CAKA,WAAQ;EACN,KAAK,WAAW,SAAQ;CAC1B;CAGA,cAAW;EACT,KAAK,YAAW;EAChB,KAAK,WAAW,QAAO;CACzB;CAlEW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAqB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAArB,OAAA,QAAA,GAAA,sBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAqB,YADR;CAAM,CAAA;;AACnB,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAqB,YAAA,CAAA;EADjC,MAAA;EAAW,MAAA,CAAA,EAAE,YAAY,OAAM,CAAE;;;ACElC,IAAa,0BAAb,MAAa,wBAAuB;CAElC,UAAU,OAAO,qBAAqB;CAGtC,gBAAgB,KAAK,QAAQ;CAGrB,YAAY,OAAO,YAAY;CAOvC,QAAQ,IAAU;EAChB,KAAK,QAAQ,QAAQ,EAAE;CACzB;CAUA,QAAQ,MAAsB;EAC5B,OAAO,0BAA0B,IAAI;CACvC;CAQA,iBAAiB,MAAY;EAC3B,OAAO,KAAK,UAAU,wBAAwB,IAAI;CACpD;CAvCW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAuB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAvB,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAuB,cAAA;EAAA,UAAA;EAAA,UAAA;EAAA,UCjBpC;EAyDA,QAAA,CAAA,ohHAAA;EAAA,iBAAA,GAAA,wBAAA;CAAA,CAAA;;ADxCa,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAuB,YAAA,CAAA;EAPnC,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAsB,YACpB;GAAI,iBAEC,wBAAwB;GAAK,UAAA;GAAA,QAAA,CAAA,ohHAAA;EAAA,CAAA"}
1
+ {"version":3,"file":"su-labs-notifications.mjs","names":[],"sources":["../../../../projects/su-labs/notifications/src/lib/notification.service.ts","../../../../projects/su-labs/notifications/src/lib/notification.component.ts","../../../../projects/su-labs/notifications/src/lib/notification.component.html"],"sourcesContent":["import { Injectable, OnDestroy, signal } from '@angular/core';\nimport {\n SuNotification,\n SuNotificationConfig,\n SuNotificationController,\n SuNotificationOptions,\n SuNotificationPosition,\n SuNotificationSlide,\n} from '@su-labs/core/notifications';\n\n/**\n * Angular service for managing notifications.\n *\n * Thin wrapper around the framework-agnostic `SuNotificationController` from\n * `@su-labs/core/notifications` that exposes the notifications as an Angular signal.\n */\n@Injectable({ providedIn: 'root' })\nexport class SuNotificationService implements OnDestroy {\n /** Framework-agnostic notification logic */\n private readonly controller = new SuNotificationController();\n\n /** Internal signal holding the list of notifications, kept in sync with the controller */\n private readonly _notifications = signal<SuNotification[]>(this.controller.notifications.get());\n\n /**\n * Read-only access to the notifications list.\n * Can be used in templates for reactive updates.\n */\n readonly notifications = this._notifications.asReadonly();\n\n /** Stops syncing the controller's notifications into the signal */\n private readonly unsubscribe = this.controller.notifications.subscribe((list) => this._notifications.set(list));\n\n /**\n * Position where notifications appear on the screen.\n * Can also be set via the `configure` method.\n * @default 'top-right'\n */\n get position(): SuNotificationPosition {\n return this.controller.position.get();\n }\n\n set position(position: SuNotificationPosition) {\n this.controller.configure({ position });\n }\n\n /**\n * The direction notifications slide in from, whatever their position.\n * Can also be set via the `configure` method.\n * @default 'auto'\n */\n get slideFrom(): SuNotificationSlide {\n return this.controller.slideFrom.get();\n }\n\n set slideFrom(slideFrom: SuNotificationSlide) {\n this.controller.configure({ slideFrom });\n }\n\n /**\n * Configure the notification service.\n * @param cfg Configuration object\n * @param cfg.position Optional position to display notifications.\n * @param cfg.slideFrom Optional direction notifications slide in from.\n */\n configure(cfg: SuNotificationConfig): void {\n this.controller.configure(cfg);\n }\n\n /**\n * Show a new notification.\n * @param options Options to configure the notification.\n * @returns The unique ID of the notification.\n */\n show(options: SuNotificationOptions): string {\n return this.controller.show(options);\n }\n\n /**\n * Dismiss a specific notification by its ID.\n * @param id ID of the notification to remove.\n */\n dismiss(id: string): void {\n this.controller.dismiss(id);\n }\n\n /**\n * Clear all notifications immediately.\n */\n clearAll(): void {\n this.controller.clearAll();\n }\n\n /** Angular lifecycle hook for service destruction */\n ngOnDestroy(): void {\n this.unsubscribe();\n this.controller.destroy();\n }\n}\n","import { Component, inject, ChangeDetectionStrategy } from '@angular/core';\nimport { SuNotificationService } from './notification.service';\nimport { DomSanitizer, SafeHtml } from '@angular/platform-browser';\nimport { isSuNotificationImageIcon, SuNotificationAction } from '@su-labs/core/notifications';\n\n/**\n * Component to display notifications on the screen.\n *\n * Uses `SuNotificationService` to manage and render notifications.\n */\n@Component({\n selector: 'su-lib-notifications',\n standalone: true,\n templateUrl: './notification.component.html',\n changeDetection: ChangeDetectionStrategy.Eager,\n styleUrls: ['./notification.component.scss'],\n})\nexport class SuNotificationComponent {\n /** Injected notification service */\n service = inject(SuNotificationService);\n\n /** Read-only signal of the current notifications */\n notifications = this.service.notifications;\n\n /** Angular sanitizer to safely render inline SVG strings */\n private sanitizer = inject(DomSanitizer);\n\n /**\n * Dismiss a notification by its ID.\n * Delegates to the service.\n * @param id ID of the notification to dismiss\n */\n dismiss(id: string): void {\n this.service.dismiss(id);\n }\n\n /**\n * Runs an action button of a notification, then closes the notification unless the action says not to.\n * @param id ID of the notification the button belongs to\n * @param action The action that was pressed\n */\n runAction(id: string, action: SuNotificationAction): void {\n action.onClick();\n if (action.dismiss !== false) {\n this.service.dismiss(id);\n }\n }\n\n /**\n * Checks if the provided `icon` value should be rendered as an image (`<img>`).\n * Inline SVG strings are rendered with `[innerHTML]` instead.\n * See `isSuNotificationImageIcon` in `@su-labs/core/notifications` for the rules.\n *\n * @param icon The icon value from the notification (boolean or string)\n * @returns `true` if the icon is an image path or URL\n */\n isImage(icon: string | boolean): boolean {\n return isSuNotificationImageIcon(icon);\n }\n\n /**\n * Sanitizes an inline SVG string so it can be safely rendered with [innerHTML].\n *\n * @param icon Inline SVG string\n * @returns SafeHtml object that can be bound to [innerHTML]\n */\n getSanitizedIcon(icon: string): SafeHtml {\n return this.sanitizer.bypassSecurityTrustHtml(icon);\n }\n}\n","<div class=\"notification-container {{ service.position }}\" [attr.data-slide]=\"service.slideFrom\">\n\t@for (notification of notifications(); track notification.id) {\n\t<div\n\t\tclass=\"notification {{ notification.type }} {{ notification.cssClass ?? '' }}\"\n\t\tanimate.enter=\"su-notification-enter\"\n\t\tanimate.leave=\"su-notification-leave\"\n\t>\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<div class=\"content\">\n\t\t\t<span class=\"message\">\n\t\t\t\t@if (typeof notification.message === 'string') {\n\t\t\t\t\t{{ notification.message }}\n\t\t\t\t} @else {\n\t\t\t\t\t@for (part of notification.message; track $index) {\n\t\t\t\t\t\t@if (typeof part === 'string') {{{ part }}} @else {<button class=\"link\" type=\"button\" (click)=\"runAction(notification.id, part)\">{{ part.label }}</button>}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t</span>\n\n\t\t\t@if (notification.actions?.length) {\n\t\t\t<div class=\"actions\">\n\t\t\t\t@for (action of notification.actions; track $index) {\n\t\t\t\t<button class=\"action\" type=\"button\" (click)=\"runAction(notification.id, action)\">{{ action.label }}</button>\n\t\t\t\t}\n\t\t\t</div>\n\t\t\t}\n\t\t</div>\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":";;;;AAiBA,IAAa,wBAAb,MAAa,sBAAqB;CAEf,aAAa,IAAI,yBAAwB;CAGzC,iBAAiB,OAAyB,KAAK,WAAW,cAAc,IAAG,GAAG,GAAA,YAAA,CAAA,EAAA,WAAA,iBAAA,CAAA,+BAAA,CAAA,CAAA;CAMtF,gBAAgB,KAAK,eAAe,WAAU;CAGtC,cAAc,KAAK,WAAW,cAAc,WAAW,SAAS,KAAK,eAAe,IAAI,IAAI,CAAC;CAO9G,IAAI,WAAQ;EACV,OAAO,KAAK,WAAW,SAAS,IAAG;CACrC;CAEA,IAAI,SAAS,UAAgC;EAC3C,KAAK,WAAW,UAAU,EAAE,SAAQ,CAAE;CACxC;CAOA,IAAI,YAAS;EACX,OAAO,KAAK,WAAW,UAAU,IAAG;CACtC;CAEA,IAAI,UAAU,WAA8B;EAC1C,KAAK,WAAW,UAAU,EAAE,UAAS,CAAE;CACzC;CAQA,UAAU,KAAyB;EACjC,KAAK,WAAW,UAAU,GAAG;CAC/B;CAOA,KAAK,SAA8B;EACjC,OAAO,KAAK,WAAW,KAAK,OAAO;CACrC;CAMA,QAAQ,IAAU;EAChB,KAAK,WAAW,QAAQ,EAAE;CAC5B;CAKA,WAAQ;EACN,KAAK,WAAW,SAAQ;CAC1B;CAGA,cAAW;EACT,KAAK,YAAW;EAChB,KAAK,WAAW,QAAO;CACzB;CAhFW,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;;;ACClC,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;CAOA,UAAU,IAAY,QAA4B;EAChD,OAAO,QAAO;EACd,IAAI,OAAO,YAAY,OACrB,KAAK,QAAQ,QAAQ,EAAE;CAE3B;CAUA,QAAQ,MAAsB;EAC5B,OAAO,0BAA0B,IAAI;CACvC;CAQA,iBAAiB,MAAY;EAC3B,OAAO,KAAK,UAAU,wBAAwB,IAAI;CACpD;CAnDW,OAAA,OAAA,GAAA,mBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,UAAA;EAAA,MAAA;EAAuB,MAAA,CAAA;EAAA,QAAA,GAAA,gBAAA;CAAA,CAAA;CAAvB,OAAA,OAAA,GAAA,qBAAA;EAAA,YAAA;EAAA,SAAA;EAAA,MAAA;EAAuB,cAAA;EAAA,UAAA;EAAA,UAAA;EAAA,UCjBpC;EA+EA,QAAA,CAAA,03HAAA;EAAA,iBAAA,GAAA,wBAAA;CAAA,CAAA;;AD9Da,GAAA,yBAAA;CAAA,YAAA;CAAA,SAAA;CAAA,UAAA;CAAA,MAAA;CAAuB,YAAA,CAAA;EAPnC,MAAA;EACW,MAAA,CAAA;GAAA,UAAA;GAAsB,YACpB;GAAI,iBAEC,wBAAwB;GAAK,UAAA;GAAA,QAAA,CAAA,03HAAA;EAAA,CAAA"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@su-labs/notifications",
3
- "version": "22.1.1",
3
+ "version": "22.3.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://greezaaa.github.io/settings-utils-lib/notifications/",
20
+ "homepage": "https://su-labs.dev/notifications/",
21
21
  "author": {
22
22
  "name": "Yevheniy Alekseyev",
23
23
  "email": "yev.alekseyev@gmail.com",
@@ -36,7 +36,7 @@
36
36
  "@angular/core": "^22.0.0"
37
37
  },
38
38
  "dependencies": {
39
- "@su-labs/core": "^1.0.0",
39
+ "@su-labs/core": "1.3.0",
40
40
  "tslib": "^2.3.0"
41
41
  },
42
42
  "sideEffects": false,
@@ -1,6 +1,6 @@
1
1
  import * as i0 from "@angular/core";
2
2
  import { OnDestroy } from "@angular/core";
3
- import { SuNotification, SuNotification as SuNotification$1, SuNotificationConfig, SuNotificationConfig as SuNotificationConfig$1, SuNotificationOptions, SuNotificationOptions as SuNotificationOptions$1, SuNotificationPosition, SuNotificationPosition as SuNotificationPosition$1, SuNotificationType } from "@su-labs/core/notifications";
3
+ import { SuNotification, SuNotification as SuNotification$1, SuNotificationAction, SuNotificationAction as SuNotificationAction$1, SuNotificationConfig, SuNotificationConfig as SuNotificationConfig$1, SuNotificationMessagePart, SuNotificationOptions, SuNotificationOptions as SuNotificationOptions$1, SuNotificationPosition, SuNotificationPosition as SuNotificationPosition$1, SuNotificationSlide, SuNotificationSlide as SuNotificationSlide$1, SuNotificationType } from "@su-labs/core/notifications";
4
4
  import { SafeHtml } from "@angular/platform-browser";
5
5
  /**
6
6
  * Angular service for managing notifications.
@@ -27,10 +27,18 @@ export declare class SuNotificationService implements OnDestroy {
27
27
  */
28
28
  get position(): SuNotificationPosition$1;
29
29
  set position(position: SuNotificationPosition$1);
30
+ /**
31
+ * The direction notifications slide in from, whatever their position.
32
+ * Can also be set via the `configure` method.
33
+ * @default 'auto'
34
+ */
35
+ get slideFrom(): SuNotificationSlide$1;
36
+ set slideFrom(slideFrom: SuNotificationSlide$1);
30
37
  /**
31
38
  * Configure the notification service.
32
39
  * @param cfg Configuration object
33
40
  * @param cfg.position Optional position to display notifications.
41
+ * @param cfg.slideFrom Optional direction notifications slide in from.
34
42
  */
35
43
  configure(cfg: SuNotificationConfig$1): void;
36
44
  /**
@@ -71,6 +79,12 @@ export declare class SuNotificationComponent {
71
79
  * @param id ID of the notification to dismiss
72
80
  */
73
81
  dismiss(id: string): void;
82
+ /**
83
+ * Runs an action button of a notification, then closes the notification unless the action says not to.
84
+ * @param id ID of the notification the button belongs to
85
+ * @param action The action that was pressed
86
+ */
87
+ runAction(id: string, action: SuNotificationAction$1): void;
74
88
  /**
75
89
  * Checks if the provided `icon` value should be rendered as an image (`<img>`).
76
90
  * Inline SVG strings are rendered with `[innerHTML]` instead.
@@ -90,4 +104,4 @@ export declare class SuNotificationComponent {
90
104
  static ɵfac: i0.ɵɵFactoryDeclaration<SuNotificationComponent, never>;
91
105
  static ɵcmp: i0.ɵɵComponentDeclaration<SuNotificationComponent, "su-lib-notifications", never, {}, {}, never, never, true, never>;
92
106
  }
93
- export type { SuNotification, SuNotificationConfig, SuNotificationOptions, SuNotificationPosition, SuNotificationType };
107
+ export type { SuNotification, SuNotificationAction, SuNotificationConfig, SuNotificationMessagePart, SuNotificationOptions, SuNotificationPosition, SuNotificationSlide, SuNotificationType };