mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-15 06:21:02 +08:00

* chore: init demo * chore: circle * docs: update * test: update test case * test: coverage * docs: update docs * docs: deprecated trailColor * chore: bump rail * chore: misc * chore: fix style * chore: move pos * chore: refactor structrue * test: fix test case * test: update snapshot * test: fix test case * chore: rm style * test: update snapshot * test: update snapshot * chore: fix steps style
71 lines
1.8 KiB
TypeScript
71 lines
1.8 KiB
TypeScript
import * as React from 'react';
|
|
import cls from 'classnames';
|
|
|
|
import type { ProgressProps } from './progress';
|
|
import { getSize } from './utils';
|
|
|
|
interface ProgressStepsProps extends ProgressProps {
|
|
steps: number;
|
|
strokeColor?: string | string[];
|
|
railColor?: string;
|
|
/** @deprecated Please use `railColor` instead */
|
|
trailColor?: string;
|
|
classNames: Required<ProgressProps>['classNames'];
|
|
styles: Required<ProgressProps>['styles'];
|
|
}
|
|
|
|
const Steps: React.FC<ProgressStepsProps> = (props) => {
|
|
const {
|
|
classNames,
|
|
styles,
|
|
size,
|
|
steps,
|
|
rounding: customRounding = Math.round,
|
|
percent = 0,
|
|
strokeWidth = 8,
|
|
strokeColor,
|
|
railColor,
|
|
trailColor,
|
|
prefixCls,
|
|
children,
|
|
} = props;
|
|
const current = customRounding(steps * (percent / 100));
|
|
const stepWidth = size === 'small' ? 2 : 14;
|
|
const mergedSize = size ?? [stepWidth, strokeWidth];
|
|
const [width, height] = getSize(mergedSize, 'step', { steps, strokeWidth });
|
|
const unitWidth = width / steps;
|
|
const styledSteps = Array.from<React.ReactNode>({ length: steps });
|
|
|
|
const mergedRailColor = railColor ?? trailColor;
|
|
|
|
for (let i = 0; i < steps; i++) {
|
|
const color = Array.isArray(strokeColor) ? strokeColor[i] : strokeColor;
|
|
styledSteps[i] = (
|
|
<div
|
|
key={i}
|
|
className={cls(
|
|
`${prefixCls}-steps-item`,
|
|
{
|
|
[`${prefixCls}-steps-item-active`]: i <= current - 1,
|
|
},
|
|
classNames.track,
|
|
)}
|
|
style={{
|
|
backgroundColor: i <= current - 1 ? color : mergedRailColor,
|
|
width: unitWidth,
|
|
height,
|
|
...styles.track,
|
|
}}
|
|
/>
|
|
);
|
|
}
|
|
return (
|
|
<div className={cls(`${prefixCls}-steps-body`, classNames.body)} style={styles.body}>
|
|
{styledSteps}
|
|
{children}
|
|
</div>
|
|
);
|
|
};
|
|
|
|
export default Steps;
|