Pengantar
AnimatedIcon membungkus ikon dari lucide-react dan menganimasikan goresannya agar tampak digambar tangan.
Pemasangan
Pasang paket berdampingan dengan lucide-react.
terminal
npm install @utilityzoo/icons lucide-reactPersyaratan
Mulai Cepat
Impor ikon dari Lucide, teruskan ke AnimatedIcon.
tsx
"use client";
import { Heart } from "lucide-react";
import { AnimatedIcon } from "@utilityzoo/icons";
export default function LikeButton() {
return <AnimatedIcon icon={Heart} trigger="hover" />;
}Itu adalah seluruh penyiapannya.
Panduan Kerangka Kerja
Next.js (App Router)
File yang merender AnimatedIcon harus berupa komponen klien.
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
Semuanya berjalan di browser.
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} />;
}Salin file sebagai gantinya
Komponen ini hanya satu file. Salin dari GitHub. GitHub.
tsx
// Copy AnimatedIcon.tsx into your project, then import it locally:
import AnimatedIcon from "@/components/animated-icon";Pemicu
Pemicu menentukan kapan animasi dimainkan.
Playground
Pilih ikon, pilih pemicu, sesuaikan waktu.
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}
/>Referensi Props
Resep
Pola siap salin.
Catatan: ikon menangani kliknya sendiri.
Penataan Gaya
Semua prop selain animasi diteruskan ke ikon.
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" />Aksesibilitas
- Gerakan dikurangi: ikon tetap statis jika diaktifkan.
- Ikon bermakna: berikan aria-label pada tombol.
- Ikon dekoratif: tidak perlu markup tambahan.
- Perulangan: gunakan secukupnya.
Performa
- Tidak ada pustaka animasi berat yang dimuat.
- Ikon inView beranimasi hanya saat terlihat.
- Ikon loop otomatis dijeda di luar layar.
- Untuk grid besar, pilih hover atau inView.
Cara Kerja
- Ikon Anda dirender sebagai SVG normal.
- Setiap bentuk mendapat pathLength="1".
- Pola garis putus-putus menyembunyikan garis.
- Opasitas dianimasikan di awal dan akhir.
- Bentuk dimulai secara berurutan.
Penyelesaian Masalah
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.