# Input

Fields where people type: names, emails, passwords, amounts, codes and more.

```tsx
import { InputField } from '@halo-ds/react';
```

## When to use it
One Input covers almost every kind of field. Icons, a Prefix and a Suffix (text or a picker) are built in: switch each one on in the right panel, and the code sets the type, like email or password, so phones show the right keyboard. Wrap it in an Input field to add a label and a hint. Two kinds work differently and have their own components: Number input, with minus and plus buttons, and Verification code, with one box per digit.

## Do
- Give every field a visible label.
- Size fields to the answer, like a short field for a postcode.
- Show errors next to the field, and say how to fix them.
- Set the type in code so phones show the right keyboard.

## Don't
- Use the placeholder as the only label; it disappears when people type.
- Disable paste in password or code fields.
- Ask for things you do not need.
- Show an error before people have finished typing.

## Props
### InputField props
| Prop | Type | What it does |
| --- | --- | --- |
| `size` | `InputSize \| undefined` | 32, 40 or 48px tall. Figma: Size. |
| `iconLeft` | `ReactNode` | Icon at the start, like a search glass. Decorative. Figma: L icon. |
| `iconRight` | `ReactNode` | Something at the end: an icon, or a CompactButton for actions like clear or show password. Figma: R icon. |
| `prefix` | `ReactNode` | Text or a control before the value, split by a line, like "https://". Figma: Prefix. |
| `suffix` | `ReactNode` | Text or a control after the value, like "kg". Figma: Suffix. |
| `invalid` | `boolean \| undefined` | Red border, a warning icon at the end and aria-invalid. Figma: State=Error. |
| `valid` | `boolean \| undefined` | A green check at the end once the value has passed a check, like an available username. Figma: State=Success. |
| `classNames` | `Partial<Record<InputPart, string>> \| undefined` | Extra class names for the parts inside the component, by part name, like `{ header: 'my-header' }`. |
| `styles` | `Partial<Record<InputPart, CSSProperties>> \| undefined` | Inline styles for the parts inside the component, by part name, like `{ footer: { gap: 4 } }`. |
| `label` | `ReactNode` |  |
| `error` | `ReactNode` | An error message. Replaces the hint, turns red and marks the control invalid. The control shows the warning icon, so the message has none. Figma: State=Error. |
| `hint` | `ReactNode` | Help text under the control. Figma: Hint. |
| `count` | `ReactNode` | Shown at the end of the hint row, like "86 / 2,000". |
| `optional` | `boolean \| undefined` |  |
| `info` | `ReactNode` |  |
| `fieldClassName` | `string \| undefined` | Class for the outer field, not the control. |
| `fieldClassNames` | `Partial<Record<FieldPart, string>> \| undefined` | Classes for the field's parts: root, label, hintRow, hint, count. |
| `fieldStyles` | `Partial<Record<FieldPart, CSSProperties>> \| undefined` | Styles for the field's parts: root, label, hintRow, hint, count. |
It also takes the usual HTML attributes for its element.

## Examples
### Overview
```tsx
import { InputField } from '@halo-ds/react';
import { MagnifyingGlass } from '@phosphor-icons/react';

export default function Example() {
  return (
    <div style={{ display: 'grid', gap: 20, width: 320 }}>
      <InputField label="Email" type="email" placeholder="name@company.com" hint="We send receipts here." />
      <InputField label="Search" placeholder="Search projects" iconLeft={<MagnifyingGlass />} />
      <InputField label="Username" placeholder="johndoe" defaultValue="ada" error="That name is taken." />
    </div>
  );
}
```

### Sizes
Small, medium and large.
```tsx
import { Input } from '@halo-ds/react';

export default function Demo() {
  return (
    <div className="demo-stack" style={{ width: 300 }}>
      <Input size="sm" placeholder="Small" aria-label="Small" />
      <Input size="md" placeholder="Medium" aria-label="Medium" />
      <Input size="lg" placeholder="Large" aria-label="Large" />
    </div>
  );
}
```

### States
Required, optional with an info tip, valid, an error and disabled.
```tsx
import { InputField } from '@halo-ds/react';

export default function Demo() {
  return (
    <div className="demo-stack" style={{ width: 320 }}>
      <InputField label="Full name" placeholder="John Doe" required defaultValue="Amara Okafor" />
      <InputField label="Company" optional info="Shown on your invoices." placeholder="Studio" />
      <InputField label="Username" placeholder="johndoe" valid defaultValue="amara.okafor" />
      <InputField label="Password" placeholder="••••••••" error="Use at least 8 characters." defaultValue="abc" />
      <InputField label="Email" placeholder="johndoe@example.com" disabled defaultValue="amara@example.com" />
    </div>
  );
}
```

### Icons, prefixes and suffixes
Extra text or an icon inside the box, for units, web addresses and search.
```tsx
import { Input, InputField } from '@halo-ds/react';
import { MagnifyingGlass } from '@phosphor-icons/react';

export default function Demo() {
  return (
    <div className="demo-stack" style={{ width: 320 }}>
      <Input iconLeft={<MagnifyingGlass />} placeholder="Search" aria-label="Search" />
      <InputField label="Website" prefix="https://" placeholder="example.com" />
      <InputField label="Weight" suffix="kg" placeholder="70" defaultValue="72" />
    </div>
  );
}
```

### Number and code
A number with minus and plus buttons, and one box per digit for sign-in codes. Pasting fills them all.
```tsx
import { NumberInput, VerificationCode } from '@halo-ds/react';

export default function Demo() {
  return (
    <div className="demo-stack">
      <NumberInput label="Guests" placeholder="1" defaultValue={2} min={1} max={10} />
      <VerificationCode length={6} defaultValue="482" />
    </div>
  );
}
```

More: https://halodesignsystem.dev/components/input
