UNPKG

@acontplus/ng-notifications

Version:

Comprehensive Angular notification system with toast notifications (ngx-toastr), alerts (SweetAlert2), snackbars, theme detection, notification providers, and configurable styling. Supports multiple notification types with Angular Material integration.

254 lines (241 loc) 10.8 kB
import * as i0 from '@angular/core'; import { InjectionToken, EnvironmentProviders } from '@angular/core'; import { IndividualConfig, GlobalConfig } from 'ngx-toastr'; import { MatSnackBarConfig } from '@angular/material/snack-bar'; import { Observable } from 'rxjs'; type NotificationType = 'success' | 'error' | 'warning' | 'info'; type NotificationPosition = 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-center' | 'bottom-center'; type NotificationProvider = 'toastr' | 'snackbar' | 'sweetalert'; interface BaseNotificationConfig { readonly message: string; readonly title?: string; readonly type?: NotificationType; } interface NotificationCallProps extends BaseNotificationConfig { readonly config?: unknown; } interface SweetAlertConfig extends BaseNotificationConfig { readonly html?: string; readonly confirmButtonText?: string; readonly cancelButtonText?: string; readonly showCancelButton?: boolean; readonly allowOutsideClick?: boolean; readonly customClass?: string; } interface NotificationResult { isConfirmed?: boolean; isDenied?: boolean; isDismissed?: boolean; value?: unknown; } declare const NOTIFICATION_MESSAGES: { readonly SUCCESS: { readonly SAVE: "Data saved successfully"; readonly DELETE: "Item deleted successfully"; readonly UPDATE: "Data updated successfully"; readonly UPLOAD: "File uploaded successfully"; readonly CREATE: "Item created successfully"; readonly SYNC: "Data synchronized successfully"; }; readonly ERROR: { readonly SAVE: "Failed to save data"; readonly DELETE: "Failed to delete item"; readonly UPDATE: "Failed to update data"; readonly UPLOAD: "Failed to upload file"; readonly NETWORK: "Network error occurred"; readonly UNKNOWN: "An unexpected error occurred"; readonly VALIDATION: "Validation error"; readonly UNAUTHORIZED: "Unauthorized access"; readonly SERVER: "Server error occurred"; }; readonly WARNING: { readonly UNSAVED_CHANGES: "You have unsaved changes"; readonly SESSION_EXPIRING: "Your session is about to expire"; readonly STORAGE_FULL: "Storage is running low"; readonly DEPRECATED: "This feature is deprecated"; readonly LIMIT_REACHED: "Limit reached"; }; readonly INFO: { readonly LOADING: "Loading data..."; readonly PROCESSING: "Processing request..."; readonly MAINTENANCE: "System maintenance scheduled"; readonly UPDATE_AVAILABLE: "Update available"; readonly BACKUP_COMPLETE: "Backup completed"; }; }; declare const NOTIFICATION_DURATIONS: { readonly SHORT: 3000; readonly MEDIUM: 5000; readonly LONG: 8000; readonly PERSISTENT: 0; }; declare const NOTIFICATION_ICONS: { readonly success: "check_circle"; readonly error: "error"; readonly warning: "warning"; readonly info: "info"; }; type ToastrNotificationConfig = Partial<IndividualConfig>; declare const TOASTR_NOTIFICATION_CONFIG: InjectionToken<Partial<IndividualConfig<any>>>; interface SnackbarConfig extends MatSnackBarConfig { readonly defaultAction?: string; readonly iconEnabled?: boolean; readonly titleEnabled?: boolean; } declare const DEFAULT_SNACKBAR_CONFIG: SnackbarConfig; declare const SNACKBAR_CONFIG: InjectionToken<SnackbarConfig>; interface ToastrCallProps { readonly message: string; readonly title?: string; readonly options?: Partial<IndividualConfig>; } interface SnackbarProps { readonly type: NotificationType; readonly message: string; readonly title?: string; readonly action?: string; readonly config?: Partial<SnackbarConfig>; } interface SnackbarCallProps { readonly message: string; readonly title?: string; readonly action?: string; readonly config?: Partial<SnackbarConfig>; } declare const NOTIFICATION_CONFIG: InjectionToken<NotificationProviderConfig>; interface NotificationProviderConfig { defaultProvider: NotificationProvider; toastr?: unknown; snackbar?: unknown; sweetalert?: { defaultTheme?: 'auto' | 'material-ui' | 'material-ui-light' | 'material-ui-dark' | string; [key: string]: unknown; }; } declare abstract class NotificationProviderBase { abstract success(props: NotificationCallProps): void | Observable<NotificationResult>; abstract error(props: NotificationCallProps): void | Observable<NotificationResult>; abstract warning(props: NotificationCallProps): void | Observable<NotificationResult>; abstract info(props: NotificationCallProps): void | Observable<NotificationResult>; abstract confirm(config: SweetAlertConfig): Observable<NotificationResult>; static ɵfac: i0.ɵɵFactoryDeclaration<NotificationProviderBase, never>; static ɵprov: i0.ɵɵInjectableDeclaration<NotificationProviderBase>; } type ToastrType = 'success' | 'error' | 'warning' | 'info'; interface ToastrShowProps { readonly type: ToastrType; readonly message: string; readonly title?: string; readonly options?: Partial<IndividualConfig>; } declare class ToastrProvider extends NotificationProviderBase { private readonly toastrService; private readonly config; /** * Generic show method for dynamic toast types */ show(props: ToastrShowProps): void; success(props: NotificationCallProps): void; error(props: NotificationCallProps): void; warning(props: NotificationCallProps): void; info(props: NotificationCallProps): void; confirm(config: SweetAlertConfig): Observable<NotificationResult>; static ɵfac: i0.ɵɵFactoryDeclaration<ToastrProvider, never>; static ɵprov: i0.ɵɵInjectableDeclaration<ToastrProvider>; } declare class SnackbarProvider extends NotificationProviderBase { private readonly snackBar; private readonly config; /** * Display a snackbar with specific type and configuration */ show(props: SnackbarProps): void; success(props: NotificationCallProps): void; error(props: NotificationCallProps): void; warning(props: NotificationCallProps): void; info(props: NotificationCallProps): void; confirm(config: SweetAlertConfig): Observable<NotificationResult>; private buildPanelClasses; private buildMessage; static ɵfac: i0.ɵɵFactoryDeclaration<SnackbarProvider, never>; static ɵprov: i0.ɵɵInjectableDeclaration<SnackbarProvider>; } declare class SweetalertProvider extends NotificationProviderBase { private config; private themeDetector; private getTheme; success(props: NotificationCallProps): Observable<NotificationResult>; error(props: NotificationCallProps): Observable<NotificationResult>; warning(props: NotificationCallProps): Observable<NotificationResult>; info(props: NotificationCallProps): Observable<NotificationResult>; confirm(config: SweetAlertConfig): Observable<NotificationResult>; private showAlert; static ɵfac: i0.ɵɵFactoryDeclaration<SweetalertProvider, never>; static ɵprov: i0.ɵɵInjectableDeclaration<SweetalertProvider>; } declare class NotificationService { private config; private toastrProvider; private snackbarProvider; private sweetAlertProvider; private providers; private currentProvider; readonly messages: { readonly SUCCESS: { readonly SAVE: "Data saved successfully"; readonly DELETE: "Item deleted successfully"; readonly UPDATE: "Data updated successfully"; readonly UPLOAD: "File uploaded successfully"; readonly CREATE: "Item created successfully"; readonly SYNC: "Data synchronized successfully"; }; readonly ERROR: { readonly SAVE: "Failed to save data"; readonly DELETE: "Failed to delete item"; readonly UPDATE: "Failed to update data"; readonly UPLOAD: "Failed to upload file"; readonly NETWORK: "Network error occurred"; readonly UNKNOWN: "An unexpected error occurred"; readonly VALIDATION: "Validation error"; readonly UNAUTHORIZED: "Unauthorized access"; readonly SERVER: "Server error occurred"; }; readonly WARNING: { readonly UNSAVED_CHANGES: "You have unsaved changes"; readonly SESSION_EXPIRING: "Your session is about to expire"; readonly STORAGE_FULL: "Storage is running low"; readonly DEPRECATED: "This feature is deprecated"; readonly LIMIT_REACHED: "Limit reached"; }; readonly INFO: { readonly LOADING: "Loading data..."; readonly PROCESSING: "Processing request..."; readonly MAINTENANCE: "System maintenance scheduled"; readonly UPDATE_AVAILABLE: "Update available"; readonly BACKUP_COMPLETE: "Backup completed"; }; }; constructor(); setProvider(provider: NotificationProvider): void; success(props: NotificationCallProps): void | Observable<NotificationResult>; error(props: NotificationCallProps): void | Observable<NotificationResult>; warning(props: NotificationCallProps): void | Observable<NotificationResult>; info(props: NotificationCallProps): void | Observable<NotificationResult>; confirm(config: SweetAlertConfig): Observable<NotificationResult>; show(props: { type: NotificationType; } & NotificationCallProps): void | Observable<NotificationResult>; get toastr(): ToastrProvider; get snackbar(): SnackbarProvider; get sweetAlert(): SweetalertProvider; quickSave(type?: 'success' | 'error'): void; quickDelete(type?: 'success' | 'error'): void; quickUpdate(type?: 'success' | 'error'): void; networkError(): void; sessionWarning(): void; static ɵfac: i0.ɵɵFactoryDeclaration<NotificationService, never>; static ɵprov: i0.ɵɵInjectableDeclaration<NotificationService>; } declare function provideNotifications(config?: Partial<NotificationProviderConfig>, toastrConfig?: Partial<GlobalConfig>): EnvironmentProviders; export { DEFAULT_SNACKBAR_CONFIG, NOTIFICATION_CONFIG, NOTIFICATION_DURATIONS, NOTIFICATION_ICONS, NOTIFICATION_MESSAGES, NotificationProviderBase, NotificationService, SNACKBAR_CONFIG, SnackbarProvider, SweetalertProvider, TOASTR_NOTIFICATION_CONFIG, ToastrProvider, provideNotifications }; export type { BaseNotificationConfig, NotificationCallProps, NotificationPosition, NotificationProvider, NotificationProviderConfig, NotificationResult, NotificationType, SnackbarCallProps, SnackbarConfig, SnackbarProps, SweetAlertConfig, ToastrCallProps, ToastrNotificationConfig, ToastrShowProps, ToastrType };