docs(modal): modals docs

This commit is contained in:
Adam Bradley
2015-12-31 22:29:37 -06:00
parent 671d72b153
commit 29399ffa82

View File

@ -1,17 +1,16 @@
import {NavController, NavParams} from '../nav/nav-controller';
import {ViewController} from '../nav/view-controller'; import {ViewController} from '../nav/view-controller';
import {Config} from '../../config/config';
import {Animation} from '../../animations/animation'; import {Animation} from '../../animations/animation';
/** /**
* @name Modal * @name Modal
* @description * @description
* The Modal is a content pane that can go over the user's current page. * A Modal is a content pane that goes over the user's current page.
* Usually it is used for making a choice or editing an item. A modal uses the * Usually it is used for making a choice or editing an item. A modal uses the
* `NavController` to "present" itself in the root nav stack. It is added to the * `NavController` to
* stack similar to how * {@link /docs/v2/api/components/nav/NavController/#present NavController.present}
* itself in the root nav stack. It is added to the stack similar to how
* {@link /docs/v2/api/components/nav/NavController/#push NavController.push} * {@link /docs/v2/api/components/nav/NavController/#push NavController.push}
* works, where it is passed a Page component, along with optional Page params * works.
* *
* When a modal (or any other overlay such as an alert or actionsheet) is * When a modal (or any other overlay such as an alert or actionsheet) is
* "presented" to a nav controller, the overlay is added to the app's root nav. * "presented" to a nav controller, the overlay is added to the app's root nav.
@ -22,15 +21,15 @@ import {Animation} from '../../animations/animation';
* *
* A modal can also emit data, which is useful when it is used to add or edit * A modal can also emit data, which is useful when it is used to add or edit
* data. For example, a profile page could slide up in a modal, and on submit, * data. For example, a profile page could slide up in a modal, and on submit,
* the submit button could emit the updated profile data, then dismiss the modal. * the submit button could pass the updated profile data, then dismiss the
* From that point, anything which is subscribed to the modal's `data` event * modal.
* would receive the modal's data.
* *
* @usage * @usage
* ```ts * ```ts
* import {Modal, NavController} from 'ionic/ionic'; * import {Modal, NavController} from 'ionic/ionic';
* *
* class MyApp { * @Page(...)
* class HomePage {
* *
* constructor(nav: NavController) { * constructor(nav: NavController) {
* this.nav = nav; * this.nav = nav;
@ -43,12 +42,24 @@ import {Animation} from '../../animations/animation';
* *
* presentProfileModal() { * presentProfileModal() {
* let profileModal = Modal.create(Profile, { userId: 8675309 }); * let profileModal = Modal.create(Profile, { userId: 8675309 });
* this.nav.present(profileModal, { * profileModal.onDismiss(data => {
* animation: 'my-fade-in'
* });
* profileModal.data.subscribe(data => {
* console.log(data); * console.log(data);
* }); * });
* this.nav.present(profileModal);
* }
*
* }
*
* @Page(...)
* class Profile {
*
* constructor(viewCtrl: ViewController) {
* this.viewCtrl = viewCtrl;
* }
*
* dismiss() {
* let data = { 'foo': 'bar' };
* this.viewCtrl.dismiss(data);
* } * }
* *
* } * }
@ -63,11 +74,18 @@ export class Modal extends ViewController {
this.viewType = 'modal'; this.viewType = 'modal';
} }
/**
* @private
*/
getTransitionName(direction) { getTransitionName(direction) {
let key = (direction === 'back' ? 'modalLeave' : 'modalEnter'); let key = (direction === 'back' ? 'modalLeave' : 'modalEnter');
return this._nav && this._nav.config.get(key); return this._nav && this._nav.config.get(key);
} }
/**
* @param {Any} componentType Modal
* @param {Object} data Modal options
*/
static create(componentType, data={}) { static create(componentType, data={}) {
return new Modal(componentType, data); return new Modal(componentType, data);
} }