// — a single header icon-button opening a popover of links, next // to the profile avatar. The swarm UI hands it the swarm's service list and // the hive dashboard its own pages; both look and behave the same, which is // why it lives here (it was the swarm UI's, and the dashboard had its own // copy with a hamburger on the left). // // A menu with no links renders nothing: no button beats a dead one. // // Styles live in `@hive/shared/links-menu.css`, which the mounting page // imports or `@import`s itself: the dashboard's JS bundle loads `.css` // imports as text, so a component that imported it would not style there // (the same split as `UserMenu`). import { useRef, useState } from "preact/hooks"; import { IconButton } from "../icon-button/IconButton.js"; import { LinkIcon } from "../icons.js"; import { useDismiss } from "../use-dismiss.js"; import { linkAttrs, type MenuLink } from "./links.js"; export type { MenuLink }; export function LinksMenu({ links, label = "links", }: { links: MenuLink[]; /** The button's accessible name. */ label?: string; }) { const [open, setOpen] = useState(false); const rootRef = useRef(null); // A press outside or Escape closes it; Escape puts the focus back on the button. useDismiss({ open, onDismiss: () => setOpen(false), inside: [rootRef], focusOnEscape: () => rootRef.current?.querySelector("button") ?? null, }); if (links.length === 0) return null; return ( ); }