ant-design/components/progress/Circle.tsx

98 lines
2.6 KiB
TypeScript
Raw Normal View History

import * as React from 'react';
2019-06-26 17:31:54 +08:00
import classNames from 'classnames';
import type { ProgressProps as RcProgressProps } from 'rc-progress';
2022-06-22 14:57:09 +08:00
import { Circle as RCCircle } from 'rc-progress';
import Tooltip from '../tooltip';
2022-06-22 14:57:09 +08:00
import type { ProgressGradient, ProgressProps } from './progress';
import { getPercentage, getSize, getStrokeColor } from './utils';
const CIRCLE_MIN_STROKE_WIDTH = 3;
const getMinPercent = (width: number): number => (CIRCLE_MIN_STROKE_WIDTH / width) * 100;
export interface CircleProps extends ProgressProps {
prefixCls: string;
children: React.ReactNode;
progressStatus: string;
strokeColor?: string | ProgressGradient;
}
const Circle: React.FC<CircleProps> = (props) => {
const {
prefixCls,
trailColor = null as unknown as string,
strokeLinecap = 'round',
gapPosition,
gapDegree,
width: originWidth = 120,
type,
children,
success,
size = originWidth,
feat: steps support for circular progress bar (#47940) * feat: steps support for circular progress bar * Update components/progress/index.zh-CN.md Co-authored-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/progress.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/__tests__/index.test.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/demo/circle-steps.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update circle-steps.tsx * Update components/progress/progress.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update package.json * Update components/progress/demo/circle-steps.md Co-authored-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> --------- Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: afc163 <afc163@gmail.com>
2024-03-24 18:30:53 +08:00
steps,
} = props;
const [width, height] = getSize(size, 'circle');
let { strokeWidth } = props;
if (strokeWidth === undefined) {
strokeWidth = Math.max(getMinPercent(width), 6);
}
const circleStyle: React.CSSProperties = { width, height, fontSize: width * 0.15 + 6 };
const realGapDegree = React.useMemo<RcProgressProps['gapDegree']>(() => {
// Support gapDeg = 0 when type = 'dashboard'
if (gapDegree || gapDegree === 0) {
return gapDegree;
}
if (type === 'dashboard') {
return 75;
}
return undefined;
}, [gapDegree, type]);
feat: steps support for circular progress bar (#47940) * feat: steps support for circular progress bar * Update components/progress/index.zh-CN.md Co-authored-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/progress.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/__tests__/index.test.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/demo/circle-steps.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update circle-steps.tsx * Update components/progress/progress.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update package.json * Update components/progress/demo/circle-steps.md Co-authored-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> --------- Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: afc163 <afc163@gmail.com>
2024-03-24 18:30:53 +08:00
const percentArray = getPercentage(props);
const gapPos = gapPosition || (type === 'dashboard' && 'bottom') || undefined;
2019-12-04 21:01:55 +08:00
// using className to style stroke color
const isGradient = Object.prototype.toString.call(props.strokeColor) === '[object Object]';
const strokeColor = getStrokeColor({ success, strokeColor: props.strokeColor });
2019-06-26 17:31:54 +08:00
const wrapperClassName = classNames(`${prefixCls}-inner`, {
[`${prefixCls}-circle-gradient`]: isGradient,
});
const circleContent = (
<RCCircle
feat: steps support for circular progress bar (#47940) * feat: steps support for circular progress bar * Update components/progress/index.zh-CN.md Co-authored-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/progress.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/__tests__/index.test.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/demo/circle-steps.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update circle-steps.tsx * Update components/progress/progress.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update package.json * Update components/progress/demo/circle-steps.md Co-authored-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> --------- Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: afc163 <afc163@gmail.com>
2024-03-24 18:30:53 +08:00
steps={steps}
percent={steps ? percentArray[1] : percentArray}
strokeWidth={strokeWidth}
trailWidth={strokeWidth}
feat: steps support for circular progress bar (#47940) * feat: steps support for circular progress bar * Update components/progress/index.zh-CN.md Co-authored-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/progress.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/__tests__/index.test.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/demo/circle-steps.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update circle-steps.tsx * Update components/progress/progress.tsx Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.zh-CN.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update components/progress/index.en-US.md Signed-off-by: lijianan <574980606@qq.com> * Update package.json * Update components/progress/demo/circle-steps.md Co-authored-by: afc163 <afc163@gmail.com> Signed-off-by: lijianan <574980606@qq.com> --------- Signed-off-by: lijianan <574980606@qq.com> Co-authored-by: lijianan <574980606@qq.com> Co-authored-by: afc163 <afc163@gmail.com>
2024-03-24 18:30:53 +08:00
strokeColor={steps ? strokeColor[1] : strokeColor}
strokeLinecap={strokeLinecap}
trailColor={trailColor}
prefixCls={prefixCls}
gapDegree={realGapDegree}
gapPosition={gapPos}
/>
);
const smallCircle = width <= 20;
const node = (
2019-06-26 17:31:54 +08:00
<div className={wrapperClassName} style={circleStyle}>
{circleContent}
{!smallCircle && children}
</div>
);
if (smallCircle) {
return <Tooltip title={children}>{node}</Tooltip>;
}
return node;
};
export default Circle;