Dual Animated Icon

Interactive wrapper that smoothly swaps between two icons on hover or click with fluid spring micro-interactions.

Hover and Click
1import { DualAnimatedIcon } from "@/components/dual-animated-icon";
2import { Copy } from "@/components/animate-ui/icons/copy";
3import { CheckCheck } from "@/components/animate-ui/icons/check-check";
4 
5export default function DualAnimatedIconDemo() {
6 return (
7 <div className="flex items-center gap-6">
8 {/* Click Trigger */}
9 <DualAnimatedIcon
10 iconA={Copy}
11 iconB={CheckCheck}
12 trigger="click"
13 size={20}
14 activeIconClassName="text-emerald-500"
15 />
16 
17 {/* Hover Trigger */}
18 <DualAnimatedIcon
19 iconA={Copy}
20 iconB={CheckCheck}
21 trigger="hover"
22 size={20}
23 activeIconClassName="text-emerald-500"
24 />
25 </div>
26 );
27}

Installation

Icon Compatibility & Optional Animations

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
bunx --bun shadcn@latest add https://www.ashutoshtiwari.is-a.dev/r/dual-animated-icon.json

Usage

1import { DualAnimatedIcon } from "@/components/dual-animated-icon"
1<DualAnimatedIcon iconA={Copy} iconB={CheckCheck} trigger="click" />

API Reference

PropTypeDefaultDescription
iconAReactNode | ComponentTypenull

First icon component or node rendered in the default state.

iconBReactNode | ComponentTypenull

Second icon component or node rendered in the active state.

trigger"click" | "hover" | "controlled""click"

Interaction mode that triggers swapping between the two icons.

activebooleannull

Controlled boolean state for programmatic icon switching.

onToggle(active: boolean) => voidnull

Callback fired whenever the active icon state changes.

sizenumber16

Icon width and height bounding box in pixels.

animateOnHoverbooleantrue

Whether the default icon plays its micro-animation when hovered.

transitionDurationnumber0.18

Duration of the icon swap spring transition in seconds.

as"span" | "div" | "button""span"

Underlying HTML element tag to render as.

iconClassNamestring""

Additional CSS classes applied to the default icon container.

activeIconClassNamestring""

Additional CSS classes applied to the active icon container.

classNamestring""

Additional CSS classes applied to the wrapper element.