parent
4193d246ba
commit
798aadcc91
@ -0,0 +1,68 @@
|
||||
import { Circle as VCCircle } from '../vc-progress';
|
||||
import { validProgress } from './utils';
|
||||
import { ProgressProps } from './progress';
|
||||
|
||||
const statusColorMap = {
|
||||
normal: '#108ee9',
|
||||
exception: '#ff5500',
|
||||
success: '#87d068',
|
||||
};
|
||||
|
||||
function getPercentage({ percent, successPercent }) {
|
||||
const ptg = validProgress(percent);
|
||||
if (!successPercent) return ptg;
|
||||
|
||||
const successPtg = validProgress(successPercent);
|
||||
return [successPercent, validProgress(ptg - successPtg)];
|
||||
}
|
||||
|
||||
function getStrokeColor({ progressStatus, successPercent, strokeColor }) {
|
||||
const color = strokeColor || statusColorMap[progressStatus];
|
||||
if (!successPercent) return color;
|
||||
return [statusColorMap.success, color];
|
||||
}
|
||||
|
||||
const Circle = {
|
||||
functional: true,
|
||||
render(h, context) {
|
||||
const { props, children } = context;
|
||||
const {
|
||||
prefixCls,
|
||||
width,
|
||||
strokeWidth,
|
||||
trailColor,
|
||||
strokeLinecap,
|
||||
gapPosition,
|
||||
gapDegree,
|
||||
type,
|
||||
} = props;
|
||||
const circleSize = width || 120;
|
||||
const circleStyle = {
|
||||
width: circleSize,
|
||||
height: circleSize,
|
||||
fontSize: circleSize * 0.15 + 6,
|
||||
};
|
||||
const circleWidth = strokeWidth || 6;
|
||||
const gapPos = gapPosition || (type === 'dashboard' && 'bottom') || 'top';
|
||||
const gapDeg = gapDegree || (type === 'dashboard' && 75);
|
||||
|
||||
return (
|
||||
<div class={`${prefixCls}-inner`} style={circleStyle}>
|
||||
<VCCircle
|
||||
percent={getPercentage(props)}
|
||||
strokeWidth={circleWidth}
|
||||
trailWidth={circleWidth}
|
||||
strokeColor={getStrokeColor(props)}
|
||||
strokeLinecap={strokeLinecap}
|
||||
trailColor={trailColor}
|
||||
prefixCls={prefixCls}
|
||||
gapDegree={gapDeg}
|
||||
gapPosition={gapPos}
|
||||
/>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export default Circle;
|
@ -0,0 +1,46 @@
|
||||
import { validProgress } from './utils';
|
||||
import { ProgressProps } from './progress';
|
||||
|
||||
const Line = {
|
||||
functional: true,
|
||||
render(h, context) {
|
||||
const { props, children } = context;
|
||||
const {
|
||||
prefixCls,
|
||||
percent,
|
||||
successPercent,
|
||||
strokeWidth,
|
||||
size,
|
||||
strokeColor,
|
||||
strokeLinecap,
|
||||
} = props;
|
||||
const percentStyle = {
|
||||
width: `${validProgress(percent)}%`,
|
||||
height: strokeWidth || (size === 'small' ? 6 : 8),
|
||||
background: strokeColor,
|
||||
borderRadius: strokeLinecap === 'square' ? 0 : '100px',
|
||||
};
|
||||
const successPercentStyle = {
|
||||
width: `${validProgress(successPercent)}%`,
|
||||
height: strokeWidth || (size === 'small' ? 6 : 8),
|
||||
borderRadius: strokeLinecap === 'square' ? 0 : '100px',
|
||||
};
|
||||
const successSegment =
|
||||
successPercent !== undefined ? (
|
||||
<div class={`${prefixCls}-success-bg`} style={successPercentStyle} />
|
||||
) : null;
|
||||
return (
|
||||
<div>
|
||||
<div class={`${prefixCls}-outer`}>
|
||||
<div class={`${prefixCls}-inner`}>
|
||||
<div class={`${prefixCls}-bg`} style={percentStyle} />
|
||||
{successSegment}
|
||||
</div>
|
||||
</div>
|
||||
{children}
|
||||
</div>
|
||||
);
|
||||
},
|
||||
};
|
||||
|
||||
export default Line;
|
@ -0,0 +1,8 @@
|
||||
export function validProgress(progress) {
|
||||
if (!progress || progress < 0) {
|
||||
return 0;
|
||||
} else if (progress > 100) {
|
||||
return 100;
|
||||
}
|
||||
return progress;
|
||||
};
|
Loading…
Reference in new issue