Examples

Notifications panel

Opening an item marks it read; the count is part of the button’s name.

Preview
Example.tsx
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

NotificationCenter props
PropTypeDefault
itemsrequired
The notifications, newest first.
{ id, title, description?, time?, read?, icon?, href? }[]—
onOpen
An item was opened; mark it read here.
(item) => void—
onMarkAllRead
Shows “Mark all as read” while there are unread items.
() => void—
footer
Content below the list (a link to all notifications).
ReactNode—
renderItem
Custom item content.
(item) => ReactNode—
open · defaultOpen · onOpenChange
Controlled panel.
boolean—
messages
Title, 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

VariableDefault
--pl-notification-badge-bgvar(--pl-color-danger-solid)
--pl-notification-max-height22rem
--pl-notification-unread-bgcolor-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.

AttributeValues
[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.
Keyboard interactions
KeyAction
Enter / SpaceOpen the panel (on the bell)
TabMove between notifications and actions
EscapeClose 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.