Communitygithub.com

モーションシステム v4.2

React/Next.js向けの本番環境対応UIモーションシステム。アニメーション、トランジション、モーションパターンの実装に使用します。

モーションシステム v4.2 とは?

このスキルは、ReactおよびNext.jsアプリケーションにおいて、パフォーマンス、アクセシビリティ、ユーザビリティを重視したUIモーションシステムを提供します。単なる装飾ではなく、注意力の誘導、状態の伝達、空間的な連続性の維持を目的としたアニメーションの実装を支援します。具体的な使いどころとして、ボタンやモーダルなどのインタラクティブコンポーネント、ローディングから完了への状態遷移、ナビゲーションやレイアウトの連続性が求められる場面が挙げられます。スキルは、motion パッケージ(旧framer-motion)のインポート方法、デュレーションやイージングのトークン定義、transformとopacityに限定したパフォーマンスルール、低スペック端末への適応、useReducedMotionを用いたアクセシビリティ対応、AnimatePresenceのmode選択(wait/popLayout)、モーダル実装のベストプラクティス、SSRセーフティ、デバッグ方法、アンチパターンなど、実践的な知識を包括的にカバーしています。提供されるコード例は、ボタンインタラクション、ステガーリスト、モーダル、パララックス、スケルトンローディング、共有レイアウトトランジションなど多岐にわたり、すぐにプロジェクトに適用できるよう設計されています。

対応~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/Cody-W-Tucker/skills/tree/HEAD/skills/motion-ui

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

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

ドキュメント

モーションシステム v4.2 は何をしますか?

React / Next.js向けの本番環境対応UIモーションシステム。

パフォーマンス、アクセシビリティ、ユーザビリティに重点を置いています — 単なる装飾ではありません。

使用するタイミング

このモーションシステムは、モーションが以下の目的を持つ場合に使用します:

  • 注意を誘導する(例:オンボーディング、主要なアクション)
  • 状態を伝達する(読み込み中、成功、エラー、遷移)
  • 空間的な連続性を維持する(レイアウト変更、ナビゲーション)

適切なシナリオ

  • インタラクティブコンポーネント(ボタン、モーダル、メニュー)
  • 状態遷移(読み込み中 → 読み込み完了、開く → 閉じる)
  • ナビゲーションとレイアウトの連続性(共有要素、クロスフェード)

考慮事項

  • アクセシビリティ: 常に動きの抑制(reduced motion)をサポートする
  • デバイス適応: 低スペック端末に合わせて調整する
  • パフォーマンスのトレードオフ: 視覚的な滑らかさよりも応答性を優先する

モーションを使用すべきでない場面

  • 純粋に装飾目的である場合
  • ユーザビリティや明瞭さを損なう場合
  • パフォーマンスに悪影響を及ぼす場合

仕組み

基本原則

モーションは以下の役割を果たさなければなりません:

  • 注意を誘導する
  • 状態を伝達する
  • 空間的な連続性を維持する

どれも満たさない場合 → 削除します。


インストール

npm install motion

バージョン

  • motion/react - Motion for React プロジェクトのデフォルト(パッケージ: motion)
  • framer-motion - Framer Motion に依存するプロジェクト向けの従来のインポートパス

混在させないでください。 混在させると、内部スケジューラが競合し、AnimatePresence のコンテキストが壊れます。一方のパッケージのコンポーネントは、もう一方のパッケージのコンポーネントと exit アニメーションを連携できなくなります。

プロジェクトがどのバージョンを使用しているかを確認するには:

cat package.json | grep -E '"motion"|"framer-motion"'

常に一貫して1つのソースからインポートします:

// 正しい(モダン)
import { motion, AnimatePresence } from "motion/react"

// 正しい(従来)
import { motion, AnimatePresence } from "framer-motion"

// 同じプロジェクト内で両方を混在させないでください

モーショントークン

// motionTokens.ts
export const motionTokens = {
  duration: {
    fast: 0.18,
    normal: 0.35,
    slow: 0.6
  },
  // これらを `transition` オブジェクト内の `ease` 値として使用します:
  // transition={{ duration: motionTokens.duration.normal, ease: motionTokens.easing.smooth }}
  easing: {
    smooth: [0.22, 1, 0.36, 1] as [number, number, number, number],
    sharp:  [0.4,  0, 0.2, 1] as [number, number, number, number]
  },
  distance: {
    sm: 8,
    md: 16,
    lg: 24
  }
}

使用例:

import { motionTokens } from "@/lib/motionTokens"

