dentil

Currency Input

CurrencyInput reads and writes integer minor units, as Stripe and most payment APIs do, so there are no floating-point amounts in your state. Type more than £120 into the first field to see it clamp. The second field passes onCurrencyChange, so its currency code is a picker. JPY has no minor unit, so it has no decimals.

@dentil/currency-input
On this page
£
GBP
Result: 2500 (max 12000)
¥
JPY
Result: — JPY

Installation

pnpm dlx shadcn@latest add @dentil/currency-input
npx shadcn@latest add @dentil/currency-input
yarn dlx shadcn@latest add @dentil/currency-input
bunx --bun shadcn@latest add @dentil/currency-input

Files land in components/dentil/currency-input/. Uses the stock shadcn input-group, react-number-format and @dentil/select-search for the searchable picker. The symbol and decimal places come from Intl.NumberFormat.

Examples

Searchable currency picker

searchable opens the picker as a popover over every currency the browser supports. Type a code or a name, such as yen.

$
Result: 4999 USD

API reference

CurrencyInput

PropTypeDefaultDescription
currencystring—ISO 4217 code, e.g. GBP. Sets the symbol and decimal places.
valuenumber | null | undefined—Amount in minor units: 1050 is £10.50, and 1050 is ¥1,050 for JPY.
onChange(value: number | undefined) => void—Called with the amount in minor units, or undefined when the field is empty.
onCurrencyChange(currency: string) => void—Turns the currency code into a picker. If the new currency has a different number of decimal places, the amount on screen is kept and onChange gets it in the new minor units.
currenciesstring[]—ISO 4217 codes the picker offers. Defaults to every currency the browser supports.
searchablebooleanfalseOpen the picker as a SelectSearch popover you can filter by code or name, instead of a native select.
maxAmountnumber—Largest amount in minor units. Larger input is clamped to it.
allowNegativebooleanfalseAllow a leading minus.
localestring—Locale for the currency symbol. Defaults to the browser’s.
inputClassNamestring—Applied to the input. className goes on the group.
…propsComponentProps<'input'>—Other props (id, aria-invalid, aria-describedby, onBlur…) are passed to the input.