-
Notifications
You must be signed in to change notification settings - Fork 13.5k
/
alert-controller.tsx
51 lines (45 loc) · 1.68 KB
/
alert-controller.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import { Build, Component, ComponentInterface, Method } from '@stencil/core';
import { AlertOptions, OverlayController } from '../../interface';
import { createOverlay, dismissOverlay, getOverlay } from '../../utils/overlays';
@Component({
tag: 'ion-alert-controller'
})
export class AlertController implements ComponentInterface, OverlayController {
constructor() {
if (Build.isDev) {
console.warn(`[DEPRECATED][ion-alert-controller] Use the alertController export from @ionic/core:
import { alertController } from '@ionic/core';
const alert = await alertController.create({...});`);
}
}
/**
* Create an alert overlay with alert options.
*
* @param options The options to use to create the alert.
*/
@Method()
create(options: AlertOptions): Promise<HTMLIonAlertElement> {
return createOverlay('ion-alert', options);
}
/**
* Dismiss the open alert overlay.
*
* @param data Any data to emit in the dismiss events.
* @param role The role of the element that is dismissing the alert.
* This can be useful in a button handler for determining which button was
* clicked to dismiss the alert.
* Some examples include: ``"cancel"`, `"destructive"`, "selected"`, and `"backdrop"`.
* @param id The id of the alert to dismiss. If an id is not provided, it will dismiss the most recently opened alert.
*/
@Method()
dismiss(data?: any, role?: string, id?: string) {
return dismissOverlay(document, data, role, 'ion-alert', id);
}
/**
* Get the most recently opened alert overlay.
*/
@Method()
async getTop(): Promise<HTMLIonAlertElement | undefined> {
return getOverlay(document, 'ion-alert') as HTMLIonAlertElement;
}
}