Atoms / Money input

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";
/01 → Amount
€ (EUR)
123450 minor units
import { 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>
  );
}
/02 → With currency
$ (USD)
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
PropTypeDefaultDescription
labelstring—Names the field for assistive technology.
value / defaultValuenumber | null—Controlled or not. Minor units, an integer.
onChange(value: number | null) => void—On every change.
currencystring—ISO 4217: EUR, USD, JPY (no decimals), BHD (three).
localestringthe device'sSeparators and side of the symbol.
min / max / stepnumber—In minor units. Step defaults to one major unit.
readOnlyboolean—Shown, not editable.
disabledboolean—Not editable.
id / aria-describedby / aria-invalidstring / string / boolean—From `Field`'s function form: the label, hint and error stay tied.
classNamestring—Extra classes.