diff --git a/frontend/packages/shared/package.json b/frontend/packages/shared/package.json index a2322acee..343dda276 100644 --- a/frontend/packages/shared/package.json +++ b/frontend/packages/shared/package.json @@ -39,6 +39,8 @@ "./api-error-panel.css": "./src/api-error-panel/api-error-panel.css", "./warn-banner.js": "./src/warn-banner/WarnBanner.tsx", "./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.css": "./src/badge/Badge.css", "./dropdown.js": "./src/dropdown/Dropdown.tsx", diff --git a/frontend/packages/shared/src/icon-button/IconButton.css b/frontend/packages/shared/src/icon-button/IconButton.css new file mode 100644 index 000000000..0366a923e --- /dev/null +++ b/frontend/packages/shared/src/icon-button/IconButton.css @@ -0,0 +1,24 @@ +/* (@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); +} diff --git a/frontend/packages/shared/src/icon-button/IconButton.tsx b/frontend/packages/shared/src/icon-button/IconButton.tsx new file mode 100644 index 000000000..d560cc18c --- /dev/null +++ b/frontend/packages/shared/src/icon-button/IconButton.tsx @@ -0,0 +1,40 @@ +// — 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; + /** The glyph. */ + children: ComponentChildren; +}) { + return ( + + ); +} diff --git a/frontend/packages/shared/src/links-menu/LinksMenu.css b/frontend/packages/shared/src/links-menu/LinksMenu.css index c6d3ce5f9..19deac8ae 100644 --- a/frontend/packages/shared/src/links-menu/LinksMenu.css +++ b/frontend/packages/shared/src/links-menu/LinksMenu.css @@ -1,35 +1,11 @@ -/* (@hive/shared) — a single header icon-button + popover. Kept visually - quiet (no border/fill until interacted with) so it reads as chrome, - not another nav item. Button is sized to the same touch-target floor - as the shared `ui/` kit (2.75em ≈ 44px, WCAG 2.5.5) even though it - isn't built from that kit — a bespoke icon trigger, not a form - 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`). */ +@import "../icon-button/IconButton.css"; +/* (@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-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 { position: absolute; top: calc(100% + 0.4em); diff --git a/frontend/packages/shared/src/links-menu/LinksMenu.tsx b/frontend/packages/shared/src/links-menu/LinksMenu.tsx index b3d0eb191..12fdcce07 100644 --- a/frontend/packages/shared/src/links-menu/LinksMenu.tsx +++ b/frontend/packages/shared/src/links-menu/LinksMenu.tsx @@ -11,6 +11,7 @@ // imports as text, so a component that imported it would not style there // (the same split as `UserMenu`). import { useEffect, useRef, useState } from "preact/hooks"; +import { IconButton } from "../icon-button/IconButton.js"; import { LinkIcon } from "../icons.js"; import { linkAttrs, type MenuLink } from "./links.js"; @@ -48,17 +49,13 @@ export function LinksMenu({ return (