<motion.div
  initial={{ opacity: 0, y: motionTokens.distance.md }}
  animate={{ opacity: 1, y: 0 }}
  transition={{
    duration: motionTokens.duration.normal,
    ease: motionTokens.easing.smooth
  }}
/>

パフォーマンスルール

安全

  • transform
  • opacity

避けるべきもの

  • width / height
  • top / left

ルール: 応答性 > 滑らかさ


デバイス適応

このヒューリスティックは、CPUコア数 と 使用可能メモリを組み合わせて、より信頼性の高いシグナルを得ます。deviceMemory は Chrome/Android で利用可能です。フォールバックは Safari と Firefox をカバーします。

const isLowEnd =
  typeof navigator !== "undefined" && (
    // メモリが少ない(Chrome/Androidのみ。それ以外は未定義 → 十分な性能とみなす)
    (navigator.deviceMemory !== undefined && navigator.deviceMemory <= 2) ||
    // コア数が少なく、かつメモリAPIがない(Safari/Firefoxの低性能ハードウェアをカバー)
    (navigator.deviceMemory === undefined && navigator.hardwareConcurrency <= 4)
  )

const duration = isLowEnd ? 0.2 : 0.4

アクセシビリティ

JS (useReducedMotion)

import { motion, useReducedMotion } from "motion/react"

export function FadeIn() {
  const reduce = useReducedMotion()

  return (
    <motion.div
      initial={{ opacity: 0, y: reduce ? 0 : 24 }}
      animate={{ opacity: 1, y: 0 }}
    />
  )
}

CSS

@media (prefers-reduced-motion: reduce) {
  .motion-safe-transition {
    transition: opacity 0.2s;
  }

  .motion-reduce-transform {
    transform: none !important;
  }
}

Tailwind

<div class="motion-safe:animate-fade motion-reduce:opacity-100"></div>

アーキテクチャとパターン

コアパターン

シナリオパターン
ホバーフィードバックwhileHover
タップ / 押下フィードバックwhileTap
スクロールに応じた表示whileInView
スクロール連動値useScroll + useTransform
条件付きマウント/アンマウントAnimatePresence
小さなレイアウトシフト(単一要素、~300px未満の変化)layout プロパティ
大きなレイアウトシフトやページ全体のリフローlayout を避け、CSS トランジションやページレベルルーティングを使用
複雑な命令型シーケンスuseAnimate

なぜ大きなコンテナで layout を避けるべきか? Framer のレイアウトアニメーションは transform を使用して位置を調整しますが、ビューポート全体にまたがる要素や深いリフローを引き起こす要素では、計測コストが原因で目に見えるジャンクや CLS が発生します。代わりに、CSS Grid/Flexbox のトランジションを使用するか、特定の子要素に layoutId を指定して連携させることを推奨します。

レイアウトとトランジション

  • 共有要素トランジション → layoutId(マウントされたインスタンスごとに一意である必要があります)
  • Enter / Exit トランジション → AnimatePresence(以下の mode ガイダンスを参照)

AnimatePresence mode

常に mode を明示的に指定してください。デフォルト("sync")は enter と exit を同時に実行するため、ほとんどの UI パターンで視覚的な重複が発生します。

mode使用する場面
"wait"Exit が完了してから Enter が開始されます。モーダル、トースト、ページトランジション に使用します。
"sync"(デフォルト)Enter と exit が重なります。重複が意図的な場合のみ使用します(例:クロスフェードカルーセル)。
"popLayout"Exit する要素は即座にフローから除外され、残りの要素がそのスペースを埋めるようにアニメーションします。リスト、タブ、非表示可能なカード に使用します。
// モーダル — 常に "wait" を使用
<AnimatePresence mode="wait">
  {open && <Modal key="modal" />}
</AnimatePresence>

// 非表示可能なリストアイテム — "popLayout" を使用
<AnimatePresence mode="popLayout">
  {items.map(item => <Card key={item.id} />)}
</AnimatePresence>

高度なパターン(概念)

  • パララックス(スクロール連動トランスフォーム)
  • スクロールストーリーテリング(スティッキーセクション)
  • 3Dチルト(ポインタ連動トランスフォーム)
  • クロスフェード(共有 layoutId)
  • プログレッシブリビール(クリップパス)
  • スケルトンローディング(ループする不透明度)
  • マイクロインタラクション(ホバー/タップフィードバック)
  • スプリングシステム(物理ベースのモーション)

モーダルの必須事項

  • フォーカストラップ
  • Escape キーで閉じる
  • スクロールロック
  • ARIA ロール
  • AnimatePresence mode="wait" を使用して、exit アニメーションが完了してから次のモーダルが入るようにする

完全な例

