Notification inbox
Notification inbox
The bell, done properly: its own circle grows into the inbox, new notifications swing it and roll the count, and read ones fold out of Unread.
Dependencies
Interaction states
- open — The bell's 36px circle grows into the inbox (460ms, size and corners together), lined up with the bell's edge and nudged back on screen; the bell fades as the list fades in 100ms behind. Escape, the cross or a click outside folds it back and returns focus to the bell.
- arrive — subscribe() pushes a notification: the bell swings from its top (720ms, ±16° settling), the badge springs in or its count rolls, and in an open inbox the row fades in on top while the rest glide down.
- read — Opening a notification (or its dot) marks it read: the dot shrinks to an outline, the title eases to grey; in Unread the row stays 900ms, then folds away. onRead failing puts it back.
- mark all — Mark all read → Marking → All read with a drawn check; every unread row reads and folds out of Unread together, and the counts roll to zero.
- archive — The archive button (shown on hover or focus, always on touch) removes the row: it folds away where it stood and the rest glide up. onArchive failing brings it back.
- empty — "You're all caught up" opens by height with a check that draws itself in a thin line circle.
Installation
Add this component with your preferred package manager.
pnpm dlx shadcn@4.21.5 add @cavemio/notification-inboxFirst install? Configure @cavemio once
Run npx shadcn@4.21.5 init if shadcn is not set up, then merge this entry into the registries field in your existing components.json. Keep your other settings and registries.
{
"registries": {
"@cavemio": "https://registry.cavemio.dev/r/cavemio-{name}.json"
}
}Where it’s used
SaaS app headers
The bell in the top bar, with an unread count.
Collaboration tools
Mentions, comments and assignments for each person.
Marketplace and shop dashboards
New orders, reviews and payouts as they happen.
Admin consoles
Alerts and system events that need to be seen and cleared.
What it handles
- The bell grows into the inbox — The bell’s circle eases into the inbox panel, and folds back the same way when it closes.
- New ones arrive visibly — subscribe() feeds new notifications. The bell swings, the count rolls, and an open inbox fades the new row in while the rest glide down.
- Unread and All — Opening a notification reads it. In Unread, the row lingers for a moment and then folds away.
- Read and archive save safely — A change shows at once, and is put back if your onRead or onArchive function throws.
- Mark all read — One button reads everything, with a drawn check, and the counts roll to zero.
- All caught up, and older ones — An empty inbox says so with a drawn check, and loadMore brings in older notifications for All.
Usage
Interactive local fixture. Data and async results are simulated in the preview; the caller supplies application services.
import { NotificationInbox } from "@/components/notification-inbox";
<NotificationInbox
defaultValue={notifications}
subscribe={(push) => feed.on("notification", push)}
onRead={(ids, read) => api.markRead(ids, read)}
onArchive={(ids) => api.archive(ids)}
onOpen={(n) => n.href && router.push(n.href)}
/>Props
| Prop | Type | Description |
|---|---|---|
| value | InboxItem[] | – · Controlled notifications, newest first: { id, title, body?, at, read?, actor?, href? }. |
| defaultValue | InboxItem[] | – · Starting notifications when uncontrolled. |
| onValueChange | (items) => void | – · Every arrival, read change and archive. |
| subscribe | (push) => () => void | – · Feeds new notifications; call push with one or many. Duplicates by id are ignored. |
| onRead | (ids, read) => Promise<unknown> | – · Saves read state; the change shows at once and is undone if this throws. Without it there is no Mark all read. |
| onArchive | (ids) => Promise<unknown> | – · Archives; the row leaves at once and comes back if this throws. Without it there is no archive button. |
| onOpen | (item) => void | – · Runs when a notification is opened, after it's marked read. Items with href are links. |
| loadMore | (before) => Promise<InboxItem[]> | – · Older notifications for the All tab; an empty list hides Show older. |
| align | "end" | "start" | "end" · Which edge of the bell the inbox lines up with. |
| label | string | "Inbox" · Names the bell and the dialog. |
| defaultOpen | boolean | false · Starts open. |
Accessibility & motion
- The bell is a button that says how many are unread ("Inbox, 2 unread") and opens a dialog; focus goes to the active tab and returns to the bell on close. - Unread and All are a tablist (arrows switch). Each row is a button or link with ", unread" read out when it is; the dot is a toggle button named for what it will do. - New notifications, read changes and archives are announced in a status region outside the dialog. - The archive button appears on hover and focus with a mouse, and is always visible on touch screens. - Reduced motion opens the inbox in place, without the swing, glides or folds; the counts still change.
pnpm dlx shadcn@4.21.5 add @cavemio/notification-inbox