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:
2026-10-20 00:01:44 +02:00
co-authored by Claude Opus 5.5
parent c81dcd3979
commit b2717df049
29 changed files with 903 additions and 23 deletions
@@ -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>
);
}
+28
View File
@@ -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');
});
});
+30
View File
@@ -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>
);
}