{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "count-badge",
  "title": "Count badge",
  "description": "A count on the top end corner of a control, such as the unread on a bell or a chat’s launcher: it rolls to its new value, reads 99+ past 99, and shrinks away at none. The Notification center’s bell and the AI chat popup’s launcher share it.",
  "dependencies": [],
  "registryDependencies": [
    "https://kinoui.com/r/animated-number.json",
    "https://kinoui.com/r/badge.json",
    "https://kinoui.com/r/theme.json"
  ],
  "files": [
    {
      "path": "registry/lib/count-badge.tsx",
      "content": "'use client'\n\nimport { AnimatedNumber } from '@/registry/components/kino/animated-number'\nimport { Badge } from '@/registry/components/kino/badge'\nimport { useState } from 'react'\n\nimport { cn } from '@/lib/utils'\n\n/*\n * A count on the top end corner of a control, such as the unread on a bell\n * or a chat's launcher. It rolls to its new value and reads 99+ past 99; at\n * none it shrinks away on `exit` and comes back on `enter`, keeping the last\n * count it showed while it goes. The control's name says the count, so a\n * screen reader hears it there and not from the badge. Its parent is\n * positioned.\n */\n\n/** The most a count shows before it reads 99+. */\nconst MAX_COUNT = 99\n\nfunction CountBadge({ count, locale }: { count: number; locale?: string }) {\n  // While the badge shrinks away it keeps the last count it showed.\n  const [shown, setShown] = useState(count)\n  if (count > 0 && count !== shown) setShown(count)\n  return (\n    <Badge\n      aria-hidden\n      data-slot='count-badge'\n      data-empty={count === 0 ? '' : undefined}\n      className={cn(\n        // On the control's top end corner, ringed in the page's colour so it reads apart from it.\n        'pointer-events-none absolute -end-1.5 -top-1.5 ring-2 ring-background',\n        // It shrinks away at none and grows back. A page that opens with none shows nothing moving.\n        'transition-[scale,opacity] duration-(--motion-enter-duration) ease-(--motion-enter-easing) data-empty:scale-95 data-empty:opacity-0 data-empty:duration-(--motion-exit-duration) data-empty:ease-(--motion-exit-easing) motion-reduce:data-empty:scale-100',\n      )}\n    >\n      <span className='flex items-center'>\n        <AnimatedNumber value={Math.min(shown, MAX_COUNT)} locale={locale} />\n        {shown > MAX_COUNT ? '+' : null}\n      </span>\n    </Badge>\n  )\n}\n\nexport { CountBadge, MAX_COUNT }\n",
      "type": "registry:lib",
      "target": "@lib/count-badge.tsx"
    }
  ],
  "type": "registry:lib"
}