diff --git a/example/src/SiteWrapper.react.js b/example/src/SiteWrapper.react.js index da962b07..25d318b1 100644 --- a/example/src/SiteWrapper.react.js +++ b/example/src/SiteWrapper.react.js @@ -12,12 +12,14 @@ import { RouterContextProvider, } from "tabler-react"; +import type { NotificationProps } from "tabler-react"; + type Props = {| +children: React.Node, |}; type State = {| - unreadCount: number, + notificationsObjects: Array, |}; type subNavItem = {| @@ -118,37 +120,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 +137,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..79ba17f5 100644 --- a/src/components/Notification/Notification.react.js +++ b/src/components/Notification/Notification.react.js @@ -16,12 +16,16 @@ export type Props = {| * The time displayed within the Notification */ +time?: string, + /** + * Indicate the notification as unread + */ + +unread?: boolean, |}; /** * An individual Notification made up of an Avatar alongside some text and the time */ -function Notification({ avatarURL, message, time }: Props): React.Node { +function Notification({ avatarURL, message, time, unread }: Props): React.Node { return ( {avatarURL && ( 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) => ( - +