diff --git a/docs/design/specs/ui/spec-ui-motion.md b/docs/design/specs/ui/spec-ui-motion.md new file mode 100644 index 0000000..bc54946 --- /dev/null +++ b/docs/design/specs/ui/spec-ui-motion.md @@ -0,0 +1,457 @@ +# 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ế @@ -59,17 +96,22 @@ export function Hero() { - + - -
+ + Profile photo -
- + + ) } diff --git a/src/components/sections/Projects.tsx b/src/components/sections/Projects.tsx index 6f5815d..0a98d5d 100644 --- a/src/components/sections/Projects.tsx +++ b/src/components/sections/Projects.tsx @@ -1,60 +1,103 @@ -import { Badge } from '@/components/ui/Badge' -import { projects } from '@/data/projects' +import { motion } from "motion/react" +import { Badge } from "@/components/ui/Badge" +import { projects } from "@/data/projects" +import { InView } from "@/components/ui/InView" const categoryLabels: Record = { - 'software-engineering': 'Software Engineering', - logistics: 'Logistics', - 'ai-ml': 'AI / ML', - 'computer-vision': 'Computer Vision', - architecture: 'Architecture', - experiment: 'Experiment', + "software-engineering": "Software Engineering", + logistics: "Logistics", + "ai-ml": "AI / ML", + "computer-vision": "Computer Vision", + architecture: "Architecture", + experiment: "Experiment", } export function Projects() { const featured = projects.filter((p) => p.featured).slice(0, 4) return ( -
-
-

Featured Projects

- - View All → - -
-
+ {project.metrics && project.metrics.length > 0 && ( +
+ {project.metrics.map((m) => ( + + {m} + + ))} +
+ )} + View Details → + + ))} + + + ) } diff --git a/src/components/ui/Button.tsx b/src/components/ui/Button.tsx index ca0da91..d626550 100644 --- a/src/components/ui/Button.tsx +++ b/src/components/ui/Button.tsx @@ -1,10 +1,11 @@ -import { forwardRef } from 'react' -import type { ComponentPropsWithoutRef } from 'react' +import { motion } from "motion/react" +import { forwardRef } from "react" +import type { ComponentPropsWithoutRef } from "react" -type ButtonVariant = 'primary' | 'secondary' | 'ghost' -type ButtonSize = 'sm' | 'md' | 'lg' +type ButtonVariant = "primary" | "secondary" | "ghost" +type ButtonSize = "sm" | "md" | "lg" -interface ButtonProps extends ComponentPropsWithoutRef<'button'> { +interface ButtonProps extends ComponentPropsWithoutRef<"button"> { variant?: ButtonVariant size?: ButtonSize href?: string @@ -13,36 +14,61 @@ interface ButtonProps extends ComponentPropsWithoutRef<'button'> { } const variantClasses: Record = { - primary: 'btn btn-primary', - secondary: 'btn btn-secondary', - ghost: 'btn btn-ghost', + primary: "btn btn-primary", + secondary: "btn btn-secondary", + ghost: "btn btn-ghost", } const sizeClasses: Record = { - sm: 'btn-sm', - md: '', - lg: 'btn-lg', + sm: "btn-sm", + md: "", + lg: "btn-lg", } export const Button = forwardRef< HTMLButtonElement | HTMLAnchorElement, ButtonProps ->(({ variant = 'primary', size = 'md', href, className = '', children, ...props }, ref) => { - const classes = `${variantClasses[variant]} ${sizeClasses[size]} ${className}`.trim() +>( + ( + { + variant = "primary", + size = "md", + href, + className = "", + children, + ...props + }, + ref + ) => { + const classes = `${variantClasses[variant]} ${sizeClasses[size]} ${className}`.trim() + + if (href) { + return ( + } + + whileTap={{ scale: 0.95 }} + {...(props as Omit, keyof ButtonProps>)} + > + {children} + + ) + } - if (href) { return ( - } {...(props as React.AnchorHTMLAttributes)}> + } + + whileTap={{ scale: 0.95 }} + {...(props as Omit, keyof ButtonProps>)} + > {children} - + ) } +) - return ( - - ) -}) - -Button.displayName = 'Button' +Button.displayName = "Button" diff --git a/src/components/ui/InView.tsx b/src/components/ui/InView.tsx new file mode 100644 index 0000000..aedc2d6 --- /dev/null +++ b/src/components/ui/InView.tsx @@ -0,0 +1,30 @@ +import { motion, type MotionProps } from "motion/react" +import type { 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} + + ) +} diff --git a/src/components/ui/OpenToWorkBadge.tsx b/src/components/ui/OpenToWorkBadge.tsx index ef28ff0..5b97efa 100644 --- a/src/components/ui/OpenToWorkBadge.tsx +++ b/src/components/ui/OpenToWorkBadge.tsx @@ -1,23 +1,33 @@ -import { profile } from '@/data/profile' +import { motion } from "motion/react" export function OpenToWorkBadge() { return ( -
- - + + + - Open to Work - {profile.title} -
+ + #OpenToWork + + ) } diff --git a/src/components/ui/SocialLinks.tsx b/src/components/ui/SocialLinks.tsx index 5c356be..63f1be6 100644 --- a/src/components/ui/SocialLinks.tsx +++ b/src/components/ui/SocialLinks.tsx @@ -1,8 +1,10 @@ +import { motion } from "motion/react" + interface SocialLink { label: string href: string icon: React.ReactNode - 'aria-label': string + "aria-label": string } interface SocialLinksProps { @@ -10,21 +12,23 @@ interface SocialLinksProps { className?: string } -export function SocialLinks({ links, className = '' }: SocialLinksProps) { +export function SocialLinks({ links, className = "" }: SocialLinksProps) { return (
{links.map((link) => ( - {link.icon} {link.label} - + ))}
) diff --git a/src/main.tsx b/src/main.tsx index bef5202..317fe21 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -1,8 +1,13 @@ +import { motion } from 'motion/react' import { StrictMode } from 'react' import { createRoot } from 'react-dom/client' import './index.css' import App from './App.tsx' +// motion v14 has motion.config for reducedMotion but TS types don't expose it +const motionWithConfig = motion as any +motionWithConfig.config.reducedMotion = 'user' + createRoot(document.getElementById('root')!).render(