Skip to content

Commit 64dff55

Browse files
committed
feat(notifications): Add static base of UI NotificationsPanel
1 parent 59fff01 commit 64dff55

6 files changed

Lines changed: 121 additions & 6 deletions

File tree

.docz/app/db.json

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,8 +77,13 @@
7777
},
7878
{
7979
"depth": 2,
80-
"slug": "render-notifications-props",
81-
"value": "Render notifications props"
80+
"slug": "basic-usage",
81+
"value": "Basic usage"
82+
},
83+
{
84+
"depth": 2,
85+
"slug": "notificationspanel",
86+
"value": "NotificationsPanel"
8287
},
8388
{
8489
"depth": 2,

src/notifications/Notifications.mdx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,16 @@ name: Notifications
33
---
44

55
import { Playground, PropsTable } from "docz";
6-
import Notifications from "./";
7-
import { notifications } from "./__tests__/__fixtures__/notifications";
6+
import Notifications, { NotificationsPanel } from "./";
7+
import { notifications } from "../__fixtures__/notifications";
88

99
# Notifications
1010

11-
Use a given user object in order to fetch the user notifications and inject them in a normalised shape to its children
11+
This scope will expose the `Notifications` component that uses a given user object in order to fetch the user notifications and inject them in a normalised shape to its children. Besides, it also exposes a NotificationPanel in order to be a component to being able to display notifications as expected and perform actions on them
1212

1313
<PropsTable of={Notifications} />
1414

15-
## Render notifications props
15+
## Basic usage
1616

1717
When a given user has _unread_ notifications, the component will inject notifications data categorised by messages and alerts
1818

@@ -32,6 +32,14 @@ When a given user has _unread_ notifications, the component will inject notifica
3232
</Notifications>
3333
</Playground>
3434

35+
## NotificationsPanel
36+
37+
<PropsTable of={NotificationsPanel} />
38+
39+
<Playground>
40+
<NotificationsPanel notifications={[{}, {}, {}, {}, {}, {}, {}, {}]} />
41+
</Playground>
42+
3543
## Types
3644

3745
```
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// @flow
2+
3+
import { getNotificationIcon } from "./helpers";
4+
import { NotificationsPanelComponents as NPC } from "./styled";
5+
import React from "react";
6+
import { Typography } from "@material-ui/core";
7+
8+
export const NotificationsPanel = ({
9+
notifications,
10+
}: {
11+
notifications: Array<Notification>,
12+
}) => {
13+
return (
14+
<NPC.Container>
15+
<NPC.Header>
16+
<Typography variant="caption">Notifications</Typography>
17+
</NPC.Header>
18+
<NPC.Body>
19+
{notifications.map(n => (
20+
<NPC.Item key={n.id}>
21+
{getNotificationIcon("foo")}
22+
<div>
23+
<Typography variant="body2">
24+
Achievement completed! <strong>Know your stuff I</strong>
25+
</Typography>
26+
<Typography variant="caption">1 hour ago</Typography>
27+
</div>
28+
</NPC.Item>
29+
))}
30+
</NPC.Body>
31+
<NPC.Footer />
32+
</NPC.Container>
33+
);
34+
};

src/notifications/helpers.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// @flow
2+
3+
import Group from "@material-ui/icons/Group";
4+
import React from "react";
5+
6+
export const getNotificationIcon = (notificationType: string) => {
7+
return notificationType && <Group />;
8+
};

src/notifications/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
export { Notifications as default } from "./Notifications";
2+
export { NotificationsPanel } from "./NotificationsPanel";

src/notifications/styled.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// @flow
2+
3+
import { grey } from "@material-ui/core/colors";
4+
import styled from "styled-components";
5+
6+
const NotificationsPanelBody = styled.div`
7+
overflow-y: auto;
8+
max-height: 20.625rem;
9+
`;
10+
11+
const NotificationsPanelContainer = styled.div`
12+
border: 1px solid ${grey[400]};
13+
border-radius: 0.25rem;
14+
box-shadow: 0 2px 4px -1px rgba(0, 0, 0, 0.1),
15+
0 2px 2px -2px rgba(0, 0, 0, 0.02), 0 1px 4px 0 rgba(0, 0, 0, 0.04);
16+
overflow: hidden;
17+
position: relative;
18+
width: 25rem;
19+
`;
20+
21+
const NotificationsPanelFooter = styled.div`
22+
border-top: 1px solid ${grey[400]};
23+
height: 2.125rem;
24+
`;
25+
26+
const NotificationsPanelHeader = styled.div`
27+
align-items: center;
28+
border-bottom: 1px solid ${grey[400]};
29+
display: flex;
30+
height: 2.125rem;
31+
padding: 0 0.625rem;
32+
`;
33+
34+
const NotificationsPanelItem = styled.div`
35+
align-items: center;
36+
display: flex;
37+
padding: 0.625rem 1.875rem 0.625rem 0.625rem;
38+
39+
> div:last-child {
40+
margin-left: 0.625rem;
41+
}
42+
43+
p {
44+
margin: 0;
45+
}
46+
47+
span {
48+
display: block;
49+
margin: 0;
50+
}
51+
`;
52+
53+
export const NotificationsPanelComponents = {
54+
Body: NotificationsPanelBody,
55+
Container: NotificationsPanelContainer,
56+
Footer: NotificationsPanelFooter,
57+
Header: NotificationsPanelHeader,
58+
Item: NotificationsPanelItem,
59+
};

0 commit comments

Comments
 (0)