Watch
0
0
Fork
You've already forked hyperhive
0

frontend: one shared IconButton for the header's settings, links and account buttons

The gear was a quiet pill badge (37px tall), the links button a bordered rounded square with its own CSS, and the avatar a third copy of the same circle. They are one IconButton now: a 2.75em circle with no fill until hovered or open, then the raised fill and a purple outline. The avatar keeps its accent fill and initials and takes the shared shape. The swarm UI and the dashboard both get the shared look.
This commit is contained in:
iris 2026-11-20 00:22:56 +01:00 • committed by mara
commit 7efa8c8ea7
9 changed files with 95 additions and 64 deletions

View file

@ -39,6 +39,8 @@
"./api-error-panel.css": "./src/api-error-panel/api-error-panel.css", "./api-error-panel.css": "./src/api-error-panel/api-error-panel.css",
"./warn-banner.js": "./src/warn-banner/WarnBanner.tsx", "./warn-banner.js": "./src/warn-banner/WarnBanner.tsx",
"./warn-banner.css": "./src/warn-banner/WarnBanner.css", "./warn-banner.css": "./src/warn-banner/WarnBanner.css",
"./icon-button.js": "./src/icon-button/IconButton.tsx",
"./icon-button.css": "./src/icon-button/IconButton.css",
"./badge.js": "./src/badge/Badge.tsx", "./badge.js": "./src/badge/Badge.tsx",
"./badge.css": "./src/badge/Badge.css", "./badge.css": "./src/badge/Badge.css",
"./dropdown.js": "./src/dropdown/Dropdown.tsx", "./dropdown.js": "./src/dropdown/Dropdown.tsx",

View file

@ -0,0 +1,24 @@
/* <IconButton> (@hive/shared): a 2.75em circle, the touch-target floor, with no
fill until hovered or open. Open: the raised fill and a purple outline. */
.ui-icon-button {
display: flex;
align-items: center;
justify-content: center;
width: 2.75em;
height: 2.75em;
padding: 0;
border: 0;
border-radius: 50%;
background: none;
color: var(--fg);
font-size: 1em;
line-height: 1;
cursor: pointer;
}
.ui-icon-button:hover {
background: var(--border);
}
.ui-icon-button[aria-expanded="true"] {
background: var(--bg-elev);
outline: 1px solid var(--purple);
}

View file

@ -0,0 +1,40 @@
// <IconButton> — the round, icon-only button of a page header: the settings
// gear, the links glyph and the account avatar are all one. It is a 2.75em
// circle (the touch-target floor) with no fill until hovered or open. It
// carries no CSS import: the pages link `icon-button.css` (the stylesheets of
// the menus built on it `@import` it), as for `LinksMenu`.
import type { ComponentChildren } from "preact";
export function IconButton({
label,
onClick,
expanded,
class: className,
style,
children,
}: {
/** What the button does, as its accessible name and its tooltip. */
label: string;
onClick: () => void;
/** Whether the popover it opens is open. */
expanded: boolean;
/** Extra classes, for the avatar's colour. */
class?: string;
style?: Record<string, string>;
/** The glyph. */
children: ComponentChildren;
}) {
return (
<button
type="button"
class={"ui-icon-button" + (className ? " " + className : "")}
style={style}
aria-expanded={expanded}
aria-label={label}
title={label}
onClick={onClick}
>
{children}
</button>
);
}

View file

