@avoraui/av-notifications 0.0.2

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 ADDED
@@ -0,0 +1,502 @@
1
+ # AvNotification Service (AvoraUI)
2
+
3
+ A flexible and customizable Angular notification service that provides toast-style notifications with multiple positioning options, themes, and animation effects. Built with Angular Material Dialog for optimal performance and accessibility.
4
+
5
+ ## Features
6
+
7
+ - ✅ **Multiple Notification Types**: Success, Error, and Warning notifications
8
+ - ✅ **Flexible Positioning**: 8 different position options (top, bottom, corners, sides)
9
+ - ✅ **Theme Support**: Light, dark, and auto themes
10
+ - ✅ **Auto-close Functionality**: Configurable duration with optional manual close
11
+ - ✅ **Animation Effects**: Smooth entrance and exit animations
12
+ - ✅ **Stack Management**: Multiple notifications with proper stacking
13
+ - ✅ **Material Design**: Built with Angular Material components
14
+ - ✅ **Memory Efficient**: Automatic cleanup and tracking of active notifications
15
+ - ✅ **Accessibility**: Full keyboard navigation and screen reader support
16
+
17
+ ## Dependencies
18
+
19
+ This service requires the following Angular Material modules:
20
+
21
+ ```typescript
22
+ import { MatDialog, MatDialogModule } from "@angular/material/dialog";
23
+ import { MatButton } from "@angular/material/button";
24
+ import { MatIcon } from '@angular/material/icon';
25
+ import { MatCard } from "@angular/material/card";
26
+ ```
27
+
28
+ **Required Dependencies:**
29
+ - `@angular/animations`: "^20.1.3"
30
+
31
+ ## Installation
32
+
33
+ 1. Ensure you have Angular Material installed in your project
34
+ 2. Install Angular Animations: `npm install @angular/animations@^20.1.3`
35
+ 3. Import the notification service in your module or inject it directly (standalone service)
36
+ 4. Add the notification components to your module declarations
37
+
38
+ ## Quick Start
39
+
40
+ ### Basic Usage
41
+
42
+ ```typescript
43
+ import { AvNotificationService } from 'your-library/notification';
44
+
45
+ export class MyComponent {
46
+ constructor(private notificationService: AvNotificationService) {}
47
+
48
+ showNotifications() {
49
+ // Success notification
50
+ this.notificationService.showSuccess('Operation completed successfully!');
51
+
52
+ // Error notification
53
+ this.notificationService.showFailure('Something went wrong!');
54
+
55
+ // Warning notification
56
+ this.notificationService.showWarning('Please check your input!');
57
+ }
58
+ }
59
+ ```
60
+
61
+ ## Advanced Configuration
62
+
63
+ ### All Available Options
64
+
65
+ ```typescript
66
+ export class AdvancedNotificationComponent {
67
+ constructor(private notificationService: AvNotificationService) {}
68
+
69
+ showCustomNotifications() {
70
+ // Success with custom configuration
71
+ this.notificationService.showSuccess('File uploaded successfully!', {
72
+ position: 'top-right',
73
+ duration: 8000,
74
+ theme: 'dark',
75
+ showCloseButton: true,
76
+ autoClose: true,
77
+ animationDuration: 500
78
+ });
79
+
80
+ // Error with persistent notification (no auto-close)
81
+ this.notificationService.showFailure('Critical system error occurred', {
82
+ position: 'center',
83
+ autoClose: false,
84
+ theme: 'light',
85
+ showCloseButton: true
86
+ });
87
+
88
+ // Warning with custom positioning
89
+ this.notificationService.showWarning('Session will expire in 5 minutes', {
90
+ position: 'bottom-left',
91
+ duration: 10000,
92
+ theme: 'auto',
93
+ animationDuration: 300
94
+ });
95
+ }
96
+ }
97
+ ```
98
+
99
+ ## Configuration Options
100
+
101
+ ### NotificationConfig Interface
102
+
103
+ | Property | Type | Required | Default | Description |
104
+ |----------|------|----------|---------|-------------|
105
+ | `message` | `string` | Yes | - | The notification message to display |
106
+ | `type` | `NotificationType` | Yes | - | Type of notification (success, error, warning) |
107
+ | `position` | `NotificationPosition` | No | `'top'` | Position where notification appears |
108
+ | `duration` | `number` | No | `5000` | Auto-close duration in milliseconds |
109
+ | `animationDuration` | `number` | No | `300` | Animation duration in milliseconds |
110
+ | `showCloseButton` | `boolean` | No | `true` | Whether to show manual close button |
111
+ | `autoClose` | `boolean` | No | `true` | Whether notification auto-closes |
112
+ | `theme` | `NotificationTheme` | No | `'auto'` | Visual theme (light, dark, auto) |
113
+
114
+ ### Position Options
115
+
116
+ ```typescript
117
+ type NotificationPosition =
118
+ | 'top' // Top center
119
+ | 'bottom' // Bottom center
120
+ | 'left' // Left center
121
+ | 'right' // Right center
122
+ | 'top-left' // Top left corner
123
+ | 'top-right' // Top right corner
124
+ | 'bottom-left' // Bottom left corner
125
+ | 'bottom-right'; // Bottom right corner
126
+ ```
127
+
128
+ ### Notification Types
129
+
130
+ ```typescript
131
+ type NotificationType = 'success' | 'error' | 'warning';
132
+ ```
133
+
134
+ ### Theme Options
135
+
136
+ ```typescript
137
+ type NotificationTheme = 'light' | 'dark' | 'auto';
138
+ ```
139
+
140
+ ## Service Methods
141
+
142
+ ### Core Methods
143
+
144
+ ```typescript
145
+ // Show success notification
146
+ showSuccess(message: string, options?: Partial<NotificationConfig>): MatDialogRef<any>
147
+
148
+ // Show error notification
149
+ showFailure(message: string, options?: Partial<NotificationConfig>): MatDialogRef<any>
150
+
151
+ // Show warning notification
152
+ showWarning(message: string, options?: Partial<NotificationConfig>): MatDialogRef<any>
153
+ ```
154
+
155
+ ### Management Methods
156
+
157
+ ```typescript
158
+ // Close all active notifications
159
+ closeAll(): void
160
+
161
+ // Close notifications by type
162
+ closeByType(type: NotificationType): void
163
+
164
+ // Get count of active notifications
165
+ getActiveCount(): number
166
+
167
+ // Check if notifications are active
168
+ hasActiveNotifications(type?: NotificationType): boolean
169
+ ```
170
+
171
+ ## Real-World Examples
172
+
173
+ ### E-commerce Application
174
+
175
+ ```typescript
176
+ export class EcommerceService {
177
+ constructor(private notificationService: AvNotificationService) {}
178
+
179
+ // Product added to cart
180
+ addToCart(product: Product) {
181
+ this.cartService.add(product).subscribe({
182
+ next: () => {
183
+ this.notificationService.showSuccess(`${product.name} added to cart!`, {
184
+ position: 'top-right',
185
+ duration: 3000,
186
+ theme: 'light'
187
+ });
188
+ },
189
+ error: () => {
190
+ this.notificationService.showFailure('Failed to add product to cart', {
191
+ position: 'top-right',
192
+ duration: 5000,
193
+ theme: 'light'
194
+ });
195
+ }
196
+ });
197
+ }
198
+
199
+ // Low stock warning
200
+ checkStockLevels() {
201
+ this.notificationService.showWarning('Only 2 items left in stock!', {
202
+ position: 'bottom-right',
203
+ duration: 8000,
204
+ theme: 'auto',
205
+ showCloseButton: true
206
+ });
207
+ }
208
+
209
+ // Payment processing
210
+ processPayment() {
211
+ this.notificationService.showSuccess('Payment processed successfully!', {
212
+ position: 'center',
213
+ duration: 4000,
214
+ theme: 'dark',
215
+ animationDuration: 500
216
+ });
217
+ }
218
+ }
219
+ ```
220
+
221
+ ### Form Validation
222
+
223
+ ```typescript
224
+ export class UserFormComponent {
225
+ constructor(private notificationService: AvNotificationService) {}
226
+
227
+ onSubmit(formData: UserForm) {
228
+ if (this.validateForm(formData)) {
229
+ this.userService.save(formData).subscribe({
230
+ next: () => {
231
+ this.notificationService.showSuccess('User profile updated successfully!', {
232
+ position: 'top',
233
+ duration: 6000,
234
+ theme: 'light'
235
+ });
236
+ },
237
+ error: (error) => {
238
+ this.notificationService.showFailure(`Update failed: ${error.message}`, {
239
+ position: 'top',
240
+ autoClose: false,
241
+ theme: 'light',
242
+ showCloseButton: true
243
+ });
244
+ }
245
+ });
246
+ } else {
247
+ this.notificationService.showWarning('Please fill in all required fields', {
248
+ position: 'top-left',
249
+ duration: 4000,
250
+ theme: 'auto'
251
+ });
252
+ }
253
+ }
254
+ }
255
+ ```
256
+
257
+ ### File Upload Progress
258
+
259
+ ```typescript
260
+ export class FileUploadComponent {
261
+ constructor(private notificationService: AvNotificationService) {}
262
+
263
+ uploadFile(file: File) {
264
+ // Start upload notification
265
+ const uploadingRef = this.notificationService.showSuccess('Starting file upload...', {
266
+ position: 'bottom-right',
267
+ duration: 2000,
268
+ theme: 'dark'
269
+ });
270
+
271
+ this.fileService.upload(file).subscribe({
272
+ next: (progress) => {
273
+ if (progress === 100) {
274
+ this.notificationService.showSuccess('File uploaded successfully!', {
275
+ position: 'bottom-right',
276
+ duration: 5000,
277
+ theme: 'light',
278
+ animationDuration: 400
279
+ });
280
+ }
281
+ },
282
+ error: () => {
283
+ this.notificationService.showFailure('Upload failed. Please try again.', {
284
+ position: 'bottom-right',
285
+ autoClose: false,
286
+ theme: 'light',
287
+ showCloseButton: true
288
+ });
289
+ }
290
+ });
291
+ }
292
+ }
293
+ ```
294
+
295
+ ### System Notifications
296
+
297
+ ```typescript
298
+ export class SystemNotificationService {
299
+ constructor(private notificationService: AvNotificationService) {}
300
+
301
+ // Session timeout warning
302
+ showSessionTimeout() {
303
+ this.notificationService.showWarning('Your session will expire in 2 minutes', {
304
+ position: 'top',
305
+ duration: 10000,
306
+ theme: 'auto',
307
+ showCloseButton: true,
308
+ animationDuration: 300
309
+ });
310
+ }
311
+
312
+ // Maintenance mode
313
+ showMaintenanceMode() {
314
+ this.notificationService.showWarning('System maintenance scheduled for tonight', {
315
+ position: 'bottom',
316
+ autoClose: false,
317
+ theme: 'dark',
318
+ showCloseButton: true
319
+ });
320
+ }
321
+
322
+ // Connection status
323
+ showConnectionLost() {
324
+ this.notificationService.showFailure('Connection lost. Attempting to reconnect...', {
325
+ position: 'top-right',
326
+ autoClose: false,
327
+ theme: 'light',
328
+ showCloseButton: false
329
+ });
330
+ }
331
+
332
+ showConnectionRestored() {
333
+ this.notificationService.showSuccess('Connection restored!', {
334
+ position: 'top-right',
335
+ duration: 3000,
336
+ theme: 'light'
337
+ });
338
+ }
339
+ }
340
+ ```
341
+
342
+ ## Advanced Usage
343
+
344
+ ### Managing Multiple Notifications
345
+
346
+ ```typescript
347
+ export class NotificationManagerComponent {
348
+ constructor(private notificationService: AvNotificationService) {}
349
+
350
+ showBulkOperationResults() {
351
+ // Clear any existing notifications
352
+ this.notificationService.closeAll();
353
+
354
+ // Show results
355
+ this.notificationService.showSuccess('5 items processed successfully', {
356
+ position: 'top-right',
357
+ duration: 4000
358
+ });
359
+
360
+ this.notificationService.showWarning('2 items skipped (duplicates)', {
361
+ position: 'top-right',
362
+ duration: 6000
363
+ });
364
+
365
+ this.notificationService.showFailure('1 item failed to process', {
366
+ position: 'top-right',
367
+ duration: 8000
368
+ });
369
+ }
370
+
371
+ clearSpecificNotifications() {
372
+ // Close only error notifications
373
+ this.notificationService.closeByType('error');
374
+
375
+ // Check if any notifications are still active
376
+ const hasActiveNotifications = this.notificationService.hasActiveNotifications();
377
+ console.log('Active notifications:', hasActiveNotifications);
378
+
379
+ // Get count of active notifications
380
+ const count = this.notificationService.getActiveCount();
381
+ console.log('Total active notifications:', count);
382
+ }
383
+ }
384
+ ```
385
+
386
+ ### Custom Styling Integration
387
+
388
+ ```scss
389
+ // Custom notification styles
390
+ .notification-dialog {
391
+ &.notification-top-right {
392
+ margin-right: 24px !important;
393
+ margin-top: 24px !important;
394
+ }
395
+
396
+ &.notification-success {
397
+ .mat-mdc-dialog-container {
398
+ background: linear-gradient(135deg, #4caf50, #45a049);
399
+ color: white;
400
+ }
401
+ }
402
+
403
+ &.notification-theme-dark {
404
+ .mat-mdc-dialog-container {
405
+ background: #333;
406
+ color: #fff;
407
+ }
408
+ }
409
+ }
410
+ ```
411
+
412
+ ## Browser Support
413
+
414
+ - Chrome/Edge 57+
415
+ - Firefox 52+
416
+ - Safari 10.1+
417
+ - Modern browsers with CSS Grid and Flexbox support
418
+
419
+ ## Requirements
420
+
421
+ - Angular 17+
422
+ - Angular Material
423
+ - Modern browser with CSS Grid support
424
+
425
+ ## Performance Considerations
426
+
427
+ - Notifications are automatically tracked and cleaned up
428
+ - Object URLs are properly revoked to prevent memory leaks
429
+ - Efficient dialog positioning with CSS transforms
430
+ - Minimal DOM impact with Angular Material's overlay system
431
+
432
+ ## Accessibility Features
433
+
434
+ - Full keyboard navigation support
435
+ - Screen reader compatibility
436
+ - High contrast theme support
437
+ - Focus management for modal notifications
438
+ - ARIA labels and descriptions
439
+
440
+ ## Best Practices
441
+
442
+ ### Do's
443
+ ```typescript
444
+ // ✅ Use appropriate notification types
445
+ this.notificationService.showSuccess('Data saved successfully');
446
+ this.notificationService.showFailure('Validation error occurred');
447
+ this.notificationService.showWarning('Session expiring soon');
448
+
449
+ // ✅ Configure duration based on content importance
450
+ this.notificationService.showSuccess('Quick action completed', { duration: 3000 });
451
+ this.notificationService.showFailure('Critical error', { autoClose: false });
452
+
453
+ // ✅ Use consistent positioning
454
+ this.notificationService.showSuccess('Success', { position: 'top-right' });
455
+ this.notificationService.showFailure('Error', { position: 'top-right' });
456
+ ```
457
+
458
+ ### Don'ts
459
+ ```typescript
460
+ // ❌ Don't show too many notifications at once
461
+ // Instead, use closeAll() or batch them appropriately
462
+
463
+ // ❌ Don't use very short durations for important messages
464
+ this.notificationService.showFailure('Critical error', { duration: 1000 }); // Too short
465
+
466
+ // ❌ Don't forget to handle notification cleanup in components
467
+ // Always let the service manage notification lifecycle
468
+ ```
469
+
470
+ ## Troubleshooting
471
+
472
+ ### Common Issues
473
+
474
+ 1. **Notifications not appearing**
475
+ - Ensure Angular Material Dialog is imported
476
+ - Check that notification components are declared
477
+ - Verify CSS z-index values
478
+
479
+ 2. **Styling issues**
480
+ - Import Angular Material themes
481
+ - Check for CSS conflicts with custom styles
482
+ - Ensure proper theme configuration
483
+
484
+ 3. **Performance issues**
485
+ - Use `closeAll()` before showing bulk notifications
486
+ - Avoid very short animation durations
487
+ - Monitor active notification count
488
+
489
+ ## License
490
+
491
+ This project is licensed under the MIT License - see the LICENSE file for details.
492
+
493
+ ## Changelog
494
+
495
+ ### v0.0.1
496
+ - Initial release
497
+ - Success, error, and warning notification types
498
+ - 8 positioning options
499
+ - Theme support (light, dark, auto)
500
+ - Animation controls
501
+ - Stack management
502
+ - Accessibility features
Binary file