Extends the shared blocks for the shoot types page

FramedImage and MediaText take a colour for the block behind the photo
(sand by default) and MediaText can put the photo in the right-hand
column from lg, without changing the reading order. RichParagraph moves
to the shared components, a new CallToAction closes a page with a
heading, lead and action, and the homepage pricing section gets the
anchor #prijzen. A test helper reads the generated CSS rules, since
jsdom applies neither media queries nor pseudo-elements.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-25 08:25:27 +01:00
co-authored by Claude Opus 5.5
parent befe97af1e
commit 6cf909564b
12 changed files with 251 additions and 12 deletions
@@ -0,0 +1,69 @@
import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import LinkButton from '@/components/LinkButton';
import RichParagraph from '@/components/RichParagraph/RichParagraph';
import { axeResults } from '@/test/axe';
import { renderWithProviders } from '@/test/renderWithProviders';
import CallToAction from './CallToAction';
describe('CallToAction', () => {
it('is a section named by its heading, with the lead and the action', async () => {
const { container } = await renderWithProviders(
<CallToAction
title="Benieuwd naar de prijzen?"
titleId="cta-title"
lead={
<RichParagraph
paragraph={[
'Bekijk ',
{ text: 'de pakketten', to: '/', hash: 'prijzen' },
' op de homepage.',
]}
/>
}
data-testid="cta"
>
<LinkButton variant="accent" to="/" hash="contact">
Boek je shoot
</LinkButton>
</CallToAction>,
);
const section = screen.getByRole('region', {
name: 'Benieuwd naar de prijzen?',
});
expect(section).toBe(screen.getByTestId('cta'));
expect(screen.getByRole('heading', { level: 2 })).toHaveAccessibleName(
'Benieuwd naar de prijzen?',
);
expect(
screen.getByRole('link', { name: 'de pakketten' }),
).toHaveAttribute('href', '/#prijzen');
expect(
screen.getByRole('link', { name: 'Boek je shoot' }),
).toHaveAttribute('href', '/#contact');
expect(await axeResults(container)).toHaveNoViolations();
});
it('wraps a plain-text lead in a paragraph', async () => {
await renderWithProviders(
<CallToAction
title="Vragen?"
titleId="q"
lead="Stuur me een bericht."
>
<LinkButton to="/">Contact</LinkButton>
</CallToAction>,
);
expect(screen.getByText('Stuur me een bericht.').tagName).toBe('P');
});
it('leaves out the lead when there is none', async () => {
await renderWithProviders(
<CallToAction title="Vragen?" titleId="q">
<LinkButton to="/">Contact</LinkButton>
</CallToAction>,
);
expect(screen.queryByRole('paragraph')).toBeNull();
});
});
@@ -0,0 +1,50 @@
import type { ReactNode } from 'react';
import { Box, Heading, Text } from '@chakra-ui/react';
import PageSection from '@/components/PageSection/PageSection';
import Reveal from '@/components/Reveal/Reveal';
type CallToActionProps = {
title: string;
// Id of the h2, which names the section
titleId: string;
// Plain text, or a paragraph with links in it (e.g. RichParagraph)
lead?: ReactNode;
'data-testid'?: string;
// The action below the text, e.g. a LinkButton
children: ReactNode;
};
// Closing block of a page (design .section--alt.section--tight with a narrow,
// centred column): a heading, a short lead and one action. The page chooses
// the action and any link in the lead.
export default function CallToAction({
title,
titleId,
lead,
'data-testid': testId,
children,
}: CallToActionProps) {
return (
<PageSection
labelledBy={titleId}
tone="alt"
width="narrow"
spacing="tight"
data-testid={testId}
>
<Reveal textAlign="center">
<Heading as="h2" id={titleId} textStyle="sectionTitle">
{title}
</Heading>
{lead && (
// design .lead.mt-sm
<Box textStyle="lead" color="ink.soft" mt={4}>
{typeof lead === 'string' ? <Text>{lead}</Text> : lead}
</Box>
)}
{/* design .mt-lg */}
<Box mt="clamp(2rem, 4vw, 2.5rem)">{children}</Box>
</Reveal>
</PageSection>
);
}
@@ -1,6 +1,7 @@
import { screen } from '@testing-library/react'; import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest'; import { describe, expect, it } from 'vitest';
import { axeResults } from '@/test/axe'; import { axeResults } from '@/test/axe';
import { cssRulesFor } from '@/test/cssRules';
import { renderWithProviders } from '@/test/renderWithProviders'; import { renderWithProviders } from '@/test/renderWithProviders';
import FramedImage from './FramedImage'; import FramedImage from './FramedImage';
@@ -35,4 +36,32 @@ describe('FramedImage', () => {
expect(img).toHaveAttribute('fetchpriority', 'high'); expect(img).toHaveAttribute('fetchpriority', 'high');
expect(img).toHaveAttribute('width', '1200'); expect(img).toHaveAttribute('width', '1200');
}); });
// The block is a ::before on the photo's wrapper
const frameRule = (img: Element) =>
cssRulesFor(img.parentElement!).find((rule) =>
rule.includes('::before {'),
);
it('puts a sand block behind the photo by default', async () => {
await renderWithProviders(
<FramedImage image={image} aspectRatio="4 / 3" />,
);
expect(frameRule(screen.getByRole('img'))).toContain(
'background: var(--slp-colors-sand)',
);
});
it('colours the block with the given token', async () => {
await renderWithProviders(
<FramedImage
image={image}
aspectRatio="4 / 5"
frameColor="frame.rust"
/>,
);
expect(frameRule(screen.getByRole('img'))).toContain(
'background: var(--slp-colors-frame-rust)',
);
});
}); });
@@ -1,6 +1,6 @@
import { Box, Image, type ImageProps } from '@chakra-ui/react'; import { Box, Image, type ImageProps } from '@chakra-ui/react';
import DeferredImage from '@/components/DeferredImage/DeferredImage'; import DeferredImage from '@/components/DeferredImage/DeferredImage';
import type { ContentImage } from '@/content/types'; import type { ContentImage, FrameColor } from '@/content/types';
type FramedImageProps = { type FramedImageProps = {
image: ContentImage; image: ContentImage;
@@ -9,16 +9,19 @@ type FramedImageProps = {
// For a photo at the top of a page, likely the largest paint: load it // For a photo at the top of a page, likely the largest paint: load it
// straight away with high priority instead of after the page has loaded // straight away with high priority instead of after the page has loaded
priority?: boolean; priority?: boolean;
// Colour token of the block behind the photo
frameColor?: FrameColor;
}; };
// A photo with a soft sand-coloured block offset behind its lower left // A photo with a soft coloured block (sand by default) offset behind its
// corner (design .about__media). The block is pure decoration (a CSS // lower left corner (design .about__media). The block is pure decoration (a
// pseudo-element), so assistive technology never announces it. On phones it // CSS pseudo-element), so assistive technology never announces it. On phones
// is left out, since it would stick out past the page edge. // it is left out, since it would stick out past the page edge.
export default function FramedImage({ export default function FramedImage({
image, image,
aspectRatio, aspectRatio,
priority = false, priority = false,
frameColor = 'sand',
}: FramedImageProps) { }: FramedImageProps) {
const style: ImageProps = { const style: ImageProps = {
display: 'block', display: 'block',
@@ -43,7 +46,7 @@ export default function FramedImage({
bottom: '-1.5rem', bottom: '-1.5rem',
width: '55%', width: '55%',
height: '55%', height: '55%',
bg: 'sand', bg: frameColor,
zIndex: -1, zIndex: -1,
}} }}
> >
@@ -2,6 +2,7 @@ import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest'; import { describe, expect, it } from 'vitest';
import type { ContentImage } from '@/content/types'; import type { ContentImage } from '@/content/types';
import { axeResults } from '@/test/axe'; import { axeResults } from '@/test/axe';
import { cssRulesFor } from '@/test/cssRules';
import { renderWithProviders } from '@/test/renderWithProviders'; import { renderWithProviders } from '@/test/renderWithProviders';
import MediaText from './MediaText'; import MediaText from './MediaText';
@@ -43,4 +44,44 @@ describe('MediaText', () => {
Node.DOCUMENT_POSITION_FOLLOWING, Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy(); ).toBeTruthy();
}); });
const photoColumnRules = () =>
cssRulesFor(screen.getByRole('img').closest('[data-reveal]')!);
it('keeps the photo in the first column by default', async () => {
await renderWithProviders(
<MediaText image={image} aspectRatio="4 / 3">
<h2>Hoi! Ik ben Andrea</h2>
</MediaText>,
);
expect(photoColumnRules().join()).not.toContain('order');
});
it('moves the photo to the second column from lg when reversed, without changing the reading order', async () => {
await renderWithProviders(
<MediaText image={image} aspectRatio="4 / 5" reverse>
<h2>Newborn</h2>
</MediaText>,
);
expect(photoColumnRules()).toContainEqual(
expect.stringMatching(/min-width: 64rem.*order: 2;/),
);
const photo = screen.getByRole('img');
const heading = screen.getByRole('heading');
expect(
photo.compareDocumentPosition(heading) &
Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
});
it('passes the frame colour on to the photo', async () => {
await renderWithProviders(
<MediaText image={image} aspectRatio="4 / 5" frameColor="accent">
<h2>Gezin</h2>
</MediaText>,
);
expect(
cssRulesFor(screen.getByRole('img').parentElement!).join(),
).toContain('var(--slp-colors-accent)');
});
}); });
+12 -4
View File
@@ -2,7 +2,7 @@ import type { ReactNode } from 'react';
import { Grid } from '@chakra-ui/react'; import { Grid } from '@chakra-ui/react';
import FramedImage from '@/components/FramedImage/FramedImage'; import FramedImage from '@/components/FramedImage/FramedImage';
import Reveal from '@/components/Reveal/Reveal'; import Reveal from '@/components/Reveal/Reveal';
import type { ContentImage } from '@/content/types'; import type { ContentImage, FrameColor } from '@/content/types';
type MediaTextProps = { type MediaTextProps = {
image: ContentImage; image: ContentImage;
@@ -10,18 +10,25 @@ type MediaTextProps = {
aspectRatio: string; aspectRatio: string;
// The photo is at the top of the page and should not wait (FramedImage) // The photo is at the top of the page and should not wait (FramedImage)
priority?: boolean; priority?: boolean;
// 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;
// Colour of the block behind the photo (FramedImage)
frameColor?: FrameColor;
'data-testid'?: string; 'data-testid'?: string;
// The text column; each page fills in its own heading and text // The text column; each page fills in its own heading and text
children: ReactNode; children: ReactNode;
}; };
// A framed photo next to a text column (design .about), used on the // A framed photo next to a text column (design .about), used on the
// homepage and the about page. Stacked on phones and tablets, two equal // homepage, the about page and the shoot types page. Stacked on phones and
// columns from `lg`; both columns fade in on scroll. // tablets, two equal columns from `lg`; both columns fade in on scroll.
export default function MediaText({ export default function MediaText({
image, image,
aspectRatio, aspectRatio,
priority, priority,
reverse = false,
frameColor,
'data-testid': testId, 'data-testid': testId,
children, children,
}: MediaTextProps) { }: MediaTextProps) {
@@ -32,11 +39,12 @@ export default function MediaText({
alignItems="center" alignItems="center"
data-testid={testId} data-testid={testId}
> >
<Reveal> <Reveal order={reverse ? { lg: 2 } : undefined}>
<FramedImage <FramedImage
image={image} image={image}
aspectRatio={aspectRatio} aspectRatio={aspectRatio}
priority={priority} priority={priority}
frameColor={frameColor}
/> />
</Reveal> </Reveal>
<Reveal>{children}</Reveal> <Reveal>{children}</Reveal>
@@ -1,5 +1,5 @@
import { Stack } from '@chakra-ui/react'; import { Stack } from '@chakra-ui/react';
import RichParagraph from '@/components/about/RichParagraph/RichParagraph'; import RichParagraph from '@/components/RichParagraph/RichParagraph';
import MediaText from '@/components/MediaText/MediaText'; import MediaText from '@/components/MediaText/MediaText';
import PageSection from '@/components/PageSection/PageSection'; import PageSection from '@/components/PageSection/PageSection';
import SectionHeading from '@/components/SectionHeading/SectionHeading'; import SectionHeading from '@/components/SectionHeading/SectionHeading';
@@ -32,6 +32,16 @@ describe('Pricing', () => {
expect(await axeResults(container)).toHaveNoViolations(); expect(await axeResults(container)).toHaveNoViolations();
}); });
it('can be linked to as /#prijzen', async () => {
await renderWithProviders(
<Pricing content={content} packages={packages} />,
);
expect(screen.getByRole('region', { name: 'Prijzen' })).toHaveAttribute(
'id',
'prijzen',
);
});
it('keeps the decorations away from assistive technology', async () => { it('keeps the decorations away from assistive technology', async () => {
const { container } = await renderWithProviders( const { container } = await renderWithProviders(
<Pricing content={content} packages={packages} />, <Pricing content={content} packages={packages} />,
+6 -1
View File
@@ -32,7 +32,12 @@ export default function Pricing({ content, packages }: PricingProps) {
if (shown.length === 0) return null; if (shown.length === 0) return null;
return ( return (
<PageSection labelledBy={TITLE_ID} data-testid="pricing"> <PageSection
labelledBy={TITLE_ID}
// Anchor for links such as "de pakketten" (/#prijzen)
id="prijzen"
data-testid="pricing"
>
<Box position="relative" isolation="isolate"> <Box position="relative" isolation="isolate">
{content.decorations.map((decoration, index) => ( {content.decorations.map((decoration, index) => (
<DeferredImage <DeferredImage
+24
View File
@@ -0,0 +1,24 @@
// The CSS rules that target one of the element's classes, as text, including
// rules inside media queries (with the query in front). jsdom does not apply
// responsive styles or pseudo-elements, so tests check the generated rules
// instead of computed styles.
export function cssRulesFor(element: Element): string[] {
const classes = [...element.classList].map((name) => `.${name}`);
const matches = (rule: CSSStyleRule) =>
classes.some((name) => rule.selectorText.includes(name));
const found: string[] = [];
const walk = (rules: CSSRuleList, prefix: string) => {
for (const rule of rules) {
if (rule instanceof CSSStyleRule && matches(rule)) {
found.push(prefix + rule.cssText);
} else if (rule instanceof CSSMediaRule) {
walk(rule.cssRules, `@media ${rule.conditionText} `);
}
}
};
for (const sheet of document.styleSheets) {
walk(sheet.cssRules, '');
}
return found;
}