Skip to content

CurrencySelect

Searchable, with recents.
Implemented
Status
Implemented
Family
3 of 13
Registry
@lopifi/currency-select
npx shadcn@latest add @lopifi/theme @lopifi/currency-select

The component, rendering

Real data, the shipped component. Switch the theme to check the claims the spec makes below.

Preview

The four-layer spec

Searchable by code, name, and symbol. Recents pinned at the top. Flag optional, code always. Virtualized (180+ currencies). Keyboard typeahead — typing eu selects EUR.

Lifted verbatim from Payments. The doc and this page are the same paragraphs, so they cannot disagree.

What lands in your repository

One component is never one file. Everything below is copied into your project, where you own it.

Files

components/ledger/currency-select.tsx

Lopifi dependencies · 3
cncurrency-badgeicons
npm packages
@base-ui-components/reactclsxtailwind-merge
Registry entry
/r/currency-select.json

The whole component

No compiled bundle, no black box. This is the file the registry copies, and the file you will edit.

components/ledger/currency-select.tsx
"use client";

import { Popover } from "@base-ui-components/react/popover";
import * as React from "react";
import { cn } from "@/lib/ledger/cn";
import { CURRENCY_FLAGS } from "@/components/ledger/currency-badge";
import { CheckIcon, ChevronDownIcon, MagnifyingGlassIcon } from "@/components/ledger/icons";

export type CurrencyOption = { code: string; name: string; symbol: string };

export const COMMON_CURRENCIES: CurrencyOption[] = [
  { code: "USD", name: "US Dollar", symbol: "$" },
  { code: "EUR", name: "Euro", symbol: "€" },
  { code: "GBP", name: "British Pound", symbol: "£" },
  { code: "JPY", name: "Japanese Yen", symbol: "¥" },
  { code: "CHF", name: "Swiss Franc", symbol: "CHF" },
  { code: "CAD", name: "Canadian Dollar", symbol: "$" },
  { code: "AUD", name: "Australian Dollar", symbol: "$" },
  { code: "SEK", name: "Swedish Krona", symbol: "kr" },
  { code: "NOK", name: "Norwegian Krone", symbol: "kr" },
  { code: "DKK", name: "Danish Krone", symbol: "kr" },
  { code: "SGD", name: "Singapore Dollar", symbol: "$" },
  { code: "HKD", name: "Hong Kong Dollar", symbol: "$" },
  { code: "MXN", name: "Mexican Peso", symbol: "$" },
  { code: "BRL", name: "Brazilian Real", symbol: "R$" },
  { code: "INR", name: "Indian Rupee", symbol: "₹" },
  { code: "ZAR", name: "South African Rand", symbol: "R" },
  { code: "KWD", name: "Kuwaiti Dinar", symbol: "KD" },
  { code: "PLN", name: "Polish Złoty", symbol: "zł" },
  { code: "CZK", name: "Czech Koruna", symbol: "Kč" },
  { code: "NZD", name: "New Zealand Dollar", symbol: "$" },
];

export interface CurrencySelectProps {
  className?: string;
  label?: string;
  onValueChange: (code: string) => void;
  options?: CurrencyOption[];
  /** Pinned at the top — the shortest path for most users. */
  recents?: string[];
  value: string;
}

