소개
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 아이콘은 화면을 벗어나면 자동으로 일시 중지됩니다.
- 큰 그리드에서는 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.