Files
AndreaSlopFotografie/web/src/components/home/IntroGallery/IntroGallery.tsx
T
SluijsensandClaude Opus 5.5 01e849c6b0 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>
2026-10-22 23:35:22 +02:00

105 lines
4.5 KiB
TypeScript

import { chakra, useBreakpointValue } from '@chakra-ui/react';
import DeferredImage, {
DEFERRED_LOAD_MARGIN,
} from '@/components/DeferredImage/DeferredImage';
import PageSection from '@/components/PageSection/PageSection';
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';
// 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)';
type IntroGalleryProps = {
content: HomeContent['intro'];
};
// "Lifestyle fotografie": heading with intro and a gallery of four photos
// (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: DEFERRED_LOAD_MARGIN,
});
// 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 (
<PageSection labelledBy={TITLE_ID} data-testid="intro-gallery">
<Reveal>
<SectionHeading
id={TITLE_ID}
title={content.title}
lead={content.lead}
/>
</Reveal>
<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}`}
>
<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>
</PageSection>
);
}