From 550396cb283bcf64f7b0515d470ecb3c4efd88a4 Mon Sep 17 00:00:00 2001 From: "dependabot-preview[bot]" <27856297+dependabot-preview[bot]@users.noreply.github.com> Date: Mon, 8 Mar 2021 21:17:05 +0000 Subject: [PATCH 1/2] build(deps-dev): bump @types/react-dom from 16.9.11 to 17.0.2 Bumps [@types/react-dom](https://github.com/DefinitelyTyped/DefinitelyTyped/tree/HEAD/types/react-dom) from 16.9.11 to 17.0.2. - [Release notes](https://github.com/DefinitelyTyped/DefinitelyTyped/releases) - [Commits](https://github.com/DefinitelyTyped/DefinitelyTyped/commits/HEAD/types/react-dom) Signed-off-by: dependabot-preview[bot] --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 2e17fb7..c7b0777 100644 --- a/package.json +++ b/package.json @@ -53,7 +53,7 @@ "@types/enzyme": "^3.10.7", "@types/jest": "^26.0.4", "@types/react": "^16.9.34", - "@types/react-dom": "^16.9.7", + "@types/react-dom": "^17.0.2", "cross-env": "^7.0.0", "dumi": "^1.1.7", "enzyme": "^3.3.0", From 4d919b92536b9e89cd4fff7bc5e03cf2bfa92cef Mon Sep 17 00:00:00 2001 From: Frankkai Date: Mon, 19 Apr 2021 10:25:21 +0800 Subject: [PATCH 2/2] Add closeType for onClose handler --- src/Notice.tsx | 23 +++++++++++++++++------ src/Notification.tsx | 8 ++++---- 2 files changed, 21 insertions(+), 10 deletions(-) diff --git a/src/Notice.tsx b/src/Notice.tsx index f367597..333608e 100644 --- a/src/Notice.tsx +++ b/src/Notice.tsx @@ -8,6 +8,8 @@ interface DivProps extends React.HTMLProps { 'data-testid'?: string; } +export type CloseTypes = 'manual' | 'auto' + export interface NoticeProps { prefixCls: string; style?: React.CSSProperties; @@ -21,7 +23,7 @@ export interface NoticeProps { closable?: boolean; props?: DivProps; onClick?: React.MouseEventHandler; - onClose?: (key: React.Key) => void; + onClose?: (key: React.Key, closeType: CloseTypes) => void; /** @private Only for internal usage. We don't promise that we will refactor this */ holder?: HTMLDivElement; @@ -52,21 +54,30 @@ export default class Notice extends Component { this.clearCloseTimer(); } + onCloseHandler = (closeType: CloseTypes) => { + const { onClose, noticeKey } = this.props; + if (onClose) { + onClose(noticeKey, closeType); + } + } + close = (e?: React.MouseEvent) => { if (e) { e.stopPropagation(); } this.clearCloseTimer(); - const { onClose, noticeKey } = this.props; - if (onClose) { - onClose(noticeKey); - } + this.onCloseHandler('manual'); }; + autoClose = () => { + this.clearCloseTimer(); + this.onCloseHandler('auto'); + } + startCloseTimer = () => { if (this.props.duration) { this.closeTimer = window.setTimeout(() => { - this.close(); + this.autoClose(); }, this.props.duration * 1000); } }; diff --git a/src/Notification.tsx b/src/Notification.tsx index 7686cc6..19da2ca 100644 --- a/src/Notification.tsx +++ b/src/Notification.tsx @@ -4,7 +4,7 @@ import type { ReactText } from 'react'; import ReactDOM from 'react-dom'; import classNames from 'classnames'; import { CSSMotionList } from 'rc-motion'; -import type { NoticeProps } from './Notice'; +import type { NoticeProps, CloseTypes } from './Notice'; import Notice from './Notice'; import useNotification from './useNotification'; @@ -23,7 +23,7 @@ export interface NoticeContent key?: React.Key; updateMark?: string; content?: React.ReactNode; - onClose?: () => void; + onClose?: (closeType: CloseTypes) => void; } export type NoticeFunc = (noticeProps: NoticeContent) => void; @@ -168,9 +168,9 @@ class Notification extends Component { key, noticeKey: userPassKey || key, updateMark, - onClose: (noticeKey: React.Key) => { + onClose: (noticeKey: React.Key, closeType: CloseTypes) => { this.remove(noticeKey); - notice.onClose?.(); + notice.onClose?.(closeType); }, onClick: notice.onClick, children: notice.content,