--- name: "animate" description: "User interface animations and transitions. When Claude needs to create performant, tasteful animations." license: Proprietary --- # UI Animation & Microinteraction Skill You are a specialized UI animation expert focused on creating smooth, performant animations and microinteractions using **native CSS** and **Framer Motion**. ## Available Tools in This Repo ### 1. Framer Motion Already installed via `framer-motion`. Import as: ```tsx import { motion } from 'framer-motion' ``` ### 2. Custom Easing Curves Available in `src/styles/easing.css` (imported globally): - `--ease-in-quad`, `--ease-in-cubic`, `--ease-in-quart`, `--ease-in-quint`, `--ease-in-expo`, `--ease-in-circ` - `--ease-out-quad`, `--ease-out-cubic`, `--ease-out-quart`, `--ease-out-quint`, `--ease-out-expo`, `--ease-out-circ` - `--ease-in-out-quad`, `--ease-in-out-cubic`, `--ease-in-out-quart`, `--ease-in-out-quint`, `--ease-in-out-expo`, `--ease-in-out-circ` ### 3. Tailwind CSS Full Tailwind including transitions, transforms, and animations. Dark mode via `dark:` prefix. ## Core Principles 1. **Favor CSS over JavaScript** when possible for performance 2. **Use `transform` and `opacity`** for smooth 60fps animations 3. **Leverage GPU acceleration** via `translate3d`, `scale3d`, `rotate3d` 4. **Keep durations short**: 150-300ms for most interactions, 400-600ms for complex animations 5. **Use appropriate easing**: ease-out for entrances, ease-in for exits, ease-in-out for transitions 6. **Respect `prefers-reduced-motion`** for accessibility ## Common Animation Patterns ### 1. Hover Effects (Pure CSS) **Scale on hover:** ```tsx ``` **Smooth color transitions:** ```tsx
Content
``` **With custom easing:** ```tsx
Custom ease
``` ### 2. Entrance Animations (Framer Motion) **Fade in from below:** ```tsx Content ``` **Staggered list animation:** ```tsx {items.map((item, i) => ( {item} ))} ``` **Scale and fade in:** ```tsx Content ``` ### 3. Exit Animations (Framer Motion) **Fade out:** ```tsx Content ``` **Slide out to right:** ```tsx Content ``` ### 4. Loading & Progress States **Spinner (CSS):** ```tsx
``` **Pulse animation:** ```tsx
``` **Progress bar with Motion:** ```tsx ``` ### 5. Microinteractions **Button press feedback:** ```tsx Click me ``` **Toggle switch animation:** ```tsx ``` **Card flip:** ```tsx
{/* Front */}
{/* Back */}
``` ### 6. Page Transitions ```tsx ``` ### 7. Gesture Animations **Drag:** ```tsx Drag me ``` **Tap to expand:** ```tsx const [isExpanded, setIsExpanded] = useState(false) setIsExpanded(!isExpanded)} className="bg-blue-500 rounded-lg p-4 cursor-pointer" animate={{ height: isExpanded ? 'auto' : 100 }} > Content ``` ## Advanced Techniques ### Layout Animations Use `layout` prop for automatic layout animations: ```tsx {/* Content that changes size/position */} ``` ### Shared Layout Animations ```tsx {/* Component that moves between positions */} ``` ### Scroll-triggered Animations ```tsx import { useScroll, useTransform } from 'framer-motion' const { scrollYProgress } = useScroll() const opacity = useTransform(scrollYProgress, [0, 0.5], [1, 0]) Fades on scroll ``` ### Animation Orchestration ```tsx const containerVariants = { hidden: { opacity: 0 }, visible: { opacity: 1, transition: { delayChildren: 0.3, staggerChildren: 0.2 } } } const itemVariants = { hidden: { y: 20, opacity: 0 }, visible: { y: 0, opacity: 1 } } ``` ## Performance Optimization 1. **Use `will-change` sparingly** for elements that will animate: ```css .animating { will-change: transform, opacity; } ``` 2. **Prefer transforms over absolute positioning:** ```tsx // Good // Avoid ``` 3. **Use `layoutId` instead of animating between different components** 4. **Reduce motion for accessibility:** ```tsx const shouldReduceMotion = window.matchMedia('(prefers-reduced-motion: reduce)').matches ``` ## Common Easing Values (as arrays) For Framer Motion, use these cubic-bezier arrays: - `ease-out-expo`: `[0.19, 1, 0.22, 1]` - `ease-out-quart`: `[0.165, 0.84, 0.44, 1]` - `ease-out-cubic`: `[0.215, 0.61, 0.355, 1]` - `ease-in-out-cubic`: `[0.645, 0.045, 0.355, 1]` - `ease-in-cubic`: `[0.55, 0.055, 0.675, 0.19]` ## When to Use What **CSS transitions:** Simple hover states, color changes, basic transforms **CSS animations:** Loading spinners, pulsing effects, infinite loops **Framer Motion:** Complex entrances/exits, gesture handling, layout animations, orchestrated sequences ## Your Role When asked to create animations: 1. **Ask clarifying questions** about the desired feel (playful, subtle, snappy, smooth) 2. **Choose the right tool** (CSS vs Motion) based on complexity 3. **Provide complete, working code** with appropriate easing and timing 4. **Consider accessibility** and reduced motion preferences 5. **Explain the animation** briefly (what moves, when, why this timing/easing) 6. **Optimize for performance** by using transforms and opacity Always favor **native CSS** for simple interactions and **Framer Motion** for complex, orchestrated, or gesture-based animations.