Inputs
Resend Timer
A code with resend: while the countdown runs the button stays disabled, and the remaining time is both a bar and a spoken sentence.
- otp
- timer
- resend
- auth
Preview
Use it with AI
- 1. Copy the link.
- 2. Write to your agent in your own words and drop the link into the sentence.
- 3. The agent opens the link and installs the component from the registry.
put this in the header: https://vibeui.ru/c/otp-003?lang=en
Show the full instructions
What the link says, spelled out. Use it when your agent cannot open links — paste this text instead.
# Install and place "otp-003" (Resend Timer) from VibeUI
## 1. Install first — do not skip, do not recreate
Run this exact command before writing any code:
npx shadcn@latest add https://vibeui.ru/r/otp-003.json
Registry item: https://vibeui.ru/r/otp-003.json
Installs to: components/vibeui/otp-003.tsx (the exact path follows this project's components.json aliases).
npm dependencies: none.
Registry dependencies: none.
Install it from the registry. Do not recreate it from the description,
do not substitute a similar component from another library, and do not
rewrite it to match the project's existing style.
## 2. What it is
A code with resend: while the countdown runs the button stays disabled, and the remaining time is both a bar and a spoken sentence.
A confirmation code with a countdown and a resend button: timing from a timestamp, a progress bar and text for screen readers. Zero dependencies, one file.
## 3. How to use it
import { Otp003 } from "@/components/vibeui/otp-003"
<Otp003 seconds={45} onChange={(code) => verify(code)} />
Read the installed file for the full prop list.
## 4. Where to place it
This is a small inline component. Put it exactly where the user asked,
inside the existing markup. Do not create a new page, section or
wrapper for it. If a similar control already sits in that spot,
replace it instead of adding a second one.
Placement: ___
(The user fills this line in. If it is still blank, ask where to put it
instead of guessing.)
## 5. Keep exactly as installed
- the local --vibeui-otp-003-* palette — do not swap it for your theme tokens
- counting from a timestamp rather than adding seconds: background timers throttle and tick counting drifts
- the disabled button with the remaining time beside it: "unavailable" without a reason is annoying
- aria-live on the remaining-time line: how long to wait must be heard, not only seen
- clearing the interval in useEffect — otherwise a resend starts a second countdown
- autoComplete="one-time-code" on the first box: phones fill it automatically
## 6. You may change
- the countdown length in the seconds prop
- the number of boxes in length and the label copy
- the wording of the countdown line and the button
- the accent through the accent prop
## 7. Rules
- The component sends nothing: attach your request to the button.
- The server rate-limits resends anyway — the client timer only shows that rule.
- The bar updates twice a second: a shorter interval adds nothing.
- Do not lift the CSS variables into globals.css: the component has to stay a single file.
## 8. Verify
- it renders with no console errors;
- it looks like the preview on the VibeUI page you copied this from;
- if it does not, you changed something listed in section 5 — put it back.For developers
npx shadcn@latest add https://vibeui.ru/r/otp-003.jsonhttps://vibeui.ru/r/otp-003.jsonКомпонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-otp-003-*. Клиентский: "use client". Отсчёт ведётся от отметки времени (Date.now() + seconds*1000), а не сложением секунд по тикам: в свёрнутой вкладке таймеры тормозят и счёт по тикам врёт. Повторная отправка увеличивает счётчик round, от него перезапускается эффект. Ширина полосы — единственное инлайновое значение, потому что она вычисляется. Клетки — массив ref с автопереходом и вставкой.
Component source
The same file your agent installs. Here in case you would rather copy it by hand.
"use client"
import { useEffect, useId, useRef, useState } from "react"
import type {
ClipboardEvent,
ComponentPropsWithoutRef,
CSSProperties,
KeyboardEvent,
} from "react"
export type Otp003Props = Omit<
ComponentPropsWithoutRef<"div">,
"children" | "onChange"
> & {
label?: string
length?: number
seconds?: number
onChange?: (code: string) => void
accent?: string
}
// Идея компонента: рядом с кодом всегда живёт вопрос «а если не пришло».
// Поэтому здесь есть повторная отправка с обратным отсчётом: пока идёт
// таймер, кнопка выключена и вслух читается оставшееся время, а не «кнопка
// недоступна». Отсчёт идёт от отметки времени, а не сложением секунд:
// вкладку сворачивают, таймеры в фоне тормозят, и счёт по тикам врёт.
const STYLES = `
:where([data-vibeui-block="otp-003"]){
--vibeui-otp-003-surface:oklch(1 0 0);
--vibeui-otp-003-shell:oklch(0.91 0.006 265);
--vibeui-otp-003-fg:oklch(0.21 0.014 265);
--vibeui-otp-003-muted:oklch(0.56 0.014 265);
--vibeui-otp-003-field:oklch(0.98 0.002 265);
--vibeui-otp-003-border:oklch(0.87 0.008 265);
--vibeui-otp-003-accent:oklch(0.5 0.16 240);
--vibeui-otp-003-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="otp-003"]{
display:flex;flex-direction:column;gap:0.625rem;
width:100%;max-width:21rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-otp-003-surface);
border:1px solid var(--vibeui-otp-003-shell);border-radius:0.875rem;
font-family:var(--vibeui-otp-003-font);color:var(--vibeui-otp-003-fg);
}
[data-vibeui-block="otp-003"] *{box-sizing:border-box}
[data-vibeui-block="otp-003"] [data-part="label"]{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="otp-003"] [data-part="row"]{display:flex;gap:0.375rem}
[data-vibeui-block="otp-003"] input{
flex:1;min-width:0;height:2.875rem;padding:0;
border:1.5px solid var(--vibeui-otp-003-border);border-radius:0.625rem;
background:var(--vibeui-otp-003-field);color:inherit;
font:inherit;font-size:1.125rem;font-weight:700;text-align:center;
font-variant-numeric:tabular-nums;
}
[data-vibeui-block="otp-003"] input:focus-visible{
outline:2px solid var(--vibeui-otp-003-accent);outline-offset:1px;border-color:transparent;
}
[data-vibeui-block="otp-003"] input:not(:placeholder-shown){border-color:var(--vibeui-otp-003-accent)}
/* Полоса времени: остаток видно, не читая цифру. */
[data-vibeui-block="otp-003"] [data-part="track"]{
height:0.1875rem;border-radius:999px;overflow:hidden;
background:color-mix(in oklab,var(--vibeui-otp-003-muted) 25%,transparent);
}
[data-vibeui-block="otp-003"] [data-part="fill"]{
display:block;height:100%;border-radius:999px;
background:var(--vibeui-otp-003-accent);
transition:width 1s linear;
}
[data-vibeui-block="otp-003"] [data-part="foot"]{
display:flex;align-items:center;justify-content:space-between;gap:0.5rem;
}
[data-vibeui-block="otp-003"] [data-part="left"]{
font-size:0.75rem;line-height:1.4;color:var(--vibeui-otp-003-muted);
font-variant-numeric:tabular-nums;
}
[data-vibeui-block="otp-003"] [data-part="resend"]{
appearance:none;cursor:pointer;flex:none;
height:2rem;padding:0 0.75rem;border-radius:0.5rem;
border:1px solid var(--vibeui-otp-003-accent);
background:transparent;color:var(--vibeui-otp-003-accent);
font:inherit;font-size:0.75rem;font-weight:650;
transition:background-color .16s ease;
}
[data-vibeui-block="otp-003"] [data-part="resend"]:hover:not(:disabled){
background:color-mix(in oklab,var(--vibeui-otp-003-accent) 12%,transparent);
}
[data-vibeui-block="otp-003"] [data-part="resend"]:disabled{
cursor:not-allowed;opacity:.45;border-color:var(--vibeui-otp-003-muted);color:var(--vibeui-otp-003-muted);
}
[data-vibeui-block="otp-003"] [data-part="resend"]:focus-visible{
outline:2px solid var(--vibeui-otp-003-accent);outline-offset:2px;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="otp-003"] *{animation:none!important;transition:none!important}}
`
function clock(total: number) {
const minutes = Math.floor(total / 60)
const rest = total % 60
return `${minutes}:${String(rest).padStart(2, "0")}`
}
/**
* Код подтверждения с таймером повторной отправки и полосой остатка времени.
* Один файл, ноль зависимостей, собственная палитра.
*/
export function Otp003({
label = "Код из письма",
length = 6,
seconds = 45,
onChange,
accent,
className,
style,
...props
}: Otp003Props) {
const id = useId()
const size = Math.max(4, Math.min(8, length))
const [code, setCode] = useState<string[]>(Array(size).fill(""))
const [left, setLeft] = useState(seconds)
const [round, setRound] = useState(0)
const boxes = useRef<(HTMLInputElement | null)[]>([])
// Отсчёт от отметки времени: в свёрнутой вкладке таймеры тормозят,
// и сложение секунд по тикам показало бы больше, чем прошло.
useEffect(() => {
const until = Date.now() + seconds * 1000
const timer = window.setInterval(() => {
const rest = Math.max(0, Math.round((until - Date.now()) / 1000))
setLeft(rest)
if (rest === 0) window.clearInterval(timer)
}, 500)
return () => window.clearInterval(timer)
}, [round, seconds])
const palette = {
...(accent ? { "--vibeui-otp-003-accent": accent } : null),
...style,
} as CSSProperties
const push = (next: string[]) => {
setCode(next)
onChange?.(next.join(""))
}
const type = (index: number, value: string) => {
const digit = value.replace(/\D/g, "").slice(-1)
const next = [...code]
next[index] = digit
push(next)
if (digit && index < size - 1) boxes.current[index + 1]?.focus()
}
const paste = (event: ClipboardEvent<HTMLInputElement>) => {
const digits = event.clipboardData.getData("text").replace(/\D/g, "")
if (!digits) return
event.preventDefault()
push(Array.from({ length: size }, (_, index) => digits[index] ?? ""))
boxes.current[Math.min(digits.length, size - 1)]?.focus()
}
const onKeyDown = (event: KeyboardEvent<HTMLInputElement>, index: number) => {
if (event.key === "Backspace" && !code[index] && index > 0) {
event.preventDefault()
const next = [...code]
next[index - 1] = ""
push(next)
boxes.current[index - 1]?.focus()
}
}
return (
<>
<style href="vibeui-otp-003" precedence="medium">
{STYLES}
</style>
<div
{...props}
data-vibeui-block="otp-003"
className={className}
style={palette}
role="group"
aria-labelledby={`${id}-label`}
>
<span data-part="label" id={`${id}-label`}>
{label}
</span>
<div data-part="row">
{code.map((digit, index) => (
<input
key={index}
ref={(node) => {
boxes.current[index] = node
}}
type="text"
inputMode="numeric"
autoComplete={index === 0 ? "one-time-code" : "off"}
maxLength={1}
placeholder=" "
value={digit}
aria-label={`Цифра ${index + 1} из ${size}`}
onChange={(event) => type(index, event.target.value)}
onPaste={paste}
onKeyDown={(event) => onKeyDown(event, index)}
/>
))}
</div>
<div data-part="track" aria-hidden="true">
<span
data-part="fill"
style={{ width: `${(left / seconds) * 100}%` }}
/>
</div>
<div data-part="foot">
<span data-part="left" aria-live="polite">
{left > 0
? `Новый код можно запросить через ${clock(left)}`
: "Код не пришёл? Запросите новый."}
</span>
<button
type="button"
data-part="resend"
disabled={left > 0}
onClick={() => {
setLeft(seconds)
setRound((was) => was + 1)
push(Array(size).fill(""))
boxes.current[0]?.focus()
}}
>
Выслать снова
</button>
</div>
</div>
</>
)
}