{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notification-list",
  "type": "registry:ui",
  "title": "Notification List",
  "description": "An inbox of notices: each with its kind, title, words and time (\"5 min ago\"), unread ones marked by a dot and the word \"Unread\", a switch between all and unread, marking one or all as read, and room for each notice's own action; every change said aloud.",
  "categories": [
    "ui"
  ],
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "@rivier-ui/theme",
    "@rivier-ui/announce",
    "@rivier-ui/cn",
    "@rivier-ui/use-controllable-state"
  ],
  "files": [
    {
      "path": "registry/ui/notification-list.tsx",
      "type": "registry:ui",
      "target": "components/ui/notification-list.tsx",
      "content": "\"use client\";\n/**\n * @name notification-list\n * @category ui\n * @description An inbox of notices: each with its kind, title, words and time (\"5 min ago\"), unread ones marked by a dot and the word \"Unread\", a switch between all and unread, marking one or all as read, and room for each notice's own action; every change said aloud.\n * @when The list behind a bell in an app's header (put it in a popover or sheet), or an activity page. For a message that appears and goes by itself use toaster; for a problem on the page use alert; for a conversation use thread.\n * @example\n * <NotificationList\n *   aria-label=\"Notifications\"\n *   now=\"2026-11-13T12:00:00Z\"\n *   defaultItems={[\n *     { id: \"1\", title: \"Report ready\", body: \"The October report can be downloaded.\", time: \"2026-11-13T11:55:00Z\" },\n *     { id: \"2\", title: \"New comment\", body: \"On the map of the coast.\", time: \"2026-11-12T09:00:00Z\", read: true },\n *   ]}\n * />\n */\nimport { AlertTriangle, Bell, CheckCheck, CircleCheck, Info } from \"lucide-react\";\nimport { useState, type ComponentProps, type ReactNode } from \"react\";\nimport { announce } from \"@/lib/announce\";\nimport { cn } from \"@/lib/cn\";\nimport { useControllableState } from \"@/lib/use-controllable-state\";\n\nexport type Notice = {\n  id: string;\n  title: string;\n  body?: string;\n  /** When it happened: an ISO date-time. */\n  time: string;\n  read?: boolean;\n  kind?: \"info\" | \"success\" | \"warning\";\n  /** A button or link of the project's own: \"Open\", \"Reply\". */\n  action?: ReactNode;\n};\n\nexport type NotificationListLabels = {\n  all: string;\n  unread: string;\n  unreadMark: string;\n  markRead: string;\n  markUnread: string;\n  markedRead: (title: string) => string;\n  markedUnread: (title: string) => string;\n  markAll: string;\n  empty: string;\n  emptyUnread: string;\n  allRead: string;\n  count: (unread: number) => string;\n  filter: string;\n};\n\nconst LABELS: NotificationListLabels = {\n  all: \"All\",\n  unread: \"Unread\",\n  unreadMark: \"Unread\",\n  markRead: \"Mark as read\",\n  markUnread: \"Mark as unread\",\n  markedRead: (title) => `${title}: read`,\n  markedUnread: (title) => `${title}: unread`,\n  markAll: \"Mark all as read\",\n  empty: \"Nothing here yet.\",\n  emptyUnread: \"Nothing unread.\",\n  allRead: \"All marked as read\",\n  count: (unread) => `${unread} unread`,\n  filter: \"Show\",\n};\n\nconst ICONS = { info: Info, success: CircleCheck, warning: AlertTriangle } as const;\n\nexport type NotificationListProps = Omit<ComponentProps<\"section\">, \"defaultValue\"> & {\n  items?: readonly Notice[];\n  defaultItems?: readonly Notice[];\n  onItemsChange?: (items: readonly Notice[]) => void;\n  /** The moment times are counted from, as an ISO date-time: pass the server's time so both sides print the same words. */\n  now: string;\n  locale?: string;\n  labels?: Partial<NotificationListLabels>;\n};\n\nfunction relative(time: string, now: string, locale: string): string {\n  const seconds = (Date.parse(time) - Date.parse(now)) / 1000;\n  if (!Number.isFinite(seconds)) return \"\";\n  const format = new Intl.RelativeTimeFormat(locale, { numeric: \"auto\", style: \"short\" });\n  const units: [Intl.RelativeTimeFormatUnit, number][] = [\n    [\"year\", 31536000],\n    [\"month\", 2592000],\n    [\"week\", 604800],\n    [\"day\", 86400],\n    [\"hour\", 3600],\n    [\"minute\", 60],\n  ];\n  for (const [unit, size] of units) if (Math.abs(seconds) >= size) return format.format(Math.round(seconds / size), unit);\n  return format.format(Math.round(seconds), \"second\");\n}\n\nexport function NotificationList({ items: itemsProp, defaultItems = [], onItemsChange, now, locale = \"en-US\", labels: given, className, ...props }: NotificationListProps) {\n  const labels = { ...LABELS, ...given };\n  const [items, setItems] = useControllableState<readonly Notice[]>({ value: itemsProp, defaultValue: defaultItems, onChange: onItemsChange });\n  const [filter, setFilter] = useState<\"all\" | \"unread\">(\"all\");\n  const unread = items.filter((item) => !item.read).length;\n  const shown = filter === \"unread\" ? items.filter((item) => !item.read) : items;\n  const full = new Intl.DateTimeFormat(locale, { dateStyle: \"medium\", timeStyle: \"short\", timeZone: \"UTC\" });\n  const setRead = (id: string, read: boolean): void => {\n    setItems(items.map((item) => (item.id === id ? { ...item, read } : item)));\n    const title = items.find((item) => item.id === id)?.title ?? \"\";\n    announce(read ? labels.markedRead(title) : labels.markedUnread(title));\n  };\n  return (\n    <section data-slot=\"notification-list\" className={cn(\"flex w-full min-w-0 flex-col rounded-surface border bg-card\", className)} {...props}>\n      <div className=\"flex flex-wrap items-center justify-between gap-2 border-b p-2\">\n        <div role=\"group\" aria-label={labels.filter} className=\"flex gap-1\">\n          {([\"all\", \"unread\"] as const).map((value) => (\n            <button\n              key={value}\n              type=\"button\"\n              aria-pressed={filter === value}\n              onClick={() => setFilter(value)}\n              className={cn(\"h-control-sm rounded-control px-3 text-sm hover:bg-accent aria-pressed:bg-highlight-soft aria-pressed:font-medium pointer-coarse:h-control\")}\n            >\n              {value === \"all\" ? labels.all : labels.unread}\n              {value === \"unread\" && unread > 0 ? <span className=\"ms-1.5 tabular-nums text-muted-foreground\">{unread}</span> : null}\n            </button>\n          ))}\n        </div>\n        <button\n          type=\"button\"\n          disabled={unread === 0}\n          onClick={() => {\n            setItems(items.map((item) => ({ ...item, read: true })));\n            announce(labels.allRead);\n          }}\n          className=\"inline-flex h-control-sm items-center gap-1.5 rounded-control px-2 text-sm text-muted-foreground hover:bg-accent hover:text-foreground disabled:opacity-50 pointer-coarse:h-control\"\n        >\n          <CheckCheck aria-hidden=\"true\" className=\"size-4\" />\n          {labels.markAll}\n        </button>\n      </div>\n      {shown.length === 0 ? (\n        <p className=\"flex flex-col items-center gap-2 p-8 text-sm text-muted-foreground\">\n          <Bell aria-hidden=\"true\" className=\"size-5\" />\n          {filter === \"unread\" ? labels.emptyUnread : labels.empty}\n        </p>\n      ) : (\n        <ul className=\"flex flex-col divide-y\">\n          {shown.map((item) => {\n            const Icon = ICONS[item.kind ?? \"info\"];\n            return (\n              <li key={item.id} data-slot=\"notification\" data-read={item.read ? \"\" : undefined} className={cn(\"flex gap-3 p-3\", !item.read && \"bg-highlight-soft/40\")}>\n                <Icon aria-hidden=\"true\" className={cn(\"mt-0.5 size-4 shrink-0\", item.kind === \"warning\" ? \"text-warning\" : item.kind === \"success\" ? \"text-success\" : \"text-muted-foreground\")} />\n                <article className=\"flex min-w-0 flex-1 flex-col gap-1\">\n                  <h3 className=\"flex items-center gap-2 text-sm font-medium\" dir=\"auto\">\n                    {!item.read ? (\n                      <>\n                        <span aria-hidden=\"true\" className=\"size-2 shrink-0 rounded-full bg-primary\" />\n                        <span className=\"sr-only\">{labels.unreadMark}: </span>\n                      </>\n                    ) : null}\n                    <span className=\"min-w-0 truncate\">{item.title}</span>\n                  </h3>\n                  {item.body ? (\n                    <p className=\"text-sm text-muted-foreground\" dir=\"auto\">\n                      {item.body}\n                    </p>\n                  ) : null}\n                  <div className=\"flex flex-wrap items-center gap-3 text-xs text-muted-foreground\">\n                    <time dateTime={item.time} title={full.format(new Date(item.time))}>\n                      {relative(item.time, now, locale)}\n                    </time>\n                    {item.action}\n                    <button type=\"button\" onClick={() => setRead(item.id, !item.read)} className=\"min-h-8 underline underline-offset-4 hover:text-foreground pointer-coarse:min-h-10\">\n                      {item.read ? labels.markUnread : labels.markRead}\n                      <span className=\"sr-only\">: {item.title}</span>\n                    </button>\n                  </div>\n                </article>\n              </li>\n            );\n          })}\n        </ul>\n      )}\n    </section>\n  );\n}\n"
    }
  ],
  "meta": {
    "category": "ui",
    "when": "The list behind a bell in an app's header (put it in a popover or sheet), or an activity page. For a message that appears and goes by itself use toaster; for a problem on the page use alert; for a conversation use thread.",
    "example": "<NotificationList\n  aria-label=\"Notifications\"\n  now=\"2026-11-13T12:00:00Z\"\n  defaultItems={[\n    { id: \"1\", title: \"Report ready\", body: \"The October report can be downloaded.\", time: \"2026-11-13T11:55:00Z\" },\n    { id: \"2\", title: \"New comment\", body: \"On the map of the coast.\", time: \"2026-11-12T09:00:00Z\", read: true },\n  ]}\n/>",
    "client": true
  }
}
