npm install react-aria-components
"use client";
import type { ReactNode } from "react";
import { Label, ProgressBar, type ProgressBarProps } from "react-aria-components";
const styles = {
root: "block font-(family-name:--tui-font) text-(length:--tui-progress-font-size) leading-none font-(--tui-progress-font-weight)",
// Like the kit's slider, the bar carries its own name and number, and they change colour as the fill passes.
track: "relative h-(--tui-progress-height) w-full overflow-hidden rounded-(--tui-progress-radius) bg-(--tui-progress-track) text-(--tui-progress-fg)",
row: "absolute inset-y-0 left-0 flex items-center justify-between gap-3 px-(--tui-progress-padding-x)",
fill: "absolute inset-y-0 left-0 overflow-hidden bg-(--tui-progress-fill) text-(--tui-progress-fill-fg) transition-[width] duration-(--tui-progress-duration) ease-out",
moving: "absolute inset-y-0 w-2/5 rounded-(--tui-progress-radius) bg-(--tui-progress-fill) opacity-80 [animation:tui-air-slide_1.4s_ease-in-out_infinite]",
};
export interface ProgressProps extends Omit<ProgressBarProps, "className" | "children"> {
label?: string;
/** Leaves the number off the bar. */
hideValue?: boolean;
className?: string;
}
export function Progress({ label, hideValue, className, ...props }: ProgressProps) {
return (
<ProgressBar {...props} className={[styles.root, className].filter(Boolean).join(" ")}>
{({ percentage, valueText, isIndeterminate }) => {
const part = Math.min(Math.max((percentage ?? 0) / 100, 0), 1);
const words = (name: ReactNode) => (
<>
{name}
{!hideValue && !isIndeterminate && <span className="tabular-nums">{valueText}</span>}
</>
);
return (
<div data-slot="progress-track" className={styles.track}>
<div className={`${styles.row} w-full`}>{words(label ? <Label>{label}</Label> : <span />)}</div>
{isIndeterminate ? (
<div data-slot="progress-fill" className={styles.moving} />
) : (
<div aria-hidden data-slot="progress-fill" className={styles.fill} style={{ width: `${part * 100}%` }}>
{/* The fill keeps its own copy of the words at the bar's full width, so they sit exactly over the ones beneath. */}
<div className={styles.row} style={{ width: part > 0 ? `${100 / part}%` : 0 }}>
{words(<span>{label}</span>)}
</div>
</div>
)}
</div>
);
}}
</ProgressBar>
);
}:root {
color-scheme: light;
--tui-bg: #ffffff;
--tui-fg: #0a0a0a;
--tui-muted: #f5f5f5;
--tui-muted-fg: #737373;
--tui-border: #e5e5e5;
--tui-primary: #171717;
--tui-primary-fg: #fafafa;
--tui-ring: #a3a3a3;
--tui-success: #16a34a;
--tui-warning: #d97706;
--tui-danger: #dc2626;
--tui-radius: 8px;
--tui-border-width: 1px;
--tui-space: 4px;
--tui-shadow: none;
--tui-font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
--tui-text: 14px;
--tui-duration: 150ms;
/* Progress */
--tui-progress-height: calc(var(--tui-space) * 10);
--tui-progress-padding-x: calc(var(--tui-space) * 4);
--tui-progress-radius: calc(var(--tui-radius) * 1.75);
--tui-progress-font-size: var(--tui-text);
--tui-progress-font-weight: 500;
--tui-progress-duration: 360ms;
--tui-progress-track: color-mix(in srgb, var(--tui-bg) 94%, var(--tui-fg));
--tui-progress-fg: var(--tui-fg);
--tui-progress-fill: var(--tui-primary);
--tui-progress-fill-fg: var(--tui-primary-fg);
}
.dark,
[data-theme="dark"] {
color-scheme: dark;
--tui-bg: #0a0a0a;
--tui-fg: #fafafa;
--tui-muted: #1c1c1c;
--tui-muted-fg: #a3a3a3;
--tui-border: #2a2a2a;
--tui-primary: #fafafa;
--tui-primary-fg: #171717;
--tui-ring: #737373;
--tui-success: #22c55e;
--tui-warning: #f59e0b;
--tui-danger: #ef4444;
}
@keyframes tui-air-slide {
0% { left: -40%; }
100% { left: 100%; }
}Needs Tailwind CSS v4. Import the stylesheet once, after Tailwind.