Communitygithub.com

503496348-ops/mischief-production

React / Next.js 向けの本番対応アニメーションパターン集 — ボタン、モーダル、トースト、スタッガー、ページトランジション、終了アニメーション、スクロール、レイアウト — motion-foundations トークンとスプリングを基盤に構築。

mischief-production とは?

このスキルは、React および Next.js アプリケーションで一般的な UI アニメーションを実装するための、コピー&ペースト可能なパターンを提供します。すべてのパターンは `motion-foundations` のトークンとスプリングに基づいており、ハードコードされた数値や新しいイージング値は使用しません。 サポートするアニメーションには、ボタンフィードバック、カード、モーダル、トースト通知、リストのスタッガー表示、Next.js App Router のページトランジション、条件付きコンテンツの出現・終了、スクロールリビール、スクロール連動プログレス、レイアウトアニメーションなどが含まれます。 スキルの原則として、条件付きレンダリングは常に `AnimatePresence` と `key` でラップし、enter と exit の両方を定義します。また、モーダルにはフォーカストラップ、Escape キー閉じ、スクロールロック、`role="dialog"`、 `aria-modal="true"` を必須とし、アクセシビリティと SSR の安全性を確保します。 これらのパターンは、Cursor、Claude Code、Codex などの AI エージェントが、プロジェクトのアニメーション要件に応じて適切なパターンを選択・生成するための明確な判断基準とコード例を提供します。

対応~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/503496348-ops/mischief-production/tree/HEAD/skills/ecc-motion-patterns

お気に入りのAIに質問する

このエージェントスキルを事前に読み込んだ状態で新しいチャットを開きます。

ドキュメント

モーションパターン

最も一般的なUIアニメーションのニーズに対応するコピー&ペーストパターン。 ここにあるすべてのパターンは motion-foundations トークンとスプリングに基づいています。 新しいdurationやeasingの値はここで定義せず、インポートしてください。

いつアクティブにするか

  • ボタン、カード、モーダル、トースト通知のアニメーション
  • スタガーを使ったリストの登場アニメーション
  • Next.js App Routerでのページ遷移の設定
  • 条件付きコンテンツへの登場・退場アニメーションの追加
  • スクロールリビール、スクロール連動プログレス、スティッキーストーリーセクションの実装
  • 展開カード、アコーディオン、共有要素トランジションの構築

出力

このスキルは以下を生成します:

  • アクセシブルでSSRセーフな、すべての標準UIコンポーネントのアニメーション
  • 正しいexit動作を伴うAnimatePresenceでラップされた条件付きレンダー
  • Next.js App Router用のページ遷移ラッパーコンポーネント
  • useScroll + useTransformを使用したスクロールリビールとスクロール連動パターン
  • 展開やクロスフェード要素のためのレイアウトアニメーションパターン(layout、layoutId)

原則

  • すべてのパターンはmotion-foundationsからインポートする。生の数値は使用しない。
  • すべての条件付きレンダーは、keyを指定してAnimatePresenceでラップする。
  • 退場アニメーションは常に登場アニメーションと一緒に定義する。後付けにしてはならない。
  • layoutは小規模で独立した移動にのみ使用する。大きなサブツリーには明示的なtransformを使用する。

ルール

  1. 条件付きレンダーは常に、直接の子要素にkeyを指定してAnimatePresenceでラップする。キーがないと、exitアニメーションは決して実行されません。
  2. initial + animateを定義するときは必ずexitも定義する。exitのないアニメーションは不完全です。
  3. ページ遷移にはmode="wait"を使用する。exitが完了するまでenterを開始してはいけません。
  4. 子要素が約5つ以上、またはDOMが深くネストされているサブツリーにはlayoutを使用しない。代わりに明示的なx/y transformを使用してください。
  5. スタガーの間隔は0.05sから0.10sの間にする。これより短いと機械的に、長いと緩慢に感じられます。
  6. モーダルには常に以下を含める:フォーカストラップ、Escapeキーでの閉じる、スクロールロック、role="dialog"、aria-modal="true"。
  7. スクロールリビールではviewport={{ once: true }}を使用する。スクロールアウト時に繰り返すのは、情報的でなく、気が散ります。
  8. すべてのトークン値はmotion-foundationsからインポートする。インラインの数値は使用しない。

