애니메이션 컴포넌트 라이브러리
개요
이 스킬은 사전 제작된 애니메이션 React 컴포넌트 라이브러리, 특히 Magic UI와 React Bits에 대한 전문 지식을 제공합니다. 이 라이브러리들은 프로덕션에 바로 사용 가능한 애니메이션 컴포넌트를 제공하여 현대적이고 인터랙티브한 웹 애플리케이션 개발을 획기적으로 가속화합니다.
Magic UI는 Tailwind CSS와 Framer Motion 기반의 150개 이상의 TypeScript 컴포넌트를 제공하며 shadcn/ui와의 완벽한 통합을 위해 설계되었습니다. 컴포넌트는 복사하여 붙여넣기만 하면 바로 사용할 수 있고高度な 커스터마이징이 가능합니다.
React Bits는 90개 이상의 최소 의존성 애니메이션 React 컴포넌트를 제공하며 시각 효과, 배경, 마이크로 인터랙션에 중점을 둡니다. 컴포넌트는 성능과 커스터마이징 용이성을 강조합니다.
두 라이브러리 모두 최신 React 패턴을 따르고 TypeScript를 지원하며 인기 있는 디자인 시스템과 통합됩니다.
핵심 개념
Magic UI 아키텍처
Magic UI 컴포넌트는 세 가지 기반 기술로 구축됩니다:
- Tailwind CSS: 유틸리티 기반 스타일링,
tailwind.config.js를 통한 완전한 커스터마이징 - Framer Motion: 물리 기반 애니메이션 및 제스처 인식
- shadcn/ui 통합: shadcn CLI 설치 및 컴포넌트 구조 규칙 준수
설치 방법:
# shadcn CLI 사용 (권장)
npx shadcn@latest add https://magicui.design/r/animated-beam
# 수동 설치
# 1. 컴포넌트 코드를 components/ui/ 디렉토리로 복사
# 2. motion 설치: npm install motion
# 3. 필요한 CSS 애니메이션을 globals.css에 추가
# 4. cn() 유틸리티가 lib/utils.ts에 존재하는지 확인
컴포넌트 구조:
// 모든 Magic UI 컴포넌트는 다음 패턴을 따릅니다:
import { cn } from "@/lib/utils"
import { motion } from "motion/react"
interface ComponentProps extends React.ComponentPropsWithoutRef<"div"> {
customProp?: string
className?: string
}
export function MagicComponent({ className, customProp, ...props }: ComponentProps) {
return (
<motion.div
className={cn("base-styles", className)}
{...props}
>
{/* 컴포넌트 내용 */}
</motion.div>
)
}
React Bits 아키텍처
React Bits는 최소 의존성을 가진 경량의 독립형 컴포넌트를 강조합니다:
- 자체 포함: 각 컴포넌트는 최소한의 외부 의존성을 가집니다
- CSS-in-JS 선택 사항: 많은 컴포넌트가 인라인 스타일 또는 CSS 모듈을 사용합니다
- 성능 우선: 60fps 애니메이션에 최적화
- WebGL 지원: 일부 컴포넌트(Particles, Plasma)는 고급 효과를 위해 WebGL을 사용합니다
설치:
# 수동 복사-붙여넣기 (기본 방법)
# reactbits.dev에서 컴포넌트 파일을 프로젝트로 복사
# 주요 의존성 (필요시 설치):
npm install framer-motion # 애니메이션 중심 컴포넌트용
npm install ogl # WebGL 컴포넌트용 (Particles, Plasma)
컴포넌트 카테고리:
- 텍스트 애니메이션: BlurText, CircularText, CountUp, SpinningText
- 인터랙티브 요소: MagicButton, Magnet, Dock, Stepper
- 배경: Aurora, Plasma, Particles
- 목록 및 레이아웃: AnimatedList, Bento Grid
일반 패턴
1. Magic UI: 애니메이션 배경 패턴
SVG 기반 패턴으로 동적 배경 효과 생성:
import { GridPattern } from "@/components/ui/grid-pattern"
import { AnimatedGridPattern } from "@/components/ui/animated-grid-pattern"
import { cn } from "@/lib/utils"
export default function HeroSection() {
return (
<div className="relative flex h-[500px] w-full items-center justify-center overflow-hidden rounded-lg border">
{/* 정적 그리드 패턴 */}
<GridPattern
squares={[
[4, 4], [5, 1], [8, 2], [5, 3], [10, 10], [12, 15]
]}
className={cn(
"[mask-image:radial-gradient(400px_circle_at_center,white,transparent)]",
"fill-gray-400/30 stroke-gray-400/30"
)}
/>
{/* 애니메이션 인터랙티브 그리드 */}
<AnimatedGridPattern
numSquares={50}
maxOpacity={0.5}
duration={4}
repeatDelay={0.5}
className={cn(
"[mask-image:radial-gradient(500px_circle_at_center,white,transparent)]",
"inset-x-0 inset-y-[-30%] h-[200%] skew-y-12"
)}
/>
<h1 className="relative z-10 text-6xl font-bold">
여기에 내용을 입력하세요
</h1>
</div>
)
}
2. React Bits: 텍스트 나타내기 애니메이션
BlurText로 스크롤 트리거 텍스트 나타내기 구현:
import BlurText from './components/BlurText'
export default function MarketingSection() {
return (
<section className="py-20">
{/* 단어 단위로 나타내기 */}
<BlurText
text="아이디어를 현실로 바꾸세요"
delay={100}
animateBy="words"
direction="top"
className="text-5xl font-bold text-center mb-8"
/>
{/* 문자 단위로 나타내기 (커스텀 이징 적용) */}
<BlurText
text="픽셀 완벽한 애니메이션을 손쉽게"
delay={50}
animateBy="characters"
direction="bottom"
threshold={0.3}
stepDuration={0.4}
animationFrom={{ filter: 'blur(20px)', opacity: 0, y: 50 }}
animationTo={{ filter: 'blur(0px)', opacity: 1, y: 0 }}
className="text-2xl text-gray-600 text-center"
/>
</section>
)
}
3. Magic UI: 효과가 적용된 버튼 컴포넌트
반짝임 및 테두리 빔 효과가 있는 인터랙티브 버튼 생성:
import { ShimmerButton } from "@/components/ui/shimmer-button"
import { BorderBeam } from "@/components/ui/border-beam"
import { Button } from "@/components/ui/button"
import { Card } from "@/components/ui/card"
export default function CTASection() {
return (
<div className="flex gap-4 items-center">
{/* 반짝임 버튼 */}
<ShimmerButton
shimmerColor="#ffffff"
shimmerSize="0.05em"
shimmerDuration="3s"
borderRadius="100px"
background="rgba(0, 0, 0, 1)"
className="px-8 py-3"
>
시작하기
</ShimmerButton>
{/* 애니메이션 테두리가 있는 카드 */}
<Card className="relative w-[350px] overflow-hidden">
<div className="p-6">
<h3 className="text-2xl font-bold">프리미엄 플랜</h3>
<p className="text-gray-600">모든 기능 잠금 해제</p>
<Button className="mt-4">구독하기</Button>
</div>
<BorderBeam duration={8} size={100} />
</Card>
</div>
)
}
4. React Bits: 인터랙티브 Dock 내비게이션
확대 효과가 있는 macOS 스타일 Dock 구현:
import Dock from './components/Dock'
import { VscHome, VscArchive, VscAccount, VscSettingsGear } from 'react-icons/vsc'
import { useNavigate } from 'react-router-dom'
export default function AppNavigation() {
const navigate = useNavigate()
const dockItems = [
{
icon: <VscHome size={24} />,
label: '대시보드',
onClick: () => navigate('/dashboard')
},
{
icon: <VscArchive size={24} />,
label: '프로젝트',
onClick: () => navigate('/projects')
},
{
icon: <VscAccount size={24} />,
label: '프로필',
onClick: () => navigate('/profile')
},
{
icon: <VscSettingsGear size={24} />,
label: '설정',
onClick: () => navigate('/settings')
}
]
return (
<div className="fixed bottom-4 left-1/2 -translate-x-1/2">
<Dock
items={dockItems}
spring={{ mass: 0.15, stiffness: 200, damping: 15 }}
magnification={80}
distance={250}
panelHeight={70}
baseItemSize={55}
/>
</div>
)
}
5. React Bits: CountUp을 사용한 애니메이션 통계
대시보드 및 랜딩 페이지를 위한 애니메이션 숫자 표시:
import CountUp from './components/CountUp'
export default function Statistics() {
return (
<div className="grid grid-cols-1 md:grid-cols-3 gap-8 py-16">
{/* 수익 카운터 */}
<div className="stat-card text-center">
<CountUp
start={0}
end={1000000}
duration={3}
separator=","
prefix="$"
className="text-6xl font-bold text-blue-600"
/>
<p className="text-xl text-gray-600 mt-2">생성된 수익</p>
</div>
{/* 가동률 백분율 */}
<div className="stat-card text-center">
<CountUp
end={99.9}
duration={2.5}
decimals={1}
suffix="%"
className="text-6xl font-bold text-green-600"
/>
<p className="text-xl text-gray-600 mt-2">가동률</p>
</div>
{/* 고객 수 */}
<div className="stat-card text-center">
<CountUp
end={10000}
duration={2}
separator=","
className="text-6xl font-bold text-purple-600"
/>
<p className="text-xl text-gray-600 mt-2">행복한 고객</p>
</div>
</div>
)
}
6. Magic UI: 무한 스크롤을 위한 Marquee 컴포넌트
무한 스크롤 콘텐츠 표시 생성:
import { Marquee } from "@/components/ui/marquee"
const testimonials = [
{ name: "홍길동", text: "훌륭한 제품입니다!", avatar: "/avatar1.jpg" },
{ name: "김영희", text: "기대 이상이었어요", avatar: "/avatar2.jpg" },
{ name: "이철수", text: "강력 추천합니다", avatar: "/avatar3.jpg" }
]
export default function Testimonials() {
return (
<section className="py-20">
<h2 className="text-4xl font-bold text-center mb-12">
고객 후기
</h2>
{/* 가로 Marquee */}
<Marquee pauseOnHover className="[--duration:40s]">
{testimonials.map((item, idx) => (
<div key={idx} className="mx-4 w-[350px] rounded-lg border p-6">
<p className="text-lg mb-4">"{item.text}"</p>
<div className="flex items-center gap-3">
<img src={item.avatar} alt={item.name} className="w-10 h-10 rounded-full" />
<p className="font-semibold">{item.name}</p>
</div>
</div>
))}
</Marquee>
{/* 세로 Marquee */}
<Marquee vertical reverse className="h-[400px] mt-8">
{testimonials.map((item, idx) => (
<div key={idx} className="my-4 w-full max-w-md rounded-lg border p-6">
<p>{item.text}</p>
</div>
))}
</Marquee>
</section>
)
}
7. React Bits: WebGL 배경 효과
고성능 애니메이션 배경 추가:
import Particles from './components/Particles'
import Plasma from './components/Plasma'
import Aurora from './components/Aurora'
// Particles 효과
export default function ParticlesHero() {
return (
<section style={{ position: 'relative', height: '100vh' }}>
<Particles
particleCount={200}
particleColors={['#FF6B6B', '#4ECDC4', '#45B7D1']}
particleSpread={10}
speed={0.12}
moveParticlesOnHover={true}
particleHoverFactor={2}
particleBaseSize={100}
sizeRandomness={1.2}
alphaParticles={true}
cameraDistance={20}
className="particles-bg"
/>
<div className="relative z-10 flex items-center justify-center h-full">
<h1 className="text-7xl font-bold text-white">
미래에 오신 것을 환영합니다
</h1>
</div>
</section>
)
}
// Plasma 효과
export default function PlasmaBackground() {
return (
<div className="relative min-h-screen">
<Plasma
color1="#FF0080"
color2="#7928CA"
color3="#00DFD8"
speed={0.8}
blur={30}
className="plasma-bg"
/>
<div className="relative z-10 p-8">
<h1>Plasma 배경이 있는 콘텐츠</h1>
</div>
</div>
)
}
// Aurora 효과
export default function AuroraHero() {
return (
<div className="relative min-h-screen">
<Aurora
colors={['#FF00FF', '#00FFFF', '#FFFF00']}
speed={0.5}
blur={80}
/>
<main className="relative z-10">
<h1>Cyberpunk 오로라 효과</h1>
</main>
</div>
)
}
통합 패턴
shadcn/ui와의 통합
Magic UI 컴포넌트는 shadcn/ui와 완벽하게 작동하도록 설계되었습니다:
# shadcn/ui 컴포넌트 설치
npx shadcn@latest add button card
# Magic UI 컴포넌트 설치
npx shadcn@latest add https://magicui.design/r/shimmer-button
# 컴포넌트에서 함께 사용
import { Button } from "@/components/ui/button"
import { Card } from "@/components/ui/card"
import { ShimmerButton } from "@/components/ui/shimmer-button"
import { BorderBeam } from "@/components/ui/border-beam"
필수 유틸리티 함수 (lib/utils.ts):
import clsx, { ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
Framer Motion과의 통합
두 라이브러리 모두 애니메이션에 Framer Motion을 활용합니다:
import { motion } from "framer-motion"
import { Magnet } from './components/Magnet'
// React Bits Magnet과 Framer Motion 제스처 결합
export default function InteractiveCard() {
return (
<Magnet magnitude={0.4} maxDistance={180}>
<motion.div
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
className="card p-6 rounded-xl shadow-lg"
>
<h3>인터랙티브 카드</h3>
<p>자석 효과와 스케일 애니메이션 결합</p>
</motion.div>
</Magnet>
)
}
React Router와의 통합
애니메이션 컴포넌트와 라우팅 결합:
import { AnimatePresence, motion } from "framer-motion"
import { useLocation, Routes, Route } from "react-router-dom"
import { Dock } from './components/Dock'
export default function App() {
const location = useLocation()
return (
<>
{/* 애니메이션 페이지 전환 */}
<AnimatePresence mode="wait">
<Routes location={location} key={location.pathname}>
<Route path="/" element={
<motion.div
initial={{ opacity: 0, y: 20 }}
animate={{ opacity: 1, y: 0 }}
exit={{ opacity: 0, y: -20 }}
transition={{ duration: 0.3 }}
>
<h1>홈페이지</h1>
</motion.div>
} />
<Route path="/about" element={
<motion.div
initial={{ opacity: 0, x: -100 }}
animate={{ opacity: 1, x: 0 }}
exit={{ opacity: 0, x: 100 }}
transition={{ duration: 0.3 }}
>
<h1>회사 소개</h1>
</motion.div>
} />
</Routes>
</AnimatePresence>
{/* 하단 Dock 내비게이션 */}
<Dock
items={[
{ icon: <span>🏠</span>, label: '홈', onClick: () => navigate('/') },
{ icon: <span>ℹ️</span>, label: '소개', onClick: () => navigate('/about') },
]}
magnification={70}
distance={200}
panelHeight={60}
baseItemSize={50}
/>
</>
)
}
Next.js와의 통합
서버 사이드 렌더링을 위해 두 라이브러리 모두 Next.js와 호환됩니다:
// app/components/hero.tsx (Next.js App Router)
"use client" // Magic UI 및 React Bits는 클라이언트 컴포넌트가 필요합니다
import { ShimmerButton } from "@/components/ui/shimmer-button"
import { AnimatedGridPattern } from "@/components/ui/animated-grid-pattern"
export default function Hero() {
return (
<section className="relative h-screen flex items-center justify-center">
<AnimatedGridPattern />
<div className="relative z-10 text-center">
<h1 className="text-6xl font-bold mb-6">Next.js로 구축</h1>
<ShimmerButton>시작하기</ShimmerButton>
</div>
</section>
)
}
모범 사례
- 성능 최적화: 애니메이션에서는
motion.div를, 정적 콘텐츠에서는 일반div를 사용하세요. - 일관된 스타일링: Tailwind 클래스를 결합하려면 cn() 유틸리티를 사용하세요.
- 컴포넌트 분리: 재사용을 위해 복잡한 애니메이션을 별도의 컴포넌트로 분리하세요.
- 접근성: 색상 대비와 포커스 관리를 유지하세요. 애니메이션에
prefers-reduced-motion미디어 쿼리를 추가하세요. - Tree Shaking: 번들 크기를 최소화하기 위해 개별 컴포넌트만 가져오세요.
- 타입 안전성: 컴포넌트 props에 TypeScript 인터페이스를 사용하세요.
- 반응형 디자인: 모바일 퍼스트 접근 방식으로 Tailwind 중단점 변형을 사용하세요.
문제 해결
| 문제 | 해결책 |
|---|---|
| 컴포넌트가 표시되지 않음 | 종속성이 설치되었고 패키지가 올바르게 가져왔는지 확인 |
| 애니메이션이 작동하지 않음 | 컴포넌트에 "use client" 지시어가 추가되었는지 확인 |
| TypeScript 오류 | 필요한 타입 정의가 설치되었는지 확인 (@types/...) |
| 스타일 충돌 | cn() 유틸리티를 사용하거나 Tailwind 구성에서 important 옵션을 활성화 |