Introduction
AnimatedIcon wraps an icon from lucide-react and animates its strokes, so the icon looks like it is being drawn by hand.
Installation
Install the package next to lucide-react. Your app supplies react and lucide-react, so nothing is duplicated.
npm install @utilityzoo/icons lucide-reactRequirements
Quick start
Import an icon from Lucide, pass it to AnimatedIcon, choose a trigger.
"use client";
import { Heart } from "lucide-react";
import { AnimatedIcon } from "@utilityzoo/icons";
export default function LikeButton() {
return <AnimatedIcon icon={Heart} trigger="hover" />;
}That is the whole setup. Change trigger to control when it plays.
Framework guides
Next.js (App Router)
The file that renders AnimatedIcon must be a client component.
// components/like-button.tsx
"use client";
import { Heart } from "lucide-react";
import { AnimatedIcon } from "@utilityzoo/icons";
export function LikeButton() {
return <AnimatedIcon icon={Heart} trigger="click" color="crimson" />;
}// app/page.tsx (a server component is fine here)
import { LikeButton } from "@/components/like-button";
export default function Page() {
return <LikeButton />;
}Vite, Create React App, React Router
Everything runs in the browser, so no directive is needed.
// src/App.tsx (Vite, Create React App, React Router)
// No directive needed outside the Next.js App Router.
import { Rocket } from "lucide-react";
import { AnimatedIcon } from "@utilityzoo/icons";
export default function App() {
return <AnimatedIcon icon={Rocket} trigger="mount" size={64} />;
}Copy the file instead
Prefer no dependency? The component is one file. Copy it from GitHub. GitHub.
// Copy AnimatedIcon.tsx into your project, then import it locally:
import AnimatedIcon from "@/components/animated-icon";Triggers
A trigger decides when the animation plays.
Playground
Pick icons, choose a trigger, tune the timing.
import { Play, Pause } from "lucide-react";
import { AnimatedIcon } from "@utilityzoo/icons";
<AnimatedIcon
icon={Play}
toggleIcon={Pause}
trigger="toggle"
size={72}
/>Props reference
Recipes
Copy-paste patterns for things people build most often.
Note: the icon handles its own click.
Styling
Every prop besides the animation ones goes to the icon.
<AnimatedIcon icon={Star} className="text-amber-500" /> {/* Tailwind color */}
<AnimatedIcon icon={Star} color="#f59e0b" size={40} /> {/* explicit color and size */}
<AnimatedIcon icon={Star} strokeWidth={1.25} /> {/* thinner lines */}
<AnimatedIcon icon={Star} absoluteStrokeWidth /> {/* keep line width fixed when resizing */}import { Home } from "@tabler/icons-react"; // any outline icon component
import { AnimatedIcon } from "@utilityzoo/icons";
<AnimatedIcon icon={Home} trigger="hover" />Accessibility
- Reduced motion: when a user has reduced motion enabled, icons stay static.
- Meaningful icons: give buttons aria-labels.
- Decorative icons: no extra markup needed next to text.
- Loops: use them sparingly.
Performance
- No animation library is loaded.
- inView icons animate only when they reach the screen.
- loop icons pause automatically when off screen.
- For big grids, prefer hover or inView over loop.
How it works
- Your icon renders as a normal SVG.
- Each shape gets pathLength="1".
- A dash pattern hides the line.
- Opacity is animated at start and end.
- Shapes start one after another.