Communitygithub.com

モーション・ファウンデーション

motion/reactを使用したReact/Next.js向けのモーショントークン、スプリングプリセット、パフォーマンスルール、デバイス適応、アクセシビリティ強制、SSR安全性を提供します。基盤レイヤーであり、他のすべてのモーションスキルはこれに依存します。ReactやNext.jsでモーショントークン、スプリングプリセット、動きの抑制処理、またはSSR安全なアニメーションを設定する際に使用してください。

モーション・ファウンデーション とは?

Motion Foundationsは、モーションシステムの基盤レイヤーです。このスキルは、すべてのアニメーション作業に先立って読み込む必要があり、モーショントークン(duration、easing、distance、scale)、5つの名前付きスプリングプリセット、アクセシビリティ対応のアニメーションゲート(shouldAnimate())、SSR安全な初期状態を定義します。motion/reactのみを使用し、framer-motionとの混在を禁止するなど、厳格なルールを強制します。prefers-reduced-motionを尊重し、低性能デバイスではアニメーションを無効化または簡略化します。また、レイアウトプロパティのアニメーションを禁止し、transformとopacityのみを使用することを推奨します。このスキルは、React、Next.js、およびmotion/reactライブラリをサポートし、下流のスキル(motion-patterns、motion-advanced)が継承するすべての値と制約を提供します。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/affaan-m/everything-claude-code/tree/main/skills/motion-foundations

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

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

ドキュメント

モーション・ファウンデーション は何をしますか?

モーションシステムのベースレイヤー。下流のスキル(motion-patterns、motion-advanced)が継承するすべての値、制約、ルールを定義します。アニメーション作業を開始する前に、このスキルを読み込んでください。

アクティブにするタイミング

  • アニメーションコンポーネントをゼロから作成する場合
  • トークン、スプリングプリセット、イージング値を設定する場合
  • prefers-reduced-motion サポートを実装する場合
  • アニメーション初期状態によるハイドレーションの不一致をデバッグする場合
  • アニメーションをそもそも存在させるべきか評価する場合

出力

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

  • 共有の motionTokens オブジェクト(duration、easing、distance、scale)
  • 共有の springs プリセットマップ(5つの名前付き設定)
  • すべてのコンポーネントで使用される shouldAnimate() ゲート
  • useReducedMotion によるアクセシビリティ準拠のアニメーションデフォルト
  • ハイドレーション警告がゼロのSSR安全な初期状態

原則

モーションは以下の少なくとも1つを果たさなければならず、そうでなければ削除されなければなりません:

  • 注意を誘導する
  • 状態を伝達する
  • 空間的一貫性を維持する

応答性は常に滑らかさよりも優先されます。入力遅延を引き起こす60fpsのアニメーションは、アニメーションがないよりも悪いです。

ルール

これらは交渉の余地がありません。システム内のすべてのコンポーネントに適用されます。

  1. motion/react のみを使用すること。 決して framer-motion からインポートしないでください。同じツリー内で両方を混在させないでください。
  2. initial はサーバーの出力と一致しなければなりません。 サーバーが opacity: 1 をレンダリングする場合、initial プロパティも opacity: 1 でなければなりません。例外はありません。
  3. 動きの抑制はすべてをオーバーライドします。 useReducedMotion() が true を返すか、prefersReduced が true の場合、すべてのトランスフォームが無効になります。0.2秒以下の不透明度のみのフェードだけが許可されたフォールバックです。
  4. レイアウトプロパティをアニメーションしないでください。 width、height、top、left、margin、padding は animate での使用が禁止されています。transform と opacity のみを使用してください。
  5. すべてのトークン値は motionTokens から取得します。 コンポーネントファイル内のハードコードされたdurationやeasingは禁止されています。
  6. すべてのスプリング設定は springs マップから取得します。 インラインの stiffness/damping 値は禁止されています。
  7. "use client" は motion/react からインポートするすべてのファイルに必要です。
  8. モジュールレベルで window や navigator を読み取らないでください。 常に typeof window !== "undefined" でガードしてください。

