popover-controller.js 5.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. import { Injectable } from '@angular/core';
  2. import { App } from '../app/app';
  3. import { Config } from '../../config/config';
  4. import { Popover } from './popover';
  5. import { DeepLinker } from '../../navigation/deep-linker';
  6. /**
  7. * @name PopoverController
  8. * @description
  9. * A Popover is a dialog that appears on top of the current page.
  10. * It can be used for anything, but generally it is used for overflow
  11. * actions that don't fit in the navigation bar.
  12. *
  13. * ### Creating
  14. * A popover can be created by calling the `create` method. The view
  15. * to display in the popover should be passed as the first argument.
  16. * Any data to pass to the popover view can optionally be passed in
  17. * the second argument. Options for the popover can optionally be
  18. * passed in the third argument. See the [create](#create) method
  19. * below for all available options.
  20. *
  21. * ### Presenting
  22. * To present a popover, call the `present` method on a PopoverController instance.
  23. * In order to position the popover relative to the element clicked, a click event
  24. * needs to be passed into the options of the the `present method. If the event
  25. * is not passed, the popover will be positioned in the center of the current
  26. * view. See the [usage](#usage) section for an example of passing this event.
  27. *
  28. * ### Dismissing
  29. * To dismiss the popover after creation, call the `dismiss()` method on the
  30. * `Popover` instance. The popover can also be dismissed from within the popover's
  31. * view by calling the `dismiss()` method on the [ViewController](../../navigation/ViewController).
  32. * The `dismiss()` call accepts an optional parameter that will be passed to the callback described
  33. * as follows. The `onDidDismiss(<func>)` function can be called to set up a callback action that will
  34. * be performed after the popover is dismissed, receiving the parameter passed to `dismiss()`.
  35. * The popover will dismiss when the backdrop is clicked by implicitly performing `dismiss(null)`,
  36. * but this can be disabled by setting `enableBackdropDismiss` to `false` in the popover options.
  37. *
  38. * > Note that after the component is dismissed, it will not be usable anymore and
  39. * another one must be created. This can be avoided by wrapping the creation and
  40. * presentation of the component in a reusable function as shown in the [usage](#usage)
  41. * section below.
  42. *
  43. * @usage
  44. *
  45. * To open a popover on the click of a button, pass `$event` to the method
  46. * which creates and presents the popover:
  47. *
  48. * ```html
  49. * <button ion-button icon-only (click)="presentPopover($event)">
  50. * <ion-icon name="more"></ion-icon>
  51. * </button>
  52. * ```
  53. *
  54. * ```ts
  55. * import { PopoverController } from 'ionic-angular';
  56. *
  57. * @Component({})
  58. * class MyPage {
  59. * constructor(public popoverCtrl: PopoverController) {}
  60. *
  61. * presentPopover(myEvent) {
  62. * let popover = this.popoverCtrl.create(PopoverPage);
  63. * popover.present({
  64. * ev: myEvent
  65. * });
  66. * }
  67. * }
  68. * ```
  69. *
  70. * The `PopoverPage` will display inside of the popover, and
  71. * can be anything. Below is an example of a page with items
  72. * that close the popover on click.
  73. *
  74. * ```ts
  75. * @Component({
  76. * template: `
  77. * <ion-list>
  78. * <ion-list-header>Ionic</ion-list-header>
  79. * <button ion-item (click)="close()">Learn Ionic</button>
  80. * <button ion-item (click)="close()">Documentation</button>
  81. * <button ion-item (click)="close()">Showcase</button>
  82. * <button ion-item (click)="close()">GitHub Repo</button>
  83. * </ion-list>
  84. * `
  85. * })
  86. * class PopoverPage {
  87. * constructor(public viewCtrl: ViewController) {}
  88. *
  89. * close() {
  90. * this.viewCtrl.dismiss();
  91. * }
  92. * }
  93. * ```
  94. * @advanced
  95. * Popover Options
  96. *
  97. * | Option | Type | Description |
  98. * |-----------------------|------------|------------------------------------------------------------------------------------------------------------------|
  99. * | cssClass |`string` | Additional classes for custom styles, separated by spaces. |
  100. * | showBackdrop |`boolean` | Whether to show the backdrop. Default true. |
  101. * | enableBackdropDismiss |`boolean` | Whether the popover should be dismissed by tapping the backdrop. Default true. |
  102. *
  103. *
  104. *
  105. * @demo /docs/demos/src/popover/
  106. */
  107. export class PopoverController {
  108. constructor(_app, config, _deepLinker) {
  109. this._app = _app;
  110. this.config = config;
  111. this._deepLinker = _deepLinker;
  112. }
  113. /**
  114. * Present a popover. See below for options
  115. * @param {object} component The Popover
  116. * @param {object} data Any data to pass to the Popover view
  117. * @param {PopoverOptions} opts Popover options
  118. */
  119. create(component, data = {}, opts = {}) {
  120. return new Popover(this._app, component, data, opts, this.config, this._deepLinker);
  121. }
  122. }
  123. PopoverController.decorators = [
  124. { type: Injectable },
  125. ];
  126. /** @nocollapse */
  127. PopoverController.ctorParameters = () => [
  128. { type: App, },
  129. { type: Config, },
  130. { type: DeepLinker, },
  131. ];
  132. //# sourceMappingURL=popover-controller.js.map