Files
ServerKit/frontend/src/components/ProgressBar.jsx
T
Juan Denis 7c8519772f Add accessible form controls and field wiring
FormField now hands its control the id, aria-describedby, aria-invalid
and aria-required through context, so every settings form announces
its hint and validation without per-call wiring. IconButton gets a real
tooltip instead of title=, ProgressBar is a labelled progressbar with
tones and an indeterminate state, and Button takes `loading` without
changing width.

New controls the panel lacked: NumberField, Combobox (single, multiple,
creatable), TagInput, Calendar with DatePicker and DateRangePicker,
PinInput, Slider, RadioGroup, Stepper, TreeView, and FileDropzone with
FileUploadList. Rounding, date and file-type rules live in lib/ with
unit tests. All of them render on /style-guide/controls.
2026-10-25 23:18:24 -04:00

55 lines
1.8 KiB
React

import { cn } from '@/lib/utils';
const TONES = new Set(['accent', 'success', 'warning', 'danger', 'info']);
/**
* Determinate or indeterminate progress, announced as a progressbar.
*
* <ProgressBar percent={48} label="Disk" valueText="48 of 100 GB" />
* <ProgressBar percent={92} tone="danger" size="md" />
* <ProgressBar indeterminate label="Pulling image" />
*
* `label` names it for screen readers (pass `aria-labelledby` instead when a
* visible label sits next to it). `tone` picks a semantic colour; `color` is
* the legacy raw-colour escape hatch and wins when both are set.
*/
export function ProgressBar({
percent = 0,
tone,
color,
size = 'sm',
indeterminate = false,
label,
valueText,
className = '',
...props
}) {
const clamped = Math.max(0, Math.min(100, Number(percent) || 0));
const fillStyle = indeterminate
? (color ? { background: color } : undefined)
: { width: `${clamped}%`, ...(color && { background: color }) };
return (
<div
role="progressbar"
aria-label={label}
aria-valuemin={indeterminate ? undefined : 0}
aria-valuemax={indeterminate ? undefined : 100}
aria-valuenow={indeterminate ? undefined : Math.round(clamped)}
aria-valuetext={valueText}
aria-busy={indeterminate || undefined}
className={cn(
'progress-bar',
size === 'md' && 'progress-bar--md',
TONES.has(tone) && `progress-bar--${tone}`,
indeterminate && 'progress-bar--indeterminate',
className,
)}
{...props}
>
<div className="progress-fill" style={fillStyle} />
</div>
);
}
export default ProgressBar;