{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"like-pop","type":"registry:ui","title":"Like Pop","description":"Like button whose heart squashes, pops and bursts into particles while the count rolls up digit by digit.","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/ui/like-pop.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useState } from \"react\";\nimport { AnimatePresence, MotionConfig, motion, useReducedMotion } from \"motion/react\";\nimport { Heart } from \"lucide-react\";\n\nexport interface LikePopProps {\n  /** Controlled liked state. */\n  liked?: boolean;\n  /** Initial liked state when uncontrolled. */\n  defaultLiked?: boolean;\n  /** Likes from everyone else. Your own like adds one on top. */\n  count?: number;\n  /** Called with the new liked state and the displayed count. */\n  onChange?: (liked: boolean, count: number) => void;\n  /** Heart and burst color. */\n  color?: string;\n  /** Particles per burst. */\n  particles?: number;\n  /** Accessible label. */\n  label?: string;\n  className?: string;\n}\n\nconst fmt = new Intl.NumberFormat(\"en-US\");\n\nfunction Burst({ color, n }: { color: string; n: number }) {\n  const tints = [color, \"#fbbf24\", \"#a78bfa\", \"#fb7185\"];\n  return (\n    <span aria-hidden className=\"pointer-events-none absolute left-1/2 top-1/2\">\n      <motion.span\n        className=\"absolute -left-5 -top-5 size-10 rounded-full border-2\"\n        style={{ borderColor: color }}\n        initial={{ scale: 0.3, opacity: 0.9 }}\n        animate={{ scale: 1.9, opacity: 0, borderWidth: 0 }}\n        transition={{ duration: 0.5, ease: \"easeOut\" }}\n      />\n      {Array.from({ length: n }, (_, i) => {\n        const a = (i / n) * Math.PI * 2 - Math.PI / 2;\n        const far = i % 2 ? 30 : 38;\n        const size = i % 2 ? 5 : 7;\n        return (\n          <motion.span\n            key={i}\n            className=\"absolute rounded-full\"\n            style={{ width: size, height: size, left: -size / 2, top: -size / 2, background: tints[i % tints.length] }}\n            initial={{ x: 0, y: 0, scale: 0 }}\n            animate={{ x: Math.cos(a) * far, y: Math.sin(a) * far, scale: [0, 1.2, 0] }}\n            transition={{ duration: 0.65, ease: [0.2, 0.8, 0.3, 1], delay: 0.08 }}\n          />\n        );\n      })}\n    </span>\n  );\n}\n\nexport function LikePop({\n  liked,\n  defaultLiked = false,\n  count = 128,\n  onChange,\n  color = \"#f43f5e\",\n  particles = 10,\n  label = \"Like\",\n  className,\n}: LikePopProps) {\n  const reduce = useReducedMotion();\n  const [inner, setInner] = useState(defaultLiked);\n  const [bursts, setBursts] = useState(0);\n  const on = liked ?? inner;\n  const total = count + (on ? 1 : 0);\n  const dir = on ? 1 : -1;\n  const chars = fmt.format(total).split(\"\").reverse(); // keyed from the right so new digits don't reshuffle\n\n  const toggle = () => {\n    const next = !on;\n    if (liked === undefined) setInner(next);\n    if (next) setBursts((b) => b + 1);\n    onChange?.(next, count + (next ? 1 : 0));\n  };\n\n  return (\n    <MotionConfig reducedMotion=\"user\">\n      <motion.button\n        type=\"button\"\n        aria-pressed={on}\n        aria-label={`${label}, ${fmt.format(total)} likes`}\n        onClick={toggle}\n        whileTap={{ scale: 0.92 }}\n        className={`group inline-flex h-12 select-none items-center gap-2.5 rounded-full border border-border bg-card pl-3 pr-5 text-foreground shadow-lg outline-none transition-colors hover:bg-muted focus-visible:ring-[3px] focus-visible:ring-ring/60 ${className ?? \"\"}`}\n      >\n        <span className=\"relative grid size-7 place-items-center\">\n          {on && bursts > 0 && !reduce && <Burst key={bursts} color={color} n={particles} />}\n          <motion.span\n            className=\"relative grid place-items-center group-active:scale-75 transition-[scale] duration-150\"\n            initial={false}\n            animate={{ scale: on ? [0.6, 1.35, 0.9, 1.05, 1] : [0.85, 1], rotate: on ? [0, -14, 8, 0] : 0 }}\n            transition={{ duration: on ? 0.6 : 0.25, ease: \"easeOut\" }}\n          >\n            <Heart\n              aria-hidden\n              className=\"size-6 transition-[fill,color] duration-200\"\n              strokeWidth={2}\n              style={{ color: on ? color : \"var(--muted-foreground)\", fill: on ? color : \"transparent\" }}\n            />\n          </motion.span>\n        </span>\n        <span aria-hidden className=\"flex flex-row-reverse text-sm font-semibold tabular-nums\">\n          {chars.map((c, i) => (\n            <span key={i} className=\"relative inline-block h-5 overflow-hidden leading-5\">\n              <span className=\"invisible\">{c}</span>\n              <AnimatePresence initial={false} custom={dir}>\n                <motion.span\n                  key={c}\n                  custom={dir}\n                  className=\"absolute inset-0 text-center\"\n                  variants={{\n                    enter: (d: number) => ({ y: d * 20, opacity: 0 }),\n                    center: { y: 0, opacity: 1 },\n                    exit: (d: number) => ({ y: d * -20, opacity: 0 }),\n                  }}\n                  initial=\"enter\"\n                  animate=\"center\"\n                  exit=\"exit\"\n                  transition={{ type: \"spring\", stiffness: 420, damping: 24, delay: i * 0.04 }}\n                >\n                  {c}\n                </motion.span>\n              </AnimatePresence>\n            </span>\n          ))}\n        </span>\n      </motion.button>\n    </MotionConfig>\n  );\n}\n"}]}