mirror of
https://github.com/ionic-team/ionic-framework.git
synced 2025-08-20 04:14:21 +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);
|
||||
}
|
||||
}
|
||||
39
core/src/components/alert-controller/readme.md
Normal file
39
core/src/components/alert-controller/readme.md
Normal file
@ -0,0 +1,39 @@
|
||||
# ion-alert-controller
|
||||
|
||||
Alert controllers programmatically control the alert component. Alerts can be created and dismissed from the alert controller. View the [Alert](../../alert/Alert) documentation for a full list of options to pass upon creation.
|
||||
|
||||
|
||||
```javascript
|
||||
async function presentAlert() {
|
||||
const alertController = document.querySelector('ion-alert-controller');
|
||||
await alertController.componentOnReady();
|
||||
|
||||
const alert = await alertController.create({
|
||||
title: 'Alert',
|
||||
subTitle: 'Subtitle',
|
||||
message: 'This is an alert message.',
|
||||
buttons: ['OK']
|
||||
});
|
||||
return await alert.present();
|
||||
}
|
||||
```
|
||||
|
||||
|
||||
<!-- Auto Generated Below -->
|
||||
|
||||
|
||||
## Methods
|
||||
|
||||
#### create()
|
||||
|
||||
|
||||
#### dismiss()
|
||||
|
||||
|
||||
#### getTop()
|
||||
|
||||
|
||||
|
||||
----------------------------------------------
|
||||
|
||||
*Built with [StencilJS](https://stenciljs.com/)*
|
||||
Reference in New Issue
Block a user