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 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 00:14:47 +02:00
co-authored by Claude Opus 5.5
parent b2717df049
commit 3e530df0af
9 changed files with 149 additions and 55 deletions
@@ -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)
---
@@ -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:
@@ -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 |
|---|---|
@@ -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*
+13 -1
View File
@@ -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; }
@@ -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(
<DeferredImage image={image} near={false} />,
);
expect(
screen.getByRole('img', { name: 'Een foto' }),
).not.toHaveAttribute('src');
unmount();
await renderWithProviders(<DeferredImage image={image} near />);
expect(screen.getByRole('img', { name: 'Een foto' })).toHaveAttribute(
'src',
'/foto.jpg',
);
expect(FakeIntersectionObserver.instances).toHaveLength(0);
});
});
@@ -8,6 +8,9 @@ const LOAD_MARGIN = '600px 0px';
type DeferredImageProps = Omit<ImageProps, 'src' | 'alt'> & {
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<ImageProps, 'src' | 'alt'> & {
// 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<HTMLImageElement>({
rootMargin: LOAD_MARGIN,
skip: near !== undefined,
});
const load = pageLoaded && (near ?? inView);
return (
<Image
ref={ref}
src={pageLoaded && inView ? image.src : undefined}
src={load ? image.src : undefined}
alt={image.alt}
htmlWidth={image.width}
htmlHeight={image.height}
@@ -32,16 +32,20 @@ describe('IntroGallery', () => {
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(<IntroGallery content={homeContent.intro} />);
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,
);
});
});
@@ -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<HTMLUListElement>({
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 (
<HomeSection labelledBy={TITLE_ID} data-testid="intro-gallery">
<Reveal>
@@ -30,46 +39,64 @@ export default function IntroGallery({ content }: IntroGalleryProps) {
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)' },
}}
<Reveal>
<chakra.ul
ref={ref}
listStyleType="none"
aria-label="Foto's"
tabIndex={scrollable ? 0 : undefined}
data-testid="intro-gallery-photos"
display={{ base: 'flex', sm: 'grid' }}
gridTemplateColumns={{
sm: 'repeat(2, 1fr)',
lg: 'repeat(4, 1fr)',
}}
alignItems="start"
gap="gridGap"
// Phones: a full-bleed row that snaps to each photo
overflowX={{ base: 'auto', sm: 'visible' }}
scrollSnapType={{ base: 'x mandatory', sm: 'none' }}
scrollPaddingInline="gutter"
mx={{ base: 'calc(-1 * {spacing.gutter})', sm: 0 }}
px={{ base: 'gutter', sm: 0 }}
scrollbarWidth="none"
css={{ '&::-webkit-scrollbar': { display: 'none' } }}
>
{content.photos.map((photo, index) => (
<chakra.li
key={photo.src}
flex={{ base: '0 0 85%', sm: 'initial' }}
scrollSnapAlign="center"
mt={index % 2 === 1 ? { base: 0, sm: OFFSET } : 0}
data-testid={`intro-gallery-photo-${index + 1}`}
>
<DeferredImage
image={photo}
w="100%"
h="auto"
aspectRatio="3 / 4"
objectFit="cover"
transitionProperty="transform"
transitionDuration="fade"
transitionTimingFunction="smooth"
_motionReduce={{ transition: 'none' }}
/>
</Box>
</Reveal>
))}
</Grid>
<chakra.figure
overflow="hidden"
// Shown until the deferred photo arrives
bg="paper.deep"
css={{
'&:hover img': {
transform: 'scale(1.05)',
},
}}
>
<DeferredImage
image={photo}
near={inView}
w="100%"
h="auto"
aspectRatio="3 / 4"
objectFit="cover"
transitionProperty="transform"
transitionDuration="fade"
transitionTimingFunction="smooth"
_motionReduce={{ transition: 'none' }}
/>
</chakra.figure>
</chakra.li>
))}
</chakra.ul>
</Reveal>
</HomeSection>
);
}