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

A numeric field for money and quantities that shows the number the way the person's locale
writes it (`1.234,56` in pt-BR, `1,234.56` in en) and submits the plain machine value
(`1234.56`).

    <.number_input field={@form[:price]} label="Price" prefix="R$" decimals={2} min={0} />
    <.number_input field={@form[:quantity]} label="Quantity" steppers min={1} step={1} suffix="un" />
    <.number_input name="qty" value={3} steppers stepper_style="round" min={0} />

The control is the design's `lu-num`: the number is a `span.v` that the `LedgerUI.NumberInput`
hook (`priv/static/ledger_ui/hooks/number_input.js`) makes editable (`contenteditable`,
`role="spinbutton"`); a hidden input named like the field carries the machine value and fires a
bubbling `input` event when it changes, so a surrounding `phx-change` runs. Typing keeps what
the person writes; leaving the field clamps to `min`/`max`, rounds to `decimals`/`max_decimals`
and writes it grouped. Arrow up/down (and the steppers) move by `step`, Page up/down by ten
steps. The steppers are disabled at `min` and `max` by the hook.

Deviations from the README: `align` defaults to `"center"` (the design's value), and the
accessible names of the steppers default to the `locale`'s (`Diminuir`/`Aumentar` in pt-BR).

# `format_number`

Formats a number for display, as the field shows it.

    iex> LedgerUI.Components.NumberInput.format_number(1284.9, decimals: 2)
    "1.284,90"
    iex> LedgerUI.Components.NumberInput.format_number(12.5, locale: "en", max_decimals: 2)
    "12.5"

# `number_input`

Renders the number input.
## Attributes

* `id` (`:string`) - Defaults to `nil`.
* `name` (`:string`) - Defaults to `nil`.
* `value` (`:any`)
* `field` (`Phoenix.HTML.FormField`) - Defaults to `nil`.
* `label` (`:string`) - Defaults to `nil`.
* `label_class` (`:any`) - Defaults to `nil`.
* `help` (`:string`) - Defaults to `nil`.
* `errors` (`:list`) - Defaults to `[]`.
* `disabled` (`:boolean`) - Defaults to `false`.
* `locale` (`:string`) - Defaults to `"pt-BR"`. Must be one of `"pt-BR"`, `"pt_BR"`, or `"en"`.
* `decimal_separator` (`:string`) - Defaults to `nil`.
* `thousands_separator` (`:string`) - Defaults to `nil`.
* `decimals` (`:integer`) - Defaults to `nil`.
* `max_decimals` (`:integer`) - Defaults to `nil`.
* `min` (`:any`) - Defaults to `nil`.
* `max` (`:any`) - Defaults to `nil`.
* `step` (`:any`) - Defaults to `1`.
* `steppers` (`:boolean`) - Defaults to `false`.
* `stepper_style` (`:string`) - Defaults to `"inset"`. Must be one of `"inset"`, `"round"`, or `"joined"`.
* `decrement_label` (`:string`) - Defaults to `nil`.
* `increment_label` (`:string`) - Defaults to `nil`.
* `prefix` (`:string`) - Defaults to `nil`.
* `suffix` (`:string`) - Defaults to `nil`.
* `variant` (`:string`) - Defaults to `"outlined"`. Must be one of `"outlined"`, or `"filled"`.
* `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 `"center"`. Must be one of `"left"`, `"right"`, or `"center"`.
* `wrapper_class` (`:any`) - Defaults to `nil`.
* `canvas` (`:boolean`) - The block of the canvas app templates: a `div.lu-num` whose minus button is `.minus` (otherwise a `span`). Defaults to `false`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.

# `number_stepper`

Same as `number_input/1` (same attributes and slots), under the name the design vitrine uses.
## Attributes

* `id` (`:string`) - Defaults to `nil`.
* `name` (`:string`) - Defaults to `nil`.
* `value` (`:any`)
* `field` (`Phoenix.HTML.FormField`) - Defaults to `nil`.
* `label` (`:string`) - Defaults to `nil`.
* `label_class` (`:any`) - Defaults to `nil`.
* `help` (`:string`) - Defaults to `nil`.
* `errors` (`:list`) - Defaults to `[]`.
* `disabled` (`:boolean`) - Defaults to `false`.
* `locale` (`:string`) - Defaults to `"pt-BR"`. Must be one of `"pt-BR"`, `"pt_BR"`, or `"en"`.
* `decimal_separator` (`:string`) - Defaults to `nil`.
* `thousands_separator` (`:string`) - Defaults to `nil`.
* `decimals` (`:integer`) - Defaults to `nil`.
* `max_decimals` (`:integer`) - Defaults to `nil`.
* `min` (`:any`) - Defaults to `nil`.
* `max` (`:any`) - Defaults to `nil`.
* `step` (`:any`) - Defaults to `1`.
* `steppers` (`:boolean`) - Defaults to `false`.
* `stepper_style` (`:string`) - Defaults to `"inset"`. Must be one of `"inset"`, `"round"`, or `"joined"`.
* `decrement_label` (`:string`) - Defaults to `nil`.
* `increment_label` (`:string`) - Defaults to `nil`.
* `prefix` (`:string`) - Defaults to `nil`.
* `suffix` (`:string`) - Defaults to `nil`.
* `variant` (`:string`) - Defaults to `"outlined"`. Must be one of `"outlined"`, or `"filled"`.
* `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 `"center"`. Must be one of `"left"`, `"right"`, or `"center"`.
* `wrapper_class` (`:any`) - Defaults to `nil`.
* `canvas` (`:boolean`) - The block of the canvas app templates: a `div.lu-num` whose minus button is `.minus` (otherwise a `span`). Defaults to `false`.
* `class` (`:any`) - Defaults to `nil`.
* Global attributes are accepted.

---

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