Skip to Content
BBRICKSv0.7.4
PR PortalLogin

OtpStep

The login's second step (inferred: the PR mock signs in with email and password only): a one-time code in length single-digit boxes, always left to right (a code reads the same in Arabic), with the resend countdown and Back. Typing a digit moves on, Backspace on an empty box moves back, Left / Right / Home / End move between boxes, and a pasted code fills them all. The first box carries autocomplete="one-time-code" so a phone can fill it from the SMS.

import { OtpStep } from '@ergasti/bricks';

Examples

Sign-in page

LoginLayout is the two-column page (brand, headline, the card); LoginCard takes email, password and "remember me", and reports a LoginValue. This frame is contained.

Code
import { Button, LoginCard, LoginLayout } from '@ergasti/bricks';

function Page() {
  return (
    <LoginLayout brand={<b>TRNDR.</b>} footer="© TRNDR 2026">
      <LoginCard
        defaultEmail="mona@trndr.co" onSubmit={() => {}}
        forgotPassword={<a className="kit-pr-link" href="#">Forgot password?</a>}
        languageToggle={<Button size="sm" variant="ghost">عربي</Button>}
        footnote="Brand accounts open the Brand portal. TRNDR team accounts open the PR portal."
      />
    </LoginLayout>
  );
}

Errors and the one-time code

error shows under the form; the otp step is the code screen (OtpStep): one box per digit, paste works, resend has a countdown.

Code
import { LoginCard, OtpStep } from '@ergasti/bricks';

function Otp() {
  return (
    <div style={{ display: 'grid', gap: 16, gridTemplateColumns: 'repeat(auto-fit, minmax(300px, 1fr))' }}>
      <div className="kit-card"><LoginCard onSubmit={() => {}} error="The email or password is wrong." defaultEmail="mona@trndr.co" /></div>
      <div className="kit-card"><OtpStep destination="+20 10•• ••• 471" onSubmit={() => {}} onResend={() => {}} onBack={() => {}} autoSubmit={false} /></div>
    </div>
  );
}

Inside a page that has its own main

LoginLayout draws its form side as the page's <main>. When the layout sits inside a page that already has one (a gallery, a preview, a docs frame), landmark="div" or "section" avoids a second main landmark.

Code
import { LoginCard, LoginLayout } from '@ergasti/bricks';

function Landmark() {
  return (
    <LoginLayout landmark="div" brand={<b>TRNDR.</b>} footer="© TRNDR 2026">
      <LoginCard defaultEmail="mona@trndr.co" onSubmit={() => {}} />
    </LoginLayout>
  );
}

Signing in, then the code step

Submit: pending turns the button into "Signing in…"; the app then moves step to otp and passes the code step's props in otp. Verifying sets the code step's own pending; a wrong code comes back as its error. brandMark, title, subtitle and defaultRemember set the card's head and the remember box.

Code
import { useState } from 'react';
import { LoginCard } from '@ergasti/bricks';

function TwoStep() {
  const [step, setStep] = useState<'credentials' | 'otp'>('credentials');
  const [pending, setPending] = useState(false);
  const [codePending, setCodePending] = useState(false);
  const [codeError, setCodeError] = useState<string | null>(null);
  return (
    <div className="kit-card" style={{ maxWidth: 420 }}>
      <LoginCard
        brandMark={<b>TRNDR.</b>} title="PR portal" subtitle="Sign in with your TRNDR team account." defaultRemember={false}
        pending={pending} step={step}
        onSubmit={() => { setPending(true); window.setTimeout(() => { setPending(false); setStep('otp'); }, 900); }}
        otp={{
          destination: '+20 10•• ••• 471', length: 4, resendAfter: 20, pending: codePending, error: codeError, autoSubmit: false,
          onSubmit: () => { setCodePending(true); setCodeError(null); window.setTimeout(() => { setCodePending(false); setCodeError('That code is wrong or expired.'); }, 900); },
          onResend: () => setCodeError(null), onBack: () => setStep('credentials'),
        }}
      />
    </div>
  );
}

Code step states

OtpStep alone: length digits (here 4), resendAfter seconds before Resend (here 45), pending while checking (boxes read-only, "Checking…").

Code
import { OtpStep } from '@ergasti/bricks';

function OtpPending() {
  return <div className="kit-card" style={{ maxWidth: 420 }}><OtpStep destination="mona@trndr.co" length={4} resendAfter={45} pending onSubmit={() => {}} onResend={() => {}} /></div>;
}

Your own headline

headline (wrap the lime words in a span) and text replace the ink side's default words.

Code
import { LoginCard, LoginLayout } from '@ergasti/bricks';

function Headline() {
  return (
    <LoginLayout landmark="div" brand={<b>TRNDR.</b>} headline={<>Every brand, <span>one desk</span>.</>} text="Approvals, payouts, gifts and challenges for the whole TRNDR team.">
      <LoginCard onSubmit={() => {}} />
    </LoginLayout>
  );
}

Props

Prop

Type

Labels

Every word this component draws, in both languages. Override one per component and language with BricksProvider labels under the key prOtpStep, or with the component's own prop where it has one. A {name} is a value the component fills in.

prOtpStep
KeyEnglishArabic
titleCheck your phoneشوف موبايلك
codeVerification codeكود التأكيد
digitDigit {n} of {of}الرقم {n} من {of}
sent[object Object][object Object]
sentPlainEnter the {n}-digit code we sent you.اكتب الكود اللي بعتناهولك ({n} أرقام).
verifyVerifyأكّد
verifyingChecking…بنتأكد…
resendResend codeابعت الكود تاني
resendInResend code in {t}تقدر تبعته تاني بعد {t}
backBackرجوع
incompleteEnter all {n} digits.اكتب الـ {n} أرقام كلهم.

