Makes the shoot blocks smaller and livelier

At the owner's review: the shoot photos are smaller (MediaText's new
`small` size), each shoot gets a square detail photo overlapping the
main one, and the text, now at most 36rem wide, sits centred between
the photos and the edge. Every shoot has its own band, alternating
paper and paper.alt, instead of a hairline. Existing MediaText callers
are unchanged. The route test expects the portfolio links once the
portfolio page is indexed, so it stays green when that page goes live.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 16:23:52 +01:00
co-authored by Claude Opus 5.5
parent ce2cb92539
commit d2c1d2c1c4
14 changed files with 253 additions and 44 deletions
@@ -84,4 +84,87 @@ describe('MediaText', () => {
cssRulesFor(screen.getByRole('img').parentElement!).join(),
).toContain('var(--slp-colors-accent)');
});
// The grid is the parent of the photo column
const gridRules = () =>
cssRulesFor(photoColumnElement().parentElement!).join('\n');
const photoColumnElement = () =>
screen.getByRole('img').closest('[data-reveal]')!;
it('shares the width equally by default', async () => {
await renderWithProviders(
<MediaText image={image} aspectRatio="4 / 3">
<h2>Hoi! Ik ben Andrea</h2>
</MediaText>,
);
expect(gridRules()).toMatch(/grid-template-columns: 1fr 1fr/);
expect(cssRulesFor(photoColumnElement()).join()).not.toContain(
'max-width',
);
});
it('keeps a small photo at most 20rem wide and centres the text (at most 36rem) in the rest, also when reversed', async () => {
const { unmount } = await renderWithProviders(
<MediaText image={image} aspectRatio="4 / 5" mediaSize="small">
<h2>Newborn</h2>
</MediaText>,
);
expect(gridRules()).toMatch(
/grid-template-columns: minmax\(0, ?20rem\) minmax\(0, ?1fr\)/,
);
expect(cssRulesFor(photoColumnElement()).join()).toContain(
'max-width: 20rem',
);
const textRules = cssRulesFor(
screen.getByRole('heading').closest('[data-reveal]')!,
).join('\n');
expect(textRules).toContain('max-width: 36rem');
expect(textRules).toMatch(/min-width: 64rem.*margin-inline: auto/s);
unmount();
await renderWithProviders(
<MediaText
image={image}
aspectRatio="4 / 5"
mediaSize="small"
reverse
>
<h2>Zwangerschap</h2>
</MediaText>,
);
expect(gridRules()).toMatch(
/grid-template-columns: minmax\(0, ?1fr\) minmax\(0, ?20rem\)/,
);
});
it('adds a detail photo that overlaps the main one, in a wider column', async () => {
const detail: ContentImage = {
src: '/voetjes.jpg',
alt: 'Babyvoetjes',
width: 480,
height: 480,
};
const { container } = await renderWithProviders(
<MediaText
image={image}
aspectRatio="4 / 5"
mediaSize="small"
detailImage={detail}
>
<h2>Newborn</h2>
</MediaText>,
);
const [main, second] = screen.getAllByRole('img');
expect(main).toHaveAccessibleName(image.alt);
expect(second).toHaveAccessibleName('Babyvoetjes');
// Main photo first, so the reading order stays photo → detail → text
expect(
main.compareDocumentPosition(second) &
Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
expect(cssRulesFor(main.closest('[data-reveal]')!).join()).toContain(
'max-width: 28rem',
);
expect(await axeResults(container)).toHaveNoViolations();
});
});
+75 -11
View File
@@ -1,9 +1,17 @@
import type { ReactNode } from 'react';
import { Grid } from '@chakra-ui/react';
import { Box, Grid } from '@chakra-ui/react';
import DeferredImage from '@/components/DeferredImage/DeferredImage';
import FramedImage from '@/components/FramedImage/FramedImage';
import Reveal from '@/components/Reveal/Reveal';
import type { ContentImage, FrameColor } from '@/content/types';
// Widest a small photo column gets, stacked or next to the text: the photo
// alone, or the photo with a detail photo overlapping it
const SMALL_MEDIA = '20rem';
const SMALL_MEDIA_WITH_DETAIL = '28rem';
// Widest the text next to a small photo gets: about 70 characters a line
const SMALL_TEXT = '36rem';
type MediaTextProps = {
image: ContentImage;
// CSS aspect ratio of the visible crop, e.g. '4 / 3'
@@ -13,6 +21,12 @@ type MediaTextProps = {
// Photo in the right-hand column from `lg` (design .about--reverse).
// Only the visual order changes: the photo stays first in the DOM.
reverse?: boolean;
// half: photo and text share the width equally (design .about);
// small: the photo column stays narrow (20rem, 28rem with a detail
// photo); the text, at most 36rem, is centred in the rest
mediaSize?: 'half' | 'small';
// A smaller square photo overlapping the main one's lower right corner
detailImage?: ContentImage;
// Colour of the block behind the photo (FramedImage)
frameColor?: FrameColor;
'data-testid'?: string;
@@ -22,32 +36,82 @@ type MediaTextProps = {
// A framed photo next to a text column (design .about), used on the
// homepage, the about page and the shoot types page. Stacked on phones and
// tablets, two equal columns from `lg`; both columns fade in on scroll.
// tablets, two columns from `lg`; both columns fade in on scroll.
export default function MediaText({
image,
aspectRatio,
priority,
reverse = false,
mediaSize = 'half',
detailImage,
frameColor,
'data-testid': testId,
children,
}: MediaTextProps) {
const small = mediaSize === 'small';
const mediaWidth = detailImage ? SMALL_MEDIA_WITH_DETAIL : SMALL_MEDIA;
const media = `minmax(0, ${mediaWidth})`;
const columns = small
? reverse
? `minmax(0, 1fr) ${media}`
: `${media} minmax(0, 1fr)`
: '1fr 1fr';
return (
<Grid
templateColumns={{ base: '1fr', lg: '1fr 1fr' }}
templateColumns={{ base: '1fr', lg: columns }}
gap="clamp(2rem, 6vw, 5.5rem)"
alignItems="center"
data-testid={testId}
>
<Reveal order={reverse ? { lg: 2 } : undefined}>
<FramedImage
image={image}
aspectRatio={aspectRatio}
priority={priority}
frameColor={frameColor}
/>
<Reveal
order={reverse ? { lg: 2 } : undefined}
maxW={small ? mediaWidth : undefined}
w={small ? 'full' : undefined}
>
{detailImage ? (
// The detail photo hangs below the main one: the padding
// (a share of the width) makes room for it
<Box position="relative" pb="15%">
<Box w="72%">
<FramedImage
image={image}
aspectRatio={aspectRatio}
priority={priority}
frameColor={frameColor}
/>
</Box>
<DeferredImage
image={detailImage}
position="absolute"
right={0}
bottom={0}
w="42%"
h="auto"
aspectRatio="1 / 1"
objectFit="cover"
borderWidth="6px"
borderColor="paper"
bg="paper.deep"
/>
</Box>
) : (
<FramedImage
image={image}
aspectRatio={aspectRatio}
priority={priority}
frameColor={frameColor}
/>
)}
</Reveal>
{/* Next to a small photo the text keeps a readable line length
and sits centred between the photo and the edge */}
<Reveal
maxW={small ? SMALL_TEXT : undefined}
mx={small ? { lg: 'auto' } : undefined}
>
{children}
</Reveal>
<Reveal>{children}</Reveal>
</Grid>
);
}