Adds the Lifestyle fotografie section to the homepage
Adds the first block below the hero: heading, intro and a staggered gallery of four live photos. Brings in the shared section building blocks (HomeSection, SectionHeading, Reveal) and DeferredImage, which holds back below-the-fold photos until the page has loaded so they do not compete with the hero for bandwidth. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
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 IntroGallery from './IntroGallery';
|
||||
|
||||
describe('IntroGallery', () => {
|
||||
it('shows the heading, the lead and the four photos', async () => {
|
||||
const { container } = await renderWithProviders(
|
||||
<IntroGallery content={homeContent.intro} />,
|
||||
);
|
||||
const section = screen.getByRole('region', {
|
||||
name: 'Lifestyle fotografie',
|
||||
});
|
||||
expect(
|
||||
within(section).getByRole('heading', { level: 2 }),
|
||||
).toHaveTextContent('Lifestyle fotografie');
|
||||
expect(
|
||||
within(section).getByText(homeContent.intro.lead),
|
||||
).toBeInTheDocument();
|
||||
|
||||
const images = within(section).getAllByRole('img');
|
||||
expect(images).toHaveLength(4);
|
||||
images.forEach((image, index) => {
|
||||
const photo = homeContent.intro.photos[index];
|
||||
expect(image).toHaveAttribute('alt', photo.alt);
|
||||
expect(image).toHaveAttribute('loading', 'lazy');
|
||||
expect(image).toHaveAttribute('width', String(photo.width));
|
||||
expect(image).toHaveAttribute('height', String(photo.height));
|
||||
});
|
||||
expect(await axeResults(container)).toHaveNoViolations();
|
||||
});
|
||||
|
||||
it('shows every photo as a figure, in order', async () => {
|
||||
await renderWithProviders(<IntroGallery content={homeContent.intro} />);
|
||||
homeContent.intro.photos.forEach((photo, index) => {
|
||||
const figure = screen.getByTestId(
|
||||
`intro-gallery-photo-${index + 1}`,
|
||||
);
|
||||
expect(figure.tagName).toBe('FIGURE');
|
||||
expect(within(figure).getByRole('img')).toHaveAttribute(
|
||||
'alt',
|
||||
photo.alt,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
it('still renders the heading when there are no photos', async () => {
|
||||
await renderWithProviders(
|
||||
<IntroGallery content={{ ...homeContent.intro, photos: [] }} />,
|
||||
);
|
||||
expect(
|
||||
screen.getByRole('heading', { name: 'Lifestyle fotografie' }),
|
||||
).toBeInTheDocument();
|
||||
expect(screen.queryAllByRole('img')).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,75 @@
|
||||
import { Box, Grid } from '@chakra-ui/react';
|
||||
import DeferredImage from '@/components/DeferredImage/DeferredImage';
|
||||
import HomeSection from '@/components/HomeSection/HomeSection';
|
||||
import Reveal from '@/components/Reveal/Reveal';
|
||||
import SectionHeading from '@/components/SectionHeading/SectionHeading';
|
||||
import type { HomeContent } from '@/content/types';
|
||||
|
||||
const TITLE_ID = 'intro-title';
|
||||
|
||||
// Every other photo sits lower, so the row is not a rigid block (design
|
||||
// .intro-gallery figure:nth-child(2|4))
|
||||
const OFFSET = 'clamp(1.5rem, 4vw, 3.5rem)';
|
||||
|
||||
// Delay between photos fading in, as in the design's .reveal:nth-child
|
||||
const STAGGER = 0.08;
|
||||
|
||||
type IntroGalleryProps = {
|
||||
content: HomeContent['intro'];
|
||||
};
|
||||
|
||||
// "Lifestyle fotografie": heading with intro and a gallery of four photos
|
||||
// (design .intro-gallery). 4 columns on desktop, 2 on tablet, 1 on phones.
|
||||
export default function IntroGallery({ content }: IntroGalleryProps) {
|
||||
return (
|
||||
<HomeSection labelledBy={TITLE_ID} data-testid="intro-gallery">
|
||||
<Reveal>
|
||||
<SectionHeading
|
||||
id={TITLE_ID}
|
||||
title={content.title}
|
||||
lead={content.lead}
|
||||
/>
|
||||
</Reveal>
|
||||
<Grid
|
||||
templateColumns={{
|
||||
base: '1fr',
|
||||
sm: 'repeat(2, 1fr)',
|
||||
lg: 'repeat(4, 1fr)',
|
||||
}}
|
||||
gap="gridGap"
|
||||
alignItems="start"
|
||||
>
|
||||
{content.photos.map((photo, index) => (
|
||||
<Reveal
|
||||
key={photo.src}
|
||||
as="figure"
|
||||
delay={index * STAGGER}
|
||||
mt={index % 2 === 1 ? { base: 0, sm: OFFSET } : 0}
|
||||
data-testid={`intro-gallery-photo-${index + 1}`}
|
||||
>
|
||||
<Box
|
||||
overflow="hidden"
|
||||
// Shown until the deferred photo arrives
|
||||
bg="paper.deep"
|
||||
css={{
|
||||
'&:hover img': { transform: 'scale(1.05)' },
|
||||
}}
|
||||
>
|
||||
<DeferredImage
|
||||
image={photo}
|
||||
w="100%"
|
||||
h="auto"
|
||||
aspectRatio="3 / 4"
|
||||
objectFit="cover"
|
||||
transitionProperty="transform"
|
||||
transitionDuration="fade"
|
||||
transitionTimingFunction="smooth"
|
||||
_motionReduce={{ transition: 'none' }}
|
||||
/>
|
||||
</Box>
|
||||
</Reveal>
|
||||
))}
|
||||
</Grid>
|
||||
</HomeSection>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user