# UI Spec - Motion Animations (Homepage) ## Overview Thêm animations cho toàn bộ homepage sử dụng **motion** library (`motion/react`). Tất cả animations dùng motion API, không CSS keyframes. --- ## Dependency ```bash pnpm add motion ``` ```tsx import { motion } from "motion/react" ``` --- ## Animation Categories ### 1. Enter Animations (Page Load) | Component | Prop | Values | Transition | |---|---|---|---| | Hero container | `initial` → `animate` | `opacity: 0, x: -30` → `opacity: 1, x: 0` | `duration: 0.6, delay: 0.2` | | Hero name | `initial` → `animate` | `opacity: 0, y: 20` → `opacity: 1, y: 0` | `duration: 0.5, delay: 0.3` | | Hero title | `initial` → `animate` | `opacity: 0, y: 20` → `opacity: 1, y: 0` | `duration: 0.5, delay: 0.4` | | Hero tagline | `initial` → `animate` | `opacity: 0, y: 20` → `opacity: 1, y: 0` | `duration: 0.5, delay: 0.5` | | Hero CTA buttons | `initial` → `animate` | `opacity: 0, y: 20` → `opacity: 1, y: 0` | `duration: 0.5, delay: 0.6` | | Hero visual (photo) | `initial` → `animate` | `opacity: 0, x: 30` → `opacity: 1, x: 0` | `duration: 0.6, delay: 0.4` | | OpenToWorkBadge | `initial` → `animate` | `opacity: 0, y: -20` → `opacity: 1, y: 0` | `duration: 0.5, delay: 0.3` | ### 2. Gesture Animations (Hover/Tap) | Component | Prop | Values | |---|---|---| | CTA buttons | `whileHover` | `scale: 1.05` | | CTA buttons | `whileTap` | `scale: 0.95` | | Project cards | `whileHover` | `scale: 1.02, y: -4` | | Project cards | `whileTap` | `scale: 0.98` | | Social links | `whileHover` | `scale: 1.1` | | Social links | `whileTap` | `scale: 0.9` | | Skill items | `whileHover` | `scale: 1.05, y: -2` | | Skill items | `whileTap` | `scale: 0.98` | ### 3. Scroll Animations (whileInView) | Component | Prop | Values | |---|---|---| | Section titles | `initial` → `whileInView` | `opacity: 0, y: 30` → `opacity: 1, y: 0` | | Expertise cards | `initial` → `whileInView` | `opacity: 0, y: 30` → `opacity: 1, y: 0` | | Experience entries | `initial` → `whileInView` | `opacity: 0, y: 30` → `opacity: 1, y: 0` | | Project cards | `initial` → `whileInView` | `opacity: 0, y: 30` → `opacity: 1, y: 0` | | Contact section | `initial` → `whileInView` | `opacity: 0, y: 30` → `opacity: 1, y: 0` | **Viewport config:** ```tsx viewport={{ once: true, amount: 0.1 }} transition={{ duration: 0.5 }} ``` --- ## Reusable Components ### `src/components/ui/InView.tsx` Wrapper component cho scroll animations. ```tsx import { motion, type MotionProps } from "motion/react" import { ReactNode } from "react" interface InViewProps extends Omit { children: ReactNode delay?: number threshold?: number className?: string } export function InView({ children, delay = 0, threshold = 0.1, className, ...props }: InViewProps) { return ( {children} ) } ``` **Usage:** ```tsx

Section Title

``` ### `src/components/ui/GestureButton.tsx` Wrapper cho hover/tap animations. ```tsx import { motion, type MotionProps } from "motion/react" import { ComponentPropsWithRef, ElementType } from "react" interface GestureButtonProps extends MotionProps { as?: ElementType className?: string children: React.ReactNode } export function GestureButton({ as: Tag = "button", className, ...props }: GestureButtonProps) { const MotionTag = motion(Tag as any) return ( ) } ``` --- ## Component Updates ### `src/components/sections/Hero.tsx` Wrap các phần tử với motion: ```tsx import { motion } from "motion/react" export function Hero() { return ( {profile.name} {profile.title} {profile.tagline} {resumeAvailable && ( )} Profile photo ) } ``` ### `src/components/ui/Button.tsx` Thêm hover/tap animation: ```tsx import { motion } from "motion/react" // Thay thế