@su-labs/notifications 21.0.4 โ 21.0.5
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/package.json +1 -1
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@^21 @angular/core@^21
|
|
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` | Global notification position |
|
|
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 | Default Icon |
|
|
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 21+
|
|
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 21+ and TypeScript 5.7+ 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).
|