feat: homepage enhancements - mobile padding, scroll animations, parallax, background gradient

- Fix mobile padding: add media queries for container and hero-content padding
- Add InView wrapper to Hero and About for scroll-triggered animations
- Add Hero parallax effect: photo moves on scroll, content fades out
- Add section background gradient for smooth visual flow between sections
- Unify section containers to container-wide for title alignment
- Add maxWidth wrappers for text-heavy sections (About, Experience, Contact)
- Replace OpenToWorkBadge with RollingTextLink component
- Update nav router links and profile data
- Add spec docs for v2 homepage enhancements and nav rolling text
This commit is contained in:
dong.nguyen committed 2026-10-06 23:42:49 +07:00
1 parent 1800fa7ceb
commit aa30aed903
20 files changed
+1301 -326

No files matched your search

+36
View File
@@ -0,0 +1,36 @@
# Agent Rules
## 1. General Principles
- Understand the existing codebase before making changes.
- Prefer simple, maintainable solutions over clever solutions.
- Do not introduce unnecessary dependencies.
- Do not rewrite working code unless there is a clear reason.
- Preserve existing behavior unless the task explicitly requires a behavior change.
- Follow the existing project architecture and coding conventions.
- Keep changes small and focused on the requested task.
## 2. Before Making Changes
Before modifying code:
1. Inspect the relevant project structure.
2. Identify the modules/classes/components affected.
3. Read the existing implementation and related tests.
4. Identify existing utilities that can be reused.
5. Check whether similar functionality already exists.
6. Understand the data flow before changing it.
Do not start coding based only on the user's description.
## 3. Change Workflow
1. **Investigate** — research the issue using the steps in Section 2.
2. **Report** — present findings: root cause, affected files, proposed fix.
3. **Confirm** — wait for user approval before applying any code changes.
4. **Execute** — apply the approved change, verify, then report results.
## 4. Conversation language
**IMPORTANT:** All responses are in Vietnamese. Source code and docs are in English.
## 5. Don't run the headless browser to verify. It costs so times to complete. I will verify the result in real browser and tell you if the change works.
+3 -3
View File
@@ -11,7 +11,7 @@ Personal engineering portfolio — multi-page SPA built with React + TypeScript
| Framework | React 19 |
| Language | TypeScript 6 (bundler mode, `verbatimModuleSyntax`, `noEmit`) |
| Bundler | Vite 8 |
| Router | React Router DOM v6 (pin `6.30.6` — do NOT upgrade to v7) |
| Router | React Router v8 (`react-router` package, pinned `8.4.0`) |
| Linter | Oxlint 1 (`plugins: react, typescript, oxc`) |
| Package manager | pnpm |
@@ -82,8 +82,8 @@ src/
## Known Issues & Gotchas
1. **React Router v6 routing:** Use `<Layout><Routes>...</Routes></Layout>`, NOT `<Route element={<Layout />}>` with nested routes — the latter doesn't pass `children` correctly
2. **React Router v6 pin:** `package.json` has `"react-router-dom": "6.30.6"` (exact, no `^`) — v7 breaks the build and routing
1. **React Router v8 routing:** Use `<Layout><Routes>...</Routes></Layout>`, NOT `<Route element={<Layout />}>` with nested routes — the latter doesn't pass `children` correctly
2. **Import path:** All router imports use `react-router` (not `react-router-dom`) — e.g., `import { Link, useLocation } from 'react-router'`
3. **Theme cycle:** `cycleTheme` dependency array must be `[]` (empty), NOT `[setTheme]` — `setTheme` is not used inside `cycleTheme`
4. **Theme from system:** When stored theme is `'system'`, `cycleTheme` must skip to opposite theme on first click (not go to `'dark'` which resolves to same visual)
5. **Footer/Nav links:** Must use `<Link to>`, not `<a href>` for client-side navigation
@@ -0,0 +1,272 @@
# Fix: Navigation & Router Links Causing Full Page Reloads
## Problem
Internal navigation links cause full page reloads instead of client-side routing. Root causes:
1. **RollingTextLink** (`src/components/ui/RollingTextLink.tsx`) — renders `<a href={to}>` for all nav items
2. **Button** (`src/components/ui/Button.tsx`) — renders `<motion.a href={href}>` for all href values, including internal routes
3. **Projects** (`src/components/sections/Projects.tsx`) — uses `<motion.a href="/projects">` and `<motion.a href="/projects/:id">`
## Changes
### 1. `src/components/ui/RollingTextLink.tsx`
Replace `<a>` with React Router `<Link>`.
```diff
import { Link } from "react-router"
- return (
- <a
- href={to}
- className={className}
- onClick={onClick}
- onPointerEnter={() => { hovered.current = true; requestActive(true) }}
- onPointerLeave={() => { hovered.current = false; requestActive(focused.current) }}
- onFocus={() => { focused.current = true; requestActive(true) }}
- onBlur={() => { focused.current = false; requestActive(hovered.current) }}
- >
+ return (
+ <Link
+ to={to}
+ className={className}
+ onClick={onClick}
+ onPointerEnter={() => { hovered.current = true; requestActive(true) }}
+ onPointerLeave={() => { hovered.current = false; requestActive(focused.current) }}
+ onFocus={() => { focused.current = true; requestActive(true) }}
+ onBlur={() => { focused.current = false; requestActive(hovered.current) }}
+ >
<span style={{ position: "relative", display: "inline-block", overflow: "hidden" }}>
<motion.span
style={{ display: "block", whiteSpace: "nowrap" }}
variants={outgoingVariants}
initial="rest"
animate={active ? "active" : "rest"}
onAnimationComplete={completeAnimation}
transition={transition}
>
{children}
</motion.span>
<motion.span
style={{
display: "block",
whiteSpace: "nowrap",
position: "absolute",
inset: 0,
}}
variants={incomingVariants}
initial="rest"
animate={active ? "active" : "rest"}
transition={transition}
>
{children}
</motion.span>
</span>
- </a>
+ </Link>
)
```
**Rationale:** `<Link>` renders an `<a>` element under the hood but intercepts click events for client-side navigation. Animation event handlers (`onPointerEnter`, `onFocus`, etc.) work identically since the DOM element is the same.
---
### 2. `src/components/ui/Button.tsx`
Detect internal routes (`href` starts with `/`) → use `motion(Link)`. External URLs keep `motion.a`.
```diff
import { Link } from "react-router"
type ButtonVariant = "primary" | "secondary" | "ghost"
type ButtonSize = "sm" | "md" | "lg"
interface ButtonProps extends ComponentPropsWithoutRef<"button"> {
variant?: ButtonVariant
size?: ButtonSize
href?: string
download?: boolean
children: React.ReactNode
}
// ... variantClasses, sizeClasses unchanged ...
export const Button = forwardRef<
HTMLButtonElement | HTMLAnchorElement,
ButtonProps
>(
(
{
variant = "primary",
size = "md",
href,
className = "",
children,
+ download,
...props
},
ref
) => {
const classes = `${variantClasses[variant]} ${sizeClasses[size]} ${className}`.trim()
if (href) {
+ const isRoute = href.startsWith("/")
+ const safeProps = { ...props }
+ if (isRoute) {
+ delete (safeProps as Record<string, unknown>)["download"]
+ }
+
+ if (isRoute) {
+ return (
+ <motion(Link
+ to={href}
+ className={classes}
+ ref={ref as React.Ref<HTMLAnchorElement>}
+ whileTap={{ scale: 0.95 }}
+ {...(safeProps as Omit<
+ React.AnchorHTMLAttributes<HTMLAnchorElement>,
+ keyof ButtonProps | "to"
+ >)}
+ >
+ {children}
+ </motion(Link)>
+ )
+ }
+
return (
<motion.a
href={href}
className={classes}
ref={ref as React.Ref<HTMLAnchorElement>}
whileTap={{ scale: 0.95 }}
{...(props as Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof ButtonProps>)}
>
{children}
</motion.a>
)
}
return (
<motion.button
className={classes}
ref={ref as React.Ref<HTMLButtonElement>}
whileTap={{ scale: 0.95 }}
{...(props as Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, keyof ButtonProps>)}
>
{children}
</motion.button>
)
}
)
```
**Rationale:**
- Internal routes (`/projects`, `/contact`) → `motion(Link)` for client-side nav
- External URLs (GitHub, LinkedIn) → `motion.a` unchanged
- `download` prop stripped for internal routes (invalid on `<Link>`, no-op on same-origin `<a>`)
---
### 3. `src/components/sections/Projects.tsx`
Replace `<motion.a>` with `motion(Link)` for project cards and "View All" link.
```diff
import { Link } from "react-router"
import { motion } from "motion/react"
import { Badge } from "@/components/ui/Badge"
import { projects } from "@/data/projects"
import { InView } from "@/components/ui/InView"
// ... categoryLabels, Projects function start unchanged ...
<motion.div
initial="hidden"
whileInView="visible"
viewport={{ once: true, amount: 0.5 }}
variants={{
hidden: { opacity: 0 },
visible: { opacity: 1, transition: { staggerChildren: 0.05 } },
}}
>
<h2 id="projects-heading">Featured Projects</h2>
- <motion.a
- href="/projects"
- style={{ fontSize: "14px", fontWeight: 500, color: "var(--accent)" }}
- whileHover={{ scale: 1.05 }}
- whileTap={{ scale: 0.95 }}
- >
+ <motion(Link
+ to="/projects"
+ style={{ fontSize: "14px", fontWeight: 500, color: "var(--accent)" }}
+ whileHover={{ scale: 1.05 }}
+ whileTap={{ scale: 0.95 }}
+ >
View All →
- </motion.a>
+ </motion(Link)>
</motion.div>
<div className="projects-grid">
{featured.map((project, i) => (
- <motion.a
- key={project.id}
- href={`/projects/${project.id}`}
+ <motion(Link
+ key={project.id}
+ to={`/projects/${project.id}`}
className="project-card"
variants={{
hidden: { opacity: 0, y: 30 },
visible: {
opacity: 1,
y: 0,
transition: { duration: 0.5, delay: i * 0.1 },
},
}}
whileHover={{ scale: 1.02, y: -4 }}
whileTap={{ scale: 0.98 }}
>
{/* card content unchanged */}
- </motion.a>
+ </motion(Link)>
))}
</div>
```
**Rationale:** `motion(Link)` passes `whileHover`/`whileTap` to the underlying `<a>` element. Animation behavior is identical.
---
### 4. `src/components/sections/Hero.tsx`
Replace `download` with `target="_blank"` for resume PDF link.
```diff
-<Button href="/resume.pdf" variant="secondary" download>
+<Button href="/resume.pdf" variant="secondary" target="_blank">
Download Resume
</Button>
```
**Rationale:**
- `download` attribute has no effect on same-origin URLs (browsers ignore it)
- Button already strips `download` for internal routes (now `/resume.pdf` is treated as a route)
- `target="_blank"` opens PDF in new tab, which is the expected behavior
---
## Verification
| Element | Expected Behavior |
|---|---|
| Nav menu items (Home, About, etc.) | Client-side nav, no page reload |
| Logo "Portfolio" | Client-side nav to `/`, no reload |
| Mobile menu items | Client-side nav + menu auto-closes |
| "View Projects" button | Client-side nav to `/projects` |
| "Contact Me" button | Client-side nav to `/contact` |
| "Download Resume" button | Opens `/resume.pdf` in new tab |
| "View All →" link | Client-side nav to `/projects` |
| Project cards | Client-side nav to `/projects/:id` |
| Social links (GitHub, LinkedIn) | Open in new tab (unchanged) |
| Skip-to-content link | Jumps to `#main-content` on same page |
-1
View File
@@ -427,7 +427,6 @@ motion.config.reducedMotion = "user"
| File | Action | Changes |
|---|---|---|
| `package.json` | Modify | Add `motion` dependency |
| `src/components/ui/OpenToWorkBadge.tsx` | Rewrite | motion + SVG spring + hashtag |
| `src/components/sections/Hero.tsx` | Modify | motion enter animations |
| `src/components/ui/Button.tsx` | Modify | motion hover/tap |
| `src/components/ui/InView.tsx` | **New** | Reusable scroll wrapper |
-229
View File
@@ -1,229 +0,0 @@
# UI Spec - Open to Work Badge (Redesign)
## Overview
Thay thế badge "Open to Work" hiện tại bằng badge dạng hashtag `#OpenToWork` với spring coil SVG phía sau và swaying animation, sử dụng motion library.
---
## Structure
```
otw-container (motion.div, position absolute, góc trên-trái)
├── otw-spring (SVG, spring coil, phía sau)
│ └── path (motion.path, swaying)
└── otw-badge (motion.div, hashtag text, phía trước)
└── #OpenToWork (span)
```
---
## Spring Coil SVG
### Design
- Shape: lò xo xoắn 1.5 vòng (3 vòng bán) + tail
- Stroke: `var(--accent)`, strokeWidth: 2, strokeLinecap: round
- ViewBox: `0 0 60 120` (dọc)
- Position: phía sau badge, offset một chút
- Width: 40px, Height: 80px
### Path data
```
M 30 0
C 50 5, 50 15, 30 20
C 10 25, 10 35, 30 40
C 50 45, 50 55, 30 60
C 10 65, 10 75, 30 80
C 50 85, 50 95, 30 100
C 10 105, 10 115, 30 120
L 30 125
```
### Animation (motion)
```tsx
<motion.path
d="M 30 0 C 50 5, 50 15, 30 20 C 10 25, 10 35, 30 40
C 50 45, 50 55, 30 60 C 10 65, 10 75, 30 80
C 50 85, 50 95, 30 100 C 10 105, 10 115, 30 120 L 30 125"
stroke="var(--accent)"
fill="none"
strokeWidth="2"
strokeLinecap="round"
animate={{ rotate: [-8, 8, -8] }}
transition={{ duration: 3, repeat: Infinity, ease: "easeInOut" }}
/>
```
---
## Badge
### Content
- `#OpenToWork` (text duy nhất)
- Font: monospace, bold, 20px
- Color: `var(--accent)` (theme-aware, light/dark)
- Background: transparent
- Padding: 8px 16px
- Border-radius: 8px
### Position
- Góc trên-trái của `hero-visual`
- Offset: top: 20px, left: 20px
- Z-index: cao hơn spring
### Animation (motion)
```tsx
<motion.div
className="otw-badge"
animate={{ rotate: [-8, 8, -8] }}
transition={{ duration: 3, repeat: Infinity, ease: "easeInOut" }}
/>
```
### Container animation (motion)
```tsx
<motion.div
className="otw-container"
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.3, duration: 0.5 }}
/>
```
---
## Swaying Animation
### Rotation oscillate
- Range: `-8° → +8° → -8°`
- Duration: 3s
- Easing: ease-in-out
- Repeat: Infinity
- Transform-origin: top center (motion default)
### Reduced motion
- `prefers-reduced-motion: reduce` → motion library auto-handles
- Không cần CSS media query
---
## Responsive
### Desktop (>768px)
- Badge: góc trên-trái hero-visual
- Spring: phía sau badge
- Font-size: 20px
- Rotation: `-8° → +8°`
### Mobile (≤768px)
- Badge: góc trên-trái hero section
- Spring: phía sau badge
- Font-size: 16px
- Rotation: `-4° → +4°` (nhẹ hơn)
- Position: top: 16px, left: 16px
---
## Component Implementation
### `src/components/ui/OpenToWorkBadge.tsx`
```tsx
import { motion } from "motion/react"
export function OpenToWorkBadge() {
return (
<motion.div
className="otw-container"
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.3, duration: 0.5 }}
>
<svg className="otw-spring" viewBox="0 0 60 120">
<motion.path
d="M 30 0 C 50 5, 50 15, 30 20 C 10 25, 10 35, 30 40
C 50 45, 50 55, 30 60 C 10 65, 10 75, 30 80
C 50 85, 50 95, 30 100 C 10 105, 10 115, 30 120 L 30 125"
stroke="var(--accent)"
fill="none"
strokeWidth="2"
strokeLinecap="round"
animate={{ rotate: [-8, 8, -8] }}
transition={{ duration: 3, repeat: Infinity, ease: "easeInOut" }}
/>
</svg>
<motion.div
className="otw-badge"
animate={{ rotate: [-8, 8, -8] }}
transition={{ duration: 3, repeat: Infinity, ease: "easeInOut" }}
>
<span>#OpenToWork</span>
</motion.div>
</motion.div>
)
}
```
---
## CSS Changes
### Removed (from current):
- `.otw-badge` current styles (bg, padding, shadow, etc.)
- `.otw-icon` styles
### New CSS:
```css
.otw-container {
position: absolute;
top: 20px;
left: 20px;
z-index: 10;
display: flex;
align-items: center;
gap: 8px;
}
.otw-spring {
width: 40px;
height: 80px;
flex-shrink: 0;
}
.otw-badge {
font-family: monospace;
font-size: 20px;
font-weight: 700;
color: var(--accent);
padding: 8px 16px;
border-radius: 8px;
white-space: nowrap;
}
/* Mobile */
@media (max-width: 768px) {
.otw-container {
top: 16px;
left: 16px;
}
.otw-badge {
font-size: 16px;
}
}
```
---
## Constraints
- Không hard-code màu — dùng CSS `var(--accent)`
- Không che profile photo
- SVG inline trong component (không file ngoài)
- Accessibility: aria-label cho badge
- Animation respects `prefers-reduced-motion` (motion library auto-handled)
- Tất cả animations dùng motion library, không CSS keyframes
@@ -0,0 +1,311 @@
# Homepage Enhancements — Section Improvements
## Overview
Enhance all homepage sections with three improvements:
1. Proper mobile padding (text not too close to edges)
2. Smooth scroll transitions between sections
3. Unified container width for consistent alignment
---
## 1. Mobile Padding Fix
### Problem
On small screens (≤768px), text content is too close to the left/right edges due to fixed `padding: 0 24px`.
### Current
```css
/* src/index.css */
.container-wide,
.container-content,
.container-narrow {
padding: 0 24px; /* fixed, all screen sizes */
}
.section {
padding: 80px 0;
}
@media (max-width: 768px) {
.section {
padding: 48px 0; /* vertical only */
}
}
```
### Proposed
**src/index.css** — Add two media queries for container padding:
```css
/* Mobile: ≤768px */
@media (max-width: 768px) {
.section {
padding: 48px 0;
}
.container-wide,
.container-content,
.container-narrow {
padding-left: 32px;
padding-right: 32px;
}
}
/* Medium: 769px–1200px */
@media (min-width: 769px) and (max-width: 1200px) {
.container-wide,
.container-content,
.container-narrow {
padding-left: 40px;
padding-right: 40px;
}
}
```
**src/App.css** — Add hero-content padding for medium screens:
```css
/* Medium: 769px–1200px */
@media (min-width: 769px) and (max-width: 1200px) {
.hero-content {
padding-left: 16px;
padding-right: 16px;
}
}
```
### Breakpoints
| Screen size | Container padding | Hero-content padding |
|---|---|---|
| ≤768px (mobile) | 32px | 24px (already set) |
| 769px–1200px (tablet/laptop) | 40px | 16px (new) |
| >1200px (desktop) | 24px | 0 |
### Files
- `src/index.css`
- `src/App.css`
---
## 2. Smooth Scroll Transitions
### Problem
- `Hero` and `About` have no scroll animations
- No scroll-driven parallax effects
- Section transitions feel abrupt
### Current State
| Section | Animation |
|---|---|
| Hero | Fade-in (opacity only, no scroll trigger) |
| About | No animation |
| Expertise | `whileInView` fade-in + slide-up |
| Experience | `whileInView` fade-in + slide-up |
| Projects | `whileInView` fade-in + slide-up |
| Contact | `whileInView` fade-in + slide-up |
### Proposed Changes
#### 2.1 Add `InView` Wrapper for Hero + About
**Hero.tsx:** Wrap section with `InView` to trigger scroll animation:
```tsx
import { InView } from "@/components/ui/InView"
export function Hero() {
return (
<InView>
<motion.section
className="hero container-wide"
// ... existing motion props
>
{/* content */}
</motion.section>
</InView>
)
}
```
**About.tsx:** Wrap section with `InView`:
```tsx
import { InView } from "@/components/ui/InView"
export function About() {
return (
<InView>
<section className="section container-content" aria-labelledby="about-heading">
{/* content */}
</section>
</InView>
)
}
```
#### 2.2 Hero Parallax Effect
Add scroll-driven parallax: hero photo moves on scroll, hero content fades out.
```tsx
import { motion, useScroll, useTransform } from "motion/react"
export function Hero() {
const { scrollY } = useScroll()
const y = useTransform(scrollY, [0, 300], [0, -80])
const opacity = useTransform(scrollY, [0, 200], [1, 0.3])
return (
<motion.section className="hero container-wide">
<motion.div className="hero-content" style={{ opacity }}>
{/* content */}
</motion.div>
<motion.div className="hero-visual" style={{ y }}>
<img src="/profile-photo.webp" alt="Profile photo" className="hero-photo" />
</motion.div>
</motion.section>
)
}
```
**Effect:** Hero photo moves up 80px as user scrolls 300px (parallax). Hero content fades to 30% opacity over first 200px scroll.
#### 2.3 Section Background Gradient
Add subtle gradient transition between sections for smooth visual flow:
```css
/* src/App.css */
.section {
position: relative;
}
.section::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(
to bottom,
transparent 0%,
var(--bg-primary) 10%,
var(--bg-primary) 90%,
transparent 100%
);
pointer-events: none;
z-index: -1;
}
```
**Effect:** Creates a smooth fade from section content to background at top/bottom edges (10% gradient zone).
### Files
- `src/components/sections/Hero.tsx`
- `src/components/sections/About.tsx`
- `src/App.css`
---
## 3. Container Width Alignment
### Problem
Sections alternate between two container widths (1200px ↔ 800px) → titles zigzag, hard to follow vertically.
### Solution
Unify all sections to use `container-wide` (1200px) for consistent title alignment. Text-heavy content gets inner `maxWidth: '700px'` wrapper for readability.
### Changes
**About.tsx:**
```tsx
// Before
<section className="section container-content">
// After
<section className="section container-wide">
```
**Experience.tsx:**
```tsx
// Before
<motion.section className="section container-content">
// After
<motion.section className="section container-wide">
{/* Added wrapper */}
<div style={{ maxWidth: '700px' }}>
<div className="timeline">...</div>
</div>
</motion.section>
```
**Contact.tsx:**
```tsx
// Before
<motion.section className="section container-content">
// After
<motion.section className="section container-wide">
{/* Added wrapper */}
<div style={{ maxWidth: '700px' }}>
<div className="contact-links">...</div>
</div>
</motion.section>
```
### Result
| Section | Container | Content Width |
|---|---|---|
| Hero | `container-wide` | N/A (grid layout) |
| About | `container-wide` | 700px (inner div) |
| Expertise | `container-wide` | N/A (grid layout) |
| Experience | `container-wide` | 700px (inner div) |
| Projects | `container-wide` | N/A (grid layout) |
| Contact | `container-wide` | 700px (inner div) |
All titles now align at the same left position. Grid sections use full width. Text sections constrained to 700px for readability.
### Files
- `src/components/sections/About.tsx`
- `src/components/sections/Experience.tsx`
- `src/components/sections/Contact.tsx`
---
## Implementation Order
| Step | Task | Files | Est. Time |
|---|---|---|---|
| 1 | Mobile padding fix | `src/index.css` | 5m |
| 2 | Add InView to Hero + About | `Hero.tsx`, `About.tsx` | 10m |
| 3 | Hero parallax effect | `Hero.tsx` | 15m |
| 4 | Section background gradient | `src/App.css` | 10m |
| 5 | Build + verify | — | 5m |
**Total:** ~45m
---
## Dependencies
- `motion` (already installed)
- No new dependencies
---
## Acceptance Criteria
1. [ ] On mobile (≤768px), text has 32px padding on both sides (not 24px)
2. [ ] Hero has scroll animation (fadeInUp on viewport entry)
3. [ ] About has scroll animation (fadeInUp on viewport entry)
4. [ ] Hero photo has parallax effect on scroll
5. [ ] All sections have scroll reveal animation (fade-in + slide-up)
6. [ ] Build passes (`tsc -b && vite build`)
7. [ ] No breaking changes to desktop layout
@@ -0,0 +1,251 @@
# Specification - Rolling Text Navigation Links
> **Document:** `spec-v2-nav-rolling-text.md`
> **Version:** 0.1.0
> **Parent:** `spec-ui-navigation.md`
> **Priority:** P2
> **Estimate:** ~45 minutes
---
## Requirement
Apply the rolling text button animation pattern (from `docs/sample-code/rolling-text-button.md`) to navigation menu links in `Navigation.tsx`. On hover/focus, the link text slides out downward while an identical copy slides in from below.
---
## Animation Design
### Pattern
Based on the sample code's dual-span approach:
| Element | Variant | Initial | Hover/Focus |
|---|---|---|---|
| Outgoing `<motion.span>` | `rest` → `active` | `translateY(0%)` | `translateY(100%)` |
| Incoming `<motion.span>` | `rest` → `active` | `translateY(-100%)` | `translateY(0%)` |
### Timing
| Property | Value |
|---|---|
| Duration | `0.3s` |
| Easing | `[0.338, 0.015, 0.395, 0.959]` (custom cubic-bezier, snappy ease-out) |
| Trigger | `onHoverStart`/`onHoverEnd` + `onFocus`/`onBlur` |
### Accessibility
- `useReducedMotion` from `motion/react` disables animation when user prefers reduced motion
- When reduced motion is active, text swaps instantly with no animation
- `aria-hidden="true"` on the animated label spans (text is still read by screen reader via parent `<a>`)
---
## Component Architecture
### `RollingTextLink` — new component
Extracted as a reusable component in `src/components/ui/RollingTextLink.tsx`:
```tsx
import { motion, useReducedMotion } from "motion/react"
import { useRef, useState } from "react"
interface RollingTextLinkProps {
to: string
children: React.ReactNode
className?: string
isActive?: boolean
}
const outgoingVariants = {
rest: { transform: "translateY(0%)" },
active: { transform: "translateY(100%)" },
}
const incomingVariants = {
rest: { transform: "translateY(-100%)" },
active: { transform: "translateY(0%)" },
}
const transition = {
duration: 0.3,
ease: [0.338, 0.015, 0.395, 0.959] as const,
}
export function RollingTextLink({ to, children, className, isActive }: RollingTextLinkProps) {
const reduceMotion = useReducedMotion()
const [active, setActive] = useState(false)
const activeRef = useRef(false)
const animating = useRef(false)
const pendingRequest = useRef<boolean | null>(null)
const hovered = useRef(false)
const focused = useRef(false)
const updateActive = (next: boolean) => {
activeRef.current = next
setActive(next)
}
const requestActive = (next: boolean) => {
if (reduceMotion) return
if (next === activeRef.current) {
pendingRequest.current = null
return
}
if (animating.current) {
pendingRequest.current = next
return
}
animating.current = true
updateActive(next)
}
const completeAnimation = () => {
if (!animating.current) return
animating.current = false
if (pendingRequest.current !== null && pendingRequest.current !== activeRef.current) {
const next = pendingRequest.current
pendingRequest.current = null
animating.current = true
updateActive(next)
} else {
pendingRequest.current = null
}
}
return (
<a
href={to}
className={className}
aria-label={typeof children === 'string' ? children : undefined}
onHoverStart={() => {
hovered.current = true
requestActive(true)
}}
onHoverEnd={() => {
hovered.current = false
requestActive(focused.current)
}}
onFocus={() => {
focused.current = true
requestActive(true)
}}
onBlur={() => {
focused.current = false
requestActive(hovered.current)
}}
>
<span style={{ position: "relative", display: "inline-block", overflow: "hidden" }}>
<motion.span
style={{ display: "block", whiteSpace: "nowrap" }}
variants={outgoingVariants}
initial="rest"
animate={active ? "active" : "rest"}
onAnimationComplete={completeAnimation}
transition={transition}
>
{children}
</motion.span>
<motion.span
style={{
display: "block",
whiteSpace: "nowrap",
position: "absolute",
inset: 0,
}}
variants={incomingVariants}
initial="rest"
animate={active ? "active" : "rest"}
transition={transition}
>
{children}
</motion.span>
</span>
</a>
)
}
```
---
## Integration Points
### Desktop nav links (`<NavLink>` → `<RollingTextLink>`)
Replace in `src/components/layout/Navigation.tsx`:
```tsx
// Before
<NavLink to={item.path} className={({ isActive }) => isActive ? 'nav-link active' : 'nav-link'}>
{item.label}
</NavLink>
// After
<RollingTextLink
to={item.path}
className={({ isActive }) => isActive ? 'nav-link active' : 'nav-link'}
>
{item.label}
</RollingTextLink>
```
### Mobile nav links
Same replacement in the mobile menu section:
```tsx
// Before
<NavLink
to={item.path}
className={({ isActive }) => isActive ? 'mobile-menu-link active' : 'mobile-menu-link'}
onClick={() => setMobileOpen(false)}
>
{item.label}
</NavLink>
// After
<RollingTextLink
to={item.path}
className={({ isActive }) => isActive ? 'mobile-menu-link active' : 'mobile-menu-link'}
onClick={() => setMobileOpen(false)}
>
{item.label}
</RollingTextLink>
```
### CSS — no changes required
The rolling text uses inline styles for the animation container. Existing `.nav-link` and `.mobile-menu-link` classes remain unchanged — color, hover color, active state, and underline all apply to the parent `<a>` as before.
---
## Edge Cases
| Scenario | Behavior |
|---|---|
| Rapid hover enter/leave | `pendingRequest` queue ensures animation completes current frame before starting next |
| `prefers-reduced-motion` | Animation disabled; text swaps instantly |
| Active link (current page) | Text still rolls on hover; `active` class preserved |
| Mobile menu open | Touch triggers `onHoverStart`/`onHoverEnd` equivalents via `onFocus`/`onBlur` |
| Screen reader | Parent `<a>` still contains text node; motion spans have `aria-hidden` |
---
## Acceptance
- [ ] `RollingTextLink` component created in `src/components/ui/RollingTextLink.tsx`
- [ ] Desktop nav links use `RollingTextLink` wrapping label text
- [ ] Mobile nav links use `RollingTextLink` wrapping label text
- [ ] Text slides out downward on hover, new text slides in from below
- [ ] Transition: 0.3s, cubic-bezier `[0.338, 0.015, 0.395, 0.959]`
- [ ] `useReducedMotion` respected — no animation when preferred
- [ ] Rapid hover transitions handled without jank (queue system)
- [ ] Active link state preserved (color + underline)
- [ ] Hover color transition still works (parent `<a>` handles `color`)
- [ ] Builds clean (`pnpm build`) with no type errors
- [ ] Existing `.nav-link` / `.mobile-menu-link` CSS classes unchanged
+194
View File
@@ -0,0 +1,194 @@
```typescript
"use client"
import { motion, useReducedMotion } from "motion/react"
import { useRef, useState } from "react"
const outgoingVariants = {
rest: { transform: "translateY(0%)" },
active: { transform: "translateY(100%)" },
}
const incomingVariants = {
rest: { transform: "translateY(-100%)" },
active: { transform: "translateY(0%)" },
}
const transition = {
duration: 0.3,
ease: [0.338, 0.015, 0.395, 0.959] as const,
}
function ChevronRightIcon() {
return (
<svg
xmlns="http://www.w3.org/2000/svg"
width="1em"
height="1em"
viewBox="0 0 24 24"
fill="none"
stroke="currentColor"
strokeWidth="2"
strokeLinecap="round"
strokeLinejoin="round"
aria-hidden="true"
focusable="false"
>
<path d="m9 18 6-6-6-6" />
</svg>
)
}
export default function RollingTextButton() {
const reduceMotion = useReducedMotion()
const [active, setActive] = useState(false)
const activeRef = useRef(false)
const animating = useRef(false)
const pendingRequest = useRef<boolean | null>(null)
const hovered = useRef(false)
const focused = useRef(false)
const updateActive = (next: boolean) => {
activeRef.current = next
setActive(next)
}
const requestActive = (next: boolean) => {
if (reduceMotion) return
if (next === activeRef.current) {
pendingRequest.current = null
return
}
if (animating.current) {
pendingRequest.current = next
return
}
animating.current = true
updateActive(next)
}
const completeAnimation = () => {
if (!animating.current) return
animating.current = false
if (
pendingRequest.current !== null &&
pendingRequest.current !== activeRef.current
) {
const next = pendingRequest.current
pendingRequest.current = null
animating.current = true
updateActive(next)
} else {
pendingRequest.current = null
}
}
return (
<main className="rolling-button-stage fresh-system">
<motion.button
type="button"
className="fresh-primary-action"
aria-label="Start free"
onHoverStart={() => {
hovered.current = true
requestActive(true)
}}
onHoverEnd={() => {
hovered.current = false
requestActive(focused.current)
}}
onFocus={() => {
focused.current = true
requestActive(true)
}}
onBlur={() => {
focused.current = false
requestActive(hovered.current)
}}
>
<span className="fresh-primary-action-content" aria-hidden="true">
<span className="label-window">
<motion.span
className="label-copy"
variants={outgoingVariants}
initial="rest"
animate={active ? "active" : "rest"}
onAnimationComplete={completeAnimation}
transition={transition}
>
Start free
</motion.span>
<motion.span
className="label-copy label-copy--incoming"
variants={incomingVariants}
initial="rest"
animate={active ? "active" : "rest"}
transition={transition}
>
Start free
</motion.span>
</span>
<span>
<ChevronRightIcon />
</span>
</span>
</motion.button>
<Stylesheet />
</main>
)
}
function Stylesheet() {
return (
<style>{`
html, body {
margin: 0;
min-height: 100%;
}
.rolling-button-stage,
.rolling-button-stage * {
box-sizing: border-box;
}
.rolling-button-stage {
--fresh-accent: var(--lab-blueberry);
display: flex;
align-items: center;
justify-content: center;
width: 100%;
min-height: 100vh;
}
.label-window {
position: relative;
display: block;
width: max-content;
overflow: hidden;
}
.label-copy {
display: block;
white-space: nowrap;
}
.label-copy--incoming {
position: absolute;
inset: 0;
}
@media (hover: hover) {
.rolling-button-stage .fresh-primary-action:hover {
border-color: var(--fresh-primary-background);
}
}
`}</style>
)
}
```
+33 -32
View File
@@ -356,6 +356,25 @@
width: 20px;
height: 20px;
}
/* ===== Section Background Gradient ===== */
.section {
position: relative;
}
.section::before {
content: '';
position: absolute;
inset: 0;
background: linear-gradient(
to bottom,
transparent 0%,
var(--bg-primary) 10%,
var(--bg-primary) 90%,
transparent 100%
);
pointer-events: none;
z-index: -1;
}
/* ===== Hero ===== */
.hero {
@@ -416,36 +435,17 @@
display: block;
}
.otw-container {
position: absolute;
top: 20px;
left: 20px;
z-index: 10;
display: flex;
align-items: center;
gap: 8px;
}
.otw-spring {
width: 40px;
height: 80px;
flex-shrink: 0;
}
.otw-badge {
font-family: monospace;
font-size: 20px;
font-weight: 700;
color: var(--accent);
padding: 8px 16px;
border-radius: 8px;
white-space: nowrap;
}
@media (max-width: 768px) {
.hero {
position: relative;
min-height: 500px;
overflow: hidden;
}
.hero {
max-width: 100%;
margin: 0;
padding: 0;
}
.hero-cta {
flex-direction: column;
}
@@ -459,22 +459,23 @@
inset: 0;
z-index: 0;
}
.hero-content {
position: relative;
position: absolute;
z-index: 1;
background: rgba(0, 0, 0, 0.55);
padding: 32px 24px;
border-radius: 16px;
backdrop-filter: blur(4px);
width: 100%;
}
.otw-container {
top: 16px;
left: 16px;
}
.otw-badge {
font-size: 16px;
}
@media (min-width: 769px) and (max-width: 1200px) {
.hero-content {
padding-left: 16px;
padding-right: 16px;
}
}
/* ===== Expertise Grid ===== */
+8 -11
View File
@@ -1,6 +1,7 @@
import { useState, useEffect } from 'react'
import { Link, NavLink, useLocation } from 'react-router'
import { Link, useLocation } from 'react-router'
import { useTheme } from '@/hooks/useTheme'
import { RollingTextLink } from '@/components/ui/RollingTextLink'
const navItems = [
{ label: 'Home', path: '/' },
@@ -42,14 +43,12 @@ export function Navigation() {
<ul className="nav-menu">
{navItems.map((item) => (
<li key={item.path}>
<NavLink
<RollingTextLink
to={item.path}
className={({ isActive }) =>
isActive ? 'nav-link active' : 'nav-link'
}
className={item.path === location.pathname ? 'nav-link active' : 'nav-link'}
>
{item.label}
</NavLink>
</RollingTextLink>
</li>
))}
</ul>
@@ -97,15 +96,13 @@ export function Navigation() {
<ul className="mobile-menu-list">
{navItems.map((item) => (
<li key={item.path}>
<NavLink
<RollingTextLink
to={item.path}
className={({ isActive }) =>
isActive ? 'mobile-menu-link active' : 'mobile-menu-link'
}
className={item.path === location.pathname ? 'mobile-menu-link active' : 'mobile-menu-link'}
onClick={() => setMobileOpen(false)}
>
{item.label}
</NavLink>
</RollingTextLink>
</li>
))}
</ul>
+4 -1
View File
@@ -1,10 +1,12 @@
import { SectionHeading } from '@/components/ui/SectionHeading'
import { InView } from '@/components/ui/InView'
import { Tag } from '@/components/ui/Tag'
import { profile } from '@/data/profile'
export function About() {
return (
<section className="section container-content" aria-labelledby="about-heading">
<InView>
<section className="section container-wide" aria-labelledby="about-heading">
<SectionHeading title="About Me" />
<div style={{ maxWidth: '700px' }}>
<p style={{ fontSize: '18px', marginBottom: '32px' }}>
@@ -41,5 +43,6 @@ export function About() {
</div>
</div>
</section>
</InView>
)
}
+3 -1
View File
@@ -8,7 +8,7 @@ export function Contact() {
return (
<InView>
<motion.section
className="section container-content"
className="section container-wide"
aria-labelledby="contact-heading"
initial="hidden"
whileInView="visible"
@@ -19,6 +19,7 @@ export function Contact() {
}}
>
<SectionHeading title="Contact" />
<div style={{ maxWidth: '700px' }}>
<div className="contact-links">
<motion.a
href={`mailto:${profile.email}`}
@@ -97,6 +98,7 @@ export function Contact() {
</div>
</motion.a>
</div>
</div>
<DownloadResume />
</motion.section>
</InView>
+3 -1
View File
@@ -6,7 +6,7 @@ export function Experience() {
return (
<InView>
<motion.section
className="section container-content"
className="section container-wide"
aria-labelledby="experience-heading"
initial="hidden"
whileInView="visible"
@@ -29,6 +29,7 @@ export function Experience() {
>
Experience
</motion.h2>
<div style={{ maxWidth: '700px' }}>
<div className="timeline">
{experiences.map((exp, i) => (
<motion.div
@@ -98,6 +99,7 @@ export function Experience() {
</motion.div>
))}
</div>
</div>
</motion.section>
</InView>
)
+10 -4
View File
@@ -1,5 +1,5 @@
import { motion } from "motion/react"
import { OpenToWorkBadge } from "@/components/ui/OpenToWorkBadge"
import { motion, useScroll, useTransform } from "motion/react"
import { InView } from "@/components/ui/InView"
import { resumeAvailable } from "@/data/resume"
import { Button } from "@/components/ui/Button"
import { SocialLinks } from "@/components/ui/SocialLinks"
@@ -40,7 +40,11 @@ const socialLinks = [
]
export function Hero() {
const { scrollY } = useScroll()
const y = useTransform(scrollY, [0, 300], [0, -80])
const opacity = useTransform(scrollY, [0, 200], [1, 0.3])
return (
<InView>
<motion.section
className="hero container-wide"
initial={{ opacity: 0 }}
@@ -50,6 +54,7 @@ export function Hero() {
>
<motion.div
className="hero-content"
style={{ opacity }}
initial={{ opacity: 0, x: -30 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.6, delay: 0.2 }}
@@ -89,7 +94,7 @@ export function Hero() {
View Projects
</Button>
{resumeAvailable && (
<Button href="/resume.pdf" variant="secondary" download>
<Button href="/resume.pdf" variant="secondary" target="_blank">
Download Resume
</Button>
)}
@@ -101,6 +106,7 @@ export function Hero() {
</motion.div>
<motion.div
className="hero-visual"
style={{ y }}
initial={{ opacity: 0, x: 30 }}
animate={{ opacity: 1, x: 0 }}
transition={{ duration: 0.6, delay: 0.4 }}
@@ -110,8 +116,8 @@ export function Hero() {
alt="Profile photo"
className="hero-photo"
/>
<OpenToWorkBadge />
</motion.div>
</motion.section>
</InView>
)
}
+8 -6
View File
@@ -1,7 +1,9 @@
import { Link } from "react-router"
import { motion } from "motion/react"
import { Badge } from "@/components/ui/Badge"
import { projects } from "@/data/projects"
import { InView } from "@/components/ui/InView"
const MotionLink = motion.create(Link)
const categoryLabels: Record<string, string> = {
"software-engineering": "Software Engineering",
@@ -44,20 +46,20 @@ export function Projects() {
}}
>
<h2 id="projects-heading">Featured Projects</h2>
<motion.a
href="/projects"
<MotionLink
to="/projects"
style={{ fontSize: "14px", fontWeight: 500, color: "var(--accent)" }}
whileHover={{ scale: 1.05 }}
whileTap={{ scale: 0.95 }}
>
View All →
</motion.a>
</MotionLink>
</motion.div>
<div className="projects-grid">
{featured.map((project, i) => (
<motion.a
<MotionLink
key={project.id}
href={`/projects/${project.id}`}
to={`/projects/${project.id}`}
className="project-card"
variants={{
hidden: { opacity: 0, y: 30 },
@@ -94,7 +96,7 @@ export function Projects() {
</div>
)}
<span className="project-card-cta">View Details →</span>
</motion.a>
</MotionLink>
))}
</div>
</motion.section>
+26 -3
View File
@@ -1,5 +1,7 @@
import { Link } from "react-router"
import { motion } from "motion/react"
import { forwardRef } from "react"
const MotionLink = motion.create(Link)
import type { ComponentPropsWithoutRef } from "react"
type ButtonVariant = "primary" | "secondary" | "ghost"
@@ -10,7 +12,7 @@ interface ButtonProps extends ComponentPropsWithoutRef<"button"> {
size?: ButtonSize
href?: string
download?: boolean
children: React.ReactNode
target?: string
}
const variantClasses: Record<ButtonVariant, string> = {
@@ -43,12 +45,34 @@ export const Button = forwardRef<
const classes = `${variantClasses[variant]} ${sizeClasses[size]} ${className}`.trim()
if (href) {
const isRoute = href.startsWith("/")
const safeProps = { ...props }
if (isRoute) {
delete (safeProps as Record<string, unknown>)["download"]
}
if (isRoute) {
return (
<MotionLink
to={href}
className={classes}
ref={ref as React.Ref<HTMLAnchorElement>}
whileTap={{ scale: 0.95 }}
{...(safeProps as Omit<
React.AnchorHTMLAttributes<HTMLAnchorElement>,
keyof ButtonProps | "to"
>)}
>
{children}
</MotionLink>
)
}
return (
<motion.a
href={href}
className={classes}
ref={ref as React.Ref<HTMLAnchorElement>}
whileTap={{ scale: 0.95 }}
{...(props as Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, keyof ButtonProps>)}
>
@@ -61,7 +85,6 @@ export const Button = forwardRef<
<motion.button
className={classes}
ref={ref as React.Ref<HTMLButtonElement>}
whileTap={{ scale: 0.95 }}
{...(props as Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, keyof ButtonProps>)}
>
-33
View File
@@ -1,33 +0,0 @@
import { motion } from "motion/react"
export function OpenToWorkBadge() {
return (
<motion.div
className="otw-container"
initial={{ opacity: 0, y: -20 }}
animate={{ opacity: 1, y: 0 }}
transition={{ delay: 0.3, duration: 0.5 }}
role="status"
aria-label="Open to work"
>
<svg className="otw-spring" viewBox="0 0 60 120">
<motion.path
d="M 30 0 C 50 5, 50 15, 30 20 C 10 25, 10 35, 30 40 C 50 45, 50 55, 30 60 C 10 65, 10 75, 30 80 C 50 85, 50 95, 30 100 C 10 105, 10 115, 30 120 L 30 125"
stroke="var(--accent)"
fill="none"
strokeWidth="2"
strokeLinecap="round"
animate={{ rotate: [-8, 8, -8] }}
transition={{ duration: 3, repeat: Infinity, ease: "easeInOut" }}
/>
</svg>
<motion.div
className="otw-badge"
animate={{ rotate: [-8, 8, -8] }}
transition={{ duration: 3, repeat: Infinity, ease: "easeInOut" }}
>
<span>#OpenToWork</span>
</motion.div>
</motion.div>
)
}
+122
View File
@@ -0,0 +1,122 @@
import { Link } from "react-router"
import { motion, useReducedMotion } from "motion/react"
import { useRef, useState } from "react"
const outgoingVariants = {
rest: { transform: "translateY(0%)" },
active: { transform: "translateY(100%)" },
}
const incomingVariants = {
rest: { transform: "translateY(-100%)" },
active: { transform: "translateY(0%)" },
}
const transition = {
duration: 0.3,
ease: [0.338, 0.015, 0.395, 0.959] as const,
}
interface RollingTextLinkProps {
to: string
className?: string
onClick?: () => void
children: React.ReactNode
}
export function RollingTextLink({ to, className, onClick, children }: RollingTextLinkProps) {
const reduceMotion = useReducedMotion()
const [active, setActive] = useState(false)
const activeRef = useRef(false)
const animating = useRef(false)
const pendingRequest = useRef<boolean | null>(null)
const hovered = useRef(false)
const focused = useRef(false)
const updateActive = (next: boolean) => {
activeRef.current = next
setActive(next)
}
const requestActive = (next: boolean) => {
if (reduceMotion) return
if (next === activeRef.current) {
pendingRequest.current = null
return
}
if (animating.current) {
pendingRequest.current = next
return
}
animating.current = true
updateActive(next)
}
const completeAnimation = () => {
if (!animating.current) return
animating.current = false
if (pendingRequest.current !== null && pendingRequest.current !== activeRef.current) {
const next = pendingRequest.current
pendingRequest.current = null
animating.current = true
updateActive(next)
} else {
pendingRequest.current = null
}
}
return (
<Link
to={to}
className={className}
onClick={onClick}
onPointerEnter={() => {
hovered.current = true
requestActive(true)
}}
onPointerLeave={() => {
hovered.current = false
requestActive(focused.current)
}}
onFocus={() => {
focused.current = true
requestActive(true)
}}
onBlur={() => {
focused.current = false
requestActive(hovered.current)
}}
>
<span style={{ position: "relative", display: "inline-block", overflow: "hidden" }}>
<motion.span
style={{ display: "block", whiteSpace: "nowrap" }}
variants={outgoingVariants}
initial="rest"
animate={active ? "active" : "rest"}
onAnimationComplete={completeAnimation}
transition={transition}
>
{children}
</motion.span>
<motion.span
style={{
display: "block",
whiteSpace: "nowrap",
position: "absolute",
inset: 0,
}}
variants={incomingVariants}
initial="rest"
animate={active ? "active" : "rest"}
transition={transition}
>
{children}
</motion.span>
</span>
</Link>
)
}
+1 -1
View File
@@ -1,7 +1,7 @@
import type { Profile } from "@/types";
export const profile: Profile = {
name: "Your Name",
name: "Dong Nguyen",
title: "Senior Software Engineer",
tagline:
"Building scalable software systems,\nintelligent logistics solutions,\nand practical AI applications.",
+16
View File
@@ -215,6 +215,21 @@ pre code {
.section {
padding: 48px 0;
}
.container-wide,
.container-content,
.container-narrow {
padding-left: 32px;
padding-right: 32px;
}
}
@media (min-width: 769px) and (max-width: 1200px) {
.container-wide,
.container-content,
.container-narrow {
padding-left: 40px;
padding-right: 40px;
}
}
/* Scroll reveal animation */
@@ -229,6 +244,7 @@ pre code {
}
}
.animate-in {
animation: fadeInUp var(--transition-slow) ease forwards;
}