mcpField
A
animated-component-libraries

animated-component-libraries

github.com/freshtechbroデザイン・UI1.2k2.9k 回インストール49 週間前に更新
リポジトリ

animated-component-libraries について

Magic UI と React Bits のアニメーションコンポーネントを扱う React 開発者向けのスキルです。インストール、カスタマイズ、連携、パフォーマンス対策、問題解決を解説します。

主な機能

  1. 01Magic UI コンポーネントの導入と調整
  2. 02React Bits の利用パターン
  3. 03背景やテキストのアニメーション
  4. 04shadcn/ui との連携
  5. 05パフォーマンス対策と問題解決

活用シーン

  1. 01マーケティングページにテキスト演出を追加
  2. 02アニメーション背景付きのホームページを作成
  3. 03ダッシュボードに動く統計値を表示

インストール

コマンドをコピーしてターミナルで実行します。

$npx skills add https://github.com/freshtechbro/claudedesignskills --skill animated-component-libraries

インストール後、Claude Code で/animated-component-librariesを入力して読み込まれたか確認します。

同梱ファイル

SKILL.md と一緒にインストールされる参考資料やスクリプト。

assets/
README.md
references/
customization_guide.md
magic_ui_components.md
react_bits_components.md
scripts/
component_importer.py
props_generator.py

詳細

アニメーション付きコンポーネントライブラリ

概要

このスキルでは、事前構築されたアニメーション付きReactコンポーネントライブラリ、特にMagic UIとReact Bitsに関する知識を提供します。これらのライブラリには、本番環境ですぐに使えるアニメーション付きコンポーネントが用意されており、モダンでインタラクティブなWebアプリケーションの開発を大幅に加速できます。

Magic UIには、Tailwind CSSとFramer Motionを基盤とする150種類以上のTypeScriptコンポーネントがあり、shadcn/uiとシームレスに統合できるよう設計されています。コンポーネントはコピー&ペーストですぐに使用でき、高度にカスタマイズできます。

React Bitsには、依存関係を最小限に抑えた90種類以上のアニメーション付きReactコンポーネントがあり、視覚効果、背景、マイクロインタラクションに重点を置いています。パフォーマンスとカスタマイズのしやすさを重視したコンポーネントです。

どちらのライブラリもモダンなReactのパターンに従い、TypeScriptをサポートし、一般的なデザインシステムと統合できます。

コアコンセプト

Magic UIのアーキテクチャ

Magic UIのコンポーネントは、次の3つの基盤技術を使用して構築されています。

  1. Tailwind CSS:ユーティリティファーストのスタイリング。tailwind.config.jsを使って全面的にカスタマイズできます
  2. Framer Motion:物理法則に基づくアニメーションとジェスチャー認識
  3. shadcn/uiとの統合:CLIによるインストールとコンポーネント構造に、shadcnの規約を採用しています

インストール方法:

# Via shadcn CLI (recommended)
npx shadcn@latest add https://magicui.design/r/animated-beam

# Manual installation
# 1. Copy component code to components/ui/
# 2. Install motion: npm install motion
# 3. Add required CSS animations to globals.css
# 4. Ensure cn() utility exists in lib/utils.ts

コンポーネントの構造:

// All Magic UI components follow this pattern:
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}
    >
      {/* Component content */}
    </motion.div>
  )
}
React Bitsのアーキテクチャ

React Bitsは、依存関係を最小限に抑えた軽量で独立性の高いコンポーネントを重視しています。

  1. 自己完結型:各コンポーネントの外部依存関係は最小限です
  2. CSS-in-JSは任意:多くのコンポーネントはインラインスタイルまたはCSSモジュールを使用します
  3. パフォーマンス優先:60fpsのアニメーション向けに最適化されています
  4. WebGLのサポート:一部のコンポーネント(Particles、Plasma)は高度なエフェクトにWebGLを使用します

インストール:

# Manual copy-paste (primary method)
# Copy component files from reactbits.dev to your project

