Adds the Over mij section to the homepage

Adds the introduction block with a framed photo of Andrea and a link to
the about page. Brings in FramedImage and an underline link variant for
the later blocks, and narrows the load margin of deferred photos so
nothing below the hero starts loading before the hero has painted.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 00:31:10 +02:00
co-authored by Claude Opus 5.5
parent 3e530df0af
commit 0b54a67dc4
20 changed files with 403 additions and 14 deletions
@@ -2,7 +2,7 @@ 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';
import DeferredImage, { DEFERRED_LOAD_MARGIN } from './DeferredImage';
const image = {
src: '/foto.jpg',
@@ -33,7 +33,7 @@ describe('DeferredImage', () => {
const [observer] = FakeIntersectionObserver.instances;
expect(img).not.toHaveAttribute('src');
expect(observer.options?.rootMargin).toBe('600px 0px');
expect(observer.options?.rootMargin).toBe(DEFERRED_LOAD_MARGIN);
act(() => observer.trigger(true));
expect(img).toHaveAttribute('src', '/foto.jpg');
@@ -3,8 +3,12 @@ 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';
// How far outside the viewport an image starts loading. Kept small on
// purpose: everything below the full-height hero must be out of range when
// the page opens, or its photos start before the hero has painted. In
// Lighthouse's throttled simulation that pushed the largest contentful
// paint from 3.8 s to 5.3 s whenever the request won the race.
export const DEFERRED_LOAD_MARGIN = '200px 0px';
type DeferredImageProps = Omit<ImageProps, 'src' | 'alt'> & {
image: ContentImage;
@@ -26,7 +30,7 @@ export default function DeferredImage({
}: DeferredImageProps) {
const pageLoaded = usePageLoaded();
const { ref, inView } = useInView<HTMLImageElement>({
rootMargin: LOAD_MARGIN,
rootMargin: DEFERRED_LOAD_MARGIN,
skip: near !== undefined,
});
const load = pageLoaded && (near ?? inView);
@@ -0,0 +1,27 @@
import { screen } from '@testing-library/react';
import { describe, expect, it } from 'vitest';
import { axeResults } from '@/test/axe';
import { renderWithProviders } from '@/test/renderWithProviders';
import FramedImage from './FramedImage';
const image = {
src: '/andrea.jpg',
alt: 'Andrea met haar camera',
width: 1200,
height: 800,
};
describe('FramedImage', () => {
it('renders only the photo for assistive technology, with its size', async () => {
const { container } = await renderWithProviders(
<FramedImage image={image} aspectRatio="4 / 3" />,
);
const img = screen.getByRole('img');
expect(img).toHaveAccessibleName('Andrea met haar camera');
expect(img).toHaveAttribute('src', '/andrea.jpg');
expect(img).toHaveAttribute('width', '1200');
expect(img).toHaveAttribute('height', '800');
expect(img).toHaveAttribute('loading', 'lazy');
expect(await axeResults(container)).toHaveNoViolations();
});
});
@@ -0,0 +1,45 @@
import { Box } from '@chakra-ui/react';
import DeferredImage from '@/components/DeferredImage/DeferredImage';
import type { ContentImage } from '@/content/types';
type FramedImageProps = {
image: ContentImage;
// CSS aspect ratio of the visible crop, e.g. '4 / 3'
aspectRatio: string;
};
// A photo with a soft sand-coloured block offset behind its lower left
// corner (design .about__media). The block is pure decoration (a CSS
// pseudo-element), so assistive technology never announces it. On phones it
// is left out, since it would stick out past the page edge.
export default function FramedImage({ image, aspectRatio }: FramedImageProps) {
return (
<Box
position="relative"
// Own stacking context, so the block can sit behind the photo
isolation="isolate"
_before={{
content: '""',
display: { base: 'none', sm: 'block' },
position: 'absolute',
left: '-1.5rem',
bottom: '-1.5rem',
width: '55%',
height: '55%',
bg: 'sand',
zIndex: -1,
}}
>
<DeferredImage
image={image}
display="block"
w="100%"
h="auto"
aspectRatio={aspectRatio}
objectFit="cover"
// Shown until the deferred photo arrives
bg="paper.deep"
/>
</Box>
);
}
@@ -31,4 +31,23 @@ describe('SectionHeading', () => {
).toBeInTheDocument();
expect(container.querySelectorAll('p')).toHaveLength(0);
});
it('supports a compact, start-aligned variant above running text', async () => {
await renderWithProviders(
<SectionHeading
id="about-title"
eyebrow="Over mij"
title="Lifestyle fotograaf"
align="start"
spacing="compact"
/>,
);
expect(
screen.getByRole('heading', {
level: 2,
name: 'Lifestyle fotograaf',
}),
).toHaveAttribute('id', 'about-title');
expect(screen.getByText('Over mij')).toBeInTheDocument();
});
});
@@ -7,6 +7,8 @@ type SectionHeadingProps = {
eyebrow?: string;
lead?: string;
align?: 'center' | 'start';
// compact: little space below, for a heading above running text
spacing?: 'default' | 'compact';
};
// Heading block of a homepage section (design .section__head): optional
@@ -17,6 +19,7 @@ export default function SectionHeading({
eyebrow,
lead,
align = 'center',
spacing = 'default',
}: SectionHeadingProps) {
const centered = align === 'center';
@@ -24,7 +27,7 @@ export default function SectionHeading({
<Box
maxW="620px"
mx={centered ? 'auto' : undefined}
mb="sectionHeadGap"
mb={spacing === 'compact' ? 6 : 'sectionHeadGap'}
textAlign={centered ? 'center' : 'start'}
>
{eyebrow && (
@@ -0,0 +1,31 @@
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 AboutBlock from './AboutBlock';
const about = homeContent.about;
describe('AboutBlock', () => {
it('shows the label, heading, text, photo and link', async () => {
const { container } = await renderWithProviders(
<AboutBlock content={about} />,
);
const section = screen.getByRole('region', { name: about.title });
expect(
within(section).getByRole('heading', { level: 2 }),
).toHaveTextContent(about.title);
expect(within(section).getByText(about.eyebrow)).toBeInTheDocument();
about.paragraphs.forEach((paragraph) =>
expect(within(section).getByText(paragraph)).toBeInTheDocument(),
);
expect(within(section).getByRole('img')).toHaveAccessibleName(
about.image.alt,
);
expect(
within(section).getByRole('link', { name: about.link.label }),
).toHaveAttribute('href', '/over-mij');
expect(await axeResults(container)).toHaveNoViolations();
});
});
@@ -0,0 +1,55 @@
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 RouterLink from '@/components/RouterLink';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
import type { HomeContent } from '@/content/types';
const TITLE_ID = 'about-title';
type AboutBlockProps = {
content: HomeContent['about'];
};
// "Over mij": a framed photo of Andrea next to a short introduction with a
// 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>
);
}
@@ -1,5 +1,7 @@
import { chakra, useBreakpointValue } from '@chakra-ui/react';
import DeferredImage from '@/components/DeferredImage/DeferredImage';
import DeferredImage, {
DEFERRED_LOAD_MARGIN,
} from '@/components/DeferredImage/DeferredImage';
import HomeSection from '@/components/HomeSection/HomeSection';
import Reveal from '@/components/Reveal/Reveal';
import SectionHeading from '@/components/SectionHeading/SectionHeading';
@@ -24,7 +26,7 @@ export default function IntroGallery({ content }: IntroGalleryProps) {
// Photos outside the row are clipped by the scroller and never intersect
// on their own, so the whole gallery decides when they load.
const { ref, inView } = useInView<HTMLUListElement>({
rootMargin: '600px 0px',
rootMargin: DEFERRED_LOAD_MARGIN,
});
// Only the swipeable row scrolls, so only then is it a focus stop for
// keyboard scrolling