{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notification-bell",
  "type": "registry:component",
  "title": "Notification Bell",
  "description": "A bell button with a popping badge, a ring on new items and an unread dropdown.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "app-ui",
    "notifications",
    "bell",
    "badge",
    "dropdown"
  ],
  "docs": "https://hyperblur.dev/effects/notification-bell",
  "files": [
    {
      "path": "registry/hyperblur/notification-bell.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/notification-bell.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface NotificationBellItem {\n  id: string;\n  title: string;\n  text?: string;\n  time: string;\n  read?: boolean;\n}\n\nexport interface NotificationBellProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n  items: NotificationBellItem[];\n  count?: number;\n  onMarkAllRead?: () => void;\n  onOpenChange?: (open: boolean) => void;\n  align?: \"left\" | \"right\";\n  inline?: boolean;\n  color?: string;\n}\n\nconst css = `\n.hb-nb {\n  position: relative;\n  display: inline-flex;\n  flex-direction: column;\n  color: #ededed;\n  font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif);\n  --hb-nb-accent: #2f7bff;\n}\n.hb-nb[data-inline=\"true\"] { display: flex; width: 100%; gap: 6px; }\n.hb-nb[data-inline=\"true\"][data-align=\"right\"] { align-items: flex-end; }\n.hb-nb[data-inline=\"true\"][data-align=\"left\"] { align-items: flex-start; }\n.hb-nb-btn {\n  position: relative;\n  display: grid;\n  flex: none;\n  place-items: center;\n  box-sizing: border-box;\n  width: 36px;\n  height: 36px;\n  margin: 0;\n  padding: 0;\n  border: 1px solid #262626;\n  border-radius: 10px;\n  background: #111111;\n  color: #ededed;\n  cursor: pointer;\n  transition: border-color .15s ease, background-color .15s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-nb-btn:hover, .hb-nb-btn[aria-expanded=\"true\"] { border-color: #333333; background: #171717; }\n.hb-nb-btn:focus-visible { outline: 2px solid var(--hb-nb-accent); outline-offset: 2px; }\n.hb-nb-bell { width: 18px; height: 18px; transform-origin: 50% 12%; }\n.hb-nb-bell[data-ring=\"true\"] { animation: hb-nb-ring .9s cubic-bezier(.36, .07, .19, .97) both; }\n.hb-nb-badge {\n  position: absolute;\n  top: -7px;\n  right: -7px;\n  box-sizing: content-box;\n  min-width: 10px;\n  height: 14px;\n  padding: 0 3px;\n  border: 2px solid #111111;\n  border-radius: 999px;\n  background: var(--hb-nb-accent);\n  color: #ffffff;\n  font-size: 10px;\n  font-weight: 600;\n  line-height: 14px;\n  text-align: center;\n  pointer-events: none;\n}\n.hb-nb-badge[data-pop=\"true\"] { animation: hb-nb-pop .45s cubic-bezier(.2, 1.5, .4, 1) both; }\n.hb-nb-panel {\n  z-index: 50;\n  box-sizing: border-box;\n  width: 320px;\n  max-width: calc(100vw - 32px);\n  overflow: hidden;\n  border: 1px solid #262626;\n  border-radius: 14px;\n  background: #111111;\n  box-shadow: 0 20px 60px rgba(0, 0, 0, .55);\n  text-align: left;\n}\n.hb-nb[data-inline=\"false\"] .hb-nb-panel {\n  position: absolute;\n  top: calc(100% + 8px);\n  transform-origin: top right;\n  animation: hb-nb-drop .2s cubic-bezier(.2, .9, .2, 1) both;\n}\n.hb-nb[data-inline=\"false\"][data-align=\"right\"] .hb-nb-panel { right: 0; transform-origin: top right; }\n.hb-nb[data-inline=\"false\"][data-align=\"left\"] .hb-nb-panel { left: 0; transform-origin: top left; }\n.hb-nb[data-inline=\"true\"] .hb-nb-panel { width: 100%; max-width: none; box-shadow: none; }\n.hb-nb-head {\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: 12px;\n  box-sizing: border-box;\n  height: 38px;\n  padding: 0 8px 0 14px;\n  border-bottom: 1px solid #262626;\n}\n.hb-nb-title { font-size: 13px; font-weight: 600; }\n.hb-nb-mark {\n  margin: 0;\n  padding: 4px 8px;\n  border: 0;\n  border-radius: 6px;\n  background: transparent;\n  color: var(--hb-nb-accent);\n  font: inherit;\n  font-size: 12px;\n  font-weight: 500;\n  cursor: pointer;\n  transition: background-color .15s ease, opacity .15s ease;\n}\n.hb-nb-mark:hover { background: #1f1f1f; }\n.hb-nb-mark:focus-visible { outline: 2px solid var(--hb-nb-accent); outline-offset: 1px; }\n.hb-nb-mark:disabled { color: #8f8f8f; cursor: default; opacity: .6; background: transparent; }\n.hb-nb-list {\n  max-height: 320px;\n  margin: 0;\n  padding: 4px;\n  overflow-y: auto;\n  overscroll-behavior: contain;\n  list-style: none;\n  scrollbar-width: thin;\n  scrollbar-color: #2a2a2a transparent;\n}\n.hb-nb[data-inline=\"true\"] .hb-nb-list { max-height: 80px; }\n.hb-nb-item {\n  display: flex;\n  align-items: flex-start;\n  gap: 10px;\n  box-sizing: border-box;\n  width: 100%;\n  margin: 0;\n  padding: 8px 10px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: inherit;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .15s ease;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-nb-item:hover { background: #1a1a1a; }\n.hb-nb-item:focus-visible { outline: 2px solid var(--hb-nb-accent); outline-offset: -2px; }\n.hb-nb-dot {\n  flex: none;\n  width: 8px;\n  height: 8px;\n  margin-top: 5px;\n  border: 1px solid #333333;\n  border-radius: 999px;\n  box-sizing: border-box;\n  transition: background-color .2s ease, border-color .2s ease;\n}\n.hb-nb-item[data-read=\"false\"] .hb-nb-dot { border-color: var(--hb-nb-accent); background: var(--hb-nb-accent); }\n.hb-nb-main { display: flex; flex: 1; flex-direction: column; min-width: 0; gap: 2px; }\n.hb-nb-name { overflow: hidden; font-size: 13px; font-weight: 500; line-height: 18px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-nb-item[data-read=\"true\"] .hb-nb-name { color: #8f8f8f; font-weight: 400; }\n.hb-nb-text { color: #8f8f8f; font-size: 12px; line-height: 17px; }\n.hb-nb-time { flex: none; margin-top: 2px; color: #8f8f8f; font-size: 11px; line-height: 16px; white-space: nowrap; }\n.hb-nb-sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n.hb-nb-empty { padding: 28px 16px; color: #8f8f8f; font-size: 13px; text-align: center; }\n@keyframes hb-nb-ring {\n  0% { transform: rotate(0); }\n  15% { transform: rotate(16deg); }\n  30% { transform: rotate(-14deg); }\n  45% { transform: rotate(10deg); }\n  60% { transform: rotate(-8deg); }\n  75% { transform: rotate(4deg); }\n  100% { transform: rotate(0); }\n}\n@keyframes hb-nb-pop {\n  0% { transform: scale(.4); }\n  60% { transform: scale(1.25); }\n  100% { transform: scale(1); }\n}\n@keyframes hb-nb-drop {\n  from { opacity: 0; transform: translate3d(0, -6px, 0) scale(.97); }\n  to { opacity: 1; transform: translate3d(0, 0, 0) scale(1); }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-nb-bell[data-ring=\"true\"], .hb-nb-badge[data-pop=\"true\"], .hb-nb[data-inline=\"false\"] .hb-nb-panel { animation: none; }\n  .hb-nb-btn, .hb-nb-item, .hb-nb-dot, .hb-nb-mark { transition: none; }\n}\n`;\n\nexport function NotificationBell({\n  items,\n  count,\n  onMarkAllRead,\n  onOpenChange,\n  align = \"right\",\n  inline = false,\n  color = \"#2f7bff\",\n  className = \"\",\n  style,\n  ...rest\n}: NotificationBellProps) {\n  const uid = React.useId();\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const btnRef = React.useRef<HTMLButtonElement>(null);\n  const panelRef = React.useRef<HTMLDivElement>(null);\n  const focusFirst = React.useRef(false);\n  const [open, setOpen] = React.useState(false);\n  const [readIds, setReadIds] = React.useState<string[]>([]);\n  const isOpen = inline || open;\n\n  const unread = items.filter((i) => !i.read && !readIds.includes(i.id)).length;\n  const total = count ?? unread;\n\n  const [prevTotal, setPrevTotal] = React.useState(total);\n  const [pops, setPops] = React.useState(0);\n  const [rings, setRings] = React.useState(0);\n  if (prevTotal !== total) {\n    setPrevTotal(total);\n    setPops((p) => p + 1);\n    if (total > prevTotal) setRings((r) => r + 1);\n  }\n\n  const change = React.useCallback(\n    (next: boolean) => {\n      setOpen(next);\n      onOpenChange?.(next);\n    },\n    [onOpenChange],\n  );\n\n  React.useEffect(() => {\n    if (!open || inline) return;\n    const onDown = (e: PointerEvent) => {\n      if (rootRef.current && !rootRef.current.contains(e.target as Node)) change(false);\n    };\n    document.addEventListener(\"pointerdown\", onDown);\n    return () => document.removeEventListener(\"pointerdown\", onDown);\n  }, [open, inline, change]);\n\n  React.useEffect(() => {\n    if (isOpen && focusFirst.current) {\n      focusFirst.current = false;\n      panelRef.current?.querySelector<HTMLElement>(\"button:not(:disabled)\")?.focus();\n    }\n  }, [isOpen]);\n\n  function markAll() {\n    setReadIds(items.map((i) => i.id));\n    onMarkAllRead?.();\n  }\n\n  function markOne(id: string) {\n    setReadIds((prev) => (prev.includes(id) ? prev : [...prev, id]));\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    if (e.key === \"Escape\" && isOpen && !inline) {\n      e.preventDefault();\n      change(false);\n      btnRef.current?.focus();\n      return;\n    }\n    if (e.key !== \"ArrowDown\" && e.key !== \"ArrowUp\") return;\n    const panel = panelRef.current;\n    const buttons = panel ? Array.from(panel.querySelectorAll<HTMLElement>(\"button:not(:disabled)\")) : [];\n    const here = buttons.indexOf(document.activeElement as HTMLElement);\n    if (here < 0) {\n      if (e.key === \"ArrowDown\" && document.activeElement === btnRef.current) {\n        e.preventDefault();\n        if (isOpen) buttons[0]?.focus();\n        else {\n          focusFirst.current = true;\n          change(true);\n        }\n      }\n      return;\n    }\n    e.preventDefault();\n    const next = e.key === \"ArrowDown\" ? Math.min(buttons.length - 1, here + 1) : Math.max(0, here - 1);\n    buttons[next]?.focus();\n  }\n\n  const panelId = `${uid}-panel`;\n  const vars = { \"--hb-nb-accent\": color, ...style } as React.CSSProperties;\n  const label = total > 0 ? `Notifications, ${total} unread` : \"Notifications\";\n\n  return (\n    <div\n      ref={rootRef}\n      className={`hb-nb ${className}`}\n      data-inline={inline}\n      data-align={align}\n      style={vars}\n      onKeyDown={handleKeyDown}\n      {...rest}\n    >\n      <style href=\"hb-notification-bell\" precedence=\"default\">{css}</style>\n      <button\n        ref={btnRef}\n        type=\"button\"\n        className=\"hb-nb-btn\"\n        aria-label={label}\n        aria-haspopup=\"true\"\n        aria-expanded={isOpen}\n        aria-controls={panelId}\n        onClick={() => {\n          if (!inline) change(!open);\n        }}\n      >\n        <svg\n          key={`r${rings}`}\n          className=\"hb-nb-bell\"\n          data-ring={rings > 0}\n          viewBox=\"0 0 24 24\"\n          fill=\"none\"\n          stroke=\"currentColor\"\n          strokeWidth=\"1.8\"\n          strokeLinecap=\"round\"\n          strokeLinejoin=\"round\"\n          aria-hidden=\"true\"\n        >\n          <path d=\"M18 8A6 6 0 0 0 6 8c0 7-3 9-3 9h18s-3-2-3-9\" />\n          <path d=\"M13.73 21a2 2 0 0 1-3.46 0\" />\n        </svg>\n        {total > 0 ? (\n          <span key={`p${pops}`} className=\"hb-nb-badge\" data-pop={pops > 0} aria-hidden=\"true\">\n            {total > 99 ? \"99+\" : total}\n          </span>\n        ) : null}\n      </button>\n      {isOpen ? (\n        <div ref={panelRef} id={panelId} className=\"hb-nb-panel\" role=\"region\" aria-label=\"Notifications\">\n          <div className=\"hb-nb-head\">\n            <span className=\"hb-nb-title\">Notifications</span>\n            <button type=\"button\" className=\"hb-nb-mark\" disabled={total === 0} onClick={markAll}>\n              Mark all as read\n            </button>\n          </div>\n          {items.length === 0 ? (\n            <div className=\"hb-nb-empty\" role=\"status\">\n              You are all caught up\n            </div>\n          ) : (\n            <ul className=\"hb-nb-list\">\n              {items.map((item) => {\n                const read = Boolean(item.read) || readIds.includes(item.id);\n                return (\n                  <li key={item.id}>\n                    <button type=\"button\" className=\"hb-nb-item\" data-read={read} onClick={() => markOne(item.id)}>\n                      <span className=\"hb-nb-dot\" aria-hidden=\"true\" />\n                      <span className=\"hb-nb-main\">\n                        <span className=\"hb-nb-name\">\n                          {item.title}\n                          {read ? null : <span className=\"hb-nb-sr\"> (unread)</span>}\n                        </span>\n                        {item.text ? <span className=\"hb-nb-text\">{item.text}</span> : null}\n                      </span>\n                      <span className=\"hb-nb-time\">{item.time}</span>\n                    </button>\n                  </li>\n                );\n              })}\n            </ul>\n          )}\n        </div>\n      ) : null}\n    </div>\n  );\n}\n"
    }
  ]
}