UNPKG

6.97 kBTypeScriptView Raw
1import { Menu, MenuType } from './menu-interface';
2import { Platform } from '../../platform/platform';
3/**
4 * @name MenuController
5 * @description
6 * The MenuController is a provider which makes it easy to control a [Menu](../../menu/Menu/).
7 * Its methods can be used to display the menu, enable the menu, toggle the menu, and more.
8 * The controller will grab a reference to the menu by the `side`, `id`, or, if neither
9 * of these are passed to it, it will grab the first menu it finds.
10 *
11 *
12 * @usage
13 *
14 * Add a basic menu component to start with. See the [Menu](../../menu/Menu/) API docs
15 * for more information on adding menu components.
16 *
17 * ```html
18 * <ion-menu [content]="mycontent">
19 * <ion-content>
20 * <ion-list>
21 * ...
22 * </ion-list>
23 * </ion-content>
24 * </ion-menu>
25 *
26 * <ion-nav #mycontent [root]="rootPage"></ion-nav>
27 * ```
28 *
29 * To call the controller methods, inject the `MenuController` provider
30 * into the page. Then, create some methods for opening, closing, and
31 * toggling the menu.
32 *
33 * ```ts
34 * import { Component } from '@angular/core';
35 * import { MenuController } from 'ionic-angular';
36 *
37 * @Component({...})
38 * export class MyPage {
39 *
40 * constructor(public menuCtrl: MenuController) {
41 *
42 * }
43 *
44 * openMenu() {
45 * this.menuCtrl.open();
46 * }
47 *
48 * closeMenu() {
49 * this.menuCtrl.close();
50 * }
51 *
52 * toggleMenu() {
53 * this.menuCtrl.toggle();
54 * }
55 *
56 * }
57 * ```
58 *
59 * Since only one menu exists, the `MenuController` will grab the
60 * correct menu and call the correct method for each.
61 *
62 *
63 * ### Multiple Menus on Different Sides
64 *
65 * For applications with both a left and right menu, the desired menu can be
66 * grabbed by passing the `side` of the menu. If nothing is passed, it will
67 * default to the `"left"` menu.
68 *
69 * ```html
70 * <ion-menu side="left" [content]="mycontent">...</ion-menu>
71 * <ion-menu side="right" [content]="mycontent">...</ion-menu>
72 * <ion-nav #mycontent [root]="rootPage"></ion-nav>
73 * ```
74 *
75 * ```ts
76 * toggleLeftMenu() {
77 * this.menuCtrl.toggle();
78 * }
79 *
80 * toggleRightMenu() {
81 * this.menuCtrl.toggle('right');
82 * }
83 * ```
84 *
85 *
86 * ### Multiple Menus on the Same Side
87 *
88 * An application can have multiple menus on the same side. In order to determine
89 * the menu to control, an `id` should be passed. In the example below, the menu
90 * with the `authenticated` id will be enabled, and the menu with the `unauthenticated`
91 * id will be disabled.
92 *
93 * ```html
94 * <ion-menu id="authenticated" side="left" [content]="mycontent">...</ion-menu>
95 * <ion-menu id="unauthenticated" side="left" [content]="mycontent">...</ion-menu>
96 * <ion-nav #mycontent [root]="rootPage"></ion-nav>
97 * ```
98 *
99 * ```ts
100 * enableAuthenticatedMenu() {
101 * this.menuCtrl.enable(true, 'authenticated');
102 * this.menuCtrl.enable(false, 'unauthenticated');
103 * }
104 * ```
105 *
106 * Note: if an app only has one menu, there is no reason to pass an `id`.
107 *
108 *
109 * @demo /docs/demos/src/menu/
110 *
111 * @see {@link /docs/components#menus Menu Component Docs}
112 * @see {@link /docs/api/components/menu/Menu/ Menu API Docs}
113 *
114 */
115export declare class MenuController {
116 private _menus;
117 /**
118 * Programatically open the Menu.
119 * @param {string} [menuId] Optionally get the menu by its id, or side.
120 * @return {Promise} returns a promise when the menu is fully opened
121 */
122 open(menuId?: string): Promise<boolean>;
123 /**
124 * Programatically close the Menu. If no `menuId` is given as the first
125 * argument then it'll close any menu which is open. If a `menuId`
126 * is given then it'll close that exact menu.
127 * @param {string} [menuId] Optionally get the menu by its id, or side.
128 * @return {Promise} returns a promise when the menu is fully closed
129 */
130 close(menuId?: string): Promise<boolean>;
131 /**
132 * Toggle the menu. If it's closed, it will open, and if opened, it
133 * will close.
134 * @param {string} [menuId] Optionally get the menu by its id, or side.
135 * @return {Promise} returns a promise when the menu has been toggled
136 */
137 toggle(menuId?: string): Promise<boolean>;
138 /**
139 * Used to enable or disable a menu. For example, there could be multiple
140 * left menus, but only one of them should be able to be opened at the same
141 * time. If there are multiple menus on the same side, then enabling one menu
142 * will also automatically disable all the others that are on the same side.
143 * @param {string} [menuId] Optionally get the menu by its id, or side.
144 * @return {Menu} Returns the instance of the menu, which is useful for chaining.
145 */
146 enable(shouldEnable: boolean, menuId?: string): Menu;
147 /**
148 * Used to enable or disable the ability to swipe open the menu.
149 * @param {boolean} shouldEnable True if it should be swipe-able, false if not.
150 * @param {string} [menuId] Optionally get the menu by its id, or side.
151 * @return {Menu} Returns the instance of the menu, which is useful for chaining.
152 */
153 swipeEnable(shouldEnable: boolean, menuId?: string): Menu;
154 /**
155 * @param {string} [menuId] Optionally get the menu by its id, or side.
156 * @return {boolean} Returns true if the specified menu is currently open, otherwise false.
157 * If the menuId is not specified, it returns true if ANY menu is currenly open.
158 */
159 isOpen(menuId?: string): boolean;
160 /**
161 * @param {string} [menuId] Optionally get the menu by its id, or side.
162 * @return {boolean} Returns true if the menu is currently enabled, otherwise false.
163 */
164 isEnabled(menuId?: string): boolean;
165 /**
166 * Used to get a menu instance. If a `menuId` is not provided then it'll
167 * return the first menu found. If a `menuId` is `left` or `right`, then
168 * it'll return the enabled menu on that side. Otherwise, if a `menuId` is
169 * provided, then it'll try to find the menu using the menu's `id`
170 * property. If a menu is not found then it'll return `null`.
171 * @param {string} [menuId] Optionally get the menu by its id, or side.
172 * @return {Menu} Returns the instance of the menu if found, otherwise `null`.
173 */
174 get(menuId?: string): Menu;
175 /**
176 * @return {Menu} Returns the instance of the menu already opened, otherwise `null`.
177 */
178 getOpen(): Menu;
179 /**
180 * @return {Array<Menu>} Returns an array of all menu instances.
181 */
182 getMenus(): Array<Menu>;
183 /**
184 * @hidden
185 * @return {boolean} if any menu is currently animating
186 */
187 isAnimating(): boolean;
188 /**
189 * @hidden
190 */
191 _register(menu: Menu): void;
192 /**
193 * @hidden
194 */
195 _unregister(menu: Menu): void;
196 /**
197 * @hidden
198 */
199 _setActiveMenu(menu: Menu): void;
200 /**
201 * @hidden
202 */
203 static registerType(name: string, cls: new (...args: any[]) => MenuType): void;
204 /**
205 * @hidden
206 */
207 static create(type: string, menuCmp: Menu, plt: Platform): MenuType;
208}