Interactive wrapper that smoothly swaps between two icons on hover or click with fluid spring micro-interactions.
DualAnimatedIcon is a lightweight transition wrapper that smoothly swaps between any two icons (Lucide, Hugeicons, Phosphor, Radix, etc.). If you want the icons themselves to play interactive stroke micro-animations on hover (like the Copy icon in the demo above), you can use animated icons from @animate-ui/react.
npm i @animate-ui/react| Prop | Type | Default | Description |
|---|---|---|---|
iconA | ReactNode | ComponentType | null | First icon component or node rendered in the default state. |
iconB | ReactNode | ComponentType | null | Second icon component or node rendered in the active state. |
trigger | "click" | "hover" | "controlled" | "click" | Interaction mode that triggers swapping between the two icons. |
active | boolean | null | Controlled boolean state for programmatic icon switching. |
onToggle | (active: boolean) => void | null | Callback fired whenever the active icon state changes. |
size | number | 16 | Icon width and height bounding box in pixels. |
animateOnHover | boolean | true | Whether the default icon plays its micro-animation when hovered. |
transitionDuration | number | 0.18 | Duration of the icon swap spring transition in seconds. |
as | "span" | "div" | "button" | "span" | Underlying HTML element tag to render as. |
iconClassName | string | "" | Additional CSS classes applied to the default icon container. |
activeIconClassName | string | "" | Additional CSS classes applied to the active icon container. |
className | string | "" | Additional CSS classes applied to the wrapper element. |