FX Converter
Two linked amount and currency fields: type what you send or what arrives, with the fee, a swap and a guaranteed rate.
Attributes
| Name | Type | Default | Description |
|---|---|---|---|
from | string | USD | The currency sent. |
to | string | EUR | The currency received. |
currencies | string[] | [] | Currencies both pickers offer, as a ; list. A picker shows with two or more. |
from-currencies | string[] | [] | Currencies the upper picker offers, when they differ from currencies. |
to-currencies | string[] | [] | Currencies the lower picker offers, when they differ from currencies. |
amount | string | — | The amount typed, in minor units of its field's currency; empty for none. |
fixed | FxSide | from | The field amount belongs to; the other is computed. |
rate | number | 0 | 1 unit of from buys rate units of to. 0 (unknown) leaves the computed field empty. |
fee | string | — | The fee, in minor units of from, taken before converting. Set, it draws the fee lines. |
rate-expires | string | — | When a guaranteed rate runs out: an ISO time or epoch milliseconds. The rate line counts down to it. |
max | string | — | The most that can be sent, in minor units of from: above it, the upper field shows an error. |
from-label | string | — | The label of the upper field. Default: "You send". |
to-label | string | — | The label of the lower field. Default: "Recipient gets", or "Recipient gets exactly" once typed in. |
locale | string | — | The locale amounts are formatted in. Without it: the nearest lang. |
disabled | boolean | false | Turns off both fields and the swap button. |
readonly | boolean | false | Shows the amounts without letting them be edited or swapped. |
Slots
| Name | Description |
|---|---|
swap-icon | The swap button's icon. Default: two arrows. |
Events
| Name | Type | Description |
|---|---|---|
rate-expire | CustomEvent<void> | Fired when the guaranteed rate runs out. Does not bubble. |
input | CustomEvent<{ from: string; to: string; fromAmount: string; toAmount: string; fixed: 'from' | 'to'; rate: number }> | Fired on every edit, with the computed amount already updated. |
change | CustomEvent<{ from: string; to: string; fromAmount: string; toAmount: string; fixed: 'from' | 'to'; rate: number }> | Fired when an edit is committed, a currency is picked, or the currencies are swapped. |
currency-change | CustomEvent<{ side: 'from' | 'to'; currency: string }> | Fired when the reader picked a currency in either field. Does not bubble. |
swap | CustomEvent<{ from: string; to: string }> | Fired when the swap button exchanged the currencies; set the new rate. Does not bubble. |
rate-refresh | CustomEvent<void> | Fired when the reader asks for a new rate after it expired. Does not bubble. |
CSS parts
Shadow DOM styling hooks used with ::part(name). Prefer CSS custom properties when they cover the change.
| Name | Description |
|---|---|
field | Each labelled amount field. |
lines | The fee and rate lines between the fields. |
CSS custom properties
Grouped by semantic target and state from --c2-<component>__<target>__<state>--<property>. Click a group to collapse it; click a name to copy it.
| Name | Type | Default | Description |
|---|---|---|---|
--c2-fx-converter--border | border | 1px solid #e4e4e7 | |
--c2-fx-converter--border-radius | border-radius | 14px | |
--c2-fx-converter--background | color | #ffffff | |
--c2-fx-converter--color | color | #18181b | |
--c2-fx-converter--padding | padding | 16px | |
--c2-fx-converter--gap | pixel | 4px | Space between the fields and the lines. |
--c2-fx-converter__label--color | color | #71717a | |
--c2-fx-converter__label--font-size | font-size | 12px | |
--c2-fx-converter__label--font-weight | font-weight | 500 | |
--c2-fx-converter__amount--font-size | font-size | 20px | The amounts in the two fields. |
--c2-fx-converter__amount--line-height | pixel | 28px | |
--c2-fx-converter__rail--border | border | 2px solid #e4e4e7 | The line the fee and rate lines hang from. |
--c2-fx-converter__line--font-size | font-size | 12px | |
--c2-fx-converter__line__value--font-weight | font-weight | 500 | |
--c2-fx-converter__line__label--color | color | #71717a | |
--c2-fx-converter__rate--color | color | #0265dc | |
--c2-fx-converter__expired--color | color | #dc2626 | |
--c2-fx-converter__stale--opacity | opacity | 0.38 | The computed amount while the rate has expired. |
--c2-fx-converter__swap--border | border | 1px solid #e4e4e7 | |
--c2-fx-converter__swap-icon--size | pixel | 20px | The swap icon, slotted or default. |
Text and languages
The text the component shows, in English. It shows another language when the app adds one with addTranslations, under fx-converter, and the nearest lang asks for it; any message not translated stays in English. {0}, {1}… stand for the values a message carries. Languages guide.
| Key | English | Values |
|---|---|---|
fromLabel | You send | — |
toLabel | Recipient gets | — |
toExactLabel | Recipient gets exactly | — |
currencyOf | {0} currency | {0} field |
fee | Fee | — |
converted | Amount converted | — |
rate | Exchange rate | — |
rateLine | 1 {0} = {1} {2} | {0} from {1} rate {2} to |
guaranteed | Guaranteed for {0} | {0} left |
expired | Rate expired | — |
indicative | Indicative rate | — |
newRate | New rate | — |
swap | Swap currencies | — |
overMax | You can send up to {0} | {0} limit |
announceTo | Recipient gets {0} | {0} amount |
announceFrom | You send {0} | {0} amount |