本文へ移動
日本語
「レシート印刷」は Pro に含まれます。解除するとプレビューが表示されます。

仕組み

A card with a slot near its bottom edge and, under it, a window that always reserves the receipt's height. The window's top edge is the middle of the slot: clip-path cuts the paper there but lets its shadow out at the sides and bottom, and a soft dark band at the top sells the slot. While printing, the paper slides from translateY(-100%) to 0 in five feeds with short stops (one keyframe animation), and the status light beside the slot blinks. The total is always the real amount: a figure that changes while it prints would read as a wrong charge. The bottom edge is torn into teeth by a CSS mask; the drop-shadow sits on the unmasked wrapper so it follows the teeth. The barcode row is drawn from the order code.

向いている場面

  • The moment after a payment, a top-up or a booking, when a summary of what was paid is the best confirmation.
  • Point-of-sale, café, shop and ticket flows where a receipt is what people expect.
  • Order confirmations that should feel tangible rather than a plain green banner.

向かない場面

  • Long invoices with many lines: show a full invoice page or a downloadable document.
  • Confirmations of actions that involve no money or items: a success check is enough.

使い方

import { useState } from 'react'
import { ReceiptPrint } from './ReceiptPrint.jsx'

const items = [
  { label: 'Flat white', qty: 2, amount: 9 },
  { label: 'Almond croissant', amount: 5.4 },
  { label: 'Sparkling water', amount: 4 },
]

export function Checkout() {
  const [status, setStatus] = useState('idle')
  const pay = async () => {
    await fetch('/api/pay', { method: 'POST' })
    setStatus('printing')
  }
  return (
    <ReceiptPrint
      status={status}
      onPrinted={() => setStatus('printed')}
      merchant="Corner Café"
      code="A-2417"
      items={items}
      meta="Nov 25 · 09:41 · Card ·· 4821"
    >
      <div className="pay-row">
        <strong>Corner Café</strong>
        <button onClick={pay} disabled={status !== 'idle'}>Pay $18.40</button>
      </div>
    </ReceiptPrint>
  )
}

プロパティ

プロパティ型既定値説明
status'idle' | 'printing' | 'printed''idle'idle: no paper. printing: the receipt feeds out, then onPrinted is called. printed: the receipt is shown at rest without motion (for one that already exists when the page loads).
childrenReactNode—Content of the card above the slot: the merchant, the amount, a pay button. Inside it, var(--ds-receipt-card) and var(--ds-receipt-on-card) give the card colour and the ink on it, so a button can be the card's inverse in both themes.
merchant / mark / codestring / ReactNode / string—Receipt heading, the small square mark beside it (defaults to the merchant's initial) and an order code; the code also seeds the barcode row.
items{ label, amount, qty? }[]—Receipt lines. qty above 1 is shown as “×2” after the label.
totalnumbersum of itemsThe total, always shown as the final amount.
format(n) => stringn => `$${n.toFixed(2)}`Formats every amount, including the total.
metaReactNode—A small line under the total, such as date, time and card ending.
tone'ink' | 'surface''ink'The card: ink (a raised dark surface in the dark theme) or the surface colour with the card shadow. The paper stays light with dark print in both themes.
durationnumber1800Length of the whole print in ms, five feeds with short stops.
onPrinted() => void—Called when the receipt is fully out (at once with reduced motion). Set status to 'printed' here.
labelsobject—Replaces built-in text: receipt, total, printing, printed. Shallow-merged over the English defaults.
...restHTMLAttributes—Other attributes go to the root <div>.

アクセシビリティ

  • The receipt is a <section> named by its heading, with the lines as a real list; while idle it is hidden from assistive tech.
  • “Printing receipt…” and “Receipt ready” are announced through a polite live region; replace them with labels.
  • The status light is not the only signal: the receipt itself and the announcement carry the state.
  • Reduced motion shows the receipt at once, without the feed or the blinking light, and calls onPrinted immediately.

モーション

Feed: 1800ms by default, five moves of about 22% each with 6% stops, each move cubic-bezier(0.35, 0, 0.25, 1); the light blinks every 360ms while printing and then stays lit with a soft halo.

プロジェクトに追加

Pro メンバーはプロンプトをコピーし、コーディングエージェントが無料コンポーネントと同じ手順でソースを導入します。

ReceiptPrint.jsxreceipt-print.csstokens.cssREADME.md

2 つのファイルを一緒に導入します。スタイルは tokens.css の変数を読み、予備の値も持つため、単体でも表示できます。

フィードバック
「紙吹雪」は Pro に含まれます。解除するとプレビューが表示されます。