@ -1,35 +1,11 @@
/* <LinksMenu> (@hive/shared) — a single header icon-button + popover. Kept visually @import "../icon-button/IconButton.css";
quiet (no border/fill until interacted with) so it reads as chrome, /* <LinksMenu> (@hive/shared) — a header icon button (the shared `IconButton`)
not another nav item. Button is sized to the same touch-target floor and its popover. No `margin-left: auto` here: the mounting page's header owns
as the shared `ui/` kit (2.75em ≈ 44px, WCAG 2.5.5) even though it pushing the action group to the right edge (the swarm UI's
isn't built from that kit — a bespoke icon trigger, not a form `.shell-header-actions`, the dashboard's `.dashboard-chrome-actions`). */
control, but the floor applies regardless of which component drew
it. 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 { .links-menu {
position: relative; position: relative;
} }
.links-menu-button {
display: flex;
align-items: center;
justify-content: center;
width: 2.75em;
height: 2.75em;
padding: 0;
border: 1px solid transparent;
border-radius: 0.4em;
background: none;
color: var(--fg);
font-size: 1em;
line-height: 1;
cursor: pointer;
}
.links-menu-button:hover,
.links-menu-button[aria-expanded="true"] {
border-color: var(--border);
background: var(--bg-elev);
}
.links-menu-popover { .links-menu-popover {
position: absolute; position: absolute;
top: calc(100% + 0.4em); top: calc(100% + 0.4em);

View file

@ -11,6 +11,7 @@
// imports as text, so a component that imported it would not style there // imports as text, so a component that imported it would not style there
// (the same split as `UserMenu`). // (the same split as `UserMenu`).
import { useEffect, useRef, useState } from "preact/hooks"; import { useEffect, useRef, useState } from "preact/hooks";
import { IconButton } from "../icon-button/IconButton.js";
import { LinkIcon } from "../icons.js"; import { LinkIcon } from "../icons.js";
import { linkAttrs, type MenuLink } from "./links.js"; import { linkAttrs, type MenuLink } from "./links.js";
@ -48,17 +49,13 @@ export function LinksMenu({
return ( return (
<div class="links-menu" ref={rootRef}> <div class="links-menu" ref={rootRef}>
<button <IconButton
type="button" label={label}
class="links-menu-button"
aria-haspopup="true"
aria-expanded={open}
aria-label={label}
title={label}
onClick={() => setOpen((v) => !v)} onClick={() => setOpen((v) => !v)}
expanded={open}
> >
<LinkIcon /> <LinkIcon />
</button> </IconButton>
{open ? ( {open ? (
<div class="links-menu-popover" role="menu"> <div class="links-menu-popover" role="menu">
{links.map((link) => ( {links.map((link) => (

View file

@ -1,3 +1,4 @@
@import "../icon-button/IconButton.css";
/* <SettingsMenu> popover — matches `@hive/shared`'s `Dropdown` /* <SettingsMenu> popover — matches `@hive/shared`'s `Dropdown`
(`../dropdown/Dropdown.css`, `.ui-dropdown`) values exactly (`../dropdown/Dropdown.css`, `.ui-dropdown`) values exactly
(background/border/radius/shadow): the values are reused, not the (background/border/radius/shadow): the values are reused, not the

View file

@ -25,7 +25,7 @@
// page-specific naming decision. // page-specific naming decision.
import { useEffect, useRef, useState } from "preact/hooks"; import { useEffect, useRef, useState } from "preact/hooks";
import type { ComponentChildren } from "preact"; import type { ComponentChildren } from "preact";
import { Badge } from "../badge/Badge.js"; import { IconButton } from "../icon-button/IconButton.js";
import { GearIcon } from "../icons.js"; import { GearIcon } from "../icons.js";
import { useThemeOverride, type ThemeOverride } from "./theme-apply.js"; import { useThemeOverride, type ThemeOverride } from "./theme-apply.js";
import { useMotionOverride, type MotionOverride } from "./motion-apply.js"; import { useMotionOverride, type MotionOverride } from "./motion-apply.js";
@ -85,13 +85,13 @@ export function SettingsMenu({
return ( return (
<div class="settings-menu-anchor" ref={rootRef}> <div class="settings-menu-anchor" ref={rootRef}>
<Badge <IconButton
value={<GearIcon />} label="settings"
title="settings"
variant="quiet"
onClick={() => setOpen((v) => !v)} onClick={() => setOpen((v) => !v)}
expanded={open} expanded={open}
/> >
<GearIcon />
</IconButton>
{open ? ( {open ? (
<div class="settings-menu-popover" role="menu" aria-label="settings"> <div class="settings-menu-popover" role="menu" aria-label="settings">
<label class="settings-menu-row"> <label class="settings-menu-row">

View file

@ -1,3 +1,4 @@
@import "../icon-button/IconButton.css";
/* <UserMenu> (@hive/shared) — same header icon-button + popover chrome as /* <UserMenu> (@hive/shared) — same header icon-button + popover chrome as
`LinksMenu`/`SettingsMenu`, except the trigger is a round, accent- `LinksMenu`/`SettingsMenu`, except the trigger is a round, accent-
coloured initials avatar rather than a glyph-on-transparent button — coloured initials avatar rather than a glyph-on-transparent button —
@ -8,25 +9,16 @@
.user-menu { .user-menu {
position: relative; position: relative;
} }
.user-menu-button { /* The round shape and the open outline are the shared icon button's; the fill is
display: flex; the accent inline on the element. */
align-items: center; .ui-icon-button.user-menu-button {
justify-content: center;
width: 2.75em;
height: 2.75em;
padding: 0;
border: 1px solid transparent;
border-radius: 50%;
color: #fff; color: #fff;
font-size: 1em;
font-weight: 600; font-weight: 600;
line-height: 1;
cursor: pointer;
text-shadow: 0 0.05em 0.15em rgba(0, 0, 0, 0.35); text-shadow: 0 0.05em 0.15em rgba(0, 0, 0, 0.35);
} }
.user-menu-button:hover, .ui-icon-button.user-menu-button:hover,
.user-menu-button[aria-expanded="true"] { .ui-icon-button.user-menu-button[aria-expanded="true"] {
border-color: var(--fg); outline: 1px solid var(--fg);
} }
.user-menu-popover { .user-menu-popover {
position: absolute; position: absolute;

View file

@ -16,6 +16,7 @@
// imports or `@import`s itself: the dashboard's JS bundle loads `.css` // 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. // imports as text, so a component that imported it would not style there.
import { useEffect, useRef, useState } from "preact/hooks"; import { useEffect, useRef, useState } from "preact/hooks";
import { IconButton } from "../icon-button/IconButton.js";
import { import {
accountLinks, accountLinks,
initialOf, initialOf,
@ -83,17 +84,15 @@ export function UserMenu({
return ( return (
<div class="user-menu" ref={rootRef}> <div class="user-menu" ref={rootRef}>
<button <IconButton
type="button"
class="user-menu-button" class="user-menu-button"
style={{ background: pickAccent(label ?? "operator") }} style={{ background: pickAccent(label ?? "operator") }}
aria-haspopup="true" label={label ? `signed in as ${label}` : "account"}
aria-expanded={open}
aria-label={label ? `signed in as ${label}` : "account"}
onClick={() => setOpen((v) => !v)} onClick={() => setOpen((v) => !v)}
expanded={open}
> >
{initialOf(label)} {initialOf(label)}
</button> </IconButton>
{open ? ( {open ? (
<div class="user-menu-popover" role="menu"> <div class="user-menu-popover" role="menu">
{label ? <div class="user-menu-name">{label}</div> : null} {label ? <div class="user-menu-name">{label}</div> : null}