{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "notification-badge",
  "title": "Notification badge",
  "description": "Count badge for icon buttons that springs in, bumps when the count rises, rolls its digits, caps at 99+ and offers a pulse ring or dot variant.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "https://goodui.dev/r/goodui-motion.json",
    "https://goodui.dev/r/locale.json",
    "https://goodui.dev/r/number-flow.json"
  ],
  "files": [
    {
      "path": "registry/components/feedback/notification-badge.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, useAnimate, useReducedMotion } from \"motion/react\"\nimport { cn } from \"@/lib/utils\"\nimport { useLabels } from \"@/lib/goodui-locale\"\nimport { NumberFlow } from \"@/components/goodui/number-flow\"\nimport { GooduiTokens, spring } from \"@/lib/goodui-motion\"\n\nconst CSS = `\n@keyframes pc-notification-badge-ping { 0% { transform: scale(1); opacity: .55 } 75%, 100% { transform: scale(2.1); opacity: 0 } }\n.pc-notification-badge-ping { animation: pc-notification-badge-ping 1.6s var(--pc-ease-out) infinite; }\n@media (prefers-reduced-motion: reduce) { .pc-notification-badge-ping { animation: none; opacity: 0 } }\n`\n\nexport type NotificationBadgeProps = Omit<React.ComponentProps<\"span\">, \"children\"> & {\n  /** The element the badge sits on, usually an icon button. */\n  children: React.ReactNode\n  /** Number shown in the badge. At 0 the badge hides (unless showZero); a higher count bumps it. */\n  count: number\n  /** Above this the badge reads \"99+\". */\n  max?: number\n  /** A plain dot instead of a number. */\n  dot?: boolean\n  /** A ring that keeps pinging outward while the count is above zero. */\n  pulse?: boolean\n  /** Keep the badge visible at 0. */\n  showZero?: boolean\n  /** Badge color: red (rose) for alerts, primary for your theme color, emerald or amber. */\n  tone?: \"red\" | \"primary\" | \"emerald\" | \"amber\"\n  /** Badge corner. Left and right are mirrored under RTL (right means the inline end). */\n  placement?: \"top-right\" | \"top-left\" | \"bottom-right\"\n  /** Words for screen readers after the count. */\n  label?: string\n  /** Text for built-in controls and screen readers; pass translations here. */\n  labels?: Partial<NotificationBadgeLabels>\n  /** Classes for the badge itself; className goes on the wrapper around children. */\n  badgeClassName?: string\n}\n\n/** Screen-reader wording for a capped count, e.g. \"More than 99\". */\nexport type NotificationBadgeLabels = { moreThan: (max: number) => string }\nconst DEFAULT_LABELS: NotificationBadgeLabels = { moreThan: (max) => `More than ${max}` }\n\n// Badge colors keep the small count at 4.5:1 or more: darker red and green fills, dark ink on amber.\nconst TONE = {\n  red: \"bg-rose-600 text-white\",\n  primary: \"bg-primary text-primary-foreground\",\n  emerald: \"bg-[oklch(0.53_0.13_155)] text-white\",\n  amber: \"bg-amber-500 text-amber-950\",\n}\nconst PING = { red: \"bg-rose-500\", primary: \"bg-primary\", emerald: \"bg-emerald-500\", amber: \"bg-amber-500\" }\nconst PLACE = {\n  \"top-right\": \"top-0 end-0 translate-x-1/3 -translate-y-1/3 rtl:-translate-x-1/3\",\n  \"top-left\": \"top-0 start-0 -translate-x-1/3 -translate-y-1/3 rtl:translate-x-1/3\",\n  \"bottom-right\": \"bottom-0 end-0 translate-x-1/3 translate-y-1/3 rtl:-translate-x-1/3\",\n}\n\n/** Count badge for an icon button. It springs in, bumps when the count goes up, caps at \"99+\" and can pulse. */\nexport function NotificationBadge({\n  children,\n  count,\n  max = 99,\n  dot = false,\n  pulse = false,\n  showZero = false,\n  tone = \"red\",\n  placement = \"top-right\",\n  label = \"unread\",\n  labels,\n  className,\n  badgeClassName,\n  ...props\n}: NotificationBadgeProps) {\n  const l = useLabels(\"notification-badge\", DEFAULT_LABELS, labels)\n  const reduce = useReducedMotion() ?? false\n  const [scope, animate] = useAnimate<HTMLSpanElement>()\n  const prev = React.useRef(count)\n  const visible = count > 0 || showZero\n  const capped = count > max\n\n  React.useEffect(() => {\n    const was = prev.current\n    prev.current = count\n    if (reduce || count <= was || was === 0 || !scope.current) return\n    // Quick swell, then a spring settles it back with a small overshoot.\n    let stopped = false\n    const up = animate(scope.current, { scale: 1.3 }, { duration: 0.1, ease: \"easeOut\" })\n    up.then(() => {\n      if (!stopped && scope.current) animate(scope.current, { scale: 1 }, spring.play)\n    })\n    return () => {\n      stopped = true\n    }\n  }, [count, reduce, animate, scope])\n\n  return (\n    <span className={cn(\"relative inline-flex shrink-0\", className)} {...props}>\n      <GooduiTokens />\n      <style href=\"pc-notification-badge\" precedence=\"default\">\n        {CSS}\n      </style>\n      {children}\n      <span className=\"sr-only\" aria-live=\"polite\">\n        {count > 0 ? `${capped ? l.moreThan(max) : count} ${label}` : \"\"}\n      </span>\n      <span aria-hidden=\"true\" className={cn(\"pointer-events-none absolute z-10\", PLACE[placement])}>\n        <AnimatePresence initial={false}>\n          {visible && (\n            <motion.span\n              key=\"badge\"\n              className=\"relative flex\"\n              initial={reduce ? { opacity: 0 } : { scale: 0, opacity: 0 }}\n              animate={{ scale: 1, opacity: 1 }}\n              exit={reduce ? { opacity: 0 } : { scale: 0, opacity: 0 }}\n              transition={reduce ? { duration: 0 } : spring.play}\n            >\n              {pulse && count > 0 && <span className={cn(\"pc-notification-badge-ping absolute inset-0 rounded-full\", PING[tone])} />}\n              <span\n                ref={scope}\n                className={cn(\n                  \"relative flex items-center justify-center rounded-full font-semibold tabular-nums ring-2 ring-background\",\n                  dot ? \"size-2.5\" : \"h-[18px] min-w-[18px] px-1 text-[10.5px] leading-none\",\n                  TONE[tone],\n                  badgeClassName,\n                )}\n              >\n                {!dot && (\n                  <NumberFlow value={Math.min(count, max)} suffix={capped ? \"+\" : \"\"} />\n                )}\n              </span>\n            </motion.span>\n          )}\n        </AnimatePresence>\n      </span>\n    </span>\n  )\n}\n",
      "type": "registry:component",
      "target": "components/goodui/notification-badge.tsx"
    }
  ],
  "categories": [
    "components",
    "feedback"
  ],
  "type": "registry:component"
}
