ant-design/components/notification/demo/with-btn.md
PCCCCCCC 1d09d6fe0c
Replace part of the Demo of the notification with the hooks (#35710)
* docs: modify the part demo to hooks

* docs: modify the part demo to hooks
2022-05-25 10:14:51 +08:00

1.3 KiB

order title
3
zh-CN en-US
自定义按钮 Custom close button

zh-CN

自定义关闭按钮的样式和文字。

en-US

To customize the style or font of the close button.

import { Button, notification, Space } from 'antd';
import React from 'react';

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;