mirror of
https://github.com/ant-design/ant-design.git
synced 2025-06-07 17:44:35 +08:00
fix: change progress to percent in success props & warning in Progress (#25356)
* fix: warning in Progress * feat: update api * feat: update * update * update demo * feat: add test case * update test case
This commit is contained in:
parent
6d5c3fe953
commit
2ad8fec45d
@ -12,9 +12,13 @@ interface CircleProps extends ProgressProps {
|
|||||||
|
|
||||||
function getPercentage({ percent, success, successPercent }: CircleProps) {
|
function getPercentage({ percent, success, successPercent }: CircleProps) {
|
||||||
const ptg = validProgress(percent);
|
const ptg = validProgress(percent);
|
||||||
|
/** @deprecated Use `percent` instead */
|
||||||
if (success && 'progress' in success) {
|
if (success && 'progress' in success) {
|
||||||
successPercent = success.progress;
|
successPercent = success.progress;
|
||||||
}
|
}
|
||||||
|
if (success && 'percent' in success) {
|
||||||
|
successPercent = success.percent;
|
||||||
|
}
|
||||||
if (!successPercent) {
|
if (!successPercent) {
|
||||||
return ptg;
|
return ptg;
|
||||||
}
|
}
|
||||||
@ -25,9 +29,13 @@ function getPercentage({ percent, success, successPercent }: CircleProps) {
|
|||||||
|
|
||||||
function getStrokeColor({ success, strokeColor, successPercent }: CircleProps) {
|
function getStrokeColor({ success, strokeColor, successPercent }: CircleProps) {
|
||||||
const color = strokeColor || null;
|
const color = strokeColor || null;
|
||||||
|
/** @deprecated Use `percent` instead */
|
||||||
if (success && 'progress' in success) {
|
if (success && 'progress' in success) {
|
||||||
successPercent = success.progress;
|
successPercent = success.progress;
|
||||||
}
|
}
|
||||||
|
if (success && 'percent' in success) {
|
||||||
|
successPercent = success.percent;
|
||||||
|
}
|
||||||
if (!successPercent) {
|
if (!successPercent) {
|
||||||
return color;
|
return color;
|
||||||
}
|
}
|
||||||
|
@ -105,10 +105,15 @@ const Line: React.FC<LineProps> = props => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let { successPercent } = props;
|
let { successPercent } = props;
|
||||||
|
/** @deprecated Use `percent` instead */
|
||||||
if (success && 'progress' in success) {
|
if (success && 'progress' in success) {
|
||||||
successPercent = success.progress;
|
successPercent = success.progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (success && 'percent' in success) {
|
||||||
|
successPercent = success.percent;
|
||||||
|
}
|
||||||
|
|
||||||
let successPercentStyle = {
|
let successPercentStyle = {
|
||||||
width: `${validProgress(successPercent)}%`,
|
width: `${validProgress(successPercent)}%`,
|
||||||
height: strokeWidth || (size === 'small' ? 6 : 8),
|
height: strokeWidth || (size === 'small' ? 6 : 8),
|
||||||
|
@ -6,17 +6,18 @@ import mountTest from '../../../tests/shared/mountTest';
|
|||||||
import rtlTest from '../../../tests/shared/rtlTest';
|
import rtlTest from '../../../tests/shared/rtlTest';
|
||||||
|
|
||||||
describe('Progress', () => {
|
describe('Progress', () => {
|
||||||
|
|
||||||
mountTest(Progress);
|
mountTest(Progress);
|
||||||
rtlTest(Progress);
|
rtlTest(Progress);
|
||||||
|
|
||||||
it('successPercent should decide the progress status when it exists', () => {
|
it('successPercent should decide the progress status when it exists', () => {
|
||||||
const wrapper = mount(<Progress percent={100} success={{ progress: 50 }} />);
|
const wrapper = mount(<Progress percent={100} success={{ percent: 50 }} />);
|
||||||
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(0);
|
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(0);
|
||||||
|
|
||||||
wrapper.setProps({ percent: 50, success: { progress: 100 } });
|
wrapper.setProps({ percent: 50, success: { percent: 100 } });
|
||||||
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(1);
|
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(1);
|
||||||
|
|
||||||
wrapper.setProps({ percent: 100, success: { progress: 0 } });
|
wrapper.setProps({ percent: 100, success: { percent: 0 } });
|
||||||
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(0);
|
expect(wrapper.find('.ant-progress-status-success')).toHaveLength(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -36,7 +37,7 @@ describe('Progress', () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
it('render negative successPercent', () => {
|
it('render negative successPercent', () => {
|
||||||
const wrapper = mount(<Progress percent={50} success={{ progress: -20 }} />);
|
const wrapper = mount(<Progress percent={50} success={{ percent: -20 }} />);
|
||||||
expect(wrapper.render()).toMatchSnapshot();
|
expect(wrapper.render()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -44,7 +45,7 @@ describe('Progress', () => {
|
|||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<Progress
|
<Progress
|
||||||
percent={50}
|
percent={50}
|
||||||
success={{ progress: 10 }}
|
success={{ percent: 10 }}
|
||||||
format={(percent, successPercent) => `${percent} ${successPercent}`}
|
format={(percent, successPercent) => `${percent} ${successPercent}`}
|
||||||
/>,
|
/>,
|
||||||
);
|
);
|
||||||
@ -83,7 +84,7 @@ describe('Progress', () => {
|
|||||||
|
|
||||||
it('render successColor progress', () => {
|
it('render successColor progress', () => {
|
||||||
const wrapper = mount(
|
const wrapper = mount(
|
||||||
<Progress percent={60} success={{ progress: 30, strokeColor: '#ffffff' }} />,
|
<Progress percent={60} success={{ percent: 30, strokeColor: '#ffffff' }} />,
|
||||||
);
|
);
|
||||||
expect(wrapper.render()).toMatchSnapshot();
|
expect(wrapper.render()).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
@ -166,4 +167,24 @@ describe('Progress', () => {
|
|||||||
'rgb(24, 144, 255)',
|
'rgb(24, 144, 255)',
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should warnning if use `progress` in success', () => {
|
||||||
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
|
mount(
|
||||||
|
<Progress percent={60} success={{ progress: 30 }} />,
|
||||||
|
);
|
||||||
|
expect(errorSpy).toHaveBeenCalledWith(
|
||||||
|
'Warning: [antd: Progress] `success.progress` is deprecated. Please use `success.percent` instead.',
|
||||||
|
);
|
||||||
|
})
|
||||||
|
|
||||||
|
it ('should warnning if use `progress` in success in type Circle', () => {
|
||||||
|
const errorSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
|
||||||
|
mount(
|
||||||
|
<Progress percent={60} success={{ progress: 30 }} type="circle"/>,
|
||||||
|
);
|
||||||
|
expect(errorSpy).toHaveBeenCalledWith(
|
||||||
|
'Warning: [antd: Progress] `success.progress` is deprecated. Please use `success.percent` instead.',
|
||||||
|
);
|
||||||
|
})
|
||||||
});
|
});
|
||||||
|
@ -19,15 +19,15 @@ import { Tooltip, Progress } from 'antd';
|
|||||||
ReactDOM.render(
|
ReactDOM.render(
|
||||||
<>
|
<>
|
||||||
<Tooltip title="3 done / 3 in progress / 4 to do">
|
<Tooltip title="3 done / 3 in progress / 4 to do">
|
||||||
<Progress percent={60} success={{ progress: 30 }} />
|
<Progress percent={60} success={{ percent: 30 }} />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
<Tooltip title="3 done / 3 in progress / 4 to do">
|
<Tooltip title="3 done / 3 in progress / 4 to do">
|
||||||
<Progress percent={60} success={{ progress: 30 }} type="circle" />
|
<Progress percent={60} success={{ percent: 30 }} type="circle" />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
|
|
||||||
<Tooltip title="3 done / 3 in progress / 4 to do">
|
<Tooltip title="3 done / 3 in progress / 4 to do">
|
||||||
<Progress percent={60} success={{ progress: 30 }} type="dashboard" />
|
<Progress percent={60} success={{ percent: 30 }} type="dashboard" />
|
||||||
</Tooltip>
|
</Tooltip>
|
||||||
</>,
|
</>,
|
||||||
mountNode,
|
mountNode,
|
||||||
|
@ -28,7 +28,7 @@ Properties that shared by all types.
|
|||||||
| strokeLinecap | to set the style of the progress linecap | `round` \| `square` | `round` |
|
| strokeLinecap | to set the style of the progress linecap | `round` \| `square` | `round` |
|
||||||
| strokeColor | color of progress bar | string | - |
|
| strokeColor | color of progress bar | string | - |
|
||||||
| trailColor | color of unfilled part | string | - |
|
| trailColor | color of unfilled part | string | - |
|
||||||
| success | configs of successfully progress bar | { progress: number, strokeColor: string } | - |
|
| success | configs of successfully progress bar | { percent: number, strokeColor: string } | - |
|
||||||
|
|
||||||
### `type="line"`
|
### `type="line"`
|
||||||
|
|
||||||
|
@ -29,7 +29,7 @@ cover: https://gw.alipayobjects.com/zos/alicdn/xqsDu4ZyR/Progress.svg
|
|||||||
| strokeLinecap | - | `round` \| `square` | `round` |
|
| strokeLinecap | - | `round` \| `square` | `round` |
|
||||||
| strokeColor | 进度条的色彩 | string | - |
|
| strokeColor | 进度条的色彩 | string | - |
|
||||||
| trailColor | 未完成的分段的颜色 | string | - |
|
| trailColor | 未完成的分段的颜色 | string | - |
|
||||||
| success | 成功进度条相关配置 | { progress: number, strokeColor: string } | - |
|
| success | 成功进度条相关配置 | { percent: number, strokeColor: string } | - |
|
||||||
|
|
||||||
### `type="line"`
|
### `type="line"`
|
||||||
|
|
||||||
|
@ -23,6 +23,8 @@ type FromToGradients = { from: string; to: string };
|
|||||||
export type ProgressGradient = { direction?: string } & (StringGradients | FromToGradients);
|
export type ProgressGradient = { direction?: string } & (StringGradients | FromToGradients);
|
||||||
|
|
||||||
export interface SuccessProps {
|
export interface SuccessProps {
|
||||||
|
percent?: number;
|
||||||
|
/** @deprecated Use `percent` instead */
|
||||||
progress?: number;
|
progress?: number;
|
||||||
strokeColor?: string;
|
strokeColor?: string;
|
||||||
}
|
}
|
||||||
@ -65,9 +67,13 @@ export default class Progress extends React.Component<ProgressProps> {
|
|||||||
getPercentNumber() {
|
getPercentNumber() {
|
||||||
const { percent = 0, success } = this.props;
|
const { percent = 0, success } = this.props;
|
||||||
let { successPercent } = this.props;
|
let { successPercent } = this.props;
|
||||||
|
/** @deprecated Use `percent` instead */
|
||||||
if (success && 'progress' in success) {
|
if (success && 'progress' in success) {
|
||||||
successPercent = success.progress;
|
successPercent = success.progress;
|
||||||
}
|
}
|
||||||
|
if (success && 'percent' in success) {
|
||||||
|
successPercent = success.percent;
|
||||||
|
}
|
||||||
return parseInt(
|
return parseInt(
|
||||||
successPercent !== undefined ? successPercent.toString() : percent.toString(),
|
successPercent !== undefined ? successPercent.toString() : percent.toString(),
|
||||||
10,
|
10,
|
||||||
@ -86,8 +92,12 @@ export default class Progress extends React.Component<ProgressProps> {
|
|||||||
const { showInfo, format, type, percent, success } = this.props;
|
const { showInfo, format, type, percent, success } = this.props;
|
||||||
let { successPercent } = this.props;
|
let { successPercent } = this.props;
|
||||||
if (success && 'progress' in success) {
|
if (success && 'progress' in success) {
|
||||||
|
devWarning(false, 'Progress', '`success.progress` is deprecated. Please use `success.percent` instead.');
|
||||||
successPercent = success.progress;
|
successPercent = success.progress;
|
||||||
}
|
}
|
||||||
|
if (success && 'percent' in success) {
|
||||||
|
successPercent = success.percent;
|
||||||
|
}
|
||||||
if (!showInfo) return null;
|
if (!showInfo) return null;
|
||||||
|
|
||||||
let text;
|
let text;
|
||||||
@ -124,7 +134,7 @@ export default class Progress extends React.Component<ProgressProps> {
|
|||||||
const progressInfo = this.renderProcessInfo(prefixCls, progressStatus);
|
const progressInfo = this.renderProcessInfo(prefixCls, progressStatus);
|
||||||
|
|
||||||
devWarning(
|
devWarning(
|
||||||
'successPercent' in props,
|
!('successPercent' in props),
|
||||||
'Progress',
|
'Progress',
|
||||||
'`successPercent` is deprecated. Please use `success` instead.',
|
'`successPercent` is deprecated. Please use `success` instead.',
|
||||||
);
|
);
|
||||||
|
Loading…
Reference in New Issue
Block a user