決定ガイダンス

期間の選択

トークン使用タイミング
instantツールチップの表示/非表示、フォーカスリング、バッジの更新
fastボタンフィードバック、アイコンの入れ替え、チップのトグル
normalモーダルオープン、カード展開、ページ要素の出現
slowヒーローエントランス、全ページトランジション
crawl意図的なストーリーテリング;控えめに使用

スプリングの選択

プリセット使用タイミング
snappyデフォルトUI — ボタン、チップ、ナビゲーションアイテム
gentleカード、モーダル、パネルがソフトに着地する場合
bouncy遊び心のある瞬間 — 空の状態、オンボーディング
instantツールチップ、ポップオーバー、ドロップダウン
releaseドラッグリリース — 自然な物理感覚

アニメーションを完全に無効にする場合

以下の場合、アニメーションを無効にします(shouldAnimate() が false を返すようにする):

  • prefersReduced が true の場合
  • isLowEnd が true で、アニメーションが必須でない場合
  • 要素が画面外にあり、ビューポートに入ることがない場合
  • アニメーションが純粋に装飾的で、UX上の目的がない場合

コアコンセプト

トークンシステム

// lib/motion-tokens.ts
export const motionTokens = {
  duration: {
    instant: 0.08,
    fast:    0.18,
    normal:  0.35,
    slow:    0.6,
    crawl:   1.0,
  },
  easing: {
    smooth: [0.22, 1, 0.36, 1],
    sharp:  [0.4, 0, 0.2, 1],
    bounce: [0.34, 1.56, 0.64, 1],
    linear: [0, 0, 1, 1],
  },
  distance: {
    xs: 4,
    sm: 8,
    md: 16,
    lg: 24,
    xl: 48,
  },
  scale: {
    subtle: 0.98,
    press:  0.95,
    pop:    1.04,
  },
}

export const springs = {
  snappy:  { type: "spring", stiffness: 300, damping: 30 },
  gentle:  { type: "spring", stiffness: 120, damping: 14 },
  bouncy:  { type: "spring", stiffness: 400, damping: 10 },
  instant: { type: "spring", stiffness: 600, damping: 35 },
  release: { type: "spring", stiffness: 200, damping: 20, restDelta: 0.001 },
}

ランタイムフラグ

// lib/motion-config.ts
export const motionConfig = {
  isLowEnd() {
    return (
      typeof navigator !== "undefined" &&
      navigator.hardwareConcurrency <= 4
    )
  },

  prefersReduced() {
    return (
      typeof window !== "undefined" &&
      window.matchMedia("(prefers-reduced-motion: reduce)").matches
    )
  },

  shouldAnimate({ essential = false } = {}) {
    if (this.prefersReduced()) return false
    if (!essential && this.isLowEnd()) return false
    return true
  },

  duration() {
    return this.isLowEnd() || this.prefersReduced()
      ? motionTokens.duration.instant
      : motionTokens.duration.normal
  },
}

アクセシビリティ

優先順位(高いものから低いものへ):

  1. prefers-reduced-motion: reduce — すべてのトランスフォームを無効にし、不透明度のトランジションを0.2秒以下に制限
  2. 低性能デバイスの検出 — 期間を短縮し、必須でないアニメーションを削除
  3. デザインの好み — その他すべて

モーションはグレースフルに劣化しなければなりません。レイアウトシフトを引き起こしたり、方向感覚を混乱させたりするように突然消えてはいけません。

// hooks/use-reduced-motion.tsx
"use client"
import { useReducedMotion } from "motion/react"

