Skip to content

TheGoat395/Codex-Skills / skills/motion-react-patterns

motion-react-patterns

Verified

Implement Motion APIs, presence and lifecycle.

FileKindSize
SKILL.mdskill md971 B
agents/openai.yamlconfig286 B
references/motion-react-patterns-guide.mdmarkdown3.3 KB

references/motion-react-patterns-guide.md

View on GitHub
# Motion React Patterns Guide

## Purpose

Use Motion when React state, component lifecycle, and declarative animation should stay aligned.

## Use When

- A React or Next.js UI needs polished component animation, reveal timing, hover/tap/focus states, or state-driven transitions.
- The existing project already uses Motion or a React-native animation API would be cleaner than imperative timelines.
- Motion should elevate product tactility without turning a site into animation soup.

## Do Not Use When

- A simple CSS transition handles the effect cleanly.
- The choreography is timeline-heavy, scroll-pinned, text-split, or SVG-path based and GSAP is a better fit.
- The project is not React and Motion for React is not appropriate.

## Discovery Questions

- Does the project already use Motion, CSS transitions, GSAP, or another animation library?
- Which UI state drives the animation: mount, hover, tap, focus, in-view, open, selected, loading, or route change?
- What should motion clarify for the user?
- What is the reduced-motion alternative?

## Decision Tree

- Use CSS first for trivial hover/focus color or opacity changes.
- Use Motion components when animation follows React state, props, or component lifecycle.
- Use variants for repeated child choreography and staggered groups.
- Use `useReducedMotion` or MotionConfig for motion-sensitive branches.
- Keep Motion islands scoped so server-rendered or static content stays lean.

## Implementation Rules

- Animate transform and opacity before layout-affecting properties.
- Keep durations short for tools and calmer for editorial scenes.
- Do not animate essential text in ways that delay comprehension.
- Avoid novelty motion on every element.
- Clean up imperative `useAnimate` sequences when components unmount.

## Useful Patterns

- Button tactility: slight y/scale/tint change on hover/tap with focus-visible styling.
- Content reveal: in-view opacity/y with a small stagger and no layout shift.
- State panel: selected card grows subtly while siblings calm down.
- Premium load-in: first viewport elements sequence by semantic priority.

## Anti-Patterns

- Using Motion for every CSS hover color.
- Animating large sections from far off-screen.
- Default spring bounce on luxury or serious product sites.
- No reduced-motion path.

## QA Checklist

- Test mouse, keyboard focus, touch, and reduced-motion behavior.
- Check mount/unmount and route navigation for stale animation state.
- Inspect mobile performance and layout shift.
- Run build/lint for import and client-boundary issues.

## Acceptance Criteria

- Motion is scoped, purposeful, and compatible with React state.
- The interaction feels premium without slowing comprehension.
- Reduced-motion users still get a complete experience.

## Shared scope

For applicable substantial web work, reuse the [shared scoped web contract](../../website-operating-rules/references/scoped-web-contract.md) when available. Preserve current authorization, stack and requested scope; this optional reference does not require another planning or approval cycle.

## Official Source Anchors

- Motion for React: https://motion.dev/docs/react
- Motion AnimatePresence: https://motion.dev/docs/react-animate-presence
- Motion gestures: https://motion.dev/docs/react-gestures
- MDN prefers-reduced-motion: https://developer.mozilla.org/en-US/docs/Web/CSS/Reference/At-rules/@media/prefers-reduced-motion
receiving-code-reviewobra/superpowersUse when receiving code review feedback, before implementing suggestions, especially if feedback seems unclear or technically questionable - requires technical rigor and verification, not performative agreement or blind implementationStars: 319kUpdated Claude CodeCodexVerifiedInstall
requesting-code-reviewobra/superpowersUse when completing tasks, implementing major features, or before merging to verify work meets requirementsStars: 319kUpdated Claude CodeCodexVerifiedInstall
using-git-worktreesobra/superpowersUse when starting feature work that needs isolation from current workspace or before executing implementation plans - ensures an isolated workspace exists via native tools or git worktree fallbackStars: 319kUpdated Claude CodeCodexVerifiedInstall
verification-before-completionobra/superpowersUse when about to claim work is complete, fixed, or passing, before committing or creating PRs - requires running verification commands and confirming output before making any success claims; evidence before assertions alwaysStars: 319kUpdated Claude CodeCodexVerifiedInstall