Input
Text field with icons, clear, reveal and error states.
Variants
6 more takes on the input, each a single file you install on its own by its id.
aui-029Floating label
The label settles into the border.
$ pnpm dlx asta-ui@latest add input-aui-029aui-030Search with recents
Search with recents and keyboard picks.
$ pnpm dlx asta-ui@latest add input-aui-030aui-031Prefix and suffix
Prefix and suffix that read as one value.
$ pnpm dlx asta-ui@latest add input-aui-031aui-032Live validation
Checks an email on pause and offers typo fixes.
$ pnpm dlx asta-ui@latest add input-aui-032aui-033Title to slug
Title becomes a slug, checked for availability.
$ pnpm dlx asta-ui@latest add input-aui-033aui-034Amount
A money field with currency and quick amounts.
$ pnpm dlx asta-ui@latest add input-aui-034Installation
Run the CLI
Run
pnpm dlx asta-ui@latest initonce, then this. The file lands incomponents/astabyte/and the colour tokens go into your CSS.$ pnpm dlx asta-ui@latest add inputOr install the package
Don’t want the file? Import from
asta-ui/inputand update withpnpm update asta-ui. Add the stylesheet once. More.$ pnpm add asta-uiimport { Input } from "asta-ui/input";Or copy it by hand
Copy this file. Keep the paths, or fix the
@/imports. Then add the tokens fromglobals.css."use client"; import { useRef, useState, type InputHTMLAttributes, type ReactNode } from "react"; const cx = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" "); export type InputState = "default" | "error" | "success"; export type InputSize = "sm" | "md" | "lg"; const SIZE: Record<InputSize, string> = { sm: "h-8 rounded-md px-2.5 text-[16px] sm:text-[13px] gap-2", md: "h-10 rounded-lg px-3 text-[16px] sm:text-[14px] gap-2.5", lg: "h-12 rounded-[9px] px-4 text-[16px] sm:text-[15px] gap-3", }; const RING: Record<InputState, string> = { default: "shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_14%,transparent)] hover:shadow-[inset_0_0_0_1px_color-mix(in_srgb,var(--color-ink)_24%,transparent)] " + "focus-within:!shadow-[inset_0_0_0_1px_var(--color-brand),0_0_0_4px_color-mix(in_srgb,var(--color-brand)_16%,transparent)]", error: "shadow-[inset_0_0_0_1.5px_var(--color-ink)] focus-within:shadow-[inset_0_0_0_1.5px_var(--color-ink),0_0_0_4px_color-mix(in_srgb,var(--color-ink)_12%,transparent)]", success: "shadow-[inset_0_0_0_1px_var(--color-brand)] focus-within:shadow-[inset_0_0_0_1px_var(--color-brand),0_0_0_4px_color-mix(in_srgb,var(--color-brand)_16%,transparent)]", }; export interface InputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "size"> { size?: InputSize; state?: InputState; iconLeft?: ReactNode; iconRight?: ReactNode; /** Shows a clear button while there is text. */ clearable?: boolean; /** Extra classes for the outer frame. */ className?: string; inputClassName?: string; } const StateIcon = ({ state }: { state: InputState }) => state === "error" ? ( <svg viewBox="0 0 24 24" className="h-4 w-4 shrink-0 text-ink" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <circle cx="12" cy="12" r="8.5" /> <path d="M12 7.5v5" /> <path d="M12 16h.01" /> </svg> ) : state === "success" ? ( <svg viewBox="0 0 24 24" className="h-4 w-4 shrink-0 text-brand" fill="none" stroke="currentColor" strokeWidth="2.7" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m5 12.5 4.5 4.5L19 7.5" /> </svg> ) : null; /** A text input in a frame that holds icons, a clear button and a state. Uncontrolled or controlled. */ export function Input({ size = "md", state = "default", iconLeft, iconRight, clearable, className, inputClassName, ...rest }: InputProps) { const ref = useRef<HTMLInputElement>(null); const controlled = rest.value !== undefined; const [inner, setInner] = useState(String(rest.defaultValue ?? "")); const value = controlled ? String(rest.value) : inner; const clear = () => { const el = ref.current!; // Go through the native setter so React's onChange fires for controlled inputs too. Object.getOwnPropertyDescriptor(HTMLInputElement.prototype, "value")!.set!.call(el, ""); el.dispatchEvent(new Event("input", { bubbles: true })); el.focus(); }; return ( <div className={cx( "group/in relative flex w-full items-center bg-paper text-ink transition-shadow duration-200", SIZE[size], RING[state], rest.disabled && "pointer-events-none opacity-50", className, )} onPointerDown={(e) => { if (e.target === e.currentTarget) { e.preventDefault(); ref.current?.focus(); } }} > {iconLeft && <span className="flex shrink-0 text-mute transition-colors group-focus-within/in:text-ink [&_svg]:h-4 [&_svg]:w-4">{iconLeft}</span>} <input ref={ref} aria-invalid={state === "error" || undefined} {...rest} onChange={(e) => { if (!controlled) setInner(e.target.value); rest.onChange?.(e); }} className={cx("h-full min-w-0 flex-1 bg-transparent outline-none placeholder:text-mute [&::-webkit-search-cancel-button]:hidden", inputClassName)} /> {clearable && ( <button type="button" tabIndex={value ? 0 : -1} aria-label="Clear" onClick={clear} className={cx( "grid h-5 w-5 shrink-0 place-items-center rounded-full bg-[color-mix(in_srgb,var(--color-ink)_9%,transparent)] text-ink-2 outline-none transition-[transform,opacity] duration-300 ease-[cubic-bezier(.16,1,.3,1)] hover:bg-[color-mix(in_srgb,var(--color-ink)_16%,transparent)] focus-visible:ring-2 focus-visible:ring-brand/50", value ? "scale-100 opacity-100" : "pointer-events-none scale-50 opacity-0", )} > <svg viewBox="0 0 24 24" className="h-2.5 w-2.5" fill="none" stroke="currentColor" strokeWidth="3.6" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="m6 6 12 12" /> <path d="M18 6 6 18" /> </svg> </button> )} <StateIcon state={state} /> {iconRight && <span className="flex shrink-0 text-mute [&_svg]:h-4 [&_svg]:w-4">{iconRight}</span>} </div> ); } /** Password field with a reveal toggle; the eye's lid blinks shut and open. */ export function PasswordInput(props: Omit<InputProps, "type" | "iconRight">) { const [show, setShow] = useState(false); return ( <Input name="password" autoComplete="current-password" autoCapitalize="none" spellCheck={false} {...props} type={show ? "text" : "password"} inputClassName={cx(!show && "tracking-[0.12em]", props.inputClassName)} iconRight={ <button type="button" onClick={() => setShow((v) => !v)} aria-label={show ? "Hide password" : "Show password"} aria-pressed={show} className="-mr-1 grid h-7 w-7 place-items-center rounded-lg text-mute outline-none transition-colors hover:bg-paper-2 hover:text-ink focus-visible:ring-2 focus-visible:ring-brand/50" > <svg viewBox="0 0 24 24" className="!h-4 !w-4" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden> <path d="M2.5 12c3-5.5 16-5.5 19 0-3 5.5-16 5.5-19 0Z" /> <circle cx="12" cy="12" r="2.75" className={cx("origin-center transition-transform duration-300", show ? "scale-100" : "scale-0" /* perf-ok: eye pupil */)} /> <path d="m4.5 4.5 15 15" pathLength={1} strokeDasharray="1" className="transition-[stroke-dashoffset] duration-300 ease-[cubic-bezier(.16,1,.3,1)]" style={{ strokeDashoffset: show ? 1 : 0 }} /> </svg> </button> } /> ); } export default Input;Or ask your AI agent
Paste this into Claude Code, Cursor, Codex, v0 or Lovable. Fill in the last line. More in Prompts.
Add the Astabyte UI Input component to my project. Text field with icons, clear, reveal and error states. It includes: Input, PasswordInput, icons, clearable, states. Install it: ```sh pnpm dlx asta-ui@latest add input --radix ``` Or with the shadcn CLI: ```sh pnpm dlx shadcn@latest add https://ui.astabyte.com/r/input.json ``` If the project isn't set up yet, run `pnpm dlx asta-ui@latest init --radix` first: it runs `shadcn init` when needed and adds the @astabyte registry (Next.js, Vite, React Router, Astro, TanStack Start; Tailwind CSS v4). Import it like this: ```tsx import { Input, PasswordInput } from "@/components/astabyte/input"; ``` Usage example and props: https://ui.astabyte.com/input Full catalogue for context: https://ui.astabyte.com/llms.txt Rules: - Keep the colour tokens (paper, paper-2, ink, ink-2, mute, brand). Don't restyle with hard-coded colours; rebrand by changing the token values in the CSS. - Keep the motion as it is: transform and opacity only, and the prefers-reduced-motion fallback. - Keep keyboard, focus and ARIA behaviour. - Use fake data and fake brand names in examples. Use it to: [describe where it goes and what it should do]Or use plain HTML + CSS
Not on React? Use it from Django, Rails, Laravel, Go
html/template, htmx or a static page. Loadasta.cssandasta.jsonce (thehead.htmltab), then paste the markup. Theui.astabyte.com/cdnlink is temporary: pin a version from jsDelivr for production. More in HTML + CSS.<div style="display:grid;gap:12px;max-width:360px"> <label class="asta-input"> <span class="asta-input-icon"><svg viewBox="0 0 16 16" fill="none" stroke="currentColor" stroke-width="1.6" stroke-linecap="round"><circle cx="7" cy="7" r="4.5"/><path d="m10.5 10.5 3 3"/></svg></span> <input class="asta-input-control" name="q" type="search" autocomplete="off" placeholder="Search Astabyte…" aria-label="Search"> </label> <label class="asta-input asta-input-sm"> <input class="asta-input-control" name="price" value="120" inputmode="decimal" autocomplete="off" aria-label="Price in USD"> <span class="asta-input-trailing">USD</span> </label> </div>
Usage
The demo above, as code.
"use client";
import { useState } from "react";
import { Input, PasswordInput } from "@/components/astabyte/input";
const Search = () => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.4" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<circle cx="10.5" cy="10.5" r="6" />
<path d="m15 15 5 5" />
</svg>
);
const Mail = () => (
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2.25" strokeLinecap="round" strokeLinejoin="round" aria-hidden>
<rect x="3.5" y="5.5" width="17" height="13" rx="2" />
<path d="m4 7 8 6 8-6" />
</svg>
);
export default function InputDemo() {
const [email, setEmail] = useState("hello@astabyte");
// The error shows after blur (the prefilled value counts as blurred). A fix clears it while typing.
const [checked, setChecked] = useState(true);
const valid = /^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(email);
const wrong = checked && !!email && !valid;
return (
<div className="flex min-h-[420px] w-full items-center justify-center p-6 sm:p-10">
<div className="flex w-full max-w-sm flex-col gap-4">
<Input type="search" name="q" autoComplete="off" iconLeft={<Search />} placeholder="Search components…" clearable defaultValue="Navbar" aria-label="Search" />
<div className="flex flex-col gap-1.5">
<Input
iconLeft={<Mail />}
name="email"
type="email"
autoComplete="email"
inputMode="email"
autoCapitalize="none"
spellCheck={false}
value={email}
onChange={(e) => {
setEmail(e.target.value);
if (/^[^\s@]+@[^\s@]+\.[^\s@]{2,}$/.test(e.target.value)) setChecked(false);
}}
onBlur={() => setChecked(true)}
state={wrong ? "error" : valid ? "success" : "default"}
placeholder="[email protected]"
aria-label="Email"
aria-describedby="email-hint"
/>
<p id="email-hint" className={`text-[12.5px] ${wrong ? "text-ink" : "text-mute"}`}>
{wrong ? "Enter an email like [email protected]." : valid ? "Looks good." : "We’ll never share it."}
</p>
</div>
<PasswordInput placeholder="Enter your password…" defaultValue="correct-horse" aria-label="Password" />
<div className="flex gap-2">
<Input size="sm" placeholder="Small…" aria-label="Small" />
<Input size="sm" placeholder="Disabled…" disabled aria-label="Disabled" />
</div>
<Input size="lg" placeholder="Large…" aria-label="Large" />
</div>
</div>
);
}