UNPKG

6.29 kBTypeScriptView Raw
1import { EventEmitter, OnChanges, OnDestroy, SimpleChanges } from '@angular/core';
2import Swal, { SweetAlertOptions } from 'sweetalert2';
3import * as events from './swal-events';
4/**
5 * <swal> component. See the README.md for usage.
6 *
7 * It contains a bunch of @Inputs that have a perfect 1:1 mapping with SweetAlert2 options.
8 * Their types are directly coming from SweetAlert2 types defintitions, meaning that ngx-sweetalert2 is tightly coupled
9 * to SweetAlert2, but also is type-safe.
10 *
11 * /!\ Some SweetAlert options aren't @Inputs but @Outputs: onBeforeOpen, onOpen, and onClose (without "on*" prefix).
12 * However, preConfirm and inputValidtor are still @Inputs because there are not event handlers, there can't be
13 * multiple listeners and we need the Promise they must return.
14 *
15 * /!\ You can notice that the SweetAlert2 `useRejections` and `expectRejections` are the only one to not have
16 * an @Input(). That's because they are deprecated and not using the default value of these parameters leads to
17 * clunky control flow. They are supported (use [options]="{}"), but please don't use them.
18 */
19export declare class SwalComponent implements OnChanges, OnDestroy {
20 private readonly defaultSwalOptions;
21 title: SweetAlertOptions['title'];
22 titleText: SweetAlertOptions['titleText'];
23 text: SweetAlertOptions['text'];
24 html: SweetAlertOptions['html'];
25 footer: SweetAlertOptions['footer'];
26 type: SweetAlertOptions['type'];
27 backdrop: SweetAlertOptions['backdrop'];
28 toast: SweetAlertOptions['toast'];
29 target: SweetAlertOptions['target'];
30 input: SweetAlertOptions['input'];
31 width: SweetAlertOptions['width'];
32 padding: SweetAlertOptions['padding'];
33 background: SweetAlertOptions['background'];
34 position: SweetAlertOptions['position'];
35 grow: SweetAlertOptions['grow'];
36 customClass: SweetAlertOptions['customClass'];
37 timer: SweetAlertOptions['timer'];
38 animation: SweetAlertOptions['animation'];
39 allowOutsideClick: SweetAlertOptions['allowOutsideClick'];
40 allowEscapeKey: SweetAlertOptions['allowEscapeKey'];
41 allowEnterKey: SweetAlertOptions['allowEnterKey'];
42 showConfirmButton: SweetAlertOptions['showConfirmButton'];
43 showCancelButton: SweetAlertOptions['showCancelButton'];
44 confirmButtonText: SweetAlertOptions['confirmButtonText'];
45 cancelButtonText: SweetAlertOptions['cancelButtonText'];
46 confirmButtonColor: SweetAlertOptions['confirmButtonColor'];
47 cancelButtonColor: SweetAlertOptions['cancelButtonColor'];
48 confirmButtonClass: SweetAlertOptions['confirmButtonClass'];
49 cancelButtonClass: SweetAlertOptions['cancelButtonClass'];
50 confirmButtonAriaLabel: SweetAlertOptions['confirmButtonAriaLabel'];
51 cancelButtonAriaLabel: SweetAlertOptions['cancelButtonAriaLabel'];
52 buttonsStyling: SweetAlertOptions['buttonsStyling'];
53 reverseButtons: SweetAlertOptions['reverseButtons'];
54 focusConfirm: SweetAlertOptions['focusConfirm'];
55 focusCancel: SweetAlertOptions['focusCancel'];
56 showCloseButton: SweetAlertOptions['showCloseButton'];
57 closeButtonAriaLabel: SweetAlertOptions['closeButtonAriaLabel'];
58 showLoaderOnConfirm: SweetAlertOptions['showLoaderOnConfirm'];
59 preConfirm: SweetAlertOptions['preConfirm'];
60 imageUrl: SweetAlertOptions['imageUrl'];
61 imageWidth: SweetAlertOptions['imageWidth'];
62 imageHeight: SweetAlertOptions['imageHeight'];
63 imageAlt: SweetAlertOptions['imageAlt'];
64 imageClass: SweetAlertOptions['imageClass'];
65 inputPlaceholder: SweetAlertOptions['inputPlaceholder'];
66 inputValue: SweetAlertOptions['inputValue'];
67 inputOptions: SweetAlertOptions['inputOptions'];
68 inputAutoTrim: SweetAlertOptions['inputAutoTrim'];
69 inputAttributes: SweetAlertOptions['inputAttributes'];
70 inputValidator: SweetAlertOptions['inputValidator'];
71 inputClass: SweetAlertOptions['inputClass'];
72 progressSteps: SweetAlertOptions['progressSteps'];
73 currentProgressStep: SweetAlertOptions['currentProgressStep'];
74 progressStepsDistance: SweetAlertOptions['progressStepsDistance'];
75 /**
76 * Emits a BeforeOpenEvent when the modal DOM element has been created.
77 * Useful to perform DOM mutations before the modal is shown.
78 */
79 readonly beforeOpen: EventEmitter<events.BeforeOpenEvent>;
80 /**
81 * Emits an OpenEvent when the modal is shown.
82 */
83 readonly open: EventEmitter<events.OpenEvent>;
84 /**
85 * Emits a CloseEvent when modal get closed.
86 */
87 readonly close: EventEmitter<events.CloseEvent>;
88 /**
89 * Emits when the user clicks "Confirm".
90 * Bears a value when using "input", resolved "preConfirm", etc.
91 *
92 * Example:
93 * public handleConfirm(email: string): void {
94 * // ... save user email
95 * }
96 */
97 readonly confirm: EventEmitter<any>;
98 /**
99 * Emits when the user clicks "Cancel" (or dismisses the modal by any other way).
100 * By default, it will emit a string representing the reason for which the SweetAlert has been closed, or the
101 * value of a rejected "preConfirm".
102 *
103 * Example:
104 * public handleCancel(reason: string): void {
105 * // reason can be 'cancel', 'overlay', 'close', and 'timer'
106 * // ... do something
107 * }
108 */
109 readonly cancel: EventEmitter<any>;
110 /**
111 * An object of SweetAlert2 native options, useful if:
112 * - you don't want to use the @Inputs for practical/philosophical reasons ;
113 * - there are missing @Inputs because ngx-sweetalert2 isn't up-to-date with SweetAlert2's latest changes.
114 *
115 * /!\ Be aware that the options defined in this object will override the @Inputs of the same name.
116 */
117 options: SweetAlertOptions;
118 nativeSwal: typeof Swal;
119 private isCurrentlyShown;
120 private readonly touchedProps;
121 private readonly markTouched;
122 constructor(defaultSwalOptions: SweetAlertOptions);
123 ngOnChanges(changes: SimpleChanges): void;
124 ngOnDestroy(): void;
125 /**
126 * Shows the SweetAlert.
127 *
128 * Returns the SweetAlert2 promise for convenience and use in code behind templates.
129 * Otherwise, (confirm)="myHandler($event)" and (cancel)="myHandler($event)" can be used in templates.
130 */
131 show(): Promise<any>;
132}