diff --git a/aidlc-docs/features/homepage-sections/aidlc-state.md b/aidlc-docs/features/homepage-sections/aidlc-state.md index 9a2974c..6b62c84 100644 --- a/aidlc-docs/features/homepage-sections/aidlc-state.md +++ b/aidlc-docs/features/homepage-sections/aidlc-state.md @@ -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 diff --git a/aidlc-docs/features/homepage-sections/audit.md b/aidlc-docs/features/homepage-sections/audit.md index 6eb13c9..1186bd3 100644 --- a/aidlc-docs/features/homepage-sections/audit.md +++ b/aidlc-docs/features/homepage-sections/audit.md @@ -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) + +--- diff --git a/aidlc-docs/features/homepage-sections/construction/lifestyle-fotografie/code/code-summary.md b/aidlc-docs/features/homepage-sections/construction/lifestyle-fotografie/code/code-summary.md new file mode 100644 index 0000000..4fcfc50 --- /dev/null +++ b/aidlc-docs/features/homepage-sections/construction/lifestyle-fotografie/code/code-summary.md @@ -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. diff --git a/aidlc-docs/features/homepage-sections/construction/plans/lifestyle-fotografie-code-generation-plan.md b/aidlc-docs/features/homepage-sections/construction/plans/lifestyle-fotografie-code-generation-plan.md index 48ac02f..a12329a 100644 --- a/aidlc-docs/features/homepage-sections/construction/plans/lifestyle-fotografie-code-generation-plan.md +++ b/aidlc-docs/features/homepage-sections/construction/plans/lifestyle-fotografie-code-generation-plan.md @@ -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`: `
` 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`: `
` 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 | diff --git a/web/src/app.test.tsx b/web/src/app.test.tsx index c16ee5a..8d17b11 100644 --- a/web/src/app.test.tsx +++ b/web/src/app.test.tsx @@ -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('/'); diff --git a/web/src/assets/home/intro-1.jpg b/web/src/assets/home/intro-1.jpg new file mode 100644 index 0000000..8c08968 Binary files /dev/null and b/web/src/assets/home/intro-1.jpg differ diff --git a/web/src/assets/home/intro-2.jpg b/web/src/assets/home/intro-2.jpg new file mode 100644 index 0000000..372e550 Binary files /dev/null and b/web/src/assets/home/intro-2.jpg differ diff --git a/web/src/assets/home/intro-3.jpg b/web/src/assets/home/intro-3.jpg new file mode 100644 index 0000000..ad2aa8f Binary files /dev/null and b/web/src/assets/home/intro-3.jpg differ diff --git a/web/src/assets/home/intro-4.jpg b/web/src/assets/home/intro-4.jpg new file mode 100644 index 0000000..be9d05f Binary files /dev/null and b/web/src/assets/home/intro-4.jpg differ diff --git a/web/src/components/DeferredImage/DeferredImage.test.tsx b/web/src/components/DeferredImage/DeferredImage.test.tsx new file mode 100644 index 0000000..683c232 --- /dev/null +++ b/web/src/components/DeferredImage/DeferredImage.test.tsx @@ -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(); + 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(); + 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(); + 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'); + }); +}); diff --git a/web/src/components/DeferredImage/DeferredImage.tsx b/web/src/components/DeferredImage/DeferredImage.tsx new file mode 100644 index 0000000..a13445b --- /dev/null +++ b/web/src/components/DeferredImage/DeferredImage.tsx @@ -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 & { + 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({ + rootMargin: LOAD_MARGIN, + }); + + return ( + {image.alt} + ); +} diff --git a/web/src/components/HomeSection/HomeSection.test.tsx b/web/src/components/HomeSection/HomeSection.test.tsx new file mode 100644 index 0000000..5f774ec --- /dev/null +++ b/web/src/components/HomeSection/HomeSection.test.tsx @@ -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( + +

Over mij

