import { MenuBar } from "@domicile-desktop/component-library/MenuBar"; import type { AppMenuEntry, AppMenuItem } from "@domicile-desktop/sdk/app-menu"; import { MenuEntryKind, ToggleKind } from "@domicile-desktop/sdk/app-menu"; type Props = { entries: readonly AppMenuEntry[]; /** The top-level entry whose menu is open, if any. */ open: number | undefined; /** A top-level entry's menu opened, or `undefined` once none is open. */ onOpen: (open: number | undefined) => void; /** The user chose entry `id`; the app runs it. */ onChoose: (id: number) => void; }; /** * An Electron app's menu bar under its window's tab: one menu per top-level * entry, drawn with the shell's menus. See "Menu bars" in * docs/SHELL-BROWSER-WINDOWS.md. */ export const AppMenuBar = ({ entries, onChoose, onOpen, open }: Props) => ( {entries.map((entry) => entry.kind === MenuEntryKind.Item ? ( { if (opening) { onOpen(entry.id); } else if (open === entry.id) { onOpen(undefined); } }} open={open === entry.id} > ) : undefined, )} ); type EntriesProps = Pick; /** A menu's entries, for the menu bar's menus and the app's popup menus. */ export const AppMenuEntries = ({ entries, onChoose }: EntriesProps) => entries.map((entry) => entry.kind === MenuEntryKind.Separator ? ( ) : ( ), ); type ItemProps = Pick & { item: AppMenuItem }; /** An entry, a submenu, a check box or a radio item. */ const Item = ({ item, onChoose }: ItemProps) => { const icon = item.icon === undefined ? undefined : ; if (item.submenu !== undefined) { return ( ); } const shared = { children: item.label, disabled: !item.enabled, icon, mnemonic: item.mnemonic, onClick: () => { onChoose(item.id); }, }; switch (item.toggle?.kind) { case undefined: { return ; } case ToggleKind.Checkmark: { // The app flips it when clicked, and the next listing shows it. return ( ); } case ToggleKind.Radio: { return ( ); } } };