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,31 +1,5 @@
@import "../icon-button/IconButton.css";
/* <SettingsMenu> popover — matches `@hive/shared`'s `Dropdown`
(`../dropdown/Dropdown.css`, `.ui-dropdown`) values exactly
(background/border/radius/shadow): the values are reused, not the
component, because this popover holds `<select>` rows, not `Dropdown`'s
command-dispatch `<button>`s. Right-anchored — this trigger lives at
the end of a header's icon-trigger cluster in every page that mounts
it, so a left anchor would push it off-screen. */
.settings-menu-anchor {
position: relative;
display: inline-block;
}
.settings-menu-popover {
position: absolute;
top: calc(100% + 0.25em);
right: 0;
left: auto;
z-index: var(--z-popover);
display: flex;
flex-direction: column;
gap: 0.15em;
min-width: 12em;
padding: 0.5em;
background: var(--bg-elev);
border: 1px solid var(--border);
border-radius: var(--radius-md);
box-shadow: var(--shadow-pop);
}
@import "../header-menu/HeaderMenu.css";
/* <SettingsMenu> — the theme and motion rows inside a `HeaderMenu` popover. */
.settings-menu-row {
display: flex;
align-items: center;

View file

@ -23,11 +23,9 @@
// once, high in its tree, with the SAME key strings passed to this
// component, so the two stay in sync without this component owning any
// page-specific naming decision.
import { useRef, useState } from "preact/hooks";
import type { ComponentChildren } from "preact";
import { IconButton } from "../icon-button/IconButton.js";
import { HeaderMenu } from "../header-menu/HeaderMenu.js";
import { GearIcon } from "../icons.js";
import { useDismiss } from "../use-dismiss.js";
import { useThemeOverride } from "./theme-apply.js";
import { AUTO_THEME, THEMES } from "./themes.js";
import { useMotionOverride, type MotionOverride } from "./motion-apply.js";
@ -61,63 +59,40 @@ export function SettingsMenu({
motionKey,
children,
}: SettingsMenuProps) {
const [open, setOpen] = useState(false);
const rootRef = useRef<HTMLDivElement>(null);
const [theme, setTheme] = useThemeOverride(themeKey);
const [motion, setMotion] = useMotionOverride(motionKey);
// 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,
});
return (
<div class="settings-menu-anchor" ref={rootRef}>
<IconButton
label="settings"
onClick={() => setOpen((v) => !v)}
expanded={open}
>
<GearIcon />
</IconButton>
{open ? (
<div class="settings-menu-popover" role="group" aria-label="settings">
<label class="settings-menu-row">
<span>theme</span>
<select
value={theme}
onChange={(e) => setTheme((e.target as HTMLSelectElement).value)}
>
{THEME_OPTIONS.map((o) => (
<option key={o.id} value={o.id}>
{o.label}
</option>
))}
</select>
</label>
<label class="settings-menu-row">
<span>motion</span>
<select
value={motion}
onChange={(e) =>
setMotion(
(e.target as HTMLSelectElement).value as MotionOverride,
)
}
>
{MOTION_OPTIONS.map((o) => (
<option key={o} value={o}>
{o}
</option>
))}
</select>
</label>
{children}
</div>
) : null}
</div>
<HeaderMenu label="settings" trigger={<GearIcon />}>
<label class="settings-menu-row">
<span>theme</span>
<select
value={theme}
onChange={(e) => setTheme((e.target as HTMLSelectElement).value)}
>
{THEME_OPTIONS.map((o) => (
<option key={o.id} value={o.id}>
{o.label}
</option>
))}
</select>
</label>
<label class="settings-menu-row">
<span>motion</span>
<select
value={motion}
onChange={(e) =>
setMotion((e.target as HTMLSelectElement).value as MotionOverride)
}
>
{MOTION_OPTIONS.map((o) => (
<option key={o} value={o}>
{o}
</option>
))}
</select>
</label>
{children}
</HeaderMenu>
);
}