+
, + ); + 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( + +

Contact

+
, + ); + expect(screen.getByRole('region', { name: 'Contact' })).toHaveAttribute( + 'id', + 'contact', + ); + }); +}); diff --git a/web/src/components/HomeSection/HomeSection.tsx b/web/src/components/HomeSection/HomeSection.tsx new file mode 100644 index 0000000..656c070 --- /dev/null +++ b/web/src/components/HomeSection/HomeSection.tsx @@ -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 ( + + + {children} + + + ); +} diff --git a/web/src/components/Reveal/Reveal.test.tsx b/web/src/components/Reveal/Reveal.test.tsx new file mode 100644 index 0000000..35a3f73 --- /dev/null +++ b/web/src/components/Reveal/Reveal.test.tsx @@ -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( + +

Inhoud

+
, + ); + 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( + + Foto + , + ); + expect(screen.getByTestId('reveal').tagName).toBe('FIGURE'); + }); +}); diff --git a/web/src/components/Reveal/Reveal.tsx b/web/src/components/Reveal/Reveal.tsx new file mode 100644 index 0000000..be5f0dc --- /dev/null +++ b/web/src/components/Reveal/Reveal.tsx @@ -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(); + + return ( + + {children} + + ); +} diff --git a/web/src/components/SectionHeading/SectionHeading.test.tsx b/web/src/components/SectionHeading/SectionHeading.test.tsx new file mode 100644 index 0000000..004595f --- /dev/null +++ b/web/src/components/SectionHeading/SectionHeading.test.tsx @@ -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( + , + ); + 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( + , + ); + expect( + screen.getByRole('heading', { level: 2, name: 'Instagram' }), + ).toBeInTheDocument(); + expect(container.querySelectorAll('p')).toHaveLength(0); + }); +}); diff --git a/web/src/components/SectionHeading/SectionHeading.tsx b/web/src/components/SectionHeading/SectionHeading.tsx new file mode 100644 index 0000000..cedd9c5 --- /dev/null +++ b/web/src/components/SectionHeading/SectionHeading.tsx @@ -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 ( + + {eyebrow && ( + // accent.deep instead of the design's accent: meets 4.5:1 (NFR-HP-01) + + {eyebrow} + + )} + + {title} + + {lead && ( + + {lead} + + )} + + ); +} diff --git a/web/src/components/home/IntroGallery/IntroGallery.test.tsx b/web/src/components/home/IntroGallery/IntroGallery.test.tsx new file mode 100644 index 0000000..70a0047 --- /dev/null +++ b/web/src/components/home/IntroGallery/IntroGallery.test.tsx @@ -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( + , + ); + 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(); + 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( + , + ); + expect( + screen.getByRole('heading', { name: 'Lifestyle fotografie' }), + ).toBeInTheDocument(); + expect(screen.queryAllByRole('img')).toHaveLength(0); + }); +}); diff --git a/web/src/components/home/IntroGallery/IntroGallery.tsx b/web/src/components/home/IntroGallery/IntroGallery.tsx new file mode 100644 index 0000000..1667908 --- /dev/null +++ b/web/src/components/home/IntroGallery/IntroGallery.tsx @@ -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 ( + + + + + + {content.photos.map((photo, index) => ( + + + + + + ))} + + + ); +} diff --git a/web/src/content/homeContent.ts b/web/src/content/homeContent.ts new file mode 100644 index 0000000..6a5a0f1 --- /dev/null +++ b/web/src/content/homeContent.ts @@ -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; diff --git a/web/src/content/types.ts b/web/src/content/types.ts index 7de09dc..852ab8a 100644 --- a/web/src/content/types.ts +++ b/web/src/content/types.ts @@ -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; diff --git a/web/src/hooks/useInView.ts b/web/src/hooks/useInView.ts new file mode 100644 index 0000000..3cec008 --- /dev/null +++ b/web/src/hooks/useInView.ts @@ -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({ + threshold = 0, + rootMargin = '0px', + skip = false, +}: UseInViewOptions = {}) { + const ref = useRef(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 }; +} diff --git a/web/src/hooks/usePageLoaded.test.tsx b/web/src/hooks/usePageLoaded.test.tsx new file mode 100644 index 0000000..1a060ed --- /dev/null +++ b/web/src/hooks/usePageLoaded.test.tsx @@ -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); + }); +}); diff --git a/web/src/hooks/usePageLoaded.ts b/web/src/hooks/usePageLoaded.ts new file mode 100644 index 0000000..ac88811 --- /dev/null +++ b/web/src/hooks/usePageLoaded.ts @@ -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; +} diff --git a/web/src/hooks/useReveal.test.tsx b/web/src/hooks/useReveal.test.tsx new file mode 100644 index 0000000..70631c7 --- /dev/null +++ b/web/src/hooks/useReveal.test.tsx @@ -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(); + return ( +
+ {visible ? 'visible' : 'hidden'} +
+ ); +} + +const renderProbe = () => + render( + + + , + ); + +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); + }); +}); diff --git a/web/src/hooks/useReveal.ts b/web/src/hooks/useReveal.ts new file mode 100644 index 0000000..d230463 --- /dev/null +++ b/web/src/hooks/useReveal.ts @@ -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() { + const [reducedMotion] = useMediaQuery( + ['(prefers-reduced-motion: reduce)'], + { ssr: false }, + ); + const { ref, inView } = useInView({ + threshold: 0.12, + rootMargin: '0px 0px -60px 0px', + skip: reducedMotion, + }); + + return { ref, visible: inView }; +} diff --git a/web/src/routes/index.tsx b/web/src/routes/index.tsx index b632c41..b44f043 100644 --- a/web/src/routes/index.tsx +++ b/web/src/routes/index.tsx @@ -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 ; + return ( + <> + + + + ); } diff --git a/web/src/test/fakeIntersectionObserver.ts b/web/src/test/fakeIntersectionObserver.ts new file mode 100644 index 0000000..ab07e36 --- /dev/null +++ b/web/src/test/fakeIntersectionObserver.ts @@ -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 = []; + } +} diff --git a/web/src/theme.ts b/web/src/theme.ts index 7ea8f69..3308575 100644 --- a/web/src/theme.ts +++ b/web/src/theme.ts @@ -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: {