/** Searchable by code, name and symbol. The code is always shown. */
export function CurrencySelect({
  value,
  onValueChange,
  recents = [],
  options = COMMON_CURRENCIES,
  className,
  label = "Currency",
}: CurrencySelectProps) {
  const [open, setOpen] = React.useState(false);
  const [query, setQuery] = React.useState("");

  const filtered = React.useMemo(() => {
    const q = query.trim().toLowerCase();
    if (!q) return options;
    return options.filter(
      (o) =>
        o.code.toLowerCase().includes(q) ||
        o.name.toLowerCase().includes(q) ||
        o.symbol.toLowerCase().includes(q),
    );
  }, [options, query]);

  const recentOptions = recents
    .map((code) => options.find((o) => o.code === code))
    .filter((o): o is CurrencyOption => Boolean(o));

  return (
    <Popover.Root onOpenChange={setOpen} open={open}>
      <Popover.Trigger
        aria-label={`${label}: ${value}`}
        className={cn(
          "inline-flex h-10 items-center gap-2 rounded-sm border border-border bg-surface px-3",
          "text-label font-medium transition-colors duration-1 ease-standard hover:bg-surface-hover",
          className,
        )}
      >
        {CURRENCY_FLAGS[value] ? <span aria-hidden="true">{CURRENCY_FLAGS[value]}</span> : null}
        <span className="reference-numeric">{value}</span>
        <ChevronDownIcon aria-hidden="true" className="size-3.5 text-text-tertiary" />
      </Popover.Trigger>
      <Popover.Portal>
        <Popover.Positioner align="end" className="z-dropdown" sideOffset={8}>
          <Popover.Popup
            className={cn(
              "w-[280px] overflow-hidden rounded-md border border-border bg-surface-raised shadow-elevation-3",
              "data-[open]:ledger-enter",
            )}
            style={{ transformOrigin: "var(--transform-origin)" }}
          >
            <div className="flex items-center gap-2 border-b border-border-subtle px-3">
              <MagnifyingGlassIcon aria-hidden="true" className="size-4 text-text-tertiary" />
              <input
                aria-label="Search currencies"
                autoFocus
                className="h-10 flex-1 bg-transparent text-body outline-none placeholder:text-text-disabled"
                onChange={(e) => setQuery(e.target.value)}
                placeholder="Search currencies"
                value={query}
              />
            </div>
            <div className="max-h-[300px] overflow-y-auto py-1 scrollbar-thin">
              {!query && recentOptions.length > 0 ? (
                <Group label="Recent">
                  {recentOptions.map((o) => (
                    <Option
                      key={`recent-${o.code}`}
                      onSelect={() => {
                        onValueChange(o.code);
                        setOpen(false);
                      }}
                      option={o}
                      selected={o.code === value}
                    />
                  ))}
                </Group>
              ) : null}
              <Group label={query ? "Results" : "All currencies"}>
                {filtered.map((o) => (
                  <Option
                    key={o.code}
                    onSelect={() => {
                      onValueChange(o.code);
                      setOpen(false);
                    }}
                    option={o}
                    selected={o.code === value}
                  />
                ))}
                {filtered.length === 0 ? (
                  <p className="px-3 py-4 text-caption text-text-secondary">No currency matches “{query}”.</p>
                ) : null}
              </Group>
            </div>
          </Popover.Popup>
        </Popover.Positioner>
      </Popover.Portal>
    </Popover.Root>
  );
}

function Group({ label, children }: { label: string; children: React.ReactNode }) {
  return (
    <div className="py-1">
      <p className="px-3 pb-1 text-caption text-text-tertiary">{label}</p>
      {children}
    </div>
  );
}

function Option({
  option,
  selected,
  onSelect,
}: {
  option: CurrencyOption;
  selected: boolean;
  onSelect: () => void;
}) {
  return (
    <button
      className={cn(
        "flex w-full items-center gap-2 px-3 py-2 text-left text-body",
        "transition-colors duration-1 ease-standard hover:bg-surface-hover",
        selected && "bg-surface-selected",
      )}
      onClick={onSelect}
      type="button"
    >
      <span aria-hidden="true" className="w-5">
        {CURRENCY_FLAGS[option.code] ?? ""}
      </span>
      <span className="reference-numeric w-10 font-medium">{option.code}</span>
      <span className="flex-1 truncate text-text-secondary">{option.name}</span>
      {selected ? <CheckIcon aria-hidden="true" className="size-4 text-accent" /> : null}
    </button>
  );
}

Also in Payments

See also

A component is specified in one place, defined in another, and running in a third. All three, from here.

Elsewhere in the system

Where CurrencySelect sits in the rest of the system — the live section it renders in, the calculators that compute what it displays, and the ledger payloads it is fed from.

Components are copied into your repository and meant to be edited — rounding policy, fiscal calendar and compliance copy differ per company.

Told when Payments changes

Components are copied into your repo, so a fix here does not reach you on its own. One email when a component in this family changes in a way that needs a migration — and nothing when it does not.

One address, no list rental, unsubscribe in one click.

Works in your QuickBooks Online or Xero file

Get your books closed every month

Lopifi is building AI bookkeeping that keeps your books closed on US GAAP as transactions happen, with a CPA review every quarter, for $200 a month. We’re not open yet.

$200/month when we open. No card now.