Communitygithub.com

Cody-W-Tucker/skills

適用於 React / Next.js 的生產級動畫模式 — 按鈕、模態框、通知、漸進清單、頁面轉場、退出動畫、滾動以及佈局動畫,皆基於 motion-foundations tokens 和 spring 建構。

skills 是什麼?

這是一套提供「複製貼上」即可使用的 UI 動畫模式技能,專為 React 與 Next.js 應用程式設計。所有動畫模式都建立在 `motion-foundations` 的 tokens 和 spring 之上,強制使用統一的設計語言,禁止使用內聯的持續時間或緩動函數。技能涵蓋了按鈕回饋、漸進清單、模態框、通知堆疊、頁面轉場、滾動觸發動畫、展開卡片、手風琴以及共享元素轉場等最常見的 UI 動畫需求。它嚴格遵循一系列規則,例如「條件渲染必須被 `AnimatePresence` 包裹並帶有 `key`」、「同時定義 `initial`、`animate` 與 `exit`」以及「漸進間隔必須控制在 0.05–0.10 秒之間」,以確保動畫行為正確且效能良好。此技能也明確指出了不涵蓋的領域(如拖拽、手勢、文字動畫等),並以反模式表格來說明常見錯誤及修復方式,並與 `motion-foundations` 和 `motion-advanced` 技能互相搭配。

相容平台~Claude Code~Codex CLI✓Cursor
npx skills add https://github.com/Cody-W-Tucker/skills/tree/HEAD/skills/motion-patterns

在你喜歡的 AI 中提問

開啟一個已預先載入此 Agent Skill 的新對話。

說明文件

Motion Patterns

針對最常見的 UI 動畫需求,提供可直接複製貼上的模式。 此處的每個模式都基於 motion-foundations 的 tokens 和 spring 建構。請勿在此定義新的持續時間或緩動函數 — 請直接匯入使用。

何時啟用

  • 對按鈕、卡片、模態框或通知進行動畫處理
  • 使用漸進效果建構清單進入動畫
  • 在 Next.js App Router 中設定頁面轉場
  • 為條件性內容加入進入或退出動畫
  • 實作滾動觸發、滾動關聯進度或黏性故事區塊
  • 建構展開卡片、手風琴或共享元素轉場

輸出

此技能產出:

  • 所有標準 UI 元件的無障礙友善、SSR 安全的動畫
  • 以 AnimatePresence 包裹的條件渲染,具備正確的退出行為
  • 適用於 Next.js App Router 的頁面轉場包裹元件
  • 使用 useScroll + useTransform 的滾動觸發與滾動關聯模式
  • 使用 layout 與 layoutId 的佈局動畫模式,適用於展開與淡入淡出效果

原則

  • 每個模式皆從 motion-foundations 匯入。不使用原始數值。
  • 每個條件渲染都必須包裹在 AnimatePresence 中,並帶有 key。
  • 退出動畫必須始終與進入動畫一同定義 — 絕非事後才考慮。
  • layout 僅用於小型、孤立的位移。大型子樹結構則使用明確的變形。

規則

  1. 始終將條件渲染包裹在 AnimatePresence 中,並在直接的子元素上加上 key。 沒有 key,退出動畫將永遠不會觸發。
  2. 在定義 initial + animate 時,務必同時定義 exit。 缺少退出動畫的動畫是不完整的。
  3. 在頁面轉場中使用 mode="wait"。 在退出動畫完成前,進入動畫不得開始。
  4. 切勿在子節點超過約 5 個或 DOM 層級過深的子樹上使用 layout。 應改用明確的 x / y 變換。
  5. 漸進間隔必須維持在 0.05s 到 0.10s 之間。 低於此範圍會感覺機械化,高於則會感覺遲緩。
  6. 模態框必須始終包含: 焦點鎖定、Escape 鍵關閉、滾動鎖定、role="dialog"、aria-modal="true"。
  7. 滾動觸發使用 viewport={{ once: true }}。 在滾出後重複顯示只會造成干擾,而非提供資訊。
  8. 所有 token 值皆從 motion-foundations 匯入。 不使用內聯數值。

決策指引

選擇正確的模式

情境模式
元素出現 / 消失AnimatePresence
順序載入的項目清單漸進變體
在路由間導航頁面轉場包裹元件
元素在相同位置改變大小layout 屬性
相同元素在不同頁面上下文間移動layoutId
元素滾入視野時進入whileInView
根據滾動位置變化的值useScroll + useTransform

何時使用 mode="wait" 與 mode="sync"

模式使用時機
wait頁面轉場、內容切換(一次一個)
sync堆疊通知、列表項目(重疊沒關係)
popLayout從重新排列的清單中移除的項目

核心概念

AnimatePresence 契約

以下三件事必須始終成立:

  1. AnimatePresence 包裹條件內容
  2. 直接的子元素帶有 key
  3. 子元素具有 exit 屬性

缺少任何一項,退出動畫將會悄悄地失敗。

layout 與 layoutId

  • layout — 動畫處理元素自身在相同位置的大小/位置變化
  • layoutId — 連結兩個不同的元素,在渲染之間進行淡入淡出轉場

在展開容器內的文字上使用 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>

端到端範例

一個在掛載時進入、處理條件存在性,並尊重減少動畫設定的漸進清單 — 結合 tokens、springs、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}>Remove</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>
  )
}

限制 / 非目標

此技能不涵蓋:

  • Token 和 spring 定義 → 請參閱 motion-foundations
  • 拖拽互動、滑動手勢、可重新排序清單 → 請參閱 motion-advanced
  • 文字動畫(字詞/字元揭示、計數器) → 請參閱 motion-advanced
  • SVG 路徑繪製或變形 → 請參閱 motion-advanced
  • 自訂動畫鉤子 → 請參閱 motion-advanced
  • 不使用 motion/react 的純 CSS 轉場

反模式

反模式違反規則修正方式
AnimatePresence 的子元素缺少 key規則 1為直接子元素添加穩定的 key
initial + animate 但沒有 exit規則 2務必同時定義三者
頁面轉場沒有使用 mode="wait"規則 3在 AnimatePresence 中添加 mode="wait"
在包含 50 個項目的清單上使用 layout規則 4使用 mode="popLayout" 或明確的變換
在包含 10 個項目的清單上使用 staggerChildren: 0.2規則 5限制在 0.08–0.10
無焦點鎖定的模態框規則 6添加 focus-trap-react 或 Radix Dialog
whileInView 沒有使用 viewport={{ once: true }}規則 7重複的進入動畫只會干擾,而非提供資訊
transition={{ duration: 0.3 }} 使用內聯數值規則 8使用 motionTokens.duration.normal

相關技能

  • motion-foundations — 定義此處每個模式所需的所有 tokens、springs、useSafeMotion 鉤子以及 SSR 保護。必須優先設定。
  • motion-advanced — 透過拖拽、手勢、SVG、文字、自訂鉤子和指令式排序擴展這些模式。不會重新定義此技能中的任何模式。

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 UI motion system for React/Next.js. Use when implementing animations, transitions, or motion patterns.

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.

相關技能