Code input
Shown as Tumbler, a made-up product
A six-digit code field approving a bank transfer: digits roll into place, paste and autofill land as a wave, with a resend timer, three tries and a receipt.
Installation
pnpm dlx shadcn@latest add "https://propui.dev/r/tumbler-code.json?token=…"Adds the piece to components/propui/04-tumbler-code/ and installs motion. Needs a free account: sign in and the command includes your token. Fonts load from Prop UI; download the zip to self-host them.
When to use
Reach for it when
- Confirming a high-stakes action (a payment, a transfer, a new device) with a one-time code.
- A code field that has to handle paste, autofill, a limited number of tries and a resend timer.
- Showing what is being approved beside the code, so people know what they are confirming.
Something else fits when
- A full sign-in with passkeys and an email code: Passkey login covers that flow.
- A code longer than about eight characters or with letters: use a single text field.
- A low-risk confirmation: a plain button is enough.
Usage
Fills a full window: give it a container with a definite height.
import Piece from "@/components/propui/04-tumbler-code/Section";
export default function Page() {
return (
<main className="h-dvh w-full overflow-hidden">
<Piece />
</main>
);
}Replace TRANSFER, CODE and PHONE_END in data.ts, and check the code against your server where Section.tsx compares it with CODE. Tumbler on its own takes value, onChange, label, note, error and status.
Your data
Replace these and everything on screen follows.
TRANSFER{ payee; sortCode; payeeEnd; reference; fromEnd; amount; fee; balance; confirmation }- The transfer panel, the totals and the receipt.
CODEstring- The demo code (418 207), shown behind the Demo button.
PHONE_ENDstring- The last digits of the phone named in the note under the code.
TRIES, RESEND_SECONDSnumber- How many wrong codes are allowed and how long until a new code can be sent.
TumblerProps{ value; onChange; label; note?; error?; status?; disabled?; split? }- The code field itself; error marks every window and nudges the row.
Interactions
- Type the six digits; focus moves on after each one and a complete code is checked on its own.
- Paste a whole code into any window, or let the phone autofill it; spaces and dashes are ignored.
- Enter a wrong code: the row nudges, turns red and one of three tries is spent; after the third the row locks until a new code is sent.
- Wait for the resend ring to empty, then send a new code, which resets the tries.
- With the right code, Approve unlocks; it shows Sending, then a receipt with the confirmation.
- Open Demo to see the code.
Keyboard
- ←or→
- Move between windows.
- HomeorEnd
- Jump to the first or last window.
- Backspace
- Clear the window, or the one before it when it is empty.
- Delete
- Clear the window in place.
- Enter
- Approve, once the code has been accepted.
- Esc
- Close the Demo popover.
Behaviour
Read from the code: roles, motion, breakpoints and what runs.
Accessibility
- The windows are a group labelled "Six-digit code"; each input is labelled with its position (digit 2 of 6).
- Inputs use a numeric keypad, and the first has autocomplete one-time-code so phones can fill the whole code.
- The note and error are tied to the inputs with aria-describedby; a wrong code is announced as an alert, and the receipt is a status region.
- Wrong and accepted codes are stated in words ("Code accepted."), not only shown in red and green.
- In forced colours mode the gliding ring, caret and rolling digits are hidden, and the plain inputs show the digits with a system outline.
Motion
- Each digit rolls up into its window like a lock tumbler; a pasted code rolls in as a short left-to-right wave.
- One focus ring glides between windows while focus stays in the row.
- A wrong code nudges the row once; the checking state pulses the windows softly.
- Reduced motion swaps digits without rolling, removes the nudge and pulse, and keeps the caret steady.
Responsive
- Above 900px the transfer and the approval sit side by side in one panel.
- Below 900px the transfer sits above the approval, in a panel up to 560px wide.
- Below 560px padding tightens and the windows shrink to 44px; below 400px the six windows share the row width so it fits a 320px screen.
Performance
- One one-second timer runs only while the resend countdown is going.
- No images: two local font weights of Geist Sans, Geist Mono for figures, and inline SVG.
Notes for AI
Give your coding assistant the Markdown, not a screenshot.
- Tumbler emits empty windows as spaces (trailing ones trimmed), so a complete code matches /^\d{6}$/.
- Keep the figures in TRANSFER and format money with money(); the totals are computed, not typed.
- Light only. Keep colours in the tokens at the top of post.css.
/p/tumbler-code/markdownThe whole library for assistants: llms.txt, or the MCP server in AI tools and MCP.