Adds the Lifestyle fotografie section to the homepage
Adds the first block below the hero: heading, intro and a staggered gallery of four live photos. Brings in the shared section building blocks (HomeSection, SectionHeading, Reveal) and DeferredImage, which holds back below-the-fold photos until the page has loaded so they do not compete with the hero for bandwidth. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
- **Feature Slug**: homepage-sections
|
||||
- **Project Type**: Brownfield
|
||||
- **Start Date**: 2026-10-19T19:19:38Z
|
||||
- **Current Stage**: CONSTRUCTION - Unit 1 Lifestyle fotografie - Code Generation (planning)
|
||||
- **Current Stage**: CONSTRUCTION - Unit 1 Lifestyle fotografie - Code Generation (awaiting approval)
|
||||
- **Branch**: feature/homepage-sections (to be created before Code Generation)
|
||||
|
||||
## Workspace State
|
||||
@@ -74,7 +74,7 @@
|
||||
|
||||
## Current Status
|
||||
- **Lifecycle Phase**: CONSTRUCTION
|
||||
- **Current Stage**: Unit 1 Lifestyle fotografie — Code Generation (planning)
|
||||
- **Current Stage**: Unit 1 Lifestyle fotografie — Code Generation complete, awaiting approval
|
||||
- **Next Stage**: CONSTRUCTION - Unit 1 Code Generation
|
||||
|
||||
## Reverse Engineering Status
|
||||
|
||||
@@ -233,3 +233,15 @@ Nou is het nog een statische site zonder back-end dus het contactformulier kan n
|
||||
**Context**: CONSTRUCTION - Unit 1 Code Generation Part 2 (start)
|
||||
|
||||
---
|
||||
|
||||
## Unit 1 Lifestyle fotografie — Code Generation Complete
|
||||
|
||||
**Timestamp**: 2026-10-20T00:10:00Z
|
||||
|
||||
**User Input**: (none — generation)
|
||||
|
||||
**AI Response**: "Executed all 20 plan steps. Step 13.5 self-check: Prettier failed on CRLF from an edit script (reformatted); tsc rejected constructor parameter properties in a test (rewritten); a leftover vite preview from an earlier session occupied port 4173 (stopped); Lighthouse home mobile failed 0.78 < 0.8 — root cause: Chrome eagerly fetches lazy images within ~1250px of the viewport, so gallery photos competed with the hero (LCP 3.8s → 5.3s). Fixed with useInView, usePageLoaded and DeferredImage (recorded as Step 18a). Final pnpm check green: 138 tests, build ok, audits ok (dev audit report-only), Lighthouse home mobile 0.85 / desktop 1.0, a11y/BP/SEO 1.0. Code summary written. Committed locally on feature/homepage-sections (not pushed)."
|
||||
|
||||
**Context**: CONSTRUCTION - Unit 1 Code Generation (complete, awaiting approval)
|
||||
|
||||
---
|
||||
|
||||
+84
@@ -0,0 +1,84 @@
|
||||
# Code Summary — Unit 1: Lifestyle fotografie
|
||||
|
||||
Plan: [lifestyle-fotografie-code-generation-plan.md](../../plans/lifestyle-fotografie-code-generation-plan.md). Branch: `feature/homepage-sections`.
|
||||
|
||||
## Files
|
||||
|
||||
### Created
|
||||
| File | Purpose |
|
||||
|---|---|
|
||||
| `web/src/assets/home/intro-1…4.jpg` | Gallery photos, 800×1200, 92–141 KB |
|
||||
| `web/src/content/homeContent.ts` | Homepage section content (intro part) |
|
||||
| `web/src/hooks/useInView.ts` | Shared "has come into/near view, once" hook (IntersectionObserver; immediate without it) |
|
||||
| `web/src/hooks/useReveal.ts` + test | Reveal trigger on top of `useInView`; immediate under reduced motion |
|
||||
| `web/src/hooks/usePageLoaded.ts` + test | True once the window load event has fired |
|
||||
| `web/src/components/Reveal/Reveal.tsx` + test | Fade-in-and-up wrapper, optional stagger delay, passes Box props |
|
||||
| `web/src/components/DeferredImage/DeferredImage.tsx` + test | Below-the-fold image that loads after the load event and within 600 px of the viewport |
|
||||
| `web/src/components/SectionHeading/SectionHeading.tsx` + test | Eyebrow, h2 with id, lead |
|
||||
| `web/src/components/HomeSection/HomeSection.tsx` + test | Section frame: rhythm, tone, width, `aria-labelledby`, anchor |
|
||||
| `web/src/components/home/IntroGallery/IntroGallery.tsx` + test | The "Lifestyle fotografie" section |
|
||||
| `web/src/test/fakeIntersectionObserver.ts` | Shared, controllable IntersectionObserver test double |
|
||||
|
||||
### Modified
|
||||
| File | Change |
|
||||
|---|---|
|
||||
| `web/src/theme.ts` | Spacing `sectionY`, `sectionYTight`, `sectionHeadGap`, `gridGap`; size `contentNarrow`; duration `reveal`; text styles `sectionTitle`, `lead` |
|
||||
| `web/src/content/types.ts` | `ContentImage`, `HomeContent` (intro) |
|
||||
| `web/src/routes/index.tsx` | Renders `IntroGallery` after the Hero |
|
||||
| `web/src/app.test.tsx` | Homepage: sections follow the hero in order, one h1, axe clean |
|
||||
|
||||
## Deviation from the plan (Step 18a)
|
||||
The first `pnpm check` failed on Lighthouse home mobile performance (0.78, budget 0.8). The LCP rose from 3.8 s to 5.3 s because Chrome fetches `loading="lazy"` images within ±1250 px of the viewport straight away: the gallery photos right under the hero were downloaded together with the first hero photo and, under Lighthouse's throttling, took its bandwidth. `DeferredImage` now holds back the `src` until the page has loaded and the image is near the viewport. Every later unit uses it for its photos.
|
||||
|
||||
## Image script
|
||||
Images are resized with a one-off PowerShell script (not part of the project; .NET `System.Drawing`, Windows). Command used:
|
||||
|
||||
```powershell
|
||||
1..4 | ForEach-Object {
|
||||
& .\resize-image.ps1 -Source "design\andreaslop-static\assets\img\intro-$_.jpg" `
|
||||
-Target "web\src\assets\home\intro-$_.jpg" -Width 800 -Quality 80
|
||||
}
|
||||
```
|
||||
|
||||
```powershell
|
||||
param(
|
||||
[Parameter(Mandatory)] [string] $Source,
|
||||
[Parameter(Mandatory)] [string] $Target,
|
||||
[Parameter(Mandatory)] [int] $Width,
|
||||
[int] $Quality = 80
|
||||
)
|
||||
Add-Type -AssemblyName System.Drawing
|
||||
$image = [System.Drawing.Image]::FromFile((Resolve-Path $Source))
|
||||
try {
|
||||
$height = [int][Math]::Round($image.Height * $Width / $image.Width)
|
||||
$bitmap = New-Object System.Drawing.Bitmap $Width, $height
|
||||
try {
|
||||
$graphics = [System.Drawing.Graphics]::FromImage($bitmap)
|
||||
$graphics.InterpolationMode = [System.Drawing.Drawing2D.InterpolationMode]::HighQualityBicubic
|
||||
$graphics.PixelOffsetMode = [System.Drawing.Drawing2D.PixelOffsetMode]::HighQuality
|
||||
$graphics.SmoothingMode = [System.Drawing.Drawing2D.SmoothingMode]::HighQuality
|
||||
$graphics.DrawImage($image, 0, 0, $Width, $height)
|
||||
$graphics.Dispose()
|
||||
$codec = [System.Drawing.Imaging.ImageCodecInfo]::GetImageEncoders() | Where-Object MimeType -eq 'image/jpeg'
|
||||
$params = New-Object System.Drawing.Imaging.EncoderParameters 1
|
||||
$params.Param[0] = New-Object System.Drawing.Imaging.EncoderParameter ([System.Drawing.Imaging.Encoder]::Quality), ([long]$Quality)
|
||||
$bitmap.Save($Target, $codec, $params)
|
||||
}
|
||||
finally { $bitmap.Dispose() }
|
||||
}
|
||||
finally { $image.Dispose() }
|
||||
```
|
||||
|
||||
Results: intro-1 92 KB, intro-2 141 KB, intro-3 137 KB, intro-4 110 KB.
|
||||
|
||||
## Verification (`pnpm check`)
|
||||
- Lint ✅, Prettier ✅ (after reformatting CRLF line endings introduced by an edit script)
|
||||
- Tests: 30 files, **138 passed** (incl. existing property-based tests; coverage thresholds met)
|
||||
- Build ✅ (`tsc` + Vite) — after rewriting constructor parameter properties in a test (`erasableSyntaxOnly`)
|
||||
- `audit:deps` ✅ no known vulnerabilities; `audit:dev` 8 findings in dev tooling (report-only, unchanged from master)
|
||||
- Lighthouse home: mobile performance **0.85** (LCP 3.8 s, equal to master), desktop **1.0**; accessibility, best practices and SEO **1.0** on all 7 URLs
|
||||
- Note: a leftover `vite preview` on port 4173 from an earlier session blocked the first Lighthouse run; it was stopped.
|
||||
|
||||
## Extension compliance
|
||||
- **Security Baseline**: SECURITY-10 compliant (no new dependencies); SECURITY-13 compliant (no external resources); SECURITY-04 compliant (headers unchanged); other rules N/A (no input, server, data store or auth in this unit).
|
||||
- **PBT**: PBT-01 N/A — no business logic, data transformation or algorithm in this unit; PBT-10 compliant (example-based tests for every component and hook); PBT-08/09 unchanged.
|
||||
+23
-20
@@ -18,13 +18,13 @@
|
||||
## Steps
|
||||
|
||||
### Branch and baseline
|
||||
- [ ] **Step 1** — Create branch `feature/homepage-sections` from `master`. First commit: the inception artifacts so far (`aidlc-docs/…/homepage-sections/`, refreshed `aidlc-docs/_shared/reverse-engineering/`, `active-features.md`) and the static design update (`design/andreaslop-static/`, `LAYOUT.md`, `.ai/layout-conventions.md`). Not pushed.
|
||||
- [x] **Step 1** — Create branch `feature/homepage-sections` from `master`. First commit: the inception artifacts so far (`aidlc-docs/…/homepage-sections/`, refreshed `aidlc-docs/_shared/reverse-engineering/`, `active-features.md`) and the static design update (`design/andreaslop-static/`, `LAYOUT.md`, `.ai/layout-conventions.md`). Not pushed.
|
||||
|
||||
### Images
|
||||
- [ ] **Step 2** — Resize the four live gallery photos (`design/andreaslop-static/assets/img/intro-1…4.jpg`, 1067×1600) to **800×1200**, JPEG quality ~80, into `web/src/assets/home/intro-1.jpg … intro-4.jpg`. Tool: a one-off PowerShell script using .NET `System.Drawing` (already on Windows; not added to the project). The script and its parameters are recorded in the code summary so later units reuse them. Target ≤ ~150 KB per photo.
|
||||
- [x] **Step 2** — Resize the four live gallery photos (`design/andreaslop-static/assets/img/intro-1…4.jpg`, 1067×1600) to **800×1200**, JPEG quality ~80, into `web/src/assets/home/intro-1.jpg … intro-4.jpg`. Tool: a one-off PowerShell script using .NET `System.Drawing` (already on Windows; not added to the project). The script and its parameters are recorded in the code summary so later units reuse them. Target ≤ ~150 KB per photo.
|
||||
|
||||
### Theme (shared)
|
||||
- [ ] **Step 3** — `web/src/theme.ts`: add tokens from the design that later units also need:
|
||||
- [x] **Step 3** — `web/src/theme.ts`: add tokens from the design that later units also need:
|
||||
- spacing `sectionY` (`clamp(4.5rem, 9vw, 8.5rem)`), `sectionYTight` (60% of it), `gridGap` (`clamp(1rem, 2.2vw, 2rem)`), `sectionHeadGap` (`clamp(2.5rem, 5vw, 4.5rem)`)
|
||||
- size `contentNarrow` (`820px`)
|
||||
- text styles `sectionTitle` (Marcellus; 1.85 / 2.125 / 2.5rem, line-height 1.15) and `lead` (1.25rem, weight 300, line-height 1.6)
|
||||
@@ -32,33 +32,36 @@
|
||||
- then run `pnpm typegen`
|
||||
|
||||
### Content
|
||||
- [ ] **Step 4** — `web/src/content/types.ts`: add `ContentImage` and `HomeContent` with the `intro` part only (`{ title, lead, photos: ContentImage[] }`); later units extend `HomeContent`.
|
||||
- [ ] **Step 5** — Create `web/src/content/homeContent.ts`: title "Lifestyle fotografie", lead "Jouw favoriete momenten, vastgelegd op een natuurlijke en ongedwongen manier.", four photos with width/height 800×1200 and alt texts:
|
||||
- [x] **Step 4** — `web/src/content/types.ts`: add `ContentImage` and `HomeContent` with the `intro` part only (`{ title, lead, photos: ContentImage[] }`); later units extend `HomeContent`.
|
||||
- [x] **Step 5** — Create `web/src/content/homeContent.ts`: title "Lifestyle fotografie", lead "Jouw favoriete momenten, vastgelegd op een natuurlijke en ongedwongen manier.", four photos with width/height 800×1200 and alt texts:
|
||||
1. "Babyhandje in de hand van de moeder, op een gebreid dekentje"
|
||||
2. "Moeder drukt haar pasgeboren baby in een gebreid truitje tegen zich aan"
|
||||
3. "Zwangere vrouw op blote voeten in het zand bij zonsondergang"
|
||||
4. "Aanstaande vader omarmt zijn zwangere partner in de duinen"
|
||||
|
||||
### Shared blocks
|
||||
- [ ] **Step 6** — `web/src/hooks/useReveal.ts`: returns `{ ref, visible }`; visible immediately when `prefers-reduced-motion: reduce` or `IntersectionObserver` is missing; otherwise observes once (threshold 0.12, rootMargin `0px 0px -60px 0px`, as in the design) and disconnects on reveal and on unmount.
|
||||
- [ ] **Step 7** — `web/src/hooks/useReveal.test.tsx`: visible without IntersectionObserver (jsdom); visible under reduced motion; hidden until intersecting with a mocked observer, then visible, then unobserved; disconnect on unmount.
|
||||
- [ ] **Step 8** — `web/src/components/Reveal/Reveal.tsx`: wraps children in a `Box`; opacity 0 + translateY(24px) until visible, transition `reveal` duration with the `smooth` easing; optional `delay` (seconds) for staggering.
|
||||
- [ ] **Step 9** — `web/src/components/Reveal/Reveal.test.tsx`: children always in the DOM and accessible; visible state without observer.
|
||||
- [ ] **Step 10** — `web/src/components/SectionHeading/SectionHeading.tsx`: optional eyebrow (`eyebrow` text style, `accent.deep`), h2 with `id` (`sectionTitle` text style), optional lead (`lead` text style, `ink.soft`); `align` center (default, max width 620px, centred) or start; bottom margin `sectionHeadGap`.
|
||||
- [ ] **Step 11** — `web/src/components/SectionHeading/SectionHeading.test.tsx`: h2 with id, optional eyebrow/lead, axe clean.
|
||||
- [ ] **Step 12** — `web/src/components/HomeSection/HomeSection.tsx`: `<section aria-labelledby>` with `py="sectionY"` (or `sectionYTight`), `bg` `paper` or `paper.alt` (`tone`), inner `Container` (`content` or `contentNarrow` width), optional `id` and `data-testid`.
|
||||
- [ ] **Step 13** — `web/src/components/HomeSection/HomeSection.test.tsx`: region named by its heading, tone and width variants render, id passes through.
|
||||
- [x] **Step 6** — `web/src/hooks/useReveal.ts`: returns `{ ref, visible }`; visible immediately when `prefers-reduced-motion: reduce` or `IntersectionObserver` is missing; otherwise observes once (threshold 0.12, rootMargin `0px 0px -60px 0px`, as in the design) and disconnects on reveal and on unmount.
|
||||
- [x] **Step 7** — `web/src/hooks/useReveal.test.tsx`: visible without IntersectionObserver (jsdom); visible under reduced motion; hidden until intersecting with a mocked observer, then visible, then unobserved; disconnect on unmount.
|
||||
- [x] **Step 8** — `web/src/components/Reveal/Reveal.tsx`: wraps children in a `Box`; opacity 0 + translateY(24px) until visible, transition `reveal` duration with the `smooth` easing; optional `delay` (seconds) for staggering.
|
||||
- [x] **Step 9** — `web/src/components/Reveal/Reveal.test.tsx`: children always in the DOM and accessible; visible state without observer.
|
||||
- [x] **Step 10** — `web/src/components/SectionHeading/SectionHeading.tsx`: optional eyebrow (`eyebrow` text style, `accent.deep`), h2 with `id` (`sectionTitle` text style), optional lead (`lead` text style, `ink.soft`); `align` center (default, max width 620px, centred) or start; bottom margin `sectionHeadGap`.
|
||||
- [x] **Step 11** — `web/src/components/SectionHeading/SectionHeading.test.tsx`: h2 with id, optional eyebrow/lead, axe clean.
|
||||
- [x] **Step 12** — `web/src/components/HomeSection/HomeSection.tsx`: `<section aria-labelledby>` with `py="sectionY"` (or `sectionYTight`), `bg` `paper` or `paper.alt` (`tone`), inner `Container` (`content` or `contentNarrow` width), optional `id` and `data-testid`.
|
||||
- [x] **Step 13** — `web/src/components/HomeSection/HomeSection.test.tsx`: region named by its heading, tone and width variants render, id passes through.
|
||||
|
||||
### The section
|
||||
- [ ] **Step 14** — `web/src/components/home/IntroGallery/IntroGallery.tsx`: `HomeSection` + `SectionHeading` (in `Reveal`) + grid of four `figure`s, each in a `Reveal` with a staggered delay; 4 columns from `lg`, 2 from `sm`, 1 below; 2nd and 4th photo offset downward from `sm` (design `margin-top`); image `aspectRatio 3/4`, `objectFit cover`, `loading="lazy"`, explicit width/height; slow hover zoom (1.05, `fade` duration), none under reduced motion.
|
||||
- [ ] **Step 15** — `web/src/components/home/IntroGallery/IntroGallery.test.tsx`: region "Lifestyle fotografie", h2 + lead, four images with their alt texts and lazy loading, works with any number of photos (0 shows only the heading), axe clean.
|
||||
- [ ] **Step 16** — `web/src/routes/index.tsx`: render `IntroGallery` with `homeContent.intro` after the Hero.
|
||||
- [ ] **Step 17** — `web/src/app.test.tsx`: the homepage shows the "Lifestyle fotografie" section after the hero, still exactly one h1, axe clean (extend the existing home checks).
|
||||
- [x] **Step 14** — `web/src/components/home/IntroGallery/IntroGallery.tsx`: `HomeSection` + `SectionHeading` (in `Reveal`) + grid of four `figure`s, each in a `Reveal` with a staggered delay; 4 columns from `lg`, 2 from `sm`, 1 below; 2nd and 4th photo offset downward from `sm` (design `margin-top`); image `aspectRatio 3/4`, `objectFit cover`, `loading="lazy"`, explicit width/height; slow hover zoom (1.05, `fade` duration), none under reduced motion.
|
||||
- [x] **Step 15** — `web/src/components/home/IntroGallery/IntroGallery.test.tsx`: region "Lifestyle fotografie", h2 + lead, four images with their alt texts and lazy loading, works with any number of photos (0 shows only the heading), axe clean.
|
||||
- [x] **Step 16** — `web/src/routes/index.tsx`: render `IntroGallery` with `homeContent.intro` after the Hero.
|
||||
- [x] **Step 17** — `web/src/app.test.tsx`: the homepage shows the "Lifestyle fotografie" section after the hero, still exactly one h1, axe clean (extend the existing home checks).
|
||||
|
||||
### Verification and wrap-up
|
||||
- [ ] **Step 18** — Run `pnpm check` (lint, format, tests incl. coverage thresholds, build, audits, Lighthouse mobile + desktop). Fix and rerun until green.
|
||||
- [ ] **Step 19** — Write `aidlc-docs/features/homepage-sections/construction/lifestyle-fotografie/code/code-summary.md`: files created/modified, image script + parameters and resulting sizes, test results, Lighthouse scores, extension compliance.
|
||||
- [ ] **Step 20** — Commit unit 1 on `feature/homepage-sections` ("Adds the Lifestyle fotografie section to the homepage" + attribution). Not pushed.
|
||||
- [x] **Step 18** — Run `pnpm check` (lint, format, tests incl. coverage thresholds, build, audits, Lighthouse mobile + desktop). Fix and rerun until green.
|
||||
- [x] **Step 19** — Write `aidlc-docs/features/homepage-sections/construction/lifestyle-fotografie/code/code-summary.md`: files created/modified, image script + parameters and resulting sizes, test results, Lighthouse scores, extension compliance.
|
||||
- [x] **Step 20** — Commit unit 1 on `feature/homepage-sections` ("Adds the Lifestyle fotografie section to the homepage" + attribution). Not pushed.
|
||||
|
||||
### Fix during Step 18 (Step 13.5 self-check)
|
||||
- [x] **Step 18a** — Lighthouse home mobile failed (0.78 < 0.8; LCP 3.8 s → 5.3 s). Root cause: Chrome fetches `loading="lazy"` images within ±1250 px of the viewport immediately, so the gallery photos right under the hero competed with the hero for bandwidth under Lighthouse's throttling. Fix: `hooks/useInView.ts` (shared observer logic; `useReveal` now builds on it), `hooks/usePageLoaded.ts`, `components/DeferredImage` (sets `src` only after the load event and when within 600 px of the viewport; width/height reserve the space), `test/fakeIntersectionObserver.ts` (shared test double); IntroGallery uses DeferredImage with a `paper.deep` placeholder. Result: mobile 0.85 (LCP 3.8 s, equal to master).
|
||||
|
||||
## Requirement traceability
|
||||
| Requirement | Steps |
|
||||
|
||||
@@ -121,6 +121,29 @@ describe('app', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('homepage', () => {
|
||||
it('shows the sections below the hero in page order', async () => {
|
||||
const { container } = await renderApp('/');
|
||||
const hero = await screen.findByRole('region', {
|
||||
name: 'Uitgelicht werk',
|
||||
});
|
||||
const sections = [
|
||||
screen.getByRole('region', { name: 'Lifestyle fotografie' }),
|
||||
];
|
||||
|
||||
let previous: Element = hero;
|
||||
for (const section of sections) {
|
||||
expect(
|
||||
previous.compareDocumentPosition(section) &
|
||||
Node.DOCUMENT_POSITION_FOLLOWING,
|
||||
).toBeTruthy();
|
||||
previous = section;
|
||||
}
|
||||
expect(screen.getAllByRole('heading', { level: 1 })).toHaveLength(1);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
});
|
||||
|
||||
describe('pagina-register', () => {
|
||||
it('bevat precies de routes van de route tree', async () => {
|
||||
const { router } = await renderApp('/');
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 92 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 141 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 137 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 110 KiB |
@@ -0,0 +1,53 @@
|
||||
import { act, screen } from '@testing-library/react';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { FakeIntersectionObserver } from '@/test/fakeIntersectionObserver';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import DeferredImage from './DeferredImage';
|
||||
|
||||
const image = {
|
||||
src: '/foto.jpg',
|
||||
alt: 'Een foto',
|
||||
width: 800,
|
||||
height: 1200,
|
||||
};
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
FakeIntersectionObserver.reset();
|
||||
});
|
||||
|
||||
describe('DeferredImage', () => {
|
||||
it('loads straight away without IntersectionObserver once the page has loaded', async () => {
|
||||
await renderWithProviders(<DeferredImage image={image} />);
|
||||
const img = screen.getByRole('img', { name: 'Een foto' });
|
||||
expect(img).toHaveAttribute('src', '/foto.jpg');
|
||||
expect(img).toHaveAttribute('width', '800');
|
||||
expect(img).toHaveAttribute('height', '1200');
|
||||
expect(img).toHaveAttribute('loading', 'lazy');
|
||||
});
|
||||
|
||||
it('waits until the image comes near the viewport', async () => {
|
||||
vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver);
|
||||
await renderWithProviders(<DeferredImage image={image} />);
|
||||
const img = screen.getByRole('img', { name: 'Een foto' });
|
||||
const [observer] = FakeIntersectionObserver.instances;
|
||||
|
||||
expect(img).not.toHaveAttribute('src');
|
||||
expect(observer.options?.rootMargin).toBe('600px 0px');
|
||||
|
||||
act(() => observer.trigger(true));
|
||||
expect(img).toHaveAttribute('src', '/foto.jpg');
|
||||
});
|
||||
|
||||
it('waits for the page load event, even when already in view', async () => {
|
||||
vi.spyOn(document, 'readyState', 'get').mockReturnValue('interactive');
|
||||
await renderWithProviders(<DeferredImage image={image} />);
|
||||
const img = screen.getByRole('img', { name: 'Een foto' });
|
||||
expect(img).not.toHaveAttribute('src');
|
||||
|
||||
act(() => {
|
||||
window.dispatchEvent(new Event('load'));
|
||||
});
|
||||
expect(img).toHaveAttribute('src', '/foto.jpg');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
import { Image, type ImageProps } from '@chakra-ui/react';
|
||||
import usePageLoaded from '@/hooks/usePageLoaded';
|
||||
import useInView from '@/hooks/useInView';
|
||||
import type { ContentImage } from '@/content/types';
|
||||
|
||||
// How far below the viewport an image starts loading
|
||||
const LOAD_MARGIN = '600px 0px';
|
||||
|
||||
type DeferredImageProps = Omit<ImageProps, 'src' | 'alt'> & {
|
||||
image: ContentImage;
|
||||
};
|
||||
|
||||
// A below-the-fold image that only starts downloading once the page has
|
||||
// finished loading and the image is near the viewport. Native
|
||||
// loading="lazy" is not enough: Chrome fetches lazy images up to ±1250px
|
||||
// below the screen straight away, so photos right under the hero compete
|
||||
// with it for bandwidth and delay the largest contentful paint.
|
||||
// Width and height reserve the space, so nothing shifts when it loads.
|
||||
export default function DeferredImage({ image, ...rest }: DeferredImageProps) {
|
||||
const pageLoaded = usePageLoaded();
|
||||
const { ref, inView } = useInView<HTMLImageElement>({
|
||||
rootMargin: LOAD_MARGIN,
|
||||
});
|
||||
|
||||
return (
|
||||
<Image
|
||||
ref={ref}
|
||||
src={pageLoaded && inView ? image.src : undefined}
|
||||
alt={image.alt}
|
||||
htmlWidth={image.width}
|
||||
htmlHeight={image.height}
|
||||
loading="lazy"
|
||||
decoding="async"
|
||||
{...rest}
|
||||
/>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import HomeSection from './HomeSection';
|
||||
|
||||
describe('HomeSection', () => {
|
||||
it('is a region named by its heading', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<HomeSection labelledBy="about-title" data-testid="about">
|
||||
<h2 id="about-title">Over mij</h2>
|
||||
</HomeSection>,
|
||||
);
|
||||
expect(screen.getByRole('region', { name: 'Over mij' })).toBe(
|
||||
screen.getByTestId('about'),
|
||||
);
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('passes the anchor id through for every tone, width and spacing', async () => {
|
||||
await renderWithProviders(
|
||||
<HomeSection
|
||||
labelledBy="contact-title"
|
||||
id="contact"
|
||||
tone="alt"
|
||||
width="narrow"
|
||||
spacing="tight"
|
||||
>
|
||||
<h2 id="contact-title">Contact</h2>
|
||||
</HomeSection>,
|
||||
);
|
||||
expect(screen.getByRole('region', { name: 'Contact' })).toHaveAttribute(
|
||||
'id',
|
||||
'contact',
|
||||
);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,40 @@
|
||||
import type { ReactNode } from 'react';
|
||||
import { Box, Container } from '@chakra-ui/react';
|
||||
|
||||
type HomeSectionProps = {
|
||||
// Id of the heading that names this section for assistive technology
|
||||
labelledBy: string;
|
||||
id?: string;
|
||||
tone?: 'paper' | 'alt';
|
||||
width?: 'default' | 'narrow';
|
||||
spacing?: 'default' | 'tight';
|
||||
'data-testid'?: string;
|
||||
children: ReactNode;
|
||||
};
|
||||
|
||||
// Frame of a homepage section (design .section): vertical rhythm, an
|
||||
// optional alternate background and the content column.
|
||||
export default function HomeSection({
|
||||
labelledBy,
|
||||
id,
|
||||
tone = 'paper',
|
||||
width = 'default',
|
||||
spacing = 'default',
|
||||
'data-testid': testId,
|
||||
children,
|
||||
}: HomeSectionProps) {
|
||||
return (
|
||||
<Box
|
||||
as="section"
|
||||
id={id}
|
||||
aria-labelledby={labelledBy}
|
||||
data-testid={testId}
|
||||
bg={tone === 'alt' ? 'paper.alt' : 'paper'}
|
||||
py={spacing === 'tight' ? 'sectionYTight' : 'sectionY'}
|
||||
>
|
||||
<Container maxW={width === 'narrow' ? 'contentNarrow' : 'content'}>
|
||||
{children}
|
||||
</Container>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import Reveal from './Reveal';
|
||||
|
||||
describe('Reveal', () => {
|
||||
it('renders its content visibly when IntersectionObserver is missing', async () => {
|
||||
await renderWithProviders(
|
||||
<Reveal data-testid="reveal">
|
||||
<p>Inhoud</p>
|
||||
</Reveal>,
|
||||
);
|
||||
expect(screen.getByText('Inhoud')).toBeVisible();
|
||||
expect(screen.getByTestId('reveal')).toHaveAttribute(
|
||||
'data-reveal',
|
||||
'visible',
|
||||
);
|
||||
});
|
||||
|
||||
it('passes element props through, e.g. to render a figure', async () => {
|
||||
await renderWithProviders(
|
||||
<Reveal as="figure" delay={0.16} data-testid="reveal">
|
||||
<span>Foto</span>
|
||||
</Reveal>,
|
||||
);
|
||||
expect(screen.getByTestId('reveal').tagName).toBe('FIGURE');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import { Box, type BoxProps } from '@chakra-ui/react';
|
||||
import useReveal from '@/hooks/useReveal';
|
||||
|
||||
type RevealProps = BoxProps & {
|
||||
// Seconds to wait before fading in, to stagger items in a row
|
||||
delay?: number;
|
||||
};
|
||||
|
||||
// Fades its content in and up once it scrolls into view (design .reveal).
|
||||
// The content is always in the DOM and readable by assistive technology;
|
||||
// only its opacity and position change.
|
||||
export default function Reveal({ delay = 0, children, ...rest }: RevealProps) {
|
||||
const { ref, visible } = useReveal<HTMLDivElement>();
|
||||
|
||||
return (
|
||||
<Box
|
||||
ref={ref}
|
||||
data-reveal={visible ? 'visible' : 'hidden'}
|
||||
opacity={visible ? 1 : 0}
|
||||
transform={visible ? 'none' : 'translateY(24px)'}
|
||||
transitionProperty="opacity, transform"
|
||||
transitionDuration="reveal"
|
||||
transitionTimingFunction="smooth"
|
||||
transitionDelay={`${delay}s`}
|
||||
{...rest}
|
||||
>
|
||||
{children}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
import { screen } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import SectionHeading from './SectionHeading';
|
||||
|
||||
describe('SectionHeading', () => {
|
||||
it('renders the label, an h2 with its id and the lead', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<SectionHeading
|
||||
id="prices-title"
|
||||
eyebrow="Pakketten"
|
||||
title="Prijzen"
|
||||
lead="Kies wat bij je past."
|
||||
/>,
|
||||
);
|
||||
const heading = screen.getByRole('heading', { level: 2 });
|
||||
expect(heading).toHaveTextContent('Prijzen');
|
||||
expect(heading).toHaveAttribute('id', 'prices-title');
|
||||
expect(screen.getByText('Pakketten')).toBeInTheDocument();
|
||||
expect(screen.getByText('Kies wat bij je past.')).toBeInTheDocument();
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('works with only a title', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<SectionHeading id="t" title="Instagram" align="start" />,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('heading', { level: 2, name: 'Instagram' }),
|
||||
).toBeInTheDocument();
|
||||
expect(container.querySelectorAll('p')).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
import { Box, Heading, Text } from '@chakra-ui/react';
|
||||
|
||||
type SectionHeadingProps = {
|
||||
// Referenced by the section's aria-labelledby
|
||||
id: string;
|
||||
title: string;
|
||||
eyebrow?: string;
|
||||
lead?: string;
|
||||
align?: 'center' | 'start';
|
||||
};
|
||||
|
||||
// Heading block of a homepage section (design .section__head): optional
|
||||
// small label, the h2 and an optional intro sentence.
|
||||
export default function SectionHeading({
|
||||
id,
|
||||
title,
|
||||
eyebrow,
|
||||
lead,
|
||||
align = 'center',
|
||||
}: SectionHeadingProps) {
|
||||
const centered = align === 'center';
|
||||
|
||||
return (
|
||||
<Box
|
||||
maxW="620px"
|
||||
mx={centered ? 'auto' : undefined}
|
||||
mb="sectionHeadGap"
|
||||
textAlign={centered ? 'center' : 'start'}
|
||||
>
|
||||
{eyebrow && (
|
||||
// accent.deep instead of the design's accent: meets 4.5:1 (NFR-HP-01)
|
||||
<Text textStyle="eyebrow" color="accent.deep" mb={4}>
|
||||
{eyebrow}
|
||||
</Text>
|
||||
)}
|
||||
<Heading as="h2" id={id} textStyle="sectionTitle">
|
||||
{title}
|
||||
</Heading>
|
||||
{lead && (
|
||||
<Text textStyle="lead" color="ink.soft" mt={2}>
|
||||
{lead}
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,58 @@
|
||||
import { screen, within } from '@testing-library/react';
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import homeContent from '@/content/homeContent';
|
||||
import { axeResults } from '@/test/axe';
|
||||
import { renderWithProviders } from '@/test/renderWithProviders';
|
||||
import IntroGallery from './IntroGallery';
|
||||
|
||||
describe('IntroGallery', () => {
|
||||
it('shows the heading, the lead and the four photos', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<IntroGallery content={homeContent.intro} />,
|
||||
);
|
||||
const section = screen.getByRole('region', {
|
||||
name: 'Lifestyle fotografie',
|
||||
});
|
||||
expect(
|
||||
within(section).getByRole('heading', { level: 2 }),
|
||||
).toHaveTextContent('Lifestyle fotografie');
|
||||
expect(
|
||||
within(section).getByText(homeContent.intro.lead),
|
||||
).toBeInTheDocument();
|
||||
|
||||
const images = within(section).getAllByRole('img');
|
||||
expect(images).toHaveLength(4);
|
||||
images.forEach((image, index) => {
|
||||
const photo = homeContent.intro.photos[index];
|
||||
expect(image).toHaveAttribute('alt', photo.alt);
|
||||
expect(image).toHaveAttribute('loading', 'lazy');
|
||||
expect(image).toHaveAttribute('width', String(photo.width));
|
||||
expect(image).toHaveAttribute('height', String(photo.height));
|
||||
});
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('shows every photo as a figure, in order', async () => {
|
||||
await renderWithProviders(<IntroGallery content={homeContent.intro} />);
|
||||
homeContent.intro.photos.forEach((photo, index) => {
|
||||
const figure = screen.getByTestId(
|
||||
`intro-gallery-photo-${index + 1}`,
|
||||
);
|
||||
expect(figure.tagName).toBe('FIGURE');
|
||||
expect(within(figure).getByRole('img')).toHaveAttribute(
|
||||
'alt',
|
||||
photo.alt,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('still renders the heading when there are no photos', async () => {
|
||||
await renderWithProviders(
|
||||
<IntroGallery content={{ ...homeContent.intro, photos: [] }} />,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('heading', { name: 'Lifestyle fotografie' }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryAllByRole('img')).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Box, Grid } from '@chakra-ui/react';
|
||||
import DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||
import HomeSection from '@/components/HomeSection/HomeSection';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
import SectionHeading from '@/components/SectionHeading/SectionHeading';
|
||||
import type { HomeContent } from '@/content/types';
|
||||
|
||||
const TITLE_ID = 'intro-title';
|
||||
|
||||
// Every other photo sits lower, so the row is not a rigid block (design
|
||||
// .intro-gallery figure:nth-child(2|4))
|
||||
const OFFSET = 'clamp(1.5rem, 4vw, 3.5rem)';
|
||||
|
||||
// Delay between photos fading in, as in the design's .reveal:nth-child
|
||||
const STAGGER = 0.08;
|
||||
|
||||
type IntroGalleryProps = {
|
||||
content: HomeContent['intro'];
|
||||
};
|
||||
|
||||
// "Lifestyle fotografie": heading with intro and a gallery of four photos
|
||||
// (design .intro-gallery). 4 columns on desktop, 2 on tablet, 1 on phones.
|
||||
export default function IntroGallery({ content }: IntroGalleryProps) {
|
||||
return (
|
||||
<HomeSection labelledBy={TITLE_ID} data-testid="intro-gallery">
|
||||
<Reveal>
|
||||
<SectionHeading
|
||||
id={TITLE_ID}
|
||||
title={content.title}
|
||||
lead={content.lead}
|
||||
/>
|
||||
</Reveal>
|
||||
<Grid
|
||||
templateColumns={{
|
||||
base: '1fr',
|
||||
sm: 'repeat(2, 1fr)',
|
||||
lg: 'repeat(4, 1fr)',
|
||||
}}
|
||||
gap="gridGap"
|
||||
alignItems="start"
|
||||
>
|
||||
{content.photos.map((photo, index) => (
|
||||
<Reveal
|
||||
key={photo.src}
|
||||
as="figure"
|
||||
delay={index * STAGGER}
|
||||
mt={index % 2 === 1 ? { base: 0, sm: OFFSET } : 0}
|
||||
data-testid={`intro-gallery-photo-${index + 1}`}
|
||||
>
|
||||
<Box
|
||||
overflow="hidden"
|
||||
// Shown until the deferred photo arrives
|
||||
bg="paper.deep"
|
||||
css={{
|
||||
'&:hover img': { transform: 'scale(1.05)' },
|
||||
}}
|
||||
>
|
||||
<DeferredImage
|
||||
image={photo}
|
||||
w="100%"
|
||||
h="auto"
|
||||
aspectRatio="3 / 4"
|
||||
objectFit="cover"
|
||||
transitionProperty="transform"
|
||||
transitionDuration="fade"
|
||||
transitionTimingFunction="smooth"
|
||||
_motionReduce={{ transition: 'none' }}
|
||||
/>
|
||||
</Box>
|
||||
</Reveal>
|
||||
))}
|
||||
</Grid>
|
||||
</HomeSection>
|
||||
);
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
import type { HomeContent } from './types';
|
||||
|
||||
// Images
|
||||
import intro1 from '../assets/home/intro-1.jpg';
|
||||
import intro2 from '../assets/home/intro-2.jpg';
|
||||
import intro3 from '../assets/home/intro-3.jpg';
|
||||
import intro4 from '../assets/home/intro-4.jpg';
|
||||
|
||||
// Static content of the homepage sections until the CMS API exists; the API
|
||||
// will then deliver this object.
|
||||
const homeContent: HomeContent = {
|
||||
intro: {
|
||||
title: 'Lifestyle fotografie',
|
||||
lead: 'Jouw favoriete momenten, vastgelegd op een natuurlijke en ongedwongen manier.',
|
||||
photos: [
|
||||
{
|
||||
src: intro1,
|
||||
alt: 'Babyhandje in de hand van de moeder, op een gebreid dekentje',
|
||||
width: 800,
|
||||
height: 1200,
|
||||
},
|
||||
{
|
||||
src: intro2,
|
||||
alt: 'Moeder drukt haar pasgeboren baby in een gebreid truitje tegen zich aan',
|
||||
width: 800,
|
||||
height: 1200,
|
||||
},
|
||||
{
|
||||
src: intro3,
|
||||
alt: 'Zwangere vrouw op blote voeten in het zand bij zonsondergang',
|
||||
width: 800,
|
||||
height: 1200,
|
||||
},
|
||||
{
|
||||
src: intro4,
|
||||
alt: 'Aanstaande vader omarmt zijn zwangere partner in de duinen',
|
||||
width: 800,
|
||||
height: 1200,
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
export default homeContent;
|
||||
@@ -21,6 +21,24 @@ export interface SiteContent {
|
||||
email: EmailAddress;
|
||||
}
|
||||
|
||||
// An image as the API will deliver it. width and height are the intrinsic
|
||||
// size, so the browser can reserve space before the image loads.
|
||||
export interface ContentImage {
|
||||
src: string;
|
||||
alt: string;
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
// Content of the homepage sections below the hero
|
||||
export interface HomeContent {
|
||||
intro: {
|
||||
title: string;
|
||||
lead: string;
|
||||
photos: ContentImage[];
|
||||
};
|
||||
}
|
||||
|
||||
export interface HeroSlide {
|
||||
id: string;
|
||||
src: string;
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
import { useEffect, useRef, useState } from 'react';
|
||||
|
||||
type UseInViewOptions = {
|
||||
threshold?: number;
|
||||
rootMargin?: string;
|
||||
// Skip observing and report "in view" right away
|
||||
skip?: boolean;
|
||||
};
|
||||
|
||||
// Tells whether an element has come into (or near) the viewport, once.
|
||||
// Without IntersectionObserver the element counts as in view right away, so
|
||||
// content is never left hidden or unloaded.
|
||||
export default function useInView<T extends Element>({
|
||||
threshold = 0,
|
||||
rootMargin = '0px',
|
||||
skip = false,
|
||||
}: UseInViewOptions = {}) {
|
||||
const ref = useRef<T>(null);
|
||||
const supported = typeof IntersectionObserver !== 'undefined';
|
||||
const [intersected, setIntersected] = useState(false);
|
||||
const immediate = skip || !supported;
|
||||
|
||||
useEffect(() => {
|
||||
const element = ref.current;
|
||||
if (!element || immediate || intersected) return;
|
||||
|
||||
const observer = new IntersectionObserver(
|
||||
(entries) => {
|
||||
if (entries.some((entry) => entry.isIntersecting)) {
|
||||
setIntersected(true);
|
||||
observer.disconnect();
|
||||
}
|
||||
},
|
||||
{ threshold, rootMargin },
|
||||
);
|
||||
observer.observe(element);
|
||||
|
||||
return () => observer.disconnect();
|
||||
}, [immediate, intersected, threshold, rootMargin]);
|
||||
|
||||
return { ref, inView: immediate || intersected };
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { act, renderHook } from '@testing-library/react';
|
||||
import { describe, expect, it, vi } from 'vitest';
|
||||
import usePageLoaded from './usePageLoaded';
|
||||
|
||||
describe('usePageLoaded', () => {
|
||||
it('is true when the page had already loaded', () => {
|
||||
const { result } = renderHook(() => usePageLoaded());
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
|
||||
it('turns true on the load event', () => {
|
||||
vi.spyOn(document, 'readyState', 'get').mockReturnValue('interactive');
|
||||
const { result } = renderHook(() => usePageLoaded());
|
||||
expect(result.current).toBe(false);
|
||||
|
||||
act(() => {
|
||||
window.dispatchEvent(new Event('load'));
|
||||
});
|
||||
expect(result.current).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,17 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
|
||||
// True once the window's load event has fired (or had already fired).
|
||||
export default function usePageLoaded() {
|
||||
const [loaded, setLoaded] = useState(
|
||||
() => document.readyState === 'complete',
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
if (loaded) return;
|
||||
const onLoad = () => setLoaded(true);
|
||||
window.addEventListener('load', onLoad, { once: true });
|
||||
return () => window.removeEventListener('load', onLoad);
|
||||
}, [loaded]);
|
||||
|
||||
return loaded;
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
import { act, render, screen } from '@testing-library/react';
|
||||
import { ChakraProvider } from '@chakra-ui/react';
|
||||
import { afterEach, describe, expect, it, vi } from 'vitest';
|
||||
import { FakeIntersectionObserver as FakeObserver } from '@/test/fakeIntersectionObserver';
|
||||
import system from '../theme';
|
||||
import useReveal from './useReveal';
|
||||
|
||||
function Probe() {
|
||||
const { ref, visible } = useReveal<HTMLDivElement>();
|
||||
return (
|
||||
<div ref={ref} data-testid="probe">
|
||||
{visible ? 'visible' : 'hidden'}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const renderProbe = () =>
|
||||
render(
|
||||
<ChakraProvider value={system}>
|
||||
<Probe />
|
||||
</ChakraProvider>,
|
||||
);
|
||||
|
||||
const mockReducedMotion = () =>
|
||||
vi.spyOn(window, 'matchMedia').mockImplementation(
|
||||
(query: string) =>
|
||||
({
|
||||
matches: query.includes('reduce'),
|
||||
media: query,
|
||||
onchange: null,
|
||||
addEventListener: () => {},
|
||||
removeEventListener: () => {},
|
||||
addListener: () => {},
|
||||
removeListener: () => {},
|
||||
dispatchEvent: () => false,
|
||||
}) as MediaQueryList,
|
||||
);
|
||||
|
||||
afterEach(() => {
|
||||
vi.unstubAllGlobals();
|
||||
FakeObserver.reset();
|
||||
});
|
||||
|
||||
describe('useReveal', () => {
|
||||
it('is visible right away without IntersectionObserver', () => {
|
||||
renderProbe();
|
||||
expect(screen.getByTestId('probe')).toHaveTextContent('visible');
|
||||
});
|
||||
|
||||
it('is visible right away when the visitor prefers reduced motion', () => {
|
||||
vi.stubGlobal('IntersectionObserver', FakeObserver);
|
||||
mockReducedMotion();
|
||||
renderProbe();
|
||||
expect(screen.getByTestId('probe')).toHaveTextContent('visible');
|
||||
expect(FakeObserver.instances).toHaveLength(0);
|
||||
});
|
||||
|
||||
it('stays hidden until the element scrolls into view, then stops observing', () => {
|
||||
vi.stubGlobal('IntersectionObserver', FakeObserver);
|
||||
renderProbe();
|
||||
const probe = screen.getByTestId('probe');
|
||||
const [observer] = FakeObserver.instances;
|
||||
|
||||
expect(probe).toHaveTextContent('hidden');
|
||||
expect(observer.observed).toEqual([probe]);
|
||||
expect(observer.options).toEqual({
|
||||
threshold: 0.12,
|
||||
rootMargin: '0px 0px -60px 0px',
|
||||
});
|
||||
|
||||
act(() => observer.trigger(false));
|
||||
expect(probe).toHaveTextContent('hidden');
|
||||
|
||||
act(() => observer.trigger(true));
|
||||
expect(probe).toHaveTextContent('visible');
|
||||
expect(observer.disconnected).toBe(true);
|
||||
expect(FakeObserver.instances).toHaveLength(1);
|
||||
});
|
||||
|
||||
it('disconnects when the element unmounts before it was seen', () => {
|
||||
vi.stubGlobal('IntersectionObserver', FakeObserver);
|
||||
const { unmount } = renderProbe();
|
||||
unmount();
|
||||
expect(FakeObserver.instances[0].disconnected).toBe(true);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,20 @@
|
||||
import { useMediaQuery } from '@chakra-ui/react';
|
||||
import useInView from './useInView';
|
||||
|
||||
// Tells whether an element has scrolled into view, once, using the design's
|
||||
// initReveal trigger: a little of the element must be on screen, and not
|
||||
// right at the bottom edge. When the visitor prefers reduced motion the
|
||||
// element counts as visible right away.
|
||||
export default function useReveal<T extends Element>() {
|
||||
const [reducedMotion] = useMediaQuery(
|
||||
['(prefers-reduced-motion: reduce)'],
|
||||
{ ssr: false },
|
||||
);
|
||||
const { ref, inView } = useInView<T>({
|
||||
threshold: 0.12,
|
||||
rootMargin: '0px 0px -60px 0px',
|
||||
skip: reducedMotion,
|
||||
});
|
||||
|
||||
return { ref, visible: inView };
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
import { createFileRoute } from '@tanstack/react-router';
|
||||
import Hero from '../components/Hero/Hero';
|
||||
import IntroGallery from '../components/home/IntroGallery/IntroGallery';
|
||||
import heroContent from '../content/heroContent';
|
||||
import homeContent from '../content/homeContent';
|
||||
import siteContent from '../content/siteContent';
|
||||
import { pageHead } from '../seo';
|
||||
|
||||
@@ -9,6 +11,12 @@ export const Route = createFileRoute('/')({
|
||||
component: Index,
|
||||
});
|
||||
|
||||
// The homepage: the hero, then the sections in the order of LAYOUT.md
|
||||
function Index() {
|
||||
return <Hero content={heroContent} socials={siteContent.socials} />;
|
||||
return (
|
||||
<>
|
||||
<Hero content={heroContent} socials={siteContent.socials} />
|
||||
<IntroGallery content={homeContent.intro} />
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,38 @@
|
||||
// A controllable IntersectionObserver for tests: install it with
|
||||
// vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver) and call
|
||||
// trigger() to simulate an element coming into view.
|
||||
export class FakeIntersectionObserver {
|
||||
static instances: FakeIntersectionObserver[] = [];
|
||||
observed: Element[] = [];
|
||||
disconnected = false;
|
||||
readonly callback: IntersectionObserverCallback;
|
||||
readonly options?: IntersectionObserverInit;
|
||||
|
||||
constructor(
|
||||
callback: IntersectionObserverCallback,
|
||||
options?: IntersectionObserverInit,
|
||||
) {
|
||||
this.callback = callback;
|
||||
this.options = options;
|
||||
FakeIntersectionObserver.instances.push(this);
|
||||
}
|
||||
|
||||
observe(element: Element) {
|
||||
this.observed.push(element);
|
||||
}
|
||||
|
||||
disconnect() {
|
||||
this.disconnected = true;
|
||||
}
|
||||
|
||||
trigger(isIntersecting: boolean) {
|
||||
this.callback(
|
||||
[{ isIntersecting } as IntersectionObserverEntry],
|
||||
this as unknown as IntersectionObserver,
|
||||
);
|
||||
}
|
||||
|
||||
static reset() {
|
||||
FakeIntersectionObserver.instances = [];
|
||||
}
|
||||
}
|
||||
@@ -71,6 +71,13 @@ const config = defineConfig({
|
||||
},
|
||||
spacing: {
|
||||
gutter: { value: 'clamp(1.25rem, 4vw, 3rem)' }, // zijmarge van de pagina
|
||||
// Vertical rhythm of homepage sections (design --section-y)
|
||||
sectionY: { value: 'clamp(4.5rem, 9vw, 8.5rem)' },
|
||||
sectionYTight: { value: 'clamp(2.7rem, 5.4vw, 5.1rem)' },
|
||||
// Space below a section heading (design .section__head)
|
||||
sectionHeadGap: { value: 'clamp(2.5rem, 5vw, 4.5rem)' },
|
||||
// Gap between grid items such as photos and cards (design --gap)
|
||||
gridGap: { value: 'clamp(1rem, 2.2vw, 2rem)' },
|
||||
},
|
||||
easings: {
|
||||
smooth: { value: 'cubic-bezier(.22, .61, .36, 1)' },
|
||||
@@ -78,6 +85,7 @@ const config = defineConfig({
|
||||
durations: {
|
||||
interaction: { value: '0.45s' }, // hover, focus
|
||||
fade: { value: '1.2s' }, // overvloeien van foto's
|
||||
reveal: { value: '0.8s' }, // fade-in of sections on scroll
|
||||
},
|
||||
// Stapelvolgorde van de vaste shell-onderdelen, van laag naar hoog
|
||||
zIndex: {
|
||||
@@ -133,6 +141,8 @@ const config = defineConfig({
|
||||
},
|
||||
// Maximale breedte van de content (Container en de to-top-knop)
|
||||
content: { value: '{sizes.8xl}' },
|
||||
// Narrow content column, e.g. the contact form (design --container-narrow)
|
||||
contentNarrow: { value: '820px' },
|
||||
},
|
||||
spacing: {
|
||||
// Zelfde waarde voor content die onder de balk begint (pt="header")
|
||||
@@ -160,6 +170,22 @@ const config = defineConfig({
|
||||
lineHeight: '1',
|
||||
},
|
||||
},
|
||||
// The h2 of a homepage section (SectionHeading)
|
||||
sectionTitle: {
|
||||
value: {
|
||||
fontFamily: 'heading',
|
||||
fontSize: { base: '1.85rem', md: '2.125rem', xl: '2.5rem' },
|
||||
lineHeight: '1.15',
|
||||
},
|
||||
},
|
||||
// Intro sentence below a section heading
|
||||
lead: {
|
||||
value: {
|
||||
fontSize: '1.25rem',
|
||||
fontWeight: '300',
|
||||
lineHeight: '1.6',
|
||||
},
|
||||
},
|
||||
// De h1 van een gewone pagina (PageIntro, StatusPage)
|
||||
pageTitle: {
|
||||
value: {
|
||||
|
||||
Reference in New Issue
Block a user