Skip to content
weftGitHub

OtpStep

The two-step sign-in screen: code, Verify, resend with a countdown, and another method.

SourcePackage @weft-js/warp

Preview

tsx
import { state } from '@weft-js/core'import { OtpStep } from '@weft-js/warp'export function Authenticator() {  const pending = state(false)  const error = state<unknown>(undefined)  const status = state<'idle' | 'success'>('idle')  const submit = async ({ code }: { code: string }) => {    pending.value = true    await wait(700)    pending.value = false    error.value = code === '123456' ? undefined : { code: 'WRONG_CODE', data: { attemptsLeft: 2 } }    if (code === '123456') status.value = 'success'  }  return <OtpStep heading="h3" title="Enter your code" lede="Open your authenticator app. The sample code is 123456." status={status.value} pending={pending.value} error={error.value} onSubmit={v => void submit(v)} onResend={() => {}} onOtherMethod={() => {}} onBack={() => (status.value = 'idle')} />}const wait = (ms: number) => new Promise(done => { setTimeout(done, ms) })

Installation

npm install @weft-js/warp

Usage

tsx
import { OtpStep } from '@weft-js/warp'

Accessibility

  • This has no shortcuts of its own: controls inside it use Tab, Enter and Space as usual, and warp's parts keep their roles and labels.

API Reference

PropTypeDefaultDescription
titleunknown—The heading.
ledeunknown—Where the code went.
lengthnumber—How many digits.
status"idle" | "checking" | "success"—Overrides the field's status.
hintunknown—Help under the field.
resendInnumber—Seconds before Resend opens.
otherMethodLabelunknown—Its words.
formFormLike—What <Form of={mutation}> gives you. The screen then renders no form of its own.
errorsRecord<string, string>—Messages by field name.
errorunknown—The failure: a string, or a typed error it can map to the right place.
errorOptionsFlowErrorOptions—Words by error code.
pendingbooleanfalseShows progress on the submit button.
headingHeading—The title's level. An auth step is usually the whole page, so h1.
EventTypeDefaultDescription
onResend(() => void)—Shows Resend.
onOtherMethod(() => void)—Shows "Use another method".
onBack(() => void)—Shows Back.
onSubmit((values: OtpValues, e: SubmitEvent) => void)—Called with the values once the screen's own checks pass.
onRetry(() => void)—The Retry on a network failure's toast.

Parts

Every element carries a stable name, so you can style it from your own CSS: [data-scope="otp-step"] [data-part="lede"]

lederow

RelatedOtp fieldSign in