NotificationBell
The bell in the top bar: how many notifications are unread, and the list in a popover.
import { NotificationBell } from '@sypnia/ui/react'
On this page
Two unread
Open it and press «Mark all as read».
Code
import { useState } from 'react';
import { NotificationBell, type NotificationEntry } from '@sypnia/ui/react';
// The count of unread ones on the bell; the list in a popover. «Mark all as read» empties the count.
const start: NotificationEntry[] = [
{ id: '1', title: 'Deploy failed', body: 'The build ran out of memory. Open the log to see where.', at: new Date(Date.now() - 4 * 60_000), unread: true, icon: 'deploy', tone: 'fail' },
{ id: '2', title: 'Backup finished', at: new Date(Date.now() - 50 * 60_000), unread: true, icon: 'backup', tone: 'ok' },
{ id: '3', title: 'Ana invited Luis to shop', at: new Date(Date.now() - 26 * 3_600_000), icon: 'user-plus' },
];
export default function Bell() {
const [items, setItems] = useState(start);
return <NotificationBell items={items} onReadAll={() => setItems(items.map((i) => ({ ...i, unread: false })))} onOpen={(id) => setItems(items.map((i) => (i.id === id ? { ...i, unread: false } : i)))} />;
} When to use it
Use it when
- Apps that tell people about things that happened while they were away.
Do not use it when
- Results of what the person just did: use a toast.
For everyone
- The button says the count: «Notifications, 2 unread».
- The list opens in a dialog; Escape closes it.
Props
| NotificationBell | Type | Default |
|---|---|---|
itemsrequired | NotificationEntry[] | |
labelDefaults to «Notifications». | string | |
onOpen | ((id: string) => void) | |
onReadAll | (() => void) |