hyperhive/frontend/packages/shared/src/links-menu/LinksMenu.tsx
iris 6f73bf0c55 frontend: one header menu for the links, user, settings and alerts popovers
Part of the unification order in the UI sweep issue (step c).

The four header menus each kept their own open state, dismiss hook and a copy
of the popover CSS, and the copies had drifted (offset, padding, fade-in). A
shared HeaderMenu now owns the state, the dismiss rules and the popover look;
each menu supplies its button and its rows. The settings popover moves 0.15em
lower and the settings and alerts popovers gain the fade-in.
2026-11-25 22:25:40 +01:00

47 lines
1.5 KiB
TypeScript

// <LinksMenu> — 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 { HeaderMenu } from "../header-menu/HeaderMenu.js";
import { LinkIcon } from "../icons.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;
}) {
if (links.length === 0) return null;
return (
<HeaderMenu label={label} trigger={<LinkIcon />}>
{(close) =>
links.map((link) => (
<a
key={link.url}
class="header-menu-item"
href={link.url}
{...linkAttrs(link)}
onClick={close}
>
{link.icon ? <span aria-hidden="true">{link.icon}</span> : null}
{link.label}
</a>
))
}
</HeaderMenu>
);
}