परिचय
AnimatedIcon lucide-react से एक आइकन को लपेटता है और उसके स्ट्रोक को एनिमेट करता है।
इंस्टालेशन
lucide-react के साथ पैकेज इंस्टॉल करें।
terminal
npm install @utilityzoo/icons lucide-reactआवश्यकताएं
त्वरित शुरुआत
Lucide से एक आइकन आयात करें, इसे AnimatedIcon में पास करें।
tsx
"use client";
import { Heart } from "lucide-react";
import { AnimatedIcon } from "@utilityzoo/icons";
export default function LikeButton() {
return <AnimatedIcon icon={Heart} trigger="hover" />;
}यह पूरा सेटअप है।
फ़्रेमवर्क गाइड
Next.js (App Router)
AnimatedIcon प्रस्तुत करने वाली फ़ाइल को एक क्लाइंट घटक होना चाहिए।
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
सब कुछ ब्राउज़र में चलता है।
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} />;
}इसके बजाय फ़ाइल कॉपी करें
घटक केवल एक फ़ाइल है। इसे GitHub से कॉपी करें। GitHub.
tsx
// Copy AnimatedIcon.tsx into your project, then import it locally:
import AnimatedIcon from "@/components/animated-icon";ट्रिगर
एक ट्रिगर तय करता है कि एनिमेशन कब चलता है।
प्लेग्राउंड
आइकन चुनें, ट्रिगर चुनें, समय सेट करें।
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}
/>प्रॉप्स संदर्भ
रेसिपी
कॉपी-पेस्ट पैटर्न।
नोट: आइकन अपने स्वयं के क्लिक को संभालता है।
स्टाइलिंग
एनिमेशन प्रॉप्स के अलावा प्रत्येक प्रॉप आइकन पर जाती है।
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" />एक्सेसिबिलिटी
- घटित गति: जब उपयोगकर्ता ने कम गति सक्षम की हो।
- सार्थक आइकन: बटन को aria-label दें।
- सजावटी आइकन: अतिरिक्त मार्कअप की आवश्यकता नहीं।
- लूप: उनका संयम से उपयोग करें।
प्रदर्शन
- कोई एनिमेशन लाइब्रेरी लोड नहीं होती।
- inView आइकन केवल तभी एनिमेट होते हैं जब वे स्क्रीन पर पहुंचते हैं।
- loop आइकन स्क्रीन से बाहर होने पर रुक जाते हैं।
- बड़े ग्रिड के लिए hover या inView को प्राथमिकता दें।
यह कैसे काम करता है
- आपका आइकन सामान्य SVG के रूप में प्रस्तुत होता है।
- प्रत्येक आकार को pathLength="1" मिलता है।
- एक डैश पैटर्न लाइन को छुपाता है।
- शुरुआत और अंत में अपारदर्शिता एनिमेट होती है।
- आकार एक के बाद एक शुरू होते हैं।
समस्या निवारण
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.