About
An order summary an assistant checks out with: items, totals, payment and a hold to pay bar.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Order Summary to your project and fits it to your theme.
Code
How Order Summary is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
"use client"
import * as React from "react"
import { OrderLineItem, OrderSummary } from "@/components/ui/order-summary"
const reducedMotion = () => window.matchMedia("(prefers-reduced-motion: reduce)").matches
type Phase = { items: number; status: "review" | "processing" | "success"; ms: number }
/** The order streams in, waits for the hold, pays, then shows its number. Loops. */
const PHASES: Phase[] = [
{ items: 0, status: "review", ms: 700 },
{ items: 1, status: "review", ms: 700 },
{ items: 2, status: "review", ms: 2600 },
{ items: 2, status: "processing", ms: 1500 },
{ items: 2, status: "success", ms: 3000 },
]
const FIT_CSS = "html,body{overflow:hidden}[data-fit-small] [data-fit-hide]{display:none!important}"
/**
* 21st shows a demo in a small frame: about 674 by 421 on a component page, 358 by 224 on a
* phone and 245 by 139 on a profile card. A demo taller than its frame gets scrollbars, which
* render white on dark pages. FitFrame fills the frame exactly instead.
*
* - "scale": the content shrinks until it fits, centered. For visuals such as orbs.
* - "crop": the content stays at full size from the top and fades out at the bottom. For text
* that streams in, where a changing scale would make the page breathe.
*
* `minWidth` lays out a wide demo (a table, a two column panel) at that width and scales it down
* to the frame, instead of letting it collapse to a narrow layout. The frame centers it, so it
* shrinks evenly on both sides.
*
* Anything marked `data-fit-hide` (state buttons, the chatcn.dev line) drops out in frames
* shorter than `hideBelow`, so a profile card shows the visual alone.
*/
function FitFrame({
children,
mode = "scale",
hideBelow = 360,
minWidth,
}: {
children: React.ReactNode
mode?: "scale" | "crop"
hideBelow?: number
minWidth?: string
}) {
const content = React.useRef<HTMLDivElement>(null)
const [cropped, setCropped] = React.useState(false)
React.useLayoutEffect(() => {
const el = content.current
if (!el) return
const measure = () => {
const vw = window.innerWidth
const vh = window.innerHeight
el.toggleAttribute("data-fit-small", vh < hideBelow)
// Layout sizes ignore the transform, so measuring never feeds back.
const w = Math.max(el.offsetWidth, el.scrollWidth)
const h = Math.max(el.offsetHeight, el.scrollHeight)
const scale = mode === "scale" ? Math.min(1, vw / w, vh / h) : 1
el.style.transform = scale < 1 ? `scale(${scale})` : ""
setCropped(mode === "crop" && h > vh + 1)
}
measure()
const observer = new ResizeObserver(measure)
observer.observe(el)
// Content that changes inside a fixed width box (a headline that cycles words) never resizes
// the box itself, so changes below it measure again on the next frame.
let frame = 0
const mutations = new MutationObserver(() => {
cancelAnimationFrame(frame)
frame = requestAnimationFrame(measure)
})
mutations.observe(el, { subtree: true, childList: true, characterData: true })
window.addEventListener("resize", measure)
return () => {
observer.disconnect()
mutations.disconnect()
cancelAnimationFrame(frame)
window.removeEventListener("resize", measure)
}
}, [mode, hideBelow])
const fade = "linear-gradient(to bottom, #000 calc(100% - 40px), transparent)"
return (
<div
className="flex w-full justify-center overflow-hidden"
style={{
height: "100dvh",
alignItems: mode === "crop" ? "flex-start" : "center",
maskImage: cropped ? fade : undefined,
WebkitMaskImage: cropped ? fade : undefined,
}}
>
<style>{FIT_CSS}</style>
<div
ref={content}
className="w-full shrink-0"
style={{ transformOrigin: mode === "crop" ? "top center" : "center", minWidth }}
>
{children}
</div>
</div>
)
}
// Unsplash 1560343090, 128 x 128, inline so the 21st preview needs no image host.
const orderShoe = {
alt: "A teal leather brogue on a pale pink block",
width: 128,
height: 128,
src: "data:image/webp;base64,UklGRuQEAABXRUJQVlA4INgEAADwGgCdASqAAIAAPpFGnEqlpCkkqBMKASASCWMHB3A6zkl0jd0PFWdA3C3PX6ZWoV+6MLY9L2uh9imEPOXHMDRFBRC8I8mr9GMBIRs8Df7AZZu5eXfVzgsAqpvkIn7XqnJdeZrL+IrP/1iNJU6l08WoWQ6U47IkQEAPc4FP0A3RzfzQeL8khO9TZm3Xer0tuMQlbYWEpnCD5BLeakl0j7NdZ10WLQfBQf5mutiqXnd0fw4YOJOBSlNXZeD/87MrEZEBo0yM/PinN3bwDlzIFma/XL+kRj5cm85JOFA1W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kDnlpWnC0IXZvx75iv+vwm4LkGUgFyzcvmD5F31XJUaMzI+VP4cBDnby3UYANUTOZeOlNOKEMUkstjSZzFRjDR7oFZkSKVbsF9NV4IdPTy8otBcjHm5fd0qRnGdjplGQ7QFuW29STyfgVloJ1bQi0B5LUoaaSFs2frYLs/TqLCMZBt4lcTqRa+GbSGq/xXn4biqfi7WecrF91jKboDDPubMzh/jjJxdoGFJ/AJIaoQbc96PVT93XgHtEqkAWj/XO6cGOqxchaCfq2ghDrrEy4WjfAA",
}
// Product photo, 128 x 128, inline so the 21st preview needs no image host.
const orderPack = {
alt: "A navy backpack standing on a pale floor",
width: 128,
height: 128,
src: "data:image/webp;base64,UklGRmYEAABXRUJQVlA4IFoEAACwHgCdASqAAIAAPo06l0elI6IhM/YKAKARiWcAzrZRSgbxKk8yFEArtxqYtLArHaomtpcoV6C4Hzd4j4mYKyeEvSzvK6jQ8CqzGyMpXhGHR9MaDxQXhKAk8YGNz2JS/TtzdU93onKXwD6u8ot+RRXC1hej9rlvipOfMbWoy6orVnVlWZq96YtZyIGNmPpx13DuZoDth9CJoPnlltLXtv+QXsIgH4gcAa+ou/C0l6OinDTez9SAWWqqZjQxxITkpVPn4gMry2tWwCLNU9TKxrD0/3g+7jAm9J24HsFJN8lyhHkOcPPMoKv1Qo1EHyCaeU6NF5PPqyr+JKXSMGHOAAD+7VFSDkCq8C6BbkO+7ox2oWdkKIU8TvyjnHixxAi46+32jN/0S+t8IBnk7mk+wKIa5p6mB2VXh20nS4elrpDXJcZ95go7CPGlfWPfYOpZGAb54B5YSgqUm2HKChzAAz66UzRSqAy4Xt+Ys2NOmNfrCqX6c3ZdhOObKiuzDqdi1zrBM9659NLTZetrM3p5FQsS+qRIWa9JTdPlvZLEYtOG5mh7OFraxbr6s0azRJa7vup2zieVU4iBN70ZZ1nCjN7rYLvzSiL0zy7qs+OciReHcjUCSqm3hkkeDlBKGkge3iiF9R0p9ae4SZlJN7yqwFNDIibNOU1eHe0mQQAhGPE0+PllU5d4J9d10ECnadkiuN+ppL/ZkfEyEGFUXuSnBVm2Zc4dG7YsxU2mxZOOf//ZeTb/UyzY72bMT+RgrJkKbPP4t5Uf7n8SKCwcR69+ps9luEnUXdhBf9y6q8+jdgX66LD+9lGHNu68Tn7phXr1KFOwqFrbbmS1850N+ow7XOFg2YIma3UZ8sYkv/QuG/f2m7+aPLSlXZdeaamSWWcWT0n/xXwSmiRAxcNqasoCpOb2B1WJcMW2p3XYPPqxCcp3S6c66/MTd1E2KhD/P6qdBNm5tkLm2uFR6J/lYyTFtWcW7ZOjfXmog/+Ze6iAzw0H5LluMBrulXw1WJghX8Dt0WUlsdRZ4SsFGF3HOmUu4g3C8HU3QOAHQGVjlutt0gjddaG9Mpo2Cdb97jvmBay4bJEZ/paX/y13rPmsnpHgZM3PyINtHMmtyg8FKB9l2JbAAwRJZeLGEoEu5mLWc62+Akt9UeZw8qTt3/rNXjpR6nIbna3eOcXXjvEkeueTDZRbQb6owyOrgoz+yA3c2Ds0Nvgzj8c8jvJwoEwBsJIVy+jcKUX31L6pqUNYlHaI8o4NhsyVzg8NVIrp5xsJet1QK9544cBazgcwOe8r7Pob1sfwgiibLUDqrIvDCwIBRnw4OHgVTFrVQiYIbJUEN6HKb1bdlgm2IHZIhcDVe8SBZUktp6V3KGv/e+BRKA1TFOlkMG+xovlKbdOJz73fCoKudb4whWdCYIIHtXcju2kQH6mJNIQ93wCJCWnlGEDMW2cK7M35RuvpQBPfDVSBsOigKkuW+Lp2XdyyoAAA",
}
const ITEMS: OrderLineItem[] = [
{
id: "brogue",
title: "Harlow suede brogue",
detail: "EU 42, Moss",
image: orderShoe.src,
quantity: 1,
unitPrice: 112,
},
{
id: "pack",
title: "Commuter backpack, 22 L",
detail: "Navy",
image: orderPack.src,
quantity: 1,
unitPrice: 89,
},
]
/** The line under each 21st demo that points back to the kit. */
function MoreOn({ slug, children }: { slug: string; children: React.ReactNode }) {
return (
<p data-fit-hide className="text-[0.75rem]/[1rem] text-(color:--chatcn-fg-faint) text-center text-balance">
{children}{" "}
<a
href={`https://chatcn.dev/docs/components/${slug}`}
target="_blank"
rel="noopener"
className="text-(color:--chatcn-fg-subtle) hover:text-(color:--chatcn-fg) underline underline-offset-2"
>
chatcn.dev
</a>
</p>
)
}
/**
* An assistant puts together an order from a chat: the items stream in, the total settles, the
* payment goes through and the order number lands. Loops. Press and hold the pay bar yourself.
*/
export default function OrderSummaryPreview() {
const [phase, setPhase] = React.useState(2)
React.useEffect(() => {
if (reducedMotion()) return
const id = window.setTimeout(() => setPhase((p) => (p + 1) % PHASES.length), PHASES[phase]!.ms)
return () => window.clearTimeout(id)
}, [phase])
const p = PHASES[phase]!
return (
<FitFrame minWidth="42rem">
<div className="flex w-full flex-col items-center justify-center gap-4 p-6">
<div className="grid w-full grid-cols-[1fr_21rem] items-center gap-6">
<div className="flex flex-col gap-3">
<p className="text-[0.875rem]/[1.25rem] tracking-[-0.003em] bg-(color:--chatcn-fill) text-(color:--chatcn-fg) rounded-(--chatcn-radius-lg) self-end px-3.5 py-2 text-pretty">
Order the moss brogues in 42 and the navy backpack. Same card as last time.
</p>
<p className="text-[0.875rem]/[1.25rem] tracking-[-0.003em] text-(color:--chatcn-fg-muted) text-pretty">
Both are in stock with free delivery by Thursday. Here is the order. Hold the bar to pay,
nothing is charged before that.
</p>
</div>
<OrderSummary
merchant="Fieldhouse"
items={ITEMS.slice(0, p.items)}
streaming={p.items < ITEMS.length}
status={p.status}
orderNumber={p.status === "success" ? "FH-208-41773" : undefined}
shipping={0}
shippingLabel="Arrives Thu, Oct 29"
tax={46.23}
currency="EUR"
locale="en-IE"
payment={{ brand: "Visa", last4: "4242", expiry: "08/28" }}
onChangePayment={() => {}}
onConfirm={() => new Promise((r) => setTimeout(r, 1200))}
receiptNote="Receipt sent to [email protected]"
onCancel={() => {}}
/>
</div>
<MoreOn slug="order-summary">An order summary an assistant can check out with. On</MoreOn>
</div>
</FitFrame>
)
}
















