Input

A field with a label, a hint, and cloth for errors.

Good. Mix in a capital letter.
Sent to mira@acme.studio. The demo code is 428193.
One email a month. Try subscribing as it is.

Installation

Terminal
npx shadcn@latest add https://fabrickit.org/r/input.json

This copies the component into components/fabricui. It's your code from then on. First time? Add the theme once: see Installation.

Code

components/fabricui/input.tsx
import * as React from "react";
import "./input.css";

const cx = (...c: (string | false | undefined)[]) => c.filter(Boolean).join(" ");

export type FieldProps = React.HTMLAttributes<HTMLElement> & {
  /** "label" (the default) when it holds one control; "div" when its label points at the control with htmlFor. */
  as?: "label" | "div";
};

/**
 * A field: a label, the box, and an optional hint or error, stacked.
 *
 *   <Field>
 *     <FieldLabel>Email</FieldLabel>
 *     <Input type="email" placeholder="you@studio.com" />
components/fabricui/input.css
/*
 * Input — shared by every page with a text field (Input, Sheet, Tabs).
 *
 * A field is a label, the box, and an optional hint or error:
 *
 *   <label class="field">
 *     <span class="field__label">Email</span>
 *     <input class="input" type="email" placeholder="you@studio.com" />
 *     <span class="field__hint">We'll never share it.</span>
 *   </label>
 *
 * The box is .input. On its own it is the <input> (or <textarea>). With an
 * icon or a button inside, .input is a wrapper and the <input> inside it
 * takes .input__el:
 *
 *   <div class="input"><svg class="icon">…</svg><input class="input__el" /></div>

Usage

Usage
import { Field, FieldLabel, FieldHint, Input } from "@/components/fabricui/input";

export function Email() {
  return (
    <Field>
      <FieldLabel>Email</FieldLabel>
      <Input type="email" placeholder="you@studio.com" />
      <FieldHint>We'll never share it.</FieldHint>
    </Field>
  );
}

Props

PropTypeDefault
Input

The box: a plain <input>, 36px tall. Takes every <input> prop. aria-invalid="true" turns it red; disabled fades it.

component—
Field

Stacks a label, the box and a hint or error. A <label> by default; as="div" when its FieldLabel points at the box with htmlFor.

component—
FieldLabel

The field's name. A <label> when given htmlFor, otherwise a <span>.

component—
FieldHint

A dim line under the box.

component—
FieldError

What's wrong, in red. Pair it with aria-invalid="true" on the box.

component—
FieldSuccess

It worked, in green.

component—
InputGroup

The box with an icon, a key hint or a button inside it. Holds an InputGroupInput and shows the ring while it has focus.

component—
InputGroupInput

The <input> inside an InputGroup.

component—
PasswordStrength

Four steps that fill as the password gets stronger, with a word and a tip. Pass it value.

component—