Standardize action and region loading states

Keep progress inside the initiating Button/IconButton or centered within a
LoadingRegion without changing layout or unmounting live content. Document
ownership and completion/error behavior in the registry and living catalog.

Validation: qualified NET02 DG build/typecheck/registry/loading tests;
existing browser geometry, theme and error lifecycle acceptance. All eleven
committed files match the qualified source artifact byte for byte.
This commit is contained in:
Codex
2026-09-10 09:19:12 +03:00
parent b10fd5d645
commit 8c53f73ee5
11 changed files with 188 additions and 9 deletions
+18
View File
@@ -1,6 +1,7 @@
import { forwardRef, type ButtonHTMLAttributes, type ReactNode } from "react";
import { createAccentVariables, type RgbTuple } from "@nodedc/ui-core";
import { cn } from "./cn.js";
import { ActivityIndicator } from "./ActivityIndicator.js";
export type ButtonVariant = "primary" | "secondary" | "ghost" | "danger" | "accent";
export type ButtonSize = "default" | "compact" | "dense";
@@ -15,6 +16,8 @@ export interface ButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
shape?: ButtonShape;
accent?: RgbTuple;
icon?: ReactNode;
/** Pending state belongs to this action; dimensions and accessible name stay unchanged. */
loading?: boolean;
}
export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button({
@@ -29,6 +32,8 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button
children,
style,
type = "button",
loading = false,
disabled,
...props
}, ref) {
const accentStyle = accent ? createAccentVariables(accent) : undefined;
@@ -44,9 +49,15 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button
data-shape={shape === "default" ? undefined : shape}
style={accentStyle ? { ...accentStyle, ...style } : style}
{...props}
disabled={disabled || loading}
aria-busy={loading || props["aria-busy"]}
data-loading={loading || undefined}
>
<span className="nodedc-button__content">
{icon ? <span className="nodedc-button__icon" aria-hidden="true">{icon}</span> : null}
{children}
</span>
{loading ? <span className="nodedc-action-loading" aria-hidden="true"><ActivityIndicator size="compact" /></span> : null}
</button>
);
});
@@ -54,6 +65,7 @@ export const Button = forwardRef<HTMLButtonElement, ButtonProps>(function Button
export interface IconButtonProps extends ButtonHTMLAttributes<HTMLButtonElement> {
label: string;
shape?: "circle" | "rounded";
loading?: boolean;
}
export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(function IconButton({
@@ -62,6 +74,8 @@ export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(functio
className,
children,
type = "button",
loading = false,
disabled,
...props
}, ref) {
return (
@@ -73,8 +87,12 @@ export const IconButton = forwardRef<HTMLButtonElement, IconButtonProps>(functio
aria-label={label}
title={label}
{...props}
disabled={disabled || loading}
aria-busy={loading || props["aria-busy"]}
data-loading={loading || undefined}
>
{children}
{loading ? <span className="nodedc-action-loading" aria-hidden="true"><ActivityIndicator size="compact" /></span> : null}
</button>
);
});