One-Time Code Verification Card
Six crisp verification cells with strong borders and an active sky glow, paste-the-whole-code support, a clear wrong-code error and success state, a resend button with a live cooldown, and readable fallback actions.
Install UI SDK & packages
npm install @ui-sdk/react @ui-sdk/core lucide-react
Give your agent the UI SDK skill
npx skills add vercel-labs/ui --skill ui-sdk
"use client"; import * as React from "react"; import { Check, Minus, RefreshCw } from "lucide-react"; import { Button } from "@ui-sdk/react/button"; import { Field, FieldDescription, FieldError, FieldLabel } from "@ui-sdk/react/field"; import { OTPInput, OTPInputGroup, OTPInputSeparator, OTPInputSlot, } from "@ui-sdk/react/otp-input"; const card = "rounded-2xl border border-[#d8e0ea] bg-white shadow-[0_18px_44px_rgba(15,23,42,0.12)] dark:border-slate-400/20 dark:bg-[#111827] dark:shadow-[0_24px_60px_rgba(0,0,0,0.5)]"; const labelCls = "block text-[13px] font-semibold leading-snug text-slate-800 dark:text-slate-200"; const hintCls = "text-xs leading-relaxed text-slate-600 dark:text-slate-400"; const errorCls = "text-xs font-semibold text-red-800 dark:text-red-300"; const btnBase = "inline-flex cursor-pointer items-center justify-center gap-2 whitespace-nowrap rounded-[10px] font-bold transition hover:-translate-y-px active:translate-y-px disabled:pointer-events-none disabled:opacity-50 focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-sky-500"; const btnMd = "h-11 px-4 text-sm"; const btnSm = "h-9 px-3 text-[13px]"; const btnPrimary = `${btnBase} border border-sky-300/60 bg-linear-to-b from-sky-300 via-sky-400 to-sky-600 text-[#031521] shadow-[inset_0_1px_0_rgba(255,255,255,0.55),inset_0_-2px_0_rgba(3,55,86,0.35),0_8px_20px_rgba(2,132,199,0.25)] hover:brightness-105`; const btnGhost = `${btnBase} border border-slate-300 bg-linear-to-b from-white to-slate-100 text-slate-900 shadow-[inset_0_1px_0_rgba(255,255,255,0.95),inset_0_-1.5px_0_rgba(15,23,42,0.08),0_1px_2px_rgba(15,23,42,0.06)] hover:border-slate-400 dark:border-slate-400/35 dark:from-[#243047] dark:to-[#182234] dark:text-slate-50 dark:shadow-[inset_0_1px_0_rgba(255,255,255,0.09),inset_0_-1.5px_0_rgba(0,0,0,0.35)] dark:hover:border-slate-400/55`; const slotBase = "relative grid h-14 min-w-0 flex-1 place-items-center rounded-xl border-[1.5px] bg-white font-mono text-[22px] font-bold text-slate-900 shadow-[0_1px_2px_rgba(15,23,42,0.06)] transition-[border-color,box-shadow] data-active:border-sky-600 data-active:ring-[3px] data-active:ring-sky-600/25 data-fake-caret:after:h-6 data-fake-caret:after:w-0.5 data-fake-caret:after:animate-pulse data-fake-caret:after:rounded-full data-fake-caret:after:bg-sky-600 data-fake-caret:after:content-[''] motion-reduce:data-fake-caret:after:animate-none dark:bg-[#182234] dark:text-slate-50 dark:shadow-[inset_0_1px_2px_rgba(0,0,0,0.35)] dark:data-active:border-sky-400 dark:data-active:shadow-[0_0_18px_rgba(56,189,248,0.3)] dark:data-active:ring-sky-400/30 dark:data-fake-caret:after:bg-sky-400"; const slotTone = { normal: "border-slate-400 dark:border-slate-400/55", invalid: "border-red-500 dark:border-red-400", }; const CODE_LENGTH = 6; export interface OtpVerificationCardProps { appName?: string; /** Square brand mark shown above the heading. */ logoSrc?: string; /** Where the code was sent. */ email?: string; /** Seconds before "Resend code" becomes available again. */ resendCooldown?: number; helpHref?: string; /** Return `false` (or throw) to show the wrong-code message. */ onVerify?: (code: string) => Promise<boolean | void> | boolean | void; onResend?: () => unknown; onChangeEmail?: () => void; } type Status = "entering" | "verifying" | "invalid" | "verified"; export function OtpVerificationCard({ appName = "Snow", logoSrc = "/brand/snow-icon-transparent.webp", email = "your inbox", resendCooldown = 30, helpHref = "https://help.wynter.ai", onVerify, onResend, onChangeEmail, }: OtpVerificationCardProps) { const [status, setStatus] = React.useState<Status>("entering"); const [code, setCode] = React.useState(""); const [secondsLeft, setSecondsLeft] = React.useState(resendCooldown); React.useEffect(() => { if (secondsLeft <= 0) return; const timer = window.setTimeout(() => setSecondsLeft((seconds) => seconds - 1), 1000); return () => window.clearTimeout(timer); }, [secondsLeft]); const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => { event.preventDefault(); if (code.length < CODE_LENGTH || status === "verifying") return; setStatus("verifying"); try { const accepted = await onVerify?.(code); setStatus(accepted === false ? "invalid" : "verified"); } catch { setStatus("invalid"); } }; const handleResend = () => { setCode(""); setStatus("entering"); setSecondsLeft(resendCooldown); return onResend?.(); }; const brand = ( <div className="flex items-center gap-2.5"> <img src={logoSrc} alt="" width={44} height={44} className="h-11 w-11 object-contain drop-shadow-[0_6px_14px_rgba(56,189,248,0.32)]" /> <span className="text-[15px] font-bold text-slate-900 dark:text-slate-50">{appName}</span> </div> ); if (status === "verified") { return ( <div role="status" className={`${card} mx-auto w-full max-w-md p-5 text-center sm:p-8`}> <div className="flex justify-center">{brand}</div> <div className="mx-auto mt-5 grid h-13 w-13 place-items-center rounded-2xl border border-emerald-600/40 bg-emerald-50 text-emerald-700 dark:border-emerald-400/40 dark:bg-emerald-400/15 dark:text-emerald-300"> <Check className="h-6 w-6" strokeWidth={2.5} aria-hidden="true" /> </div> <h1 className="mt-4 text-2xl font-bold tracking-tight text-slate-900 dark:text-slate-50">Email confirmed</h1> <p className="mt-1.5 text-sm text-slate-600 dark:text-slate-400"> <strong className="font-semibold break-words text-slate-900 dark:text-slate-50">{email}</strong> is verified. Taking you to {appName}. </p> </div> ); } const tone = status === "invalid" ? slotTone.invalid : slotTone.normal; const slot = (index: number) => <OTPInputSlot key={index} index={index} className={`${slotBase} ${tone}`} />; return ( <form onSubmit={handleSubmit} noValidate className={`${card} mx-auto w-full max-w-md p-5 sm:p-8`}> {brand} <h1 className="mt-5 text-2xl font-bold tracking-tight text-slate-900 dark:text-slate-50">Check your email</h1> <p className="mt-1.5 text-sm text-slate-600 dark:text-slate-400"> Enter the 6-digit code we sent to{" "} <strong className="font-semibold break-words text-slate-900 dark:text-slate-50">{email}</strong>. </p> <Field name="code" invalid={status === "invalid"} className="mt-6 grid gap-2"> <FieldLabel className={labelCls}>Verification code</FieldLabel> <OTPInput maxLength={CODE_LENGTH} value={code} onValueChange={(value) => { setCode(value); if (status === "invalid") setStatus("entering"); }} disabled={status === "verifying"} autoFocus className="flex w-full items-center gap-1.5 sm:gap-2" > <OTPInputGroup className="flex min-w-0 flex-1 gap-1.5 sm:gap-2">{[0, 1, 2].map(slot)}</OTPInputGroup> <OTPInputSeparator className="text-slate-500 dark:text-slate-400"> <Minus className="h-3.5 w-3.5" aria-hidden="true" /> </OTPInputSeparator> <OTPInputGroup className="flex min-w-0 flex-1 gap-1.5 sm:gap-2">{[3, 4, 5].map(slot)}</OTPInputGroup> </OTPInput> {status === "invalid" ? ( <FieldError match className={errorCls}> That code didn’t match. Check the email and try again. </FieldError> ) : ( <FieldDescription className={hintCls}>Paste the full code and it fills in for you.</FieldDescription> )} </Field> <Button type="submit" disabled={code.length < CODE_LENGTH || status === "verifying"} className={`${btnPrimary} ${btnMd} mt-5 w-full`} > {status === "verifying" ? "Checking…" : "Verify code"} </Button> <div className="mt-4 flex flex-wrap items-center gap-x-3 gap-y-2"> <Button onClick={handleResend} disabled={secondsLeft > 0} className={`${btnGhost} ${btnSm}`}> <RefreshCw className="h-3.5 w-3.5" aria-hidden="true" /> <span>Resend code</span> </Button> <span aria-live="off" className={`${hintCls} tabular-nums`}> {secondsLeft > 0 ? `Available in 0:${String(secondsLeft).padStart(2, "0")}` : "Didn’t get it? Send a new one."} </span> </div> <div className="mt-5 flex flex-wrap items-center justify-between gap-3 border-t border-[#d8e0ea] pt-4 dark:border-slate-400/20"> <Button onClick={() => onChangeEmail?.()} className={`${btnGhost} ${btnSm}`}> Use a different email </Button> <a href={helpHref} target="_blank" rel="noopener noreferrer" className="rounded text-[13px] font-semibold text-sky-700 hover:underline dark:text-sky-300" > Get help </a> </div> </form> ); } export default OtpVerificationCard;
More in Auth & Login
WynterHub SSO Sign-In Card
Centered high-trust sign-in card with your real brand mark, one prominent WynterHub single sign-on button, and a tucked-away email + password fallback with crisp readable inputs, show/hide password, inline validation, and a signed-in confirmation.
Account & Workspace Signup Card
Focused account setup form: two-column fields that stack on mobile, clear labels with short helper lines, role selector cards, password with show/hide and live requirements, an unticked marketing consent checkbox, inline validation, and a success state.