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:
parent
1552019580
commit
7efa8c8ea7
9 changed files with 95 additions and 64 deletions
|
|
@ -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",
|
||||
|
|
|
|||
24
frontend/packages/shared/src/icon-button/IconButton.css
Normal file
24
frontend/packages/shared/src/icon-button/IconButton.css
Normal 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);
|
||||
}
|
||||
40
frontend/packages/shared/src/icon-button/IconButton.tsx
Normal file
40
frontend/packages/shared/src/icon-button/IconButton.tsx
Normal 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>
|
||||
);
|
||||
}
|
||||
|
|
@ -1,35 +1,11 @@
|
|||
/* <LinksMenu> (@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";
|
||||
/* <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-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);
|
||||
|
|
|
|||
|
|
@ -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 (
|
||||
<div class="links-menu" ref={rootRef}>
|
||||
<button
|
||||
type="button"
|
||||
class="links-menu-button"
|
||||
aria-haspopup="true"
|
||||
aria-expanded={open}
|
||||
aria-label={label}
|
||||
title={label}
|
||||
<IconButton
|
||||
label={label}
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
expanded={open}
|
||||
>
|
||||
<LinkIcon />
|
||||
</button>
|
||||
</IconButton>
|
||||
{open ? (
|
||||
<div class="links-menu-popover" role="menu">
|
||||
{links.map((link) => (
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
@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
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
// page-specific naming decision.
|
||||
import { useEffect, useRef, useState } from "preact/hooks";
|
||||
import type { ComponentChildren } from "preact";
|
||||
import { Badge } from "../badge/Badge.js";
|
||||
import { IconButton } from "../icon-button/IconButton.js";
|
||||
import { GearIcon } from "../icons.js";
|
||||
import { useThemeOverride, type ThemeOverride } from "./theme-apply.js";
|
||||
import { useMotionOverride, type MotionOverride } from "./motion-apply.js";
|
||||
|
|
@ -85,13 +85,13 @@ export function SettingsMenu({
|
|||
|
||||
return (
|
||||
<div class="settings-menu-anchor" ref={rootRef}>
|
||||
<Badge
|
||||
value={<GearIcon />}
|
||||
title="settings"
|
||||
variant="quiet"
|
||||
<IconButton
|
||||
label="settings"
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
expanded={open}
|
||||
/>
|
||||
>
|
||||
<GearIcon />
|
||||
</IconButton>
|
||||
{open ? (
|
||||
<div class="settings-menu-popover" role="menu" aria-label="settings">
|
||||
<label class="settings-menu-row">
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
@import "../icon-button/IconButton.css";
|
||||
/* <UserMenu> (@hive/shared) — same header icon-button + popover chrome as
|
||||
`LinksMenu`/`SettingsMenu`, except the trigger is a round, accent-
|
||||
coloured initials avatar rather than a glyph-on-transparent button —
|
||||
|
|
@ -8,25 +9,16 @@
|
|||
.user-menu {
|
||||
position: relative;
|
||||
}
|
||||
.user-menu-button {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
width: 2.75em;
|
||||
height: 2.75em;
|
||||
padding: 0;
|
||||
border: 1px solid transparent;
|
||||
border-radius: 50%;
|
||||
/* The round shape and the open outline are the shared icon button's; the fill is
|
||||
the accent inline on the element. */
|
||||
.ui-icon-button.user-menu-button {
|
||||
color: #fff;
|
||||
font-size: 1em;
|
||||
font-weight: 600;
|
||||
line-height: 1;
|
||||
cursor: pointer;
|
||||
text-shadow: 0 0.05em 0.15em rgba(0, 0, 0, 0.35);
|
||||
}
|
||||
.user-menu-button:hover,
|
||||
.user-menu-button[aria-expanded="true"] {
|
||||
border-color: var(--fg);
|
||||
.ui-icon-button.user-menu-button:hover,
|
||||
.ui-icon-button.user-menu-button[aria-expanded="true"] {
|
||||
outline: 1px solid var(--fg);
|
||||
}
|
||||
.user-menu-popover {
|
||||
position: absolute;
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@
|
|||
// 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.
|
||||
import { useEffect, useRef, useState } from "preact/hooks";
|
||||
import { IconButton } from "../icon-button/IconButton.js";
|
||||
import {
|
||||
accountLinks,
|
||||
initialOf,
|
||||
|
|
@ -83,17 +84,15 @@ export function UserMenu({
|
|||
|
||||
return (
|
||||
<div class="user-menu" ref={rootRef}>
|
||||
<button
|
||||
type="button"
|
||||
<IconButton
|
||||
class="user-menu-button"
|
||||
style={{ background: pickAccent(label ?? "operator") }}
|
||||
aria-haspopup="true"
|
||||
aria-expanded={open}
|
||||
aria-label={label ? `signed in as ${label}` : "account"}
|
||||
label={label ? `signed in as ${label}` : "account"}
|
||||
onClick={() => setOpen((v) => !v)}
|
||||
expanded={open}
|
||||
>
|
||||
{initialOf(label)}
|
||||
</button>
|
||||
</IconButton>
|
||||
{open ? (
|
||||
<div class="user-menu-popover" role="menu">
|
||||
{label ? <div class="user-menu-name">{label}</div> : null}
|
||||
|
|
|
|||
Loading…
Reference in a new issue