跳到主要内容

CircleProgress

Circular progress indicator: renders an inline SVG (viewBox 0 0 size size) with a track circle (lh-circle-progress__track) and an arc circle (lh-circle-progress__arc) whose stroke-dasharray drives the filled ratio. All geometry, clamping, color normalization and text formatting are consumed from @lh-ui/share/core/circle-progress pure functions, so the semantics are identical across all platforms.

  • modelValue is clamped to [0, 100] (no error for out-of-range values).
  • startAngle uses the clock convention: 0 = 12 o'clock, clockwise positive. The SVG default starting point (3 o'clock) is compensated by an inline rotate(startAngle - 90deg) transform on the svg element.
  • clockwise defaults to true; false appends scaleX(-1) to the same inline transform so the arc sweeps counterclockwise from the same origin.
  • color accepts a single color or an array; arrays with 2+ entries render a defs > linearGradient (id generated via React.useId(), unique per instance) and the arc references it via stroke="url(#id)".

Basic usage​

CircleProgress (default / gradient / counterclockwise / start angle / custom format / no text)
70%100%60%50%88 分
import { LhCircleProgress } from '@lh-ui/react'

export default function Demo() {
return (
<>
<LhCircleProgress modelValue={70} />
<LhCircleProgress modelValue={100} color="#E4007E" />
<LhCircleProgress modelValue={60} color={['#2B4C7C', '#E4007E']} size={80} />
<LhCircleProgress modelValue={50} clockwise={false} startAngle={90} />
<LhCircleProgress modelValue={88} format={(v) => `${v} 分`} />
<LhCircleProgress modelValue={40} showText={false} />
</>
)
}

Custom text​

By default the center shows the rounded percentage (via formatCircleText). format replaces the text content, and children overrides the default text entirely (aligning with the default slot semantics of other platforms):

<LhCircleProgress modelValue={42} format={(v) => `${v} / 100 分`} />
<LhCircleProgress modelValue={50}>
<em className="my-text">自定义</em>
</LhCircleProgress>

CircleProgress API​

PropDescriptionTypeDefault
modelValueProgress percentage 0-100 (clamped; default 0)number0
sizeRing diameter in pxnumber120
strokeWidthStroke width in pxnumber6
colorProgress color: single color, or an array (2+ entries render a gradient)string | string[]theme token
trackColorTrack color (falls back to the track token)stringtheme token
clockwiseClockwise sweep (false appends scaleX(-1) to the svg transform)booleantrue
startAngleStart angle in degrees (0 = 12 o'clock, clockwise positive)number0
showTextShow the default percentage textbooleantrue
formatText formatter (receives the clamped percentage)(percentage: number) => stringrounded %
linecapStroke endpoint shape'butt' | 'round' | 'square''round'
labelAccessible name (aria-label)string—
childrenOverrides the default text (default slot semantics)ReactNode—
sxQuick layout propsLhSxProps—

Accessibility​

  • The root carries role="progressbar" with aria-valuemin / aria-valuemax / aria-valuenow (the clamped percentage), plus aria-valuetext (the rendered text) so screen readers announce a meaningful value.
  • Provide label when the surrounding context does not describe the task.