Currency widget (Pro)
ProIncluded in $99A conversion you can work with: both amounts are fields, swap turns the pair, and the rate says how fresh it is.
On this page
Installation
Needs chatcn Pro
This command works with a Pro license, along with every Pro component.
Or start free: sign up and get three Pro components on us, with a new one every month.
Usage
import { CurrencyWidget } from "@/components/ui/chatcn/pro/currency-widget"
<CurrencyWidget
rates={{ USD: 1, EUR: 0.862, JPY: 151.2 }}
defaultFrom="EUR"
defaultTo="JPY"
defaultAmount={250}
updatedAt={fetchedAt}
history={eurJpyLastMonth}
fee={0.0175}
/>Pass rates against any common base and the widget works out each pair. Both amounts are fields: type in either and the other follows, with each currency's own decimals (no cents on yen). The menus are native selects, so they work well on phones; picking the currency already on the other side swaps them. Under the amounts the rate shows with its freshness: a green Live while it is younger than staleAfter minutes, an amber Delayed after. history draws the month as a small line in green or red with its change, and flips when the pair is swapped. fee adds what would arrive after a card or transfer fee.
Examples
States
Props
| Prop | Type | Notes |
|---|---|---|
rates | Record<string, number> | Units per one unit of a common base |
defaultFrom, defaultTo, defaultAmount | The starting pair and amount | |
updatedAt, staleAfter | Date | string, number | Freshness; default 15 minutes |
history | number[] | The starting pair's rate, oldest first |
fee | number | A fraction, such as 0.0175 |
currencies | string[] | Codes in the menus. Default all in rates |
title, meta, locale | Header and formatting | |
labels | Partial<CurrencyWidgetLabels> | Every string, for translation |
Keyboard
| Key | Action |
|---|---|
| Tab | Currency, amount, swap, then the other side |
| Enter | Finish typing an amount |
Accessibility
- Amounts are labelled with their currency; menus with their side.
- Freshness is said in words as well as color, and the history has its change in its label.
Motion
The swap arrow turns half a circle per swap over 300 ms; the live dot pulses. Reduced motion stills both.