Extracts shared section blocks for use beyond the homepage

HomeSection becomes PageSection, since every page needs the same section
frame, and gains a flushTop spacing for a block right below a page head.
The framed photo next to text from the homepage About block becomes
MediaText, and the accent label that four components wrote out by hand
becomes Eyebrow, which can also render as a heading. The homepage renders
exactly as before: a layout comparison of every element against master
at three widths shows no differences.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-22 23:35:22 +02:00
co-authored by Claude Opus 5.5
parent 26106f280f
commit 01e849c6b0
18 changed files with 321 additions and 89 deletions
@@ -1,5 +1,6 @@
import type { ReactNode } from 'react';
import { Box, chakra, Link, Text, useRecipe } from '@chakra-ui/react';
import Eyebrow from '@/components/Eyebrow/Eyebrow';
import type { EmailAddress } from '@/content/types';
import { emailAddress } from '@/lib/emailAddress';
import { mailtoLink } from '@/lib/mailLink';
@@ -46,10 +47,7 @@ export default function ContactFormGate({
textAlign="center"
data-testid="contact-gate-notice"
>
{/* accent.deep instead of the design's accent: meets 4.5:1 */}
<Text textStyle="eyebrow" color="accent.deep" mb={4}>
Binnenkort
</Text>
<Eyebrow>Binnenkort</Eyebrow>
<Text color="ink.soft" mb={address ? 7 : 0}>
Het contactformulier komt binnenkort.
{address && (
@@ -0,0 +1,42 @@
import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { axeResults } from '@/test/axe';
import { renderWithProviders } from '@/test/renderWithProviders';
import Eyebrow from './Eyebrow';
describe('Eyebrow', () => {
it('is a paragraph by default', async () => {
const { container } = await renderWithProviders(
<Eyebrow>Over mij</Eyebrow>,
);
expect(screen.getByText('Over mij').tagName).toBe('P');
expect(screen.queryByRole('heading')).not.toBeInTheDocument();
expect(await axeResults(container)).toHaveNoViolations();
});
it('can be a heading that a section refers to by id', async () => {
const { container } = await renderWithProviders(
<section aria-labelledby="story-title">
<Eyebrow as="h3" id="story-title">
Hoe het begon
</Eyebrow>
</section>,
);
expect(
screen.getByRole('heading', { level: 3, name: 'Hoe het begon' }),
).toHaveAttribute('id', 'story-title');
expect(
screen.getByRole('region', { name: 'Hoe het begon' }),
).toBeInTheDocument();
expect(await axeResults(container)).toHaveNoViolations();
});
it('passes other props through', async () => {
await renderWithProviders(
<Eyebrow data-testid="label" textAlign="center">
Binnenkort
</Eyebrow>,
);
expect(screen.getByTestId('label')).toHaveTextContent('Binnenkort');
});
});
+21
View File
@@ -0,0 +1,21 @@
import { Text, type TextProps } from '@chakra-ui/react';
type EyebrowProps = Omit<TextProps, 'as'> & {
// A heading level makes the label a real heading that keeps the small
// label look, e.g. the story headings on the about page
as?: 'p' | 'span' | 'h2' | 'h3' | 'h4';
};
// Small capitals label above a heading or text (design .eyebrow).
// accent.deep instead of the design's accent: meets 4.5:1 on paper and white.
export default function Eyebrow({ as = 'p', ...rest }: EyebrowProps) {
return (
<Text
as={as}
textStyle="eyebrow"
color="accent.deep"
mb={4}
{...rest}
/>
);
}
@@ -0,0 +1,46 @@
import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import type { ContentImage } from '@/content/types';
import { axeResults } from '@/test/axe';
import { renderWithProviders } from '@/test/renderWithProviders';
import MediaText from './MediaText';
const image: ContentImage = {
src: '/andrea.jpg',
alt: 'Andrea met haar camera',
width: 1200,
height: 800,
};
describe('MediaText', () => {
it('shows the photo and the text column', async () => {
const { container } = await renderWithProviders(
<MediaText image={image} aspectRatio="4 / 3" data-testid="block">
<h2>Hoi! Ik ben Andrea</h2>
<p>Lifestyle fotograaf uit Huizen.</p>
</MediaText>,
);
expect(screen.getByRole('img')).toHaveAccessibleName(image.alt);
expect(
screen.getByRole('heading', { name: 'Hoi! Ik ben Andrea' }),
).toBeInTheDocument();
expect(
screen.getByText('Lifestyle fotograaf uit Huizen.'),
).toBeInTheDocument();
expect(await axeResults(container)).toHaveNoViolations();
});
it('puts the photo before the text, also when stacked', async () => {
await renderWithProviders(
<MediaText image={image} aspectRatio="4 / 3">
<h2>Hoi! Ik ben Andrea</h2>
</MediaText>,
);
const photo = screen.getByRole('img');
const heading = screen.getByRole('heading');
expect(
photo.compareDocumentPosition(heading) &
Node.DOCUMENT_POSITION_FOLLOWING,
).toBeTruthy();
});
});
@@ -0,0 +1,38 @@
import type { ReactNode } from 'react';
import { Grid } from '@chakra-ui/react';
import FramedImage from '@/components/FramedImage/FramedImage';
import Reveal from '@/components/Reveal/Reveal';
import type { ContentImage } from '@/content/types';
type MediaTextProps = {
image: ContentImage;
// CSS aspect ratio of the visible crop, e.g. '4 / 3'
aspectRatio: string;
'data-testid'?: string;
// The text column; each page fills in its own heading and text
children: ReactNode;
};
// 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
// columns from `lg`; both columns fade in on scroll.
export default function MediaText({
image,
aspectRatio,
'data-testid': testId,
children,
}: MediaTextProps) {
return (
<Grid
templateColumns={{ base: '1fr', lg: '1fr 1fr' }}
gap="clamp(2rem, 6vw, 5.5rem)"
alignItems="center"
data-testid={testId}
>
<Reveal>
<FramedImage image={image} aspectRatio={aspectRatio} />
</Reveal>
<Reveal>{children}</Reveal>
</Grid>
);
}
+2 -6
View File
@@ -1,5 +1,6 @@
import type { ReactNode } from 'react';
import { Container, Heading, Text } from '@chakra-ui/react';
import Eyebrow from '@/components/Eyebrow/Eyebrow';
type PageIntroProps = {
title: string;
@@ -21,12 +22,7 @@ export default function PageIntro({
pb={{ base: 8, md: 12, lg: 16 }}
textAlign="center"
>
{eyebrow && (
// accent.deep i.p.v. accent uit het design: haalt 4.5:1 (NFR-01)
<Text textStyle="eyebrow" color="accent.deep" mb={4}>
{eyebrow}
</Text>
)}
{eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
<Heading as="h1" textStyle="pageTitle" mb={4}>
{title}
</Heading>
@@ -2,14 +2,14 @@ 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';
import PageSection from './PageSection';
describe('HomeSection', () => {
describe('PageSection', () => {
it('is a region named by its heading', async () => {
const { container } = await renderWithProviders(
<HomeSection labelledBy="about-title" data-testid="about">
<PageSection labelledBy="about-title" data-testid="about">
<h2 id="about-title">Over mij</h2>
</HomeSection>,
</PageSection>,
);
expect(screen.getByRole('region', { name: 'Over mij' })).toBe(
screen.getByTestId('about'),
@@ -19,7 +19,7 @@ describe('HomeSection', () => {
it('passes the anchor id through for every tone, width and spacing', async () => {
await renderWithProviders(
<HomeSection
<PageSection
labelledBy="contact-title"
id="contact"
tone="alt"
@@ -27,7 +27,7 @@ describe('HomeSection', () => {
spacing="tight"
>
<h2 id="contact-title">Contact</h2>
</HomeSection>,
</PageSection>,
);
expect(screen.getByRole('region', { name: 'Contact' })).toHaveAttribute(
'id',
@@ -35,13 +35,35 @@ describe('HomeSection', () => {
);
});
it('has no space above when it sits flush below a page head', async () => {
await renderWithProviders(
<>
<PageSection labelledBy="flush-title" data-testid="flush">
<h2 id="flush-title">Hoi!</h2>
</PageSection>
<PageSection
labelledBy="next-title"
spacing="flushTop"
data-testid="flush-top"
>
<h2 id="next-title">Verder</h2>
</PageSection>
</>,
);
const regular = getComputedStyle(screen.getByTestId('flush'));
const flush = getComputedStyle(screen.getByTestId('flush-top'));
expect(flush.paddingTop).toBe('0px');
expect(flush.paddingBottom).toBe(regular.paddingBottom);
expect(regular.paddingTop).not.toBe('0px');
});
it('leaves out the content column at full width', async () => {
await renderWithProviders(
<HomeSection labelledBy="insta-title" width="full">
<PageSection labelledBy="insta-title" width="full">
<h2 id="insta-title" data-testid="child">
Instagram
</h2>
</HomeSection>,
</PageSection>,
);
// The heading is a direct child of the section, not of a Container
expect(screen.getByTestId('child').parentElement).toBe(
@@ -1,7 +1,7 @@
import type { ReactNode } from 'react';
import { Box, Container } from '@chakra-ui/react';
type HomeSectionProps = {
type PageSectionProps = {
// Id of the heading that names this section for assistive technology
labelledBy: string;
id?: string;
@@ -9,14 +9,16 @@ type HomeSectionProps = {
// full: no content column, for edge-to-edge content; the section then
// places its own Container around what should stay in the column
width?: 'default' | 'narrow' | 'full';
spacing?: 'default' | 'tight';
// flushTop: no space above, for the first block right below a page head
// (design .section--flush-top)
spacing?: 'default' | 'tight' | 'flushTop';
'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({
// Frame of a content section on any page (design .section): vertical
// rhythm, an optional alternate background and the content column.
export default function PageSection({
labelledBy,
id,
tone = 'paper',
@@ -24,7 +26,9 @@ export default function HomeSection({
spacing = 'default',
'data-testid': testId,
children,
}: HomeSectionProps) {
}: PageSectionProps) {
const padding = spacing === 'tight' ? 'sectionYTight' : 'sectionY';
return (
<Box
as="section"
@@ -35,7 +39,8 @@ export default function HomeSection({
// An anchor target (#contact) lands right below the fixed header,
// which has shrunk to its sticky height by the time it gets there
scrollMarginTop={id ? 'header.sticky' : undefined}
py={spacing === 'tight' ? 'sectionYTight' : 'sectionY'}
pt={spacing === 'flushTop' ? 0 : padding}
pb={padding}
>
{width === 'full' ? (
children
@@ -1,5 +1,6 @@
import type { ReactNode } from 'react';
import { Box, Heading, Text } from '@chakra-ui/react';
import Eyebrow from '@/components/Eyebrow/Eyebrow';
type SectionHeadingProps = {
// Referenced by the section's aria-labelledby
@@ -35,12 +36,7 @@ export default function SectionHeading({
mb={spacing === 'compact' ? 6 : '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>
)}
{eyebrow && <Eyebrow>{eyebrow}</Eyebrow>}
<Heading
as="h2"
id={id}
@@ -1,7 +1,6 @@
import { Grid, Link, Stack, Text } from '@chakra-ui/react';
import FramedImage from '@/components/FramedImage/FramedImage';
import HomeSection from '@/components/HomeSection/HomeSection';
import Reveal from '@/components/Reveal/Reveal';
import { Link, Stack, Text } from '@chakra-ui/react';
import MediaText from '@/components/MediaText/MediaText';
import PageSection from '@/components/PageSection/PageSection';
import RouterLink from '@/components/RouterLink';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
import type { HomeContent } from '@/content/types';
@@ -16,40 +15,31 @@ type AboutBlockProps = {
// link to the about page (design .about). Stacked on phones and tablets.
export default function AboutBlock({ content }: AboutBlockProps) {
return (
<HomeSection labelledBy={TITLE_ID} tone="alt" data-testid="about-block">
<Grid
templateColumns={{ base: '1fr', lg: '1fr 1fr' }}
gap="clamp(2rem, 6vw, 5.5rem)"
alignItems="center"
>
<Reveal>
<FramedImage image={content.image} aspectRatio="4 / 3" />
</Reveal>
<Reveal>
<SectionHeading
id={TITLE_ID}
eyebrow={content.eyebrow}
title={content.title}
align="start"
spacing="compact"
/>
<Stack gap={4} color="ink.soft">
{content.paragraphs.map((paragraph) => (
<Text key={paragraph}>{paragraph}</Text>
))}
<Text>
<Link variant="underline" asChild>
<RouterLink
to={content.link.to}
data-testid="about-block-link"
>
{content.link.label}
</RouterLink>
</Link>
</Text>
</Stack>
</Reveal>
</Grid>
</HomeSection>
<PageSection labelledBy={TITLE_ID} tone="alt" data-testid="about-block">
<MediaText image={content.image} aspectRatio="4 / 3">
<SectionHeading
id={TITLE_ID}
eyebrow={content.eyebrow}
title={content.title}
align="start"
spacing="compact"
/>
<Stack gap={4} color="ink.soft">
{content.paragraphs.map((paragraph) => (
<Text key={paragraph}>{paragraph}</Text>
))}
<Text>
<Link variant="underline" asChild>
<RouterLink
to={content.link.to}
data-testid="about-block-link"
>
{content.link.label}
</RouterLink>
</Link>
</Text>
</Stack>
</MediaText>
</PageSection>
);
}
@@ -3,7 +3,7 @@ import { Box, useMediaQuery } from '@chakra-ui/react';
import { useNavigate } from '@tanstack/react-router';
import { DEFERRED_LOAD_MARGIN } from '@/components/DeferredImage/DeferredImage';
import ContactFormGate from '@/components/ContactForm/ContactFormGate';
import HomeSection from '@/components/HomeSection/HomeSection';
import PageSection from '@/components/PageSection/PageSection';
import Reveal from '@/components/Reveal/Reveal';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
import type {
@@ -109,7 +109,7 @@ export default function ContactSection({
const placeholder = <Box minH={FORM_PLACEHOLDER_HEIGHT} />;
return (
<HomeSection
<PageSection
labelledBy={TITLE_ID}
id="contact"
width="narrow"
@@ -146,6 +146,6 @@ export default function ContactSection({
</Box>
</ContactFormGate>
</Reveal>
</HomeSection>
</PageSection>
);
}
@@ -1,6 +1,6 @@
import { Box, chakra, Container, Link, VisuallyHidden } from '@chakra-ui/react';
import DeferredImage from '@/components/DeferredImage/DeferredImage';
import HomeSection from '@/components/HomeSection/HomeSection';
import PageSection from '@/components/PageSection/PageSection';
import Reveal from '@/components/Reveal/Reveal';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
import type { HomeContent } from '@/content/types';
@@ -22,7 +22,7 @@ export default function InstagramGrid({
profileUrl,
}: InstagramGridProps) {
return (
<HomeSection
<PageSection
labelledBy={TITLE_ID}
spacing="tight"
width="full"
@@ -112,6 +112,6 @@ export default function InstagramGrid({
))}
</chakra.ul>
</Reveal>
</HomeSection>
</PageSection>
);
}
@@ -2,7 +2,7 @@ import { chakra, useBreakpointValue } from '@chakra-ui/react';
import DeferredImage, {
DEFERRED_LOAD_MARGIN,
} from '@/components/DeferredImage/DeferredImage';
import HomeSection from '@/components/HomeSection/HomeSection';
import PageSection from '@/components/PageSection/PageSection';
import Reveal from '@/components/Reveal/Reveal';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
import type { HomeContent } from '@/content/types';
@@ -33,7 +33,7 @@ export default function IntroGallery({ content }: IntroGalleryProps) {
const scrollable = useBreakpointValue({ base: true, sm: false }) ?? false;
return (
<HomeSection labelledBy={TITLE_ID} data-testid="intro-gallery">
<PageSection labelledBy={TITLE_ID} data-testid="intro-gallery">
<Reveal>
<SectionHeading
id={TITLE_ID}
@@ -99,6 +99,6 @@ export default function IntroGallery({ content }: IntroGalleryProps) {
))}
</chakra.ul>
</Reveal>
</HomeSection>
</PageSection>
);
}
+3 -3
View File
@@ -1,6 +1,6 @@
import { Box, Grid } from '@chakra-ui/react';
import DeferredImage from '@/components/DeferredImage/DeferredImage';
import HomeSection from '@/components/HomeSection/HomeSection';
import PageSection from '@/components/PageSection/PageSection';
import Reveal from '@/components/Reveal/Reveal';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
import type { HomeContent, PricingPackage } from '@/content/types';
@@ -32,7 +32,7 @@ export default function Pricing({ content, packages }: PricingProps) {
if (shown.length === 0) return null;
return (
<HomeSection labelledBy={TITLE_ID} data-testid="pricing">
<PageSection labelledBy={TITLE_ID} data-testid="pricing">
<Box position="relative" isolation="isolate">
{content.decorations.map((decoration, index) => (
<DeferredImage
@@ -68,6 +68,6 @@ export default function Pricing({ content, packages }: PricingProps) {
))}
</Grid>
</Box>
</HomeSection>
</PageSection>
);
}
@@ -1,4 +1,5 @@
import { Box, chakra, Grid, Text } from '@chakra-ui/react';
import Eyebrow from '@/components/Eyebrow/Eyebrow';
import FramedImage from '@/components/FramedImage/FramedImage';
import type { Testimonial } from '@/content/types';
@@ -44,10 +45,7 @@ export default function TestimonialSlide({
>
“
</Text>
{/* accent.deep instead of the design's accent: meets 4.5:1 (NFR-HP-01) */}
<Text textStyle="eyebrow" color="accent.deep" mb={4}>
{testimonial.shoot}
</Text>
<Eyebrow>{testimonial.shoot}</Eyebrow>
{/* Plain elements, not Chakra's Blockquote: its slot recipe
would pull shared code into the chunk the hero waits for */}
<chakra.figure display="flex" flexDirection="column" gap={7}>
@@ -1,7 +1,7 @@
import { lazy, Suspense } from 'react';
import { Box } from '@chakra-ui/react';
import { DEFERRED_LOAD_MARGIN } from '@/components/DeferredImage/DeferredImage';
import HomeSection from '@/components/HomeSection/HomeSection';
import PageSection from '@/components/PageSection/PageSection';
import Reveal from '@/components/Reveal/Reveal';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
import type { HomeContent, Testimonial } from '@/content/types';
@@ -36,7 +36,7 @@ export default function Testimonials({
if (shown.length === 0) return null;
return (
<HomeSection
<PageSection
labelledBy={TITLE_ID}
tone="alt"
data-testid="testimonials"
@@ -63,7 +63,7 @@ export default function Testimonials({
</Box>
)}
</Reveal>
</HomeSection>
</PageSection>
);
}