UNPKG

3.47 kBTypeScriptView Raw
1import { ComponentRef, Injector, NgZone } from '@angular/core';
2import { DomSanitizer } from '@angular/platform-browser';
3import { Observable } from 'rxjs';
4import { Overlay } from '../overlay/overlay';
5import { ToastRef } from './toast-ref';
6import { ToastContainerDirective } from './toast.directive';
7import { GlobalConfig, IndividualConfig, ToastToken } from './toastr-config';
8import * as i0 from "@angular/core";
9export interface ActiveToast<C> {
10 /** Your Toast ID. Use this to close it individually */
11 toastId: number;
12 /** the title of your toast. Stored to prevent duplicates */
13 title: string;
14 /** the message of your toast. Stored to prevent duplicates */
15 message: string;
16 /** a reference to the component see portal.ts */
17 portal: ComponentRef<C>;
18 /** a reference to your toast */
19 toastRef: ToastRef<C>;
20 /** triggered when toast is active */
21 onShown: Observable<void>;
22 /** triggered when toast is destroyed */
23 onHidden: Observable<void>;
24 /** triggered on toast click */
25 onTap: Observable<void>;
26 /** available for your use in custom toast */
27 onAction: Observable<any>;
28}
29export declare class ToastrService {
30 private overlay;
31 private _injector;
32 private sanitizer;
33 private ngZone;
34 toastrConfig: GlobalConfig;
35 currentlyActive: number;
36 toasts: ActiveToast<any>[];
37 overlayContainer?: ToastContainerDirective;
38 previousToastMessage: string | undefined;
39 private index;
40 constructor(token: ToastToken, overlay: Overlay, _injector: Injector, sanitizer: DomSanitizer, ngZone: NgZone);
41 /** show toast */
42 show<ConfigPayload = any>(message?: string, title?: string, override?: Partial<IndividualConfig<ConfigPayload>>, type?: string): ActiveToast<any>;
43 /** show successful toast */
44 success<ConfigPayload = any>(message?: string, title?: string, override?: Partial<IndividualConfig<ConfigPayload>>): ActiveToast<any>;
45 /** show error toast */
46 error<ConfigPayload = any>(message?: string, title?: string, override?: Partial<IndividualConfig<ConfigPayload>>): ActiveToast<any>;
47 /** show info toast */
48 info<ConfigPayload = any>(message?: string, title?: string, override?: Partial<IndividualConfig<ConfigPayload>>): ActiveToast<any>;
49 /** show warning toast */
50 warning<ConfigPayload = any>(message?: string, title?: string, override?: Partial<IndividualConfig<ConfigPayload>>): ActiveToast<any>;
51 /**
52 * Remove all or a single toast by id
53 */
54 clear(toastId?: number): void;
55 /**
56 * Remove and destroy a single toast by id
57 */
58 remove(toastId: number): boolean;
59 /**
60 * Determines if toast message is already shown
61 */
62 findDuplicate(title: string, message: string, resetOnDuplicate: boolean, countDuplicates: boolean): ActiveToast<any>;
63 /** create a clone of global config and apply individual settings */
64 private applyConfig;
65 /**
66 * Find toast object by id
67 */
68 private _findToast;
69 /**
70 * Determines the need to run inside angular's zone then builds the toast
71 */
72 private _preBuildNotification;
73 /**
74 * Creates and attaches toast data to component
75 * returns the active toast, or in case preventDuplicates is enabled the original/non-duplicate active toast.
76 */
77 private _buildNotification;
78 static ɵfac: i0.ɵɵFactoryDeclaration<ToastrService, never>;
79 static ɵprov: i0.ɵɵInjectableDeclaration<ToastrService>;
80}