Components
Input
An input component with leading/trailing slot support and validation states
Installation
$npx litefy@latest add input
$pnpm dlx litefy@latest add input
$yarn dlx litefy@latest add input
$bun --bun litefy@latest add input
Usage
Basic Usage
Input fields for different data types.
@example.com
"use client";
import { Mail, Phone, Search } from "lucide-react";
import { Input } from "@/ui";
export default function Demo() {
return (
<div className="flex flex-col gap-4">
<Input type="email" placeholder="Enter email" leading={<Mail />} trailing={"@example.com"} />
<Input type="search" placeholder="Search..." leading={<Search />} />
<Input type="tel" placeholder="Enter phone" leading={<Phone />} />
</div>
);
}
Invalid State
Input fields with validation error state.
"use client";
import { useState } from "react";
import { Input } from "@/ui";
export default function Demo() {
const [value, setValue] = useState("");
const [invalid, setInvalid] = useState(false);
function handleChange(e: React.ChangeEvent<HTMLInputElement>) {
const val = e.target.value;
setValue(val);
if (!val) {
setInvalid(false);
return;
}
const isEmail = /^[^\s@]+@[^\s@]+\.[^\s@]+$/.test(val);
setInvalid(!isEmail);
}
return (
<div className="flex flex-col gap-4 w-72">
<Input
type="email"
placeholder="Enter email"
value={value}
invalid={invalid}
onChange={handleChange}
/>
{invalid && <span className="text-danger text-sm">Please enter a valid email address</span>}
</div>
);
}
Custom
Compose InputGroup, InputLeading, InputRoot, InputTrailing for full control — the parts belong to the Input Group component, see its page for the complete API. The focus-within focus ring and data-invalid invalid styles apply automatically.
⌘+K
"use client";import { useState } from "react";import { Search, TriangleAlert } from "lucide-react";import { InputGroup, InputLeading, InputRoot, InputTrailing } from "@/ui";export default function Demo() { const [value, setValue] = useState(""); const invalid = value.length > 0 && !value.includes("@"); return ( <InputGroup data-invalid={invalid || undefined}> <InputLeading> <Search /> </InputLeading> <InputRoot value={value} onChange={(e) => setValue(e.target.value)} placeholder="Search mail..." aria-invalid={invalid} /> <InputTrailing> {invalid ? ( <TriangleAlert className="text-danger" /> ) : ( <kbd className="font-mono text-xs">⌘+K</kbd> )} </InputTrailing> </InputGroup> );}API Reference
High-level Components
Ready-to-use composite components.
Input
The input component with slot and validation support.
| Prop | Type | Default | Description |
|---|---|---|---|
type | 'text' | 'email' | 'url' | 'tel' | 'search' | - | Input type |
leading | ReactNode | - | Leading slot content (e.g., icons) |
trailing | ReactNode | - | Trailing slot content (e.g., buttons, icons) |
invalid | boolean | - | Whether the input is in an invalid state |
className | ClassNameValue | - | Custom classes, applied to the group shell |
style | React.CSSProperties | - | Inline styles, applied to the group shell |
classNames | { leading?: ClassNameValue; trailing?: ClassNameValue; root?: ClassNameValue } | - | Custom classes for the leading/trailing slots and the inner input (root) |
styles | { leading?: React.CSSProperties; trailing?: React.CSSProperties; root?: React.CSSProperties } | - | Inline styles for the leading/trailing slots and the inner input (root) |
...props | React.ComponentProps<"input"> | - | Supports all native input props (except type, className) |