Inputs

Handle Check

A username field that checks availability and offers free alternatives: a taken name is not just rejected, three working ones appear instead.

  • input
  • username
  • availability
  • suggest

Preview

1440pxHost theme

Use it with AI

  1. 1. Copy the link.
  2. 2. Write to your agent in your own words and drop the link into the sentence.
  3. 3. The agent opens the link and installs the component from the registry.

put this in the header: https://vibeui.ru/c/input-014?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 "input-014" (Handle Check) 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/input-014.json

Registry item: https://vibeui.ru/r/input-014.json
Installs to: components/vibeui/input-014.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 username field that checks availability and offers free alternatives: a taken name is not just rejected, three working ones appear instead.

A handle field: input normalised as you type, availability checked after a pause, and three free alternatives as buttons when it is taken. Zero dependencies, one file.

## 3. How to use it
import { Input014 } from "@/components/vibeui/input-014"

<Input014
  label="Username"
  taken={["anna", "design"]}
  onChange={(handle) => setHandle(handle)}
/>

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-input-014-* palette — do not swap it for your theme tokens
- storing the answer together with the name it describes, plus the pause before the request: otherwise the screen shows an answer about a different name
- the free alternatives as buttons — "taken" with no options forces the user to start over
- normalising the value itself: people must see exactly what will be saved
- the @ prefix outside the input: it must not be deleted or duplicated by accident
- the three sign states (checking, taken, free) alongside the text: colour alone carries no meaning

## 6. You may change
- the label copy and the taken array
- the normalisation rule — allowing hyphens, for instance
- the rule that builds the free alternatives
- the accent through the accent prop

## 7. Rules
- Availability is a server question: the taken array only demonstrates the states here.
- Do not echo other people's names in the response — that leaks your user list.
- Re-check the name on submit anyway: it can be taken between the check and the save.
- 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/input-014.json
https://vibeui.ru/r/input-014.json

Компонент самодостаточен: один файл, без зависимостей, собственная палитра в локальных переменных --vibeui-input-014-*. Клиентский: "use client". Ввод нормализуется на лету: нижний регистр, пробелы в подчёркивание, лишние символы отбрасываются. Ответ о занятости хранится вместе с именем, к которому относится, а видимое состояние выводится из него: пока ответ не про то имя, что в поле, показывается «проверяем» — расхождение невозможно по построению. Запрос идёт через паузу в 600 мс с очисткой таймера. Приставка @ вынесена из поля отдельным span.

Component source

The same file your agent installs. Here in case you would rather copy it by hand.

"use client"

import { useEffect, useId, useState } from "react"
import type { ComponentPropsWithoutRef, CSSProperties } from "react"

export type Input014Props = Omit<
  ComponentPropsWithoutRef<"div">,
  "children" | "onChange"
> & {
  label?: string
  taken?: string[]
  onChange?: (handle: string) => void
  accent?: string
}

