StampCard
A loyalty punch card: a row of paper slots that fill with rubber stamps. Each stamp lands with its own seeded tilt and ink, and the newest one thunks onto the card.
Server ComponentWCAG AANew
Contributed by @luxmoncoeur. Meet the contributors
Matcha Corner
- Stamped
- Stamped
- Stamped
- Empty
- Empty
- Empty
- Empty
- Empty
5 more for a free matcha
Hojicha Club
- Stamped
- Stamped
- Stamped
- Stamped
- Empty
- Empty
Mixed inks
- Stamped
- Stamped
- Stamped
- Stamped
- Stamped
- Stamped
- Stamped
- Stamped
- Stamped
- Stamped
import { StampCard } from "@plop-ui/react";
<StampCard total={8} filled={3} title="Matcha Corner" />
// Your own stamp, drawn in currentColor so it takes the ink.
<StampCard
total={8}
filled={5}
title="Matcha Corner"
ink="leaf"
stamp={
<svg viewBox="0 0 48 48" aria-hidden="true">
<path d="M10 17h25l-2.6 19.5c-.3 2.4-2.3 4.2-4.7 4.2H17.4c-2.4 0-4.4-1.8-4.7-4.2Z" fill="none" stroke="currentColor" strokeWidth="3" />
</svg>
}
/>
// A different last stamp: pass a function of the slot index.
<StampCard total={6} filled={6} stamp={(i) => (i === 5 ? <b>FREE</b> : "★")} />Change every prop live in the playground.
Props
| Prop | Type | Default | What it does |
|---|---|---|---|
| filledrequired | number | — | How many slots are stamped, counted from the first. Clamped to 0…`total`. |
| totalrequired | number | — | How many slots the card has, e.g. 8 for "buy 8, get one free". |
| className | string | none | Extra class on the card. |
| columns | number | up to 6, balanced across rows (8 slots: 2 rows of 4) | Slots per row. |
| countText | (filled: number, total: number) => string | "3 of 8 stamps" | The count, shown on the card and read by screen readers. |
| id | string | none | Id of the card. |
| ink | "ink" | "tomato" | "leaf" | "ochre" | "berry" | "mixed" | mixed | The ink stamps are pressed in. `mixed` gives each stamp its own seeded ink. |
| label | string | title when it's text | Names the list for screen readers, before the count. |
| seed | string | number | generated from useId | Stable imperfections, shared by server and client. |
| showCount | boolean | true | Show the count ("3 of 8 stamps") on the card. It's always in the list's accessible name. |
| stamp | ReactNode | ((index: number) => ReactNode) | none | What each stamp looks like. Draw it with `currentColor` so it takes the ink. Pass a function to vary it by slot, e.g. a different last stamp. Decorative: screen readers hear the count instead. Default a ring stamp with a star. |
| statusText | { filled: string; empty: string; } | "Stamped" and "Empty" | What screen readers hear for each slot. |
| style | CSSProperties | none | Inline styles on the card. |
| title | ReactNode | none | A heading on the card, e.g. the café's name. |
Use it well
DoUse it for a short run of repeat visits, like 6 to 12 drinks, and say what the card is for in the title. Pass your own stamp so it feels like your café.
Don'tUse it for long or fine-grained progress (use Progress) or for steps in a process (use StatusTimeline).
Accessibility
- An ordered list named with the progress, like "Matcha Corner, 3 of 8 stamps"; each slot says "Stamped" or "Empty" in text, and countText and statusText change the words.
- Stamps are decorative and hidden from screen readers, so a custom stamp never needs alt text. The count on the card is hidden too, since the list's name already says it.
- Nothing is focusable: it's a picture of progress, not a control. A Server Component: no client JavaScript.
- The card is paper with ink text, so it passes AA on every surface, light and dark; every stamp ink is 3:1 or more on the paper. Reduced motion stops the thunk, and forced colors draw stamps in the system text color.