De nouveaux outils sont arrivés ! Découvrir les nouveautés

Introduction

AnimatedIcon enveloppe une icône de lucide-react et anime ses traits pour simuler un dessin à la main.

Traits, pas de remplissage

Les icônes Lucide sont des contours.

L'astuce du tiret

Chaque ligne obtient un tiret de sa propre longueur.

Zéro dépendance

Utilise l'API Web Animations du navigateur.

Installation

Installez le package aux côtés de lucide-react.

terminal
npm install @utilityzoo/icons lucide-react

Prérequis

BesoinVersion
react18 or 19
lucide-react0.300 or newer
BrowserAny current browser (needs the Web Animations API)

Démarrage rapide

Importez une icône de Lucide, passez-la à AnimatedIcon.

tsx
"use client";

import { Heart } from "lucide-react";
import { AnimatedIcon } from "@utilityzoo/icons";

export default function LikeButton() {
  return <AnimatedIcon icon={Heart} trigger="hover" />;
}

C'est toute la configuration.

Guides de frameworks

Next.js (App Router)

Le fichier rendant AnimatedIcon doit être un composant client.

components/like-button.tsx
// 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
// 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

Tout s'exécute dans le navigateur.

tsx
// 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} />;
}

Copier le fichier à la place

Le composant tient dans un seul fichier. Copiez-le depuis GitHub. GitHub.

tsx
// Copy AnimatedIcon.tsx into your project, then import it locally:
import AnimatedIcon from "@/components/animated-icon";

Déclencheurs

Un déclencheur détermine quand l'animation se lance.

inView

The default. Draws once when scrolled into view.

tsx
<AnimatedIcon icon={Heart} />

mount

Draws once as soon as the page loads.

tsx
<AnimatedIcon icon={Rocket} trigger="mount" />

hover

Draws each time the mouse enters. Hover it.

tsx
<AnimatedIcon icon={Bell} trigger="hover" />

click

Draws on every click. Click it.

tsx
<AnimatedIcon icon={Star} trigger="click" />

toggle

One icon that erases, then draws back, on each click.

tsx
<AnimatedIcon icon={Bookmark} trigger="toggle" />

toggle + toggleIcon

Two icons: the first erases, then the second draws.

tsx
<AnimatedIcon icon={Play} toggleIcon={Pause} trigger="toggle" />

loop

Endless draw and erase. Pauses when off screen.

tsx
<AnimatedIcon icon={Zap} trigger="loop" loopDelay={1000} />

Aire de jeux

Choisissez des icônes, un déclencheur, et ajustez le minutage.

Click the icon to erase and draw (or swap with the second icon).

Color
tsx (updates as you change settings)
import { Play, Pause } from "lucide-react";
import { AnimatedIcon } from "@utilityzoo/icons";

<AnimatedIcon
  icon={Play}
  toggleIcon={Pause}
  trigger="toggle"
  size={72}
/>

Vous voulez toutes les icônes Lucide ?

Référence des props

PropTypeDéfautRôle
iconLucideIconrequiredThe Lucide icon component to animate.
trigger"inView" | "mount" | "hover" | "click" | "toggle" | "loop""inView"What starts the animation.
toggleIconLucideIconnoneSecond icon for trigger="toggle". The first erases, then this one draws.
durationnumber800Milliseconds each stroke takes.
staggernumber120Milliseconds between strokes. 0 draws them all together.
easingstring"ease-in-out"Any CSS easing, e.g. linear or cubic-bezier(...).
oncebooleantrueinView only. Animate the first time only.
replayOnClickbooleanfalseinView, mount, hover. Clicking replays the animation.
loopDelaynumber600loop only. Pause in ms between draw and erase.
size, color, strokeWidth, className…LucidePropsLucide defaultsEverything else goes straight to the icon.

Recettes

Modèles prêts à l'emploi.

Menu button

Menu turns into a close icon. Fast timing feels snappy in a navbar.

tsx
<button aria-label="Toggle menu" className="p-0">
  <AnimatedIcon
    icon={Menu} toggleIcon={X} trigger="toggle"
    duration={350} stagger={0} size={28}
  />
</button>

Play / pause

Swap two icons on click. Keep your own state in sync with onClick on the button.

tsx
<AnimatedIcon icon={Play} toggleIcon={Pause} trigger="toggle" size={32} />

Attention bell

A slow, quiet loop draws the eye without being annoying.

tsx
<AnimatedIcon icon={Bell} trigger="loop" loopDelay={2000} size={24} />

Feature card icon

Draws once as the card scrolls into view. Color comes from Tailwind.

tsx
<AnimatedIcon
  icon={Rocket} trigger="inView" size={40}
  className="text-primary" strokeWidth={1.5}
/>

Remarque : l'icône gère son propre clic.

Styles

Toutes les props hors animation sont transmises à l'icône.

tsx
<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 */}
tsx (other outline icon sets)
import { Home } from "@tabler/icons-react"; // any outline icon component
import { AnimatedIcon } from "@utilityzoo/icons";

<AnimatedIcon icon={Home} trigger="hover" />

Accessibilité

  • Mouvement réduit : les icônes restent statiques si l'option est activée.
  • Icônes significatives : ajoutez un aria-label aux boutons.
  • Icônes décoratives : aucun balisage supplémentaire requis.
  • Boucles : à utiliser avec modération.

Performance

  • Aucune bibliothèque d'animation lourde n'est chargée.
  • Les icônes inView s'animent uniquement à l'écran.
  • Les boucles se mettent en pause hors écran.
  • Pour les grandes grilles, privilégiez hover ou inView.

Comment ça marche

  1. Votre icône s'affiche sous forme de SVG normal.
  2. Chaque forme reçoit pathLength="1".
  3. Un motif en tirets masque la ligne.
  4. L'opacité s'anime au début et à la fin.
  5. Les formes se déclenchent en cascade.

Dépannage

You passed an icon from a server component. Icons are components, and components can't cross from server to client. Put the <AnimatedIcon /> usage in a file that starts with "use client" (see the Next.js guide), then import that file where you need it.

Journal des modifications

VersionTitleChanges
0.1.2Initial releaseTriggers: inView, mount, hover, click, toggle, loop. Two-icon toggle. Reduced-motion support.

Prêt à donner vie à vos icônes ?

Parcourez chaque icône Lucide, ajustez-la et copiez le code.