Overlays
NotificationCenter
A bell button with an unread count that opens a panel of notifications, with “Mark all as read” and links to each item.
import { NotificationCenter } from '@reactloom/ui';Examples
Notifications panel
Opening an item marks it read; the count is part of the button’s name.
import { useState } from 'react';
import { Avatar, Button, NotificationCenter, type NotificationItem } from '@reactloom/ui';
const minute = 60_000;
const initial: NotificationItem[] = [
{ id: '1', title: 'Ada commented on “Q3 plan”', description: 'Looks good, one question on the budget.', time: Date.now() - 4 * minute, icon: <Avatar name="Ada Lovelace" alt="" size="sm" /> },
{ id: '2', title: 'Build #482 failed', description: 'main · unit tests', time: Date.now() - 40 * minute },
{ id: '3', title: 'Grace invited you to “Design review”', time: Date.now() - 26 * 60 * minute, read: true, icon: <Avatar name="Grace Hopper" alt="" size="sm" /> },
];
export default function Example() {
const [items, setItems] = useState(initial);
return (
<NotificationCenter
items={items}
onOpen={(item) => setItems((all) => all.map((n) => (n.id === item.id ? { ...n, read: true } : n)))}
onMarkAllRead={() => setItems((all) => all.map((n) => ({ ...n, read: true })))}
footer={<Button variant="link" size="sm">View all notifications</Button>}
/>
);
}API reference
| Prop | Type | Default |
|---|---|---|
itemsrequiredThe notifications, newest first. | { id, title, description?, time?, read?, icon?, href? }[] | — |
onOpenAn item was opened; mark it read here. | (item) => void | — |
onMarkAllReadShows “Mark all as read” while there are unread items. | () => void | — |
footerContent below the list (a link to all notifications). | ReactNode | — |
renderItemCustom item content. | (item) => ReactNode | — |
open · defaultOpen · onOpenChangeControlled panel. | boolean | — |
messagesTitle, button name, empty and unread text. | Partial<NotificationCenterMessages> | — |
Customization
Extracted from the component’s source on every build, so it matches the code. How the layers fit together is explained in Customization.
Slot class names
Add classes to inner parts with classNames (className is shorthand for root): trigger, badge, popover, header, list, item, empty, footer.
CSS variables
| Variable | Default |
|---|---|
--pl-notification-badge-bg | var(--pl-color-danger-solid) |
--pl-notification-max-height | 22rem |
--pl-notification-unread-bg | color-mix(in srgb, var(--pl-color-accent-subtle) 60%, transparent) |
State attributes
Target these in your CSS to style states without depending on class names.
| Attribute | Values |
|---|---|
[data-unread] | present when on |
Theme tokens it reads
--pl-color-accent-subtle --pl-color-bg-subtle --pl-color-border-default --pl-color-danger-solid --pl-color-fg-muted --pl-color-fg-on-accent --pl-focus-ring-color --pl-focus-ring-width --pl-font-size-sm --pl-radius-full --pl-radius-md
Accessibility
- The bell’s name includes the unread count (“Notifications, 2 unread”); the visual badge is hidden from assistive technology.
- Unread items say so in their name. The panel is a non-modal dialog that returns focus to the bell.
| Key | Action |
|---|---|
| Enter / Space | Open the panel (on the bell) |
| Tab | Move between notifications and actions |
| Escape | Close and return to the bell |
Usage guidelines
Do
- Keep titles short and say what happened and where.
Don’t
- Don’t use notifications for urgent errors; show those where they happen.