Shows the Lifestyle fotografie photos as a swipeable row on phones

Four stacked photos were too much on a phone screen. Below the small
breakpoint the gallery is now a scroll-snap row with one photo at a
time and the next one peeking in; tablets and desktops keep the grid.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-20 00:14:47 +02:00
co-authored by Claude Opus 5.5
parent b2717df049
commit 3e530df0af
9 changed files with 149 additions and 55 deletions
@@ -32,16 +32,20 @@ describe('IntroGallery', () => {
expect(await axeResults(container)).toHaveNoViolations();
});
it('shows every photo as a figure, in order', async () => {
it('shows the photos as a list in order, swipeable and focusable on phones', async () => {
await renderWithProviders(<IntroGallery content={homeContent.intro} />);
homeContent.intro.photos.forEach((photo, index) => {
const figure = screen.getByTestId(
`intro-gallery-photo-${index + 1}`,
// jsdom has no viewport, so Chakra resolves the base (phone) breakpoint
const list = screen.getByRole('list', { name: "Foto's" });
expect(list).toHaveAttribute('tabindex', '0');
const items = within(list).getAllByRole('listitem');
expect(items).toHaveLength(homeContent.intro.photos.length);
items.forEach((item, index) => {
expect(item).toBe(
screen.getByTestId(`intro-gallery-photo-${index + 1}`),
);
expect(figure.tagName).toBe('FIGURE');
expect(within(figure).getByRole('img')).toHaveAttribute(
expect(within(item).getByRole('img')).toHaveAttribute(
'alt',
photo.alt,
homeContent.intro.photos[index].alt,
);
});
});
@@ -1,9 +1,10 @@
import { Box, Grid } from '@chakra-ui/react';
import { chakra, useBreakpointValue } 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';
import useInView from '@/hooks/useInView';
const TITLE_ID = 'intro-title';
@@ -11,16 +12,24 @@ const TITLE_ID = 'intro-title';
// .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.
// (design .intro-gallery). On phones the photos form a swipeable row, one
// at a time with the next one peeking in; from `sm` a grid of 2, from `lg`
// of 4 columns.
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',
});
// Only the swipeable row scrolls, so only then is it a focus stop for
// keyboard scrolling
const scrollable = useBreakpointValue({ base: true, sm: false }) ?? false;
return (
<HomeSection labelledBy={TITLE_ID} data-testid="intro-gallery">
<Reveal>
@@ -30,46 +39,64 @@ export default function IntroGallery({ content }: IntroGalleryProps) {
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)' },
}}
<Reveal>
<chakra.ul
ref={ref}
listStyleType="none"
aria-label="Foto's"
tabIndex={scrollable ? 0 : undefined}
data-testid="intro-gallery-photos"
display={{ base: 'flex', sm: 'grid' }}
gridTemplateColumns={{
sm: 'repeat(2, 1fr)',
lg: 'repeat(4, 1fr)',
}}
alignItems="start"
gap="gridGap"
// Phones: a full-bleed row that snaps to each photo
overflowX={{ base: 'auto', sm: 'visible' }}
scrollSnapType={{ base: 'x mandatory', sm: 'none' }}
scrollPaddingInline="gutter"
mx={{ base: 'calc(-1 * {spacing.gutter})', sm: 0 }}
px={{ base: 'gutter', sm: 0 }}
scrollbarWidth="none"
css={{ '&::-webkit-scrollbar': { display: 'none' } }}
>
{content.photos.map((photo, index) => (
<chakra.li
key={photo.src}
flex={{ base: '0 0 85%', sm: 'initial' }}
scrollSnapAlign="center"
mt={index % 2 === 1 ? { base: 0, sm: OFFSET } : 0}
data-testid={`intro-gallery-photo-${index + 1}`}
>
<DeferredImage
image={photo}
w="100%"
h="auto"
aspectRatio="3 / 4"
objectFit="cover"
transitionProperty="transform"
transitionDuration="fade"
transitionTimingFunction="smooth"
_motionReduce={{ transition: 'none' }}
/>
</Box>
</Reveal>
))}
</Grid>
<chakra.figure
overflow="hidden"
// Shown until the deferred photo arrives
bg="paper.deep"
css={{
'&:hover img': {
transform: 'scale(1.05)',
},
}}
>
<DeferredImage
image={photo}
near={inView}
w="100%"
h="auto"
aspectRatio="3 / 4"
objectFit="cover"
transitionProperty="transform"
transitionDuration="fade"
transitionTimingFunction="smooth"
_motionReduce={{ transition: 'none' }}
/>
</chakra.figure>
</chakra.li>
))}
</chakra.ul>
</Reveal>
</HomeSection>
);
}