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';
|
2019-11-22 10:46:33 +08:00
|
|
|
import { ProgressProps, ProgressSize } from './progress';
|
|
|
|
|
|
|
|
interface StepsProps extends ProgressProps {
|
|
|
|
steps: number;
|
|
|
|
size?: ProgressSize;
|
2020-05-29 13:43:53 +08:00
|
|
|
strokeColor?: string;
|
2019-11-22 10:46:33 +08:00
|
|
|
}
|
|
|
|
|
2020-03-28 11:56:57 +08:00
|
|
|
const Steps: React.FC<StepsProps> = props => {
|
2020-05-25 16:27:02 +08:00
|
|
|
const { size, steps, percent = 0, strokeWidth = 8, strokeColor, prefixCls, children } = props;
|
2020-05-29 13:43:53 +08:00
|
|
|
const current = Math.floor(steps * (percent / 100));
|
|
|
|
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={{
|
|
|
|
backgroundColor: i <= current - 1 ? strokeColor : undefined,
|
|
|
|
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;
|