Inputs
MoneyInput
Currency field. The bound value is an integer in the currency's minor unit and the display is formatted as you type. BRL by default.
<script>
import { MoneyInput } from "@codeatlasdev/ui/forms";
let price = $state(123456); // R$ 1.234,56
</script>
<MoneyInput label="Price" bind:value={price} />
Import from the @codeatlasdev/ui/forms subpath. The value is always an integer in the currency’s minor unit (cents for BRL and USD, whole yen for JPY), so there is no floating-point rounding. Digits shift in from the right: typing 123456 gives R$ 1.234,56. min and max clamp the value, and an out-of-range value set from outside is clamped back into value.
Default
Type 123456 to get R$ 1.234,56.
value = 123456 cents → R$ 1.234,56
Code
Min, max, negative, error and disabled
Deposit is clamped between R$ 10,00 and R$ 100,00. Include a minus sign to toggle the sign when allowNegative is set.
Between R$ 10,00 and R$ 100,00.
Amount must be greater than zero.
Code
Currency and locale
currency picks the minor unit (USD 2 decimals, JPY none); locale picks separators and symbol placement.
Code
Helpers
Pure functions exported from @codeatlasdev/ui/forms.
centsToDisplay(123456) = R$ 1.234,56
parseInputToCents("R$ 1.234,56") = 123456
Code
Props
| Prop | Type | Default | Description |
|---|---|---|---|
value | number | 0 | Bindable amount in the currency's minor unit (integer). |
currency | string | 'BRL' | ISO 4217 code. Decimals come from Intl: USD 2, JPY 0, BHD 3. |
locale | string | – | BCP 47 tag for separators and symbol placement. Defaults to the active i18n locale when currency is set, and to 'pt-BR' when it is not, so the BRL default keeps its format. |
min | number | – | Minimum value in cents. |
max | number | – | Maximum value in cents. |
allowNegative | boolean | false | Accepts negative amounts. Type a minus sign to toggle. |
label | string | – | Label text. |
placeholder | string | the formatted zero amount | Input placeholder. |
error | string | – | Error message. Puts the field in the error state. |
description | string | – | Hint shown below the field. |
disabled | boolean | false | Disables the input. |
required | boolean | false | Marks the field as required. |
readonly | boolean | false | Makes the input read-only. |
size | 'sm' | 'md' | 'md' | Field height. |
name | string | – | Native name, for form submission. |
leading / trailing | Snippet | – | Content before or after the input. |
class | string | – | Extra classes on the root. |
onchange | (cents: number) => void | – | Called on every edit with the new cents value. |
onblur | (e: FocusEvent) => void | – | Called when the input loses focus. The display is re-formatted first. |