SwapWidget
From/to with the flip. The signature component.
npx shadcn add @lopifi/swap-widgetExamples
The same component, case by case. Each stage is the shipped code with the props it shows; switch to Code for the usage.
How it behaves
What it renders, what it refuses to render, and why. The same paragraphs as the family spec, so the two can’t disagree.
The signature component: from and to, with the flip.
┌─ 24 ───────────────────────────────────┐
│ You send │ label
│ [1,000.00] [USD ↓] │ figure-lg · currency select
│ Balance $4,120.00 [Max] │ caption
│ │
│ [ ↑↓ ] flip button │ centered, overlapping the divider
│ │
│ Recipient gets │
│ [918.42] [EUR ↓] │
│ │
│ 1 USD = 0.91842 EUR · 12s [locked] │ RateLine
│ ├─ ConversionBreakdown ─────────────┤ │
└────────────────────────────────────────┘
The flip#
The one place spring.playful is used.
icon rotateY? no — rotate(180deg), spring.playful { duration: 0.45, bounce: 0.22 }
fields cross-translate: top ↕ bottom, transform only, same spring
values swap INSTANTLY. The amounts do not interpolate. (Money Law 1)
The fields move; the numbers don't animate. Motion explains what happened structurally and never renders a false value.
Under reduced motion: instant swap, no rotation.
Rules#
- Editing either field recomputes the other, with a 140ms blur-masked crossfade on the computed value, never a count-up.
- The computed field looks derived:
--text-secondaryuntil it's focused. - Debounce rate fetches at 300ms; never show a stale computed value as current. During refetch, dim the computed value to 0.6.
- Insufficient balance is an inline error under the send field, not a disabled button.
- Fee and rate are always visible without expanding anything.
- A pair with no quote has no rate. Never a 1:1 fallback: the receive side stays empty, the breakdown is withheld, and the line says "No quote for USD to JPY."
- The fee is in the send currency.
feetakes oneMoneyValueper currency the user can send from; after a flip, a send currency with no fee listed is unquoted rather than charged another currency's number. Omitted, no fee is charged. - The balance check runs only when the send side is in the balance's currency. After a flip into another currency the balance and Max stand down.
defaultFrom,defaultToanddefaultAmountset the opening state.
More in Swaps & FX
See also
Where this component is specified, defined and running.
Elsewhere in the system
The live section SwapWidget renders in, the calculators behind its figures, and the ledger payloads that feed it.
- SwapWidget, runningThe swaps showcase — live, with theme, density, grayscale and reduced-motion switches.
- Swaps & FXThe rule for this family: A rate is a perishable fact. It never appears without a timestamp, and it is never transacted on without a lock. Specs for 9 React components: SwapWidget, RateLine, RateLock, ConversionBreakdown and 5 more.
Components are copied into your repository and meant to be edited. Rounding policy, fiscal calendar and compliance copy differ per company.
Release notes
Get an email when Swaps & FX changes
Your copy doesn’t update itself when we fix something here.
- One email when a Swaps & FX component needs a migration
- Nothing when nothing changes
Or install it now