Code input Free
Free forever. One command, source you own.
Install
npx shadcn@latest add https://cottoncandy.dev/r/code-input.jsonFree. Lands in components/mu/code-input/ with the shared foundation. Needs React 19, Tailwind v4 and motion; reads your shadcn theme, and dark mode follows .dark.
Usage
import { CodeInput } from "@/components/mu/code-input/CodeInput";
<CodeInput verify={check} onVerified={() => router.push("/")} resend={<ResendButton />} />Use with an agent Beta
npx shadcn@latest add https://cottoncandy.dev/r/uisdk/code-input.jsonOptional. An AI agent in your app can read and set this piece by name, and you can ask before anything it can’t undo. The piece itself doesn’t change. Built on UI SDK 0.1.0-beta.23, which is in beta too, so this add-on follows its releases.
Source
How it works
Building with an agent? Hand it a ready prompt for this piece.
Input and reduced motion
- Pointer / touch: tap the beads to type; the phone's keyboard is numeric and offers a code from a message. Paste fills them all.
- Keyboard: Tab reaches the one field; type, Backspace and the arrows work as in any field. After a wrong code the digits are selected, so typing replaces them. The words ("Checking…", the errors, "Verified") are read out through a polite status region tied to the field.
- Reduced motion: no merge travel, shake or rise: the beads gather and split at once, the colour and words still change, and the tick appears drawn.
Props
| Prop | Default | What it does |
|---|---|---|
length | 6 | 4–8 | how many digits |
value | — | digits | the code typed (controlled) |
defaultValue | "" | digits | the code at first, when it keeps its own |
onValueChange | — | (value) => void | every change a person makes, a paste included |
verify | — | (code) => unknown | runs when the code is full; resolve true (or nothing) for right, false for wrong; a rejection says it couldn't check |
onVerified | — | (code) => void | the code was right |
name | — | string | posts the code in a form |
resend | — | React node | a slot under the beads, for your resend button |
labels | see below | object | label ("One-time code"), checking ("Checking…"), wrong ("That code didn't work. Try again."), failed ("Couldn't check the code. Try again."), verified ("Verified") |
accent | off | boolean | tints the right pill toward --mu-signal |
sound | off | true or 0–1 | a soft key per digit, a chime when right, a low note when wrong |
className | — | — | added to the root |
Sound
None. It loads in silence.
Off unless you pass sound (true, or a volume 0–1). Each digit typed plays a soft key, a right code saved and a wrong one failed. It never plays on hover, on mount, or when value changes from outside. setMuted(true) from components/mu/sounds.ts silences every cottoncandy item at once.
Licence
Free to use in your projects, under the terms on the licence.
One-time code beads fill as you type; a full code merges into one pill to check it, splits with a shake if it's wrong, and turns mint if it's right.
For one-time codes and two-step sign-inMore in Controls & forms