{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "animated-badge",
  "title": "Animated Badge",
  "description": "Badge whose icon, label and width animate on status change; loading spin and live pulse.",
  "dependencies": [
    "class-variance-authority",
    "lucide-react",
    "motion"
  ],
  "registryDependencies": [
    "@ikas/animated-check",
    "@ikas/badge",
    "@ikas/motion",
    "@ikas/spinner",
    "@ikas/utils"
  ],
  "files": [
    {
      "path": "registry/ikas/animated-badge.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { AnimatePresence, motion, type Transition } from \"motion/react\"\nimport type { VariantProps } from \"class-variance-authority\"\nimport { CircleIcon, InfoIcon, TriangleAlertIcon, XIcon } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\nimport { EASE_OUT, FADE_IN, FADE_OUT, ICON_SPRING, SPRING, usePrefersReducedMotion } from \"@/lib/motion\"\nimport { badgeVariants, type BadgeColor, type BadgeStatus } from \"@/components/ui/badge\"\nimport { Spinner } from \"@/components/ui/spinner\"\nimport { AnimatedCheckIcon } from \"@/components/ikas/animated-check\"\n\ntype AnimatedBadgeStatus = BadgeStatus | \"loading\"\ntype AnimatedBadgeMedia = \"icon\" | \"dot\" | \"none\"\n\ntype AnimatedBadgeProps = Omit<\n  React.ComponentProps<\"span\">,\n  \"color\" | \"children\" | \"onDrag\" | \"onDragStart\" | \"onDragEnd\" | \"onAnimationStart\" | \"onAnimationEnd\"\n> &\n  Pick<VariantProps<typeof badgeVariants>, \"variant\" | \"size\"> & {\n    /** Semantic status. loading keeps the neutral tint and spins. Changing it rolls the icon and label. */\n    status?: AnimatedBadgeStatus\n    /** Raw palette color; wins over `status`. */\n    color?: BadgeColor\n    /** icon shows the status glyph, dot the quiet list dot, none only the label. */\n    media?: AnimatedBadgeMedia\n    /** Replaces the status glyph. Give it a `key` that changes with the status so it rolls. */\n    icon?: React.ReactNode\n    /** Opens a ring from the dot every 1.6s. For live states only; loading spins instead. */\n    pulse?: boolean\n    /** Identity of the label. Defaults to the text, so the same text with a new meaning needs a key. */\n    contentKey?: string | number\n    /** The label. Only the parts that change roll: pass an array to roll a number but keep its unit. */\n    children?: React.ReactNode | React.ReactNode[]\n  }\n\n/** Same mapping as Badge; the type is exported there, the table is not. */\nconst statusColor: Record<AnimatedBadgeStatus, BadgeColor> = {\n  neutral: \"neutral\",\n  info: \"blue\",\n  success: \"green\",\n  warning: \"amber\",\n  danger: \"red\",\n  loading: \"neutral\",\n}\n\nconst glyphs: Record<Exclude<AnimatedBadgeStatus, \"success\" | \"loading\">, React.ComponentType<{ className?: string }>> = {\n  neutral: CircleIcon,\n  info: InfoIcon,\n  warning: TriangleAlertIcon,\n  danger: XIcon,\n}\n\nconst blur = \"blur(2px)\"\nconst sharp = \"blur(0px)\"\n/** Reduced motion swaps in place: a short crossfade keeps the change legible without movement. */\nconst REDUCED_FADE: Transition = { duration: 0.12, ease: EASE_OUT }\n\n/** The leaving label rides up and out while the next one comes up from below. Full transform strings stay off the main thread. */\nconst roll = (reduce: boolean) =>\n  reduce\n    ? { initial: false as const, animate: { opacity: 1 }, exit: { opacity: 0, transition: REDUCED_FADE }, transition: REDUCED_FADE }\n    : {\n        initial: { transform: \"translateY(90%)\", opacity: 0, filter: blur },\n        animate: { transform: \"translateY(0%)\", opacity: 1, filter: sharp },\n        exit: { transform: \"translateY(-90%)\", opacity: 0, filter: blur, transition: FADE_OUT },\n        transition: { transform: SPRING, opacity: FADE_IN, filter: FADE_IN },\n      }\n\n/** Glyphs trade places in the slot: the old one shrinks and blurs away, the next one lands on the icon spring. */\nconst pop = (reduce: boolean, drawn: boolean) =>\n  reduce\n    ? { initial: false as const, animate: { opacity: 1 }, exit: { opacity: 0, transition: REDUCED_FADE }, transition: REDUCED_FADE }\n    : {\n        // A self-drawing check scales itself, so its wrapper only fades in.\n        initial: { transform: drawn ? \"scale(1)\" : \"scale(0.8)\", opacity: 0, filter: blur },\n        animate: { transform: \"scale(1)\", opacity: 1, filter: sharp },\n        exit: { transform: \"scale(0.8)\", opacity: 0, filter: blur, transition: FADE_OUT },\n        transition: { transform: ICON_SPRING, opacity: FADE_IN, filter: FADE_IN },\n      }\n\nfunction Glyph({ status, icon }: { status: AnimatedBadgeStatus; icon?: React.ReactNode }) {\n  if (icon) return <>{icon}</>\n  if (status === \"loading\") return <Spinner className=\"size-3\" />\n  if (status === \"success\") return <AnimatedCheckIcon className=\"size-3\" />\n  const Icon = glyphs[status]\n  return <Icon className=\"size-3\" />\n}\n\n/**\n * Badge whose icon, label and width animate when its status changes. The pill, colors\n * and sizes are Badge's own; motion only runs on a change, never on mount.\n */\nfunction AnimatedBadge({\n  status = \"neutral\",\n  color,\n  variant = \"soft\",\n  size,\n  media = \"icon\",\n  icon,\n  pulse = false,\n  contentKey,\n  children,\n  className,\n  ...props\n}: AnimatedBadgeProps) {\n  const reduce = usePrefersReducedMotion()\n  const resolved = color ?? statusColor[status]\n  const layout = reduce ? false : true\n  const slot = reduce ? false : (\"position\" as const)\n  const parts = React.Children.toArray(children).filter((part) => part !== \"\" && typeof part !== \"boolean\")\n  const keyOf = (part: React.ReactNode, index: number) =>\n    contentKey != null && parts.length === 1 ? contentKey : typeof part === \"string\" || typeof part === \"number\" ? part : `${status}-${index}`\n  const glyphKey = icon ? `icon-${React.isValidElement(icon) && icon.key != null ? icon.key : status}` : `${status}`\n  const ringing = pulse && media === \"dot\" && status !== \"loading\" && !reduce\n\n  return (\n    <motion.span\n      layout={layout}\n      transition={SPRING}\n      data-slot=\"animated-badge\"\n      data-status={status}\n      data-variant={variant}\n      data-color={resolved}\n      className={cn(\n        badgeVariants({ variant, color: resolved, size }),\n        \"relative overflow-hidden transition-[background-color,color,box-shadow] duration-200 ease-linear\",\n        className,\n      )}\n      {...props}\n    >\n      {media !== \"none\" && (\n        <motion.span layout={slot} transition={SPRING} className=\"relative grid size-3 shrink-0 place-items-center *:[grid-area:1/1]\">\n          {media === \"dot\" ? (\n            <>\n              <span aria-hidden className={cn(\"size-1.5 rounded-full\", variant === \"solid\" ? \"bg-current/80\" : \"bg-(--c-dot)\")} />\n              {ringing && (\n                <motion.span\n                  aria-hidden\n                  className={cn(\"size-1.5 rounded-full ring-1\", variant === \"solid\" ? \"ring-current/80\" : \"ring-(--c-dot)\")}\n                  animate={{ transform: [\"scale(1)\", \"scale(2.6)\"], opacity: [0.9, 0] }}\n                  transition={{ duration: 1.6, ease: EASE_OUT, repeat: Infinity }}\n                />\n              )}\n            </>\n          ) : (\n            <AnimatePresence initial={false} mode=\"popLayout\">\n              <motion.span key={glyphKey} aria-hidden className=\"grid place-items-center\" {...pop(reduce, !icon && status === \"success\")}>\n                <Glyph status={status} icon={icon} />\n              </motion.span>\n            </AnimatePresence>\n          )}\n        </motion.span>\n      )}\n      {parts.length > 0 && (\n        <motion.span layout={slot} transition={SPRING} className=\"inline-flex [clip-path:inset(-2px_-999px)]\">\n          {parts.map((part, index) => (\n            <span key={index} className=\"relative grid *:[grid-area:1/1]\">\n              <AnimatePresence initial={false} mode=\"popLayout\">\n                <motion.span key={keyOf(part, index)} className=\"block whitespace-pre\" {...roll(reduce)}>\n                  {part}\n                </motion.span>\n              </AnimatePresence>\n            </span>\n          ))}\n        </motion.span>\n      )}\n    </motion.span>\n  )\n}\n\nexport { AnimatedBadge, type AnimatedBadgeProps, type AnimatedBadgeStatus, type AnimatedBadgeMedia }\n",
      "type": "registry:component",
      "target": "@components/ikas/animated-badge.tsx"
    }
  ],
  "docs": "https://builders.ikas.com/tr/docs/app-development/ui-kit/components/animated-badge",
  "categories": [
    "motion",
    "data-display"
  ],
  "type": "registry:component"
}