判断ガイダンス

適切なパターンの選択

状況パターン
要素の表示/非表示AnimatePresence
アイテムが順に読み込まれるリストスタガーバリアント
ルート間の移動ページ遷移ラッパー
要素がその場でサイズ変更layout プロパティ
同じ要素がページコンテキスト間を移動layoutId
スクロールして表示されたときに要素が入るwhileInView
スクロール位置に連動する値useScroll + useTransform

mode="wait" と mode="sync" の使い分け

モード使用する状況
waitページ遷移、コンテンツの入れ替え(一度に1つ)
sync積み重なった通知、リストアイテム(オーバーラップ可)
popLayoutリフローリストからアイテムが削除される場合

コアコンセプト

AnimatePresence の契約

3つのことが常に真でなければなりません:

  1. AnimatePresenceが条件付きをラップしている
  2. 直接の子要素にkeyがある
  3. 子要素にexitプロパティがある

これらのいずれかが欠けると、exitアニメーションは静かに失敗します。

layout と layoutId

  • layout — その場で要素自身のサイズ/位置の変化をアニメーション化します
  • layoutId — 2つの別々の要素をリンクし、レンダー間でそれらをクロスフェードします

展開するコンテナ内のテキストに対してlayout="position"を使用すると、テキストのリフローがアニメーション化されるのを防ぎます。

コード例

ボタンフィードバック

"use client"
import { motion } from "motion/react"
import { springs, motionTokens } from "@/lib/motion-tokens"

<motion.button
  whileHover={{ scale: motionTokens.scale.pop }}
  whileTap={{ scale: motionTokens.scale.press }}
  transition={springs.snappy}
/>

スタガーリスト

"use client"
import { motion } from "motion/react"
import { motionTokens, springs } from "@/lib/motion-tokens"

const container = {
  hidden: {},
  visible: {
    transition: {
      staggerChildren: 0.08,   // 0.05–0.10 ルール内
      delayChildren: 0.1,
    },
  },
}

const item = {
  hidden:  { opacity: 0, y: motionTokens.distance.md },
  visible: { opacity: 1, y: 0, transition: springs.gentle },
}

<motion.ul variants={container} initial="hidden" animate="visible">
  {items.map((i) => (
    <motion.li key={i.id} variants={item} />
  ))}
</motion.ul>

モーダル

"use client"
import { motion, AnimatePresence } from "motion/react"
import { motionTokens, springs } from "@/lib/motion-tokens"

// 呼び出し側でラップ:
// <AnimatePresence>{isOpen && <Modal key="modal" />}</AnimatePresence>

export function Modal({ onClose }: { onClose: () => void }) {
  return (
    <>
      {/* オーバーレイ */}
      <motion.div
        className="fixed inset-0 bg-black/50"
        initial={{ opacity: 0 }}
        animate={{ opacity: 1 }}
        exit={{ opacity: 0 }}
        onClick={onClose}
      />

      {/* パネル — アクセシビリティ要件: フォーカストラップ、Escapeで閉じる、
          スクロールロック、role="dialog"、aria-modal="true" */}
      <motion.div
        role="dialog"
        aria-modal="true"
        className="fixed inset-x-4 top-1/2 -translate-y-1/2 rounded-xl bg-white p-6"
        initial={{
          opacity: 0,
          scale: motionTokens.scale.press,
          y: motionTokens.distance.sm,
        }}
        animate={{ opacity: 1, scale: 1, y: 0 }}
        exit={{
          opacity: 0,
          scale: motionTokens.scale.press,
          y: motionTokens.distance.sm,
        }}
        transition={springs.gentle}
      />
    </>
  )
}

トーストスタック

"use client"
import { motion, AnimatePresence } from "motion/react"
import { motionTokens, springs } from "@/lib/motion-tokens"

<AnimatePresence mode="sync">
  {toasts.map((t) => (
    <motion.div
      key={t.id}
      layout
      initial={{
        opacity: 0,
        x: motionTokens.distance.xl,
        scale: motionTokens.scale.subtle,
      }}
      animate={{ opacity: 1, x: 0, scale: 1 }}
      exit={{
        opacity: 0,
        x: motionTokens.distance.xl,
        scale: motionTokens.scale.subtle,
      }}
      transition={springs.snappy}
    />
  ))}
