Skip to content
This repository was archived by the owner on Mar 1, 2024. It is now read-only.

Commit bcdd4e4

Browse files
authored
Merge pull request #378 from mattsoftware/NotificationTray-UnreadNotificationHighlight
feat(NotificationTray): Style the unread notifications
2 parents 4fe40a7 + 96d9d18 commit bcdd4e4

File tree

6 files changed

+74
-39
lines changed

6 files changed

+74
-39
lines changed

example/src/SiteWrapper.react.js

Lines changed: 58 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ import {
1212
RouterContextProvider,
1313
} from "tabler-react";
1414

15+
import type { NotificationProps } from "tabler-react";
16+
1517
type Props = {|
1618
+children: React.Node,
1719
|};
1820

1921
type State = {|
20-
unreadCount: number,
22+
notificationsObjects: Array<NotificationProps>,
2123
|};
2224

2325
type subNavItem = {|
@@ -118,37 +120,6 @@ const navBarItems: Array<navItem> = [
118120
},
119121
];
120122

121-
const notificationsObjects = [
122-
{
123-
avatarURL: "demo/faces/male/41.jpg",
124-
message: (
125-
<React.Fragment>
126-
<strong>Nathan</strong> pushed new commit: Fix page load performance
127-
issue.
128-
</React.Fragment>
129-
),
130-
time: "10 minutes ago",
131-
},
132-
{
133-
avatarURL: "demo/faces/female/1.jpg",
134-
message: (
135-
<React.Fragment>
136-
<strong>Alice</strong> started new task: Tabler UI design.
137-
</React.Fragment>
138-
),
139-
time: "1 hour ago",
140-
},
141-
{
142-
avatarURL: "demo/faces/female/18.jpg",
143-
message: (
144-
<React.Fragment>
145-
<strong>Rose</strong> deployed new version of NodeJS REST Api // V3
146-
</React.Fragment>
147-
),
148-
time: "2 hours ago",
149-
},
150-
];
151-
152123
const accountDropdownProps = {
153124
avatarURL: "./demo/faces/female/25.jpg",
154125
name: "Jane Pearson",
@@ -166,11 +137,47 @@ const accountDropdownProps = {
166137

167138
class SiteWrapper extends React.Component<Props, State> {
168139
state = {
169-
unreadCount: 2,
140+
notificationsObjects: [
141+
{
142+
unread: true,
143+
avatarURL: "demo/faces/male/41.jpg",
144+
message: (
145+
<React.Fragment>
146+
<strong>Nathan</strong> pushed new commit: Fix page load performance
147+
issue.
148+
</React.Fragment>
149+
),
150+
time: "10 minutes ago",
151+
},
152+
{
153+
unread: true,
154+
avatarURL: "demo/faces/female/1.jpg",
155+
message: (
156+
<React.Fragment>
157+
<strong>Alice</strong> started new task: Tabler UI design.
158+
</React.Fragment>
159+
),
160+
time: "1 hour ago",
161+
},
162+
{
163+
unread: false,
164+
avatarURL: "demo/faces/female/18.jpg",
165+
message: (
166+
<React.Fragment>
167+
<strong>Rose</strong> deployed new version of NodeJS REST Api // V3
168+
</React.Fragment>
169+
),
170+
time: "2 hours ago",
171+
},
172+
],
170173
};
171174

172175
render(): React.Node {
173-
const unreadCount = this.state.unreadCount || 0;
176+
const notificationsObjects = this.state.notificationsObjects || [];
177+
const unreadCount = this.state.notificationsObjects.reduce(
178+
(a, v) => a || v.unread,
179+
false
180+
);
174181
return (
175182
<Site.Wrapper
176183
headerProps={{
@@ -194,10 +201,24 @@ class SiteWrapper extends React.Component<Props, State> {
194201
notificationsTray: {
195202
notificationsObjects,
196203
markAllAsRead: () =>
197-
this.setState({ unreadCount: 0 }, () =>
198-
setTimeout(() => this.setState({ unreadCount: 4 }), 5000)
204+
this.setState(
205+
() => ({
206+
notificationsObjects: this.state.notificationsObjects.map(
207+
v => ({ ...v, unread: false })
208+
),
209+
}),
210+
() =>
211+
setTimeout(
212+
() =>
213+
this.setState({
214+
notificationsObjects: this.state.notificationsObjects.map(
215+
v => ({ ...v, unread: true })
216+
),
217+
}),
218+
5000
219+
)
199220
),
200-
unread: unreadCount > 0,
221+
unread: unreadCount,
201222
},
202223
accountDropdown: accountDropdownProps,
203224
}}

src/components/Notification/Notification.react.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,16 @@ export type Props = {|
1616
* The time displayed within the Notification
1717
*/
1818
+time?: string,
19+
/**
20+
* Indicate the notification as unread
21+
*/
22+
+unread?: boolean,
1923
|};
2024

2125
/**
2226
* An individual Notification made up of an Avatar alongside some text and the time
2327
*/
24-
function Notification({ avatarURL, message, time }: Props): React.Node {
28+
function Notification({ avatarURL, message, time, unread }: Props): React.Node {
2529
return (
2630
<React.Fragment>
2731
{avatarURL && (

src/components/Notification/NotificationTray.react.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ function NotificationTray(props: Props): React.Node {
4848
))) ||
4949
(notificationsObjects &&
5050
notificationsObjects.map((n, i) => (
51-
<Dropdown.Item className="d-flex" key={i}>
51+
<Dropdown.Item
52+
className={`d-flex ${n.unread ? "bg-light" : ""}`}
53+
key={i}
54+
>
5255
<Notification
56+
unread={n.unread}
5357
avatarURL={n.avatarURL}
5458
message={n.message}
5559
time={n.time}

src/components/Notification/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
// @flow
22

33
import Notification from "./Notification.react";
4+
import type Props from "./Notification.react";
45

56
export { Notification as default };
7+
export type { Props as NotificationProps };

src/components/index.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
// @flow
22

3+
import type NotificationProps from "./Notification";
4+
export type { NotificationProps };
5+
36
export { default as AccountDropdown } from "./AccountDropdown";
47
export { default as Alert } from "./Alert";
58
export { default as Avatar } from "./Avatar";

src/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export type { Selection as SelectionEvents } from "./flow";
1616
export type { Touch as TouchEvents } from "./flow";
1717
export type { UserInterface as UIEvents } from "./flow";
1818
export type { Wheel as WheelEvents } from "./flow";
19+
export type { NotificationProps } from "./components";
1920

2021
export {
2122
default as RouterContextProvider,

0 commit comments

Comments
 (0)