{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "list-notifications-grouped",
  "type": "registry:component",
  "title": "List Notifications Grouped",
  "description": "Notifications grouped by day with unread dots, a mark all as read button and hover actions to toggle read or dismiss a row.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "lists",
    "notifications",
    "inbox",
    "unread",
    "groups",
    "dismiss",
    "activity"
  ],
  "docs": "https://hyperblur.dev/effects/list-notifications-grouped",
  "files": [
    {
      "path": "registry/hyperblur/list-notifications-grouped.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/list-notifications-grouped.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type NotificationKind = \"comment\" | \"mention\" | \"approve\" | \"alert\" | \"invite\";\n\nexport interface NotificationItem {\n  id: string;\n  actor: string;\n  title: string;\n  body?: string;\n  time: string;\n  kind?: NotificationKind;\n  unread?: boolean;\n}\n\nexport interface NotificationGroup {\n  id: string;\n  label: string;\n  items: NotificationItem[];\n}\n\nexport interface ListNotificationsGroupedProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\" | \"children\" | \"defaultValue\" | \"title\" | \"onSelect\"> {\n  groups?: NotificationGroup[];\n  title?: string;\n  onSelect?: (item: NotificationItem) => void;\n  onMarkRead?: (id: string, read: boolean) => void;\n  onMarkAllRead?: () => void;\n  onDismiss?: (id: string) => void;\n  emptyTitle?: string;\n  emptyText?: string;\n  compact?: boolean;\n  accent?: string;\n}\n\nconst defaultGroups: NotificationGroup[] = [\n  {\n    id: \"today\",\n    label: \"Today\",\n    items: [\n      { id: \"n1\", actor: \"Priya Raman\", title: \"commented on Q4 roadmap\", body: \"Can we move the billing work up a sprint?\", time: \"9m\", kind: \"comment\", unread: true },\n      { id: \"n2\", actor: \"Daniel Okafor\", title: \"mentioned you in Launch plan\", body: \"@maya the final copy is ready for review.\", time: \"1h\", kind: \"mention\", unread: true },\n      { id: \"n3\", actor: \"Stripe\", title: \"Payout of $3,240.00 is on the way\", time: \"3h\", kind: \"approve\" },\n    ],\n  },\n  {\n    id: \"yesterday\",\n    label: \"Yesterday\",\n    items: [\n      { id: \"n4\", actor: \"Leo Marsh\", title: \"invited you to Design systems\", time: \"Mon\", kind: \"invite\", unread: true },\n      { id: \"n5\", actor: \"Status page\", title: \"Elevated API latency was resolved\", time: \"Mon\", kind: \"alert\" },\n    ],\n  },\n];\n\nconst KIND_ICON: Record<NotificationKind, string> = {\n  comment: \"M4 5.5h12a1 1 0 0 1 1 1v6.2a1 1 0 0 1-1 1H9.5L6 16.5v-3.8H4a1 1 0 0 1-1-1V6.5a1 1 0 0 1 1-1z\",\n  mention: \"M10 13a3 3 0 1 0 0-6 3 3 0 0 0 0 6zM13 7v4.2c0 .9.7 1.6 1.6 1.6 1.3 0 2-1.2 2-2.8a6.6 6.6 0 1 0-2.6 5.2\",\n  approve: \"M4.5 10.5l3.5 3.5 7.5-8\",\n  alert: \"M10 3.5l7 12.5H3zM10 8.5v3.2M10 13.8v.01\",\n  invite: \"M8 9a2.7 2.7 0 1 0 0-5.4A2.7 2.7 0 0 0 8 9zM2.8 16c.5-2.5 2.5-3.8 5.2-3.8M14.5 11v5M12 13.5h5\",\n};\n\nconst KIND_COLOR: Record<NotificationKind, string> = {\n  comment: \"#2f7bff\",\n  mention: \"#8b5cf6\",\n  approve: \"#30a46c\",\n  alert: \"#f5a623\",\n  invite: \"#d6409f\",\n};\n\nconst PALETTE = [\"#3b4a6b\", \"#5b3f7a\", \"#6b3a3f\", \"#2f5d4a\", \"#6a5a2a\", \"#2a5a66\", \"#6a3a58\"];\n\nfunction hash(text: string) {\n  let h = 2166136261;\n  for (let i = 0; i < text.length; i++) h = Math.imul(h ^ text.charCodeAt(i), 16777619);\n  return h >>> 0;\n}\n\nfunction initials(name: string) {\n  const parts = name.trim().split(/\\s+/).filter(Boolean);\n  return ((parts[0]?.[0] ?? \"\") + (parts.length > 1 ? (parts[parts.length - 1]?.[0] ?? \"\") : \"\")).toUpperCase();\n}\n\nconst css = `\n.hb-yc7 {\n  --hb-yc7-a: #2f7bff;\n  display: flex;\n  flex-direction: column;\n  box-sizing: border-box;\n  width: 100%;\n  overflow: hidden;\n  border: 1px solid #262626;\n  border-radius: 14px;\n  background: #111111;\n  color: #ededed;\n  font-family: inherit;\n  font-size: 13px;\n  line-height: 18px;\n}\n.hb-yc7 *, .hb-yc7 *::before, .hb-yc7 *::after { box-sizing: border-box; }\n.hb-yc7-top { display: flex; flex: none; align-items: center; gap: 8px; padding: 9px 8px 9px 14px; border-bottom: 1px solid #1f1f1f; }\n.hb-yc7-ttl { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -.01em; line-height: 20px; }\n.hb-yc7-num { min-width: 20px; padding: 0 6px; border-radius: 999px; background: var(--hb-yc7-a); color: #ffffff; font-size: 11px; font-variant-numeric: tabular-nums; font-weight: 700; line-height: 18px; text-align: center; transition: opacity .2s ease, transform .25s cubic-bezier(.3, 1.4, .5, 1); }\n.hb-yc7-num[data-zero=\"true\"] { opacity: 0; transform: scale(.5); }\n.hb-yc7-all {\n  height: 26px;\n  margin: 0 0 0 auto;\n  padding: 0 9px;\n  border: 0;\n  border-radius: 8px;\n  background: transparent;\n  color: #a1a1a1;\n  font: inherit;\n  font-size: 12px;\n  font-weight: 500;\n  cursor: pointer;\n  transition: background-color .15s ease, color .15s ease, opacity .15s ease;\n}\n.hb-yc7-all:hover:not(:disabled) { background: #1c1c1c; color: #ffffff; }\n.hb-yc7-all:disabled { opacity: .4; cursor: default; }\n.hb-yc7-all:focus-visible { outline: 2px solid var(--hb-yc7-a); outline-offset: 1px; }\n.hb-yc7-group { padding: 6px 6px 2px; }\n.hb-yc7-label { margin: 0; padding: 4px 8px 3px; color: #6f6f6f; font-size: 10.5px; font-weight: 600; letter-spacing: .08em; line-height: 14px; text-transform: uppercase; }\n.hb-yc7-list { margin: 0; padding: 0; list-style: none; }\n.hb-yc7-wrap { display: grid; grid-template-rows: 1fr; transition: grid-template-rows .26s cubic-bezier(.4, 0, .2, 1), opacity .2s ease; animation: hb-yc7-in .4s cubic-bezier(.2, .9, .2, 1) both; animation-delay: calc(var(--hb-yc7-i, 0) * 55ms); }\n.hb-yc7-wrap[data-leaving=\"true\"] { grid-template-rows: 0fr; opacity: 0; }\n.hb-yc7-cut { min-height: 0; overflow: hidden; }\n.hb-yc7-row { position: relative; }\n.hb-yc7-main {\n  display: flex;\n  align-items: flex-start;\n  gap: 10px;\n  width: 100%;\n  margin: 0;\n  padding: 7px 8px 7px 16px;\n  border: 0;\n  border-radius: 10px;\n  background: transparent;\n  color: inherit;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  transition: background-color .15s ease;\n}\n.hb-yc7-row:hover .hb-yc7-main, .hb-yc7-row:focus-within .hb-yc7-main { background: #171717; }\n.hb-yc7-main:focus-visible { outline: 2px solid var(--hb-yc7-a); outline-offset: -2px; }\n.hb-yc7-dot {\n  position: absolute;\n  top: 50%;\n  left: 7px;\n  width: 6px;\n  height: 6px;\n  margin-top: -3px;\n  border-radius: 999px;\n  background: var(--hb-yc7-a);\n  box-shadow: 0 0 8px var(--hb-yc7-a);\n  transform: scale(0);\n  transition: transform .25s cubic-bezier(.3, 1.5, .5, 1);\n  pointer-events: none;\n}\n.hb-yc7-row[data-unread=\"true\"] .hb-yc7-dot { transform: scale(1); }\n.hb-yc7-av {\n  position: relative;\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 28px;\n  height: 28px;\n  margin-top: 1px;\n  border-radius: 999px;\n  background: var(--hb-yc7-c, #3b4a6b);\n  color: #ffffff;\n  font-size: 10.5px;\n  font-weight: 700;\n  letter-spacing: .02em;\n}\n.hb-yc7-kind {\n  position: absolute;\n  right: -4px;\n  bottom: -3px;\n  display: grid;\n  place-items: center;\n  width: 14px;\n  height: 14px;\n  border: 2px solid #111111;\n  border-radius: 999px;\n  background: var(--hb-yc7-k, #2f7bff);\n  color: #ffffff;\n  transition: border-color .15s ease;\n}\n.hb-yc7-kind svg { width: 8px; height: 8px; }\n.hb-yc7-row:hover .hb-yc7-kind, .hb-yc7-row:focus-within .hb-yc7-kind { border-color: #171717; }\n.hb-yc7-txt { flex: 1; min-width: 0; }\n.hb-yc7-line { display: block; margin: 0; overflow: hidden; color: #a1a1a1; font-size: 12.5px; line-height: 17px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yc7-line b { color: #d4d4d4; font-weight: 600; }\n.hb-yc7-row[data-unread=\"true\"] .hb-yc7-line { color: #ededed; }\n.hb-yc7-row[data-unread=\"true\"] .hb-yc7-line b { color: #ffffff; font-weight: 700; }\n.hb-yc7-body { display: block; margin: 0; overflow: hidden; color: #77777f; font-size: 11.5px; line-height: 16px; text-overflow: ellipsis; white-space: nowrap; }\n.hb-yc7-time { flex: none; margin-top: 1px; color: #6f6f6f; font-size: 11px; line-height: 16px; transition: opacity .12s ease; }\n.hb-yc7-acts {\n  position: absolute;\n  top: 5px;\n  right: 6px;\n  display: flex;\n  gap: 2px;\n  padding: 2px;\n  border: 1px solid #2a2a2a;\n  border-radius: 9px;\n  background: #1a1a1a;\n  box-shadow: 0 6px 16px rgba(0, 0, 0, .45);\n  opacity: 0;\n  transform: translateX(6px);\n  pointer-events: none;\n  transition: opacity .15s ease, transform .2s cubic-bezier(.2, .9, .2, 1);\n}\n.hb-yc7-row:hover .hb-yc7-acts, .hb-yc7-row:focus-within .hb-yc7-acts { opacity: 1; transform: none; pointer-events: auto; }\n.hb-yc7-row:hover .hb-yc7-time, .hb-yc7-row:focus-within .hb-yc7-time { opacity: 0; }\n.hb-yc7-act {\n  display: grid;\n  place-items: center;\n  width: 24px;\n  height: 24px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 6px;\n  background: transparent;\n  color: #a1a1a1;\n  cursor: pointer;\n  transition: background-color .15s ease, color .15s ease;\n}\n.hb-yc7-act svg { width: 14px; height: 14px; }\n.hb-yc7-act:hover { background: #2a2a2a; color: #ffffff; }\n.hb-yc7-act:focus-visible { outline: 2px solid var(--hb-yc7-a); outline-offset: 0; }\n.hb-yc7-empty { display: grid; justify-items: center; gap: 2px; padding: 30px 16px 32px; text-align: center; animation: hb-yc7-in .4s ease both; }\n.hb-yc7-ok { display: grid; place-items: center; width: 36px; height: 36px; margin-bottom: 6px; border-radius: 999px; background: color-mix(in srgb, #30a46c 18%, transparent); color: #30a46c; }\n.hb-yc7-ok svg { width: 18px; height: 18px; }\n.hb-yc7-empty b { font-size: 13px; font-weight: 600; }\n.hb-yc7-empty span { color: #77777f; font-size: 12px; }\n@media (hover: none) {\n  .hb-yc7-acts { opacity: 1; transform: none; pointer-events: auto; }\n  .hb-yc7-time { opacity: 0; }\n}\n.hb-yc7[data-compact=\"true\"] .hb-yc7-top { padding-top: 6px; padding-bottom: 6px; }\n.hb-yc7[data-compact=\"true\"] .hb-yc7-group { padding-top: 3px; padding-bottom: 0; }\n.hb-yc7[data-compact=\"true\"] .hb-yc7-label { padding-top: 2px; padding-bottom: 2px; }\n.hb-yc7[data-compact=\"true\"] .hb-yc7-main { padding-top: 4px; padding-bottom: 4px; }\n.hb-yc7[data-compact=\"true\"] .hb-yc7-av { width: 24px; height: 24px; font-size: 9.5px; }\n@keyframes hb-yc7-in {\n  from { opacity: 0; transform: translateY(6px); }\n  to { opacity: 1; transform: none; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-yc7-wrap, .hb-yc7-empty { animation: none; }\n  .hb-yc7-wrap, .hb-yc7-dot, .hb-yc7-acts, .hb-yc7-main, .hb-yc7-num, .hb-yc7-time { transition: none; }\n}\n`;\n\nexport function ListNotificationsGrouped({\n  groups = defaultGroups,\n  title = \"Notifications\",\n  onSelect,\n  onMarkRead,\n  onMarkAllRead,\n  onDismiss,\n  emptyTitle = \"You're all caught up\",\n  emptyText = \"New activity will show up here.\",\n  compact = false,\n  accent = \"#2f7bff\",\n  className = \"\",\n  style,\n  onKeyDown,\n  ...rest\n}: ListNotificationsGroupedProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const timers = React.useRef<number[]>([]);\n  const [overrides, setOverrides] = React.useState<Record<string, boolean>>({});\n  const [gone, setGone] = React.useState<string[]>([]);\n  const [leaving, setLeaving] = React.useState<string[]>([]);\n  const [focusId, setFocusId] = React.useState(\"\");\n\n  React.useEffect(() => {\n    const list = timers.current;\n    return () => list.forEach((t) => window.clearTimeout(t));\n  }, []);\n\n  const shown = groups\n    .map((g) => ({ ...g, items: g.items.filter((i) => !gone.includes(i.id)) }))\n    .filter((g) => g.items.length > 0);\n  const flat = shown.flatMap((g) => g.items);\n  const isUnread = (i: NotificationItem) => overrides[i.id] ?? !!i.unread;\n  const unreadCount = flat.filter((i) => isUnread(i) && !leaving.includes(i.id)).length;\n  const live = flat.filter((i) => !leaving.includes(i.id));\n  const tabStop = live.some((i) => i.id === focusId) ? focusId : live[0]?.id;\n\n  function setRead(id: string, read: boolean) {\n    setOverrides((o) => ({ ...o, [id]: !read }));\n    onMarkRead?.(id, read);\n  }\n\n  function markAll() {\n    const next: Record<string, boolean> = {};\n    flat.forEach((i) => {\n      next[i.id] = false;\n    });\n    setOverrides((o) => ({ ...o, ...next }));\n    onMarkAllRead?.();\n  }\n\n  function dismiss(id: string) {\n    const items = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(\"[data-yc7-main]\") ?? []);\n    const at = items.findIndex((el) => el.dataset.yc7Main === id);\n    const neighbor = items[at + 1] ?? items[at - 1];\n    neighbor?.focus();\n    onDismiss?.(id);\n    const instant = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    if (instant) {\n      setGone((g) => [...g, id]);\n      return;\n    }\n    setLeaving((l) => [...l, id]);\n    timers.current.push(\n      window.setTimeout(() => {\n        setGone((g) => [...g, id]);\n        setLeaving((l) => l.filter((x) => x !== id));\n      }, 280),\n    );\n  }\n\n  function handleKeyDown(e: React.KeyboardEvent<HTMLDivElement>) {\n    onKeyDown?.(e);\n    if (e.defaultPrevented) return;\n    if (e.key === \"Escape\") {\n      (document.activeElement as HTMLElement | null)?.blur();\n      return;\n    }\n    const target = e.target as HTMLElement;\n    const id = target.dataset.yc7Main;\n    if (!id) return;\n    const items = Array.from(rootRef.current?.querySelectorAll<HTMLElement>(\"[data-yc7-main]\") ?? []).filter((el) => el.closest('[data-leaving=\"true\"]') === null);\n    const at = items.indexOf(target);\n    let next = -1;\n    if (e.key === \"ArrowDown\") next = Math.min(items.length - 1, at + 1);\n    else if (e.key === \"ArrowUp\") next = Math.max(0, at - 1);\n    else if (e.key === \"Home\") next = 0;\n    else if (e.key === \"End\") next = items.length - 1;\n    if (next >= 0) {\n      e.preventDefault();\n      items[next]?.focus();\n      return;\n    }\n    if (e.key === \"Delete\" || e.key === \"Backspace\") {\n      e.preventDefault();\n      dismiss(id);\n    }\n  }\n\n  const vars = { \"--hb-yc7-a\": accent, ...style } as React.CSSProperties;\n  const order = new Map(flat.map((it, n) => [it.id, n]));\n\n  return (\n    <div ref={rootRef} className={`hb-yc7 ${className}`} data-compact={compact} style={vars} onKeyDown={handleKeyDown} {...rest}>\n      <style href=\"hb-list-notifications-grouped\" precedence=\"default\">{css}</style>\n      <div className=\"hb-yc7-top\">\n        <h3 className=\"hb-yc7-ttl\">{title}</h3>\n        <span className=\"hb-yc7-num\" data-zero={unreadCount === 0} aria-label={`${unreadCount} unread`}>\n          {unreadCount}\n        </span>\n        <button type=\"button\" className=\"hb-yc7-all\" disabled={unreadCount === 0} onClick={markAll}>\n          Mark all as read\n        </button>\n      </div>\n      {shown.length === 0 ? (\n        <div className=\"hb-yc7-empty\">\n          <span className=\"hb-yc7-ok\">\n            <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n              <path d=\"M4.5 10.5l3.5 3.5 7.5-8\" />\n            </svg>\n          </span>\n          <b>{emptyTitle}</b>\n          <span>{emptyText}</span>\n        </div>\n      ) : (\n        shown.map((g) => (\n          <div key={g.id} className=\"hb-yc7-group\" role=\"group\" aria-label={g.label}>\n            <p className=\"hb-yc7-label\">{g.label}</p>\n            <ul className=\"hb-yc7-list\" role=\"list\">\n              {g.items.map((item) => {\n                const unread = isUnread(item);\n                const kind = item.kind ?? \"comment\";\n                const i = order.get(item.id) ?? 0;\n                return (\n                  <li key={item.id} className=\"hb-yc7-wrap\" data-leaving={leaving.includes(item.id)} style={{ \"--hb-yc7-i\": i } as React.CSSProperties}>\n                    <div className=\"hb-yc7-cut\">\n                      <div className=\"hb-yc7-row\" data-unread={unread}>\n                        <span className=\"hb-yc7-dot\" aria-hidden=\"true\" />\n                        <button\n                          type=\"button\"\n                          className=\"hb-yc7-main\"\n                          data-yc7-main={item.id}\n                          tabIndex={item.id === tabStop ? 0 : -1}\n                          onFocus={() => setFocusId(item.id)}\n                          onClick={() => {\n                            if (unread) setRead(item.id, true);\n                            onSelect?.(item);\n                          }}\n                        >\n                          <span className=\"hb-yc7-av\" style={{ \"--hb-yc7-c\": PALETTE[hash(item.actor) % PALETTE.length] } as React.CSSProperties} aria-hidden=\"true\">\n                            {initials(item.actor)}\n                            <span className=\"hb-yc7-kind\" style={{ \"--hb-yc7-k\": KIND_COLOR[kind] } as React.CSSProperties}>\n                              <svg viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                                <path d={KIND_ICON[kind]} />\n                              </svg>\n                            </span>\n                          </span>\n                          <span className=\"hb-yc7-txt\">\n                            <span className=\"hb-yc7-line\">\n                              <b>{item.actor}</b> {item.title}\n                            </span>\n                            {item.body ? <span className=\"hb-yc7-body\">{item.body}</span> : null}\n                          </span>\n                          <span className=\"hb-yc7-time\">{item.time}</span>\n                        </button>\n                        <div className=\"hb-yc7-acts\">\n                          <button\n                            type=\"button\"\n                            className=\"hb-yc7-act\"\n                            tabIndex={item.id === tabStop ? 0 : -1}\n                            aria-label={unread ? \"Mark as read\" : \"Mark as unread\"}\n                            title={unread ? \"Mark as read\" : \"Mark as unread\"}\n                            onClick={() => setRead(item.id, unread)}\n                          >\n                            <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                              {unread ? <path d=\"M3.5 8.5l3 3 6-7\" /> : <circle cx=\"8\" cy=\"8\" r=\"3\" fill=\"currentColor\" stroke=\"none\" />}\n                            </svg>\n                          </button>\n                          <button\n                            type=\"button\"\n                            className=\"hb-yc7-act\"\n                            tabIndex={item.id === tabStop ? 0 : -1}\n                            aria-label=\"Dismiss\"\n                            title=\"Dismiss\"\n                            onClick={() => dismiss(item.id)}\n                          >\n                            <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" aria-hidden=\"true\">\n                              <path d=\"M4 4l8 8M12 4L4 12\" />\n                            </svg>\n                          </button>\n                        </div>\n                      </div>\n                    </div>\n                  </li>\n                );\n              })}\n            </ul>\n          </div>\n        ))\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}