UNPKG

9.48 kBTypeScriptView Raw
1import { Message } from '@lumino/messaging';
2import { ElementARIAAttrs, ElementDataset, h, VirtualElement } from '@lumino/virtualdom';
3import { Menu } from './menu';
4import { Title } from './title';
5import { Widget } from './widget';
6/**
7 * A widget which displays menus as a canonical menu bar.
8 */
9export declare class MenuBar extends Widget {
10 /**
11 * Construct a new menu bar.
12 *
13 * @param options - The options for initializing the menu bar.
14 */
15 constructor(options?: MenuBar.IOptions);
16 /**
17 * Dispose of the resources held by the widget.
18 */
19 dispose(): void;
20 /**
21 * The renderer used by the menu bar.
22 */
23 readonly renderer: MenuBar.IRenderer;
24 /**
25 * The child menu of the menu bar.
26 *
27 * #### Notes
28 * This will be `null` if the menu bar does not have an open menu.
29 */
30 readonly childMenu: Menu | null;
31 /**
32 * Get the menu bar content node.
33 *
34 * #### Notes
35 * This is the node which holds the menu title nodes.
36 *
37 * Modifying this node directly can lead to undefined behavior.
38 */
39 readonly contentNode: HTMLUListElement;
40 /**
41 * Get the currently active menu.
42 */
43 /**
44 * Set the currently active menu.
45 *
46 * #### Notes
47 * If the menu does not exist, the menu will be set to `null`.
48 */
49 activeMenu: Menu | null;
50 /**
51 * Get the index of the currently active menu.
52 *
53 * #### Notes
54 * This will be `-1` if no menu is active.
55 */
56 /**
57 * Set the index of the currently active menu.
58 *
59 * #### Notes
60 * If the menu cannot be activated, the index will be set to `-1`.
61 */
62 activeIndex: number;
63 /**
64 * A read-only array of the menus in the menu bar.
65 */
66 readonly menus: ReadonlyArray<Menu>;
67 /**
68 * Open the active menu and activate its first menu item.
69 *
70 * #### Notes
71 * If there is no active menu, this is a no-op.
72 */
73 openActiveMenu(): void;
74 /**
75 * Add a menu to the end of the menu bar.
76 *
77 * @param menu - The menu to add to the menu bar.
78 *
79 * #### Notes
80 * If the menu is already added to the menu bar, it will be moved.
81 */
82 addMenu(menu: Menu): void;
83 /**
84 * Insert a menu into the menu bar at the specified index.
85 *
86 * @param index - The index at which to insert the menu.
87 *
88 * @param menu - The menu to insert into the menu bar.
89 *
90 * #### Notes
91 * The index will be clamped to the bounds of the menus.
92 *
93 * If the menu is already added to the menu bar, it will be moved.
94 */
95 insertMenu(index: number, menu: Menu): void;
96 /**
97 * Remove a menu from the menu bar.
98 *
99 * @param menu - The menu to remove from the menu bar.
100 *
101 * #### Notes
102 * This is a no-op if the menu is not in the menu bar.
103 */
104 removeMenu(menu: Menu): void;
105 /**
106 * Remove the menu at a given index from the menu bar.
107 *
108 * @param index - The index of the menu to remove.
109 *
110 * #### Notes
111 * This is a no-op if the index is out of range.
112 */
113 removeMenuAt(index: number): void;
114 /**
115 * Remove all menus from the menu bar.
116 */
117 clearMenus(): void;
118 /**
119 * Handle the DOM events for the menu bar.
120 *
121 * @param event - The DOM event sent to the menu bar.
122 *
123 * #### Notes
124 * This method implements the DOM `EventListener` interface and is
125 * called in response to events on the menu bar's DOM nodes. It
126 * should not be called directly by user code.
127 */
128 handleEvent(event: Event): void;
129 /**
130 * A message handler invoked on a `'before-attach'` message.
131 */
132 protected onBeforeAttach(msg: Message): void;
133 /**
134 * A message handler invoked on an `'after-detach'` message.
135 */
136 protected onAfterDetach(msg: Message): void;
137 /**
138 * A message handler invoked on an `'activate-request'` message.
139 */
140 protected onActivateRequest(msg: Message): void;
141 /**
142 * A message handler invoked on an `'update-request'` message.
143 */
144 protected onUpdateRequest(msg: Message): void;
145 /**
146 * Handle the `'keydown'` event for the menu bar.
147 */
148 private _evtKeyDown;
149 /**
150 * Handle the `'mousedown'` event for the menu bar.
151 */
152 private _evtMouseDown;
153 /**
154 * Handle the `'mousemove'` event for the menu bar.
155 */
156 private _evtMouseMove;
157 /**
158 * Handle the `'mouseleave'` event for the menu bar.
159 */
160 private _evtMouseLeave;
161 /**
162 * Open the child menu at the active index immediately.
163 *
164 * If a different child menu is already open, it will be closed,
165 * even if there is no active menu.
166 */
167 private _openChildMenu;
168 /**
169 * Close the child menu immediately.
170 *
171 * This is a no-op if a child menu is not open.
172 */
173 private _closeChildMenu;
174 /**
175 * Handle the `aboutToClose` signal of a menu.
176 */
177 private _onMenuAboutToClose;
178 /**
179 * Handle the `menuRequested` signal of a child menu.
180 */
181 private _onMenuMenuRequested;
182 /**
183 * Handle the `changed` signal of a title object.
184 */
185 private _onTitleChanged;
186 private _activeIndex;
187 private _forceItemsPosition;
188 private _menus;
189 private _childMenu;
190}
191/**
192 * The namespace for the `MenuBar` class statics.
193 */
194export declare namespace MenuBar {
195 /**
196 * An options object for creating a menu bar.
197 */
198 interface IOptions {
199 /**
200 * A custom renderer for creating menu bar content.
201 *
202 * The default is a shared renderer instance.
203 */
204 renderer?: IRenderer;
205 /**
206 * Whether to force the position of the menu. The MenuBar forces the
207 * coordinates of its menus by default. With this option you can disable it.
208 *
209 * Setting to `false` will enable the logic which repositions the
210 * coordinates of the menu if it will not fit entirely on screen.
211 *
212 * The default is `true`.
213 */
214 forceItemsPosition?: Menu.IOpenOptions;
215 }
216 /**
217 * An object which holds the data to render a menu bar item.
218 */
219 interface IRenderData {
220 /**
221 * The title to be rendered.
222 */
223 readonly title: Title<Widget>;
224 /**
225 * Whether the item is the active item.
226 */
227 readonly active: boolean;
228 readonly onfocus?: (event: FocusEvent) => void;
229 }
230 /**
231 * A renderer for use with a menu bar.
232 */
233 interface IRenderer {
234 /**
235 * Render the virtual element for a menu bar item.
236 *
237 * @param data - The data to use for rendering the item.
238 *
239 * @returns A virtual element representing the item.
240 */
241 renderItem(data: IRenderData): VirtualElement;
242 }
243 /**
244 * The default implementation of `IRenderer`.
245 *
246 * #### Notes
247 * Subclasses are free to reimplement rendering methods as needed.
248 */
249 class Renderer implements IRenderer {
250 /**
251 * Render the virtual element for a menu bar item.
252 *
253 * @param data - The data to use for rendering the item.
254 *
255 * @returns A virtual element representing the item.
256 */
257 renderItem(data: IRenderData): VirtualElement;
258 /**
259 * Render the icon element for a menu bar item.
260 *
261 * @param data - The data to use for rendering the icon.
262 *
263 * @returns A virtual element representing the item icon.
264 */
265 renderIcon(data: IRenderData): VirtualElement;
266 /**
267 * Render the label element for a menu item.
268 *
269 * @param data - The data to use for rendering the label.
270 *
271 * @returns A virtual element representing the item label.
272 */
273 renderLabel(data: IRenderData): VirtualElement;
274 /**
275 * Create the class name for the menu bar item.
276 *
277 * @param data - The data to use for the class name.
278 *
279 * @returns The full class name for the menu item.
280 */
281 createItemClass(data: IRenderData): string;
282 /**
283 * Create the dataset for a menu bar item.
284 *
285 * @param data - The data to use for the item.
286 *
287 * @returns The dataset for the menu bar item.
288 */
289 createItemDataset(data: IRenderData): ElementDataset;
290 /**
291 * Create the aria attributes for menu bar item.
292 *
293 * @param data - The data to use for the aria attributes.
294 *
295 * @returns The aria attributes object for the item.
296 */
297 createItemARIA(data: IRenderData): ElementARIAAttrs;
298 /**
299 * Create the class name for the menu bar item icon.
300 *
301 * @param data - The data to use for the class name.
302 *
303 * @returns The full class name for the item icon.
304 */
305 createIconClass(data: IRenderData): string;
306 /**
307 * Create the render content for the label node.
308 *
309 * @param data - The data to use for the label content.
310 *
311 * @returns The content to add to the label node.
312 */
313 formatLabel(data: IRenderData): h.Child;
314 }
315 /**
316 * The default `Renderer` instance.
317 */
318 const defaultRenderer: Renderer;
319}
320//# sourceMappingURL=menubar.d.ts.map
\No newline at end of file