本文へ移動
日本語

仕組み

A track in --ds-chart-track and a round-capped arc drawn with pathLength = 1, so stroke-dashoffset runs from 1 (empty) to 0 (full); the svg is turned −90° to start at 12 o'clock. The arc moves with a CSS transition and the number counts in requestAnimationFrame on the same curve and duration. An IntersectionObserver starts the first sweep when the ring is 30% in view; until then (and in the server render) it rests at zero. A new value transitions from the arc's current position, never back through zero. Indeterminate mode spins the whole ring at 2s while a quarter arc chases at 1.4s.

向いている場面

  • A single completion figure that should read at a glance, such as course progress, storage used or profile strength.
  • Tasks with a clear percentage, like an upload or export, when the space is square.
  • Checks and matching of unknown length: use indeterminate mode.

向かない場面

  • Progress inside table rows or list items: a horizontal bar saves space and aligns better.
  • Comparing several values: rings are hard to compare by length; use a bar chart.
  • Operations that end within a second: show the result or a button loading state.

使い方

import { ProgressRing } from './ProgressRing.jsx'

export function CourseProgress({ done, total }) {
  return <ProgressRing value={done} max={total} size={124} thickness={14} aria-label="Course progress" />
}

// Red, amber or green by value
<ProgressRing value={score} thresholds label="Strength" />

// Unknown wait
<ProgressRing indeterminate label="Syncing" />

プロパティ

プロパティ型既定値説明
valuenumber0Current value, between min and max.
minnumber0Minimum value.
maxnumber100Maximum value.
sizenumber120Ring diameter in px; the number scales with it.
thicknessnumber14Ring width in px. 14 to 16 reads best at 120px.
thresholdsboolean | { danger: number, warning: number }falseColor by percentage: true means below 30 danger, below 70 warning, otherwise success. Pass custom limits. false (default) keeps one color: the accent or `color`.
indeterminatebooleanfalseShows a spinning arc and no number.
labelReactNode—Caption under the number. A string also becomes the accessible name.
unitstring'%'Unit after the number; an empty string hides it.
colorstring—Arc color when thresholds are off, any CSS color such as var(--ds-chart-3). Defaults to the accent.
durationnumber900Length in ms of the sweep and the count, on cubic-bezier(0.22, 1, 0.36, 1).
animateOnMountbooleantrueStart at zero and sweep to the value the first time the ring is 30% in view. false shows the value at once.
formatValue(value: number) => string—Custom number format. It receives the in-between value while counting (not rounded), for example to keep one decimal.
...restHTMLAttributes<HTMLDivElement>—Other attributes go to the root element, such as aria-label, className and style.

アクセシビリティ

  • The root is role="progressbar" with aria-valuenow, aria-valuemin and aria-valuemax; aria-valuetext includes the unit, such as “86%”.
  • Screen readers get only the final value: the counting digits are aria-hidden, so no run of in-between numbers is read.
  • A string label becomes the aria-label automatically; indeterminate mode omits aria-valuenow and sets aria-busy.
  • Color is not the only signal: the number and caption are always visible.
  • Reduced motion shows the final value at once with no counting, and indeterminate mode breathes in place instead of spinning.

モーション

First view: the arc sweeps and the number counts for 900ms on cubic-bezier(0.22, 1, 0.36, 1). Value changes use the same curve from the current position; threshold colors cross-fade in 240ms. Indeterminate: 2s linear spin plus a 1.4s ease-in-out chase. Reduced motion shows the final value at once, without counting.

プロジェクトに追加

プロンプトを Codex または Claude Code に貼り付けます。エージェントが公開ソースを読み、書き込む内容を示したうえで、既存のコンポーネントの隣に追加します。

ProgressRing.jsxprogress-ring.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

読み込み
「画像リビール」は Pro に含まれます。解除するとプレビューが表示されます。
「オービットローダー」は Pro に含まれます。解除するとプレビューが表示されます。