{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gift-box",
  "title": "Gift Box",
  "author": "VenusUI",
  "description": "A wrapped gift that pops its lid with confetti and reveals a coupon code with a copy button.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/gift-box.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { Check, Copy } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface GiftBoxProps extends React.ComponentProps<\"div\"> {\n  /** The coupon code revealed inside. */\n  code: string\n  /** What the code gets you, e.g. \"15% off your next order\". */\n  reward: string\n  /** Box color: any CSS color. The ribbon stays gold. */\n  color?: string\n  onOpen?: () => void\n}\n\nconst CONFETTI_COLORS = [\"#f43f5e\", \"#f59e0b\", \"#10b981\", \"#3b82f6\", \"#a855f7\", \"#facc15\"]\n/** Stable pseudo-random numbers in [0, 1), so every render places the confetti the same way. */\nconst spread = (i: number, salt: number) => {\n  const n = Math.sin(i * 12.9898 + salt * 78.233) * 43758.5453\n  return n - Math.floor(n)\n}\n/** A confetti piece's landing offset: an upward fan, each piece at its own angle and distance. */\nconst burst = (i: number) => {\n  const angle = (-90 + (spread(i, 1) - 0.5) * 150) * (Math.PI / 180)\n  const distance = 90 + spread(i, 2) * 130\n  return { x: Math.cos(angle) * distance * 1.3, y: Math.sin(angle) * distance }\n}\n\n/**\n * A wrapped gift. Click (or press Enter or Space) and the lid pops off,\n * confetti bursts out and a card with a coupon code rises from the box,\n * with a copy button. With reduced motion there's no confetti.\n */\nfunction GiftBox({ code, reward, color = \"oklch(0.62 0.2 15)\", onOpen, className, style, ...props }: GiftBoxProps) {\n  const [open, setOpen] = React.useState(false)\n  const [copied, setCopied] = React.useState(false)\n\n  const copy = async () => {\n    try {\n      await navigator.clipboard.writeText(code)\n      setCopied(true)\n      setTimeout(() => setCopied(false), 1800)\n    } catch {\n      // Clipboard blocked: the code is still visible to copy by hand.\n    }\n  }\n\n  return (\n    <div\n      data-slot=\"gift-box\"\n      data-open={open || undefined}\n      className={cn(\"group/gift relative flex w-64 flex-col items-center pt-36 select-none\", className)}\n      style={{ \"--box\": color, \"--box-dark\": `color-mix(in oklch, ${color} 78%, black)`, ...style } as React.CSSProperties}\n      {...props}\n    >\n      {/* The reward card, rising out of the box. */}\n      <div\n        inert={!open}\n        aria-hidden={!open}\n        className={cn(\n          \"absolute top-36 left-1/2 z-10 w-56 -translate-x-1/2 rounded-xl border bg-card p-4 text-center shadow-xl transition-[translate,opacity] duration-700 ease-[cubic-bezier(0.34,1.4,0.64,1)] motion-reduce:transition-none\",\n          open ? \"-translate-y-[118%] opacity-100 delay-200\" : \"translate-y-6 opacity-0\"\n        )}\n      >\n        <p className=\"text-xs font-medium tracking-widest text-muted-foreground uppercase\">Your gift</p>\n        <p className=\"mt-1 font-semibold text-balance\">{reward}</p>\n        <div className=\"mt-3 flex items-center justify-center gap-2\">\n          <code className=\"rounded-md border border-dashed bg-muted px-3 py-1.5 font-mono text-sm font-semibold tracking-widest\">{code}</code>\n          <button\n            type=\"button\"\n            onClick={copy}\n            aria-label={copied ? \"Copied\" : `Copy code ${code}`}\n            className=\"grid size-8 place-items-center rounded-md border outline-none hover:bg-muted focus-visible:ring-3 focus-visible:ring-ring/50\"\n          >\n            {copied ? <Check aria-hidden=\"true\" className=\"size-4 text-emerald-600\" /> : <Copy aria-hidden=\"true\" className=\"size-4\" />}\n          </button>\n        </div>\n        <p aria-live=\"polite\" className=\"sr-only\">\n          {copied ? \"Code copied\" : \"\"}\n        </p>\n      </div>\n\n      {/* Confetti */}\n      {open ? (\n        <div aria-hidden=\"true\" className=\"pointer-events-none absolute top-40 left-1/2 z-20 motion-reduce:hidden\">\n          {Array.from({ length: 40 }, (_, i) => {\n            const { x, y } = burst(i)\n            return (\n              <span\n                key={i}\n                className={cn(\"absolute animate-gift-box-confetti rounded-[2px]\", i % 3 === 0 ? \"h-1.5 w-3\" : \"size-2\")}\n                style={\n                  {\n                    background: CONFETTI_COLORS[i % CONFETTI_COLORS.length],\n                    \"--x\": `${x.toFixed(1)}px`,\n                    \"--y\": `${y.toFixed(1)}px`,\n                    \"--r\": `${(spread(i, 3) * 720 - 360).toFixed(0)}deg`,\n                    animationDelay: `${(spread(i, 4) * 140).toFixed(0)}ms`,\n                  } as React.CSSProperties\n                }\n              />\n            )\n          })}\n        </div>\n      ) : null}\n\n      <button\n        type=\"button\"\n        onClick={() => {\n          if (open) return\n          setOpen(true)\n          onOpen?.()\n        }}\n        aria-label={open ? \"Gift opened\" : \"Open the gift\"}\n        aria-disabled={open}\n        className=\"relative z-30 h-40 w-48 cursor-pointer rounded-md outline-none focus-visible:ring-3 focus-visible:ring-ring/50 aria-disabled:cursor-default\"\n      >\n        {/* Box */}\n        <span aria-hidden=\"true\" className=\"absolute inset-x-2 top-10 bottom-0 rounded-b-md bg-(--box) shadow-[inset_0_-12px_20px_rgb(0_0_0/0.15),0_18px_30px_-16px_rgb(0_0_0/0.5)]\">\n          <span className=\"absolute inset-y-0 left-1/2 w-7 -translate-x-1/2 bg-linear-to-r from-amber-300 via-amber-200 to-amber-400\" />\n        </span>\n        {/* Lid with bow */}\n        <span\n          aria-hidden=\"true\"\n          className={cn(\n            \"absolute inset-x-0 top-4 h-8 transition-[translate,rotate,opacity] duration-700 ease-out motion-reduce:transition-none\",\n            open\n              ? \"translate-x-28 -translate-y-20 rotate-[38deg] opacity-0\"\n              : \"group-hover/gift:-translate-y-1.5 group-hover/gift:rotate-[-2deg]\"\n          )}\n        >\n          <span className=\"absolute inset-0 rounded-md bg-(--box-dark) shadow-md\">\n            <span className=\"absolute inset-y-0 left-1/2 w-7 -translate-x-1/2 bg-linear-to-r from-amber-300 via-amber-200 to-amber-400\" />\n          </span>\n          <span className=\"absolute bottom-[85%] left-1/2 h-10 w-24 -translate-x-1/2\">\n            <span className=\"absolute bottom-0 left-0 h-9 w-11 rotate-[-25deg] rounded-[50%_50%_40%_60%] border-[7px] border-amber-300\" />\n            <span className=\"absolute right-0 bottom-0 h-9 w-11 rotate-[25deg] rounded-[50%_50%_60%_40%] border-[7px] border-amber-300\" />\n            <span className=\"absolute bottom-0 left-1/2 size-5 -translate-x-1/2 rounded-full bg-amber-400\" />\n          </span>\n        </span>\n      </button>\n      <p className=\"mt-4 text-sm text-muted-foreground\">{open ? \"Enjoy!\" : \"Tap the gift to open it\"}</p>\n    </div>\n  )\n}\n\nexport { GiftBox }\n",
      "type": "registry:ui"
    }
  ],
  "cssVars": {
    "theme": {
      "animate-gift-box-confetti": "gift-box-confetti 1.6s cubic-bezier(0.2, 0.7, 0.4, 1) forwards"
    }
  },
  "css": {
    "@keyframes gift-box-confetti": {
      "0%": {
        "transform": "translate(0, 0) rotate(0deg)",
        "opacity": "1"
      },
      "45%": {
        "transform": "translate(calc(var(--x) * 0.7), var(--y)) rotate(calc(var(--r) * 0.5))",
        "opacity": "1"
      },
      "100%": {
        "transform": "translate(var(--x), calc(var(--y) + 260px)) rotate(var(--r))",
        "opacity": "0"
      }
    }
  },
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "interactive",
    "animations"
  ],
  "type": "registry:ui"
}