feat(notification): support pauseOnHover props (#49024)

This commit is contained in:
Eden Wang 2024-05-27 13:35:37 +08:00 committed by GitHub
parent 57cb8b1a4f
commit 1a250cef7e
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 72 additions and 20 deletions

View File

@ -538,14 +538,34 @@ exports[`renders components/notification/demo/render-panel.tsx extend context co
exports[`renders components/notification/demo/render-panel.tsx extend context correctly 2`] = `[]`; exports[`renders components/notification/demo/render-panel.tsx extend context correctly 2`] = `[]`;
exports[`renders components/notification/demo/show-with-progress.tsx extend context correctly 1`] = ` exports[`renders components/notification/demo/show-with-progress.tsx extend context correctly 1`] = `
<button <div
class="ant-btn ant-btn-primary" class="ant-space ant-space-horizontal ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
type="button"
> >
<span> <div
Open the notification box class="ant-space-item"
</span> >
</button> <button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Pause on hover
</span>
</button>
</div>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Don't pause on hover
</span>
</button>
</div>
</div>
`; `;
exports[`renders components/notification/demo/show-with-progress.tsx extend context correctly 2`] = `[]`; exports[`renders components/notification/demo/show-with-progress.tsx extend context correctly 2`] = `[]`;

View File

@ -524,14 +524,34 @@ exports[`renders components/notification/demo/render-panel.tsx correctly 1`] = `
`; `;
exports[`renders components/notification/demo/show-with-progress.tsx correctly 1`] = ` exports[`renders components/notification/demo/show-with-progress.tsx correctly 1`] = `
<button <div
class="ant-btn ant-btn-primary" class="ant-space ant-space-horizontal ant-space-align-center ant-space-gap-row-small ant-space-gap-col-small"
type="button"
> >
<span> <div
Open the notification box class="ant-space-item"
</span> >
</button> <button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Pause on hover
</span>
</button>
</div>
<div
class="ant-space-item"
>
<button
class="ant-btn ant-btn-primary"
type="button"
>
<span>
Don't pause on hover
</span>
</button>
</div>
</div>
`; `;
exports[`renders components/notification/demo/stack.tsx correctly 1`] = ` exports[`renders components/notification/demo/stack.tsx correctly 1`] = `

View File

@ -1,24 +1,30 @@
import React from 'react'; import React from 'react';
import { Button, notification } from 'antd'; import { Button, Space, notification } from 'antd';
const App: React.FC = () => { const App: React.FC = () => {
const [api, contextHolder] = notification.useNotification(); const [api, contextHolder] = notification.useNotification();
const openNotification = () => { const openNotification = (pauseOnHover: boolean) => () => {
api.open({ api.open({
message: 'Notification Title', message: 'Notification Title',
description: description:
'This is the content of the notification. This is the content of the notification. This is the content of the notification.', 'This is the content of the notification. This is the content of the notification. This is the content of the notification.',
showProgress: true, showProgress: true,
pauseOnHover,
}); });
}; };
return ( return (
<> <>
{contextHolder} {contextHolder}
<Button type="primary" onClick={openNotification}> <Space>
Open the notification box <Button type="primary" onClick={openNotification(true)}>
</Button> Pause on hover
</Button>
<Button type="primary" onClick={openNotification(false)}>
Don&apos;t pause on hover
</Button>
</Space>
</> </>
); );
}; };

View File

@ -55,6 +55,7 @@ The properties of config are as follows:
| description | The content of notification box (required) | ReactNode | - | - | | description | The content of notification box (required) | ReactNode | - | - |
| duration | Time in seconds before Notification is closed. When set to 0 or null, it will never be closed automatically | number | 4.5 | - | | duration | Time in seconds before Notification is closed. When set to 0 or null, it will never be closed automatically | number | 4.5 | - |
| showProgress | Show progress bar for auto-closing notification | boolean | | 5.18.0 | | showProgress | Show progress bar for auto-closing notification | boolean | | 5.18.0 |
| pauseOnHover | keep the timer running or not on hover | boolean | true | 5.18.0 |
| icon | Customized icon | ReactNode | - | - | | icon | Customized icon | ReactNode | - | - |
| key | The unique identifier of the Notification | string | - | - | | key | The unique identifier of the Notification | string | - | - |
| message | The title of notification box (required) | ReactNode | - | - | | message | The title of notification box (required) | ReactNode | - | - |

View File

@ -107,6 +107,7 @@ notification.config({
| closeIcon | 自定义关闭图标 | ReactNode | true | 5.7.0:设置为 null 或 false 时隐藏关闭按钮 | | closeIcon | 自定义关闭图标 | ReactNode | true | 5.7.0:设置为 null 或 false 时隐藏关闭按钮 |
| duration | 默认自动关闭延时,单位秒 | number | 4.5 | | | duration | 默认自动关闭延时,单位秒 | number | 4.5 | |
| showProgress | 显示自动关闭通知框的进度条 | boolean | | 5.18.0 | | showProgress | 显示自动关闭通知框的进度条 | boolean | | 5.18.0 |
| pauseOnHover | 悬停时是否暂停计时器 | boolean | true | 5.18.0 |
| getContainer | 配置渲染节点的输出位置,但依旧为全屏展示 | () => HTMLNode | () => document.body | | | getContainer | 配置渲染节点的输出位置,但依旧为全屏展示 | () => HTMLNode | () => document.body | |
| placement | 弹出位置,可选 `top` `topLeft` `topRight` `bottom` `bottomLeft` `bottomRight` | string | `topRight` | | | placement | 弹出位置,可选 `top` `topLeft` `topRight` `bottom` `bottomLeft` `bottomRight` | string | `topRight` | |
| rtl | 是否开启 RTL 模式 | boolean | false | | | rtl | 是否开启 RTL 模式 | boolean | false | |

View File

@ -26,6 +26,7 @@ export interface ArgsProps {
onClose?: () => void; onClose?: () => void;
duration?: number | null; duration?: number | null;
showProgress?: boolean; showProgress?: boolean;
pauseOnHover?: boolean;
icon?: React.ReactNode; icon?: React.ReactNode;
placement?: NotificationPlacement; placement?: NotificationPlacement;
style?: React.CSSProperties; style?: React.CSSProperties;
@ -54,6 +55,7 @@ export interface GlobalConfigProps {
bottom?: number; bottom?: number;
duration?: number; duration?: number;
showProgress?: boolean; showProgress?: boolean;
pauseOnHover?: boolean;
prefixCls?: string; prefixCls?: string;
getContainer?: () => HTMLElement | ShadowRoot; getContainer?: () => HTMLElement | ShadowRoot;
placement?: NotificationPlacement; placement?: NotificationPlacement;
@ -75,4 +77,5 @@ export interface NotificationConfig {
stack?: boolean | { threshold?: number }; stack?: boolean | { threshold?: number };
duration?: number; duration?: number;
showProgress?: boolean; showProgress?: boolean;
pauseOnHover?: boolean;
} }

View File

@ -89,6 +89,7 @@ const Holder = React.forwardRef<HolderRef, HolderProps>((props, ref) => {
closable: true, closable: true,
closeIcon: getCloseIcon(prefixCls), closeIcon: getCloseIcon(prefixCls),
duration: duration ?? DEFAULT_DURATION, duration: duration ?? DEFAULT_DURATION,
pauseOnHover: true,
getContainer: () => staticGetContainer?.() || getPopupContainer?.() || document.body, getContainer: () => staticGetContainer?.() || getPopupContainer?.() || document.body,
maxCount, maxCount,
onAllRemoved, onAllRemoved,

View File

@ -128,7 +128,7 @@
"rc-mentions": "~2.13.1", "rc-mentions": "~2.13.1",
"rc-menu": "~9.14.0", "rc-menu": "~9.14.0",
"rc-motion": "^2.9.1", "rc-motion": "^2.9.1",
"rc-notification": "~5.5.0", "rc-notification": "~5.6.0",
"rc-pagination": "~4.0.4", "rc-pagination": "~4.0.4",
"rc-picker": "~4.5.0", "rc-picker": "~4.5.0",
"rc-progress": "~4.0.0", "rc-progress": "~4.0.0",