组件

Progress

A bar somebody hatched in pencil and is coloring in with a marker. The marker is one full-length pass revealed by a CSS clip up to the value, so changing the value is a transition, not a redraw. Without a value it becomes a scribble sliding across. Radix Progress underneath.

安装

terminal
npx shadcn@latest add @wobko/progress

第一次使用?先把 registry 加进 components.json。 如何安装

示例

Default

A pencil-hatched box colored in with a marker as far as the value says. Change the value and the marker glides to it (a CSS clip on a full-length pass; nothing is redrawn).

Sizes, tones and waiting

sm, default and lg; marker, highlighter, grass and sky inks. Without a value the bar is indeterminate: a marker scribble slides across (it holds still, mid-bar, with reduced motion).

Upload queue

A real-world use: three files at different speeds, an indeterminate bar while one is being checked, a green bar and a tick when it is done. Progress is announced through aria-valuenow; the percentage is text.

Steps

`max` sets the scale, so value and max can be a step and a step count. The label is the only text; the bar has the same value in aria-valuenow and aria-valuemax.

Demo

Official `progress-demo`: the bar starts at 13 and jumps to 66 half a second later. The marker is drawn once, full length, and revealed to the value, so the change is a CSS transition. Only addition: an `aria-label`, which a progressbar needs.

API 参考

Progress

Radix Progress.Root (role=progressbar with aria-valuenow / min / max, data-state loading | complete | indeterminate) and its Indicator, both drawn hosts. The Indicator (data-slot="progress-indicator") is stretched over the whole bar and clipped to the value.

属性类型默认值说明
valuenumber | null-How far along, out of `max`; clamped to 0..max (an upload that reports 100.4 is a full bar; Radix alone would call that invalid and start the waiting animation). Leave it out, pass null or NaN for an indeterminate bar (no aria-valuenow).
maxnumber100The scale: value 3 of max 5 is 60 %.
size"sm" | "default" | "lg""default"12, 16 or 20 px tall. Any h-* class in `className` wins; the drawing follows the box.
tone"marker" | "hi" | "green" | "blue""marker"The ink: terracotta marker, highlighter, grass marker or sky marker.
getValueLabel(value: number, max: number) => string-Radix: builds aria-valuetext. Or pass aria-valuetext yourself.
seedstring | number-Pins the hand: the same seed always draws the same bar. Default: derived from useId().

无障碍

  • role="progressbar" with aria-valuemin, aria-valuemax and aria-valuenow (omitted while indeterminate); Radix also sets data-state, data-value and data-max. Give it a name with aria-label or aria-labelledby; use aria-valuetext for "Step 2 of 5" style text.
  • It is a status display, not a control: not focusable. Put the percentage in text next to it if people need the number; screen readers get it from aria-valuenow.
  • The drawing is aria-hidden and pointer-events: none. The hatch shows how much is left even when the marker's hue is hard to tell; in Windows high contrast the ink is replaced by a real border and a Highlight fill.
  • Reduced motion (the OS setting or data-motion="reduced"): value changes jump instead of gliding and the indeterminate scribble stops, sitting still in the middle of the bar.
  • Right-to-left: the marker grows from the right and the indeterminate window slides right to left.

源码

CLI 会复制进你项目的文件。

正在加载源码