Skip to content

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
  1. Two currencies
  2. When to use it
  3. For everyone
  4. Props

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 currency of 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

CurrencyInputTypeDefault
currencyrequired string
aria-describedby string
aria-label

The name for screen readers when there is no Field around it.

string
aria-labelledby string
className string
defaultValue number
disabled boolean
id

Inside a Field it comes from the Field.

string
invalid

Marks 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"
step

How much each press of a stepper or an arrow key adds.

number
value

The number, or null while the box is empty.

number | null
FieldTypeDefault
labelrequired ReactNode
className string
error

What is wrong and how to fix it. Its presence marks the control as invalid.

ReactNode
hint

Help that is always visible: what to write, in what format.

ReactNode
optional

Adds «optional» beside the label. Required is the default and is not marked.

boolean
wide

Spans both columns of a FormGrid.

boolean
  1. Two currencies
  2. When to use it
  3. For everyone
  4. Props

    Search pages, sections and terms