# Notification center

> A panel at the edge of the screen for your app's own notifications, from your server, a socket or local state, in groups that expand into stacks, with a bell that counts what is unread. Part of @cloudlet/toast, with a shadcn registry item for the bell.

Source: https://cloudlet.dev/docs/components/notification-center

`NotificationCenter` shows your app's own array of notifications in a panel at the edge of the screen. It never changes the array: clearing, actions and reading call your callbacks, you update the array, and the panel animates the difference.

## Preview

Live preview at https://cloudlet.dev/docs/components/notification-center#preview: a bell button with a badge of unread notifications, and three buttons that change the Preview's own list, as an app changes its own. Send a notification adds one unread notification with a Remind me action, as a socket message would; Send a group adds three with one `group`, a stack in the panel that expands; Load from the server adds two older ones a moment later, as a REST answer would. The panel's clear buttons, swipes and Clear all call `onDismiss` and `onClear`, which take the notifications out of the list, and the unread ones the open panel shows go to `onRead`, which marks them read. Controls set the panel's side and backdrop. The code they make:

```tsx
<NotificationCenter
  center={center}
  notifications={notifications}
  onDismiss={dismiss}
  onClear={clear}
  onRead={markRead}
  side="left"
  backdrop="tint"
/>
```

- `side`: `right` (the default), `left`; physical, so the panel stays at that edge in RTL too.
- `backdrop`: `blur` (the default: the page blurred under the panel), `tint` (a tone, no blur), `none` (nothing under the panel).

A prop at its default is left out; with every default the code has only the list and its callbacks.

## Installation

The center ships in `@cloudlet/toast` 1.5.0 or newer, at its own entry `@cloudlet/toast/center`; it needs no Toaster.

### From npm

```sh title="Terminal"
npm install @cloudlet/toast
```

