mirror of
https://github.com/ant-design/ant-design.git
synced 2025-08-06 16:06:28 +08:00
fix: Progress steps support trailColor (#26323)
* fix: Progress steps support trailColor close #26316 * add test case * add test case
This commit is contained in:
parent
63816fa6ba
commit
d839cb1af9
@ -6,10 +6,20 @@ interface StepsProps extends ProgressProps {
|
|||||||
steps: number;
|
steps: number;
|
||||||
size?: ProgressSize;
|
size?: ProgressSize;
|
||||||
strokeColor?: string;
|
strokeColor?: string;
|
||||||
|
trailColor?: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Steps: React.FC<StepsProps> = props => {
|
const Steps: React.FC<StepsProps> = props => {
|
||||||
const { size, steps, percent = 0, strokeWidth = 8, strokeColor, prefixCls, children } = props;
|
const {
|
||||||
|
size,
|
||||||
|
steps,
|
||||||
|
percent = 0,
|
||||||
|
strokeWidth = 8,
|
||||||
|
strokeColor,
|
||||||
|
trailColor,
|
||||||
|
prefixCls,
|
||||||
|
children,
|
||||||
|
} = props;
|
||||||
const current = Math.floor(steps * (percent / 100));
|
const current = Math.floor(steps * (percent / 100));
|
||||||
const stepWidth = size === 'small' ? 2 : 14;
|
const stepWidth = size === 'small' ? 2 : 14;
|
||||||
const styledSteps = [];
|
const styledSteps = [];
|
||||||
@ -21,7 +31,7 @@ const Steps: React.FC<StepsProps> = props => {
|
|||||||
[`${prefixCls}-steps-item-active`]: i <= current - 1,
|
[`${prefixCls}-steps-item-active`]: i <= current - 1,
|
||||||
})}
|
})}
|
||||||
style={{
|
style={{
|
||||||
backgroundColor: i <= current - 1 ? strokeColor : undefined,
|
backgroundColor: i <= current - 1 ? strokeColor : trailColor,
|
||||||
width: stepWidth,
|
width: stepWidth,
|
||||||
height: strokeWidth,
|
height: strokeWidth,
|
||||||
}}
|
}}
|
||||||
|
@ -608,3 +608,9 @@ exports[`Progress should support steps 1`] = `
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
|
exports[`Progress steps should have default percent 0 1`] = `
|
||||||
|
<div
|
||||||
|
class="undefined-steps-outer"
|
||||||
|
/>
|
||||||
|
`;
|
||||||
|
@ -2,6 +2,7 @@ import React from 'react';
|
|||||||
import { mount } from 'enzyme';
|
import { mount } from 'enzyme';
|
||||||
import Progress from '..';
|
import Progress from '..';
|
||||||
import { handleGradient, sortGradient } from '../Line';
|
import { handleGradient, sortGradient } from '../Line';
|
||||||
|
import ProgressSteps from '../Steps';
|
||||||
import mountTest from '../../../tests/shared/mountTest';
|
import mountTest from '../../../tests/shared/mountTest';
|
||||||
import rtlTest from '../../../tests/shared/rtlTest';
|
import rtlTest from '../../../tests/shared/rtlTest';
|
||||||
|
|
||||||
@ -167,6 +168,18 @@ describe('Progress', () => {
|
|||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('steps should support trailColor', () => {
|
||||||
|
const wrapper = mount(<Progress steps={5} percent={20} trailColor="#1890ee" />);
|
||||||
|
expect(wrapper.find('.ant-progress-steps-item').at(1).getDOMNode().style.backgroundColor).toBe(
|
||||||
|
'rgb(24, 144, 238)',
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('steps should have default percent 0', () => {
|
||||||
|
const wrapper = mount(<ProgressSteps />);
|
||||||
|
expect(wrapper.render()).toMatchSnapshot();
|
||||||
|
});
|
||||||
|
|
||||||
it('should warnning if use `progress` in success', () => {
|
it('should warnning if use `progress` in success', () => {
|
||||||
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
mount(<Progress percent={60} success={{ progress: 30 }} />);
|
mount(<Progress percent={60} success={{ progress: 30 }} />);
|
||||||
|
Loading…
Reference in New Issue
Block a user