</AnimatePresence>

ページ遷移 (Next.js App Router)

// components/page-transition.tsx
"use client"
import { motion, AnimatePresence } from "motion/react"
import { usePathname } from "next/navigation"
import { motionTokens } from "@/lib/motion-tokens"

const variants = {
  initial: { opacity: 0, y: motionTokens.distance.sm },
  enter:   { opacity: 1, y: 0 },
  exit:    { opacity: 0, y: -motionTokens.distance.sm },
}

export function PageTransition({ children }: { children: React.ReactNode }) {
  const pathname = usePathname()
  return (
    <AnimatePresence mode="wait">
      <motion.div
        key={pathname}
        variants={variants}
        initial="initial"
        animate="enter"
        exit="exit"
        transition={{
          duration: motionTokens.duration.normal,
          ease: motionTokens.easing.smooth,
        }}
      >
        {children}
      </motion.div>
    </AnimatePresence>
  )
}

スクロールリビール

"use client"
import { motion } from "motion/react"
import { motionTokens, springs } from "@/lib/motion-tokens"

<motion.div
  initial={{ opacity: 0, y: motionTokens.distance.lg }}
  whileInView={{ opacity: 1, y: 0 }}
  viewport={{ once: true, margin: "-80px" }}   // once: true — ルール7
  transition={{ duration: motionTokens.duration.slow, ease: motionTokens.easing.smooth }}
/>

スクロールプログレスバー

"use client"
import { motion, useScroll } from "motion/react"

export function ScrollProgress() {
  const { scrollYProgress } = useScroll()
  return (
    <motion.div
      className="fixed top-0 left-0 h-1 bg-indigo-500 origin-left w-full"
      style={{ scaleX: scrollYProgress }}
    />
  )
}

展開カード

"use client"
import { useState } from "react"
import { motion, AnimatePresence } from "motion/react"
import { springs, motionTokens } from "@/lib/motion-tokens"

export function ExpandingCard({ title, body }: { title: string; body: string }) {
  const [expanded, setExpanded] = useState(false)

  return (
    <motion.div layout onClick={() => setExpanded(!expanded)} className="cursor-pointer">
      {/* layout="position" はテキストのリフローがアニメーションするのを防ぎます */}
      <motion.h2 layout="position" className="font-semibold">
        {title}
      </motion.h2>

      <AnimatePresence>
        {expanded && (
          <motion.p
            key="body"
            initial={{ opacity: 0 }}
            animate={{ opacity: 1 }}
            exit={{ opacity: 0 }}
            transition={{ duration: motionTokens.duration.fast }}
          >
            {body}
          </motion.p>
        )}
      </AnimatePresence>
    </motion.div>
  )
}

共有要素クロスフェード

// 元のコンテキスト
<motion.img layoutId="hero-image" src={src} className="w-16 h-16 rounded" />

// 遷移先のコンテキスト (同じ layoutId — motion がトランジションを処理)
<motion.img layoutId="hero-image" src={src} className="w-full rounded-xl" />

アコーディオン

<motion.div
  initial={false}
  animate={{ opacity: open ? 1 : 0, scaleY: open ? 1 : 0 }}
  style={{ transformOrigin: "top", overflow: "hidden" }}
  transition={{
    duration: motionTokens.duration.normal,
    ease: motionTokens.easing.smooth,
  }}
> {children}
</motion.div>

エンドツーエンドの例

マウント時に登場し、条件付きの存在を処理し、モーションの軽減を尊重するスタガーリスト — トークン、スプリング、AnimatePresence、および motion-foundations からのアクセシビリティフックを組み合わせています:

"use client"
import { useState } from "react"
import { motion, AnimatePresence } from "motion/react"
import { motionTokens, springs } from "@/lib/motion-tokens"
import { useSafeMotion } from "@/hooks/use-reduced-motion"

const containerVariants = {
  hidden: {},
  visible: {
    transition: { staggerChildren: 0.08, delayChildren: 0.1 },
  },
}

