MenuBar
MenuBar is the top-of-window menu bar — File, Edit, View, etc. Construct it with a config array describing each top-level entry; the bar handles dropdown panels, keyboard navigation, and submenus internally.
Usage
typescript
import { Body } from '@jimka/typescript-ui/core';
import { MenuBar } from '@jimka/typescript-ui/component/menubar';
const bar = MenuBar([
{ label: 'File', items: [
{ text: 'New', shortcut: 'Ctrl+N', action: () => newFile() },
{ text: 'Open…', shortcut: 'Ctrl+O', action: () => openFile() },
{ separator: true },
{ text: 'Quit', enabled: false },
]},
{ label: 'Edit', items: [
{ text: 'Undo', shortcut: 'Ctrl+Z', action: () => undo() },
{ text: 'Redo', shortcut: 'Ctrl+Y', action: () => redo() },
]},
]);
Body.getInstance().addComponent(bar);Config shape
The config is MenuConfig[] (see MenuConfig).
Each entry has:
label— bar button text.glyph(optional) — registryGlyphname displayed to the left of the bar button's label (e.g."file","pen-to-square","eye","info-circle").items— array ofMenuItemConfigentries.
Each MenuItemConfig supports:
| Field | Purpose |
|---|---|
text | Display label. |
action | Called when the item is activated (click or Enter). |
enabled | Defaults to true. Disabled items are dimmed. |
shortcut | Hint string displayed on the right (e.g. "Ctrl+S"). |
glyph | Registry Glyph name displayed on the left. Takes precedence over icon when both are set. |
icon | Legacy single-character icon displayed on the left. Prefer glyph. |
submenu | Nested MenuConfig; opens a child panel instead of calling action. |
separator | When true, render a horizontal rule and ignore other fields. |
Notes
- The
shortcutfield is purely a visual hint — wire the actual keyboard binding yourself, e.g. viaEvent.addListener(window, 'keydown', …). - Nested
submenupanels open after a 150 ms hover delay — seeMenuItem.
See also
- API: MenuBar
- API: MenuConfig, MenuItemConfig
Menu— the dropdown panel (also handles right-click context menus)