# Input

Text inputs of every type, with optional icons.

Source: https://www.zazz.sh/api/primitives/input/

## Installation

```bash
pnpm dlx zazz-ui add input
```

Also adds `fields`, which it depends on.

Run `zazz-ui init` first if the project has no `zazz/` folder yet.

## Examples

### Default

```html
<div data-ui="field">
  <label data-field-slot="label" for="f-name">Name</label>
  <input
    data-ui="input"
    id="f-name"
    name="name"
    type="text"
    inputmode="text"
    placeholder="Ada Lovelace"
    autocomplete="name"
    autocapitalize="words"
    enterkeyhint="next"
  />
</div>
<div data-ui="field">
  <label data-field-slot="label" for="f-email">Email</label>
  <input
    data-ui="input"
    id="f-email"
    name="email"
    type="email"
    inputmode="email"
    required
    placeholder="you@example.com"
    autocomplete="email"
    autocapitalize="off"
    spellcheck="false"
    enterkeyhint="next"
    aria-describedby="f-email-hint"
  />
  <div data-field-slot="description">
    <span data-field-slot="hint" id="f-email-hint"
      >We'll never sell or share your email address.</span
    >
    <span data-field-slot="error" role="alert">Please enter a valid email address.</span>
  </div>
</div>
<div data-ui="field">
  <label data-field-slot="label" for="f-phone">Phone</label>
  <input
    data-ui="input"
    id="f-phone"
    name="phone"
    type="tel"
    inputmode="tel"
    placeholder="+1 (555) 012-3456"
    autocomplete="tel"
    enterkeyhint="next"
  />
</div>
<div data-ui="field">
  <label data-field-slot="label" for="f-date">Datetime</label>
  <input
    data-ui="input"
    id="f-date"
    name="date"
    type="datetime-local"
    inputmode="none"
    autocomplete="off"
  />
</div>
```

### Icon leading

```html
<label data-ui="input-group">
  <input data-ui="input" type="text" name="query" placeholder="Placeholder" />
  <span data-input-group-slot="addon">
    <svg
      xmlns="http://www.w3.org/2000/svg"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
      aria-hidden="true"
    >
      <line x1="4" y1="6" x2="20" y2="6" />
      <line x1="4" y1="12" x2="20" y2="12" />
      <line x1="4" y1="18" x2="20" y2="18" />
    </svg>
  </span>
</label>
```

### Icon trailing

```html
<label data-ui="input-group">
  <input data-ui="input" type="search" name="q" placeholder="Search…" aria-label="Search" />
  <span data-input-group-slot="addon" data-input-group-align="inline-end">
    <svg
      xmlns="http://www.w3.org/2000/svg"
      viewBox="0 0 24 24"
      fill="none"
      stroke="currentColor"
      stroke-width="2"
      stroke-linecap="round"
      stroke-linejoin="round"
      aria-hidden="true"
    >
      <circle cx="11" cy="11" r="8" />
      <line x1="21" y1="21" x2="16.65" y2="16.65" />
    </svg>
  </span>
</label>
```

## Attributes

| Attribute | Kind | Values |
| --- | --- | --- |
| `data-ui="input"` | identity | free value |

Requires: fields.

## Hooks

| Hook | Default | State |
| --- | --- | --- |
| `--ui-input-border-color` | `var(--ui-field-border-color)` | — |
| `--ui-input-border-style` | `var(--ui-field-border-style)` | — |
| `--ui-input-border-width` | `var(--ui-field-border-width)` | — |
| `--ui-input-calendar-picker-color` | `currentColor` | — |
| `--ui-input-calendar-picker-corner-shape` | `var(--ui-field-corner-shape)` | — |
| `--ui-input-calendar-picker-icon-size` | `calc(var(--spacing) * 4)` | — |
| `--ui-input-calendar-picker-mask` | `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 256 256'%3E%3Crect width='256' height='256' fill='none'/%3E%3Crect x='40' y='40' width='176' height='176' rx='8' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='176' y1='24' x2='176' y2='56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='80' y1='24' x2='80' y2='56' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3Cline x1='40' y1='88' x2='216' y2='88' fill='none' stroke='currentColor' stroke-linecap='round' stroke-linejoin='round' stroke-width='16'/%3E%3C/svg%3E")` | — |
| `--ui-input-calendar-picker-radius` | `var(--ui-field-inset-radius)` | — |
| `--ui-input-calendar-picker-size` | `calc(var(--spacing) * 6)` | — |
| `--ui-input-corner-shape` | `var(--ui-field-corner-shape)` | — |
| `--ui-input-font-size` | `var(--ui-field-font-size)` | — |
| `--ui-input-leading` | `var(--ui-field-leading)` | — |
| `--ui-input-min-w` | `16ch` | — |
| `--ui-input-pl` | `var(--ui-field-px)` | — |
| `--ui-input-pr` | `var(--ui-field-px)` | — |
| `--ui-input-py` | `var(--ui-field-py)` | — |
| `--ui-input-radius` | `var(--ui-field-radius)` | — |
| `--ui-input-w` | `100%` | — |
