You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
46 lines
1.1 KiB
46 lines
1.1 KiB
2 years ago
|
import React from 'react';
|
||
|
import { Button, notification, Space } from 'antd';
|
||
|
|
||
|
const close = () => {
|
||
|
console.log(
|
||
|
'Notification was closed. Either the close button was clicked or duration time elapsed.',
|
||
|
);
|
||
|
};
|
||
|
|
||
|
const App: React.FC = () => {
|
||
|
const [api, contextHolder] = notification.useNotification();
|
||
|
|
||
|
const openNotification = () => {
|
||
|
const key = `open${Date.now()}`;
|
||
|
const btn = (
|
||
|
<Space>
|
||
|
<Button type="link" size="small" onClick={() => notification.destroy()}>
|
||
|
Destroy All
|
||
|
</Button>
|
||
|
<Button type="primary" size="small" onClick={() => notification.destroy(key)}>
|
||
|
Confirm
|
||
|
</Button>
|
||
|
</Space>
|
||
|
);
|
||
|
api.open({
|
||
|
message: 'Notification Title',
|
||
|
description:
|
||
|
'A function will be be called after the notification is closed (automatically after the "duration" time of manually).',
|
||
|
btn,
|
||
|
key,
|
||
|
onClose: close,
|
||
|
});
|
||
|
};
|
||
|
|
||
|
return (
|
||
|
<>
|
||
|
{contextHolder}
|
||
|
<Button type="primary" onClick={openNotification}>
|
||
|
Open the notification box
|
||
|
</Button>
|
||
|
</>
|
||
|
);
|
||
|
};
|
||
|
|
||
|
export default App;
|