The example below loads live from Storybook; open it there to use the controls.
Default
Section titled “Default”Each character has its own box, but the code is one tab stop. groupSize splits the boxes into groups.
Enter the 6-digit code sent to you.
import { OtpInput, Provider } from '@bigbang/ui';
export default function Default() { return ( <Provider locale="en-GB"> <OtpInput label="Verification code" description="Enter the 6-digit code sent to you." groupSize={3} /> </Provider> );}States
Section titled “States”Partly filled, invalid, masked (PIN) and disabled.
The code is wrong. Try again.
import { OtpInput, Provider } from '@bigbang/ui';
export default function States() { return ( <Provider locale="en-GB"> <div className="flex flex-col gap-xl"> <OtpInput label="Verification code" defaultValue="123" groupSize={3} /> <OtpInput label="Verification code" defaultValue="123456" error="The code is wrong. Try again." /> <OtpInput label="Verification code" defaultValue="1234" length={4} mask /> <OtpInput label="Verification code" disabled /> </div> </Provider> );}Verification
Section titled “Verification”onValueComplete runs on the last character; on a wrong code, clear the value and show an error.
The right code: 123456
import { OtpInput, Provider } from '@bigbang/ui';import { useState } from 'react';
export default function Verify() { const [value, setValue] = useState(''); const [error, setError] = useState(false); return ( <Provider locale="en-GB"> <OtpInput label="Verification code" description="The right code: 123456" groupSize={3} value={value} onValueChange={(next) => { setValue(next); setError(false); }} onValueComplete={(code) => { if (code !== '123456') { setError(true); setValue(''); } }} {...(error ? { error: 'The code is wrong. Try again.' } : {})} /> </Provider> );}Light and dark mode
Section titled “Light and dark mode”A filled box turns to the color-surface-sunken background and a strong border.
The code is wrong. Try again.
The code is wrong. Try again.
import { OtpInput, Provider } from '@bigbang/ui';
export default function States() { return ( <Provider locale="en-GB"> <div className="flex flex-col gap-xl"> <OtpInput label="Verification code" defaultValue="123" groupSize={3} /> <OtpInput label="Verification code" defaultValue="123456" error="The code is wrong. Try again." /> <OtpInput label="Verification code" defaultValue="1234" length={4} mask /> <OtpInput label="Verification code" disabled /> </div> </Provider> );}