Receipt Printer

An animated thermal receipt printer with realistic paper physics and tear-off interaction.

Receipt Printer

An animated thermal receipt printer with realistic paper physics and tear-off interaction.

When the card scrolls into view it feeds a receipt one line at a time, with a small motor pause between lines. The sheet hangs from the slot, swings gently, and can be dragged, torn, and thrown. A printed barcode, totals, and a thank-you line are generated from the props.

Installation

Install the component with the Craft-UI Blocks CLI — it drops receipt-printer.tsx into your project and wires up its runtime dependencies:

npx mvpblocks add receipt-printer
pnpm dlx mvpblocks add receipt-printer
yarn dlx mvpblocks add receipt-printer
bunx mvpblocks add receipt-printer

File Structure

The CLI saves the component to your project's components/ui folder:

Import the default export from @/components/ui/receipt-printer. The prop types are exported as ReceiptPrinterProps and ReceiptItem.

Usage

ReceiptPrinter is a client component and every prop is optional — with no props it prints a demo coffee receipt. Drop it into a narrow card slot:

"use client";

import ReceiptPrinter from "@/components/ui/receipt-printer";

export function CheckoutCard() {
  return <ReceiptPrinter />;
}

Pass your own merchant, order, date, line items, tax rate, and currency. tax is a rate, so 0.075 means 7.5%:

const items = [
  { name: "Notebook", quantity: 2, price: 6.5 },
  { name: "Pen", quantity: 1, price: 2.25 },
];

<ReceiptPrinter
  merchant="Northwind Supply"
  order="#204"
  date="12 Nov 2026 · 09:15"
  items={items}
  tax={0.075}
  currency="£"
  onPrint={() => console.log("printed")}
  onTear={() => console.log("torn")}
/>

Set autoPrint={false} if you want the receipt to wait for the built-in Print receipt button:

<ReceiptPrinter autoPrint={false} className="max-w-xs" />

Theming

The housing is a zinc card (border-zinc-200 bg-zinc-50, inverting to dark:border-zinc-800 dark:bg-zinc-950) with a white front panel and a dark slot. The paper is always white for legibility, uses a monospace font, and gets serrated edges from CSS masks rather than images.

className lands on the outer card, so width and height overrides are safe:

<ReceiptPrinter className="h-[34rem] w-80" />

Animations

  • Feeding: the printer advances 15px at a time, pausing 55ms plus a little jitter between lines, while the housing buzzes.
  • Pendulum: the hanging sheet swings from the slot using a fixed 1/120s Verlet step with gravity 2600 and damping 0.996.
  • Tear: drag down more than 72px, flick faster than 900px/s, or press the keyboard tear button. The edge mask switches from bottom-only to top-and-bottom perforation.
  • Fall: a torn sheet uses gravity, air damping, and a slight sideways glide based on its angle.
  • Feedback: the printer shakes for 220ms on tear and calls navigator.vibrate where supported.
  • Reduced motion: the paper appears hanging immediately and tear returns to idle without a fall.

How it works

The receipt content is a normal React tree, so totals and the barcode stay crisp at any size. The animation state lives in a ref and writes transforms directly to the paper node; React only re-renders when the phase changes.

While printing, stepPrinting lowers the hidden offset of the sheet one line at a time. Once fully fed, stepPendulum constrains the sheet's center of mass to a fixed rod from the slot. Dragging moves the hinge; tearing changes the hinge to the grabbed point and starts free fall.

onPrint fires when the feed begins and onTear fires when the sheet detaches. The RAF loop pauses offscreen and resumes when the card is visible again.

Props

Prop

Type

ReceiptItem

Prop

Type

Registry Bundle

Install the exact registry entry shown on the right when you want the component file and its declared runtime dependencies together. Dependencies: none — the physics is written directly with React and the DOM.

Contact

If you find any bug or issue, feel free to raise an issue.

Last updated on