One-Time Code

Boxes for a verification code that take a pasted or autofilled code whole, with Backspace across boxes.

Check your email

We sent a 6-digit code to [email protected]. It expires in 10 minutes.

Installation

pnpm dlx shadcn@latest add checkfu/uicontext/one-time-code

Usage

import { OneTimeCode } from "./ui/uicontext/components/OneTimeCode.ts"
const Message = UiSchema.TaggedEnum({	UpdatedCode: { code: Schema.Redacted(Schema.String) },	EnteredCode: { code: Schema.Redacted(Schema.String) },})export const CodeField = (h: Html.H<typeof Message.Type>, code: Redacted.Redacted<string>) =>	OneTimeCode(h, {		label: "Verification code",		value: code,		onChange: (next) => Message.UpdatedCode({ code: next }),		onComplete: (next) => Message.EnteredCode({ code: next }),	})

Examples

Letters, masked and disabled

Backup code

One of the ten codes you saved when you turned on two-step sign-in.

PIN
Code

Send a new code to try again.

API reference

Options

OneTimeCode options
NameTypeDefaultDescription
keystring—Names the field among others in the same view; needed for more than one.
labelrequiredstring—What the code is: "Verification code". It names the boxes, "Verification code 2 of 6".
hideLabelboolean—Hide the label but keep it as the boxes' name, when a heading above says what to type.
valuerequiredRedacted.Redacted<string>—The code so far. The caller keeps it and stores what onChange asks for.
lengthnumber6How many characters; 6 by default.
kind"numeric" | "alphanumeric"—Digits only (numeric, the default, with the number keypad on a phone) or letters and digits.
groupSizenumber—A gap after every this many boxes, as "123–456"; half the length by default, 0 for none.
maskboolean—Show dots instead of the characters, for a code read aloud in a shared space.
hintstring—A line under the boxes: "We sent it to [email protected]".
errorstring—What's wrong: "That code has expired". Marks every box invalid and is announced.
disabledboolean——
readOnlyboolean—Showing a code that's being checked: the boxes can't change.
namestring—The form field the whole code submits under.
onChangerequired(value: Redacted.Redacted<string>) => Message——
onComplete(value: Redacted.Redacted<string>) => Message—Every box is filled: check the code here.
styleStyle—StyleX styles applied after the field's own.

Source