# `LedgerUI.Components.Input`
[🔗](https://github.com/devaction-labs/ledger_ui/blob/v0.2.0/lib/ledger_ui/components/input.ex#L1)

Single-line text field: `outlined`, `filled` or `plain`, `rounded` or `pill`, three sizes, icon,
prefix and suffix, states, masks.

    <.input field={@form[:name]} label="Nome" />
    <.input field={@form[:total]} align="right" label="Total"><:prefix text>R$</:prefix></.input>
    <.input field={@form[:email]} type="email" variant="filled" size="lg" state="success" help="E-mail verificado" />
    <.input field={@form[:q]} shape="pill" layout="inline" label="Buscar" label_hint="opcional" />

`field={@form[:name]}` fills `id`, `name`, `value` and `errors`. With errors the help line shows
the messages and the box turns red.

## Masks

`mask` formats what is typed (hook `LedgerUI.InputMask`, which needs a stable `id`; it comes
from `field`):

    <.input name="doc" mask="cpf_cnpj" label="CPF ou CNPJ" mask_submit="raw" />
    <.input name="amount" mask="numeral" mask_options={%{thousands: "lakh"}} />
    <.input name="code" mask="blocks" mask_options={%{blocks: [3, 2, 3], delimiter: "-", uppercase: true}} />

| mask | options |
|---|---|
| `blocks` | `blocks`, `delimiter`, `delimiters`, `prefix`, `uppercase`, `lowercase`, `numeric` |
| `credit_card` | `delimiter` |
| `date` | `pattern` (`~w(d m Y)`), `delimiter` |
| `time` | `pattern` (`~w(h m s)`), `delimiter` |
| `phone` | `blocks`, `delimiter` |
| `cpf_cnpj` | none |
| `numeral` | `thousands`, `decimals`, `delimiter`, `decimal_mark`, `positive`, `prefix` |

The input submits the masked text; `mask_submit="raw"` submits the unmasked value through a
hidden input that carries the field's name.

## Slots

`:prefix` and `:suffix` hold an icon (or, with `text`, an addon such as `R$`, `%`, `.com.br`);
`interactive` puts a button there. `:label_aside` goes at the right of the caption and `:below`
between the box and the help line.

Inside an `input_group` use `variant="plain"`: the group draws the shared border.

# `input`

Renders a text-like `<input>`, with its caption, help and errors when given.
## Attributes

* `field` (`Phoenix.HTML.FormField`) - A form field: fills id/name/value/errors. Defaults to `nil`.
* `id` (`:string`) - Defaults to `nil`.
* `name` (`:string`) - Defaults to `nil`.
* `value` (`:any`) - Defaults to `nil`.
* `type` (`:string`) - Defaults to `"text"`. Must be one of `"text"`, `"email"`, `"password"`, `"number"`, `"search"`, `"tel"`, `"url"`, `"date"`, `"time"`, `"datetime-local"`, `"month"`, `"week"`, `"color"`, `"file"`, or `"hidden"`.
* `variant` (`:string`) - Defaults to `"outlined"`. Must be one of `"outlined"`, `"filled"`, or `"plain"`.
* `size` (`:string`) - Defaults to `"md"`. Must be one of `"sm"`, `"md"`, or `"lg"`.
* `shape` (`:string`) - Defaults to `"rounded"`. Must be one of `"rounded"`, or `"pill"`.
* `align` (`:string`) - Defaults to `"left"`. Must be one of `"left"`, or `"right"`.
* `state` (`:string`) - Defaults to `nil`.Must be one of `nil`, `""`, `"success"`, or `"error"`.
* `label` (`:string`) - Defaults to `nil`.
* `label_class` (`:any`) - Defaults to `nil`.
* `label_hint` (`:string`) - Defaults to `nil`.
* `layout` (`:string`) - Defaults to `"stacked"`. Must be one of `"stacked"`, or `"inline"`.
* `help` (`:string`) - Defaults to `nil`.
* `errors` (`:list`) - Defaults to `[]`.
* `disabled` (`:boolean`) - Defaults to `false`.
* `options` (`:list`) - Suggestions, rendered as the input's `<datalist>`. Defaults to `[]`.
* `icon` (`:string`) - Icon name at the left of the text. Defaults to `nil`.
* `mask` (`:string`) - Defaults to `nil`.Must be one of `nil`, `""`, `"blocks"`, `"credit_card"`, `"date"`, `"time"`, `"phone"`, `"numeral"`, or `"cpf_cnpj"`.
* `mask_options` (`:map`) - Defaults to `%{}`.
* `mask_submit` (`:string`) - Defaults to `"formatted"`. Must be one of `"formatted"`, or `"raw"`.
* `clear_on_submit` (`:boolean`) - Defaults to `false`.
* `wrapper_class` (`:any`) - Defaults to `nil`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted. Supports all globals plus: `["accept", "autocomplete", "autofocus", "form", "list", "max", "maxlength", "min", "minlength", "multiple", "pattern", "placeholder", "readonly", "required", "step", "inputmode", "size"]`.
## Slots

* `below`
* `label_aside`
* `prefix` - Accepts attributes:

  * `interactive` (`:boolean`)
  * `text` (`:boolean`)
  * `class` (`:any`)
* `suffix` - Accepts attributes:

  * `interactive` (`:boolean`)
  * `text` (`:boolean`)
  * `class` (`:any`)

---

*Consult [api-reference.md](api-reference.md) for complete listing*
