{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "like-burst",
  "title": "Like Burst",
  "description": "A like toggle with the same props as Like, whose outline collapses into a bubble that hollows into a ring as the heart pops back amid paired confetti dots.",
  "dependencies": [
    "@base-ui/react",
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/base/ui/like-burst.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\nimport { Button as ButtonPrimitive } from \"@base-ui/react/button\";\nimport { HeartIcon } from \"lucide-react\";\n\nimport { cn } from \"@/lib/utils\";\n\nimport \"./like-burst.css\";\n\n/** Keep in sync with the nth-child choreography in like-burst.css. */\nconst LIKE_BURST_PARTICLE_COUNT = 7;\n\n/**\n * The ring and every particle group run for the full burst duration, so the\n * burst is done once all of them report in. The per-dot animations on their\n * pseudo-elements share that clock and are not counted.\n */\nconst LIKE_BURST_SETTLE_ANIMATIONS = new Set([\n  \"like-burst-ring\",\n  \"like-burst-particle\",\n]);\nconst LIKE_BURST_SETTLE_COUNT = 1 + LIKE_BURST_PARTICLE_COUNT;\n\ntype ButtonProps = React.ComponentProps<typeof ButtonPrimitive>;\ntype LikeBurstClickEvent = Parameters<NonNullable<ButtonProps[\"onClick\"]>>[0];\n\nexport type LikeBurstProps = Omit<\n  ButtonProps,\n  \"aria-pressed\" | \"children\" | \"duration\" | \"onClick\" | \"size\"\n> & {\n  /** Controlled liked state. */\n  liked?: boolean;\n  /** Initial liked state for uncontrolled usage. */\n  defaultLiked?: boolean;\n  /** Called when the control requests a liked-state change. */\n  onLikedChange?: (liked: boolean) => void;\n  /** Called before the liked state changes. Prevent default to cancel the change. */\n  onClick?: (event: LikeBurstClickEvent) => void;\n  /** Accessible action label while unliked. Applied only when icon-only. */\n  likeLabel?: string;\n  /** Accessible action label while liked. Applied only when icon-only. */\n  unlikeLabel?: string;\n  /** Optional content placed after the heart. */\n  children?: React.ReactNode;\n  /**\n   * Heart size. Numbers are interpreted as pixels; CSS lengths are also\n   * accepted. Defaults to 32px via the `--like-burst-size` custom property,\n   * which can also be set in CSS. The ring and particles scale with it.\n   */\n  iconSize?: number | string;\n  /**\n   * Total burst duration in milliseconds; every phase keeps its share of it.\n   * Defaults to 700ms via the `--like-burst-duration` custom property, which\n   * can also be set in CSS.\n   */\n  duration?: number;\n  /** Classes applied to the heart and burst wrapper. */\n  iconClassName?: string;\n};\n\ntype LikeBurstStyle = React.CSSProperties & {\n  \"--like-burst-duration\"?: string;\n  \"--like-burst-size\"?: string;\n};\n\nexport function LikeBurst({\n  liked,\n  defaultLiked = false,\n  onLikedChange,\n  onClick,\n  likeLabel = \"Like\",\n  unlikeLabel = \"Unlike\",\n  children,\n  iconSize,\n  duration,\n  className,\n  iconClassName,\n  disabled,\n  ref,\n  style,\n  ...props\n}: LikeBurstProps) {\n  const [internalLiked, setInternalLiked] = React.useState(defaultLiked);\n  const controlled = liked !== undefined;\n  const isLiked = controlled ? liked : internalLiked;\n  const previousLikedRef = React.useRef(isLiked);\n  const likeIntentRef = React.useRef(false);\n  const [burstId, setBurstId] = React.useState(0);\n  const [burstActive, setBurstActive] = React.useState(false);\n  const settledAnimationsRef = React.useRef(0);\n  const likeBurstStyle: LikeBurstStyle = { ...style };\n\n  if (duration !== undefined) {\n    likeBurstStyle[\"--like-burst-duration\"] = `${duration}ms`;\n  }\n\n  if (iconSize !== undefined) {\n    likeBurstStyle[\"--like-burst-size\"] =\n      typeof iconSize === \"number\" ? `${iconSize}px` : iconSize;\n  }\n\n  // A burst only belongs to a liked heart, so unliking mid-burst drops it.\n  if (burstActive && !isLiked) {\n    setBurstActive(false);\n  }\n\n  // The burst celebrates user intent: it plays when `isLiked` turns true after\n  // a click asked for it — immediately for optimistic parents, or once a\n  // non-optimistic parent commits the result — but never for controlled state\n  // arriving from a fetch or a realtime update.\n  React.useEffect(() => {\n    if (!previousLikedRef.current && isLiked && likeIntentRef.current) {\n      settledAnimationsRef.current = 0;\n      setBurstId((current) => current + 1);\n      setBurstActive(true);\n    }\n\n    if (previousLikedRef.current !== isLiked) {\n      likeIntentRef.current = false;\n    }\n\n    previousLikedRef.current = isLiked;\n  }, [isLiked]);\n\n  const handleClick = React.useCallback(\n    (event: LikeBurstClickEvent) => {\n      onClick?.(event);\n\n      if (event.defaultPrevented || disabled) {\n        return;\n      }\n\n      const nextLiked = !isLiked;\n\n      if (!controlled) {\n        setInternalLiked(nextLiked);\n      }\n\n      likeIntentRef.current = nextLiked;\n\n      onLikedChange?.(nextLiked);\n    },\n    [controlled, disabled, isLiked, onClick, onLikedChange],\n  );\n\n  // The burst leaves the DOM once the ring and every particle group have\n  // finished, so long-lived liked items don't keep its layers mounted.\n  const handleBurstAnimationEnd = React.useCallback(\n    (event: React.AnimationEvent<HTMLSpanElement>) => {\n      if (!LIKE_BURST_SETTLE_ANIMATIONS.has(event.animationName)) return;\n\n      settledAnimationsRef.current += 1;\n\n      if (settledAnimationsRef.current >= LIKE_BURST_SETTLE_COUNT) {\n        setBurstActive(false);\n      }\n    },\n    [],\n  );\n\n  const bursting = isLiked && burstActive;\n\n  return (\n    <ButtonPrimitive\n      ref={ref}\n      type=\"button\"\n      disabled={disabled}\n      // With visible content, the accessible name must stay the visible text\n      // (WCAG 2.5.3); aria-pressed alone conveys the state. The action label\n      // only becomes the name when the control is icon-only.\n      aria-label={children ? undefined : isLiked ? unlikeLabel : likeLabel}\n      aria-pressed={isLiked}\n      data-slot=\"like-burst\"\n      data-liked={isLiked}\n      data-bursting={bursting ? \"\" : undefined}\n      data-icon-only={children ? undefined : \"\"}\n      className={cn(\n        \"like-burst relative inline-flex shrink-0 items-center justify-center gap-1.5 outline-none select-none focus-visible:ring-[3px] focus-visible:ring-ring/50 disabled:pointer-events-none disabled:opacity-50\",\n        children ? \"w-fit\" : \"rounded-full text-muted-foreground\",\n        className,\n      )}\n      style={likeBurstStyle}\n      onClick={handleClick}\n      {...props}\n    >\n      <span\n        data-slot=\"like-burst-icon\"\n        data-icon={children ? \"inline-start\" : undefined}\n        className={cn(\"like-burst-icon\", iconClassName)}\n        aria-hidden=\"true\"\n      >\n        {bursting ? (\n          <span\n            key={burstId}\n            data-slot=\"like-burst-effects\"\n            className=\"like-burst-effects\"\n            onAnimationEnd={handleBurstAnimationEnd}\n          >\n            <span className=\"like-burst-ring\" />\n            <span className=\"like-burst-particles\">\n              {Array.from({ length: LIKE_BURST_PARTICLE_COUNT }, (_, index) => (\n                <span className=\"like-burst-particle\" key={index} />\n              ))}\n            </span>\n          </span>\n        ) : null}\n\n        <HeartIcon className=\"like-burst-heart like-burst-heart-outline size-full\" />\n        <HeartIcon\n          className=\"like-burst-heart like-burst-heart-fill size-full\"\n          fill=\"currentColor\"\n        />\n      </span>\n\n      {children ? <span data-slot=\"like-burst-content\">{children}</span> : null}\n    </ButtonPrimitive>\n  );\n}\n",
      "type": "registry:ui",
      "target": "@ui/like-burst.tsx"
    },
    {
      "path": "registry/base/ui/like-burst.css",
      "content": "/* Defaults are layered for customization. Normal unlayered styles and\n   utilities in a later layer can override them. */\n@layer components {\n  .like-burst {\n    /* Its own heart colour, a touch pinker than Like's --ericts-like, to suit\n       the bubble's violet. A dedicated token rather than --destructive: a\n       like is not an error. */\n    --like-burst-color: var(--ericts-like-burst);\n    /* The bubble turns this colour before it hollows into a ring. Without\n       the token the burst keeps a single hue rather than losing its shadows. */\n    --like-burst-ring-color: var(\n      --ericts-like-burst-ring,\n      var(--like-burst-color)\n    );\n    --like-burst-size: 32px;\n    --like-burst-duration: 700ms;\n    --like-burst-ease-out: cubic-bezier(0.23, 1, 0.32, 1);\n  }\n\n  .like-burst[data-icon-only] {\n    width: max(2rem, calc(var(--like-burst-size) * 1.75));\n    height: max(2rem, calc(var(--like-burst-size) * 1.75));\n    transition: background-color 150ms var(--like-burst-ease-out);\n  }\n\n  /* Every burst length below is in em, and 1em is the heart, so the whole\n     effect scales with --like-burst-size. */\n  .like-burst-icon {\n    position: relative;\n    display: inline-flex;\n    width: var(--like-burst-size);\n    height: var(--like-burst-size);\n    flex: none;\n    font-size: var(--like-burst-size);\n    transform: scale(1);\n    transition: transform 160ms var(--like-burst-ease-out);\n  }\n\n  .like-burst:active .like-burst-icon {\n    transform: scale(0.97);\n  }\n\n  .like-burst-heart {\n    position: absolute;\n    inset: 0;\n    width: 100%;\n    height: 100%;\n    stroke-width: 1.75;\n  }\n\n  .like-burst-heart-outline {\n    color: currentColor;\n    transition:\n      opacity 150ms var(--like-burst-ease-out),\n      color 150ms var(--like-burst-ease-out);\n  }\n\n  .like-burst-heart-fill {\n    color: var(--like-burst-color);\n    opacity: 0;\n    transition: opacity 150ms var(--like-burst-ease-out);\n  }\n\n  .like-burst[data-liked=\"true\"] .like-burst-heart-outline {\n    opacity: 0;\n  }\n\n  .like-burst[data-liked=\"true\"] .like-burst-heart-fill {\n    opacity: 1;\n  }\n\n  /* The outline collapses into the point the bubble grows from. */\n  .like-burst[data-bursting] .like-burst-heart-outline {\n    animation: like-burst-collapse var(--like-burst-duration) both;\n  }\n\n  .like-burst[data-bursting] .like-burst-heart-fill {\n    animation: like-burst-pop var(--like-burst-duration) both;\n  }\n\n  .like-burst-effects {\n    position: absolute;\n    inset: 0;\n    pointer-events: none;\n  }\n\n  /* A filled disc drawn as an inset shadow, so hollowing it into a ring is a\n     paint-only spread change rather than a border-width layout change. */\n  .like-burst-ring {\n    position: absolute;\n    top: 50%;\n    left: 50%;\n    width: 1.3em;\n    height: 1.3em;\n    margin: -0.65em;\n    border-radius: 50%;\n    transform: scale(0);\n    animation: like-burst-ring var(--like-burst-duration) both;\n  }\n\n  .like-burst-particles {\n    position: absolute;\n    inset: 0;\n  }\n\n  /* A zero-size anchor at the centre, turned to face its own direction, so\n     travelling outward is a plain translateX in that rotated frame. */\n  .like-burst-particle {\n    position: absolute;\n    top: 50%;\n    left: 50%;\n    width: 0;\n    height: 0;\n    rotate: var(--like-burst-particle-angle, 0deg);\n    animation: like-burst-particle var(--like-burst-duration) both;\n  }\n\n  /* Only 7 groups are choreographed below (LIKE_BURST_PARTICLE_COUNT in\n     like-burst.tsx); anything past them has no direction, so hide it. */\n  .like-burst-particle:nth-child(n + 8) {\n    display: none;\n  }\n\n  /* Each group is a pair of dots set diagonally across its travel line, one\n     larger than the other. */\n  .like-burst-particle::before,\n  .like-burst-particle::after {\n    position: absolute;\n    width: var(--like-burst-dot-size);\n    height: var(--like-burst-dot-size);\n    margin: calc(var(--like-burst-dot-size) / -2);\n    border-radius: 50%;\n    /* Mixing the heart and ring colours the long way round the hue wheel\n       spreads the two into a rainbow, which white then softens to pastel. */\n    background-color: color-mix(\n      in oklch,\n      color-mix(\n          in oklch longer hue,\n          var(--like-burst-color),\n          var(--like-burst-ring-color) var(--like-burst-dot-hue)\n        )\n        70%,\n      white\n    );\n    transform: scale(0);\n    animation: like-burst-dot var(--like-burst-duration) both;\n    content: \"\";\n  }\n\n  .like-burst-particle::before {\n    --like-burst-dot-size: 0.15em;\n    --like-burst-dot-hue: var(--like-burst-particle-hue-a);\n    top: 0.13em;\n    left: 0.075em;\n  }\n\n  .like-burst-particle::after {\n    --like-burst-dot-size: 0.11em;\n    --like-burst-dot-hue: var(--like-burst-particle-hue-b);\n    top: -0.13em;\n    left: -0.075em;\n  }\n\n  /* Seven groups, clockwise from the top. Each takes two neighbouring stops\n     of the heart→ring sweep, so adjacent groups share a colour and the burst\n     reads as one continuous wheel. */\n  .like-burst-particle:nth-child(1) {\n    --like-burst-particle-angle: -90deg;\n    --like-burst-particle-hue-a: 0%;\n    --like-burst-particle-hue-b: 14.29%;\n  }\n\n  .like-burst-particle:nth-child(2) {\n    --like-burst-particle-angle: -38.57deg;\n    --like-burst-particle-hue-a: 14.29%;\n    --like-burst-particle-hue-b: 28.57%;\n  }\n\n  .like-burst-particle:nth-child(3) {\n    --like-burst-particle-angle: 12.86deg;\n    --like-burst-particle-hue-a: 28.57%;\n    --like-burst-particle-hue-b: 42.86%;\n  }\n\n  .like-burst-particle:nth-child(4) {\n    --like-burst-particle-angle: 64.29deg;\n    --like-burst-particle-hue-a: 42.86%;\n    --like-burst-particle-hue-b: 57.14%;\n  }\n\n  .like-burst-particle:nth-child(5) {\n    --like-burst-particle-angle: 115.71deg;\n    --like-burst-particle-hue-a: 57.14%;\n    --like-burst-particle-hue-b: 71.43%;\n  }\n\n  .like-burst-particle:nth-child(6) {\n    --like-burst-particle-angle: 167.14deg;\n    --like-burst-particle-hue-a: 71.43%;\n    --like-burst-particle-hue-b: 85.71%;\n  }\n\n  .like-burst-particle:nth-child(7) {\n    --like-burst-particle-angle: 218.57deg;\n    --like-burst-particle-hue-a: 85.71%;\n    --like-burst-particle-hue-b: 100%;\n  }\n\n  /* One clock for every layer: the percentages below are the choreography,\n     and --like-burst-duration stretches all of it together. The heart is\n     the payoff, so it lands early and the dots carry the tail.\n\n     0–8%     outline collapses to a point\n     3–22%    bubble grows from that point, turning ring-coloured from 15%\n     20–38%   filled heart bursts out of the bubble, past full size\n     22–40%   bubble hollows around it until the ring is gone\n     38–54%   heart settles back to full size\n     22–100%  dot pairs fly out, swell, then shrink away */\n  @keyframes like-burst-collapse {\n    0% {\n      opacity: 1;\n      transform: scale(1);\n      animation-timing-function: cubic-bezier(0.55, 0, 1, 0.45);\n    }\n\n    8%,\n    100% {\n      opacity: 0;\n      transform: scale(0);\n    }\n  }\n\n  /* Each offset appears once. A keyframe that omits a property leaves that\n     property's interval, and its easing, to the keyframes that name it. The\n     0.66em spread overfills the 0.65em radius, so the disc has no pinhole. */\n  @keyframes like-burst-ring {\n    0%,\n    3% {\n      transform: scale(0);\n      box-shadow: inset 0 0 0 0.66em var(--like-burst-color);\n      animation-timing-function: var(--like-burst-ease-out);\n    }\n\n    /* The colour turns late and fast: an even blend lingers on a washed-out\n       pink-lavender midpoint. */\n    15% {\n      box-shadow: inset 0 0 0 0.66em var(--like-burst-color);\n      animation-timing-function: ease-in-out;\n    }\n\n    22% {\n      transform: scale(1);\n      box-shadow: inset 0 0 0 0.66em var(--like-burst-ring-color);\n      animation-timing-function: var(--like-burst-ease-out);\n    }\n\n    40%,\n    100% {\n      transform: scale(1);\n      box-shadow: inset 0 0 0 0 var(--like-burst-ring-color);\n    }\n  }\n\n  /* Two segments rather than one overshooting curve: an ease-out spends most\n     of its travel in the first few frames, so the heart is near full size\n     almost as soon as it appears, and the settle is its own gentle move. */\n  @keyframes like-burst-pop {\n    0%,\n    20% {\n      transform: scale(0);\n      animation-timing-function: var(--like-burst-ease-out);\n    }\n\n    38% {\n      transform: scale(1.15);\n      animation-timing-function: ease-in-out;\n    }\n\n    54%,\n    100% {\n      transform: scale(1);\n    }\n  }\n\n  @keyframes like-burst-particle {\n    0%,\n    22% {\n      transform: translateX(0.6em);\n      animation-timing-function: cubic-bezier(0.21, 0.61, 0.35, 1);\n    }\n\n    100% {\n      transform: translateX(1em);\n    }\n  }\n\n  @keyframes like-burst-dot {\n    0%,\n    22% {\n      transform: scale(0);\n      animation-timing-function: var(--like-burst-ease-out);\n    }\n\n    32% {\n      transform: scale(1);\n      animation-timing-function: cubic-bezier(0.55, 0.085, 0.68, 0.53);\n    }\n\n    100% {\n      transform: scale(0);\n    }\n  }\n\n  /* Icon-only hover tints the heart and fills the round hit area with a halo\n     of the same colour. The heart is targeted directly because the root's\n     text colour is a utility, which outranks this layer. */\n  @media (hover: hover) and (pointer: fine) {\n    .like-burst[data-icon-only]:hover {\n      background-color: color-mix(\n        in oklch,\n        var(--like-burst-color) 12%,\n        transparent\n      );\n    }\n\n    .like-burst[data-icon-only]:hover .like-burst-heart-outline {\n      color: var(--like-burst-color);\n    }\n  }\n}\n\n/* Motion guards override ordinary customization, including inline timing.\n   Keep these outside the defaults layer; only motion declarations are important. */\n@media (prefers-reduced-motion: reduce) {\n  .like-burst-icon,\n  .like-burst:active .like-burst-icon {\n    transform: none !important;\n  }\n\n  /* The hearts keep their opacity crossfade; the burst ends where it starts.\n     Zero duration instead of `none` so animationend still fires and the\n     component can unmount the burst. `both` fill ends every layer invisible. */\n  .like-burst[data-bursting] .like-burst-heart-outline,\n  .like-burst[data-bursting] .like-burst-heart-fill,\n  .like-burst-ring,\n  .like-burst-particle,\n  .like-burst-particle::before,\n  .like-burst-particle::after {\n    animation-duration: 0ms !important;\n    animation-delay: 0ms !important;\n  }\n}\n",
      "type": "registry:file",
      "target": "@ui/like-burst.css"
    }
  ],
  "cssVars": {
    "light": {
      "ericts-like-burst": "oklch(0.7 0.19 6)",
      "ericts-like-burst-ring": "oklch(0.77 0.15 311)"
    },
    "dark": {
      "ericts-like-burst": "oklch(0.7 0.19 6)",
      "ericts-like-burst-ring": "oklch(0.77 0.15 311)"
    }
  },
  "meta": {
    "tags": [
      "like",
      "heart",
      "favorite",
      "toggle",
      "controlled",
      "render-prop",
      "button",
      "confetti",
      "social"
    ],
    "effects": [
      "collapse",
      "bubble-ring",
      "pop-in",
      "dot-burst",
      "reduced-motion"
    ]
  },
  "categories": [
    "action"
  ],
  "type": "registry:ui"
}