ant-design/components/progress/Steps.tsx
afc163 2113c25664
feat: Progress steps support custom strokeColor for each step (#35855)
* feat: <Progress steps /> could accept string[] as strokeColor

close #35852
close #26858

* fix: tsx demo

* docs: add version column
2022-06-01 23:00:03 +08:00

51 lines
1.2 KiB
TypeScript

import * as React from 'react';
import classNames from 'classnames';
import type { ProgressProps, ProgressSize } from './progress';
interface ProgressStepsProps extends ProgressProps {
steps: number;
size?: ProgressSize;
strokeColor?: string | string[];
trailColor?: string;
}
const Steps: React.FC<ProgressStepsProps> = props => {
const {
size,
steps,
percent = 0,
strokeWidth = 8,
strokeColor,
trailColor = null as any,
prefixCls,
children,
} = props;
const current = Math.round(steps * (percent / 100));
const stepWidth = size === 'small' ? 2 : 14;
const styledSteps = [];
for (let i = 0; i < steps; i += 1) {
const color = Array.isArray(strokeColor) ? strokeColor[i] : strokeColor;
styledSteps.push(
<div
key={i}
className={classNames(`${prefixCls}-steps-item`, {
[`${prefixCls}-steps-item-active`]: i <= current - 1,
})}
style={{
backgroundColor: i <= current - 1 ? color : trailColor,
width: stepWidth,
height: strokeWidth,
}}
/>,
);
}
return (
<div className={`${prefixCls}-steps-outer`}>
{styledSteps}
{children}
</div>
);
};
export default Steps;