Skip to content

Commit 275e8e3

Browse files
committed
feat(notifications): allow panel to use ClickAwayListener to close on outer click
1 parent a02b8e2 commit 275e8e3

3 files changed

Lines changed: 38 additions & 32 deletions

File tree

src/notifications/Notifications.mdx

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
name: Notifications
33
---
44

5+
import noop from "lodash/noop";
56
import { Playground, PropsTable } from "docz";
67
import Notifications, { NotificationsPanel } from "./";
78
import { notifications } from "../__fixtures__/notifications";
@@ -37,7 +38,7 @@ When a given user has _unread_ notifications, the component will inject notifica
3738
<PropsTable of={NotificationsPanel} />
3839

3940
<Playground>
40-
<NotificationsPanel notifications={notifications} />
41+
<NotificationsPanel notifications={notifications} handleClose={noop} />
4142
</Playground>
4243

4344
## Types

src/notifications/NotificationsPanel.js

Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { getNotificationIcon } from "./helpers";
44
import moment from "moment";
55
import { NotificationsPanelComponents as NPC } from "./styled";
66
import React from "react";
7-
import { Typography } from "@material-ui/core";
7+
import { ClickAwayListener, Typography } from "@material-ui/core";
88

99
type Props = {
1010
handleClose: Function,
@@ -13,35 +13,37 @@ type Props = {
1313

1414
export const NotificationsPanel = ({ handleClose, notifications }: Props) => {
1515
return (
16-
<NPC.Container>
17-
<NPC.Header>
18-
<Typography variant="caption">Notifications</Typography>
19-
</NPC.Header>
20-
<NPC.Body>
21-
{notifications.map(n => (
22-
<NPC.Item key={n.created_at} onClick={handleClose}>
23-
{getNotificationIcon("foo")}
24-
<div aria-label="NotificationItem">
25-
<Typography variant="body2">{n.data.topic_title}</Typography>
26-
<Typography variant="caption">
27-
{moment(n.created_at).fromNow()}
28-
</Typography>
29-
</div>
30-
</NPC.Item>
31-
))}
32-
{notifications.length === 0 && (
33-
<NPC.Item>
34-
{getNotificationIcon("announcement")}
35-
<div aria-label="EmptyFeedback">
36-
<Typography variant="body2">
37-
<i>There is not notifications yet</i>
38-
</Typography>
39-
</div>
40-
</NPC.Item>
41-
)}
42-
</NPC.Body>
43-
<NPC.Footer />
44-
</NPC.Container>
16+
<ClickAwayListener onClickAway={handleClose}>
17+
<NPC.Container>
18+
<NPC.Header>
19+
<Typography variant="caption">Notifications</Typography>
20+
</NPC.Header>
21+
<NPC.Body>
22+
{notifications.map(n => (
23+
<NPC.Item key={n.created_at} onClick={handleClose}>
24+
{getNotificationIcon("foo")}
25+
<div aria-label="NotificationItem">
26+
<Typography variant="body2">{n.data.topic_title}</Typography>
27+
<Typography variant="caption">
28+
{moment(n.created_at).fromNow()}
29+
</Typography>
30+
</div>
31+
</NPC.Item>
32+
))}
33+
{notifications.length === 0 && (
34+
<NPC.Item>
35+
{getNotificationIcon("announcement")}
36+
<div aria-label="EmptyFeedback">
37+
<Typography variant="body2">
38+
<i>There is not notifications yet</i>
39+
</Typography>
40+
</div>
41+
</NPC.Item>
42+
)}
43+
</NPC.Body>
44+
<NPC.Footer />
45+
</NPC.Container>
46+
</ClickAwayListener>
4547
);
4648
};
4749

src/profile/AlertsDropdown.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,10 @@ export const AlertsDropdown = ({ alerts }: { alerts: Array<Alert> }) => {
4848
ref={arrowProps.ref}
4949
style={arrowProps.style}
5050
/>
51-
<NotificationsPanel notifications={alerts} />
51+
<NotificationsPanel
52+
notifications={alerts}
53+
handleClose={handleClose}
54+
/>
5255
</div>
5356
)}
5457
</Popper>

0 commit comments

Comments
 (0)