/**
* Progress - a linear determinate/indeterminate bar, plus a circular Spinner.
*
* fills an accent bar; omit `value` (or pass
* `indeterminate`) for a looping sweep when the amount is unknown. is
* a rotating accent ring for inline "loading" states. Both use keyframes from
* styles.ts and colour from the theme accent.
*
* Accessibility: the bar is role="progressbar" with aria-valuemin/max/now (absent
* when indeterminate); the spinner is role="status" with an aria-label.
*/
import type { CSSProperties } from "react";
import { R } from "@rukin/tokens";
import { useTheme } from "./theme";
import { keyframes, ANIM } from "./styles";
export type ProgressProps = {
/** 0-100. Omit (or set indeterminate) for the looping sweep. */
value?: number;
indeterminate?: boolean;
/** Bar thickness in px (default 8). */
height?: number;
/** Accessible label. */
ariaLabel?: string;
style?: CSSProperties;
};
export function Progress({
value,
indeterminate,
height = 8,
ariaLabel = "Progress",
style,
}: ProgressProps) {
const { C } = useTheme();
const isIndeterminate = indeterminate || value === undefined;
const pct = Math.max(0, Math.min(100, value ?? 0));
return (
{isIndeterminate ? (
) : (
)}
);
}
export type SpinnerProps = {
/** Diameter in px (default 24). */
size?: number;
/** Ring thickness in px (default size/8). */
thickness?: number;
/** Ring colour; defaults to the theme accent. */
color?: string;
ariaLabel?: string;
style?: CSSProperties;
};
export function Spinner({
size = 24,
thickness,
color,
ariaLabel = "Loading",
style,
}: SpinnerProps) {
const { C } = useTheme();
const bw = thickness ?? Math.max(2, Math.round(size / 8));
return (
);
}