# Key dependencies (install as needed):
npm install framer-motion  # For animation-heavy components
npm install ogl           # For WebGL components (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">
      {/* Static Grid Pattern */}
      <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"
        )}
      />

      {/* Animated Interactive Grid */}
      <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">
        Your Content Here
      </h1>
    </div>
  )
}
2. React Bits:テキストの表示アニメーション

BlurTextを使って、スクロールをトリガーとするテキストの表示アニメーションを実装します。

import BlurText from './components/BlurText'

export default function MarketingSection() {
  return (
    <section className="py-20">
      {/* Word-by-word reveal */}
      <BlurText
        text="Transform your ideas into reality"
        delay={100}
        animateBy="words"
        direction="top"
        className="text-5xl font-bold text-center mb-8"
      />

      {/* Character-by-character reveal with custom easing */}
      <BlurText
        text="Pixel-perfect animations at your fingertips"
        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">
      {/* Shimmer Button */}
      <ShimmerButton
        shimmerColor="#ffffff"
        shimmerSize="0.05em"
        shimmerDuration="3s"
        borderRadius="100px"
        background="rgba(0, 0, 0, 1)"
        className="px-8 py-3"
      >
        Get Started
      </ShimmerButton>

      {/* Card with Animated Border */}
      <Card className="relative w-[350px] overflow-hidden">
        <div className="p-6">
          <h3 className="text-2xl font-bold">Premium Plan</h3>
          <p className="text-gray-600">Unlock all features</p>
          <Button className="mt-4">Subscribe</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: 'Dashboard',
      onClick: () => navigate('/dashboard')
    },
    {
      icon: <VscArchive size={24} />,
      label: 'Projects',
      onClick: () => navigate('/projects')
    },
    {
      icon: <VscAccount size={24} />,
      label: 'Profile',
      onClick: () => navigate('/profile')
    },
    {
      icon: <VscSettingsGear size={24} />,
      label: 'Settings',
      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">
      {/* Revenue Counter */}
      <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">Revenue Generated</p>
      </div>

      {/* Uptime Percentage */}
      <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">Uptime</p>
      </div>

      {/* Customer Count */}
      <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">Happy Customers</p>
      </div>
    </div>
  )
}
6. Magic UI:無限スクロール用Marqueeコンポーネント

無限スクロールするコンテンツ表示を作成します。

import { Marquee } from "@/components/ui/marquee"

const testimonials = [
  { name: "John Doe", text: "Amazing product!", avatar: "/avatar1.jpg" },
  { name: "Jane Smith", text: "Exceeded expectations", avatar: "/avatar2.jpg" },
  { name: "Bob Johnson", text: "Highly recommend", avatar: "/avatar3.jpg" }
]

export default function Testimonials() {
  return (
    <section className="py-20">
      <h2 className="text-4xl font-bold text-center mb-12">
        What Our Customers Say
      </h2>

      {/* Horizontal 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>

      {/* Vertical 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 Effect
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">
          Welcome to the Future
        </h1>
      </div>
    </section>
  )
}

// Plasma Effect
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>Content with Plasma Background</h1>
      </div>
    </div>
  )
}

// Aurora Effect
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 Aurora Effect</h1>
      </main>
    </div>
  )
}

統合パターン

shadcn/uiとの統合

Magic UIのコンポーネントは、shadcn/uiとシームレスに連携するよう設計されています。

# Install shadcn/ui component
npx shadcn@latest add button card

# Install Magic UI component
npx shadcn@latest add https://magicui.design/r/shimmer-button

# Use together in components
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'

// Combine React Bits Magnet with Framer Motion gestures
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>Interactive Card</h3>
        <p>Combines magnetic pull with scale animation</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 (
    <>
      {/* Animated Page Transitions */}
      <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 }}
            >
              <HomePage />
            </motion.div>
          } />
        </Routes>
      </AnimatePresence>

      {/* Persistent Dock Navigation */}
      <Dock items={navItems} />
    </>
  )
}
Magic UIとReact Bitsの組み合わせ

1つのプロジェクトで、両方のライブラリの強みを活用します。

