From 3e530df0af07fe755c27fed51eb453f2f29b1ebf Mon Sep 17 00:00:00 2001 From: Sluijsens Date: Tue, 20 Oct 2026 00:14:47 +0200 Subject: [PATCH] Shows the Lifestyle fotografie photos as a swipeable row on phones Four stacked photos were too much on a phone screen. Below the small breakpoint the gallery is now a scroll-snap row with one photo at a time and the next one peeking in; tablets and desktops keep the grid. Co-Authored-By: Claude Opus 5.5 --- .../features/homepage-sections/audit.md | 12 ++ .../lifestyle-fotografie/code/code-summary.md | 8 ++ ...festyle-fotografie-code-generation-plan.md | 3 + .../inception/requirements/requirements.md | 3 +- design/andreaslop-static/assets/css/style.css | 14 ++- .../DeferredImage/DeferredImage.test.tsx | 18 +++ .../DeferredImage/DeferredImage.tsx | 13 +- .../home/IntroGallery/IntroGallery.test.tsx | 18 +-- .../home/IntroGallery/IntroGallery.tsx | 115 +++++++++++------- 9 files changed, 149 insertions(+), 55 deletions(-) diff --git a/aidlc-docs/features/homepage-sections/audit.md b/aidlc-docs/features/homepage-sections/audit.md index 1186bd3..576cd43 100644 --- a/aidlc-docs/features/homepage-sections/audit.md +++ b/aidlc-docs/features/homepage-sections/audit.md @@ -245,3 +245,15 @@ Nou is het nog een statische site zonder back-end dus het contactformulier kan n **Context**: CONSTRUCTION - Unit 1 Code Generation (complete, awaiting approval) --- + +## Unit 1 Lifestyle fotografie — Change Request + +**Timestamp**: 2026-10-20T00:30:00Z + +**User Input**: "o pmobiel staan nu 4 afbeeldingen onder elkaar. dat is een beetje veel. kan je zorgen dat op mobiele schermen 1 afbeelding tegelijk wordt getoond die je kan swipen naar de volgende foto en dat je zo alle 4 de foto's alsnog kan bekijken?" + +**AI Response**: "Implemented a CSS scroll-snap row below sm (85% wide photos, next one peeking in, keyboard-focusable list), gallery-level deferred loading (DeferredImage near prop) because clipped items never intersect, single fade-in for the gallery. Updated the static design and FR-HP-02. Verified at an emulated 390px phone via CDP. pnpm check green (139 tests; Lighthouse home mobile 0.84, desktop 1.0, a11y 1.0). Committed locally. Re-presented the completion message." + +**Context**: CONSTRUCTION - Unit 1 Code Generation (change applied, 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 index 4fcfc50..f6cf460 100644 --- 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 @@ -30,6 +30,14 @@ Plan: [lifestyle-fotografie-code-generation-plan.md](../../plans/lifestyle-fotog ## 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. +## Change request after review: swipeable row on phones +Requested: on phones the four photos stacked vertically were too much; show one at a time and swipe to the next. +- `IntroGallery` now renders the photos as a list (`ul` named "Foto's"). Below `sm` it is a full-bleed row with CSS scroll snap: each photo 85% of the width, centred on snap, the next one peeking in; scrollbar hidden; the list is focusable (`tabIndex=0`, only while it scrolls, via `useBreakpointValue`) so keyboard users can scroll it with the arrow keys. From `sm` the grid (2 / 4 columns, staggered offsets) is unchanged. +- Photos clipped by the scroller never intersect on their own, so the gallery observes its list once (`useInView`, 600 px margin) and passes `near` to each `DeferredImage` (new optional prop). The gallery now fades in as one block instead of per photo. +- Static design updated to match (`style.css`, ≤ 680 px); FR-HP-02 updated. +- Verified at an emulated 390×844 phone via the Chrome DevTools Protocol (one photo with the next peeking in; second photo snaps to the centre after swiping). +- `pnpm check` green: **139 tests**, Lighthouse home mobile **0.84** (LCP 3.9 s), desktop **1.0**, accessibility/best practices/SEO **1.0**. + ## Image script Images are resized with a one-off PowerShell script (not part of the project; .NET `System.Drawing`, Windows). Command used: 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 a12329a..e6f4ae0 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 @@ -63,6 +63,9 @@ ### 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). +### Change request at review +- [x] **Step 21** — Phones: one photo at a time in a swipeable scroll-snap row with the next photo peeking in; keyboard-scrollable list; gallery-level loading via `DeferredImage near`; static design and FR-HP-02 updated; `pnpm check` green. + ## Requirement traceability | Requirement | Steps | |---|---| diff --git a/aidlc-docs/features/homepage-sections/inception/requirements/requirements.md b/aidlc-docs/features/homepage-sections/inception/requirements/requirements.md index d9f71dc..e28fbd3 100644 --- a/aidlc-docs/features/homepage-sections/inception/requirements/requirements.md +++ b/aidlc-docs/features/homepage-sections/inception/requirements/requirements.md @@ -38,7 +38,8 @@ Each of the six new sections is a separate unit of work. ### FR-HP-02 Lifestyle fotografie - Heading **"Lifestyle fotografie"** (h2) with lead text "Jouw favoriete momenten, vastgelegd op een natuurlijke en ongedwongen manier." -- A gallery of **four photos** (the four current live photos), layout as `.intro-gallery` in the design. +- A gallery of **four photos** (the four current live photos), layout as `.intro-gallery` in the design: 4 columns on desktop, 2 on tablet. +- **On phones one photo at a time** in a horizontally swipeable row (scroll snap), with the next photo peeking in so it is clear there is more; the row is keyboard-scrollable. *Source: user change request at unit 1 review* - Every photo has a descriptive Dutch alt text (to be reviewed by Andrea). - The live page's stray headings "Foto2" and "Foto" are not carried over. - *Source: Q1 = A* diff --git a/design/andreaslop-static/assets/css/style.css b/design/andreaslop-static/assets/css/style.css index 024497d..8aa1cfe 100644 --- a/design/andreaslop-static/assets/css/style.css +++ b/design/andreaslop-static/assets/css/style.css @@ -1407,7 +1407,19 @@ p:last-child { margin-bottom: 0; } .hero__socials { bottom: 1.5rem; flex-direction: row; } .hero__scroll { display: none; } - .intro-gallery { grid-template-columns: 1fr; } + /* Phones: one photo at a time in a swipeable row, the next one peeking in */ + .intro-gallery:not(.intro-gallery--duo) { + display: flex; + overflow-x: auto; + scroll-snap-type: x mandatory; + scroll-padding-inline: var(--gutter); + margin-inline: calc(-1 * var(--gutter)); + padding-inline: var(--gutter); + scrollbar-width: none; + } + .intro-gallery:not(.intro-gallery--duo)::-webkit-scrollbar { display: none; } + .intro-gallery:not(.intro-gallery--duo) figure { flex: 0 0 85%; scroll-snap-align: center; } + .intro-gallery--duo { grid-template-columns: 1fr; } .intro-gallery figure { margin-top: 0 !important; } .portfolio-grid { grid-template-columns: 1fr; } diff --git a/web/src/components/DeferredImage/DeferredImage.test.tsx b/web/src/components/DeferredImage/DeferredImage.test.tsx index 683c232..2e70a93 100644 --- a/web/src/components/DeferredImage/DeferredImage.test.tsx +++ b/web/src/components/DeferredImage/DeferredImage.test.tsx @@ -50,4 +50,22 @@ describe('DeferredImage', () => { }); expect(img).toHaveAttribute('src', '/foto.jpg'); }); + + it('follows the near prop from a parent instead of observing itself', async () => { + vi.stubGlobal('IntersectionObserver', FakeIntersectionObserver); + const { unmount } = await renderWithProviders( + , + ); + expect( + screen.getByRole('img', { name: 'Een foto' }), + ).not.toHaveAttribute('src'); + unmount(); + + await renderWithProviders(); + expect(screen.getByRole('img', { name: 'Een foto' })).toHaveAttribute( + 'src', + '/foto.jpg', + ); + expect(FakeIntersectionObserver.instances).toHaveLength(0); + }); }); diff --git a/web/src/components/DeferredImage/DeferredImage.tsx b/web/src/components/DeferredImage/DeferredImage.tsx index a13445b..d498b7a 100644 --- a/web/src/components/DeferredImage/DeferredImage.tsx +++ b/web/src/components/DeferredImage/DeferredImage.tsx @@ -8,6 +8,9 @@ const LOAD_MARGIN = '600px 0px'; type DeferredImageProps = Omit & { image: ContentImage; + // Set by a parent that knows better, e.g. a horizontal scroller whose + // off-screen items are clipped and would never intersect on their own + near?: boolean; }; // A below-the-fold image that only starts downloading once the page has @@ -16,16 +19,22 @@ type DeferredImageProps = Omit & { // 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) { +export default function DeferredImage({ + image, + near, + ...rest +}: DeferredImageProps) { const pageLoaded = usePageLoaded(); const { ref, inView } = useInView({ rootMargin: LOAD_MARGIN, + skip: near !== undefined, }); + const load = pageLoaded && (near ?? inView); return ( {image.alt} { expect(await axeResults(container)).toHaveNoViolations(); }); - it('shows every photo as a figure, in order', async () => { + it('shows the photos as a list in order, swipeable and focusable on phones', async () => { await renderWithProviders(); - homeContent.intro.photos.forEach((photo, index) => { - const figure = screen.getByTestId( - `intro-gallery-photo-${index + 1}`, + // jsdom has no viewport, so Chakra resolves the base (phone) breakpoint + const list = screen.getByRole('list', { name: "Foto's" }); + expect(list).toHaveAttribute('tabindex', '0'); + const items = within(list).getAllByRole('listitem'); + expect(items).toHaveLength(homeContent.intro.photos.length); + items.forEach((item, index) => { + expect(item).toBe( + screen.getByTestId(`intro-gallery-photo-${index + 1}`), ); - expect(figure.tagName).toBe('FIGURE'); - expect(within(figure).getByRole('img')).toHaveAttribute( + expect(within(item).getByRole('img')).toHaveAttribute( 'alt', - photo.alt, + homeContent.intro.photos[index].alt, ); }); }); diff --git a/web/src/components/home/IntroGallery/IntroGallery.tsx b/web/src/components/home/IntroGallery/IntroGallery.tsx index 1667908..52d0a25 100644 --- a/web/src/components/home/IntroGallery/IntroGallery.tsx +++ b/web/src/components/home/IntroGallery/IntroGallery.tsx @@ -1,9 +1,10 @@ -import { Box, Grid } from '@chakra-ui/react'; +import { chakra, useBreakpointValue } 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'; +import useInView from '@/hooks/useInView'; const TITLE_ID = 'intro-title'; @@ -11,16 +12,24 @@ const TITLE_ID = 'intro-title'; // .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. +// (design .intro-gallery). On phones the photos form a swipeable row, one +// at a time with the next one peeking in; from `sm` a grid of 2, from `lg` +// of 4 columns. export default function IntroGallery({ content }: IntroGalleryProps) { + // Photos outside the row are clipped by the scroller and never intersect + // on their own, so the whole gallery decides when they load. + const { ref, inView } = useInView({ + rootMargin: '600px 0px', + }); + // Only the swipeable row scrolls, so only then is it a focus stop for + // keyboard scrolling + const scrollable = useBreakpointValue({ base: true, sm: false }) ?? false; + return ( @@ -30,46 +39,64 @@ export default function IntroGallery({ content }: IntroGalleryProps) { lead={content.lead} /> - - {content.photos.map((photo, index) => ( - - + + {content.photos.map((photo, index) => ( + - - - - ))} - + + + + + ))} + + ); }