Design guidance

How the BRICKS design system uses OtpStep. Written in docs/content/components/OtpStep.md; the props above are read from the code, which wins where the two disagree.

The sign-in's one-time-code step: single-digit boxes that read left to right, Verify, a resend countdown and Back; use it after the password when the account needs a code, usually through LoginCard's step="otp".

OtpStep is inferred (the PR mock signs in with email and password only). The code always reads left to right, even in Arabic. Typing a digit moves on, Backspace on an empty box moves back, arrow keys and Home / End move between boxes, and a pasted code fills the boxes from the focused one onwards; Arabic-Indic digits are accepted. The first box carries autocomplete="one-time-code" so a phone can fill it from the SMS. With autoSubmit (default) the code is sent as soon as the last box fills.

Anatomy

  1. Form: <form class="kit-pr-otp" noValidate>.
  2. Title: h2 "Check your phone" (28px display).
  3. Line: "We sent a 6-digit code to +20 10•• ••• 471." (or "Enter the 6-digit code we sent you.").
  4. Boxes: a role="group" named "Verification code", dir="ltr", a grid of 54px-tall boxes, 8px gaps; each inputMode="numeric", named "Digit 1 of 6".
  5. Error: role="alert" line (the app's error, or "Enter all 6 digits.").
  6. Verify: full-width ink button ("Checking…" while pending).
  7. Foot: "Back" link at the start, "Resend code in 0:30" (muted) or the "Resend code" link at the end.

Variants

PropValueEffect
length6 (default), any numberBoxes in the code
autoSubmittrue (default) / falseSend when the last box fills, or only on Verify
resendAfter30 (default) secondsCountdown before "Resend code"
destinationmasked stringNames where the code went

States

StateTrigger
Typingdigits move focus forward; focus selects the box's digit
Pasteda pasted code fills from the focused box
IncompleteVerify with empty boxes: "Enter all 6 digits.", boxes aria-invalid
Pendingpending: boxes read-only, button "Checking…" and disabled
Wrong codeerror: alert and invalid boxes
CountdownonResend given and time left: "Resend code in 0:12"
Resend readycountdown at 0: "Resend code" link; pressing it calls onResend, clears the boxes, restarts the countdown and focuses the first box

Usage

import { OtpStep } from '@ergasti/bricks';

<OtpStep
  destination="+20 10•• ••• 471"
  onSubmit={(code) => verify(code)}
  onResend={() => sendCode()}
  onBack={() => setStep('credentials')}
  pending={verifying}
  error={wrong ? 'That code is not right. Try again.' : undefined}
/>
// Through the login card (the usual way)
<LoginLayout brand={<TrndrMark />}>
  <LoginCard onSubmit={signIn} step="otp" otp={{ destination: '+20 10•• ••• 471', onSubmit: verify, onResend: resend, onBack: back }} />
</LoginLayout>

Code step states. OtpStep alone: length digits (here 4), resendAfter seconds before Resend (here 45), pending while checking (boxes read-only, "Checking…"). (docs example OtpPending)

import { Button, LoginCard, LoginLayout, OtpStep } from '@ergasti/bricks';

export function OtpPending() {
  return <div className="kit-card" style={{ maxWidth: 420 }}><OtpStep destination="mona@trndr.co" length={4} resendAfter={45} pending onSubmit={() => {}} onResend={() => {}} /></div>;
}

Where it appears

  • Library-only (no v3 mock screen): a second sign-in step after PR Portal › Login (the mock signs in with email and password only).
  • Dashboard screen: PrLogin.

Guidelines

Do

  • Mask the destination in the app before passing it.
  • Keep autoSubmit on for SMS codes; turn it off when the user must review.
  • Say whether a code is wrong or expired in error.

Don't

  • Don't reverse the boxes in Arabic: codes read left to right.
  • Don't shorten resendAfter below what the SMS provider allows.

RTL and Arabic

The boxes stay dir="ltr"; the rest mirrors (Back on the right). Arabic words: "شوف موبايلك", "بعتنالك كود من 6 أرقام على …", "أكّد" / "بنتأكد…", "ابعت الكود تاني", "تقدر تبعته تاني بعد 0:30", "رجوع". Arabic-Indic digits typed or pasted become ASCII.

Tokens

--line, --card, --ink, --ink-3, --rasp, --bad, --radius-md, --focus-ring-field, --font-family-display.

Accessibility

  • A labelled group of inputs, each "Digit n of 6"; errors tied by aria-describedby, boxes aria-invalid.
  • The first box is autocomplete="one-time-code" and auto-focused.
  • Full keyboard: arrows, Home / End, Backspace back; a paste fills from the focused box onwards.
  • Errors are role="alert"; Verify carries aria-busy while pending.

Found in the source

  • Roles in the markup: group, alert.
  • ARIA attributes set: aria-labelledby, aria-describedby, aria-label, aria-invalid, aria-busy.
  • Keys the code handles: Backspace, ArrowLeft, ArrowRight, Home, End.
  • It moves focus in code.
  • Its tests cover: “Backspace on an empty box goes back and clears; arrows, Home and End move; letters are ignored”.

Read from the component's source and tests. See Accessibility for the patterns the library follows.

See also: Button · useLanguage

Source

src/pr/login/OtpStep.tsx (line 65) on GitHub.

On this page