Watch
0
0
Fork
You've already forked hyperhive
0
hyperhive/frontend/packages/swarm-ui/src/ui/button/Button.tsx
iris 16a5bff2b1 dashboard: action buttons use the swarm UI's button, with its danger tone and touch height
Button.css moves to @hive/shared, a rename from swarm-ui/src/ui/button/Button.css to shared/src/button/Button.css; the swarm UI's Button imports it from there and the dashboard imports it too. The dashboard's own .btn rules and its eleven per-action colour modifiers are gone: the bulk action buttons, the per-row purge and the selection bar's clear are ui-button, destroy and purge are ui-button-danger, and all of them have the 2.75em height the dashboard buttons were under. The form() and addBulkButton helpers take a tone (danger or default) in place of a btn-* class. The danger variant is the one the confirmations PR adds, identical, so the two merge in either order.
2026-11-20 12:55:25 +01:00

60 lines
2 KiB
TypeScript

// <Button> — the shared clickable-action control (form submit today,
// any future toolbar/dialog action later). `variant` is `'primary'`
// (the one emphasised action on a page, e.g. a form's submit) or
// `'default'` (everything else), or `'danger'` (the action that cannot be
// taken back: destroy, delete, a removal that cuts access).
import type { ComponentChildren } from "preact";
import { Spinner } from "../spinner/Spinner.js";
import "@hive/shared/button.css";
export type ButtonVariant = "primary" | "default" | "danger";
export function Button({
variant = "default",
type = "button",
disabled,
busy = false,
onClick,
describedBy,
ariaLabel,
autofocus = false,
children,
}: {
variant?: ButtonVariant;
type?: "button" | "submit";
disabled?: boolean;
/** A request from this button is in flight: a spinner covers the label,
* which keeps its space so the button does not change width, and the button
* cannot be pressed again. */
busy?: boolean;
onClick?: (e: Event) => void;
/** Id of the element that says why the button is disabled. */
describedBy?: string;
/** A name that says what the button acts on, where its visible text repeats
* across a list ("remove", "edit"). It should start with the visible text. */
ariaLabel?: string;
/** Takes the focus when the dialog around it opens, in place of its first
* control. A destructive confirm puts it on the safe button. */
autofocus?: boolean;
children: ComponentChildren;
}) {
return (
<button
class={"ui-button ui-button-" + variant + (busy ? " ui-button-busy" : "")}
type={type}
disabled={disabled || busy}
aria-busy={busy || undefined}
onClick={onClick}
aria-describedby={describedBy}
aria-label={ariaLabel}
autofocus={autofocus || undefined}
>
<span class="ui-button-label">{children}</span>
{busy ? (
<span class="ui-button-spinner">
<Spinner />
</span>
) : null}
</button>
);
}