2016-03-31 09:40:55 +08:00
|
|
|
---
|
|
|
|
order: 2
|
2016-08-28 17:45:27 +08:00
|
|
|
title:
|
|
|
|
zh-CN: 带有图标的通知提醒框
|
|
|
|
en-US: Notification with icon
|
2016-03-31 09:40:55 +08:00
|
|
|
---
|
2015-07-28 15:40:28 +08:00
|
|
|
|
2016-08-17 11:07:02 +08:00
|
|
|
## zh-CN
|
|
|
|
|
2015-08-06 15:19:45 +08:00
|
|
|
通知提醒框左侧有图标。
|
2015-07-28 15:40:28 +08:00
|
|
|
|
2016-08-17 11:07:02 +08:00
|
|
|
## en-US
|
|
|
|
|
|
|
|
A notification box with a icon at the left side.
|
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
```tsx
|
2020-04-30 21:04:19 +08:00
|
|
|
import { Button, notification, Space } from 'antd';
|
2022-05-21 22:14:15 +08:00
|
|
|
import React from 'react';
|
2015-07-28 15:40:28 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
type NotificationType = 'success' | 'info' | 'warning' | 'error';
|
|
|
|
|
2022-05-25 10:14:51 +08:00
|
|
|
const App: React.FC = () => {
|
|
|
|
const [api, contextHolder] = notification.useNotification();
|
|
|
|
|
|
|
|
const openNotificationWithIcon = (type: NotificationType) => {
|
|
|
|
api[type]({
|
|
|
|
message: 'Notification Title',
|
|
|
|
description:
|
|
|
|
'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
return (
|
|
|
|
<>
|
|
|
|
{contextHolder}
|
|
|
|
<Space>
|
|
|
|
<Button onClick={() => openNotificationWithIcon('success')}>Success</Button>
|
|
|
|
<Button onClick={() => openNotificationWithIcon('info')}>Info</Button>
|
|
|
|
<Button onClick={() => openNotificationWithIcon('warning')}>Warning</Button>
|
|
|
|
<Button onClick={() => openNotificationWithIcon('error')}>Error</Button>
|
|
|
|
</Space>
|
|
|
|
</>
|
|
|
|
);
|
2016-12-14 17:57:15 +08:00
|
|
|
};
|
2015-08-03 15:17:12 +08:00
|
|
|
|
2022-05-19 09:46:26 +08:00
|
|
|
export default App;
|
2019-05-07 14:57:32 +08:00
|
|
|
```
|