Skip to content

Icon swap

Cross-fades between two glyphs on an infrequent state change.

For a glyph that changes on an occasional action: copy to copied, star to starred. state is the key, so change it together with the child. The first render does not animate, and under reduced motion the glyphs fade without scale or blur.

Copy button

Favourite toggle

Installation

npx shadcn@latest add @khaeli/icon-swap

Install @khaeli/foundation first: this item's styling lives in its tokens and [data-slot] rules.

Installs with

npm packages
  • motion ^12.23.12

Keyboard

EnterSpace
Activate the control around the icon; the swap follows its state. IconSwap itself takes no focus.

Accessible name

  • The swap is visual only. Name the control with text or an aria-label, and keep that name the same in both states.
  • Say the new state another way: aria-pressed on a toggle, or a role="status" message such as Copied for a one-off action.

Registry JSON

The item as the shadcn CLI reads it, with every file it ships: https://ui.khaeli.com/r/icon-swap.json