Receipt chat
Chat as a receipt printer. Each answer prints out of a slot above the composer, the paper feeding up as the text streams, then it is cut with a torn edge and settles into the thread.
On this page
Installation
Usage
import { ReceiptChat } from "@/components/ui/chatcn/receipt-chat"
<ReceiptChat
title="Pocket ledger"
messages={chat.chatcnMessages}
status={chat.status}
onSend={(text) => chat.sendMessage({ text })}
onStop={chat.stop}
onRetry={() => chat.regenerate()}
/>While an answer streams, the paper feeds up by the height of each new line in small motor steps (feed="smooth" eases instead), and the line being printed always sits just above the slot. When the stream ends the foot prints, the blank tail feeds out, and the paper is cut with a torn edge and lifts off with a slight lean, so a thread reads as a stack of real receipts. Scroll up and the feed lets go; send and it returns to the slot.
Markdown tables print as receipt lines with the last column on the right, and a row in bold is a total with a dashed rule above it. A printer prints whole lines: a table row appears once it has fully arrived, so raw pipes never print. The head carries title, the receipt number and the time; the foot carries model, tokens and durationMs from message.metadata when you set them, Stopped early for stopped, then a barcode drawn from the message id. Only text parts print: tool calls and reasoning stay off the paper.
Examples
States
Props
| Prop | Type | Notes |
|---|---|---|
messages | ChatcnMessage[] | The thread |
status | "ready" | "submitted" | "streaming" | "error" | Same as AI SDK useChat |
error | ReactNode | Shown with Retry. Say how to fix it |
onSend, onStop, onRetry | (text) => void, () => void, () => void | Wire to your chat |
title | ReactNode | Printed at the head of every receipt |
feed | "stepper" | "smooth" | How the paper moves. Defaults to stepper |
barcode | boolean | A barcode from the message id. Defaults to true |
renderFooter | (message) => ReactNode | Extra lines under the totals |
message.metadata | { model?, tokens?, durationMs?, createdAt?, stopped? } | The foot |
value, defaultValue, onValueChange | string | The input, controlled or not |
disabled, autoFocus, locale | Input and time formatting | |
labels | Partial<ReceiptChatLabels> | Every string, for translation |
Keyboard
| Key | Action |
|---|---|
Enter | Send |
Shift Enter | New line |
Escape | Stop printing |
Accessibility
- The thread is a
logregion of real text, and each receipt anarticlenamed by its number. - The torn edges, slot, curl and barcode are decorative and hidden from assistive tech.
- The finished answer is announced once through a polite live region, never per line.
- Under forced colors the paper drops its torn edges for a plain border.
Motion
- The feed moves the thread with additive transform animations, so a fast stream reads as one continuous feed instead of restarting on every line.
- The cut lifts the receipt 10 px and leans it under 1 degree over 300 ms.
- Reduced motion keeps every receipt still and flat: text appears, edges still tear.