function ListItem({ label, onRemove }: { label: string; onRemove: () => void }) {
  const safe = useSafeMotion(motionTokens.distance.sm)
  return (
    <motion.li
      variants={{
        hidden:  safe.initial,
        visible: safe.animate,
      }}
      exit={safe.exit}
      transition={springs.gentle}
      className="flex items-center justify-between p-3 rounded-lg bg-white shadow-sm"
    >
      <span>{label}</span>
      <button onClick={onRemove}>削除</button>
    </motion.li>
  )
}

export function AnimatedList({ items, onRemove }: {
  items: { id: string; label: string }[]
  onRemove: (id: string) => void
}) {
  return (
    <motion.ul
      variants={containerVariants}
      initial="hidden"
      animate="visible"
      className="space-y-2"
    >
      <AnimatePresence mode="popLayout">
        {items.map((item) => (
          <ListItem
            key={item.id}
            label={item.label}
            onRemove={() => onRemove(item.id)}
          />
        ))}
      </AnimatePresence>
    </motion.ul>
  )
}

制約 / 非目標

このスキルは以下をカバーしません:

  • トークンとスプリングの定義 → motion-foundations を参照
  • ドラッグ操作、スワイプジェスチャー、並べ替え可能なリスト → motion-advanced を参照
  • テキストアニメーション(単語/文字の表示、カウンター) → motion-advanced を参照
  • SVGパスの描画またはモーフィング → motion-advanced を参照
  • カスタムアニメーションフック → motion-advanced を参照
  • motion/react を使用しないCSSのみのトランジション

アンチパターン

アンチパターン違反しているルール修正方法
AnimatePresence の子要素に key がないルール1直接の子要素に安定した key を追加する
initial + animate に exit がないルール2常に3つすべてを一緒に定義する
mode="wait" がないページ遷移ルール3AnimatePresence に mode="wait" を追加する
50アイテムのリストに layout を使用ルール4mode="popLayout" または明示的なtransformを使用する
10アイテムのリストで staggerChildren: 0.2ルール50.08–0.10 に制限する
フォーカストラップがないモーダルルール6focus-trap-react または Radix Dialog を追加する
viewport={{ once: true }} がない whileInViewルール7繰り返しの登場は情報的でなく、気が散る
インラインで transition={{ duration: 0.3 }}ルール8motionTokens.duration.normal を使用する

関連スキル

  • motion-foundations — ここにあるすべてのパターンがインポートするトークン、スプリング、useSafeMotion フック、SSRガードを定義します。最初にセットアップする必要があります。
  • motion-advanced — これらのパターンを、ドラッグ、ジェスチャー、SVG、テキスト、カスタムフック、命令型シーケンスで拡張します。このスキルのパターンを再定義することはありません。

Individual skills in this repo

This repo contains 7 individual skills — each has its own dedicated page.

503496348-ops/mischief-production

Use this skill when inspecting Blender characters, rigs, poses, animation retargeting, ground contact, facing direction, or model-vs-motion alignment where screenshots alone are not enough.

503496348-ops/mischief-production

Build reusable Manim explainers for technical concepts, graphs, system diagrams, and product walkthroughs, then hand off to the wider HCP video stack if needed. Use when the user wants a clean animated explainer rather than a generic talking-head script.

503496348-ops/mischief-production

Advanced motion patterns for React / Next.js — drag & drop, gestures, text animations, SVG path drawing, custom hooks, imperative sequences (useAnimate), loaders, and the full API decision tree. Requires motion-foundations.

503496348-ops/mischief-production

Motion tokens, spring presets, performance rules, device adaptation, accessibility enforcement, and SSR safety for React / Next.js using motion/react. Foundation layer — all other motion skills depend on this.

503496348-ops/mischief-production

Production-ready UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

503496348-ops/mischief-production

Best practices for Remotion - Video creation in React. 29 domain-specific rules covering 3D, animations, audio, captions, charts, transitions, and more.

503496348-ops/mischief-production

See, Understand, Act on video and audio. See- ingest from local files, URLs, RTSP/live feeds, or live record desktop; return realtime context and playable stream links. Understand- extract frames, build visual/semantic/temporal indexes, and search moments with timestamps and auto-clips. Act- transcode and normalize (codec, fps, resolution, aspect ratio), perform timeline edits (subtitles, text/image overlays, branding, audio overlays, dubbing, translation), generate media assets (image, audio, video), and create real time alerts for events from live streams or desktop capture.

関連スキル