Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/src/ui/badge-popover/BadgePopover.tsx
iris 3a846c8c45 swarm ui: the terminal's status badges overhaul
The connection is a light on the agent's icon instead of a "live" badge, the
model and the effort are one badge, the context badge has an icon, subagents
and a new bash tasks badge are an icon and a count, and an agent's tab shows a
drag grip on hover.

It also removes two things the overhaul replaces: the cost badge, and the
"split" badge with its menu in group panes (splitting is by dragging a tab, or
from the subagents list).
2026-11-17 06:49:03 +01:00

65 lines
1.9 KiB
TypeScript

// <BadgePopover> — a badge that shows a value and, when clicked, opens a
// popover under it holding the control that changes the value: a list of
// checkboxes, a choice of modes, the entries behind a count. The control sits
// next to the thing it changes instead of in a dialog away from it.
//
// A click on the badge toggles the popover; a click outside it or Escape
// closes it (`Popover` does that).
import { useRef, useState } from "preact/hooks";
import type { ComponentChildren } from "preact";
import { Badge, type BadgeTone } from "@hive/shared/badge.js";
import { Popover } from "../popover/Popover.js";
import "./BadgePopover.css";
export function BadgePopover({
label,
value,
icon,
tone,
title,
ariaLabel,
popoverLabel,
children,
}: {
/** Dim prefix of the badge, e.g. "permissions". */
label?: ComponentChildren;
/** What the badge says, e.g. "7 granted". */
value: ComponentChildren;
/** A glyph before the value. */
icon?: ComponentChildren;
tone?: BadgeTone;
/** Tooltip on the badge: what clicking it does. */
title?: string;
/** The badge's accessible name, when its text is not enough of one. */
ariaLabel?: string;
/** `aria-label` of the floating box. */
popoverLabel: string;
children: ComponentChildren;
}) {
const [open, setOpen] = useState(false);
const anchorRef = useRef<HTMLSpanElement>(null);
return (
<>
<span class="ui-badge-popover" ref={anchorRef}>
<Badge
label={label}
value={value}
icon={icon}
tone={tone}
title={title}
ariaLabel={ariaLabel}
expanded={open}
onClick={() => setOpen((o) => !o)}
/>
</span>
<Popover
open={open}
onClose={() => setOpen(false)}
anchorRef={anchorRef}
label={popoverLabel}
>
<div class="ui-badge-popover-body">{children}</div>
</Popover>
</>
);
}