UNPKG

10 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 * #### Notes
149 * All keys are trapped except the tab key that is ignored.
150 */
151 private _evtKeyDown;
152 /**
153 * Handle the `'mousedown'` event for the menu bar.
154 */
155 private _evtMouseDown;
156 /**
157 * Handle the `'mousemove'` event for the menu bar.
158 */
159 private _evtMouseMove;
160 /**
161 * Find initial position for the menu based on menubar item position.
162 *
163 * NOTE: this should be called before updating active index to avoid
164 * an additional layout and style invalidation as changing active
165 * index modifies DOM.
166 */
167 private _positionForMenu;
168 /**
169 * Handle the `'mouseleave'` event for the menu bar.
170 */
171 private _evtMouseLeave;
172 /**
173 * Open the child menu at the active index immediately.
174 *
175 * If a different child menu is already open, it will be closed,
176 * even if there is no active menu.
177 */
178 private _openChildMenu;
179 /**
180 * Close the child menu immediately.
181 *
182 * This is a no-op if a child menu is not open.
183 */
184 private _closeChildMenu;
185 /**
186 * Handle the `aboutToClose` signal of a menu.
187 */
188 private _onMenuAboutToClose;
189 /**
190 * Handle the `menuRequested` signal of a child menu.
191 */
192 private _onMenuMenuRequested;
193 /**
194 * Handle the `changed` signal of a title object.
195 */
196 private _onTitleChanged;
197 private _activeIndex;
198 private _tabFocusIndex;
199 private _forceItemsPosition;
200 private _menus;
201 private _childMenu;
202}
203/**
204 * The namespace for the `MenuBar` class statics.
205 */
206export declare namespace MenuBar {
207 /**
208 * An options object for creating a menu bar.
209 */
210 interface IOptions {
211 /**
212 * A custom renderer for creating menu bar content.
213 *
214 * The default is a shared renderer instance.
215 */
216 renderer?: IRenderer;
217 /**
218 * Whether to force the position of the menu. The MenuBar forces the
219 * coordinates of its menus by default. With this option you can disable it.
220 *
221 * Setting to `false` will enable the logic which repositions the
222 * coordinates of the menu if it will not fit entirely on screen.
223 *
224 * The default is `true`.
225 */
226 forceItemsPosition?: Menu.IOpenOptions;
227 }
228 /**
229 * An object which holds the data to render a menu bar item.
230 */
231 interface IRenderData {
232 /**
233 * The title to be rendered.
234 */
235 readonly title: Title<Widget>;
236 /**
237 * Whether the item is the active item.
238 */
239 readonly active: boolean;
240 /**
241 * Whether the user can tab to the item.
242 */
243 readonly tabbable?: boolean;
244 readonly onfocus?: (event: FocusEvent) => void;
245 }
246 /**
247 * A renderer for use with a menu bar.
248 */
249 interface 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 /**
260 * The default implementation of `IRenderer`.
261 *
262 * #### Notes
263 * Subclasses are free to reimplement rendering methods as needed.
264 */
265 class Renderer implements IRenderer {
266 /**
267 * Render the virtual element for a menu bar item.
268 *
269 * @param data - The data to use for rendering the item.
270 *
271 * @returns A virtual element representing the item.
272 */
273 renderItem(data: IRenderData): VirtualElement;
274 /**
275 * Render the icon element for a menu bar item.
276 *
277 * @param data - The data to use for rendering the icon.
278 *
279 * @returns A virtual element representing the item icon.
280 */
281 renderIcon(data: IRenderData): VirtualElement;
282 /**
283 * Render the label element for a menu item.
284 *
285 * @param data - The data to use for rendering the label.
286 *
287 * @returns A virtual element representing the item label.
288 */
289 renderLabel(data: IRenderData): VirtualElement;
290 /**
291 * Create the class name for the menu bar item.
292 *
293 * @param data - The data to use for the class name.
294 *
295 * @returns The full class name for the menu item.
296 */
297 createItemClass(data: IRenderData): string;
298 /**
299 * Create the dataset for a menu bar item.
300 *
301 * @param data - The data to use for the item.
302 *
303 * @returns The dataset for the menu bar item.
304 */
305 createItemDataset(data: IRenderData): ElementDataset;
306 /**
307 * Create the aria attributes for menu bar item.
308 *
309 * @param data - The data to use for the aria attributes.
310 *
311 * @returns The aria attributes object for the item.
312 */
313 createItemARIA(data: IRenderData): ElementARIAAttrs;
314 /**
315 * Create the class name for the menu bar item icon.
316 *
317 * @param data - The data to use for the class name.
318 *
319 * @returns The full class name for the item icon.
320 */
321 createIconClass(data: IRenderData): string;
322 /**
323 * Create the render content for the label node.
324 *
325 * @param data - The data to use for the label content.
326 *
327 * @returns The content to add to the label node.
328 */
329 formatLabel(data: IRenderData): h.Child;
330 }
331 /**
332 * The default `Renderer` instance.
333 */
334 const defaultRenderer: Renderer;
335}
336//# sourceMappingURL=menubar.d.ts.map
\No newline at end of file