Components
Progress Circle
Shows how far along a task is as a ring that fills up, small enough for a button, a card or a list row.
Introduction
Progress Circle is the ring version of a progress bar. It shows how much of a task is done as an arc that grows around a circle, and it takes so little room that it fits where a bar does not: inside a button, on a card, beside a line of text, in a dashboard.
- Announced as a
progressbarwith its value, its range and the value as text. A circle has no visible label, soaria-labelis required. - The middle can show the value (
showValue) or anything you put in it: a number, an icon, a check mark when it is done. - The value is written as a percentage, as a number with a unit, or in your own words, over any range. Five sizes, three thicknesses and four colors.
- With
isIndeterminatean arc turns around the ring, for work whose progress is not known. For people who prefer reduced motion it does not turn, it breathes.
For a wide, thin display, or when a label and a value should sit above it, use Progress Bar. For a measurement that is not going anywhere, use Meter.
Installation
centerUI has no CLI or registry yet: components are copied into your project.
# bun
bun add react-aria-components tailwind-variants tailwind-merge clsx
# pnpm
pnpm add react-aria-components tailwind-variants tailwind-merge clsx
# npm
npm install react-aria-components tailwind-variants tailwind-merge clsxManual installation
Copy these files into your project and keep the paths, or adjust the imports.
1. Add the styles
src/types/progress-circle-styles.tsShow code
import { tv } from "tailwind-variants";
// Styles for ProgressCircle: a ring of a track and an arc on it, drawn as two
// svg circles, with room in the middle for a value. The svg is turned so the
// arc starts at the top.
export const progressCircleStyles = tv({
slots: {
root: "relative inline-flex shrink-0 items-center justify-center",
svg: "size-full -rotate-90",
track: "fill-none stroke-fg/10",
arc: "fill-none transition-[stroke-dashoffset,stroke] duration-300 ease-out motion-reduce:transition-none",
// The middle of the ring, as big as the hole in it, so what is inside is
// sized against the hole and not against the whole ring. It is a container,
// so the value can be sized in `cqw`, a share of its own width.
center:
"absolute grid place-items-center text-center font-medium text-fg tabular-nums [container-type:size]",
// The value: a number, with its unit smaller and lighter beside it.
value:
"flex items-baseline justify-center whitespace-nowrap font-semibold leading-none tracking-tight text-fg tabular-nums",
unit: "font-medium text-[0.62em] text-fg/60",
},
variants: {
size: {
xs: { root: "size-5", center: "hidden" },
sm: { root: "size-8", center: "text-[9px]" },
md: { root: "size-12", center: "text-xs" },
lg: { root: "size-16", center: "text-sm" },
xl: { root: "size-24", center: "text-lg" },
},
variant: {
default: { arc: "stroke-primary" },
success: { arc: "stroke-success" },
warning: { arc: "stroke-warning" },
danger: { arc: "stroke-danger" },
},
},
defaultVariants: { size: "md", variant: "default" },
});
// The width of the ring, in the 100-unit box of the svg.
export const ringWidth = { thin: 6, regular: 10, thick: 16 } as const;2. Add the Progress Circle file
src/components/ui/progress-circle/progress-circle.tsxShow code
"use client";
import type { ReactNode } from "react";
import { ProgressBar as AriaProgressBar } from "react-aria-components";
import { cn } from "@/lib/cn";
import {
progressCircleStyles,
ringWidth,
} from "@/types/progress-circle-styles";
export interface ProgressCircleState {
/** How far along it is, from 0 to 100. */
percentage: number;
/** The value as text, or `undefined` while indeterminate. */
valueText: string | undefined;
}
export interface ProgressCircleProps {
/** How far along it is. Not needed when the circle is indeterminate. */
value?: number;
/** The value at the start. Defaults to 0. */
minValue?: number;
/** The value at the end. Defaults to 100. */
maxValue?: number;
/** The work is going on but how much is done is not known: an arc turns around. */
isIndeterminate?: boolean;
/**
* What is in progress. A circle has no room for a visible label, so this is
* what a screen reader hears. Every circle needs one.
*/
"aria-label": string;
/** Write the value in the middle. It needs a size of `sm` or more. */
showValue?: boolean;
/**
* What goes in the middle, instead of the value: an icon, a number, a check
* mark when it is done. A function receives the percentage and the value as
* text.
*/
children?: ReactNode | ((state: ProgressCircleState) => ReactNode);
/**
* How the value is written. The default is a percentage. Use
* `{ style: "unit", unit: "megabyte" }` and the like for a real unit.
*/
formatOptions?: Intl.NumberFormatOptions;
/** Replaces the written value with your own text, such as "3 of 8 files". It is also what a screen reader hears. */
valueLabel?: string;
/** The color of the arc. Defaults to the neutral one. */
variant?: "default" | "success" | "warning" | "danger";
size?: "xs" | "sm" | "md" | "lg" | "xl";
/** How wide the ring is. */
thickness?: "thin" | "regular" | "thick";
className?: string;
}
const radius = 45;
const circumference = 2 * Math.PI * radius;
// Splits "64%", "128 MB" or "3 of 8" into what comes before the number, the
// number, and what comes after, so the number can be big and the rest small.
// Text that has no number in it is left as it is.
function splitValue(text: string) {
const match = text.match(/^(\D*?)(-?\d[\d.,]*)(.*)$/);
if (!match) return null;
return { prefix: match[1].trim(), number: match[2], suffix: match[3].trim() };
}
/**
* Shows how far along a task is as a ring that fills up: an upload, a goal, the
* score of a quiz. It takes little room, so it fits in a button, a card or a
* list row, and it can hold a value or any content in the middle. It is
* announced as a progress bar with its value.
*
* With `isIndeterminate` an arc turns around the ring, for work whose progress
* is not known.
*
* @example
* <ProgressCircle aria-label="Upload" value={64} showValue />
* <ProgressCircle aria-label="Connecting" isIndeterminate />
*/
export function ProgressCircle({
showValue = false,
children,
variant,
size,
thickness = "regular",
className,
...props
}: ProgressCircleProps) {
const styles = progressCircleStyles({ size, variant });
return (
<AriaProgressBar {...props} className={cn(styles.root(), className)}>
{({ percentage: measured, valueText, isIndeterminate }) => {
const percentage = measured ?? 0;
const width = ringWidth[thickness];
// The arc is a dash as long as the progress, on a gap as long as the
// rest. While indeterminate it is a quarter of the ring, and it turns.
const arc = isIndeterminate
? circumference * 0.25
: (circumference * percentage) / 100;
const custom =
typeof children === "function"
? children({ percentage, valueText })
: children;
const text = showValue && !isIndeterminate ? valueText : undefined;
const parts = text ? splitValue(text) : null;
// The value is as big as the hole allows: 34% of its width, less for
// a long text, which is shrunk to fit.
const fontSize = text
? `min(34cqw, ${(160 / Math.max(text.length, 1)).toFixed(1)}cqw)`
: undefined;
return (
<>
<svg
viewBox="0 0 100 100"
aria-hidden="true"
data-loader={isIndeterminate ? "" : undefined}
className={cn(
styles.svg(),
isIndeterminate && "animate-loader-spin",
)}
>
<circle
cx="50"
cy="50"
r={radius}
strokeWidth={width}
className={styles.track()}
/>
<circle
cx="50"
cy="50"
r={radius}
strokeWidth={width}
strokeLinecap="round"
strokeDasharray={`${arc} ${circumference}`}
className={styles.arc()}
// A ring at 0 would still show its round cap as a dot.
opacity={!isIndeterminate && percentage === 0 ? 0 : 1}
/>
</svg>
{custom || text ? (
// The hole is inside the ring, so the middle is inset by the
// width of the ring, and a little more for air.
<span
className={styles.center()}
style={{ inset: `${width + 3}%` }}
>
{custom ?? (
<span className={styles.value()} style={{ fontSize }}>
{parts ? (
<>
{parts.prefix ? (
<span className={cn(styles.unit(), "mr-[0.15em]")}>
{parts.prefix}
</span>
) : null}
<span>{parts.number}</span>
{parts.suffix ? (
// A percent sign hugs its number; a unit or a few
// words get a little room.
<span
className={cn(
styles.unit(),
parts.suffix === "%"
? "ml-[0.06em]"
: "ml-[0.22em]",
)}
>
{parts.suffix}
</span>
) : null}
</>
) : (
text
)}
</span>
)}
</span>
) : null}
</>
);
}}
</AriaProgressBar>
);
}3. Add the animation
The indeterminate arc turns with the --animate-loader-spin line of the theme and the loader-spin keyframes, and stops turning with the [data-loader] rule in the reduced-motion query. All three come from Loader, so if you added Loader there is nothing more to copy. Without them the arc is still.
4. Use it
import { ProgressCircle } from "@/components/ui/progress-circle/progress-circle";Anatomy
A ring made of a track and an arc, with room in the middle.
<ProgressCircle aria-label="Upload" value={64} size="lg" showValue />
<ProgressCircle aria-label="Connecting" isIndeterminate />| Part | Rendered as | Notes |
|---|---|---|
| ProgressCircle | div with role progressbar | Reports the value, the range and the written value to assistive technology. It needs an aria-label, since there is no room for a visible one. |
| Track | svg circle | The whole ring. |
| Arc | svg circle | As long as the progress, starting at the top and going clockwise. When indeterminate, a quarter of the ring that turns. |
| Middle | span | The value, with showValue, or whatever you put in children: an icon, a number, a check mark. |
Examples
Usage
Value in the middle
showValue writes the value in the ring. The number is set large and its unit small and light beside it, and it is sized to the hole inside the ring, so it stays tidy at every size and thickness. It needs room, so it starts at size sm and reads best from md up.
Value format
A percentage by default. minValue and maxValue set the ends, formatOptions writes the number with a unit, and valueLabel replaces it with your own text, which a screen reader hears too. A long text needs a bigger ring.
Indeterminate
For work whose progress is not known. An arc, a quarter of the ring, turns around it. No value is shown or announced.
Variants
The color of the arc: neutral, or the theme's success, warning and danger.
Sizes
From 20 to 96 pixels: xs, sm, md, lg and xl.
Thickness
How wide the ring is. Thin is delicate, and thick leaves less room in the middle.
Content in the middle
children replaces the value with anything: text, an icon. A function receives the percentage and the value as text, to change what is shown as it moves, such as a check mark at 100.
Beside text
A small ring next to what it measures. The text carries the meaning, and the ring gives it a shape.
Complete your profile
70% done
Live progress
A simulated upload: 10% every half second. The arc grows, and a check mark replaces the number when it is done.
Component API
Progress Circle takes the props below.
| Prop | Type | Default |
|---|---|---|
| aria-label | string | - (required) |
| value | number | 0 |
| minValue | number | 0 |
| maxValue | number | 100 |
| isIndeterminate | boolean | false |
| showValue | boolean | false |
| children | ReactNode | ({ percentage, valueText }) => ReactNode | - |
| formatOptions | Intl.NumberFormatOptions | a percentage |
| valueLabel | string | - |
| variant | "default" | "success" | "warning" | "danger" | "default" |
| size | "xs" | "sm" | "md" | "lg" | "xl" | "md" |
| thickness | "thin" | "regular" | "thick" | "regular" |
| className | string | - |