{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "receipt-printer",
  "title": "Receipt Printer",
  "author": "VenusUI",
  "description": "A receipt that prints out of a slot line by line, with itemized totals and a torn zig-zag edge.",
  "dependencies": [
    "lucide-react"
  ],
  "files": [
    {
      "path": "registry/default/ui/receipt-printer.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport { RotateCcw } from \"lucide-react\"\n\nimport { cn } from \"@/lib/utils\"\n\nexport interface ReceiptItem {\n  name: string\n  quantity: number\n  /** Unit price. */\n  price: number\n}\n\ninterface ReceiptPrinterProps extends React.ComponentProps<\"div\"> {\n  store: string\n  /** Address or a short line under the store name. */\n  address?: string\n  items: ReceiptItem[]\n  /** e.g. 0.2 for 20% tax, added on top of the subtotal. */\n  taxRate?: number\n  /** Intl currency code. */\n  currency?: string\n  locale?: string\n  /** e.g. \"Visa •• 4821\". */\n  paidWith?: string\n  orderId?: string\n  /** e.g. \"16 Nov 2026, 09:41\". */\n  date?: string\n}\n\nconst ZIGZAG = \"linear-gradient(-45deg, transparent 6px, #000 0) bottom left / 12px 12px repeat-x, linear-gradient(45deg, transparent 6px, #000 0) bottom left / 12px 12px repeat-x, linear-gradient(#000, #000) top / 100% calc(100% - 6px) no-repeat\"\n\n/**\n * A receipt that prints out of a slot, a line at a time, when it scrolls into\n * view; \"Print again\" replays it. Totals are calculated from the items. With\n * reduced motion it appears already printed.\n */\nfunction ReceiptPrinter({\n  store,\n  address,\n  items,\n  taxRate = 0,\n  currency = \"USD\",\n  locale = \"en-US\",\n  paidWith,\n  orderId,\n  date,\n  className,\n  ...props\n}: ReceiptPrinterProps) {\n  const ref = React.useRef<HTMLDivElement>(null)\n  const [printed, setPrinted] = React.useState(false)\n  const [run, setRun] = React.useState(0)\n\n  React.useEffect(() => {\n    const el = ref.current\n    if (!el) return\n    const observer = new IntersectionObserver(([entry]) => {\n      if (entry?.isIntersecting) {\n        observer.disconnect()\n        setTimeout(() => setPrinted(true), 250)\n      }\n    }, { threshold: 0.3 })\n    observer.observe(el)\n    return () => observer.disconnect()\n  }, [run])\n\n  const money = (n: number) => new Intl.NumberFormat(locale, { style: \"currency\", currency }).format(n)\n  const subtotal = items.reduce((sum, item) => sum + item.price * item.quantity, 0)\n  const tax = subtotal * taxRate\n  const lines = items.length + 10\n\n  return (\n    <div ref={ref} data-slot=\"receipt-printer\" className={cn(\"flex w-full max-w-xs flex-col items-center\", className)} {...props}>\n      {/* Printer */}\n      <div aria-hidden=\"true\" className=\"relative z-10 h-12 w-full rounded-2xl bg-linear-to-b from-neutral-700 to-neutral-900 shadow-lg\">\n        <span className=\"absolute inset-x-6 bottom-3 h-1.5 rounded-full bg-black/80 shadow-[inset_0_1px_2px_rgb(0_0_0)]\" />\n        <span className={cn(\"absolute top-3 right-4 size-1.5 rounded-full\", printed ? \"bg-emerald-400 shadow-[0_0_6px_rgb(52_211_153)]\" : \"bg-amber-400\")} />\n      </div>\n\n      {/* Paper, fed out of the slot in steps like a thermal printer. */}\n      <div className=\"-mt-3 w-[88%] overflow-hidden pt-3\">\n        <div\n          key={run}\n          className={cn(\n            \"bg-[#fdfcf8] px-5 pt-5 pb-8 font-mono text-[12px] leading-relaxed text-neutral-800 shadow-[0_10px_20px_-10px_rgb(0_0_0/0.35)] motion-reduce:translate-y-0 motion-reduce:transition-none\",\n            printed ? \"translate-y-0\" : \"-translate-y-full\"\n          )}\n          style={{ mask: ZIGZAG, WebkitMask: ZIGZAG, transition: `translate ${lines * 0.12}s steps(${lines})` }}\n        >\n          <p className=\"text-center text-sm font-bold tracking-widest uppercase\">{store}</p>\n          {address ? <p className=\"text-center text-[11px] text-neutral-500\">{address}</p> : null}\n          <p className=\"mt-2 flex justify-between text-[11px] text-neutral-500\">\n            <span>{date}</span>\n            <span>{orderId}</span>\n          </p>\n          <p aria-hidden=\"true\" className=\"my-2 overflow-hidden whitespace-nowrap text-neutral-400\">\n            {\"- \".repeat(40)}\n          </p>\n          <table className=\"w-full\">\n            <caption className=\"sr-only\">Items</caption>\n            <tbody>\n              {items.map((item) => (\n                <tr key={item.name}>\n                  <td className=\"py-0.5 pr-2 align-top\">\n                    {item.quantity > 1 ? `${item.quantity} × ` : \"\"}\n                    {item.name}\n                  </td>\n                  <td className=\"py-0.5 text-right align-top tabular-nums\">{money(item.price * item.quantity)}</td>\n                </tr>\n              ))}\n            </tbody>\n          </table>\n          <p aria-hidden=\"true\" className=\"my-2 overflow-hidden whitespace-nowrap text-neutral-400\">\n            {\"- \".repeat(40)}\n          </p>\n          <dl className=\"space-y-0.5\">\n            <div className=\"flex justify-between\">\n              <dt>Subtotal</dt>\n              <dd className=\"tabular-nums\">{money(subtotal)}</dd>\n            </div>\n            {taxRate > 0 ? (\n              <div className=\"flex justify-between\">\n                <dt>Tax ({Math.round(taxRate * 100)}%)</dt>\n                <dd className=\"tabular-nums\">{money(tax)}</dd>\n              </div>\n            ) : null}\n            <div className=\"flex justify-between pt-1 text-sm font-bold\">\n              <dt>Total</dt>\n              <dd className=\"tabular-nums\">{money(subtotal + tax)}</dd>\n            </div>\n          </dl>\n          {paidWith ? <p className=\"mt-2 text-[11px] text-neutral-500\">Paid · {paidWith}</p> : null}\n          <div aria-hidden=\"true\" className=\"mt-4 flex h-9 justify-center gap-px\">\n            {Array.from({ length: 44 }, (_, i) => (\n              <span key={i} className=\"bg-neutral-800\" style={{ width: [1, 2, 1, 3, 1, 1, 2][i % 7] }} />\n            ))}\n          </div>\n          <p className=\"mt-3 text-center\">Thank you! ♥</p>\n        </div>\n      </div>\n\n      <button\n        type=\"button\"\n        onClick={() => {\n          setPrinted(false)\n          setRun((n) => n + 1)\n        }}\n        className=\"mt-4 inline-flex items-center gap-1.5 rounded-md px-2 py-1 text-xs text-muted-foreground outline-none hover:text-foreground focus-visible:ring-3 focus-visible:ring-ring/50\"\n      >\n        <RotateCcw aria-hidden=\"true\" className=\"size-3\" /> Print again\n      </button>\n    </div>\n  )\n}\n\nexport { ReceiptPrinter }\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "version": "0.1.0"
  },
  "categories": [
    "animations",
    "data-display"
  ],
  "type": "registry:ui"
}