import React, { FC, HTMLAttributes } from 'react' import { Flex } from '../flex' import classNames from 'classnames' const radius = 110 // 半径r const diameter = Math.round(Math.PI * radius * 2) // 周长(路径长度) const getOffset = (val = 0): number => Math.round(((100 - Math.min(val, 100)) / 100) * diameter) interface ProgressCircleProps extends HTMLAttributes { percentage: number type?: 'success' | 'danger' size?: number lineWidth?: number disabledText?: boolean } const ProgressCircle: FC = ({ type, percentage, size = 40, lineWidth = 60, disabledText, className, ...rest }) => { const { centerColor, animate, animationDuration, roundedStroke } = { centerColor: 'transparent', animate: false, animationDuration: '1s', roundedStroke: false, } const strokeDashoffset = getOffset(percentage) const transition = animate ? `stroke-dashoffset ${animationDuration} ease-out` : undefined const strokeLinecap = roundedStroke ? 'round' : 'butt' return ( {!disabledText && ( {percentage + '%'} )} ) } export default ProgressCircle export type { ProgressCircleProps }