Show how much of a task is complete or indicate that work is still underway.
Upload progress
Sizes and variants
Formats & Bounds
Indeterminate & Live Transfer
Purpose
Show how much of a task is complete or indicate that work is still underway.
Parts & Composition
Place ProgressLabel and ProgressValue in Progress, followed by ProgressTrack. The track supplies the indicator, marker, or centered value for the chosen variant. Pass children into the track to replace its default indicator. Set showValueMarker on the root to add a moving badge.
API & Props
| Prop or part | Purpose |
|---|---|
value | Current amount of work. Pass null if the amount is unknown. |
min, max | Bounds for the task, defaulting to 0 and 100. |
format, locale | Format the value for the visible text and accessible value. |
getValueLabel | Supply a more descriptive accessible value. |
variant | linear (default), segmented, or circular. |
showValueMarker | Adds a floating value badge to the track. On circular progress, the badge sits above the arc and the value label stays centered inside the ring. Defaults to false. |
ProgressTrack.segments | Number of marks for segmented. Defaults to six. |
size | Adjust track height and text scale from xs to lg. Defaults to md. |
Theming, Layout & Responsiveness
The bar fills its container, uses semantic rail and fill colors, and follows text direction.
Motion & Accessibility
The SDK exposes the progressbar role and its range. Give it a visible label or an accessible name. The visible value animates independently of the accessible value. Reduced-motion preferences disable fill and indeterminate motion.
Guidance for Coding Agents
Install Progress using the command in the Install tab and read this Info page. Pass real task progress from the app. Use a numeric value when the total is known and null while work is unmeasured. Choose a visible label and describe the unit when it matters. Follow the UI SDK Progress reference for inherited options and behavior.
CLI installation
bunx --bun shadcn@latest add https://ui.devvarena.com/api/r/progress'use client';
import {
Progress as SDKProgress,
ProgressIndicator as SDKProgressIndicator,
ProgressLabel as SDKProgressLabel,
ProgressTrack as SDKProgressTrack,
ProgressValue as SDKProgressValue,
} from '@ui-sdk/react/progress';
import { cva } from 'class-variance-authority';
import { type ComponentProps, createContext, useContext, useMemo } from 'react';
import { ValueTransition } from '@/hooks/use-value-transition';
import { controlTextSizes, partClass, type StandardControlSize } from '@/lib/devvarena-ui';
import { cn } from '@/lib/utils';
const progressIndeterminateKeyframes =
'@keyframes progress-sweep{0%{transform:translateX(-100%)}100%{transform:translateX(300%)}}';
const progressStyles = cva(
'grid w-full min-w-0 grid-cols-[minmax(0,1fr)_auto] items-center gap-2',
{
variants: {
size: {
xs: [
controlTextSizes.xs,
'[--progress-track-height:0.25rem] [--progress-ring-size:3.5rem]',
],
sm: [
controlTextSizes.sm,
'[--progress-track-height:0.375rem] [--progress-ring-size:4.25rem]',
],
md: [controlTextSizes.md, '[--progress-track-height:0.5rem] [--progress-ring-size:5rem]'],
lg: [controlTextSizes.lg, '[--progress-track-height:0.75rem] [--progress-ring-size:6rem]'],
} satisfies Record<StandardControlSize, string[]>,
},
defaultVariants: { size: 'md' },
},
);
type ProgressVariant = 'linear' | 'segmented' | 'circular';
const ProgressContext = createContext<{ variant: ProgressVariant; showValueMarker: boolean }>({
variant: 'linear',
showValueMarker: false,
});
type ProgressProps = ComponentProps<typeof SDKProgress> & {
size?: StandardControlSize;
variant?: ProgressVariant;
showValueMarker?: boolean;
};
function Progress({
size = 'md',
variant = 'linear',
showValueMarker = false,
className,
...props
}: ProgressProps) {
const context = useMemo(() => ({ variant, showValueMarker }), [variant, showValueMarker]);
return (
<ProgressContext value={context}>
<SDKProgress
{...props}
data-size={size}
data-variant={variant}
className={partClass(progressStyles({ size }), className)}
/>
</ProgressContext>
);
}
function ProgressLabel({ className, ...props }: ComponentProps<typeof SDKProgressLabel>) {
return (
<SDKProgressLabel {...props} className={partClass('font-medium text-foreground', className)} />
);
}
function ProgressValue({ className, children, ...props }: ComponentProps<typeof SDKProgressValue>) {
return (
<SDKProgressValue
{...props}
aria-hidden="true"
className={partClass(
'col-start-2 justify-self-end text-muted-foreground tabular-nums',
className,
)}
>
{children ?? (({ text }) => text && <ValueTransition value={text} />)}
</SDKProgressValue>
);
}
type ProgressTrackProps = ComponentProps<typeof SDKProgressTrack> & { segments?: number };
function ProgressTrack({ className, children, segments = 6, ...props }: ProgressTrackProps) {
const { variant, showValueMarker } = useContext(ProgressContext);
const circular = variant === 'circular';
const segmented = variant === 'segmented';
const count = Number.isFinite(segments) ? Math.min(100, Math.max(1, Math.round(segments))) : 6;
return (
<SDKProgressTrack
{...props}
className={partClass(
'relative col-span-full min-w-0',
circular ? 'size-(--progress-ring-size)' : 'w-full',
showValueMarker && markerSpacing,
!segmented && !circular && 'h-(--progress-track-height) rounded-lg bg-muted shadow-inner',
className,
)}
>
{(state) => {
const trackContent =
typeof children === 'function'
? children(state)
: (children ??
(circular ? (
<CircularProgress percent={state.percent} />
) : segmented ? (
<SegmentedProgress count={count} percent={state.percent} />
) : (
<ProgressIndicator />
)));
return (
<>
{!circular && !segmented ? (
<span className="block size-full overflow-hidden rounded-lg">{trackContent}</span>
) : (
trackContent
)}
{showValueMarker && state.percent !== null && (
<ProgressValueMarker
inlinePosition={
circular ? 50 + Math.sin((state.percent / 100) * 2 * Math.PI) * 25 : undefined
}
/>
)}
</>
);
}}
</SDKProgressTrack>
);
}
const markerSpacing = 'data-progressing:mt-6 data-complete:mt-6';
function ProgressValueMarker({ inlinePosition }: { inlinePosition?: number }) {
return (
<ProgressValue
data-value-marker=""
style={inlinePosition === undefined ? undefined : { insetInlineStart: `${inlinePosition}%` }}
className="pointer-events-none absolute bottom-full z-10 mb-1.5 start-[clamp(1.5rem,var(--progress-value),max(1.5rem,calc(100%-1.5rem)))] -translate-x-1/2 whitespace-nowrap rounded-sm bg-primary px-1.5 py-0.5 text-xs text-primary-foreground transition-[inset-inline-start] duration-300 ease-out rtl:translate-x-1/2 motion-reduce:transition-none"
/>
);
}
function CircularProgress({ percent }: { percent: number | null }) {
const arcPercent = percent ?? 28;
return (
<>
<span
aria-hidden="true"
className={cn(
'pointer-events-none absolute inset-0 block size-full rtl:-scale-x-100',
percent === null && 'motion-safe:animate-spin motion-safe:[animation-duration:1.4s]',
)}
>
<svg aria-hidden="true" viewBox="0 0 40 40" className="block size-full -rotate-90">
<circle cx="20" cy="20" r="17" fill="none" strokeWidth="4" className="stroke-muted" />
<circle
cx="20"
cy="20"
r="17"
fill="none"
strokeWidth="4"
strokeLinecap="round"
pathLength="100"
strokeDasharray="100"
strokeDashoffset={100 - arcPercent}
className={cn(
'stroke-primary transition-[stroke-dashoffset,opacity] duration-300 ease-out motion-reduce:transition-none',
percent === 0 && 'opacity-0',
)}
/>
</svg>
</span>
<ProgressValue
data-ring-value=""
className="pointer-events-none absolute inset-0 grid place-items-center justify-self-stretch text-center text-xs font-medium text-foreground"
/>
</>
);
}
function SegmentedProgress({ count, percent }: { count: number; percent: number | null }) {
return (
<span
aria-hidden="true"
className="flex w-full items-center justify-between"
style={{ columnGap: `min(0.375rem, ${25 / count}%)` }}
>
{Array.from({ length: count }, (_, index) => {
const fill =
percent === null
? index === 0
? 1
: 0
: Math.min(1, Math.max(0, (percent * count) / 100 - index));
return (
<span
// biome-ignore lint/suspicious/noArrayIndexKey: Segments are fixed indexed positions in a progress scale.
key={index}
className="relative h-(--progress-track-height) min-w-0 flex-1 overflow-hidden rounded-lg bg-muted shadow-inner"
>
<span
style={{ transform: `scaleX(${fill})` }}
className={cn(
'absolute inset-0 origin-left rounded-lg bg-primary transition-transform duration-300 ease-out rtl:origin-right motion-reduce:transition-none',
percent === null && index === 0 && 'motion-safe:animate-pulse',
)}
/>
</span>
);
})}
</span>
);
}
function ProgressIndicator({ className, ...props }: ComponentProps<typeof SDKProgressIndicator>) {
return (
<>
<style>{progressIndeterminateKeyframes}</style>
<SDKProgressIndicator
{...props}
className={partClass(
'h-full rounded-lg bg-primary transition-[width] duration-300 ease-out data-indeterminate:w-1/3 motion-safe:data-indeterminate:[animation:progress-sweep_1.4s_cubic-bezier(0.4,0,0.2,1)_infinite] motion-reduce:data-indeterminate:w-full motion-reduce:data-indeterminate:opacity-50 motion-reduce:transition-none',
className,
)}
/>
</>
);
}
export type { GaugeLabelDetails, ProgressState, ProgressValueState } from '@ui-sdk/react/progress';
export {
Progress,
ProgressIndicator,
ProgressLabel,
type ProgressProps,
ProgressTrack,
type ProgressTrackProps,
ProgressValue,
type ProgressVariant,
};
'use client';
import { type ComponentProps, useState } from 'react';
import { cn } from '@/lib/utils';
export type UseValueTransitionOptions = {
/** Whether characters animate when the value changes. Defaults to `true`. */
enabled?: boolean;
/** Roll direction. `auto` rolls up when a number grows (or for text), down when it shrinks. */
direction?: 'auto' | 'up' | 'down';
/** Delay in ms between consecutive changed characters. Defaults to `28`. */
stagger?: number;
/**
* Animation granularity:
* - `auto` (default): per-character for numeric values, whole-string for text.
* - `char`: always animate per-character.
* - `whole`: always animate the entire value as one unit.
*/
mode?: 'auto' | 'char' | 'whole';
};
export type TransitionChar = {
key: string;
char: string;
/** The character being replaced. Only set when this character should roll. */
prev?: string;
/** Transition delay in ms. */
delay: number;
};
const MAX_DELAY = 140;
const hasDigit = (text: string) => /\d/.test(text);
const isNumeric = (text: string) => hasDigit(text) && !/[a-zA-Z]/.test(text);
const toNumber = (text: string) => Number.parseFloat(text.replace(/[^\d.-]/g, ''));
/**
* Diffs `value` against its previous value and returns per-character data, so
* only the characters that actually changed roll, one after another.
*
* - Numbers align from the right (the ones digit stays the ones digit),
* text aligns from the left.
* - Pure derivation from state, with no effects or DOM reads, so it works for
* any value: numbers, formatted numbers, labels, statuses.
*/
export function useValueTransition(
value: string | number | null | undefined,
{
enabled = true,
direction = 'auto',
stagger = 28,
mode = 'auto',
}: UseValueTransitionOptions = {},
) {
const text = value == null ? '' : String(value);
const [state, setState] = useState({ text, prev: text });
if (state.text !== text) setState({ text, prev: state.text });
const numeric = isNumeric(state.text);
const perChar = mode === 'char' || (mode === 'auto' && numeric);
const dir: 1 | -1 =
direction === 'up'
? 1
: direction === 'down'
? -1
: numeric && hasDigit(state.prev) && toNumber(state.text) < toNumber(state.prev)
? -1
: 1;
if (!perChar) {
const changed = enabled && state.prev !== state.text;
const chars: TransitionChar[] = state.text
? [
{
key: `whole-${state.text}`,
char: state.text,
prev: changed ? state.prev : undefined,
delay: 0,
},
]
: [];
return { text: state.text, chars, dir };
}
const next = [...state.text];
const old = [...state.prev];
const offset = numeric ? old.length - next.length : 0;
const fromEmpty = state.prev === '' && state.text !== '';
// Stagger starts at the least significant end: ones digit first for numbers.
let rank = 0;
const chars: TransitionChar[] = new Array(next.length);
for (let step = 0; step < next.length; step++) {
const i = numeric ? next.length - 1 - step : step;
const char = next[i];
const prevChar = old[i + offset];
const shouldRoll = enabled && (fromEmpty || (prevChar !== undefined && prevChar !== char));
chars[i] = {
// Keyed by position + char: a changed character remounts (replaying the
// animation, even on rapid changes) while untouched ones stay mounted.
key: `${numeric ? next.length - i : i}-${char}`,
char,
prev: shouldRoll ? (prevChar ?? '') : undefined,
delay: shouldRoll ? Math.min(rank++ * stagger, MAX_DELAY) : 0,
};
}
return { text: state.text, chars, dir };
}
const motion =
'transition-[translate,opacity,filter] duration-300 ease-[cubic-bezier(0.22,1,0.36,1)] motion-reduce:transition-none';
export type ValueTransitionProps = Omit<ComponentProps<'span'>, 'children'> &
UseValueTransitionOptions & {
value: string | number | null | undefined;
/** Whether to apply a subtle blur during the transition. Defaults to `true`. */
blur?: boolean;
};
/**
* Drop-in display for any value: `<ValueTransition value={count} />`.
* Inherits font, size and color from its parent.
*/
export function ValueTransition({
value,
enabled,
direction,
stagger,
mode,
blur = true,
className,
...props
}: ValueTransitionProps) {
const { text, chars, dir } = useValueTransition(value, { enabled, direction, stagger, mode });
return (
<span
{...props}
className={cn(
'inline-flex overflow-hidden tabular-nums [mask-image:linear-gradient(to_bottom,transparent,#000_14%,#000_88%,transparent)]',
className,
)}
>
<span className="sr-only"> {text} </span>
<span aria-hidden="true" className="inline-flex">
{chars.map(({ key, char, prev, delay }) => (
<span
key={key}
className={cn(
'relative inline-block whitespace-pre leading-normal',
dir > 0 ? '[--d:1]' : '[--d:-1]',
)}
>
{prev === undefined ? (
char
) : (
<>
<span
style={{ transitionDelay: `${delay}ms` }}
className={cn(
'inline-block starting:translate-y-[calc(var(--d)*100%)] starting:opacity-0',
blur && 'starting:blur-[2px]',
motion,
)}
>
{char}
</span>
<span
aria-hidden="true"
style={{ transitionDelay: `${delay}ms` }}
className={cn(
'absolute inset-0 translate-y-[calc(var(--d)*-100%)] opacity-0 starting:translate-y-0 starting:opacity-100 motion-reduce:hidden',
blur && 'blur-[2px] starting:blur-none',
motion,
)}
>
{prev}
</span>
</>
)}
</span>
))}
</span>
</span>
);
}
import { cn } from '@/lib/utils';
type ClassValue = string | false | null | undefined;
type PartClassValue<State> = ClassValue | ((state: State) => ClassValue);
/** Composes static class names and UI-SDK state class functions into a single `className` prop. */
export function partClass<State>(...parts: PartClassValue<State>[]) {
if (parts.some((part) => typeof part === 'function')) {
return (state: State) =>
cn(...parts.map((part) => (typeof part === 'function' ? part(state) : part)));
}
return cn(...(parts as ClassValue[]));
}
export const surfacePadding = 'p-1 [--surface-padding:1.5rem] [--concentric-inset:0.25rem]';
export const surfaceRegionInset = 'p-[calc(var(--surface-padding,1rem)-0.5rem)]';
export const surfaceHeaderRadius = 'rounded-t-[max(0px,calc(var(--radius-lg,0.5rem)-0.25rem))]';
export const surfaceFooterRadius = 'rounded-b-[max(0px,calc(var(--radius-lg,0.5rem)-0.25rem))]';
/** Concentric inner radius (`outer - inset`); set `[--concentric-inset:0.125rem]` on `p-0.5` rails (defaults to `0.25rem` for `p-1`). */
export const concentricRadius =
'rounded-[max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem)))]';
export const surfaceBodyPadding =
'py-[max(0px,calc(var(--surface-padding,1rem)-1rem))] has-[>[data-slot=list]:not([data-variant=plain])]:p-0 has-[>[data-slot=list-items-container]]:p-0';
export type StandardControlSize = 'xs' | 'sm' | 'md' | 'lg';
/** Standard control heights (`28px / 32px / 40px / 48px`) for buttons, inputs, selects, tabs, and sliders. */
export const controlHeights = {
xs: 'h-7',
sm: 'h-8',
md: 'h-10',
lg: 'h-12',
} as const satisfies Record<StandardControlSize, string>;
/** Standard minimum control heights (`28px / 32px / 40px / 48px`) for expandable controls and menu items. */
export const controlMinHeights = {
xs: 'min-h-7',
sm: 'min-h-8',
md: 'min-h-10',
lg: 'min-h-12',
} as const satisfies Record<StandardControlSize, string>;
/** Standard control text sizes (`xs / xs / sm / base`) paired with `StandardControlSize`. */
export const controlTextSizes = {
xs: 'text-xs',
sm: 'text-xs',
md: 'text-sm',
lg: 'text-base',
} as const satisfies Record<StandardControlSize, string>;
/** Compact control heights (`1.25rem / 1.3rem / 1.625rem / 1.75rem`), one step smaller than standard, for switches and compact controls. */
export const compactControlHeights = {
xs: 'h-[1.3rem]',
sm: 'h-[1.4rem]',
md: 'h-[1.5rem]',
lg: 'h-[1.6rem]',
} as const satisfies Record<StandardControlSize, string>;
/** Compact minimum control heights (`1rem / 1.25rem / 1.5rem / 1.75rem`) for badges and tooltips. */
export const compactControlMinHeights = {
xs: 'min-h-[1.3rem]',
sm: 'min-h-[1.4rem]',
md: 'min-h-[1.5rem]',
lg: 'min-h-[1.6rem]',
} as const satisfies Record<StandardControlSize, string>;
/** Universal keyboard focus + invalid ring/border styles shared across controls. */
export const focusRing =
'touch-manipulation outline-none focus-visible:border-ring/30 transition-ring focus-visible:ring-3 focus-visible:ring-ring/15 focus-visible:brightness-[0.97] dark:focus-visible:brightness-[1.15] has-[:focus-visible]:border-ring/30 has-[:focus-visible]:ring-3 has-[:focus-visible]:ring-ring/15 has-[:focus-visible]:brightness-[0.97] dark:has-[:focus-visible]:brightness-[1.15] data-active:border-ring/30 data-active:ring-3 data-active:ring-ring/15 data-active:brightness-[0.97] dark:data-active:brightness-[1.15] data-open:border-ring/30 data-open:ring-3 data-open:ring-ring/15 data-open:brightness-[0.97] dark:data-open:brightness-[1.15] data-disabled:cursor-not-allowed data-disabled:opacity-50 aria-invalid:border-destructive aria-invalid:ring-3 aria-invalid:ring-destructive/25 data-invalid:border-destructive data-invalid:ring-3 data-invalid:ring-destructive/25 has-[[data-invalid]]:border-destructive has-[[data-invalid]]:ring-3 has-[[data-invalid]]:ring-destructive/25 group-aria-invalid/control:border-destructive group-aria-invalid/control:ring-3 group-aria-invalid/control:ring-destructive/25 group-data-invalid/control:border-destructive group-data-invalid/control:ring-3 group-data-invalid/control:ring-destructive/25 group-has-[input[aria-invalid=true]]/control:border-destructive group-has-[input[aria-invalid=true]]/control:ring-3 group-has-[input[aria-invalid=true]]/control:ring-destructive/25 hover:brightness-[0.97] dark:hover:brightness-[1.15]';
/** Shared sliding highlight indicator base (pointer-safe, concentric inner radius inside rounded-lg containers, 200ms transition). */
export const slidingHighlight =
'pointer-events-none -z-10 rounded-[max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem)))] bg-primary/10 [clip-path:inset(0px_round_max(0px,calc(var(--radius-lg,0.5rem)-var(--concentric-inset,0.25rem))))] transition-[transform,width,height,opacity] duration-200 ease-out motion-reduce:transition-none';
export const textFieldSurfaces = {
filled: 'border-input bg-card text-card-foreground',
outline: 'border-input bg-transparent text-foreground dark:bg-transparent',
ghost: 'border-transparent bg-muted text-foreground shadow-none',
underline:
'rounded-none border-0 border-b-2 border-input bg-transparent px-0 text-foreground shadow-none focus-visible:border-ring focus-visible:ring-0 aria-invalid:ring-0 data-invalid:ring-0 dark:bg-transparent',
} as const;
export const textFieldUnderlineMotion =
'border-transparent! bg-origin-border bg-bottom bg-no-repeat [--underline-color:var(--primary)] [background-image:linear-gradient(var(--underline-color),var(--underline-color)),linear-gradient(var(--input),var(--input))] [background-size:0%_2px,100%_2px] focus:[background-size:100%_2px,100%_2px] aria-invalid:[--underline-color:var(--destructive)] data-invalid:[--underline-color:var(--destructive)] transition-[border-color,background-color,box-shadow,filter,background-size] duration-200 motion-reduce:transition-none';
/** Generic balanced icon & floating-label layout tokens shared across all text-field sizes. */
export const textFieldLayout = {
icon: 'size-4',
iconStart: 'start-3',
iconEnd: 'end-3',
padStart: 'ps-9',
padEnd: 'pe-9',
underlinePadStart: 'ps-7',
underlinePadEnd: 'pe-7',
floatingStart: 'start-2.5',
floatingWithIcon: 'start-8',
floatingUnderlineIcon: 'start-6',
} as const;
export const textFieldLabelSegmenter = new Intl.Segmenter(undefined, { granularity: 'grapheme' });
/** Clamps per-grapheme wave delay (ms) so total staggering stays within 300ms. */
export function clampWaveDelay(waveDelay: number, count: number): number {
return Math.max(
0,
Math.min(Number.isFinite(waveDelay) ? waveDelay : 24, 80, 300 / Math.max(1, count - 1)),
);
}
/** Shared scale/color transition for floating labels inside a `group/field` wrapper. */
export const textFieldLabelMotion =
'inline-block origin-left backdrop-blur-xs transition-[scale,color] duration-200 ease-out group-has-[input:focus]/field:scale-85 group-has-[input:not(:placeholder-shown)]/field:scale-85 rtl:origin-right motion-reduce:transition-none';
/** Resolves start/end padding for a text field when a leading or trailing icon is present. */
export function getTextFieldIconPadding(iconPosition: 'start' | 'end', underline: boolean): string {
if (iconPosition === 'start') {
return underline ? textFieldLayout.underlinePadStart : textFieldLayout.padStart;
}
return underline ? textFieldLayout.underlinePadEnd : textFieldLayout.padEnd;
}
/** Shared per-grapheme ripple transition for wave labels inside a `group/field` wrapper. */
export const textFieldWaveMotion =
'inline-block origin-left backdrop-blur-xs transition-[translate,scale,color] duration-200 ease-out group-has-[input:focus]/field:-translate-y-5 group-has-[input:focus]/field:scale-85 group-has-[input:focus]/field:text-primary group-has-[input:not(:placeholder-shown)]/field:-translate-y-5 group-has-[input:not(:placeholder-shown)]/field:scale-85 group-has-[input[aria-invalid=true]]/field:text-destructive rtl:origin-right motion-reduce:transition-none';