Input
A field with a label, a hint, and cloth for errors.
Installation
npx shadcn@latest add https://fabrickit.org/r/input.jsonpnpm dlx shadcn@latest add https://fabrickit.org/r/input.jsonyarn shadcn@latest add https://fabrickit.org/r/input.jsonbunx --bun shadcn@latest add https://fabrickit.org/r/input.jsonThis copies the component into components/fabricui. It's your code from then on. First time? Add the theme once: see Installation.
Step 1: Add the theme (once)
Every colour, radius and curve the components use, as --fabric-* variables. Save it as fabric.css next to your global CSS and import it there. If you've added another Fabric Kit component before, skip this.globals.css@import "./fabric.css";fabric.css/* * fabric.css — Fabric Kit's theme: every colour, radius, ring and curve the * components use, as --fabric-* variables (prefixed, so they never clash * with your own shadcn theme). Installed by `shadcn add @fabrickit/theme` * (it lands in your global CSS) — or import this file once, globally. * Dark by default. For light, put data-theme="light" on <html> (or on any * element: the tokens follow it down the tree; data-theme="dark" turns back). */ :root, [data-theme="dark"] { --fabric-page: #111111; --fabric-surface: #191919; /* triggers, recessed tiles */ --fabric-panel: #202020; /* open panels */ --fabric-raised: #2a2a2a; /* hover, range band */ --fabric-raised-hi: #343434; /* hover inside a band */ --fabric-preview: #252525; /* soft preview fills */ --fabric-text: #e0e0e0;Step 2: Copy the Input files
The component itself. Create each one at the same path in your project. It's your code from here on.components/fabricui/input.tsximport * 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>Step 3: Check the import paths
The files import each other through the @/ alias (the shadcn default, there in a new Next.js app). If your project doesn't have it, add it to tsconfig.json, or change the imports to relative paths.tsconfig.json{ "compilerOptions": { "baseUrl": ".", "paths": { "@/*": ["./*"] } } }Step 4: Use it
Import it from @/components/fabricui/input. The Usage example below shows it in a page.
Code
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" />/*
* 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
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
| Prop | Type | Default |
|---|---|---|
| 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 | — |