@rc-component/progress

repository·master·Indexed 20 days ago

https://github.com/react-component/progress

A 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.

Tokens
3.1K
Snippets
15
Records
16
Agent score
71%

What's inside @rc-component/progress

  1. Configure color gradients for Circle progress

    master

    When 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} ... />
  2. Example: Implement a gradient circle progress component

    master

    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.
  3. Render segmented progress with multiple tracks and colors

    master

    To 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}
      />
    );
  4. Use Line and Circle progress components

    master

    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" />
      </>
    );
  5. Reference shared props for Line and Circle

    master

    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 过渡。 |
  6. Use the Circle progress component

    master

    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.

    Key Features

    • Single/Multiple Percentages: Pass a single number or an array of numbers to percent to show layered progress.
    • Steps Mode: Pass a steps object to divide the circle into equal segments.
    • Loading State: Set loading to true to trigger an indeterminate animation.
    • Gaps: Use gapDegree to create a gap in the progress ring.
    • Custom Styling: Use 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} />
  7. Configure Progress component props

    master

    The Progress component accepts a ProgressProps object to control its appearance, behavior, and styling. Key configuration options include:

    • Value & State:
      • 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.
    • Styling & Colors:
      • 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').
    • Layout & Gaps:
      • 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'.
    • Interaction:
      • onClick: A React.MouseEventHandler for click events on the component.
    <Progress 
      percent={50} 
      strokeColor="#1890ff" 
      strokeWidth={10} 
      railWidth={10} 
      strokeLinecap="round"
    />
  8. Import Progress components

    master

    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';
  9. Reference StrokeColorType configurations

    master

    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[];