export function useSafeMotion(fullY: number = 16) {
  const reduce = useReducedMotion()
  return {
    initial: { opacity: 0, y: reduce ? 0 : fullY },
    animate: { opacity: 1, y: 0 },
    exit:    { opacity: 0, y: reduce ? 0 : -fullY },
  }
}
/* globals.css */
@media (prefers-reduced-motion: reduce) {
  .motion-safe-transition  { transition: opacity 0.15s; }
  .motion-reduce-transform { transform: none !important; }
}
<!-- Tailwind -->
<div class="motion-safe:animate-fade motion-reduce:opacity-100"></div>

SSR / ハイドレーションの安全性

ルール:initial は常にサーバーがレンダリングするものと一致しなければなりません。

// 間違い — サーバーは opacity:1 をレンダリングするが、initial は 0 → ハイドレーション不一致
<motion.div initial={{ opacity: 0 }} animate={{ opacity: 1 }} />

// 正しい — AnimatePresence を使用するか、クライアントマウントに委ねる
"use client"
const [mounted, setMounted] = useState(false)
useEffect(() => setMounted(true), [])

<motion.div
  initial={{ opacity: mounted ? 0 : 1 }}
  animate={{ opacity: 1 }}
/>

コード例

エンドツーエンド:トークン + スプリング + アクセシビリティ + SSRガード

// components/fade-in-card.tsx
"use client"

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

interface FadeInCardProps {
  children: React.ReactNode
  delay?: number
}

export function FadeInCard({ children, delay = 0 }: FadeInCardProps) {
  // SSRガード — initial はサーバー出力 (opacity: 1) と一致しなければならない
  const [mounted, setMounted] = useState(false)
  useEffect(() => setMounted(true), [])

  // アクセシビリティ — 動きの抑制が優先される場合、トランスフォームを無効にする
  const safeMotion = useSafeMotion(motionTokens.distance.md)

  // デバイスゲート — 低性能ハードウェアではアニメーションをスキップ
  if (!motionConfig.shouldAnimate() || !mounted) {
    return <div>{children}</div>
  }

  return (
    <motion.div
      initial={safeMotion.initial}
      animate={safeMotion.animate}
      exit={safeMotion.exit}
      transition={{
        ...springs.gentle,
        delay,
      }}
      whileHover={{ scale: motionTokens.scale.pop }}
      whileTap={{ scale: motionTokens.scale.press }}
    >
      {children}
    </motion.div>
  )
}

制約 / 非目標

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

  • UIコンポーネントパターン(ボタン、モーダル、ステガー) → motion-patterns を参照
  • ドラッグ、ジェスチャー、SVG、テキストアニメーション、カスタムフック → motion-advanced を参照
  • CSSのみのアニメーションや motion/react を使用しないTailwindの animate-* クラス
  • サードパーティのアニメーションライブラリ(GSAP、anime.js など)
  • モーションデザインの決定(いつアニメーションするか、何を強調するか) — それはコードの制約ではなく、デザインの関心事です

アンチパターン

アンチパターン違反したルール修正方法
import { motion } from "framer-motion"ルール1motion/react を使用
SSRコンポーネントでの initial={{ opacity: 0 }}ルール2マウントガードを追加
useReducedMotion チェックの省略ルール3useSafeMotion フックを使用
animate={{ width: "100%" }}ルール4代わりに scaleX トランスフォームを使用
インラインの transition={{ duration: 0.4 }}ルール5motionTokens.duration.normal を使用
インラインの { stiffness: 300, damping: 30 }ルール6springs.snappy を使用
"use client" ディレクティブの欠落ルール7ファイルの先頭に追加
モジュールレベルでの navigator.hardwareConcurrencyルール8typeof navigator !== "undefined" でラップ

関連スキル

  • motion-patterns — ここで定義されたトークンとスプリングを消費して、ボタン、モーダル、ステガー、ページトランジション、スクロールパターンを構築します。値を再定義することはありません。
  • motion-advanced — ここで定義されたトークンとスプリングを消費して、ドラッグ、SVG、テキスト、ジェスチャーパターンを実現します。この基盤の上に useAnimate シーケンスとカスタムフックを追加します。

Individual skills in this repo

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

accessibility

