Swap

Animated toggle between two icon/content states with rotate or flip transition

Category: inputs · WCAG 2.2-AA · toggle, icon, animate, switch, flip, rotate

Variants

States

Props

PropTypeDefaultDescription
onReact.ReactNodeContent shown in the active (on) state.
offReact.ReactNodeContent shown in the inactive (off) state.
checkedbooleanfalseWhether the control is checked (controlled).
onValueChange(checked: boolean) => voidCalled with the new checked state when the swap is toggled.
onChange(checked: boolean) => voidDeprecated: use onValueChange (same checked boolean).
mode'rotate' | 'flip'rotateTransition between states ('rotate' | 'flip').
aria-labelstringAccessible label used when no visible label is present.
classNamestringAdditional CSS class names merged onto the root element.

Design tokens

When to use

When not to use

How to build an accessible Swap in React →

Examples

Theme toggle (rotate)

Sun/moon icon that rotates between two states

<Swap on={<SunIcon />} off={<MoonIcon />} mode="rotate" aria-label="Toggle theme" />

Flip mode

Heart icon that flips to filled on activation

<Swap on={<HeartFilledIcon />} off={<HeartIcon />} mode="flip" aria-label="Favorite" />

Related components

← Back to docs