Skip to Content

Notification Screens

An in-app notification inbox and a preferences centre with one switch per category and channel.

Notifications2 unread

Show
import { useState } from "react"
import { NotificationInbox } from "@dapplelight/signet-ui/screens/notification-screens"
import { initial } from "./notifications"

function NotificationInboxDemo() {
  const [items, setItems] = useState(initial)
  const now = new Date().toISOString()
  return (
    <NotificationInbox
      className="w-full max-w-lg"
      items={items}
      onMarkRead={(ids) =>
        setItems((l) => l.map((i) => (ids.includes(i.id) ? { ...i, readAt: now } : i)))
      }
      onMarkAllRead={() => setItems((l) => l.map((i) => ({ ...i, readAt: i.readAt ?? now })))}
      onArchive={(item) => setItems((l) => l.filter((i) => i.id !== item.id))}
    />
  )
}

Installation

npm i @dapplelight/signet-ui

Usage

import {
  NotificationInbox,
  NotificationPreferences,
} from "@dapplelight/signet-ui/screens/notification-screens"

Shapes match signet-server's notifier: InboxEntry from inbox.list, ChannelPrefs from getPrefs and updatePrefs.

import { NotificationInbox } from "@dapplelight/signet-ui/screens/notification-screens"
import { items, markRead } from "./notifications"

<NotificationInbox items={items} onMarkRead={markRead} />

Examples

NotificationInbox

Notifications2 unread

Show
import { useState } from "react"
import { NotificationInbox } from "@dapplelight/signet-ui/screens/notification-screens"
import { initial } from "./notifications"

function NotificationInboxDemo() {
  const [items, setItems] = useState(initial)
  const now = new Date().toISOString()
  return (
    <NotificationInbox
      className="w-full max-w-lg"
      items={items}
      onMarkRead={(ids) =>
        setItems((l) => l.map((i) => (ids.includes(i.id) ? { ...i, readAt: now } : i)))
      }
      onMarkAllRead={() => setItems((l) => l.map((i) => ({ ...i, readAt: i.readAt ?? now })))}
      onArchive={(item) => setItems((l) => l.filter((i) => i.id !== item.id))}
    />
  )
}

An empty inbox shows the all-caught-up state.

Notifications

Show
You're all caught up
import { NotificationInbox } from "@dapplelight/signet-ui/screens/notification-screens"

function NotificationInboxEmptyDemo() {
  return <NotificationInbox className="w-full max-w-lg" items={[]} />
}

InboxItem

One row, on its own. It is a button; pass render={<a href={item.link} />} to make it a link.

import { InboxItem } from "@dapplelight/signet-ui/screens/notification-screens"
import { initial } from "./notifications"

function InboxItemDemo() {
  return (
    <div className="w-full max-w-lg">
      <InboxItem item={initial[0]} onOpen={() => undefined} />
      <InboxItem item={initial[2]} onOpen={() => undefined} />
    </div>
  )
}

NotificationPreferences

Notification preferences

CategoryEmailPushIn app
BillingReceipts and failed payments.
MentionsWhen someone @mentions you.
Product newsNew features and tips.
import { useState } from "react"
import { NotificationPreferences, type ChannelPrefs } from "@dapplelight/signet-ui/screens/notification-screens"

function NotificationPreferencesDemo() {
  const [value, setValue] = useState<ChannelPrefs>({ marketing: { email: false } })
  return (
    <NotificationPreferences
      className="w-full max-w-xl"
      value={value}
      onValueChange={setValue}
      channels={["email", "push", "inApp"]}
      categories={[
        { id: "billing", label: "Billing", description: "Receipts and failed payments.", required: true },
        { id: "mentions", label: "Mentions", description: "When someone @mentions you." },
        { id: "marketing", label: "Product news", description: "New features and tips." },
      ]}
    />
  )
}

API Reference

NotificationInbox

PropTypeDefaultDescription
itemsreadonly InboxEntry[]requiredNotifications, newest first.
unreadCountnumberunread among itemsCount for the badge.
filter"all" | "unread"-Filter (controlled).
defaultFilter"all" | "unread""all"Initial filter.
onFilterChange(filter: InboxFilter) => void-Called when the filter changes.
onMarkRead(ids: string[]) => unknown-Opening an unread item calls it.
onMarkAllRead() => unknown-Mark everything read.
onArchive(item: InboxEntry) => unknown-Adds an archive button per item.
onOpen(item: InboxEntry) => void-Follow the item's link or open a detail view.
renderItem(item: InboxEntry) => ReactElement | undefined-Swap each item's element, e.g. a link.
hasMoreboolean-Shows Load more.
onLoadMore() => unknown-Fetch the next page.
localestringbrowserLocale for relative times.
labelsPartial<NotificationLabels>DEFAULT_NOTIFICATION_LABELSOverride any string.
classNamestring-Class on the root.
classNamesPartial<Record<"header" | "filter" | "list" | "item" | "empty" | "more", string>>-Classes per part.

InboxItem

Also accepts button props except onClick, and render.

PropTypeDefaultDescription
itemInboxEntryrequiredThe notification.
onOpen(item: InboxEntry) => void-Called on click.
localestringbrowserLocale for relative times.
labelsPartial<NotificationLabels>-Override any string.

NotificationPreferences

PropTypeDefaultDescription
categoriesreadonly PreferenceCategory[]requiredid, label, optional description, and required for always-on categories.
channelsreadonly NotifyChannel[]["email", "push", "inApp"]Columns, in order.
valueChannelPrefs-Prefs (controlled).
defaultValueChannelPrefs{}Initial prefs.
onValueChange(value: ChannelPrefs) => void-Every change, with the full next value.
onToggle(change: { category; channel; on }) => unknown-Save one change. Throwing puts the switch back.
labelsPartial<NotificationLabels>DEFAULT_NOTIFICATION_LABELSOverride any string.
classNamestring-Class on the root.
classNamesPartial<Record<"table" | "row" | "switch", string>>-Classes per part.