CurrencyInput
An amount of money in one currency, written the way the person's language writes it. The value is a plain number.
import { CurrencyInput, Field } from '@sypnia/ui/react'
On this page
Two currencies
Saved as 29
Saved as 120000
Code
import { useState } from 'react';
import { CurrencyInput, Field, FormGrid } from '@sypnia/ui/react';
// The amount is a number; it is written the way the person's language writes money in that currency.
export default function Price() {
const [usd, setUsd] = useState<number | null>(29);
const [cop, setCop] = useState<number | null>(120000);
return (
<FormGrid>
<Field label="Monthly price" hint={`Saved as ${usd ?? '—'}`}><CurrencyInput currency="USD" value={usd} onChange={setUsd} /></Field>
<Field label="Price in Colombia" hint={`Saved as ${cop ?? '—'}`}><CurrencyInput currency="COP" value={cop} onChange={setCop} /></Field>
</FormGrid>
);
} When to use it
Use it when
- Prices, limits and amounts to charge.
- Pass the ISO
currencyof the account: «USD», «COP».
Do not use it when
- Amounts in several currencies at once: one field per currency.
For everyone
- It is a number field: arrow keys step, and the currency is read with the value.
Props
| CurrencyInput | Type | Default |
|---|---|---|
currencyrequired | string | |
aria-describedby | string | |
aria-labelThe name for screen readers when there is no Field around it. | string | |
aria-labelledby | string | |
className | string | |
defaultValue | number | |
disabled | boolean | |
idInside a Field it comes from the Field. | string | |
invalidMarks the value as wrong. Inside a `<Field error>` it is set for you. | boolean | |
max | number | |
min | number | |
name | string | |
onChange | ((value: number | null) => void) | |
placeholder | string | |
size | "sm" | "md" | "lg" | |
stepHow much each press of a stepper or an arrow key adds. | number | |
valueThe number, or null while the box is empty. | number | null |
| Field | Type | Default |
|---|---|---|
labelrequired | ReactNode | |
className | string | |
errorWhat is wrong and how to fix it. Its presence marks the control as invalid. | ReactNode | |
hintHelp that is always visible: what to write, in what format. | ReactNode | |
optionalAdds «optional» beside the label. Required is the default and is not marked. | boolean | |
wideSpans both columns of a FormGrid. | boolean |