mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-22 13:32:54 +08:00
chore(packages): move the packages to root
This commit is contained in:
51
core/src/components/alert-controller/alert-controller.tsx
Normal file
51
core/src/components/alert-controller/alert-controller.tsx
Normal file
@ -0,0 +1,51 @@
|
||||
import { Component, Listen, Method } from '@stencil/core';
|
||||
import { AlertEvent, AlertOptions, OverlayController } from '../../index';
|
||||
import { createOverlay, dismissOverlay, getTopOverlay, removeLastOverlay } from '../../utils/overlays';
|
||||
|
||||
@Component({
|
||||
tag: 'ion-alert-controller'
|
||||
})
|
||||
export class AlertController implements OverlayController {
|
||||
|
||||
private alerts = new Map<number, HTMLIonAlertElement>();
|
||||
|
||||
@Listen('body:ionAlertWillPresent')
|
||||
protected alertWillPresent(ev: AlertEvent) {
|
||||
this.alerts.set(ev.target.overlayId, ev.target);
|
||||
}
|
||||
|
||||
@Listen('body:ionAlertWillDismiss')
|
||||
@Listen('body:ionAlertDidUnload')
|
||||
protected alertWillDismiss(ev: AlertEvent) {
|
||||
this.alerts.delete(ev.target.overlayId);
|
||||
}
|
||||
|
||||
@Listen('body:keyup.escape')
|
||||
protected escapeKeyUp() {
|
||||
removeLastOverlay(this.alerts);
|
||||
}
|
||||
|
||||
/*
|
||||
* Create an alert overlay with alert options.
|
||||
*/
|
||||
@Method()
|
||||
create(opts?: AlertOptions): Promise<HTMLIonAlertElement> {
|
||||
return createOverlay(document.createElement('ion-alert'), opts);
|
||||
}
|
||||
|
||||
/*
|
||||
* Dismiss the open alert overlay.
|
||||
*/
|
||||
@Method()
|
||||
dismiss(data?: any, role?: string, alertId = -1) {
|
||||
return dismissOverlay(data, role, this.alerts, alertId);
|
||||
}
|
||||
|
||||
/*
|
||||
* Get the most recently opened alert overlay.
|
||||
*/
|
||||
@Method()
|
||||
getTop(): HTMLIonAlertElement {
|
||||
return getTopOverlay(this.alerts);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user