{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "event-ticket",
  "title": "Event Ticket",
  "author": "VenusUI",
  "description": "A ticket with a perforated stub you can drag or click to tear off.",
  "files": [
    {
      "path": "registry/default/ui/event-ticket.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nimport { cn } from \"@/lib/utils\"\n\ninterface EventTicketProps extends React.ComponentProps<\"div\"> {\n  event: string\n  /** e.g. \"Sat, 14 Mar 2026\". */\n  date: string\n  /** e.g. \"Doors 19:00\". */\n  time: string\n  venue: string\n  /** e.g. \"Floor · GA\". */\n  seat?: string\n  image?: { src: string; alt: string }\n  /** Ticket code: printed under the barcode, and the barcode is drawn from it. */\n  code: string\n  torn?: boolean\n  defaultTorn?: boolean\n  onTornChange?: (torn: boolean) => void\n}\n\nconst NOTCH = 12\n/** Half-circle notches cut into the top and bottom of an edge (the perforation). */\nconst notchMask = (side: \"left\" | \"right\") => {\n  const x = side === \"right\" ? \"100%\" : \"0%\"\n  const circle = (y: string) => `radial-gradient(circle ${NOTCH}px at ${x} ${y}, transparent ${NOTCH - 0.5}px, #000 ${NOTCH}px)`\n  return {\n    maskImage: `${circle(\"0%\")}, ${circle(\"100%\")}`,\n    maskSize: \"100% 51%\",\n    maskPosition: \"top, bottom\",\n    maskRepeat: \"no-repeat\",\n  } satisfies React.CSSProperties\n}\n\n/** Bar widths for a barcode-looking pattern, stable for a given code. */\nfunction bars(code: string) {\n  const widths: number[] = []\n  for (const char of code) {\n    const n = char.charCodeAt(0)\n    widths.push(1 + (n % 3), 1 + ((n >> 2) % 2), 1 + ((n >> 3) % 3), 1)\n  }\n  return widths\n}\n\nconst TEAR_DISTANCE = 70\n\n/**\n * A ticket with a perforated stub. Drag the stub to the right to tear it\n * off (a short drag springs back), or click, tap, Enter or Space to tear it.\n */\nfunction EventTicket({\n  event,\n  date,\n  time,\n  venue,\n  seat = \"General admission\",\n  image,\n  code,\n  torn: tornProp,\n  defaultTorn = false,\n  onTornChange,\n  className,\n  ...props\n}: EventTicketProps) {\n  const [uncontrolled, setUncontrolled] = React.useState(defaultTorn)\n  const torn = tornProp ?? uncontrolled\n  const [drag, setDrag] = React.useState<number | null>(null)\n  const start = React.useRef(0)\n  const moved = React.useRef(false)\n\n  const tear = () => {\n    setDrag(null)\n    setUncontrolled(true)\n    onTornChange?.(true)\n  }\n\n  const offset = drag ?? 0\n  const stubTransform = torn\n    ? \"translate(70px, 46px) rotate(16deg)\"\n    : `translateX(${offset}px) rotate(${offset * 0.12}deg)`\n\n  return (\n    <div data-slot=\"event-ticket\" data-torn={torn || undefined} className={cn(\"flex w-full max-w-xl drop-shadow-[0_18px_22px_rgb(0_0_0/0.16)] select-none dark:drop-shadow-[0_18px_22px_rgb(0_0_0/0.6)]\", className)} {...props}>\n      {/* Main part */}\n      <div\n        className=\"flex min-w-0 flex-1 flex-col overflow-hidden rounded-l-2xl bg-white text-neutral-900 dark:bg-neutral-900 dark:text-neutral-100\"\n        style={notchMask(\"right\")}\n      >\n        {image ? <img src={image.src} alt={image.alt} className=\"h-28 w-full object-cover sm:h-32\" draggable={false} /> : null}\n        <div className=\"flex flex-1 flex-col gap-3 p-5\">\n          <p className=\"text-lg leading-tight font-semibold tracking-tight text-balance sm:text-xl\">{event}</p>\n          <dl className=\"grid grid-cols-2 gap-x-4 gap-y-2 text-sm\">\n            <div>\n              <dt className=\"text-[10px] tracking-widest text-neutral-500 dark:text-neutral-400 uppercase\">Date</dt>\n              <dd className=\"font-medium\">{date}</dd>\n            </div>\n            <div>\n              <dt className=\"text-[10px] tracking-widest text-neutral-500 dark:text-neutral-400 uppercase\">Time</dt>\n              <dd className=\"font-medium\">{time}</dd>\n            </div>\n            <div className=\"col-span-2\">\n              <dt className=\"text-[10px] tracking-widest text-neutral-500 dark:text-neutral-400 uppercase\">Venue</dt>\n              <dd className=\"font-medium\">{venue}</dd>\n            </div>\n          </dl>\n        </div>\n      </div>\n\n      {/* Stub: a button you can drag, click or press to tear off. */}\n      <button\n        type=\"button\"\n        aria-label={torn ? \"Stub torn off\" : `Tear off the stub, ${seat}`}\n        disabled={torn}\n        onPointerDown={(e) => {\n          if (torn) return\n          e.currentTarget.setPointerCapture(e.pointerId)\n          start.current = e.clientX\n          moved.current = false\n          setDrag(0)\n        }}\n        onPointerMove={(e) => {\n          if (drag === null) return\n          const dx = Math.max(0, e.clientX - start.current)\n          if (dx > 4) moved.current = true\n          setDrag(dx)\n        }}\n        onPointerUp={() => {\n          if (drag === null) return\n          if (drag > TEAR_DISTANCE) tear()\n          else setDrag(null)\n        }}\n        onPointerCancel={() => setDrag(null)}\n        onClick={() => {\n          // A drag ends with a click too; only a tap or a key press tears here.\n          if (!moved.current && !torn) tear()\n          moved.current = false\n        }}\n        className={cn(\n          \"relative flex w-[30%] max-w-40 shrink-0 cursor-grab touch-pan-y flex-col items-center justify-between rounded-r-2xl border-l-2 border-dashed border-neutral-300 bg-white px-3 py-5 text-neutral-900 outline-none active:cursor-grabbing dark:border-neutral-700 dark:bg-neutral-900 dark:text-neutral-100\",\n          \"focus-visible:ring-3 focus-visible:ring-ring/50\",\n          drag === null && \"transition-[transform,opacity] duration-500 ease-[cubic-bezier(0.34,1.4,0.64,1)] motion-reduce:transition-none\",\n          torn && \"pointer-events-none opacity-0 duration-700 ease-in\"\n        )}\n        style={{ ...notchMask(\"left\"), transform: stubTransform, transformOrigin: \"0% 100%\" }}\n      >\n        <span className=\"text-[10px] font-semibold tracking-[0.25em] text-neutral-500 dark:text-neutral-400 uppercase\">Admit one</span>\n        <span className=\"text-center text-sm leading-tight font-medium\">{seat}</span>\n        <span className=\"flex w-full flex-col items-center gap-1.5\">\n          <span aria-hidden=\"true\" className=\"flex h-10 w-full items-stretch justify-center gap-px overflow-hidden\">\n            {bars(code).map((w, i) => (\n              <span key={i} className={i % 2 ? \"bg-transparent\" : \"bg-current\"} style={{ width: w }} />\n            ))}\n          </span>\n          <span className=\"font-mono text-[10px] tracking-wider text-neutral-500 dark:text-neutral-400\">{code}</span>\n        </span>\n      </button>\n      <p aria-live=\"polite\" className=\"sr-only\">\n        {torn ? \"Stub torn off.\" : \"\"}\n      </p>\n    </div>\n  )\n}\n\nexport { EventTicket }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.1"
  },
  "categories": [
    "interactive",
    "cards"
  ],
  "type": "registry:ui"
}