Watch
0
0
Fork
You've already forked hyperhive
0

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.
This commit is contained in:
iris 2026-11-25 22:25:40 +01:00
commit 6f73bf0c55
2 changed files with 310 additions and 365 deletions

View file

@ -1,63 +1,5 @@
@import "../icon-button/IconButton.css";
/* <LinksMenu> (@hive/shared) — a header icon button (the shared `IconButton`)
and its popover. No `margin-left: auto` here: the mounting page's header owns
pushing the action group to the right edge (the swarm UI's
`.shell-header-actions`, the dashboard's `.dashboard-chrome-actions`). */
.links-menu {
position: relative;
}
.links-menu-popover {
position: absolute;
top: calc(100% + 0.4em);
right: 0;
z-index: var(--z-popover);
display: flex;
flex-direction: column;
min-width: 10em;
padding: 0.4em;
border: 1px solid var(--border);
border-radius: var(--radius-md);
background: var(--bg-elev);
box-shadow: var(--shadow-pop);
animation: links-menu-popover-enter 140ms ease;
}
/* Mount-triggered, not a state transition — the popover only exists in
the DOM while open (`{open ? <div> : null}`), so a keyframe animation
on entry is the right tool, same shape as `.shell-body`'s own
`shell-page-enter` (Shell.css) — that's the precedent every popover
in this issue's "menus should animate" ask follows. */
@keyframes links-menu-popover-enter {
from {
opacity: 0;
transform: translateY(-0.25em) scale(0.98);
}
to {
opacity: 1;
transform: none;
}
}
@media (prefers-reduced-motion: reduce) {
.links-menu-popover {
animation: none;
}
}
:root[data-motion="reduce"] .links-menu-popover {
animation: none;
}
:root[data-motion="allow"] .links-menu-popover {
animation: links-menu-popover-enter 140ms ease;
}
.links-menu-item {
display: flex;
align-items: center;
gap: 0.5em;
min-height: 2.75em;
padding: 0.4em 0.6em;
border-radius: var(--radius-sm);
color: var(--fg);
text-decoration: none;
white-space: nowrap;
}
.links-menu-item:hover {
background: var(--bg);
}
/* <LinksMenu> (@hive/shared) — a `HeaderMenu` of links; the popover and the
link row are `HeaderMenu.css`'s. No `margin-left: auto` here: the mounting
page's header owns pushing the action group to the right edge (the swarm
UI's `.shell-header-actions`, the dashboard's `.dashboard-chrome-actions`). */
@import "../header-menu/HeaderMenu.css";

View file

@ -10,10 +10,8 @@
// 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 { HeaderMenu } from "../header-menu/HeaderMenu.js";
import { LinkIcon } from "../icons.js";
import { useDismiss } from "../use-dismiss.js";
import { linkAttrs, type MenuLink } from "./links.js";
export type { MenuLink };
@ -26,44 +24,24 @@ export function LinksMenu({
/** The button's accessible name. */
label?: string;
}) {
const [open, setOpen] = useState(false);
const rootRef = useRef<HTMLDivElement>(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 (
<div class="links-menu" ref={rootRef}>
<IconButton
label={label}
onClick={() => setOpen((v) => !v)}
expanded={open}
>
<LinkIcon />
</IconButton>
{open ? (
<div class="links-menu-popover" role="group" aria-label={label}>
{links.map((link) => (
<a
key={link.url}
class="links-menu-item"
href={link.url}
{...linkAttrs(link)}
onClick={() => setOpen(false)}
>
{link.icon ? <span aria-hidden="true">{link.icon}</span> : null}
{link.label}
</a>
))}
</div>
) : null}
</div>
<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>
);
}