feat: add waring for props#iconType in component Alert (#18046)

This commit is contained in:
vagusX 2019-08-02 22:50:11 +08:00 committed by 偏右
parent b5e13b2541
commit 6841e059b7
2 changed files with 30 additions and 6 deletions

View File

@ -49,4 +49,19 @@ describe('Alert', () => {
expect(input.getAttribute('role')).toBe('status');
});
});
it('warning for props#iconType', () => {
const warnSpy = jest.spyOn(console, 'error').mockImplementation(() => {});
mount(
<Alert
message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text"
type="warning"
iconType="up"
/>,
);
expect(warnSpy).toHaveBeenCalledWith(
'Warning: [antd: Alert] `iconType` is deprecated. Please use `icon` instead.',
);
warnSpy.mockRestore();
});
});

View File

@ -5,6 +5,7 @@ import Icon, { ThemeType } from '../icon';
import classNames from 'classnames';
import { ConfigConsumer, ConfigConsumerProps } from '../config-provider';
import getDataOrAriaProps from '../_util/getDataOrAriaProps';
import warning from '../_util/warning';
function noop() {}
@ -41,10 +42,20 @@ export interface AlertState {
}
export default class Alert extends React.Component<AlertProps, AlertState> {
state: AlertState = {
closing: true,
closed: false,
};
constructor(props: AlertProps) {
super(props);
warning(
!('iconType' in props),
'Alert',
'`iconType` is deprecated. Please use `icon` instead.',
);
this.state = {
closing: true,
closed: false,
};
}
handleClose = (e: React.MouseEvent<HTMLAnchorElement>) => {
e.preventDefault();
@ -89,8 +100,6 @@ export default class Alert extends React.Component<AlertProps, AlertState> {
type = banner && type === undefined ? 'warning' : type || 'info';
let iconTheme: ThemeType = 'filled';
// should we give a warning?
// warning(!iconType, `The property 'iconType' is deprecated. Use the property 'icon' instead.`);
if (!iconType) {
switch (type) {
case 'success':