Skip to Content
文档

进度圈

用于以循环形式显示任务进度。

SourceStorybookRecipeArk

用法

¥Usage

import { ProgressCircle } from "@chakra-ui/react"
<ProgressCircle.Root>
  <ProgressCircle.Circle>
    <ProgressCircle.Track />
    <ProgressCircle.Range />
  </ProgressCircle.Circle>
  <ProgressCircle.ValueText />
</ProgressCircle.Root>

示例

¥Examples

圆角

¥Rounded

使用 ProgressCircle.Range 上的 strokeLinecap 属性使进度圈的两端变为圆角。

¥Use the strokeLinecap prop on ProgressCircle.Range to make the ends of the progress circle rounded.

尺寸

¥Sizes

使用 size 属性更改进度圈组件的大小。

¥Use the size prop to change the size of the progress circle component.

颜色

¥Colors

使用 colorPalette 属性更改组件的配色方案。

¥Use the colorPalette prop to change the color scheme of the component.

gray

red

green

blue

teal

pink

purple

cyan

orange

yellow

值文本

¥Value Text

渲染 ProgressCircle.ValueText 组件以显示进度值。

¥Render the ProgressCircle.ValueText component to display the progress value.

5%
5%
5%

自定义粗细

¥Custom Thickness

--thickness CSS 变量传递给 ProgressCircleRing 组件,以更改圆环的粗细。

¥Pass the --thickness css variable to the ProgressCircleRing component to change the thickness of the ring.

不确定

¥Indeterminate

value 属性设置为 null 可渲染不确定状态。

¥Set the value prop to null to render the indeterminate state.

颜色

¥Color

stroke 属性传递给 ProgressCircle.Range 组件,即可更改范围的颜色。

¥Pass the stroke prop to the ProgressCircle.Range component to change the color of the range.

已关闭组件

¥Closed Component

以下是如何使用 ProgressCircle 组件创建封闭组件。

¥Here's how to create a closed component using the ProgressCircle component.

import type { SystemStyleObject } from "@chakra-ui/react"
import {
  AbsoluteCenter,
  ProgressCircle as ChakraProgressCircle,
} from "@chakra-ui/react"
import * as React from "react"

interface ProgressCircleProps extends ChakraProgressCircle.RootProps {
  showValueText?: boolean
  valueText?: React.ReactNode
  trackColor?: SystemStyleObject["stroke"]
  cap?: SystemStyleObject["strokeLinecap"]
  thickness?: SystemStyleObject["strokeWidth"]
}

export const ProgressCircle = React.forwardRef<
  HTMLDivElement,
  ProgressCircleProps
>(function ProgressCircle(props, ref) {
  const {
    showValueText,
    valueText,
    trackColor,
    color,
    cap,
    thickness,
    ...rest
  } = props

  return (
    <ChakraProgressCircle.Root {...rest} ref={ref}>
      <ChakraProgressCircle.Circle css={{ "--thickness": thickness }}>
        <ChakraProgressCircle.Track stroke={trackColor} />
        <ChakraProgressCircle.Range stroke={color} strokeLinecap={cap} />
      </ChakraProgressCircle.Circle>
      {showValueText && (
        <AbsoluteCenter>
          <ChakraProgressCircle.ValueText>
            {valueText}
          </ChakraProgressCircle.ValueText>
        </AbsoluteCenter>
      )}
    </ChakraProgressCircle.Root>
  )
})

属性

¥Props

根元素

¥Root

PropDefaultType
colorPalette 'gray'
'gray' | 'red' | 'orange' | 'yellow' | 'green' | 'teal' | 'blue' | 'cyan' | 'purple' | 'pink'

The color palette of the component

size 'md'
'xs' | 'sm' | 'md' | 'lg' | 'xl'

The size of the component

as
React.ElementType

The underlying element to render.

asChild
boolean

Use the provided child element as the default rendered element, combining their props and behavior.

For more details, read our Composition guide.
unstyled
boolean

Whether to remove the component's style.

Previous

空状态

Next

进度