Adds the portfolio page

The ten live photos in a filterable masonry grid with an accessible
lightbox, filters per shoot type kept in the URL (?shoot=), the shared
Instagram block, and an indexed page with image gallery structured data
and its own preview image. Soorten fotoshoots now only links to the
portfolio for shoot types that have photos there.

The filter bar stays on one row, so the web font loading no longer
shifts the photos below it, and no photo loads before the page has: the
grid fades in, so loading its photos early only delayed the fonts and the
intro text.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-27 19:05:13 +01:00
co-authored by Claude Opus 5.5
parent 18bf0311ef
commit 9efa7fc596
58 changed files with 1492 additions and 48 deletions
+8 -2
View File
@@ -29,8 +29,14 @@ export default function FilterBar({
aria-label={label}
data-testid="filter-bar"
display="flex"
flexWrap="wrap"
justifyContent="center"
// One row, always: when the web font replaces the fallback, a
// wrapping row could gain or lose a line and push the photos
// below it down (layout shift). Too narrow: the row scrolls.
flexWrap="nowrap"
overflowX="auto"
// Centred while it fits; from the start when it scrolls, so the
// first choice is never cut off
justifyContent="safe center"
columnGap={{ base: 4, md: 6 }}
>
{options.map((option) => {
@@ -0,0 +1,145 @@
import { useEffect, useState } from 'react';
import { act, screen, waitFor, within } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';
import portfolioContent from '@/content/portfolioContent';
import shootTypes from '@/content/shootTypes';
import type { ShootTypeId } from '@/content/types';
import { axeResults } from '@/test/axe';
import { renderWithProviders } from '@/test/renderWithProviders';
import PortfolioGallery from './PortfolioGallery';
const photos = portfolioContent.photos;
// Lets a test change the shoot from outside, as the route would
let setShootFromOutside: (shoot: string | undefined) => void = () => {};
// The route's part: it keeps the chosen shoot (in the URL)
function Harness({
start,
onShootChange = () => {},
}: {
start?: string;
onShootChange?: (shoot: ShootTypeId | undefined) => void;
}) {
const [shoot, setShoot] = useState<string | undefined>(start);
useEffect(() => {
setShootFromOutside = setShoot;
}, []);
return (
<PortfolioGallery
photos={photos}
shootTypes={shootTypes}
shoot={shoot}
onShootChange={(next) => {
setShoot(next);
onShootChange(next);
}}
/>
);
}
// By test id: while the closed dialog fades out (in jsdom it never
// finishes), the page behind it is still hidden from the accessibility tree
const tiles = () =>
screen
.getByTestId('portfolio-grid')
.querySelectorAll('[data-testid^="portfolio-tile-"]');
describe('PortfolioGallery', () => {
it('is a section named by a hidden heading, with filters for the types that have photos', async () => {
const { container } = await renderWithProviders(<Harness />);
expect(
screen.getByRole('region', { name: "Foto's" }),
).toBeInTheDocument();
const group = screen.getByRole('group', {
name: 'Filter op soort shoot',
});
expect(
within(group)
.getAllByRole('button')
.map((b) => b.textContent),
).toEqual(['Alles', 'Newborn', 'Zwangerschap', 'Gezin']);
expect(
screen.getByRole('button', { name: 'Alles', pressed: true }),
).toBeInTheDocument();
expect(tiles()).toHaveLength(10);
// Every photo waits until the page has loaded (none eager)
for (const image of screen.getAllByRole('img')) {
expect(image).not.toHaveAttribute('fetchpriority');
expect(image).toHaveAttribute('loading', 'lazy');
}
expect(await axeResults(container)).toHaveNoViolations();
});
it('filters on a shoot type, announces the count and reports the choice', async () => {
const onShootChange = vi.fn();
await renderWithProviders(<Harness onShootChange={onShootChange} />);
const user = userEvent.setup();
await user.click(screen.getByRole('button', { name: 'Gezin' }));
expect(onShootChange).toHaveBeenLastCalledWith('gezin');
expect(tiles()).toHaveLength(2);
expect(screen.getByTestId('portfolio-count')).toHaveTextContent(
"2 foto's",
);
await user.click(screen.getByRole('button', { name: 'Alles' }));
expect(onShootChange).toHaveBeenLastCalledWith(undefined);
expect(tiles()).toHaveLength(10);
});
it('starts with the shoot from the URL', async () => {
await renderWithProviders(<Harness start="zwangerschap" />);
expect(
screen.getByRole('button', { name: 'Zwangerschap', pressed: true }),
).toBeInTheDocument();
expect(tiles()).toHaveLength(2);
});
it.each(['loveshoot', 'onzin', '<script>'])(
'shows everything for ?shoot=%s',
async (value) => {
await renderWithProviders(<Harness start={value} />);
expect(
screen.getByRole('button', { name: 'Alles', pressed: true }),
).toBeInTheDocument();
expect(tiles()).toHaveLength(10);
expect(document.body).not.toHaveTextContent(value);
},
);
it('opens the lightbox within the filtered photos, captioned with the shoot type', async () => {
await renderWithProviders(<Harness start="gezin" />);
const user = userEvent.setup();
await user.click(screen.getByTestId('portfolio-tile-2'));
const counter = await screen.findByTestId('lightbox-counter');
expect(counter).toHaveTextContent('2 / 2');
expect(screen.getByTestId('lightbox-caption')).toHaveTextContent(
'Gezinsshoot',
);
expect(screen.getByTestId('lightbox-image')).toHaveAttribute(
'src',
photos.find((p) => p.id === 'f41a7138')?.full.src,
);
});
it('closes the lightbox when the filter changes', async () => {
await renderWithProviders(<Harness />);
const user = userEvent.setup();
await user.click(screen.getByTestId('portfolio-tile-1'));
expect(await screen.findByTestId('lightbox')).toHaveAttribute(
'data-state',
'open',
);
// The dialog makes the page inert, so the filter changes from
// outside, as through the URL
act(() => setShootFromOutside('newborn'));
expect(tiles()).toHaveLength(6);
// A close from the parent reaches the dialog in an effect
await waitFor(() =>
expect(screen.getByTestId('lightbox')).toHaveAttribute(
'data-state',
'closed',
),
);
});
});
@@ -0,0 +1,136 @@
import { lazy, Suspense, useReducer, useRef, useState } from 'react';
import { Box, chakra, Heading, VisuallyHidden } from '@chakra-ui/react';
import FilterBar from '@/components/FilterBar/FilterBar';
import PageSection from '@/components/PageSection/PageSection';
import PortfolioGrid from '@/components/PortfolioGrid/PortfolioGrid';
import type { PortfolioPhoto, ShootType, ShootTypeId } from '@/content/types';
import { closedLightbox, lightboxReducer } from '@/lib/lightboxReducer';
import {
ALL_FILTER,
filterOptions,
filterPhotos,
photoCountLabel,
shootFromSearch,
shootTypesWithPhotos,
toGalleryItems,
} from '@/lib/portfolioFilters';
// Loaded on the first hover, focus or click on a photo (application design Q7)
const Lightbox = lazy(() => import('@/components/Lightbox/Lightbox'));
const TITLE_ID = 'portfolio-title';
type PortfolioGalleryProps = {
photos: readonly PortfolioPhoto[];
shootTypes: readonly ShootType[];
// The shoot from ?shoot=; checked here against the types with photos
shoot: string | undefined;
onShootChange: (shoot: ShootTypeId | undefined) => void;
};
// The portfolio's photos: filters per shoot type, the masonry grid and the
// lightbox, connected. The URL holds the chosen filter (via the route); this
// component holds which photo is open.
export default function PortfolioGallery({
photos,
shootTypes,
shoot,
onShootChange,
}: PortfolioGalleryProps) {
const available = shootTypesWithPhotos(shootTypes, photos);
const active = shootFromSearch(
shoot,
available.map((type) => type.id),
);
const shown = filterPhotos(photos, active);
const items = toGalleryItems(shown, shootTypes);
const [lightbox, dispatch] = useReducer(lightboxReducer, closedLightbox);
const [lightboxRequested, setLightboxRequested] = useState(false);
const [announcement, setAnnouncement] = useState('');
const grid = useRef<HTMLDivElement>(null);
// Another list, however the filter changed: the open photo may no longer
// be in it, so the lightbox closes (BR-FL-05). Adjusted during render,
// as React advises for state that follows a prop.
const [listFor, setListFor] = useState(active);
if (listFor !== active) {
setListFor(active);
dispatch({ type: 'listChanged', count: items.length });
}
const chooseFilter = (id: string) => {
const next = id === ALL_FILTER ? undefined : (id as ShootTypeId);
setAnnouncement(photoCountLabel(filterPhotos(photos, next).length));
onShootChange(next);
};
const open = (index: number) => {
setLightboxRequested(true);
dispatch({ type: 'open', index, count: items.length });
};
// Back to the tile of the photo shown last (BR-LB-08)
const tileOfShownPhoto = () =>
lightbox.open
? (grid.current?.querySelector<HTMLElement>(
`[data-testid="portfolio-tile-${lightbox.index + 1}"]`,
) ?? null)
: null;
return (
<PageSection
labelledBy={TITLE_ID}
spacing="flushTop"
data-testid="portfolio-gallery"
>
{/* The design shows no heading here; one for screen readers
names the section */}
<VisuallyHidden>
<Heading as="h2" id={TITLE_ID}>
Foto's
</Heading>
</VisuallyHidden>
<Box mb={{ base: 6, md: 10 }}>
<FilterBar
options={filterOptions(available, 'Alles')}
value={active ?? ALL_FILTER}
onChange={chooseFilter}
label="Filter op soort shoot"
/>
</Box>
<chakra.p srOnly aria-live="polite" data-testid="portfolio-count">
{announcement}
</chakra.p>
<Box ref={grid}>
<PortfolioGrid
items={items}
// No photo loads before the page has: the grid fades in, so
// its photos are never the largest paint, and loading them
// early only slowed the fonts and the intro text (measured
// 0.80 vs 0.91 on mobile; decision 2026-10-27)
eagerCount={0}
onOpen={open}
onIntent={() => setLightboxRequested(true)}
/>
</Box>
{lightboxRequested && (
<Suspense fallback={null}>
<Lightbox
items={items}
index={lightbox.open ? lightbox.index : null}
onIndexChange={(index) =>
dispatch({
type: 'open',
index,
count: items.length,
})
}
onClose={() => dispatch({ type: 'close' })}
finalFocusEl={tileOfShownPhoto}
/>
</Suspense>
)}
</PageSection>
);
}
@@ -10,7 +10,7 @@ const shoot = (id: string) => shootTypes.find((item) => item.id === id)!;
const renderBlock = (
id: string,
{ portfolioLive = false, reverse = false, priority = false } = {},
{ portfolioLink = false, reverse = false, priority = false } = {},
) =>
renderWithProviders(
<ShootBlock
@@ -18,7 +18,7 @@ const renderBlock = (
packages={packages}
reverse={reverse}
priority={priority}
portfolioLive={portfolioLive}
portfolioLink={portfolioLink}
/>,
);
@@ -67,7 +67,7 @@ describe('ShootBlock', () => {
});
it('links to the portfolio filtered on the shoot type when live', async () => {
await renderBlock('portret', { portfolioLive: true });
await renderBlock('portret', { portfolioLink: true });
expect(
screen.getByRole('link', { name: "Bekijk meer portretfoto's" }),
).toHaveAttribute('href', '/portfolio?shoot=portret');
@@ -13,8 +13,8 @@ type ShootBlockProps = {
reverse: boolean;
// The first photo on the page loads straight away
priority: boolean;
// Show "Bekijk meer …foto's" (BR-SF-04)
portfolioLive: boolean;
// Show "Bekijk meer …foto's" (BR-SF-04, BR-SL-01)
portfolioLink: boolean;
};
// Links in the text column: room around them for a 44px touch target
@@ -28,7 +28,7 @@ export default function ShootBlock({
packages,
reverse,
priority,
portfolioLive,
portfolioLink,
}: ShootBlockProps) {
const titleId = `shoot-${shoot.id}-title`;
@@ -74,7 +74,7 @@ export default function ShootBlock({
Stuur een berichtje
</RouterLink>
</Link>
{portfolioLive && (
{portfolioLink && (
<Link variant="underline" asChild {...linkStyle}>
<RouterLink
{...shootPortfolioLink(shoot)}
@@ -12,7 +12,7 @@ const renderList = () =>
<ShootList
shoots={shootTypes}
packages={packages}
portfolioLive={false}
portfolioShoots={[]}
/>,
);
@@ -1,12 +1,14 @@
import { Box } from '@chakra-ui/react';
import PageSection from '@/components/PageSection/PageSection';
import type { PricingPackage, ShootType } from '@/content/types';
import type { PricingPackage, ShootType, ShootTypeId } from '@/content/types';
import ShootBlock from '../ShootBlock/ShootBlock';
type ShootListProps = {
shoots: readonly ShootType[];
packages: readonly PricingPackage[];
portfolioLive: boolean;
// Shoot types that link to the portfolio: only while it is live, and
// only for types with portfolio photos (BR-SL-01)
portfolioShoots: readonly ShootTypeId[];
};
// The shoot types below the page head, each in its own full-width band:
@@ -16,7 +18,7 @@ type ShootListProps = {
export default function ShootList({
shoots,
packages,
portfolioLive,
portfolioShoots,
}: ShootListProps) {
return (
<Box data-testid="shoot-list">
@@ -32,7 +34,7 @@ export default function ShootList({
packages={packages}
reverse={index % 2 === 1}
priority={index === 0}
portfolioLive={portfolioLive}
portfolioLink={portfolioShoots.includes(shoot.id)}
/>
</PageSection>
))}