mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 09:26:06 +08:00
chore: simplify strokeWidth code (#38733)
This commit is contained in:
parent
d32a1fe274
commit
ff73eb9eb1
@ -1,4 +1,5 @@
|
|||||||
import classNames from 'classnames';
|
import classNames from 'classnames';
|
||||||
|
import type { ProgressProps as RcProgressProps } from 'rc-progress';
|
||||||
import { Circle as RCCircle } from 'rc-progress';
|
import { Circle as RCCircle } from 'rc-progress';
|
||||||
import * as React from 'react';
|
import * as React from 'react';
|
||||||
import Tooltip from '../tooltip';
|
import Tooltip from '../tooltip';
|
||||||
@ -19,8 +20,8 @@ export interface CircleProps extends ProgressProps {
|
|||||||
const Circle: React.FC<CircleProps> = (props) => {
|
const Circle: React.FC<CircleProps> = (props) => {
|
||||||
const {
|
const {
|
||||||
prefixCls,
|
prefixCls,
|
||||||
width,
|
width = 120,
|
||||||
strokeWidth,
|
strokeWidth = Math.max(getMinPercent(width), 6),
|
||||||
trailColor = null as unknown as string,
|
trailColor = null as unknown as string,
|
||||||
strokeLinecap = 'round',
|
strokeLinecap = 'round',
|
||||||
gapPosition,
|
gapPosition,
|
||||||
@ -30,22 +31,9 @@ const Circle: React.FC<CircleProps> = (props) => {
|
|||||||
success,
|
success,
|
||||||
} = props;
|
} = props;
|
||||||
|
|
||||||
const circleSize = width || 120;
|
const circleStyle: React.CSSProperties = { width, height: width, fontSize: width * 0.15 + 6 };
|
||||||
|
|
||||||
const circleStyle: React.CSSProperties = {
|
const realGapDegree = React.useMemo<RcProgressProps['gapDegree']>(() => {
|
||||||
width: circleSize,
|
|
||||||
height: circleSize,
|
|
||||||
fontSize: circleSize * 0.15 + 6,
|
|
||||||
};
|
|
||||||
|
|
||||||
const memoizedStrokeWidth = React.useMemo<number>(() => {
|
|
||||||
if (!strokeWidth) {
|
|
||||||
return Math.max(getMinPercent(circleSize), 6);
|
|
||||||
}
|
|
||||||
return strokeWidth;
|
|
||||||
}, [circleSize, strokeWidth]);
|
|
||||||
|
|
||||||
const getGapDegree = React.useMemo<number | undefined>(() => {
|
|
||||||
// Support gapDeg = 0 when type = 'dashboard'
|
// Support gapDeg = 0 when type = 'dashboard'
|
||||||
if (gapDegree || gapDegree === 0) {
|
if (gapDegree || gapDegree === 0) {
|
||||||
return gapDegree;
|
return gapDegree;
|
||||||
@ -69,20 +57,20 @@ const Circle: React.FC<CircleProps> = (props) => {
|
|||||||
const circleContent = (
|
const circleContent = (
|
||||||
<RCCircle
|
<RCCircle
|
||||||
percent={getPercentage(props)}
|
percent={getPercentage(props)}
|
||||||
strokeWidth={memoizedStrokeWidth}
|
strokeWidth={strokeWidth}
|
||||||
trailWidth={memoizedStrokeWidth}
|
trailWidth={strokeWidth}
|
||||||
strokeColor={strokeColor}
|
strokeColor={strokeColor}
|
||||||
strokeLinecap={strokeLinecap}
|
strokeLinecap={strokeLinecap}
|
||||||
trailColor={trailColor}
|
trailColor={trailColor}
|
||||||
prefixCls={prefixCls}
|
prefixCls={prefixCls}
|
||||||
gapDegree={getGapDegree}
|
gapDegree={realGapDegree}
|
||||||
gapPosition={gapPos}
|
gapPosition={gapPos}
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={wrapperClassName} style={circleStyle}>
|
<div className={wrapperClassName} style={circleStyle}>
|
||||||
{circleSize <= 20 ? (
|
{width <= 20 ? (
|
||||||
<Tooltip title={children}>{circleContent}</Tooltip>
|
<Tooltip title={children}>{circleContent}</Tooltip>
|
||||||
) : (
|
) : (
|
||||||
<>
|
<>
|
||||||
|
Loading…
Reference in New Issue
Block a user