{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "stacked-alerts-tray",
  "title": "Stacked Alerts Tray",
  "description": "Keep many alerts out of the way: they stack in a corner as a small deck with a count, open into a list over the page, and clear one at a time or all at once.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/new-york/stacked-alerts-tray/stacked-alerts-tray.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type TrayLevel = \"critical\" | \"warning\" | \"info\" | \"success\";\n\nexport interface TrayAlert {\n  id: string;\n  level: TrayLevel;\n  title: string;\n  message?: string;\n  /** Short time, e.g. \"2m ago\". */\n  when?: string;\n  /** A button on the alert. */\n  action?: { label: string; onClick?: () => void };\n}\n\nexport interface StackedAlertsTrayProps extends React.ComponentPropsWithoutRef<\"div\"> {\n  theme?: \"dark\" | \"light\";\n  /** Newest first. */\n  alerts?: TrayAlert[];\n  /** Which corner it sits in. */\n  corner?: \"bottom-right\" | \"bottom-left\";\n  /** Keep it inside the nearest positioned parent instead of the screen. */\n  contained?: boolean;\n  /** Most alerts to show when open. The rest wait behind a count. */\n  maxOpen?: number;\n  onDismiss?: (alert: TrayAlert) => void;\n  onClearAll?: () => void;\n}\n\nconst FONT =\n  '\"Inter Variable\", Inter, \"SF Pro Display\", -apple-system, BlinkMacSystemFont, sans-serif';\nconst RING = \"outline-none focus-visible:ring-2 focus-visible:ring-[#5E6AD2]\";\nconst CARD_H = 68;\nconst GAP = 8;\nconst PEEK = 9;\nconst WIDTH = 340;\nconst HEAD = 38;\n\nconst LEVELS: Record<TrayLevel, { label: string; color: string }> = {\n  critical: { label: \"Critical\", color: \"#EB5757\" },\n  warning: { label: \"Warning\", color: \"#FC7840\" },\n  info: { label: \"Info\", color: \"#5E6AD2\" },\n  success: { label: \"Done\", color: \"#27A644\" },\n};\n\nconst PALETTES = {\n  dark: {\n    card: \"#161718\",\n    border: \"rgba(255,255,255,0.1)\",\n    text: \"#F7F8F8\",\n    soft: \"#D0D6E0\",\n    sub: \"#8A8F98\",\n    faint: \"#62666D\",\n    chip: \"rgba(255,255,255,0.07)\",\n    shadow: \"0 10px 30px rgba(0,0,0,0.45)\",\n  },\n  light: {\n    card: \"#FFFFFF\",\n    border: \"rgba(8,9,10,0.1)\",\n    text: \"#08090A\",\n    soft: \"#3C3F44\",\n    sub: \"#62666D\",\n    faint: \"#8A8F98\",\n    chip: \"rgba(8,9,10,0.05)\",\n    shadow: \"0 10px 30px rgba(8,9,10,0.12)\",\n  },\n};\n\nconst DEFAULT_ALERTS: TrayAlert[] = [\n  {\n    id: \"payments\",\n    level: \"critical\",\n    title: \"Payments are failing\",\n    message: \"12% of checkouts in the last hour.\",\n    when: \"Now\",\n    action: { label: \"Open\" },\n  },\n  {\n    id: \"storage\",\n    level: \"warning\",\n    title: \"Storage is almost full\",\n    message: \"You've used 92% of your plan.\",\n    when: \"8m ago\",\n  },\n  {\n    id: \"deploy\",\n    level: \"success\",\n    title: \"Deploy finished\",\n    message: \"Version 4.2 is live.\",\n    when: \"21m ago\",\n  },\n  {\n    id: \"invite\",\n    level: \"info\",\n    title: \"Sam joined your team\",\n    message: \"They've got editor access.\",\n    when: \"1h ago\",\n  },\n];\n\n/** Drawn as SVG, because a tiny border-radius circle turns lumpy on 1x screens. */\nfunction Dot({ size, color }: { size: number; color: string }) {\n  const r = size / 2;\n  return (\n    <svg\n      aria-hidden=\"true\"\n      width={size}\n      height={size}\n      viewBox={`0 0 ${size} ${size}`}\n      className=\"block shrink-0\"\n    >\n      <circle cx={r} cy={r} r={r} style={{ fill: color }} />\n    </svg>\n  );\n}\n\nexport function StackedAlertsTray({\n  theme = \"dark\",\n  alerts = DEFAULT_ALERTS,\n  corner = \"bottom-right\",\n  contained = false,\n  maxOpen = 5,\n  onDismiss,\n  onClearAll,\n  className,\n  style,\n  ...rest\n}: StackedAlertsTrayProps) {\n  const c = PALETTES[theme];\n  const [open, setOpen] = React.useState(false);\n  const [gone, setGone] = React.useState<string[]>([]);\n\n  const live = alerts.filter((a) => !gone.includes(a.id));\n  const shown = live.slice(0, maxOpen);\n  const hiddenCount = live.length - shown.length;\n  const isOpen = open && live.length > 0;\n  // On the document, because dismissing a card takes the focus with it.\n  React.useEffect(() => {\n    if (!isOpen) return;\n    const onKey = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") setOpen(false);\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => document.removeEventListener(\"keydown\", onKey);\n  }, [isOpen]);\n\n  const dismiss = (alert: TrayAlert) => {\n    setGone((prev) => [...prev, alert.id]);\n    onDismiss?.(alert);\n  };\n\n  const clearAll = () => {\n    setGone(alerts.map((a) => a.id));\n    setOpen(false);\n    onClearAll?.();\n  };\n\n  // Everything is anchored to the bottom edge, so opening grows upward over the page.\n  const closedHeight = CARD_H + PEEK * 2;\n  const openHeight = HEAD + shown.length * (CARD_H + GAP);\n\n  return (\n    <div\n      role=\"region\"\n      aria-label={`${live.length} alerts`}\n      className={`z-40 motion-safe:transition-[height,opacity] motion-safe:duration-300 motion-safe:ease-[cubic-bezier(0.22,1,0.36,1)] ${className ?? \"\"}`}\n      style={{\n        position: contained ? \"absolute\" : \"fixed\",\n        bottom: 16,\n        [corner === \"bottom-right\" ? \"right\" : \"left\"]: 16,\n        width: WIDTH,\n        maxWidth: \"calc(100% - 32px)\",\n        height: isOpen ? openHeight : closedHeight,\n        opacity: live.length ? 1 : 0,\n        pointerEvents: live.length ? \"auto\" : \"none\",\n        fontFamily: FONT,\n        color: c.text,\n        ...style,\n      }}\n      {...rest}\n    >\n      <div\n        className=\"absolute inset-x-0 top-0 flex items-center justify-between gap-2 motion-safe:transition-opacity motion-safe:duration-200\"\n        style={{\n          height: HEAD - GAP,\n          opacity: isOpen ? 1 : 0,\n          visibility: isOpen ? \"visible\" : \"hidden\",\n        }}\n      >\n        <button\n          type=\"button\"\n          data-collapse=\"\"\n          onClick={() => setOpen(false)}\n          className={`h-7 cursor-pointer rounded-full border px-3 text-[12.5px] leading-[18px] font-[510] tracking-[-0.008em] ${RING}`}\n          style={{ background: c.card, borderColor: c.border, color: c.soft }}\n        >\n          Show less\n        </button>\n        <button\n          type=\"button\"\n          data-clear=\"\"\n          onClick={clearAll}\n          className={`h-7 cursor-pointer rounded-full border px-3 text-[12.5px] leading-[18px] font-[510] tracking-[-0.008em] ${RING}`}\n          style={{ background: c.card, borderColor: c.border, color: c.soft }}\n        >\n          Clear all\n        </button>\n      </div>\n\n      {alerts.map((alert) => {\n        const at = shown.indexOf(alert);\n        const removed = gone.includes(alert.id);\n        const parked = at < 0;\n        const depth = Math.min(Math.max(at, 0), 3);\n        const top = at === 0;\n        const y = isOpen\n          ? -(shown.length - 1 - Math.max(at, 0)) * (CARD_H + GAP)\n          : -depth * -PEEK - PEEK * 2;\n        const scale = isOpen ? 1 : 1 - depth * 0.04;\n        const visible = !parked && (isOpen || at < 3);\n        const level = LEVELS[alert.level];\n        return (\n          <article\n            key={alert.id}\n            data-alert={alert.id}\n            aria-hidden={!visible || (!isOpen && !top)}\n            inert={!visible || (!isOpen && !top)}\n            className=\"absolute inset-x-0 flex items-center gap-2.5 rounded-xl border px-3 motion-safe:transition-[transform,opacity] motion-safe:duration-300 motion-safe:ease-[cubic-bezier(0.22,1,0.36,1)]\"\n            style={{\n              bottom: 0,\n              height: CARD_H,\n              zIndex: 10 - depth,\n              background: c.card,\n              borderColor: c.border,\n              boxShadow: c.shadow,\n              transformOrigin: \"bottom center\",\n              opacity: visible ? 1 : 0,\n              visibility: visible ? \"visible\" : \"hidden\",\n              transform: removed\n                ? `translateX(${corner === \"bottom-right\" ? 36 : -36}px) translateY(${y}px)`\n                : `translateY(${y}px) scale(${scale})`,\n            }}\n          >\n            <Dot size={8} color={level.color} />\n            <button\n              type=\"button\"\n              data-open=\"\"\n              onClick={() => setOpen(true)}\n              aria-expanded={isOpen}\n              disabled={isOpen}\n              className={`min-w-0 flex-1 cursor-pointer rounded border-0 bg-transparent p-0 text-left disabled:cursor-default ${RING}`}\n              style={{ color: \"inherit\" }}\n            >\n              <span className=\"flex items-baseline justify-between gap-2\">\n                <span className=\"truncate text-[13.5px] leading-[20px] font-[510] tracking-[-0.011em]\">\n                  {alert.title}\n                </span>\n                <span\n                  className=\"shrink-0 text-[12px] leading-[16px] tracking-[-0.005em] tabular-nums\"\n                  style={{ color: c.faint }}\n                >\n                  {!isOpen && top && live.length > 1\n                    ? `${live.length} alerts`\n                    : alert.when}\n                </span>\n              </span>\n              <span\n                className=\"block truncate text-[12.5px] leading-[18px] tracking-[-0.008em]\"\n                style={{ color: c.sub }}\n              >\n                {alert.message}\n              </span>\n            </button>\n            {alert.action && isOpen && (\n              <button\n                type=\"button\"\n                onClick={alert.action.onClick}\n                className={`h-7 shrink-0 cursor-pointer rounded-full border-0 px-2.5 text-[12.5px] leading-[18px] font-[510] tracking-[-0.008em] ${RING}`}\n                style={{ background: c.chip, color: c.soft }}\n              >\n                {alert.action.label}\n              </button>\n            )}\n            <button\n              type=\"button\"\n              data-dismiss={alert.id}\n              aria-label={`Dismiss ${alert.title}`}\n              onClick={() => dismiss(alert)}\n              className={`flex shrink-0 cursor-pointer items-center justify-center rounded-full border-0 ${RING}`}\n              style={{\n                width: 26,\n                height: 26,\n                background: c.chip,\n                color: c.sub,\n              }}\n            >\n              <svg\n                aria-hidden=\"true\"\n                viewBox=\"0 0 16 16\"\n                width=\"13\"\n                height=\"13\"\n                fill=\"none\"\n                className=\"block\"\n              >\n                <path\n                  d=\"m4.5 4.5 7 7m0-7-7 7\"\n                  stroke=\"currentColor\"\n                  strokeWidth=\"1.5\"\n                  strokeLinecap=\"round\"\n                />\n              </svg>\n            </button>\n          </article>\n        );\n      })}\n\n      {isOpen && hiddenCount > 0 && (\n        <p\n          className=\"absolute right-0 m-0 text-[12px] leading-[16px]\"\n          style={{ top: -18, color: c.sub }}\n        >\n          {hiddenCount} more\n        </p>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component"
    }
  ],
  "type": "registry:component"
}