Input
A text field in a drawn box, or on the line you write on. Focus draws one more pass in full ink; invalid redraws it in red pen.
That code has already been used.
import { Input } from "@/components/ui/input";
import { Label } from "@/components/ui/label";
export default function InputDemo() {
return (
<div className="grid w-full max-w-md gap-6">
<div className="grid gap-2">
<Label htmlFor="input-email">Email</Label>
<Input id="input-email" type="email" placeholder="you@example.com" seed="input-email" />
</div>
<div className="grid gap-2">
<Label htmlFor="input-name">Name, written on the line</Label>
<Input id="input-name" variant="line" placeholder="Oussama" seed="input-name" />
</div>
<div className="grid gap-2">
<Label htmlFor="input-code">Invite code</Label>
<Input id="input-code" aria-invalid defaultValue="NOPE-123" seed="input-code" />
<p className="text-sm text-destructive">That code has already been used.</p>
</div>
<div className="grid grid-cols-2 gap-4">
<Input placeholder="Rounded" radius={10} seed="input-rounded" aria-label="Rounded" />
<Input placeholder="Disabled" disabled seed="input-disabled" aria-label="Disabled" />
</div>
</div>
);
}Installation
pnpm dlx shadcn@latest add @ballpoint/ input"use client";
import { Input as InputPrimitive } from "@base-ui/react/input";
import { cn } from "@/lib/utils";
import { usePen, type Pen } from "@/hooks/use-ink-box";
import { InkOutline } from "@/lib/ink-outline";
type InputProps = Omit<InputPrimitive.Props, "className"> &
Pen & {
className?: string;
/** "box" is drawn around the field; "line" is the line you write on. */
variant?: "box" | "line";
seed?: string | number;
};
/**
* A text field in a drawn box. The drawing sits in a wrapper around the
* <input>, so `className` styles that box (width, margins, type size);
* every other prop goes to the input. Focus draws one more pass in full ink;
* aria-invalid redraws it in red pen.
*/
function Input({
className,
variant = "box",
seed,
roughness,
passes,
radius,
corners,
draw,
weight,
speed,
...props
}: Omit<InputProps, "fill" | "shadow">) {
const pen = usePen({ roughness, passes, radius, corners, draw, weight, speed });
return (
<span
data-slot="input"
data-variant={variant}
className={cn("group/input ink-within relative inline-flex h-10 w-full min-w-0 items-center", className)}
>
<InkOutline
pen={pen}
seed={seed}
estimate={[240, 40]}
shape={variant === "line" ? "line" : "box"}
focusPass
className={cn(
"text-ink-3 transition-colors duration-(--dur-hover)",
"group-hover/input:text-ink group-focus-within/input:text-ink",
"group-has-[[aria-invalid=true]]/input:text-destructive group-has-[[data-invalid]]/input:text-destructive",
"group-has-disabled/input:opacity-50",
)}
/>
<InputPrimitive
data-slot="input-control"
className={cn(
"relative h-full w-full min-w-0 bg-transparent text-base text-foreground outline-none placeholder:text-ink-3",
"disabled:cursor-not-allowed disabled:opacity-50",
"file:mr-3 file:border-0 file:bg-transparent file:text-base file:text-ink",
variant === "line" ? "px-1" : "px-3",
)}
{...props}
/>
</span>
);
}
export { Input };Usage
import { Input } from "@/components/ui/input"
<Input type="email" placeholder="you@example.com" />Examples
Types
Password, number, search and file inputs, each with a field label and hint.
Use a phrase you could write from memory.
import { Field, FieldDescription, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
export default function InputTypes() {
return (
<div className="grid w-full max-w-md gap-6">
<Field>
<FieldLabel htmlFor="it-password">Password</FieldLabel>
<Input id="it-password" type="password" placeholder="At least eight characters" autoComplete="new-password" seed="it-password" />
<FieldDescription>Use a phrase you could write from memory.</FieldDescription>
</Field>
<Field>
<FieldLabel htmlFor="it-number">Copies</FieldLabel>
<Input id="it-number" type="number" min={1} max={20} defaultValue={3} seed="it-number" />
</Field>
<Field>
<FieldLabel htmlFor="it-search">Search</FieldLabel>
<Input id="it-search" type="search" placeholder="Find a page" seed="it-search" />
</Field>
<Field>
<FieldLabel htmlFor="it-file">Photo</FieldLabel>
<Input id="it-file" type="file" seed="it-file" />
</Field>
</div>
);
}States
Read-only, disabled, and invalid in the box or on the line.
You can select it and copy it, but not change it.
import { Field, FieldDescription, FieldError, FieldLabel } from "@/components/ui/field";
import { Input } from "@/components/ui/input";
export default function InputStates() {
return (
<div className="grid w-full max-w-md gap-6">
<Field>
<FieldLabel htmlFor="is-readonly">Read-only</FieldLabel>
<Input id="is-readonly" readOnly defaultValue="ballpoint.st9wd.com" seed="is-readonly" />
<FieldDescription>You can select it and copy it, but not change it.</FieldDescription>
</Field>
<Field data-disabled>
<FieldLabel htmlFor="is-disabled">Disabled</FieldLabel>
<Input id="is-disabled" disabled defaultValue="Locked while it saves" seed="is-disabled" />
</Field>
<Field data-invalid>
<FieldLabel htmlFor="is-invalid">Handle</FieldLabel>
<Input id="is-invalid" aria-invalid defaultValue="ada lovelace" seed="is-invalid" />
<FieldError>Handles can't have spaces.</FieldError>
</Field>
<Field>
<FieldLabel htmlFor="is-line">On the line</FieldLabel>
<Input id="is-line" variant="line" aria-invalid defaultValue="Wrong, in red pen" seed="is-line" />
</Field>
</div>
);
}With a button
An email field and a submit button on one row.
"use client";
import { Button } from "@/components/ui/button";
import { Input } from "@/components/ui/input";
export default function InputWithButton() {
return (
<form onSubmit={(event) => event.preventDefault()} className="flex w-full max-w-md items-center gap-3">
<Input type="email" placeholder="you@example.com" aria-label="Email" className="flex-1" seed="iwb-email" />
<Button type="submit" seed="iwb-submit">
Subscribe
</Button>
</form>
);
}Search
A leading icon, a shortcut hint that goes when you type, and a filtered list.
- Cream notebook
- Blue ballpoint
- Legal pad
- Fineliner set
- Graph pad
- Pencil case
"use client";
import { useState } from "react";
import { Input } from "@/components/ui/input";
import { InkIcon } from "@/components/ui/ink-icons";
import { Kbd } from "@/components/ui/kbd";
const things = ["Cream notebook", "Blue ballpoint", "Legal pad", "Fineliner set", "Graph pad", "Pencil case"];
export default function InputSearch() {
const [query, setQuery] = useState("");
const shown = things.filter((t) => t.toLowerCase().includes(query.trim().toLowerCase()));
return (
<div className="flex w-full max-w-sm flex-col gap-4">
<div className="relative">
<InkIcon name="search" className="pointer-events-none absolute top-1/2 left-3 size-4 -translate-y-1/2 text-ink-3" />
<Input type="search" aria-label="Search" placeholder="Search the shop" value={query} onChange={(event) => setQuery(event.target.value)} seed="is-search" className="w-full pl-9" />
{!query && <Kbd className="pointer-events-none absolute top-1/2 right-3 -translate-y-1/2">/</Kbd>}
</div>
<ul className="flex flex-col gap-1 text-ink-2">
{shown.map((t) => (
<li key={t}>{t}</li>
))}
{shown.length === 0 && <li className="text-ink-3">Nothing called that.</li>}
</ul>
</div>
);
}API reference
- variantdefault
"box" "box" | "line"Drawn around the field, or the line you write on.
- className
stringStyles the drawn box (width, margins, type size). Every other prop goes to the <input>.
- aria-invalid
booleanRedraws the box in red pen.
- seed
string | numberPins the drawing.
Every other prop goes to Base UI's Input.
Pen settings
The drawing also takes draw, roughness, passes, radius, corners, weight and speed, as props or from the nearest InkProvider. What each one does.