Install @rc-component/progress
masterInstall the progress component package using npm:
npm install @rc-component/progressrepository·master·Indexed 20 days ago
https://github.com/react-component/progressA lightweight, SVG-based React UI component library for displaying progress via Line and Circle indicators. Part of the Ant Design ecosystem, it supports single or segmented values, gradient colors, indeterminate loading states, and customizable styling for tracks and rails.
Install the progress component package using npm:
npm install @rc-component/progressWhen using the Circle progress component, you can provide a StrokeColorObject to the color prop to create a color gradient. This object defines color stops based on percentage keys.
To create a gradient, pass an object where the keys are strings representing the percentage (e.g., '0', '50', '100') and the values are valid CSS color strings. The component uses these to generate both conic-gradient and linear-gradient backgrounds to ensure the progress bar renders correctly across different stroke styles.
Note: The component internally calculates the distribution of these colors based on the gapDegree and the total scale of the circle.
// Example of a color gradient configuration
const gradientColor = {
'0': '#ff0000', // Red at 0%
'50': '#00ff00', // Green at 50%
'100': '#0000ff' // Blue at 100%
};
// This would be passed to the progress component's color prop
<Progress color={gradientColor} ... />The gradient-circle demo demonstrates how to create a circular progress indicator with a gradient effect. This typically involves using the Progress component with specific props to define the stroke, color, and shape to achieve a circular appearance.
// Note: The actual implementation is located in ../examples/gradient-circle.tsx
// This demo showcases a circular progress bar with a gradient stroke.The loading demo demonstrates how to use the progress component in a loading state. You can find the source code for this specific implementation in the examples/loading.tsx file.
// See implementation in ../examples/loading.tsxTo render multiple progress tracks simultaneously, pass an array of numbers to the percent prop. You can also pass an array of colors to strokeColor to match the segments.
import { Circle } from '@rc-component/progress';
export default () => (
<Circle
percent={[30, 20, 10]}
strokeWidth={6}
strokeColor={['#1677ff', '#52c41a', '#faad14']}
railWidth={6}
/>
);Import Line and Circle from @rc-component/progress to render linear or circular progress bars. Both components support single values, segmented values (via arrays), gradient colors, and indeterminate loading states.
import { Circle, Line } from '@rc-component/progress';
export default () => (
<>
<Line percent={42} strokeWidth={4} strokeColor="#1677ff" />
<Circle percent={75} strokeWidth={6} strokeColor="#52c41a" />
</>
);Both Line and Circle components share the following properties for configuration and styling:
| 名称 | 类型 | 默认值 | 说明 |
| --- | --- | --- | --- |
| `className` | string | - | 根节点的附加 className。 |
| `classNames` | Partial<Record<'root' \| 'rail' \| 'track', string>> | - | 内部插槽的语义化 className。 |
| `gapDegree` | number | - | 环形进度缺口角度。 |
| `gapPosition` | `'top'` \| `'right'` \| `'bottom'` \| `'left'` | `'bottom'` | 循环进度的间隙位置。 |
| `id` | string | - | 根元素 ID。 |
| `loading` | boolean | false | 渲染不确定的加载动画。 |
| `onClick` | React.MouseEventHandler | - | 单击根 SVG 的处理程序。 |
| `percent` | number \| number[] | 0 | 进度百分比。数组会渲染多条轨道。 |
| `prefixCls` | string | `'rc-progress'` | 前缀 className。 |
| `railColor` | string | `'#D9D9D9'` | 导轨颜色。 |
| `railWidth` | number | 1 | 导轨行程宽度。 |
| `steps` | number \| { count: number; gap: number } | - | 以离散步骤渲染进度。 |
| `strokeColor` | string \| Record<string, string \| boolean> \| Array<string \| Record<string, string \| boolean>> | `'#2db7f5'` | 轨道颜色、渐变对象或每条轨道的颜色。 |
| `strokeLinecap` | `'round'` \| `'butt'` \| `'square'` | `'round'` | 描边端点样式。 |
| `strokeWidth` | number | 1 | 轨道描边宽度。 |
| `style` | React.CSSProperties | - | 根样式。 |
| `styles` | Partial<Record<'root' \| 'rail' \| 'track', React.CSSProperties>> | - | 内部插槽的语义化样式。 |
| `transition` | string | - | 用于跟踪更新的 CSS 过渡。 |The Circle component renders a circular progress indicator. It supports single or multiple percentage values, segmented steps, and loading states. You can customize its appearance using props like strokeWidth, railWidth, strokeColor, and railColor.
percent to show layered progress.steps object to divide the circle into equal segments.loading to true to trigger an indeterminate animation.gapDegree to create a gap in the progress ring.classNames and styles to target specific parts of the component like the root, track, or rail.import Circle from '@rc-component/progress/lib/Circle';
// Basic usage
<Circle percent={50} />
// Multiple layers
<Circle percent={[30, 50]} strokeColor={['#1890ff', '#1890ff']} />
// Steps mode
<Circle
percent={50}
steps={{ count: 4, gap: 2 }}
strokeColor={['#1890ff']}
/>
// Loading state
<Circle loading percent={50} />The Progress component accepts a ProgressProps object to control its appearance, behavior, and styling. Key configuration options include:
percent: The progress value. Accepts a single number or an array of number[] for multi-segment progress.loading: A boolean to indicate a loading state.strokeColor: Defines the color of the progress bar. Can be a string, a StrokeColorObject, or an array of these types.railColor: A string defining the color of the track.strokeWidth: A number for the thickness of the progress line.railWidth: A number for the thickness of the track.strokeLinecap: Controls the end of the stroke. Options: 'round', 'butt', or 'square'.styles: A partial record of React.CSSProperties mapped to SemanticName ('root', 'rail', or 'track').classNames: A partial record of CSS class strings mapped to SemanticName ('root', 'rail', or 'track').steps: Defines segmenting. Can be a number or an object { count: number; gap: number }.gapDegree: A number defining the size of gaps between segments.gapPosition: The position of gaps. Options: 'top', 'right', 'bottom', or 'left'.onClick: A React.MouseEventHandler for click events on the component.<Progress
percent={50}
strokeColor="#1890ff"
strokeWidth={10}
railWidth={10}
strokeLinecap="round"
/>The @rc-component/progress package provides two main visual progress components: Line for linear progress bars and Circle for circular progress indicators. You can import them directly from the package entrypoint.
import { Line, Circle, ProgressProps } from '@rc-component/progress';The strokeColor prop supports several formats for defining colors, including single colors, objects for conditional coloring, or arrays for multi-segment progress.
export type StrokeColorObject = Record<string, string | boolean>;
export type BaseStrokeColorType = string | StrokeColorObject;
export type StrokeColorType = BaseStrokeColorType | BaseStrokeColorType[];When using the classNames or styles props, you can target specific parts of the progress component using these semantic keys:
export type SemanticName = 'root' | 'rail' | 'track';