diff --git a/example/src/SiteWrapper.react.js b/example/src/SiteWrapper.react.js index da962b07..69e3039e 100644 --- a/example/src/SiteWrapper.react.js +++ b/example/src/SiteWrapper.react.js @@ -17,7 +17,12 @@ type Props = {| |}; type State = {| - unreadCount: number, + notificationsObjects: Array<{ + unread: boolean, + avatarURL: string, + message: React.Node, + time: string, + }>, |}; type subNavItem = {| @@ -118,37 +123,6 @@ const navBarItems: Array = [ }, ]; -const notificationsObjects = [ - { - avatarURL: "demo/faces/male/41.jpg", - message: ( - - Nathan pushed new commit: Fix page load performance - issue. - - ), - time: "10 minutes ago", - }, - { - avatarURL: "demo/faces/female/1.jpg", - message: ( - - Alice started new task: Tabler UI design. - - ), - time: "1 hour ago", - }, - { - avatarURL: "demo/faces/female/18.jpg", - message: ( - - Rose deployed new version of NodeJS REST Api // V3 - - ), - time: "2 hours ago", - }, -]; - const accountDropdownProps = { avatarURL: "./demo/faces/female/25.jpg", name: "Jane Pearson", @@ -166,11 +140,47 @@ const accountDropdownProps = { class SiteWrapper extends React.Component { state = { - unreadCount: 2, + notificationsObjects: [ + { + unread: true, + avatarURL: "demo/faces/male/41.jpg", + message: ( + + Nathan pushed new commit: Fix page load performance + issue. + + ), + time: "10 minutes ago", + }, + { + unread: true, + avatarURL: "demo/faces/female/1.jpg", + message: ( + + Alice started new task: Tabler UI design. + + ), + time: "1 hour ago", + }, + { + unread: false, + avatarURL: "demo/faces/female/18.jpg", + message: ( + + Rose deployed new version of NodeJS REST Api // V3 + + ), + time: "2 hours ago", + }, + ], }; render(): React.Node { - const unreadCount = this.state.unreadCount || 0; + const notificationsObjects = this.state.notificationsObjects || []; + const unreadCount = this.state.notificationsObjects.reduce( + (a, v) => a || v.unread, + false + ); return ( { notificationsTray: { notificationsObjects, markAllAsRead: () => - this.setState({ unreadCount: 0 }, () => - setTimeout(() => this.setState({ unreadCount: 4 }), 5000) + this.setState( + () => ({ + notificationsObjects: this.state.notificationsObjects.map( + v => ({ ...v, unread: false }) + ), + }), + () => + setTimeout( + () => + this.setState({ + notificationsObjects: this.state.notificationsObjects.map( + v => ({ ...v, unread: true }) + ), + }), + 5000 + ) ), - unread: unreadCount > 0, + unread: unreadCount, }, accountDropdown: accountDropdownProps, }} diff --git a/src/components/Notification/Notification.react.js b/src/components/Notification/Notification.react.js index cddfd91f..8b567cc1 100644 --- a/src/components/Notification/Notification.react.js +++ b/src/components/Notification/Notification.react.js @@ -16,6 +16,10 @@ export type Props = {| * The time displayed within the Notification */ +time?: string, + /** + * The time displayed within the Notification + */ + +unread?: boolean, |}; /** diff --git a/src/components/Notification/NotificationTray.react.js b/src/components/Notification/NotificationTray.react.js index 9ab3bc71..ac7760a3 100644 --- a/src/components/Notification/NotificationTray.react.js +++ b/src/components/Notification/NotificationTray.react.js @@ -48,8 +48,12 @@ function NotificationTray(props: Props): React.Node { ))) || (notificationsObjects && notificationsObjects.map((n, i) => ( - +