Introducción
AnimatedIcon envuelve un icono de lucide-react y anima sus trazos para que parezca dibujado a mano.
Instalación
Instala el paquete junto con lucide-react.
terminal
npm install @utilityzoo/icons lucide-reactRequisitos
Inicio rápido
Importa un icono de Lucide, pásalo a AnimatedIcon.
tsx
"use client";
import { Heart } from "lucide-react";
import { AnimatedIcon } from "@utilityzoo/icons";
export default function LikeButton() {
return <AnimatedIcon icon={Heart} trigger="hover" />;
}Esa es toda la configuración.
Guías de frameworks
Next.js (App Router)
El archivo que renderiza AnimatedIcon debe ser un componente cliente.
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
Todo se ejecuta en el navegador.
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} />;
}Copiar el archivo en su lugar
El componente es un solo archivo. Cópialo desde GitHub. GitHub.
tsx
// Copy AnimatedIcon.tsx into your project, then import it locally:
import AnimatedIcon from "@/components/animated-icon";Disparadores
Un disparador decide cuándo se reproduce la animación.
Zona de pruebas
Elige iconos, selecciona un disparador y ajusta el tiempo.
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}
/>Referencia de Props
Recetas
Patrones listos para copiar y pegar.
Nota: el icono gestiona su propio clic.
Estilos
Todas las props excepto las de animación se pasan al icono.
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" />Accesibilidad
- Movimiento reducido: los iconos permanecen estáticos.
- Iconos significativos: añade un aria-label a los botones.
- Iconos decorativos: no se requiere marcado adicional.
- Bucles: úsalos con moderación.
Rendimiento
- No se carga ninguna biblioteca de animación pesada.
- Los iconos inView solo se animan cuando son visibles.
- Los iconos en bucle se pausan automáticamente fuera de la pantalla.
- Para cuadrículas grandes, prefiere hover o inView.
Cómo funciona
- Tu icono se renderiza como un SVG normal.
- Cada forma recibe pathLength="1".
- Un patrón de guiones oculta la línea.
- La opacidad se anima al principio y al final.
- Las formas comienzan secuencialmente.
Solución de problemas
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.