// Идея компонента: если имя занято, мало сказать «занято» — надо дать
// свободное. Поле нормализует ввод на лету (нижний регистр, пробелы в дефис,
// лишние символы отбрасываются), через паузу спрашивает занятость и при отказе
// предлагает три свободных варианта кнопками. Приставка @ живёт вне поля,
// чтобы её нельзя было стереть или продублировать.
const STYLES = `
:where([data-vibeui-block="input-014"]){
--vibeui-input-014-surface:oklch(1 0 0);
--vibeui-input-014-shell:oklch(0.91 0.006 265);
--vibeui-input-014-fg:oklch(0.23 0.014 265);
--vibeui-input-014-muted:oklch(0.56 0.014 265);
--vibeui-input-014-field:oklch(0.985 0.002 265);
--vibeui-input-014-border:oklch(0.88 0.008 265);
--vibeui-input-014-accent:oklch(0.55 0.17 250);
--vibeui-input-014-bad:oklch(0.55 0.2 25);
--vibeui-input-014-ok:oklch(0.48 0.13 155);
--vibeui-input-014-font:ui-sans-serif,system-ui,-apple-system,"Segoe UI",Roboto,"Helvetica Neue",Arial,sans-serif;
}
[data-vibeui-block="input-014"]{
display:flex;flex-direction:column;gap:0.4375rem;
width:100%;max-width:22rem;box-sizing:border-box;padding:0.875rem;
background:var(--vibeui-input-014-surface);
border:1px solid var(--vibeui-input-014-shell);border-radius:0.875rem;
font-family:var(--vibeui-input-014-font);color:var(--vibeui-input-014-fg);
}
[data-vibeui-block="input-014"] *{box-sizing:border-box}
[data-vibeui-block="input-014"] label{font-size:0.8125rem;font-weight:600}
[data-vibeui-block="input-014"] [data-part="body"]{display:flex;flex-direction:column;gap:0.4375rem}
[data-vibeui-block="input-014"] [data-part="frame"]{
display:flex;align-items:center;gap:0.25rem;
height:2.5rem;padding:0 0.75rem;
background:var(--vibeui-input-014-field);
border:1px solid var(--vibeui-input-014-border);border-radius:0.75rem;
transition:border-color .16s ease,box-shadow .16s ease;
}
[data-vibeui-block="input-014"] [data-part="frame"]:focus-within{
border-color:var(--vibeui-input-014-accent);
box-shadow:0 0 0 3px color-mix(in oklab,var(--vibeui-input-014-accent) 18%,transparent);
}
[data-vibeui-block="input-014"] [data-state="taken"] [data-part="frame"]{border-color:var(--vibeui-input-014-bad)}
[data-vibeui-block="input-014"] [data-state="free"] [data-part="frame"]{border-color:var(--vibeui-input-014-ok)}
[data-vibeui-block="input-014"] [data-part="at"]{
flex:none;color:var(--vibeui-input-014-muted);font-size:0.875rem;user-select:none;
}
[data-vibeui-block="input-014"] input{
flex:1;min-width:0;height:100%;border:0;background:none;color:inherit;
font:inherit;font-size:0.875rem;
}
[data-vibeui-block="input-014"] input:focus{outline:none}
/* Индикатор — три состояния одного места: точки, крест, галочка. */
[data-vibeui-block="input-014"] [data-part="sign"]{
flex:none;width:1.125rem;height:1.125rem;display:grid;place-items:center;
color:var(--vibeui-input-014-muted);
}
[data-vibeui-block="input-014"] [data-part="sign"] svg{width:1rem;height:1rem;display:block}
[data-vibeui-block="input-014"] [data-state="taken"] [data-part="sign"]{color:var(--vibeui-input-014-bad)}
[data-vibeui-block="input-014"] [data-state="free"] [data-part="sign"]{color:var(--vibeui-input-014-ok)}
[data-vibeui-block="input-014"] [data-part="spin"]{
width:0.875rem;height:0.875rem;border-radius:999px;
border:2px solid color-mix(in oklab,var(--vibeui-input-014-muted) 35%,transparent);
border-top-color:var(--vibeui-input-014-accent);
animation:vibeui-input-014-turn .7s linear infinite;
}
@keyframes vibeui-input-014-turn{to{transform:rotate(360deg)}}
[data-vibeui-block="input-014"] [data-part="note"]{
margin:0;font-size:0.75rem;line-height:1.4;color:var(--vibeui-input-014-muted);
}
[data-vibeui-block="input-014"] [data-state="taken"] [data-part="note"]{color:var(--vibeui-input-014-bad)}
[data-vibeui-block="input-014"] [data-state="free"] [data-part="note"]{color:var(--vibeui-input-014-ok)}
[data-vibeui-block="input-014"] [data-part="ideas"]{
display:flex;flex-wrap:wrap;gap:0.375rem;
}
[data-vibeui-block="input-014"] [data-part="idea"]{
appearance:none;cursor:pointer;
padding:0.3125rem 0.625rem;border-radius:999px;
border:1px solid var(--vibeui-input-014-border);
background:var(--vibeui-input-014-surface);color:inherit;
font:inherit;font-size:0.75rem;
transition:border-color .16s ease,background-color .16s ease;
}
[data-vibeui-block="input-014"] [data-part="idea"]:hover{
border-color:var(--vibeui-input-014-accent);
background:color-mix(in oklab,var(--vibeui-input-014-accent) 10%,transparent);
}
[data-vibeui-block="input-014"] [data-part="idea"]:focus-visible{
outline:2px solid var(--vibeui-input-014-accent);outline-offset:2px;
}
@media (prefers-reduced-motion:reduce){[data-vibeui-block="input-014"] *{animation:none!important;transition:none!important}}
`

const TAKEN = ["anna", "orlova", "design", "anna_orlova"]

