Build App (Preview) / compute-version (pull_request) Successful in 5s
Secret Scan / scan (push) Successful in 23s
Secret Scan / scan (pull_request) Successful in 9s
Build App (Preview) / create-release (pull_request) Successful in 3s
Build App (Preview) / build-macos (pull_request) Successful in 6m24s
Build App (Preview) / build-windows (pull_request) Successful in 11m28s
Build App (Preview) / build-linux (pull_request) Successful in 23m6s
Build App (Preview) / test (pull_request) Successful in 26m21s
Build App (Preview) / prune-previews (pull_request) Successful in 5s
Hosts settings live in a 224-320px sidebar; nowrap buttons and long ARNs, policy names and run summaries overflowed it. Button and StatusIndicator get an opt-in wrap prop; host, environment, progress and policy rows wrap with min-w-0 children; policy copy buttons sit in an auto-fill grid; pre blocks scroll; the Modal footer wraps. Deploy a new environment and self-join are offered to anyone after a scan. When the permission check didn't confirm environment-admin rights a note says AWS has the last word, and the policies and environment request sit under a 'Not an admin?' disclosure. The boundary note shows whenever the boundary is missing. AWS refusals show AWS's message (awsErrorMessage now names the denied action) and offer the admin bundle: in the deploy and join modals, and under a failed deploy/join run whose output reads as denied. The backend already had no tier check on onboard_aws_user; its comment is corrected. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
95 lines
4.3 KiB
TypeScript
95 lines
4.3 KiB
TypeScript
import type { ButtonHTMLAttributes, ReactNode, Ref } from "react";
|
|
import { useUnavailable } from "./unavailable";
|
|
|
|
export type ButtonVariant = "primary" | "secondary" | "danger" | "ghost";
|
|
export type ButtonSize = "sm" | "md";
|
|
|
|
interface Props extends ButtonHTMLAttributes<HTMLButtonElement> {
|
|
variant?: ButtonVariant;
|
|
size?: ButtonSize;
|
|
children: ReactNode;
|
|
/**
|
|
* Unavailable, but still announced. Renders `aria-disabled` and wires
|
|
* `unavailableReason` to `aria-describedby` instead of using the native
|
|
* `disabled` attribute, which would take the button out of the tab order and
|
|
* out of the accessibility tree — reason and all. Clicks and Enter/Space are
|
|
* guarded for you. Prefer this over `disabled` whenever there is a reason
|
|
* worth telling the user.
|
|
*/
|
|
unavailable?: boolean;
|
|
/** Why the button cannot be used. Required for `unavailable` to say anything. */
|
|
unavailableReason?: string;
|
|
/**
|
|
* Let a long label wrap onto more lines instead of forcing the button (and
|
|
* its row) wider than a narrow container, such as the settings sidebar.
|
|
*/
|
|
wrap?: boolean;
|
|
/** React 19 passes `ref` as a prop; it lands on the `<button>` via `rest`. */
|
|
ref?: Ref<HTMLButtonElement>;
|
|
}
|
|
|
|
/**
|
|
* Real buttons with visible bounds and a ≥24px hit target.
|
|
* Filled variants use the *-emphasis tokens so white text clears WCAG AA;
|
|
* `--accent` stays reserved for foreground/link use.
|
|
*
|
|
* The `aria-disabled:` class mirrors below exist because Tailwind's
|
|
* `disabled:` variant only matches the native attribute, which `unavailable`
|
|
* deliberately does not set. Keep the two lists in step.
|
|
*/
|
|
const VARIANTS: Record<ButtonVariant, string> = {
|
|
primary:
|
|
"bg-[var(--accent-emphasis)] text-white border border-transparent hover:bg-[var(--accent-emphasis-hover)] disabled:bg-[var(--bg-tertiary)] disabled:text-[var(--text-disabled)] disabled:border-[var(--border-color)] aria-disabled:bg-[var(--bg-tertiary)] aria-disabled:text-[var(--text-disabled)] aria-disabled:border-[var(--border-color)] aria-disabled:hover:bg-[var(--bg-tertiary)]",
|
|
secondary:
|
|
"bg-[var(--bg-tertiary)] text-[var(--text-primary)] border border-[var(--border-color)] hover:bg-[var(--border-color)] disabled:text-[var(--text-disabled)] disabled:hover:bg-[var(--bg-tertiary)] aria-disabled:text-[var(--text-disabled)] aria-disabled:hover:bg-[var(--bg-tertiary)]",
|
|
danger:
|
|
"bg-transparent text-[var(--error)] border border-[var(--error)]/40 hover:bg-[var(--error-muted)] disabled:text-[var(--text-disabled)] disabled:border-[var(--border-color)] disabled:hover:bg-transparent aria-disabled:text-[var(--text-disabled)] aria-disabled:border-[var(--border-color)] aria-disabled:hover:bg-transparent",
|
|
ghost:
|
|
"bg-transparent text-[var(--text-secondary)] border border-transparent hover:text-[var(--text-primary)] hover:bg-[var(--bg-tertiary)] disabled:text-[var(--text-disabled)] disabled:hover:bg-transparent aria-disabled:text-[var(--text-disabled)] aria-disabled:hover:text-[var(--text-disabled)] aria-disabled:hover:bg-transparent",
|
|
};
|
|
|
|
const SIZES: Record<ButtonSize, string> = {
|
|
sm: "h-6 px-2 text-xs gap-1",
|
|
md: "h-8 px-3 text-[13px] gap-1.5",
|
|
};
|
|
|
|
/** `wrap`: the same sizes as a minimum height, so a second line can grow the button. */
|
|
const WRAP_SIZES: Record<ButtonSize, string> = {
|
|
sm: "min-h-6 py-0.5 px-2 text-xs gap-1",
|
|
md: "min-h-8 py-1 px-3 text-[13px] gap-1.5",
|
|
};
|
|
|
|
export default function Button({
|
|
variant = "secondary",
|
|
size = "sm",
|
|
className = "",
|
|
type = "button",
|
|
unavailable = false,
|
|
unavailableReason = "",
|
|
wrap = false,
|
|
children,
|
|
...rest
|
|
}: Props) {
|
|
const { controlProps, reasonNode } = useUnavailable({
|
|
unavailable,
|
|
reason: unavailableReason,
|
|
onClick: rest.onClick,
|
|
onKeyDown: rest.onKeyDown,
|
|
});
|
|
|
|
return (
|
|
<>
|
|
<button
|
|
type={type}
|
|
{...rest}
|
|
{...controlProps}
|
|
className={`inline-flex items-center justify-center ${wrap ? `whitespace-normal break-words text-left max-w-full min-w-0 ${WRAP_SIZES[size]}` : `whitespace-nowrap ${SIZES[size]}`} rounded-[var(--radius-control)] font-medium transition-colors disabled:cursor-not-allowed aria-disabled:cursor-not-allowed ${VARIANTS[variant]} ${className}`}
|
|
>
|
|
{children}
|
|
</button>
|
|
{/* Outside the button: inside, the reason would join its accessible name. */}
|
|
{reasonNode}
|
|
</>
|
|
);
|
|
}
|