UNPKG

4.17 kBJavaScriptView Raw
1var __extends = (this && this.__extends) || (function () {
2 var extendStatics = Object.setPrototypeOf ||
3 ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
4 function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
5 return function (d, b) {
6 extendStatics(d, b);
7 function __() { this.constructor = d; }
8 d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
9 };
10})();
11import { isPresent } from '../../util/util';
12import { PORTAL_TOAST } from '../app/app-constants';
13import { ToastCmp } from './toast-component';
14import { ToastMdSlideIn, ToastMdSlideOut, ToastSlideIn, ToastSlideOut, ToastWpPopIn, ToastWpPopOut } from './toast-transitions';
15import { ViewController } from '../../navigation/view-controller';
16/**
17 * @hidden
18 */
19var Toast = (function (_super) {
20 __extends(Toast, _super);
21 function Toast(app, opts, config) {
22 if (opts === void 0) { opts = {}; }
23 var _this = this;
24 opts.dismissOnPageChange = isPresent(opts.dismissOnPageChange) ? !!opts.dismissOnPageChange : false;
25 _this = _super.call(this, ToastCmp, opts, null) || this;
26 _this._app = app;
27 // set the position to the bottom if not provided
28 if (!opts.position || !_this.isValidPosition(opts.position)) {
29 opts.position = TOAST_POSITION_BOTTOM;
30 }
31 _this.isOverlay = true;
32 config.setTransition('toast-slide-in', ToastSlideIn);
33 config.setTransition('toast-slide-out', ToastSlideOut);
34 config.setTransition('toast-md-slide-in', ToastMdSlideIn);
35 config.setTransition('toast-md-slide-out', ToastMdSlideOut);
36 config.setTransition('toast-wp-slide-out', ToastWpPopOut);
37 config.setTransition('toast-wp-slide-in', ToastWpPopIn);
38 return _this;
39 }
40 /**
41 * @hidden
42 */
43 Toast.prototype.getTransitionName = function (direction) {
44 var key = 'toast' + (direction === 'back' ? 'Leave' : 'Enter');
45 return this._nav && this._nav.config.get(key);
46 };
47 /**
48 * @hidden
49 */
50 Toast.prototype.isValidPosition = function (position) {
51 return position === TOAST_POSITION_TOP || position === TOAST_POSITION_MIDDLE || position === TOAST_POSITION_BOTTOM;
52 };
53 /**
54 * @param {string} message Toast message content
55 */
56 Toast.prototype.setMessage = function (message) {
57 this.data.message = message;
58 return this;
59 };
60 /**
61 * @param {number} dur Toast message duration
62 */
63 Toast.prototype.setDuration = function (dur) {
64 this.data.duration = dur;
65 return this;
66 };
67 /**
68 * @param {'top'|'middle'|'bottom'} pos Toast message position
69 */
70 Toast.prototype.setPosition = function (pos) {
71 this.data.position = pos;
72 return this;
73 };
74 /**
75 * @param {string} cssClass Toast message CSS class
76 */
77 Toast.prototype.setCssClass = function (cssClass) {
78 this.data.cssClass = cssClass;
79 return this;
80 };
81 /**
82 * @param {boolean} closeButton Toast message close button
83 */
84 Toast.prototype.setShowCloseButton = function (closeButton) {
85 this.data.showCloseButton = closeButton;
86 return this;
87 };
88 /**
89 * Present the toast instance.
90 *
91 * @param {NavOptions} [navOptions={}] Nav options to go with this transition.
92 * @returns {Promise} Returns a promise which is resolved when the transition has completed.
93 */
94 Toast.prototype.present = function (navOptions) {
95 if (navOptions === void 0) { navOptions = {}; }
96 navOptions.disableApp = false;
97 navOptions.keyboardClose = false;
98 return this._app.present(this, navOptions, PORTAL_TOAST);
99 };
100 /**
101 * Dismiss all toast components which have been presented.
102 */
103 Toast.prototype.dismissAll = function () {
104 this._nav && this._nav.popAll();
105 };
106 return Toast;
107}(ViewController));
108export { Toast };
109var TOAST_POSITION_TOP = 'top';
110var TOAST_POSITION_MIDDLE = 'middle';
111var TOAST_POSITION_BOTTOM = 'bottom';
112//# sourceMappingURL=toast.js.map
\No newline at end of file