2020-05-29 13:43:53 +08:00
|
|
|
import classNames from 'classnames';
|
2023-05-06 15:49:37 +08:00
|
|
|
import * as React from 'react';
|
2023-03-01 11:49:42 +08:00
|
|
|
import type { ProgressProps } from './progress';
|
|
|
|
import { getSize } from './utils';
|
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;
|
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-11-19 13:47:33 +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;
|
2023-03-01 11:49:42 +08:00
|
|
|
const mergedSize = size ?? [stepWidth, strokeWidth];
|
|
|
|
const [width, height] = getSize(mergedSize, 'step', { steps, strokeWidth });
|
|
|
|
const unitWidth = width / steps;
|
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,
|
2023-03-01 11:49:42 +08:00
|
|
|
width: unitWidth,
|
|
|
|
height,
|
2020-05-29 13:43:53 +08:00
|
|
|
}}
|
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;
|