Money input
An amount in a currency, in minor units: 1250 is 12.50. The symbol sits where the locale puts it.
import { MoneyInput, formatMoney } from "@forgeron/ui";123450 minor unitsimport { MoneyInput } from "@forgeron/ui";
import { useState } from "react";
export default function Amount() {
const [cents, setCents] = useState<number | null>(123450);
return (
<div style={{ display: "grid", gap: 8 }}>
<MoneyInput label="Price" currency="EUR" locale="fr-FR" value={cents} onChange={setCents} />
<code>{cents === null ? "none" : `${cents} minor units`}</code>
</div>
);
}Currency
import { CurrencyPicker, MoneyInput } from "@forgeron/ui";
import { useState } from "react";
export default function WithCurrency() {
const [currency, setCurrency] = useState("USD");
return (
<div style={{ display: "flex", gap: 8, alignItems: "flex-end" }}>
<MoneyInput label="Amount" currency={currency} locale="en-US" defaultValue={2500} />
<CurrencyPicker label="Currency" value={currency} onChange={setCurrency} locale="en" />
</div>
);
}API → Props
| Prop | Type | Default | Description |
|---|---|---|---|
label | string | — | Names the field for assistive technology. |
value / defaultValue | number | null | — | Controlled or not. Minor units, an integer. |
onChange | (value: number | null) => void | — | On every change. |
currency | string | — | ISO 4217: EUR, USD, JPY (no decimals), BHD (three). |
locale | string | the device's | Separators and side of the symbol. |
min / max / step | number | — | In minor units. Step defaults to one major unit. |
readOnly | boolean | — | Shown, not editable. |
disabled | boolean | — | Not editable. |
id / aria-describedby / aria-invalid | string / string / boolean | — | From `Field`'s function form: the label, hint and error stay tied. |
className | string | — | Extra classes. |