Design, implement, and audit inclusive digital products using WCAG 2.2 Level AA. Use when building or auditing UI that must meet WCAG 2.2 Level AA, or when reviewing a change for keyboard, contrast, or screen-reader support.

affaan-m/claude-api

Anthropic Claude API patterns for Python and TypeScript. Covers Messages API, streaming, tool use, vision, extended thinking, batches, prompt caching, and Claude Agent SDK. Use when building applications with the Claude API or Anthropic SDKs.

affaan-m/everything-claude-code

End-to-end marketing campaign planning and execution. Covers audience research, positioning, campaign angle definition, landing page copy, email sequences, social posts, ad copy, short-form video scripts, and content calendars. Use as the orchestration layer for multi-channel product launches. Use when planning or executing a multi-channel product launch, or producing landing page, email, social, or ad copy.

affaan-m/everything-claude-code

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/everything-claude-code-conventions

Development conventions and patterns for everything-claude-code. JavaScript project with conventional commits.

affaan-m/frontend-design

Create distinctive, production-grade frontend interfaces with high design quality. Use when the user asks to build web components, pages, or applications and the visual direction matters as much as the code quality.

affaan-m/gget

gget CLI and Python workflow for quick genomic database queries, sequence lookup, BLAST-style searches, enrichment checks, and reproducible bioinformatics evidence logs.

affaan-m/literature-review

Systematic literature-review workflow for academic, biomedical, technical, and scientific topics, including search planning, source screening, synthesis, citation checks, and evidence logging.

affaan-m/motion-ui

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

affaan-m/project-guidelines-example

Example project-specific skill template based on a real production application.

affaan-m/pubmed-database

Direct PubMed and NCBI E-utilities search workflows for biomedical literature, MeSH queries, PMID lookup, citation retrieval, and API-backed literature monitoring.

affaan-m/scholar-evaluation

Structured scholarly-work evaluation for papers, proposals, literature reviews, methods sections, evidence quality, citation support, and research-writing feedback.

affaan-m/uspto-database

USPTO patent and trademark data workflow for official record lookup, PatentSearch queries, TSDR checks, assignment data, and reproducible IP research logs.

agent-architecture-audit

Full-stack diagnostic for agent and LLM applications. Audits the 12-layer agent stack for wrapper regression, memory pollution, tool discipline failures, hidden repair loops, and rendering corruption. Produces severity-ranked findings with code-first fixes. Essential for developers building agent applications, autonomous loops, or any LLM-powered feature. Use when an agent or LLM feature misbehaves and the failing layer is unknown, or before shipping an agent stack.

agent-eval

Head-to-head comparison of coding agents (Claude Code, Aider, Codex, etc.) on custom tasks with pass rate, cost, time, and consistency metrics. Use when choosing between coding agents, or when a change to an agent setup needs measured pass rate, cost, and time rather than an impression.

agent-harness-construction

Design and optimize AI agent action spaces, tool definitions, and observation formatting for higher completion rates. Use when defining or revising an agent

agentic-engineering

Operate as an agentic engineer using eval-first execution, decomposition, and cost-aware model routing. Use when planning or executing engineering work that agents will carry out end to end.

agentic-os

Build persistent multi-agent operating systems on Claude Code. Covers kernel architecture, specialist agents, slash commands, file-based memory, scheduled automation, and state management without external databases. Use when building a persistent multi-agent system on Claude Code with its own memory, commands, and scheduling.

agent-introspection-debugging

Structured self-debugging workflow for AI agent failures using capture, diagnosis, contained recovery, and introspection reports. Use when an agent run fails and you need a reproducible diagnosis instead of a retry.

agent-payment-x402

Add x402 payment execution to AI agents with per-task budgets, spending controls, and non-custodial wallets. Supports Base through agentwallet-sdk and X Layer through OKX Payments / OKX Agent Payments Protocol. Use when an agent must pay for something itself and needs per-task budgets, spending controls, and a non-custodial wallet.

関連スキル