2019-11-22 10:46:33 +08:00
|
|
|
import * as React from 'react';
|
2020-05-29 13:43:53 +08:00
|
|
|
import classNames from 'classnames';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { ProgressProps, ProgressSize } from './progress';
|
2019-11-22 10:46:33 +08:00
|
|
|
|
|
|
|
interface StepsProps extends ProgressProps {
|
|
|
|
steps: number;
|
|
|
|
size?: ProgressSize;
|
2020-05-29 13:43:53 +08:00
|
|
|
strokeColor?: string;
|
2020-08-22 01:29:48 +08:00
|
|
|
trailColor?: string;
|
2019-11-22 10:46:33 +08:00
|
|
|
}
|
|
|
|
|
2020-03-28 11:56:57 +08:00
|
|
|
const Steps: React.FC<StepsProps> = props => {
|
2020-08-22 01:29:48 +08:00
|
|
|
const {
|
|
|
|
size,
|
|
|
|
steps,
|
|
|
|
percent = 0,
|
|
|
|
strokeWidth = 8,
|
|
|
|
strokeColor,
|
2022-05-06 18:34:45 +08:00
|
|
|
trailColor = null as any,
|
2020-08-22 01:29:48 +08:00
|
|
|
prefixCls,
|
|
|
|
children,
|
|
|
|
} = props;
|
2020-12-29 12:20:11 +08:00
|
|
|
const current = Math.round(steps * (percent / 100));
|
2020-05-29 13:43:53 +08:00
|
|
|
const stepWidth = size === 'small' ? 2 : 14;
|
|
|
|
const styledSteps = [];
|
|
|
|
for (let i = 0; i < steps; i += 1) {
|
|
|
|
styledSteps.push(
|
|
|
|
<div
|
|
|
|
key={i}
|
|
|
|
className={classNames(`${prefixCls}-steps-item`, {
|
|
|
|
[`${prefixCls}-steps-item-active`]: i <= current - 1,
|
|
|
|
})}
|
|
|
|
style={{
|
2020-08-22 01:29:48 +08:00
|
|
|
backgroundColor: i <= current - 1 ? strokeColor : trailColor,
|
2020-05-29 13:43:53 +08:00
|
|
|
width: stepWidth,
|
|
|
|
height: strokeWidth,
|
|
|
|
}}
|
|
|
|
/>,
|
|
|
|
);
|
|
|
|
}
|
2019-11-22 10:46:33 +08:00
|
|
|
return (
|
|
|
|
<div className={`${prefixCls}-steps-outer`}>
|
2020-05-29 13:43:53 +08:00
|
|
|
{styledSteps}
|
2019-11-22 10:46:33 +08:00
|
|
|
{children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Steps;
|