Skip to main content

Notification center Pro

NotificationCenter is the bell in an app's top bar and the inbox it opens, as Linear, GitHub and Slack have it. Tabs for All, Unread, Mentions and Archived, a filter by kind, notifications grouped by day (Today, Yesterday, the weekday, then the date), each with who or what it's from, where it happened, a short time and its own buttons. Swipe one right to mark it read, left to snooze or archive (a long swipe archives); with a pointer the same actions show on hover. Notifications that arrive while you're reading wait behind a New pill instead of pushing the list, and the bell's count pops when it goes up. It opens by the bell on wide screens and as a sheet on phones. NotificationInbox is the inbox without the bell, for a full-page Inbox screen.

For a message that comes and goes, use the free Toast.

import { NotificationCenter, NotificationInbox } from '@patine-ui/pro';
Loading…
<NotificationCenter
  notifications={list}
  onMarkRead={(id) => update(id, { read: true })}
  onMarkUnread={(id) => update(id, { read: false })}
  onArchive={(id) => update(id, { archived: true, read: true })}
  onSnooze={(id, until) => update(id, { snoozedUntil: until })}
  onMarkAllRead={() => setList((l) => l.map((n) => ({ ...n, read: true })))}
  onOpenSettings={() => {}}
/>

A full-page inbox​

NotificationInbox takes the same props and draws the inbox in place, for an Inbox screen or a side panel. Hover a notification for its actions; on a phone, swipe it.

Loading…
<NotificationInbox
  style={{ width: '100%', maxWidth: 420, borderRadius: 12, borderWidth: 1, borderColor: 'rgba(127,127,127,0.25)', overflow: 'hidden' }}
  notifications={list}
  onMarkRead={(id) => update(id, { read: true })}
  onMarkUnread={(id) => update(id, { read: false })}
  onArchive={(id) => update(id, { archived: true, read: true })}
  onSnooze={(id, until) => update(id, { snoozedUntil: until })}
  onMarkAllRead={() => setList((l) => l.map((n) => ({ ...n, read: true })))}
/>

Snooze and archive​

onArchive adds Archive (a long swipe left, or the button on hover) and the Archived tab. onSnooze(id, until) adds Snooze, with a choice of when it comes back: in an hour, this evening (before 5 PM), tomorrow morning, or next Monday morning. A snoozed notification leaves the inbox and comes back by itself once snoozedUntil has passed; the header counts how many are snoozed. onMarkUnread adds Mark as unread.

Live arrivals​

Add notifications to the list as they arrive, from a socket or a poll. At the top of the list they simply show; scrolled down, they wait behind a ↑ 2 new pill that scrolls up to them, so what you're reading doesn't move. The bell's count pops each time it goes up.

Filters, settings and states​

The filter button narrows to one kind (mention, activity or system); a note under the tabs says so with Clear. onOpenSettings adds a settings button to the header. loading shows skeleton rows, and each tab has its own empty state: "You’re all caught up" for Unread, "No mentions", "Nothing archived".

In the app's top bar​

Put it in AppShell's actions, which draw a top bar on tablets and desktops.

<AppShell {...shell} actions={<NotificationCenter notifications={notifications} onMarkAllRead={markAllRead} onArchive={archive} />}>

Accessibility​

  • The bell says the count: "Notifications, 3 unread". The panel is a dialog named Notifications that closes with Escape and Back.
  • Each notification reads as one line, starting with "Unread" when it is, with where it happened and when; it opens with onPress, which also marks it read. Its buttons sit beside it, not inside it.
  • Days are headings; tabs are a segmented control. Swipe actions are also buttons on hover, and Snooze opens a menu or a sheet of choices with their times. The New pill says how many and what it does.

Props​

PropTypeDefault
notifications{ id, title, body?, createdAt, read?, kind?, actor?, icon?, tone?, context?, actions?, archived?, snoozedUntil? }[]
onPress(notification) => void
onMarkRead, onMarkUnread(id) => void
onMarkAllRead() => void: shows Mark all read
onArchive(id) => void: adds Archive and the Archived tab
onSnooze(id, until) => void: adds Snooze
onOpenSettings() => void: a settings button in the header
loadingboolean: skeleton rowsfalse
open, onOpenChangethe panel, controlled (NotificationCenter)
widthnumber, the panel on wide screens (NotificationCenter)400
nownumber, pins the times in tests

notificationsFor(list, tab, now?, filter?), unreadCount(list, now?) and snoozeOptions(now) are exported for your own badges and menus.