import React, { useEffect, useRef, useState } from "react"
import { motion, AnimatePresence } from "motion/react"

function useFocusTrap(ref: React.RefObject<HTMLDivElement | null>, active: boolean) {
  useEffect(() => {
    if (!active || !ref.current) return
    const el = ref.current
    const focusable = el.querySelectorAll<HTMLElement>(
      'button, [href], input, select, textarea, [tabindex]:not([tabindex="-1"])'
    )
    const first = focusable[0]
    const last  = focusable[focusable.length - 1]

    function handleKey(e: KeyboardEvent) {
      if (e.key !== "Tab") return
      if (e.shiftKey && document.activeElement === first) {
        e.preventDefault()
        last?.focus()
      } else if (!e.shiftKey && document.activeElement === last) {
        e.preventDefault()
        first?.focus()
      }
    }

    el.addEventListener("keydown", handleKey)
    first?.focus()
    return () => el.removeEventListener("keydown", handleKey)
  }, [active, ref])
}

function useScrollLock(active: boolean) {
  useEffect(() => {
    if (!active) return
    const prev = document.body.style.overflow
    document.body.style.overflow = "hidden"
    return () => { document.body.style.overflow = prev }
  }, [active])
}

function Modal({ open, closeModal }: { open: boolean; closeModal: () => void }) {
  const ref = useRef<HTMLDivElement>(null)

  useFocusTrap(ref, open)
  useScrollLock(open)

  useEffect(() => {
    function onKey(e: KeyboardEvent) {
      if (e.key === "Escape") closeModal()
    }
    if (open) window.addEventListener("keydown", onKey)
    return () => window.removeEventListener("keydown", onKey)
  }, [open, closeModal])

  return (
    // mode="wait" により、exit アニメーションが完了してから新しいモーダルが入ることを保証する
    <AnimatePresence mode="wait">
      {open && (
        <motion.div
          role="dialog"
          aria-modal="true"
          aria-labelledby="modal-title"
          initial={{ opacity: 0 }}
          animate={{ opacity: 1 }}
          exit={{ opacity: 0 }}
          transition={{ duration: 0.2 }}
          className="fixed inset-0 flex items-center justify-center bg-black/40"
        >
          <motion.div
            ref={ref}
            initial={{ scale: 0.95, opacity: 0 }}
            animate={{ scale: 1,    opacity: 1 }}
            exit={{    scale: 0.95, opacity: 0 }}
            transition={{ duration: 0.2, ease: [0.22, 1, 0.36, 1] }}
            className="bg-white p-6 rounded"
          >
            <h2 id="modal-title">ダイアログタイトル</h2>
            <button onClick={closeModal}>閉じる</button>
          </motion.div>
        </motion.div>
      )}
    </AnimatePresence>
  )
}

export function Example() {
  const [open, setOpen] = useState(false)

  return (
    <>
      <button onClick={() => setOpen(true)}>開く</button>
      <Modal open={open} closeModal={() => setOpen(false)} />
    </>
  )
}

SSR セーフティ

  • サーバーとクライアントのレンダリング間で初期状態を一致させる
  • 暗黙のアニメーション起点を避ける(常に initial を明示的に設定する)
  • Next.js App Router では motion コンポーネントを "use client" でラップする

デバッグ

チェック項目:

  • インポートの誤り(motion/react と framer-motion の混在)
  • Next.js App Router での "use client" ディレクティブの欠落
  • AnimatePresence の子要素の key プロパティの欠落
  • ハイドレーションの不一致(SSR とクライアントで初期状態が異なる)
  • 大きなコンテナでの layout プロパティの誤用によるリフローのジャンク
  • 状態駆動型アニメーションがトリガーされない(依存配列を確認)

QA(品質保証)

  • CLS(累積レイアウトシフト)がないこと
  • キーボード操作が機能すること
  • モーダル内でフォーカスがトラップされていること
  • ARIA ロールが正しいこと(role="dialog"、aria-modal="true")
  • 動きの抑制(reduced motion)が尊重されていること(useReducedMotion + CSS メディアクエリ)
  • Next.js でハイドレーションの警告が出ないこと
  • アンマウント時にアニメーションがクリーンに停止すること(メモリリークがないこと)
  • すべての使用箇所で AnimatePresence の mode が明示的に設定されていること

アンチパターン

  • レイアウトプロパティ(width、height、top、left)のアニメーション
  • 目的のない無限アニメーション(常に問いかける:これはどのような状態を伝えるのか?)
  • リストの過度なステガリング(staggerChildren は ≤ 0.1秒に保つ。それを超えると遅く感じられる)
  • 動きの抑制設定を無視すること
  • 大きなコンテナやビューポート全体のコンテナで layout を使用すること
  • AnimatePresence で mode を省略すること(デフォルトの "sync" は視覚的な重複を引き起こす)
  • 純粋に装飾目的でモーションを使用すること

