ant-design/components/progress/Steps.tsx
kiner-tang(文辉) da3babbe39
refactor(progress): progress size (#40903)
* feat: progress size

* feat: update snapshots

* feat: update demo

* feat: update demo

* docs: fix lint

* feat: update demo

* feat: update demo

* docs: update doc

* feat: update snapshots

* docs: update doc

* docs: update doc

* docs: update doc

* Update components/progress/index.en-US.md

Co-authored-by: lijianan <574980606@qq.com>

* Update components/progress/index.zh-CN.md

Co-authored-by: lijianan <574980606@qq.com>

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* feat: optimize code

* Update components/progress/utils.ts

Co-authored-by: MadCcc <1075746765@qq.com>

* feat: optimize code

* feat: optimize code

* feat: optimize code

* Update components/progress/Circle.tsx

Co-authored-by: MadCcc <1075746765@qq.com>

* feat: optimize code

* feat: optimize code

* docs: update doc

---------

Co-authored-by: 二货机器人 <smith3816@gmail.com>
Co-authored-by: lijianan <574980606@qq.com>
Co-authored-by: MadCcc <1075746765@qq.com>
2023-03-01 11:49:42 +08:00

54 lines
1.4 KiB
TypeScript

import classNames from 'classnames';
import * as React from 'react';
import type { ProgressProps } from './progress';
import { getSize } from './utils';
interface ProgressStepsProps extends ProgressProps {
steps: number;
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 mergedSize = size ?? [stepWidth, strokeWidth];
const [width, height] = getSize(mergedSize, 'step', { steps, strokeWidth });
const unitWidth = width / steps;
const styledSteps: React.ReactNode[] = new Array(steps);
for (let i = 0; i < steps; i++) {
const color = Array.isArray(strokeColor) ? strokeColor[i] : strokeColor;
styledSteps[i] = (
<div
key={i}
className={classNames(`${prefixCls}-steps-item`, {
[`${prefixCls}-steps-item-active`]: i <= current - 1,
})}
style={{
backgroundColor: i <= current - 1 ? color : trailColor,
width: unitWidth,
height,
}}
/>
);
}
return (
<div className={`${prefixCls}-steps-outer`}>
{styledSteps}
{children}
</div>
);
};
export default Steps;