{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notifications",
  "title": "Notifications",
  "description": "Primitives for notifications: a bell with an unread count that opens a panel, a header with an action, a notification row that opens as a whole while its own buttons still work, with relative times and an unread dot, and a ready bell menu that keeps what the person read.",
  "registryDependencies": [
    "button",
    "popover",
    "https://www.dashboardblocks.com/r/radix/activity-feed.json",
    "https://www.dashboardblocks.com/r/radix/format.json",
    "https://www.dashboardblocks.com/r/radix/link.json",
    "https://www.dashboardblocks.com/r/radix/status-label.json"
  ],
  "files": [
    {
      "path": "registry/components/dashboardblocks/notifications.tsx",
      "content": "'use client'\n\nimport {\n  ActivityTime,\n  type ActivityTone,\n  MarkAllReadButton,\n  UnreadDot,\n} from '@/registry/components/dashboardblocks/activity-feed'\nimport { Link } from '@/registry/components/dashboardblocks/link'\nimport { statusToneClasses } from '@/registry/components/dashboardblocks/status-label'\nimport { IconPlaceholder } from '@/registry/icons/icon-placeholder'\nimport { formatNumber } from '@/registry/lib/dashboardblocks/format'\nimport { type MouseEvent, type ReactNode, useState } from 'react'\n\nimport { Button } from '@/components/ui/button'\nimport { Popover, PopoverContent, PopoverTrigger } from '@/components/ui/popover'\n\nimport { cn } from '@/lib/utils'\n\ninterface AppNotification {\n  at: Date\n  body?: string\n  href?: string\n  icon: ReactNode\n  id: string\n  read: boolean\n  title: ReactNode\n  /** @default 'neutral' */\n  tone?: ActivityTone\n}\n\ninterface NotificationBellProps {\n  children: ReactNode\n  className?: string\n  open?: boolean\n  onOpenChange?: (open: boolean) => void\n  unreadCount: number\n}\n\nfunction isLinkClick(event: MouseEvent) {\n  return (\n    !event.metaKey &&\n    !event.ctrlKey &&\n    !event.shiftKey &&\n    !event.altKey &&\n    event.target instanceof Element &&\n    event.target.closest('a[href]') !== null\n  )\n}\n\nfunction NotificationBell({\n  children,\n  className,\n  onOpenChange,\n  open,\n  unreadCount,\n}: NotificationBellProps) {\n  const [uncontrolledOpen, setUncontrolledOpen] = useState(false)\n  const setOpen = (next: boolean) => {\n    setUncontrolledOpen(next)\n    onOpenChange?.(next)\n  }\n\n  return (\n    <Popover open={open ?? uncontrolledOpen} onOpenChange={setOpen}>\n      <PopoverTrigger asChild>\n        <Button\n          variant='ghost'\n          size='icon'\n          className='relative'\n          aria-label={\n            unreadCount > 0 ? `Notifications, ${unreadCount} unread` : 'Notifications'\n          }\n        >\n          <IconPlaceholder\n            lucide='BellIcon'\n            tabler='IconBell'\n            hugeicons='NotificationIcon'\n            phosphor='BellIcon'\n            remixicon='RiNotificationLine'\n          />\n          {unreadCount > 0 && (\n            <span className='bg-primary text-primary-foreground ring-background absolute -top-0.5 -right-0.5 flex h-4 min-w-4 items-center justify-center rounded-full px-1 text-xs font-medium tabular-nums ring-2'>\n              {unreadCount > 9 ? '9+' : unreadCount}\n            </span>\n          )}\n        </Button>\n      </PopoverTrigger>\n      <PopoverContent\n        align='end'\n        className={cn('w-96 max-w-[calc(100vw-2rem)] gap-0 p-0', className)}\n        onClick={(event) => {\n          if (isLinkClick(event)) setOpen(false)\n        }}\n      >\n        {children}\n      </PopoverContent>\n    </Popover>\n  )\n}\n\nfunction NotificationsHeader({\n  action,\n  className,\n  description,\n  title = 'Notifications',\n}: {\n  action?: ReactNode\n  className?: string\n  description?: ReactNode\n  /** @default 'Notifications' */\n  title?: string\n}) {\n  return (\n    <div\n      className={cn('flex items-start justify-between gap-3 px-4 pt-4 pb-3', className)}\n    >\n      <div className='flex min-w-0 flex-col gap-0.5'>\n        <h2 className='font-semibold tracking-tight'>{title}</h2>\n        {description && <p className='text-muted-foreground text-sm'>{description}</p>}\n      </div>\n      {action}\n    </div>\n  )\n}\n\nfunction NotificationList({\n  children,\n  className,\n  label = 'Notifications',\n}: {\n  children: ReactNode\n  className?: string\n  /** @default 'Notifications' */\n  label?: string\n}) {\n  return (\n    <ul aria-label={label} className={cn('flex flex-col divide-y', className)}>\n      {children}\n    </ul>\n  )\n}\n\nconst toneClasses: Record<ActivityTone, string> = {\n  accent: 'text-foreground',\n  danger: statusToneClasses.bad,\n  info: statusToneClasses.info,\n  neutral: statusToneClasses.neutral,\n  success: statusToneClasses.good,\n  warning: statusToneClasses.warning,\n}\n\ninterface NotificationItemProps {\n  actions?: ReactNode\n  className?: string\n  notification: AppNotification\n  /** Pass a fixed date, so times render the same on the server and in the browser. */\n  now: Date\n  onOpen: (notification: AppNotification) => void\n  trailing?: ReactNode\n}\n\nfunction NotificationItem({\n  actions,\n  className,\n  notification,\n  now,\n  onOpen,\n  trailing,\n}: NotificationItemProps) {\n  const target = (\n    <>\n      <span aria-hidden className='absolute inset-0' />\n      {notification.title}\n    </>\n  )\n  return (\n    <li\n      data-read={notification.read || undefined}\n      className={cn(\n        'hover:bg-muted/50 focus-within:bg-muted/50 relative flex gap-3 px-4 py-3 transition-colors',\n        className,\n      )}\n    >\n      <span\n        aria-hidden\n        className={cn(\n          'flex h-5 shrink-0 items-center [&_svg]:size-4',\n          toneClasses[notification.tone ?? 'neutral'],\n        )}\n      >\n        {notification.icon}\n      </span>\n      <div className='flex min-w-0 flex-1 flex-col gap-1'>\n        <p className={cn('text-sm', notification.read && 'text-muted-foreground')}>\n          {notification.href ? (\n            <Link\n              href={notification.href}\n              onClick={() => onOpen(notification)}\n              className='outline-none focus-visible:underline'\n            >\n              {target}\n            </Link>\n          ) : (\n            <button\n              type='button'\n              onClick={() => onOpen(notification)}\n              className='text-left outline-none focus-visible:underline'\n            >\n              {target}\n            </button>\n          )}\n        </p>\n        {notification.body && (\n          <p className='text-muted-foreground line-clamp-2 text-sm'>\n            {notification.body}\n          </p>\n        )}\n        <ActivityTime className='tabular-nums' date={notification.at} now={now} />\n        {actions && <div className='relative mt-1 flex flex-wrap gap-2'>{actions}</div>}\n      </div>\n      <div className='relative flex shrink-0 items-center gap-2 self-start'>\n        {trailing && <div className='-my-1'>{trailing}</div>}\n        <span className='flex h-5 w-2 items-center'>\n          {!notification.read && <UnreadDot />}\n        </span>\n      </div>\n    </li>\n  )\n}\n\ninterface NotificationsMenuProps {\n  className?: string\n  notifications: AppNotification[]\n  /** Pass a fixed date, so times render the same on the server and in the browser. */\n  now: Date\n  /** Called with the ids the person read, by opening one or with Mark all as read, so they stay read. */\n  onRead?: (ids: string[]) => void\n}\n\nfunction NotificationsMenu({\n  className,\n  notifications,\n  now,\n  onRead,\n}: NotificationsMenuProps) {\n  const [readIds, setReadIds] = useState<ReadonlySet<string>>(() => new Set())\n  const shown = notifications.map((notification) =>\n    readIds.has(notification.id) ? { ...notification, read: true } : notification,\n  )\n  const unread = shown.filter((notification) => !notification.read)\n\n  function markRead(ids: string[]) {\n    setReadIds((current) => new Set([...current, ...ids]))\n    onRead?.(ids)\n  }\n\n  return (\n    <NotificationBell className={className} unreadCount={unread.length}>\n      <NotificationsHeader\n        description={\n          unread.length > 0\n            ? `${formatNumber(unread.length)} unread.`\n            : 'You’re all caught up.'\n        }\n        action={\n          unread.length > 0 && (\n            <MarkAllReadButton\n              onClick={() => markRead(unread.map((notification) => notification.id))}\n            />\n          )\n        }\n      />\n      {shown.length > 0 && (\n        <NotificationList className='max-h-96 overflow-y-auto border-t pe-2 [scrollbar-width:thin]'>\n          {shown.map((notification) => (\n            <NotificationItem\n              key={notification.id}\n              notification={notification}\n              now={now}\n              onOpen={() => markRead([notification.id])}\n            />\n          ))}\n        </NotificationList>\n      )}\n    </NotificationBell>\n  )\n}\n\nexport {\n  NotificationBell,\n  NotificationItem,\n  NotificationList,\n  NotificationsHeader,\n  NotificationsMenu,\n}\n\nexport type {\n  AppNotification,\n  NotificationBellProps,\n  NotificationItemProps,\n  NotificationsMenuProps,\n}\n",
      "type": "registry:component",
      "target": "@components/dashboardblocks/notifications.tsx"
    }
  ],
  "type": "registry:component"
}