Import `NotificationCenter` and `useNotificationCenter` from `@cloudlet/toast/center`, and the styles from `@cloudlet/toast/styles.css` ([Import the styles](https://cloudlet.dev/docs/components/toaster#import-the-styles)).

### The shadcn registry item

```sh title="Terminal"
npx shadcn@latest add https://cloudlet.dev/r/notification-center.json
```

It copies three files and adds `@cloudlet/toast` as a dependency:

- **`components/ui/notification-center.tsx`**: `NotificationCenter`, `NotificationCenterButton` (a bell with a badge of your count), and `useNotificationCenter` with the types.
- **`components/ui/notification-center-button.tsx`**: the bell on its own, which the first file re-exports.
- **`components/ui/notification-center.css`**: your shadcn tokens mapped onto the panel's, and the bell's styles.

## Usage

Give the panel your array and update it in the callbacks. Each notification needs a stable `id` and a `time`; the panel shows the newest first.

```tsx title="components/notifications.tsx"
'use client';
import { useState } from 'react';
import {
  NotificationCenter,
  NotificationCenterButton,
  useNotificationCenter,
  type NotificationItem,
} from '@/components/ui/notification-center';

export function Notifications({ initial }: { initial: NotificationItem[] }) {
  const center = useNotificationCenter();
  const [notifications, setNotifications] = useState(initial);
  const remove = (ids: readonly string[]) => setNotifications((list) => list.filter((item) => !ids.includes(item.id)));
  const markRead = (ids: readonly string[]) =>
    setNotifications((list) => list.map((item) => (ids.includes(item.id) ? { ...item, read: true } : item)));

  return (
    <>
      <NotificationCenterButton center={center} count={notifications.filter((item) => item.read === false).length} />
      <NotificationCenter
        center={center}
        notifications={notifications}
        onDismiss={(id) => remove([id])}
        onClear={remove}
        onRead={markRead}
      />
    </>
  );
}
```

Without `onDismiss` and `onClear` there are no clear buttons and no swipes. A card you keep after `onDismiss`, while your server confirms, springs back and leaves once your array drops it.

### From a REST API

Fetch the list, put it in state, and send your requests from the callbacks; the example updates the list optimistically.

```tsx title="rest.tsx"
"use client";

import { useCallback, useEffect, useState } from "react";
import {
  NotificationCenter,
  NotificationCenterButton,
  useNotificationCenter,
  type NotificationItem,
} from "@/components/ui/notification-center";

const MINUTE = 60_000;

/** Stands in for `fetch("/api/notifications")`: your server answers with its list a moment later. */
function fetchNotifications(): Promise<NotificationItem[]> {
  const now = Date.now();
  return new Promise((resolve) =>
    setTimeout(
      () =>
        resolve([
          { id: "forecast-3", title: "Rain on the way", description: "Showers reach the coast around 4 pm.", kind: "info", time: now - 5 * MINUTE, read: false },
          { id: "forecast-2", title: "Storm warning lifted", description: "The front moved out to sea.", kind: "success", time: now - 2 * 60 * MINUTE },
          { id: "forecast-1", title: "Weekly outlook", description: "Mostly sunny, a cloud or two.", time: now - 3 * 24 * 60 * MINUTE },
        ]),
      600,
    ),
  );
}

export function RestInbox({ theme }: { theme: "light" | "dark" }) {
  const center = useNotificationCenter();
  const [notifications, setNotifications] = useState<NotificationItem[]>([]);
  const [loading, setLoading] = useState(false);
  const load = useCallback(async () => {
    setLoading(true);
    setNotifications(await fetchNotifications());
    setLoading(false);
  }, []);
  useEffect(() => {
    void load();
  }, [load]);
  // Optimistic: the list changes at once, and your DELETE request goes out next to it.
  const remove = (ids: readonly string[]) => setNotifications((list) => list.filter((item) => !ids.includes(item.id)));
  const markRead = (ids: readonly string[]) =>
    setNotifications((list) => list.map((item) => (ids.includes(item.id) ? { ...item, read: true } : item)));
  return (
    <div className="flex flex-wrap items-center justify-center gap-2 text-sm">
      <NotificationCenterButton center={center} count={notifications.filter((item) => item.read === false).length} />
      <button type="button" className="rounded-md border px-3 py-1.5" disabled={loading} onClick={() => void load()}>
        {loading ? "Loading…" : "Load again"}
      </button>
      <NotificationCenter
        center={center}
        notifications={notifications}
        onDismiss={(id) => remove([id])}
        onClear={remove}
        onRead={markRead}
        theme={theme}
      />
    </div>
  );
}
```

### From a WebSocket

Add each message to the same state. A notification that arrives while the panel is open grows in at the top.

```tsx title="socket.tsx"
"use client";

import { useEffect, useState } from "react";
import {
  NotificationCenter,
  NotificationCenterButton,
  useNotificationCenter,
  type NotificationItem,
} from "@/components/ui/notification-center";

const CLOUDS = ["Cumulus", "Cirrus", "Stratus", "Nimbus"];

/** Stands in for a WebSocket: a message every two seconds until the returned function closes it. */
function connect(onMessage: (item: NotificationItem) => void) {
  let count = 0;
  const timer = setInterval(() => {
    count += 1;
    const cloud = CLOUDS[count % CLOUDS.length];
    onMessage({ id: `cloud-${Date.now()}`, title: `${cloud} overhead`, description: "Seen from the station.", time: Date.now(), read: false });
  }, 2000);
  return () => clearInterval(timer);
}

export function LiveFeed({ theme }: { theme: "light" | "dark" }) {
  const center = useNotificationCenter();
  const [notifications, setNotifications] = useState<NotificationItem[]>([]);
  const [live, setLive] = useState(false);
  // Each message joins the list; the open panel grows it in at the top.
  useEffect(() => (live ? connect((item) => setNotifications((list) => [item, ...list])) : undefined), [live]);
  const remove = (ids: readonly string[]) => setNotifications((list) => list.filter((item) => !ids.includes(item.id)));
  const markRead = (ids: readonly string[]) =>
    setNotifications((list) => list.map((item) => (ids.includes(item.id) ? { ...item, read: true } : item)));
  return (
    <div className="flex flex-wrap items-center justify-center gap-2 text-sm">
      <NotificationCenterButton center={center} count={notifications.filter((item) => item.read === false).length} />
      <button type="button" className="rounded-md border px-3 py-1.5" aria-pressed={live} onClick={() => setLive(!live)}>
        {live ? "Disconnect" : "Connect"}
      </button>
      <NotificationCenter
        center={center}
        notifications={notifications}
        onDismiss={(id) => remove([id])}
        onClear={remove}
        onRead={markRead}
        theme={theme}
      />
    </div>
  );
}
```

### Groups

Notifications with the same `group` stand as one stack that expands. Clear on a group and Clear all take two presses and pass the ids to `onClear`.

```tsx title="groups.tsx"
"use client";

import { useState } from "react";
import {
  NotificationCenter,
  NotificationCenterButton,
  useNotificationCenter,
  type NotificationItem,
} from "@/components/ui/notification-center";

const MINUTE = 60_000;

function journal(now: number): NotificationItem[] {
  return [
    { id: "deploy-3", title: "Deploy finished", description: "production · build 483 is live", kind: "success", group: "Deploys", time: now - MINUTE },
    { id: "deploy-2", title: "Health checks passed", description: "12 of 12 instances", kind: "success", group: "Deploys", time: now - 2 * MINUTE },
    { id: "deploy-1", title: "Deploy started", description: "production · build 483", kind: "info", group: "Deploys", time: now - 3 * MINUTE },
    { id: "invoice", title: "Invoice paid", description: "November · 3 seats", time: now - 40 * MINUTE },
    { id: "mail-2", title: "Anna replied", description: "See you at 7.", group: "Mail", time: now - 90 * MINUTE },
    { id: "mail-1", title: "Mark mentioned you", description: "in the launch checklist", group: "Mail", time: now - 120 * MINUTE },
  ];
}

export function GroupedJournal({ theme }: { theme: "light" | "dark" }) {
  const center = useNotificationCenter();
  const [notifications, setNotifications] = useState(() => journal(Date.now()));
  const deploy = () =>
    setNotifications((list) => [
      { id: `deploy-${Date.now()}`, title: "Rollback ready", description: "build 482 can go back live", kind: "warning", group: "Deploys", time: Date.now() },
      ...list,
    ]);
  // Clear on a group and Clear all pass the ids they clear.
  const remove = (ids: readonly string[]) => setNotifications((list) => list.filter((item) => !ids.includes(item.id)));
  return (
    <div className="flex flex-wrap items-center justify-center gap-2 text-sm">
      <NotificationCenterButton center={center} />
      <button type="button" className="rounded-md border px-3 py-1.5" onClick={deploy}>
        Add a deploy
      </button>
      <button type="button" className="rounded-md border px-3 py-1.5" onClick={() => setNotifications(journal(Date.now()))}>
        Reset
      </button>
      <NotificationCenter center={center} notifications={notifications} onDismiss={(id) => remove([id])} onClear={remove} theme={theme} />
    </div>
  );
}
```

### Read state and badge

`read: false` marks a notification unread. The open panel reports the unread ids it shows to `onRead`, once per opening; the badge is your own `count`.

```tsx title="read.tsx"
"use client";

import { useState } from "react";
import {
  NotificationCenter,
  NotificationCenterButton,
  useNotificationCenter,
  type NotificationItem,
} from "@/components/ui/notification-center";

const MINUTE = 60_000;

function unreadNews(now: number): NotificationItem[] {
  return [
    { id: "news-3", title: "Fog this morning", description: "It lifts by 10.", time: now - MINUTE, read: false },
    { id: "news-2", title: "Pollen count high", description: "Birch, mostly.", kind: "warning", time: now - 20 * MINUTE, read: false },
    { id: "news-1", title: "New station online", description: "Readings every minute.", kind: "success", time: now - 4 * 60 * MINUTE },
  ];
}

export function ReadState({ theme }: { theme: "light" | "dark" }) {
  const center = useNotificationCenter();
  const [notifications, setNotifications] = useState(() => unreadNews(Date.now()));
  // The badge is your count: here, what is still `read: false`.
  const unread = notifications.filter((item) => item.read === false).length;
  // Called with the unread ids the panel showed: your PATCH request goes out here.
  const markRead = (ids: readonly string[]) =>
    setNotifications((list) => list.map((item) => (ids.includes(item.id) ? { ...item, read: true } : item)));
  return (
    <div className="flex flex-wrap items-center justify-center gap-2 text-sm">
      <NotificationCenterButton center={center} count={unread} />
      <span className="tabular-nums">{unread} unread</span>
      <button type="button" className="rounded-md border px-3 py-1.5" onClick={() => setNotifications(unreadNews(Date.now()))}>
        Mark unread again
      </button>
      <NotificationCenter center={center} notifications={notifications} onRead={markRead} theme={theme} />
    </div>
  );
}
```

### Custom cards

`renderNotification` draws a card from the default parts ([`NotificationParts`](#notificationparts)); the panel keeps the card's motion, swipe and keyboard order. `actions` call `onAction(id, actionId)`.

```tsx title="render.tsx"
"use client";

import { useState } from "react";
import {
  NotificationCenter,
  NotificationCenterButton,
  useNotificationCenter,
  type NotificationItem,
} from "@/components/ui/notification-center";

type Message = { author: string; tone: string };

const MINUTE = 60_000;

function messages(now: number): NotificationItem[] {
  return [
    { id: "m-2", title: "Anna", description: "The radar shows a gap at 5. Walk then?", time: now - 2 * MINUTE, data: { author: "Anna", tone: "bg-pink-200" }, actions: [{ id: "reply", label: "Reply" }] },
    { id: "m-1", title: "Oleg", description: "Uploaded the cloud photos.", time: now - 30 * MINUTE, data: { author: "Oleg", tone: "bg-teal-200" } },
  ];
}

export function MessageCards({ theme }: { theme: "light" | "dark" }) {
  const center = useNotificationCenter();
  const [notifications, setNotifications] = useState(() => messages(Date.now()));
  const [replied, setReplied] = useState("");
  const remove = (ids: readonly string[]) => setNotifications((list) => list.filter((item) => !ids.includes(item.id)));
  return (
    <div className="flex flex-wrap items-center justify-center gap-2 text-sm">
      <NotificationCenterButton center={center} />
      <span aria-live="polite">{replied && `Replying to ${replied}`}</span>
      <NotificationCenter
        center={center}
        notifications={notifications}
        onDismiss={(id) => remove([id])}
        onClear={remove}
        onAction={(id) => {
          setReplied((notifications.find((item) => item.id === id)?.data as Message).author);
          center.setOpen(false);
        }}
        // The center keeps the card, its motion and swipe; this draws what is inside it from the default parts.
        renderNotification={(item, parts) => {
          const message = item.data as Message;
          return (
            <div className="flex items-start gap-3 py-2.5 ps-3.5">
              <span aria-hidden="true" className={`mt-1 grid size-8 shrink-0 place-items-center rounded-full text-xs font-semibold text-black ${message.tone}`}>
                {message.author[0]}
              </span>
              <div className="min-w-0 flex-1">
                {parts.title}
                {parts.description}
                {parts.actions}
              </div>
              {parts.time}
            </div>
          );
        }}
        theme={theme}
      />
    </div>
  );
}
```

### Controlled open

`useNotificationCenter({ open, onOpenChange })` lets your state decide. Without a button, give the same props to `NotificationCenter` and leave out `center`.

```tsx title="controlled.tsx"
"use client";

import { useState } from "react";
import {
  NotificationCenter,
  NotificationCenterButton,
  useNotificationCenter,
  type NotificationItem,
} from "@/components/ui/notification-center";

const ALERT: NotificationItem = {
  id: "frost",
  title: "Frost tonight",
  description: "Cover the seedlings before 9 pm.",
  kind: "warning",
  time: Date.now(),
  actions: [{ id: "done", label: "Done" }],
};

export function ControlledCenter({ theme }: { theme: "light" | "dark" }) {
  // Your state decides: the bell, Escape, a press outside and the close button ask through onOpenChange.
  const [open, setOpen] = useState(false);
  const center = useNotificationCenter({ open, onOpenChange: setOpen });
  const [notifications, setNotifications] = useState<NotificationItem[]>([ALERT]);
  return (
    <div className="flex flex-wrap items-center justify-center gap-2 text-sm">
      <NotificationCenterButton center={center} />
      <button type="button" className="rounded-md border px-3 py-1.5" onClick={() => { setNotifications([ALERT]); setOpen(true); }}>
        Show the alert
      </button>
      <span aria-live="polite">{open ? "Open" : "Closed"}</span>
      <NotificationCenter
        center={center}
        notifications={notifications}
        onAction={() => {
          // Done closes the center from your code and takes the alert out.
          setOpen(false);
          setNotifications([]);
        }}
        theme={theme}
      />
    </div>
  );
}
```

### Your own button

Spread `triggerProps` on any button; several buttons can share one center, and focus returns to the one that opened it.

```tsx title="components/inbox.tsx"
'use client';
import { NotificationCenter, useNotificationCenter, type NotificationItem } from '@cloudlet/toast/center';

export function Inbox({ notifications, onClear }: { notifications: NotificationItem[]; onClear: (ids: readonly string[]) => void }) {
  const center = useNotificationCenter();
  const unread = notifications.filter((item) => item.read === false).length;
  return (
    <>
      <button type="button" {...center.triggerProps} aria-label={unread > 0 ? `Inbox, ${unread} unread` : 'Inbox'}>
        Inbox{unread > 0 && <span aria-hidden="true"> {unread}</span>}
      </button>
      <NotificationCenter center={center} notifications={notifications} onClear={onClear} />
    </>
  );
}
```

### Swipes

A card swiped away from the edge asks `onDismiss` past 40 % of its width or after a flick of at least 60 px; a swipe towards the edge closes the drawer. Speed is measured over the last 100 ms, so a burst of trackpad events is no flick.

### Backdrop

[`backdrop`](#notificationcenter-props) is `blur` (default; one layer in Safari, the tone of `tint` below 48rem), `tint` (a tone, no blur, cheaper on heavy pages) or `none`. Reduced motion turns the drawer into a fade and turns swipes off; reduced transparency draws `tint` in place of `blur`.

### SSR and Next.js

`NotificationCenter` renders nothing on the server and in the first client render, so hydration never mismatches; the hook renders the same on both sides.

### Content Security Policy

The panel writes its motion as CSSOM rules in its own `<style>`; pass your request's nonce as [`nonce`](#notificationcenter-props) ([Content Security Policy](https://cloudlet.dev/docs/components/toaster/csp)).

### Styling

The panel is `.cloudlet-host.cloudlet-center`, styled by the Toaster's tokens ([Tokens](https://cloudlet.dev/docs/components/toaster/styling#tokens)) plus `--cloudlet-center-width` (`392px`), `--cloudlet-center-tint` (`70%`), `--cloudlet-center-blur-tint` (`38%` light, `58%` dark), `--cloudlet-center-blur` (`16px`) and `--cloudlet-center-backdrop-reach` (`160px`). `classNames` adds classes per [part](#notificationcenterpart); a card carries `data-kind` and, while unread, `data-read="false"`. The bell takes `--notification-center-button-radius`, `--notification-center-badge` and `--notification-center-badge-foreground`.

## API Reference

Everything here is exported from `@cloudlet/toast/center`, except the [registry item](#registry-item)'s `NotificationCenterButton`.

| Export | What it is |
| --- | --- |
| [`NotificationCenter`](#notificationcenter-props), `NotificationCenterProps`, `NotificationCenterComponent` | The panel. |
| [`NotificationItem`](#notificationitem), [`NotificationItemAction`](#notificationitemaction) | A notification of your list, and its buttons. |
| [`NotificationParts`](#notificationparts) | The default parts of a card, for `renderNotification`. |
| [`useNotificationCenter`](#usenotificationcenter), `UseNotificationCenter`, `UseNotificationCenterResult`, `NotificationCenterOpenOptions`, `NotificationCenterTriggerProps` | The open state and the props of your buttons. |
| [`NotificationCenterLabels`](#notificationcenterlabels) | The panel's texts. |
| [`NotificationCenterPart`](#notificationcenterpart) | The parts `classNames` styles. |
| [`NotificationCenterMotion`](#notificationcentermotion), `NotificationCenterMotionConstants`, `NotificationCenterMotionOverrides`, `NotificationCenterBackdropConstants` | The panel's debugging channel for motion and the backdrop. |

### NotificationCenter props

`<NotificationCenter center={center} notifications={notifications} />` renders the panel. Mount it once, anywhere under your app: it portals itself into `<body>`. It renders nothing on the server and in the first client render, even for an open center, and nothing once a closed center's drawer has left. `NotificationCenterProps` are its props, and `NotificationCenterComponent` is its signature.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `notifications` | `readonly NotificationItem[]` | — | Required. Your list, in any order ([below](#notificationitem)); the panel shows the newest first and animates what changed from the previous array. |
| `center` | `UseNotificationCenterResult` | — | The open state and the buttons from `useNotificationCenter()`. Without it the panel keeps its own state from `open`, `defaultOpen` and `onOpenChange`. |
| `open`, `defaultOpen`, `onOpenChange` | `NotificationCenterOpenOptions` | — | Used without `center`: as the [hook's options](#usenotificationcenter). |
| `onDismiss` | `(id: string) => void` | — | A card's clear button or a swipe asks to dismiss it. Without it, and without `onClear`, a card has no clear button and does not swipe. |
| `onClear` | `(ids: readonly string[]) => void` | — | A group's two-step Clear or the header's Clear all asks to clear these ids, newest first. Without it they call `onDismiss` for each id; with neither there are no two-step buttons. |
| `onAction` | `(id: string, actionId: string) => void` | — | A press of one of a notification's `actions`. The card stays. |
| `onRead` | `(ids: readonly string[]) => void` | — | Unread notifications the open panel shows on a visible page, each id once per opening. |
| `renderNotification` | `(item: NotificationItem, parts: NotificationParts) => ReactNode` | — | Draws a card's content from the default parts ([below](#notificationparts)); the panel keeps the card, its motion and swipe. |
| `side` | `'left' \| 'right'` | `'right'` | The edge the panel stands at. Physical: it stays there in right-to-left pages too. |
| `theme` | `'system' \| 'light' \| 'dark'` | `'system'` | Colour scheme; `system` follows the user's preference. The root keeps it in `data-theme` and the active one in `data-resolved-theme`. |
| `dir` | `'ltr' \| 'rtl'` | the document's `dir` | Text direction. |
| `labels` | `Partial<NotificationCenterLabels>` | English labels | The panel's texts ([below](#notificationcenterlabels)). |
| `classNames` | `Partial<Record<NotificationCenterPart, string>>` | — | Your classes per part, added to the own `cloudlet-*` classes, never replacing them ([parts](#notificationcenterpart)). |
| `backdrop` | `'blur' \| 'tint' \| 'none'` | `'blur'` | What lies under the column and a band past it ([Backdrop](#backdrop)). Any other value is `blur`; under reduced transparency `blur` draws the tone of `tint`. The root says the app's result in `data-backdrop`, and with `blur` the number of blur layers in `data-backdrop-layers`. Read on every render. |
| `motion` | `NotificationCenterMotion` | — | Debugging channel for the motion ([below](#notificationcentermotion)). Read on every render. |
| `reducedMotion` | `boolean` | `false` | `true` removes motion whatever the system says; `false` follows the system and `data-reduced-motion` on `<body>` or `<html>`. Read on every render. |
| `nonce` | `string` | — | The nonce of the panel's own `<style>` block, for a strict Content Security Policy. Read when the panel opens. |

### NotificationItem

One notification of your list.

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `id` | `string` | — | Required. Stable and unique in the list: the panel follows a notification by its id from one array to the next. |
| `title` | `ReactNode` | — | Required. The card's heading. |
| `description` | `ReactNode` | — | The text under the title; a string becomes a paragraph. |
| `time` | `Date \| number` | — | Required. When it happened, a `Date` or milliseconds since the epoch; the list shows the newest first. A time that is not one shows no time and stands last. |
| `group` | `string` | — | Notifications with the same non-empty `group` stand as one stack; without it a notification stands alone. |
| `kind` | `string` | — | `success`, `error`, `info`, `warning` or `loading` draw the Toaster's status icon and tint and a hidden word for screen readers; any other string is your own kind, in `data-kind`, with no icon of its own. |
| `read` | `boolean` | read | `false` marks it unread: a dot, "Unread" for screen readers, and `onRead` once the open panel shows it. |
| `icon` | `ReactNode` | the kind's icon | Replaces the status icon. |
| `actions` | `readonly NotificationItemAction[]` | — | The card's buttons ([below](#notificationitemaction)). |
| `data` | `unknown` | — | Your own data, passed back untouched in `renderNotification`. |

### NotificationItemAction

| Field | Type | Description |
| --- | --- | --- |
| `id` | `string` | Unique among the notification's actions; `onAction` receives it. |
| `label` | `string` | The button's text. |

### NotificationParts

What `renderNotification` receives besides the item: the default card, cut into parts to place as you like.

| Field | Type | Description |
| --- | --- | --- |
| `icon` | `ReactNode` | The status icon or `item.icon`; `null` without either. |
| `title` | `ReactElement` | The title as the card's heading, `h3` (`h4` in an expanded group), with the id `titleId`. |
| `description` | `ReactNode` | The description in its part; `null` without one. |
| `actions` | `ReactNode` | The row of action buttons; `null` without actions. |
| `time` | `ReactElement` | The time and, in its place on hover and focus, the clear button. Leave it out and the card has no clear button. |
| `titleId` | `string` | The id of the title's heading, for your own `aria-labelledby`. |
| `dismiss` | `() => void` | Asks to dismiss this notification, as its clear button does. |
| `action` | `(actionId: string) => void` | Runs an action of this notification, as its button does. |
| `content` | `ReactElement` | The default content: the head (icon, title, time) and the body (description, actions). |

### useNotificationCenter

`useNotificationCenter(options?)` returns a `UseNotificationCenterResult` for your buttons and the panel; `UseNotificationCenter` is its signature. Its `options` are `NotificationCenterOpenOptions`:

| Option | Type | Default | Description |
| --- | --- | --- | --- |
| `open` | `boolean` | — | Controls the open state; pair it with `onOpenChange`. |
| `defaultOpen` | `boolean` | `false` | The first open state of an uncontrolled center. |
| `onOpenChange` | `(open: boolean) => void` | — | Called with the next state when a button, Escape, a press outside, the close button or a swipe asks to open or close. |

`UseNotificationCenterResult`:

| Field | Type | Description |
| --- | --- | --- |
| `open` | `boolean` | The center is open. |
| `setOpen` | `(open: boolean) => void` | Opens or closes the center from your code; a controlled center asks through `onOpenChange`. The same function on every render. |
| `triggerProps` | `NotificationCenterTriggerProps` | Spread on your button: it opens and closes the center. |

`NotificationCenterTriggerProps`:

| Field | Type | Description |
| --- | --- | --- |
| `ref` | `(element: HTMLElement \| null) => (() => void) \| undefined` | Makes the element a button of the center: a press on it is not a press outside the panel, and focus returns to it when it opened the center. A center takes several buttons, one hook's props spread on each; a button is the center's until its `ref` lets it go or it leaves the document. |
| `aria-expanded` | `boolean` | The center is open. |
| `aria-controls` | `string \| undefined` | The panel's id while it is open. |
| `aria-haspopup` | `'dialog'` | The panel is a dialog. |
| `onClick` | `(event?) => void` | Opens or closes the center. The button it opened the center from is the one focus returns to. |

### NotificationCenterLabels

Every label is optional in `labels`; anything left out keeps its English default. A formatter that throws or returns something other than a string gives the default text.

| Key | Type | Default | Description |
| --- | --- | --- | --- |
| `title` | `string` | `'Notifications'` | The panel's visible heading and its accessible name. |
| `close` | `string` | `'Close notifications'` | The panel's close button. |
| `clear` | `string` | `'Clear notification'` | The button that clears one card, in place of its time. |
| `empty` | `string` | `'No notifications'` | The line of an open center without notifications. |
| `kind` | `(kind: string) => string` | `'Success'`, `'Error'`, `'Info'`, `'Warning'`, `'In progress'` | The hidden word before a card's title that tells a screen reader its kind; an empty string, the default for your own kinds, says nothing. |
| `unread` | `string` | `'Unread'` | The hidden word before the title of an unread notification. |
| `time` | `(time: number, now: number) => string` | `'now'`, `'2m'`, `'1h'`, `'3d'`, then a date | A card's time, both in milliseconds since the epoch. From seven days the default is a short date in the document's language, such as `'Nov 23'`. |
| `group` | `(key: string) => string` | the key | A group's name from its key. |
| `more` | `(label: string, count: number) => string` | `'Deploys · 2 more'` | The button under a folded stack that expands it; `count` is the notifications under the top one. |
| `stack` | `(label: string, count: number) => string` | `'Deploys, 3 notifications'` | The accessible name of a group of `count` notifications. |
| `showLess` | `string` | `'Show less'` | The button beside an expanded group's name that folds it. |
| `clearGroup` | `string` | `'Clear'` | The two-step button in an expanded group's heading row that clears the group. |
| `clearGroupConfirm` | `(count: number) => string` | `'Clear 3'` | That button armed, and the polite status then; also the armed clear button of a folded stack. |
| `clearStack` | `(label: string) => string` | `'Clear Deploys'` | The accessible name of a folded stack's clear button, in place of its top card's time. |
| `clearAll` | `string` | `'Clear all'` | The two-step button in the panel's header that clears the whole list, shown from two notifications. |
| `clearAllConfirm` | `(count: number) => string` | `'Clear 5'` | That button armed, and the polite status then; `count` is every notification of the list. |

### NotificationCenterPart

The parts `classNames` takes.

| Part | Element |
| --- | --- |
| `center` | The panel's root, `div.cloudlet-host.cloudlet-center` with `role="dialog"`. |
| `header` | The row with the heading, Clear all and the close button. |
| `heading` | The panel's heading, `h2`. |
| `clear-all` | The two-step Clear all button; `data-armed="true"` after the first press. |
| `dismiss` | The panel's close button. |
| `list` | The list of cards and groups, `ul`. |
| `card` | Each card, `li.cloudlet-card` with `data-kind` and, while unread, `data-read="false"`. |
| `unread` | The dot of an unread card. |
| `time` | A card's time, `time`. |
| `clear` | A card's clear button, in place of its time. |
| `empty` | The line of an empty center. |
| `group` | A group of two notifications or more, `li` with `data-expanded`. |
| `group-header` | An expanded group's heading row. |
| `group-title` | The button with the group's name and count, which folds it. |
| `show-less` | The Show less button. |
| `group-clear` | The two-step Clear button of an expanded group. |
| `group-list` | The list of a group's cards, `ul`. |
| `edge` | Each of up to two cards that show under a folded stack's top card. |
| `stack-clear` | A folded stack's two-step clear button, in place of its top card's time. |
| `more` | The button under a folded stack that expands it. |
| `icon`, `title`, `body`, `description`, `actions`, `action` | The parts of a card, as in the Toaster. |

### NotificationCenterMotion

`motion` is a debugging and laboratory channel, not a styling API: the values may change between releases. Leave it out in production.

| Field | Type | Default | Description |
| --- | --- | --- | --- |
| `timeScale` | `number` | `1` | Slows every transition: `0.5` is twice as slow. A value that is not finite and positive falls back to `1`. |
| `overrides` | `NotificationCenterMotionOverrides` | — | Replaces motion constants live, for transitions that start after the change. A field that is not a finite number in range (stiffness and mass above 0, the rest 0 or more) keeps its default. |

`NotificationCenterMotionConstants` names the constants: the drawer's `open` and `close` springs, `travel` and `lag` of the cards that trail it, `enter`, `exit` and `reflow` of the list, `swap` and `swapBlur` of the time and its clear button, `reduced` for reduced motion, and `stack` for folding and expanding groups. `NotificationCenterMotionOverrides` takes any part of them, nested springs included, plus `backdrop` with `NotificationCenterBackdropConstants`: `layers`, the number of blur layers under the tone (an integer from 1 to 8; 4 by default, and 1 in Apple engines without an override), and `scrollTint`, which shows the tone alone while the page scrolls under the open center (`false` by default).

### Keyboard and screen readers

The panel is a non-modal `role="dialog"` named by its heading. Opening moves focus to the heading, whose focus announces the dialog. Tab goes through Clear all and the close button, then the cards: each with its actions and its clear button, which shows in place of the time while focus is in the card. A folded stack is a group named "Deploys, 3 notifications" with two stops, its clear button and the button under it that expands it; an expanded group offers the name button, Show less and Clear, then its cards.

Escape closes the center while focus is in the panel, on one of the center's buttons or on the page's body; Escape in a field of your page is left alone. A primary press outside the panel and the center's buttons closes it and still reaches your page. On closing, focus returns to the button that opened the center, or else to what had it before the center opened, or else to the center's first button on the page; focus elsewhere on the page stays where it is. A card that leaves with focus in it hands focus to the first control of the next item, or to the heading.

A notification that arrives while the center is open is spoken in the panel's own polite live region, its title and description, a moment after it shows; several are spoken together. The notifications already there when the center opens are not read out. The first press on a two-step clear button arms it and its text, "Clear 3", is spoken as a status; the second press within 3 seconds clears, silently, and focus moves to the next item, or to the heading after Clear all. With a pointer, a swipe toward the panel's edge closes it and a swipe of a card away from the edge dismisses the card; under reduced motion swipes are off and the buttons do everything.

### Registry item

The item's `components/ui/notification-center.tsx` exports `NotificationCenter`, the package's panel with every prop as it is, `NotificationCenterButton`, and `useNotificationCenter` with the types `NotificationCenterProps`, `NotificationItem` and `UseNotificationCenterResult`, passed through from `@cloudlet/toast/center`.

The bell is its own file, `components/ui/notification-center-button.tsx`, and needs only the hook's result. A page that shows the bell at once can load the panel when it is first wanted: import `NotificationCenterButton` from that file and `useNotificationCenter` from `@cloudlet/toast/center`, and render `NotificationCenter` through `React.lazy` or `next/dynamic` once the page is ready, so the panel is mounted before the first press.

#### NotificationCenterButton

`NotificationCenterButton` is a bell button that opens and closes the center, built on the hook's `triggerProps`. Its badge shows your `count`, up to `99+`, and is hidden from screen readers: the exact count is in the button's accessible name. It sets `data-slot="notification-center-button"`, and `NotificationCenterButtonProps` take every `<button>` prop except `type`, `children`, `onClick`, `aria-label`, `aria-expanded`, `aria-controls` and `aria-haspopup`, which the button sets itself; it takes no `ref`.

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `center` | `UseNotificationCenterResult` | — | Required. The center the button opens and closes, from `useNotificationCenter()`. Several buttons may share one. |
| `count` | `number` | `0` | The badge: your own count, such as your unread notifications. 0 or less shows none. |
| `labels` | `Partial<NotificationCenterButtonLabels>` | English labels | The button's accessible name. |
| `className` | `string` | — | Added after the button's own `notification-center-button` class. |

`NotificationCenterButtonLabels`:

| Key | Type | Default | Description |
| --- | --- | --- | --- |
| `name` | `string` | `'Notifications'` | The accessible name with nothing to count. |
| `unread` | `(count: number) => string` | `'Notifications, 3 unread'` | The accessible name with `count` in the badge. |
