Active Foundation · Example
A currency by its code
A currency by its codeClient
Value: EUR
Full source examples/ui/currency-combobox.tsx
// apps/docs/examples/ui/currency-combobox.tsx'use client';
import {useMemo, useState} from 'react';
import {CurrencyCombobox} from '@workspace/active-ui/components/composed/currency-combobox';import { Field, FieldDescription, FieldLabel,} from '@workspace/active-ui/components/primitives/field';
// The list and its order are the application's: here the euro first.const CODES = ['EUR', 'USD', 'GBP', 'CHF', 'SEK', 'DKK', 'NOK', 'PLN', 'JPY'];
/** * A currency by its ISO 4217 code. The names come from the browser's * `Intl.DisplayNames`, in the reader's language; the code is shown first * and is searchable too (try "fr" for the Swiss franc). */export default function CurrencyComboboxExample() { const [currency, setCurrency] = useState('EUR'); const options = useMemo(() => { const names = new Intl.DisplayNames(['en'], {type: 'currency'}); return CODES.map((code) => ({code, name: names.of(code) ?? code})); }, []); return ( <Field className="w-full max-w-xs"> <FieldLabel htmlFor="currency">Currency</FieldLabel> <CurrencyCombobox id="currency" value={currency} onValueChange={setCurrency} options={options} locale="en" placeholder="Choose a currency" searchLabel="Search currencies" searchPlaceholder="Search…" emptyText="No currency found." aria-describedby="currency-value" /> <FieldDescription id="currency-value"> Value: <code>{currency || "''"}</code> </FieldDescription> </Field> );}