// Magic UI: Patterns and structural components
import { GridPattern } from "@/components/ui/grid-pattern"
import { BorderBeam } from "@/components/ui/border-beam"
import { Marquee } from "@/components/ui/marquee"

// React Bits: Interactive elements and effects
import BlurText from './components/BlurText'
import CountUp from './components/CountUp'
import Particles from './components/Particles'

export default function LandingPage() {
  return (
    <main>
      {/* Hero with React Bits background + Magic UI pattern */}
      <section className="relative h-screen">
        <Particles particleCount={150} />
        <GridPattern
          squares={[[4,4], [8,2], [12,6]]}
          className="opacity-30"
        />
        <BlurText
          text="Next-Generation Platform"
          className="text-7xl font-bold"
        />
      </section>

      {/* Stats with React Bits CountUp */}
      <section>
        <CountUp end={10000} suffix="+" />
      </section>

      {/* Testimonials with Magic UI Marquee */}
      <section>
        <Marquee>
          {/* Testimonial cards */}
        </Marquee>
      </section>
    </main>
  )
}

パフォーマンスの最適化

Magic UIのパフォーマンスに関するヒント
  1. クリッピングではなくCSSマスクを使用する:大きなパターンでより高いパフォーマンスを得られます
<GridPattern
  className="[mask-image:radial-gradient(400px_circle_at_center,white,transparent)]"
/>
  1. アニメーションの複雑さを抑える:モバイルではAnimatedGridPatternのnumSquaresを小さくします
const isMobile = window.innerWidth < 768
<AnimatedGridPattern
  numSquares={isMobile ? 20 : 50}
  duration={isMobile ? 6 : 4}
/>
  1. コンポーネントを遅延読み込みする:重いコンポーネントにはReact.lazyを使用します
const AnimatedGridPattern = React.lazy(() =>
  import("@/components/ui/animated-grid-pattern")
)
React Bitsのパフォーマンスに関するヒント
  1. WebGLコンポーネント:ローエンドデバイスではパーティクル数を減らします
const particleCount = navigator.hardwareConcurrency > 4 ? 300 : 150

<Particles
  particleCount={particleCount}
  speed={0.1}
/>
  1. 視差効果を減らす設定が有効な場合はアニメーションを無効にする:
const prefersReducedMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches

<BlurText
  text="Accessible text"
  delay={prefersReducedMotion ? 0 : 100}
  animateBy={prefersReducedMotion ? "none" : "words"}
/>
  1. Marqueeのコンテンツを最適化する:パフォーマンス向上のため、アイテム数を制限します
<Marquee repeat={2}> {/* Instead of default 4 */}
  {items.slice(0, 10)} {/* Limit items */}
</Marquee>
  1. 重要度の低いアニメーションにはRequestIdleCallbackを使用する:
useEffect(() => {
  if ('requestIdleCallback' in window) {
    requestIdleCallback(() => {
      // Initialize expensive animations
    })
  }
}, [])

よくある落とし穴

1. 依存関係の不足

問題:motion またはユーティリティ関数が不足しているため、コンポーネントが動作しません。

解決策:必要な依存関係とユーティリティを必ずインストールしてください。

# Magic UI requirements
npm install motion clsx tailwind-merge

# React Bits WebGL components
npm install ogl

# Ensure cn() utility exists
// lib/utils.ts
import clsx, { ClassValue } from "clsx"
import { twMerge } from "tailwind-merge"

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs))
}
2. CSS アニメーションが適用されない

問題:手動でインストールした後、Magic UI のアニメーションが動作しません。

解決策:必要な CSS アニメーションを globals.css に追加してください。

/* app/globals.css */
@theme inline {
  --animate-ripple: ripple var(--duration, 2s) ease calc(var(--i, 0) * 0.2s) infinite;
  --animate-shimmer-slide: shimmer-slide var(--speed) ease-in-out infinite alternate;
  --animate-marquee: marquee var(--duration) linear infinite;
  --animate-marquee-vertical: marquee-vertical var(--duration) linear infinite;
}

