Icon swap
Turns one icon into another in place for a control whose meaning flips: copy to copied, play to pause, menu to close.
halden.app/i/northwind-q4
Roadmap walkthroughMaya Chen · 4:12
When to use
- Toggle buttons with an icon for each state.
- A short confirmation inside an icon button.
When not to use
- Icons that change without a state change.
- Text labels; use the action swap.
Installation
terminal
pnpm dlx shadcn@latest add @caliper/icon-swap
Adds its 2 files to components/ui/, each with its own stylesheet, and installs their packages. Pro installs with your access token, set up once per project. See Pro access. The first part also adds Caliper UI’s tokens; import them once as in Installation.
API reference
IconSwap
3 props
PropTypeDefaultDescription
icon *ReactNode—
swapKey *string—Changes whenever the icon should change, e.g. "copy" and "copied".
classNamestring—
Keyboard
- No custom key handling; Tab and the native activation keys do the work.
Accessibility
It is built on native elements and keeps aria-hidden in step with state.
Notes for AI
Give your coding assistant this page as Markdown instead of screenshots: the props, keyboard and examples in one file.
/docs/components/icon-swap.mdThe index of every part is at /llms.txt.
More in Actions
Action swapA button that cycles through a few labelled states, swapping label and icon in place.Copy buttonCopies a value and confirms what was copied, with a fallback when the clipboard is blocked.ButtonA familiar action with immediate focus, a tactile press, and optional pending or label feedback that stays on the button itself.