哲学

モーションはインタラクションデザインです。


最終ルール

モーションが UX を向上させない場合 → 削除する。


例

ボタンインタラクション

import { motion } from "motion/react"

export function Button() {
  return (
    <motion.button
      whileHover={{ scale: 1.02 }}
      whileTap={{ scale: 0.97 }}
      transition={{ duration: 0.15, ease: [0.4, 0, 0.2, 1] }}
    >
      クリックしてください
    </motion.button>
  )
}

動きの抑制の例

import { motion, useReducedMotion } from "motion/react"

export function FadeIn() {
  const reduce = useReducedMotion()

  return (
    <motion.div
      initial={{ opacity: 0, y: reduce ? 0 : 24 }}
      animate={{ opacity: 1, y: 0 }}
      transition={{ duration: reduce ? 0.1 : 0.35, ease: [0.22, 1, 0.36, 1] }}
    />
  )
}

ステガーリスト

import { motion } from "motion/react"

const container = {
  hidden: {},
  visible: {
    transition: { staggerChildren: 0.08 } // 鈍さを避けるため ≤ 0.1秒に保つ
  }
}

const item = {
  hidden:  { opacity: 0, y: 10 },
  visible: { opacity: 1, y: 0,  transition: { duration: 0.3, ease: [0.22, 1, 0.36, 1] } }
}

export function List() {
  return (
    <motion.ul variants={container} initial="hidden" animate="visible">
      {[1, 2, 3].map(i => (
        <motion.li key={i} variants={item}>アイテム {i}</motion.li>
      ))}
    </motion.ul>
  )
}

AnimatePresence を使用したモーダル

import { motion, AnimatePresence } from "motion/react"

export function Modal({ open }: { open: boolean }) {
  return (
    <AnimatePresence mode="wait">
      {open && (
        <motion.div
          initial={{ opacity: 0, scale: 0.95 }}
          animate={{ opacity: 1, scale: 1    }}
          exit={{    opacity: 0, scale: 0.95 }}
          transition={{ duration: 0.2, ease: [0.22, 1, 0.36, 1] }}
        />
      )}
    </AnimatePresence>
  )
}

スクロールパララックス

import { useScroll, useTransform, motion } from "motion/react"

export function Parallax() {
  const { scrollYProgress } = useScroll()
  const y = useTransform(scrollYProgress, [0, 1], [0, -80])

  return <motion.div style={{ y }} />
}

スケルトンローディング

import { motion } from "motion/react"

export function Skeleton() {
  return (
    <motion.div
      className="bg-gray-200 h-6 w-full rounded"
      animate={{ opacity: [0.5, 1, 0.5] }}
      transition={{
        duration: 1.5,       // 快適なパルス — 以前は欠落しており、高速なフラッシュを引き起こしていました
        repeat: Infinity,
        ease: "easeInOut"
      }}
    />
  )
}

共有レイアウト(クロスフェード)

import { motion } from "motion/react"

// layoutId はマウントされたインスタンスごとに一意である必要があります。
// 複数のインスタンスが同時に存在できる場合は、一意のIDを追加します:
// layoutId={`shared-${item.id}`}
export function Shared() {
  return <motion.div layoutId="shared" />
}

Individual skills in this repo

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

Cody-W-Tucker/skills

Landing page quality assessment for paid advertising campaigns. Evaluates message match, page speed, mobile experience, trust signals, form optimization, and conversion rate potential. Use when user says landing page, post-click experience, landing page audit, conversion rate, or landing page optimization.

Cody-W-Tucker/skills

TikTok Ads deep analysis covering creative quality, tracking, bidding, campaign structure, and TikTok Shop. Evaluates 28 checks with emphasis on creative-first strategy, safe zone compliance, and Smart+ campaigns. Use when user says TikTok Ads, TikTok marketing, TikTok Shop, Spark Ads, Smart+, or TikTok campaign.

Cody-W-Tucker/skills

YouTube Ads specific analysis covering campaign types, creative quality, audience targeting, and measurement. Evaluates video ad performance across skippable, non-skippable, bumper, Shorts, Demand Gen, and Connected TV formats. Covers VAC→Demand Gen migration, Shorts creative requirements, and CTV shoppable ads. Use when user says YouTube Ads, video ads, pre-roll, bumper ads, YouTube campaign, Shorts ads, or CTV ads.

Cody-W-Tucker/skills