@keyframes ripple {
  0%, 100% { transform: translate(-50%, -50%) scale(1); }
  50% { transform: translate(-50%, -50%) scale(0.9); }
}

@keyframes shimmer-slide {
  to { transform: translate(calc(100cqw - 100%), 0); }
}

@keyframes marquee {
  from { transform: translateX(0); }
  to { transform: translateX(calc(-100% - var(--gap))); }
}

@keyframes marquee-vertical {
  from { transform: translateY(0); }
  to { transform: translateY(calc(-100% - var(--gap))); }
}
3. Z-index の競合

問題:背景パターンやエフェクトが前景のコンテンツを覆ってしまいます。

解決策:適切な Z-index のレイヤリングを使用してください。

<div className="relative">
  {/* Background (z-0 or negative) */}
  <GridPattern className="absolute inset-0 -z-10" />

  {/* Content (higher z-index) */}
  <div className="relative z-10">
    <h1>Content appears above pattern</h1>
  </div>
</div>
4. 複数のアニメーションコンポーネントによるパフォーマンスの問題

問題:負荷の高いアニメーションを複数同時に実行すると、ページの動作が遅くなります。

解決策:プログレッシブエンハンスメントと条件付きレンダリングを実装してください。

import { useState, useEffect } from 'react'

export default function OptimizedPage() {
  const [enableHeavyEffects, setEnableHeavyEffects] = useState(false)

  useEffect(() => {
    // Check device capability
    const isHighEnd = navigator.hardwareConcurrency > 4 &&
                     !navigator.userAgent.includes('Mobile')
    setEnableHeavyEffects(isHighEnd)
  }, [])

  return (
    <section className="relative">
      {enableHeavyEffects ? (
        <Particles particleCount={300} />
      ) : (
        <GridPattern /> {/* Lighter alternative */}
      )}

      <div className="content">
        {/* Page content */}
      </div>
    </section>
  )
}
5. TypeScript の型エラー

問題:TypeScript がコンポーネントの props についてエラーを報告します。

解決策:適切な基本型を拡張してください。

// Magic UI pattern
interface CustomComponentProps extends React.ComponentPropsWithoutRef<"div"> {
  customProp?: string
  className?: string
}

// React Bits pattern
interface CustomProps extends React.HTMLAttributes<HTMLDivElement> {
  customProp?: string
}
6. Tailwind のクラスが適用されない

問題:Magic UI コンポーネントのカスタム Tailwind クラスが動作しません。

解決策:コンテンツパスにコンポーネントのディレクトリが含まれていることを確認してください。

// tailwind.config.js
module.exports = {
  content: [
    "./src/**/*.{js,jsx,ts,tsx}",
    "./components/**/*.{js,jsx,ts,tsx}", // Include components directory
  ],
  theme: {
    extend: {},
  },
  plugins: [],
}

リソース

公式ドキュメント
主なスクリプト
  • scripts/component_importer.py - 両方のライブラリからコンポーネントをインポートしてカスタマイズします
  • scripts/props_generator.py - コンポーネントの prop 設定を生成します
リファレンス
  • references/magic_ui_components.md - 使用例を含む Magic UI コンポーネントの完全なカタログ
  • references/react_bits_components.md - React Bits コンポーネントライブラリのリファレンス
  • references/customization_guide.md - 両ライブラリの prop ベースのカスタマイズパターン
スターターアセット
  • assets/component_showcase/ - すべてのコンポーネントを紹介するインタラクティブなデモ
  • assets/examples/ - ランディングページのセクション、ダッシュボードのウィジェット、マイクロインタラクション

関連スキル

  • motion-framer:両ライブラリで使用されている基礎的なアニメーションの概念を理解するためのスキル
  • gsap-scrolltrigger:スクロール駆動型アニメーションの代替アプローチ
  • react-spring-physics:物理ベースのアニメーションライブラリの代替
  • threejs-webgl:Particles/Plasma の代替となる 3D 背景エフェクト

コメント