Commit 96c97b8b authored by wingsico's avatar wingsico Committed by 陈帅

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
parent 6b15e21c
...@@ -43,6 +43,7 @@ const getNotices = (req, res) => ...@@ -43,6 +43,7 @@ const getNotices = (req, res) =>
description: '描述信息描述信息描述信息', description: '描述信息描述信息描述信息',
datetime: '2017-08-07', datetime: '2017-08-07',
type: 'message', type: 'message',
clickClose: true,
}, },
{ {
id: '000000007', id: '000000007',
...@@ -51,6 +52,7 @@ const getNotices = (req, res) => ...@@ -51,6 +52,7 @@ const getNotices = (req, res) =>
description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像', description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
datetime: '2017-08-07', datetime: '2017-08-07',
type: 'message', type: 'message',
clickClose: true,
}, },
{ {
id: '000000008', id: '000000008',
...@@ -59,6 +61,7 @@ const getNotices = (req, res) => ...@@ -59,6 +61,7 @@ const getNotices = (req, res) =>
description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像', description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
datetime: '2017-08-07', datetime: '2017-08-07',
type: 'message', type: 'message',
clickClose: true,
}, },
{ {
id: '000000009', id: '000000009',
......
...@@ -116,6 +116,7 @@ export default class GlobalHeaderRight extends PureComponent { ...@@ -116,6 +116,7 @@ export default class GlobalHeaderRight extends PureComponent {
onPopupVisibleChange={onNoticeVisibleChange} onPopupVisibleChange={onNoticeVisibleChange}
loading={fetchingNotices} loading={fetchingNotices}
popupAlign={{ offset: [20, -16] }} popupAlign={{ offset: [20, -16] }}
clearClose
> >
<NoticeIcon.Tab <NoticeIcon.Tab
list={noticeData.notification} list={noticeData.notification}
......
...@@ -49,6 +49,7 @@ const data = [{ ...@@ -49,6 +49,7 @@ const data = [{
description: '描述信息描述信息描述信息', description: '描述信息描述信息描述信息',
datetime: '2017-08-07', datetime: '2017-08-07',
type: '消息', type: '消息',
clickClose: true,
}, { }, {
id: '000000007', id: '000000007',
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg', avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
...@@ -56,6 +57,7 @@ const data = [{ ...@@ -56,6 +57,7 @@ const data = [{
description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像', description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
datetime: '2017-08-07', datetime: '2017-08-07',
type: '消息', type: '消息',
clickClose: true,
}, { }, {
id: '000000008', id: '000000008',
avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg', avatar: 'https://gw.alipayobjects.com/zos/rmsportal/fcHMVNCjPOsbUGdEduuv.jpeg',
...@@ -63,6 +65,7 @@ const data = [{ ...@@ -63,6 +65,7 @@ const data = [{
description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像', description: '这种模板用于提醒谁与你发生了互动,左侧放『谁』的头像',
datetime: '2017-08-07', datetime: '2017-08-07',
type: '消息', type: '消息',
clickClose: true,
}, { }, {
id: '000000009', id: '000000009',
title: '任务名称', title: '任务名称',
......
...@@ -22,6 +22,7 @@ export interface INoticeIconProps { ...@@ -22,6 +22,7 @@ export interface INoticeIconProps {
onPopupVisibleChange?: (visible: boolean) => void; onPopupVisibleChange?: (visible: boolean) => void;
popupVisible?: boolean; popupVisible?: boolean;
locale?: { emptyText: string; clear: string }; locale?: { emptyText: string; clear: string };
clearClose?: boolean;
} }
export default class NoticeIcon extends React.Component<INoticeIconProps, any> { export default class NoticeIcon extends React.Component<INoticeIconProps, any> {
......
import React, { PureComponent } from 'react'; import React, { PureComponent } from 'react';
import ReactDOM from 'react-dom';
import { Popover, Icon, Tabs, Badge, Spin } from 'antd'; import { Popover, Icon, Tabs, Badge, Spin } from 'antd';
import classNames from 'classnames'; import classNames from 'classnames';
import List from './NoticeList'; import List from './NoticeList';
...@@ -15,6 +16,7 @@ export default class NoticeIcon extends PureComponent { ...@@ -15,6 +16,7 @@ export default class NoticeIcon extends PureComponent {
onTabChange: () => {}, onTabChange: () => {},
onClear: () => {}, onClear: () => {},
loading: false, loading: false,
clearClose: false,
locale: { locale: {
emptyText: 'No notifications', emptyText: 'No notifications',
clear: 'Clear', clear: 'Clear',
...@@ -24,16 +26,28 @@ export default class NoticeIcon extends PureComponent { ...@@ -24,16 +26,28 @@ export default class NoticeIcon extends PureComponent {
onItemClick = (item, tabProps) => { onItemClick = (item, tabProps) => {
const { onItemClick } = this.props; const { onItemClick } = this.props;
const { clickClose } = item;
onItemClick(item, tabProps); onItemClick(item, tabProps);
if (clickClose) {
this.popover.click();
}
}; };
onClear = (name) => {
const { onClear, clearClose } = this.props;
onClear(name)
if (clearClose) {
this.popover.click();
}
}
onTabChange = tabType => { onTabChange = tabType => {
const { onTabChange } = this.props; const { onTabChange } = this.props;
onTabChange(tabType); onTabChange(tabType);
}; };
getNotificationBox() { getNotificationBox() {
const { children, loading, locale, onClear } = this.props; const { children, loading, locale } = this.props;
if (!children) { if (!children) {
return null; return null;
} }
...@@ -48,7 +62,7 @@ export default class NoticeIcon extends PureComponent { ...@@ -48,7 +62,7 @@ export default class NoticeIcon extends PureComponent {
{...child.props} {...child.props}
data={child.props.list} data={child.props.list}
onClick={item => this.onItemClick(item, child.props)} onClick={item => this.onItemClick(item, child.props)}
onClear={() => onClear(child.props.name)} onClear={() => this.onClear(child.props.name)}
title={child.props.title} title={child.props.title}
locale={locale} locale={locale}
/> />
...@@ -93,6 +107,7 @@ export default class NoticeIcon extends PureComponent { ...@@ -93,6 +107,7 @@ export default class NoticeIcon extends PureComponent {
popupAlign={popupAlign} popupAlign={popupAlign}
onVisibleChange={onPopupVisibleChange} onVisibleChange={onPopupVisibleChange}
{...popoverProps} {...popoverProps}
ref={node => { this.popover = ReactDOM.findDOMNode(node)}} // eslint-disable-line
> >
{trigger} {trigger}
</Popover> </Popover>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment