From 96c97b8bf83212d9869f8570c95933ea65d2d06c Mon Sep 17 00:00:00 2001 From: wingsico Date: Wed, 31 Oct 2018 14:08:28 +0800 Subject: [PATCH] Feat/noticeicon-close (#2716) * add new feature: click the clear button or list item to close the pop-up * add the new property: clickClose and set the value: true * add the new property: clearClose * update d.ts and .md * add eslint-disable-line --- mock/notices.js | 3 +++ src/components/GlobalHeader/RightContent.js | 1 + src/components/NoticeIcon/demo/popover.md | 3 +++ src/components/NoticeIcon/index.d.ts | 1 + src/components/NoticeIcon/index.js | 19 +++++++++++++++++-- 5 files changed, 25 insertions(+), 2 deletions(-) diff --git a/mock/notices.js b/mock/notices.js index 76ab162e..505088e0 100644 --- a/mock/notices.js +++ b/mock/notices.js @@ -43,6 +43,7 @@ const getNotices = (req, res) => description: '描述信息描述信息描述信息', datetime: '2017-08-07', type: 'message', + clickClose: true, }, { id: '000000007', @@ -51,6 +52,7 @@ const getNotices = (req, res) => description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像', datetime: '2017-08-07', type: 'message', + clickClose: true, }, { id: '000000008', @@ -59,6 +61,7 @@ const getNotices = (req, res) => description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像', datetime: '2017-08-07', type: 'message', + clickClose: true, }, { id: '000000009', diff --git a/src/components/GlobalHeader/RightContent.js b/src/components/GlobalHeader/RightContent.js index 45bb2042..260f38b1 100644 --- a/src/components/GlobalHeader/RightContent.js +++ b/src/components/GlobalHeader/RightContent.js @@ -116,6 +116,7 @@ export default class GlobalHeaderRight extends PureComponent { onPopupVisibleChange={onNoticeVisibleChange} loading={fetchingNotices} popupAlign={{ offset: [20, -16] }} + clearClose > void; popupVisible?: boolean; locale?: { emptyText: string; clear: string }; + clearClose?: boolean; } export default class NoticeIcon extends React.Component { diff --git a/src/components/NoticeIcon/index.js b/src/components/NoticeIcon/index.js index 61f56b92..284bde72 100644 --- a/src/components/NoticeIcon/index.js +++ b/src/components/NoticeIcon/index.js @@ -1,4 +1,5 @@ import React, { PureComponent } from 'react'; +import ReactDOM from 'react-dom'; import { Popover, Icon, Tabs, Badge, Spin } from 'antd'; import classNames from 'classnames'; import List from './NoticeList'; @@ -15,6 +16,7 @@ export default class NoticeIcon extends PureComponent { onTabChange: () => {}, onClear: () => {}, loading: false, + clearClose: false, locale: { emptyText: 'No notifications', clear: 'Clear', @@ -24,16 +26,28 @@ export default class NoticeIcon extends PureComponent { onItemClick = (item, tabProps) => { const { onItemClick } = this.props; + const { clickClose } = item; onItemClick(item, tabProps); + if (clickClose) { + this.popover.click(); + } }; + onClear = (name) => { + const { onClear, clearClose } = this.props; + onClear(name) + if (clearClose) { + this.popover.click(); + } + } + onTabChange = tabType => { const { onTabChange } = this.props; onTabChange(tabType); }; getNotificationBox() { - const { children, loading, locale, onClear } = this.props; + const { children, loading, locale } = this.props; if (!children) { return null; } @@ -48,7 +62,7 @@ export default class NoticeIcon extends PureComponent { {...child.props} data={child.props.list} onClick={item => this.onItemClick(item, child.props)} - onClear={() => onClear(child.props.name)} + onClear={() => this.onClear(child.props.name)} title={child.props.title} locale={locale} /> @@ -93,6 +107,7 @@ export default class NoticeIcon extends PureComponent { popupAlign={popupAlign} onVisibleChange={onPopupVisibleChange} {...popoverProps} + ref={node => { this.popover = ReactDOM.findDOMNode(node)}} // eslint-disable-line > {trigger} -- GitLab