Charcoal UI

Token Swap

A token swap panel: type an amount and the other side fills in, the arrow spins as it swaps sides, and the button says exactly what's wrong until the trade is valid.

Examples

Token Swap

API reference

PropTypeDefaultDescription
tokens{ symbol; name; price; balance; color }[]—
onSwap({ from, to, amount, receive }) => void—
classNamestring—

About Token Swap

Token Swap is a swap widget: type an amount and the other side fills in, the arrow spins as it swaps sides, and the button says exactly what is wrong until the trade is valid.

Token Swap is an input component for React 19, styled with Tailwind CSS 4 and animated with Motion. It drops into Next.js, Vite, Remix or Astro through the shadcn CLI as a single file you own.

When to use Token Swap

  • DEX and wallet apps.
  • Currency converters.
  • Points and credit exchanges.
  • Fintech demos.

How it works

Quotes are calculated from token prices with a fee, and inputs accept only numbers. Picking the same token on both sides swaps them, and the button text changes with a short crossfade.

It is a real form control: it has an accessible name, works with the keyboard alone, shows a visible focus ring and announces its state to screen readers. With prefers-reduced-motion on, it holds still or settles instantly instead of animating.

Customizing Token Swap

Every prop is documented in the API reference above with its type and default. The ones you will reach for first are listed here.

Style it with className like any other element. It only uses your theme's tokens, so it follows light and dark mode without extra work.

  • tokens.

Goes well with Token Swap

These inputs pieces share its tokens and motion language, so they sit together on one page without clashing.

  • Magnetic: Make any React element lean toward the pointer and spring home: a magnetic hover in one wrapper
  • Color Picker: An animated React swatch colour picker with a ring that glides to the selection
  • Rating: An animated React star rating with hover preview and a ripple of popping stars
  • File Dropzone: An animated React file dropzone that lifts on hover and lists uploads with progress
  • Like Button: An animated React like button: the heart pops, sparks burst and the count rolls

Install Token Swap

npx shadcn@latest add @charcoal/token-swap

Token Swap is part of Charcoal UI Pro. One seat unlocks all 393 Pro components, 112 landing-page sections and 100 full templates, for every personal and client project, with updates included. Add the @charcoal registry once with your access token, then the command above copies token-swap.tsx into components/ui and installs clsx, tailwind-merge.

You own the file you install: no runtime package, no lock-in, nothing to keep in sync. Change it however your product needs.

See Charcoal UI Pro pricing · Pro setup

Frequently asked questions

How do I install Token Swap?
Token Swap is part of Charcoal UI Pro. Add the @charcoal registry to components.json with your access token, then run npx shadcn@latest add @charcoal/token-swap. It copies token-swap.tsx into components/ui and installs motion, clsx, tailwind-merge.
Is Token Swap free for commercial use?
Token Swap needs a Charcoal UI Pro seat, monthly or a one-time lifetime price. A seat covers unlimited personal and commercial projects, including client work, and every future Pro component.
Does Token Swap work with Next.js?
Yes. It is a client component for React 19 styled with Tailwind CSS 4, so it works in the Next.js App Router and Pages Router, Vite, Remix and Astro.
Can an AI coding agent install Token Swap?
Yes. Connect the Charcoal UI MCP server (https://charcoalui.com/mcp) to Claude Code, Cursor or any MCP client; get_component returns Token Swap's props and get_install_command returns the exact command.

Token Swap as Markdown · llms.txt