// Нормализация на вводе, а не на отправке: иначе человек видит одно, а
// сохраняется другое.
function normalize(value: string) {
  return value
    .toLowerCase()
    .replace(/\s+/g, "_")
    .replace(/[^a-z0-9_.]/g, "")
    .slice(0, 20)
}

function ideasFor(handle: string, taken: string[]) {
  return [`${handle}_ru`, `${handle}2026`, `real_${handle}`].filter(
    (idea) => !taken.includes(idea),
  )
}

/**
 * Имя пользователя с проверкой занятости и готовыми свободными вариантами.
 * Один файл, ноль зависимостей, собственная палитра.
 */
export function Input014({
  label = "Имя пользователя",
  taken = TAKEN,
  onChange,
  accent,
  className,
  style,
  ...props
}: Input014Props) {
  const id = useId()
  const [handle, setHandle] = useState("anna")
  const [answer, setAnswer] = useState<{
    handle: string
    free: boolean
  } | null>(null)

  // Состояние выводится из ответа, а не хранится отдельно: пока ответ пришёл
  // не про то имя, что в поле, показывается «проверяем» — расхождение
  // невозможно по построению.
  const state =
    handle.length < 3
      ? "idle"
      : answer?.handle !== handle
        ? "checking"
        : answer.free
          ? "free"
          : "taken"

  // Пауза перед запросом: иначе занятость спрашивают на каждый символ,
  // и ответ приходит про имя, которого в поле уже нет.
  useEffect(() => {
    if (handle.length < 3 || answer?.handle === handle) return

    const timer = window.setTimeout(() => {
      setAnswer({ handle, free: !taken.includes(handle) })
    }, 600)

    return () => window.clearTimeout(timer)
  }, [handle, answer, taken])

  const palette = {
    ...(accent ? { "--vibeui-input-014-accent": accent } : null),
    ...style,
  } as CSSProperties

  const apply = (next: string) => {
    setHandle(next)
    onChange?.(next)
  }

  const ideas = state === "taken" ? ideasFor(handle, taken) : []

  return (
    <>
      <style href="vibeui-input-014" precedence="medium">
        {STYLES}
      </style>
      <div
        {...props}
        data-vibeui-block="input-014"
        className={className}
        style={palette}
      >
        <label htmlFor={id}>{label}</label>
        <div data-part="body" data-state={state}>
          <div data-part="frame">
            <span data-part="at" aria-hidden="true">
              @
            </span>
            <input
              id={id}
              type="text"
              autoComplete="username"
              spellCheck={false}
              autoCapitalize="none"
              placeholder="anna_orlova"
              value={handle}
              aria-invalid={state === "taken"}
              aria-describedby={`${id}-note`}
              onChange={(event) => apply(normalize(event.target.value))}
            />
            <span data-part="sign" aria-hidden="true">
              {state === "checking" ? (
                <span data-part="spin" />
              ) : state === "free" ? (
                <svg
                  viewBox="0 0 16 16"
                  fill="none"
                  stroke="currentColor"
                  strokeWidth="2"
                >
                  <path
                    d="M3.5 8.5 6.5 11.5 12.5 5"
                    strokeLinecap="round"
                    strokeLinejoin="round"
                  />
                </svg>
              ) : state === "taken" ? (
                <svg
                  viewBox="0 0 16 16"
                  fill="none"
                  stroke="currentColor"
                  strokeWidth="2"
                >
                  <path d="m4.5 4.5 7 7M11.5 4.5l-7 7" strokeLinecap="round" />
                </svg>
              ) : null}
            </span>
          </div>
          <p data-part="note" id={`${id}-note`} aria-live="polite">
            {state === "checking"
              ? "Проверяем, свободно ли имя…"
              : state === "taken"
                ? `Имя @${handle} занято. Возьмите одно из свободных:`
                : state === "free"
                  ? `Имя @${handle} свободно.`
                  : "Латиница, цифры, точка и подчёркивание. От трёх символов."}
          </p>
          {ideas.length > 0 ? (
            <div data-part="ideas">
              {ideas.map((idea) => (
                <button
                  key={idea}
                  type="button"
                  data-part="idea"
                  onClick={() => apply(idea)}
                >
                  @{idea}
                </button>
              ))}
            </div>
          ) : null}
        </div>
      </div>
    </>
  )
}