Alert警告提示
当某个页面需要向用户显示警告的信息时。
非浮层的静态展现形式,始终展现,不会自动消失,用户可以点击关闭。
最简单的用法,适用于简短的警告提示。
显示关闭按钮,点击可关闭警告提示。
const onClose = e => {
console.log(e, 'I was closed.');
};
ReactDOM.render(
<div>
<Alert
message="Warning Text Warning Text Warning TextW arning Text Warning Text Warning TextWarning Text"
type="warning"
closable
onClose={onClose}
/>
<Alert
message="Error Text"
description="Error Description Error Description Error Description Error Description Error Description Error Description"
type="error"
closable
onClose={onClose}
/>
</div>,
mountNode,
);
可口的图标让信息类型更加醒目。
页面顶部通告形式,默认有图标且type
为 'warning'。
import { Alert } from 'antd';
ReactDOM.render(
<div>
<br />
<Alert
message="Very long warning text warning text text text text text text text"
banner
closable
/>
<br />
<Alert showIcon={false} message="Warning text without icon" banner />
<Alert type="error" message="Error text" banner />
</div>,
mountNode,
);
共有四种样式 success
、info
、warning
、error
。
含有辅助性文字介绍的警告提示。
import { Alert } from 'antd';
ReactDOM.render(
<div>
<Alert
message="Success Text"
description="Success Description Success Description Success Description"
type="success"
/>
<Alert
message="Info Text"
description="Info Description Info Description Info Description Info Description"
type="info"
/>
<Alert
message="Warning Text"
description="Warning Description Warning Description Warning Description Warning Description"
type="warning"
/>
<Alert
description="Error Description Error Description Error Description Error Description"
type="error"
/>
</div>,
mountNode,
);
可以自定义关闭,自定义的文字会替换原先的关闭 Icon
。
平滑、自然的卸载提示。
import { Alert } from 'antd';
class App extends React.Component {
state = {
visible: true,
};
handleClose = () => {
this.setState({ visible: false });
};
render() {
return (
<div>
{this.state.visible ? (
<Alert
message="Alert Message Text"
type="success"
closable
afterClose={this.handleClose}
/>
) : null}
<p>placeholder text here</p>
</div>
);
}
}
ReactDOM.render(<App />, mountNode);