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

@@ -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