{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"click-burst","type":"registry:component","title":"Click Burst","description":"Wrap any clickable element and each click throws a small burst of stars and dots from the point you click: a moment of delight on a check, a like or a save.","author":"Saurabh <saurabh10102@gmail.com>","dependencies":["clsx","motion","tailwind-merge"],"registryDependencies":[],"docs":"Click Burst: usage, props and types at https://beui.dev/micro-interactions/click-burst.md","files":[{"path":"components/motion/click-burst.tsx","type":"registry:component","target":"@components/motion/click-burst.tsx","content":"\"use client\";\n// beui.dev/micro-interactions/click-burst\n\nimport { motion, useReducedMotion } from \"motion/react\";\nimport {\n  type ComponentPropsWithRef,\n  type MouseEvent,\n  type ReactNode,\n  useEffect,\n  useRef,\n  useState,\n} from \"react\";\nimport { EASE_OUT } from \"@/lib/ease\";\nimport { cn } from \"@/lib/utils\";\n\nexport interface ClickBurstProps extends Omit<ComponentPropsWithRef<\"span\">, \"children\"> {\n  /** The element to burst from: a checkbox, a button, a card. Its own clicks still work. */\n  children: ReactNode;\n  /** Whether a click bursts right now, e.g. only when a task is being checked, not unchecked. Default: true */\n  enabled?: boolean;\n  /** Where the burst starts: the click point, or the wrapper's centre. Keyboard clicks always use the centre. Default: \"pointer\" */\n  origin?: \"pointer\" | \"center\";\n  /** How many pieces fly out. Default: 12 */\n  count?: number;\n  /** How far the pieces fly, in px. Default: 34 */\n  spread?: number;\n  /** Piece colours, any CSS colour. Default: green, amber, sky and the theme's primary colour */\n  colors?: string[];\n}\n\ntype Piece = {\n  id: number;\n  x: number;\n  y: number;\n  star: boolean;\n  size: number;\n  spin: number;\n  color: string;\n  delay: number;\n};\n\ntype Burst = { id: number; x: number; y: number; pieces: Piece[] };\n\nconst COLORS = [\"#10b981\", \"#f59e0b\", \"#38bdf8\", \"var(--primary)\"];\n// Out fast and fading as they slow: a pop, not a drift.\nconst FLY = { duration: 0.6, ease: EASE_OUT } as const;\n// A burst is removed once its slowest piece has finished.\nconst LIFETIME_MS = 760;\n// A four-point star with concave sides, drawn in a 24 box.\nconst STAR = \"M12 0C12.6 7.4 16.6 11.4 24 12C16.6 12.6 12.6 16.6 12 24C11.4 16.6 7.4 12.6 0 12C7.4 11.4 11.4 7.4 12 0Z\";\n\nfunction makePieces(count: number, spread: number, colors: string[]): Piece[] {\n  return Array.from({ length: count }, (_, index) => {\n    // Even angles with a little jitter, so the burst is round but not mechanical.\n    const angle = (index / count) * Math.PI * 2 + (Math.random() - 0.5) * 0.5;\n    const distance = spread * (0.55 + Math.random() * 0.55);\n    const star = index % 3 !== 2;\n    return {\n      id: index,\n      x: Math.cos(angle) * distance,\n      y: Math.sin(angle) * distance,\n      star,\n      size: star ? 7 + Math.random() * 4 : 3 + Math.random() * 1.5,\n      spin: (Math.random() - 0.5) * 160,\n      color: colors[index % colors.length],\n      delay: Math.random() * 0.06,\n    };\n  });\n}\n\n/**\n * Wraps any clickable element and throws a small burst of stars and dots from\n * the point you click: a moment of delight on a check, a like or a save.\n * The child keeps its own behaviour; the burst is drawn on top, takes no\n * pointer events and is hidden from assistive technology. Nothing is drawn\n * with reduced motion.\n */\nexport function ClickBurst({\n  children,\n  enabled = true,\n  origin = \"pointer\",\n  count = 12,\n  spread = 34,\n  colors = COLORS,\n  className,\n  onClick,\n  ...props\n}: ClickBurstProps) {\n  const reduce = useReducedMotion() ?? false;\n  const [bursts, setBursts] = useState<Burst[]>([]);\n  const nextId = useRef(0);\n  const timers = useRef<number[]>([]);\n\n  useEffect(\n    () => () => {\n      for (const timer of timers.current) window.clearTimeout(timer);\n    },\n    [],\n  );\n\n  const fire = (event: MouseEvent<HTMLSpanElement>) => {\n    const box = event.currentTarget.getBoundingClientRect();\n    // A click from the keyboard has no pointer position (detail 0).\n    const fromPointer = origin === \"pointer\" && event.detail > 0;\n    const x = fromPointer ? event.clientX - box.left : box.width / 2;\n    const y = fromPointer ? event.clientY - box.top : box.height / 2;\n    const id = nextId.current++;\n    setBursts((current) => [...current, { id, x, y, pieces: makePieces(count, spread, colors) }]);\n    timers.current.push(\n      window.setTimeout(() => {\n        setBursts((current) => current.filter((burst) => burst.id !== id));\n      }, LIFETIME_MS),\n    );\n  };\n\n  return (\n    // biome-ignore lint/a11y/noStaticElementInteractions: listens to clicks that bubble from the interactive child; it is not a control itself\n    // biome-ignore lint/a11y/useKeyWithClickEvents: keyboard activation of the child arrives here as a click too\n    <span\n      {...props}\n      onClick={(event) => {\n        onClick?.(event);\n        if (enabled && !reduce && !event.defaultPrevented) fire(event);\n      }}\n      className={cn(\"relative inline-flex\", className)}\n    >\n      {children}\n      <span aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 overflow-visible\">\n        {bursts.map((burst) => (\n          <span key={burst.id} className=\"absolute\" style={{ left: burst.x, top: burst.y }}>\n            {burst.pieces.map((piece) => (\n              <motion.span\n                key={piece.id}\n                className=\"absolute\"\n                style={{\n                  width: piece.size,\n                  height: piece.size,\n                  left: -piece.size / 2,\n                  top: -piece.size / 2,\n                  color: piece.color,\n                }}\n                initial={{ x: 0, y: 0, scale: 0.4, opacity: 0, rotate: 0 }}\n                animate={{\n                  x: piece.x,\n                  y: piece.y,\n                  scale: [0.4, 1, 0.5],\n                  opacity: [0, 1, 0],\n                  rotate: piece.spin,\n                }}\n                transition={{ ...FLY, delay: piece.delay }}\n              >\n                {piece.star ? (\n                  <svg aria-hidden=\"true\" viewBox=\"0 0 24 24\" className=\"size-full\" fill=\"currentColor\">\n                    <path d={STAR} />\n                  </svg>\n                ) : (\n                  <span className=\"block size-full rounded-full bg-current\" />\n                )}\n              </motion.span>\n            ))}\n          </span>\n        ))}\n      </span>\n    </span>\n  );\n}\n"},{"path":"lib/ease.ts","type":"registry:lib","target":"@lib/ease.ts","content":"// Shared motion tokens. Easing curves mirror the CSS custom properties in\n// globals.css; springs are the canonical physics used across components.\n// Strong custom variants — defaults like `ease-in`/`ease-out` feel weak.\n\nexport const EASE_OUT = [0.16, 1, 0.3, 1] as const;\n/** Accelerating curve for things that fall (a dropped ball, a toppled block). Not for UI entrances. */\nexport const EASE_IN = [0.55, 0, 1, 0.45] as const;\nexport const EASE_IN_OUT = [0.77, 0, 0.175, 1] as const;\nexport const EASE_DRAWER = [0.32, 0.72, 0, 1] as const;\n\n/** CSS string form of EASE_OUT for inline style transitions. */\nexport const EASE_OUT_CSS = \"cubic-bezier(0.16, 1, 0.3, 1)\";\n\n/** Press feedback on buttons and other tappable surfaces. */\nexport const SPRING_PRESS = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 30,\n  mass: 0.6,\n} as const;\n\n/** Content swaps — label/icon slots trading places inside a control. */\nexport const SPRING_SWAP = {\n  type: \"spring\",\n  stiffness: 460,\n  damping: 30,\n  mass: 0.55,\n} as const;\n\n/** Overlay panel entrances — modals and sheets summoned by pointer. */\nexport const SPRING_PANEL = {\n  type: \"spring\",\n  stiffness: 420,\n  damping: 40,\n  mass: 0.5,\n} as const;\n\n/** Shared-layout glides — pills, indicators and panels morphing between positions. */\nexport const SPRING_LAYOUT = {\n  type: \"spring\",\n  stiffness: 360,\n  damping: 32,\n  mass: 0.6,\n} as const;\n\n/** Cursor-follow physics for decorative mouse tracking (magnetic, tilt, dock). */\nexport const SPRING_MOUSE = {\n  stiffness: 200,\n  damping: 15,\n  mass: 0.3,\n} as const;\n\n/** Dragged handles and fills (sliders) — critically damped `useSpring` config,\n * so the value follows the pointer butterily and never rebounds off an end. */\nexport const SPRING_GLIDE = {\n  stiffness: 700,\n  damping: 50,\n  mass: 0.5,\n} as const;\n\n/** Shared-surface morphs: a trigger growing into its panel and back on one\n * weighted spring, so opening and closing travel the same path. */\nexport const SPRING_MORPH = {\n  type: \"spring\",\n  duration: 0.5,\n  bounce: 0.22,\n} as const;\n"},{"path":"lib/utils.ts","type":"registry:lib","target":"@lib/utils.ts","content":"import { clsx, type ClassValue } from \"clsx\"\nimport { twMerge } from \"tailwind-merge\"\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs))\n}\n"}]}