Input

Text fields with icons, an error shake and a drawn success check.

Preview

"use client";

import { Eye, EyeOff, Mail, Search } from "lucide-react";
import { useState } from "react";
import { Input } from "@/components/motion/input";

export function InputPreview() {
  const [email, setEmail] = useState("");
  const [pass, setPass] = useState("hunter2");
  const [query, setQuery] = useState("Ada");
  const [show, setShow] = useState(false);

  const emailError =
    email.length > 0 && !email.includes("@") ? "Enter a valid email address." : undefined;

  return (
    <div className="flex w-full max-w-xs flex-col gap-1">
      <Input
        label="Email"
        type="email"
        placeholder="[email protected]"
        leftIcon={<Mail />}
        value={email}
        onChange={setEmail}
        error={emailError}
        reserveErrorLine
      />
      <Input
        label="Password"
        type={show ? "text" : "password"}
        value={pass}
        onChange={setPass}
        rightIcon={
          <button
            type="button"
            onClick={() => setShow((s) => !s)}
            aria-label={show ? "Hide password" : "Show password"}
            className="pointer-events-auto"
          >
            {show ? <EyeOff /> : <Eye />}
          </button>
        }
        reserveErrorLine
      />
      <Input
        label="Search"
        leftIcon={<Search />}
        value={query}
        onChange={setQuery}
        success={query.length > 1}
        reserveErrorLine
      />
    </div>
  );
}

Install

Add it with the shadcn CLI, or copy the source manually.

$ bunx --bun shadcn add @beui/input

API Reference

label?
string

Text shown above the field and tied to it as its label.

value?
string

The field text, for controlled use.

defaultValue?
string

The initial field text when uncontrolled.

onChange?
((value: string) => void)

Called with the new text on every edit.

error?
string | boolean

Truthy error triggers a shake, red border and (if a string) a message.

reserveErrorLine?
boolean

Reserve one message line so validation does not shift nearby content.

Defaultfalse
success?
boolean

Shows a green check in place of `rightIcon`.

leftIcon?
ReactNode

Icon inside the field, before the text.

rightIcon?
ReactNode

Icon inside the field, after the text. Hidden while `success` is set.

className?
string

Classes merged onto the root element.

classNames?
InputClassNames

Classes for the root, label, field, input, icons and error message.

Also on React Native. Error shake, focus ring and a drawn success check.

Updated