Craft the story that makes investors say \"I want in.\" Master the narrative structure that Reid Hoffman, Sequoia, and top founders use to raise capital. Use when: **Preparing to fundraise** to develop your story before the deck; **Investor meetings** to structure conversations that convert; **Pitch practice** to refine your narrative arc; **Cold outreach** to write compelling investor emails; **Pivoting** to reframe your story after a change

Cody-W-Tucker/skills

Identify the best GTM motions and tools across 7 motion types: Inbound, Outbound, Paid Digital, Community, Partners, ABM, and PLG. Use when selecting marketing channels, choosing between inbound and outbound strategy, or planning cross-channel campaigns.

Cody-W-Tucker/skills

Produce a print-grade single-page kami (紙 / 纸) document — warm parchment canvas, ink-blue accent, serif at one weight, no italic, no cool grays. The output reads like a professional white paper or studio one-pager, not an app UI. Multilingual by design (EN · zh-CN · ja). One self-contained HTML file, zero dependencies.

Cody-W-Tucker/skills

Optimize landing pages for maximum conversions using proven frameworks from Unbounce and Oli Gardner—apply the \"one goal, one message, one action\" principle with data-driven design, copy, and CTA best practices. Use when: **Create a new landing page** for a campaign; **Optimize an existing landing page** that isn't converting; **Review landing page design** before launch; **Improve form conversion rates** on lead gen pages; **A/B test landing page elements** systematically

Cody-W-Tucker/skills

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.

Cody-W-Tucker/skills

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.

Cody-W-Tucker/skills

A single-frame motion-design composition with looping CSS animations — rotating type ring, animated globe, ticking timer, parallax labels. Renders as a hero video poster you can hand straight to HyperFrames or any keyframe-based exporter. Use when the brief asks for "motion design", "animated hero", "loop", "video poster", "title card", or pairs Open Claude Design with HyperFrames for a kinetic export.

Cody-W-Tucker/skills

Production-ready animation patterns for React / Next.js — button, modal, toast, stagger, page transitions, exit animations, scroll, and layout — built on motion-foundations tokens and springs.

Cody-W-Tucker/skills

Produce a single-file slide deck in the Atelier Zero visual language (warm-paper background, italic-serif emphasis spans, coral terminating dots, surreal collage plates) — Open Design's brand deck recipe. The deck uses **horizontal magazine-style swipe pagination** (←/→, wheel, swipe), a per-slide chrome strip with brand mark and slide counter, an ESC overview grid, a coral progress bar, and inherits the canonical stylesheet + 16-slot image library from the sister `open-design-landing` skill.

Cody-W-Tucker/skills

Produce a world-class single-page editorial landing site in the Atelier Zero visual language (Monocle / Apartamento / Études editorial collage) — the same aesthetic Open Design uses for its own marketing surface. The agent fills a typed `inputs.json` from a brand brief, optionally generates 16 collage assets via gpt-image-2, then runs a pure-function composer that emits a self-contained HTML file; a separate path can mirror the Astro marketing site in `apps/landing-page/`. Drop-in scroll-reveal motion and a Headroom-style sticky nav are wired automatically.

Cody-W-Tucker/skills

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

Cody-W-Tucker/skills

Single-page SaaS landing with hero, features, social proof, pricing, and CTA. Respects the active DESIGN.md color/typography/layout tokens. Trigger keywords: "saas landing", "marketing page", "product landing".

Cody-W-Tucker/skills

Single-page SaaS landing with hero, features, social proof, pricing, and CTA. Respects the active DESIGN.md color/typography/layout tokens. Trigger keywords: "saas landing", "marketing page", "product landing".

Cody-W-Tucker/skills

Master April Dunford's 8-step sales narrative from \"Sales Pitch\" (2023). Transform your positioning into a compelling story that wins enterprise deals. Use when: Structuring B2B sales presentations and demos; Creating pitch decks for complex products; Training sales teams on narrative-driven selling; Converting positioning strategy into sales conversations; Winning against entrenched competitors

Cody-W-Tucker/skills

Swiss-style user-research narrative template in warm-paper editorial aesthetics. Use when users ask for a premium research deck or story-first live artifact with minimalist typography, high-clarity layout, subtle motion, donut breakdowns, and keyboard/click navigation across slides in a single HTML file.

Cody-W-Tucker/skills

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.

Cody-W-Tucker/skills

Download YouTube videos with customizable quality and format options. Use this skill when the user asks to download, save, or grab YouTube videos. Supports various quality settings (best, 1080p, 720p, 480p, 360p), multiple formats (mp4, webm, mkv), and audio-only downloads as MP3.

関連スキル