2020-05-29 13:43:53 +08:00
|
|
|
import classNames from 'classnames';
|
2022-06-22 10:06:02 +08:00
|
|
|
import * as React from 'react';
|
2022-05-07 14:31:54 +08:00
|
|
|
import type { ProgressProps, ProgressSize } from './progress';
|
2019-11-22 10:46:33 +08:00
|
|
|
|
2022-06-01 23:00:03 +08:00
|
|
|
interface ProgressStepsProps extends ProgressProps {
|
2019-11-22 10:46:33 +08:00
|
|
|
steps: number;
|
|
|
|
size?: ProgressSize;
|
2022-06-01 23:00:03 +08:00
|
|
|
strokeColor?: string | string[];
|
2020-08-22 01:29:48 +08:00
|
|
|
trailColor?: string;
|
2019-11-22 10:46:33 +08:00
|
|
|
}
|
|
|
|
|
2022-06-01 23:00:03 +08:00
|
|
|
const Steps: React.FC<ProgressStepsProps> = 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;
|
2022-06-22 10:06:02 +08:00
|
|
|
const styledSteps: React.ReactNode[] = new Array(steps);
|
|
|
|
for (let i = 0; i < steps; i++) {
|
2022-06-01 23:00:03 +08:00
|
|
|
const color = Array.isArray(strokeColor) ? strokeColor[i] : strokeColor;
|
2022-06-22 10:06:02 +08:00
|
|
|
styledSteps[i] = (
|
2020-05-29 13:43:53 +08:00
|
|
|
<div
|
|
|
|
key={i}
|
|
|
|
className={classNames(`${prefixCls}-steps-item`, {
|
|
|
|
[`${prefixCls}-steps-item-active`]: i <= current - 1,
|
|
|
|
})}
|
|
|
|
style={{
|
2022-06-01 23:00:03 +08:00
|
|
|
backgroundColor: i <= current - 1 ? color : trailColor,
|
2020-05-29 13:43:53 +08:00
|
|
|
width: stepWidth,
|
|
|
|
height: strokeWidth,
|
|
|
|
}}
|
2022-06-22 10:06:02 +08:00
|
|
|
/>
|
2020-05-29 13:43:53 +08:00
|
|
|
);
|
|
|
|
}
|
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;
|