The mobile menu works through CSS, and controls that need JavaScript are hidden without it. The contact photo gets its own preload, and the tests cover the new Reveal behaviour, the first row and the noscript markup. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
209 lines
7.5 KiB
TypeScript
209 lines
7.5 KiB
TypeScript
import { useState } from 'react';
|
|
import {
|
|
Box,
|
|
chakra,
|
|
Container,
|
|
Heading,
|
|
Image,
|
|
VisuallyHidden,
|
|
} from '@chakra-ui/react';
|
|
import LinkButton from '../LinkButton';
|
|
import HeroArrows from './HeroArrows';
|
|
import HeroPauseButton from './HeroPauseButton';
|
|
import HeroSocials from './HeroSocials';
|
|
import useHeroSlider, { type HeroAnnouncement } from './useHeroSlider';
|
|
import type { HeroContent, SocialLink } from '@/content/types';
|
|
import { slidesToLoad } from '@/lib/slidesToLoad';
|
|
|
|
const SLIDE_DURATION = '6s';
|
|
|
|
function announcementText(announcement: HeroAnnouncement, slide: string) {
|
|
switch (announcement) {
|
|
case 'slide':
|
|
return slide;
|
|
case 'paused':
|
|
return 'Diavoorstelling gepauzeerd';
|
|
case 'playing':
|
|
return 'Diavoorstelling speelt weer af';
|
|
default:
|
|
return '';
|
|
}
|
|
}
|
|
|
|
type HeroProps = {
|
|
content: HeroContent;
|
|
socials: SocialLink[];
|
|
};
|
|
|
|
export default function Hero({ content, socials }: HeroProps) {
|
|
const { title, tagline, cta, slides } = content;
|
|
const {
|
|
active,
|
|
announcement,
|
|
reducedMotion,
|
|
autoplay,
|
|
paused,
|
|
stopped,
|
|
toggleStopped,
|
|
next,
|
|
prev,
|
|
advance,
|
|
handlers,
|
|
} = useHeroSlider(slides.length);
|
|
// De slides liggen op elkaar in beeld, dus loading="lazy" stelt niets uit.
|
|
// Eerst alleen de actieve foto; zodra die binnen en getekend is (twee
|
|
// frames later, dus na de eerste paint) ook de volgende en de vorige.
|
|
// Verder weg laden we pas als de slider in de buurt komt (BR-HERO-01).
|
|
const [firstPainted, setFirstPainted] = useState(false);
|
|
const onFirstLoaded = () =>
|
|
requestAnimationFrame(() =>
|
|
requestAnimationFrame(() => setFirstPainted(true)),
|
|
);
|
|
const loaded = firstPainted
|
|
? slidesToLoad(active, slides.length)
|
|
: [active];
|
|
|
|
return (
|
|
<Box
|
|
as="section"
|
|
aria-label="Uitgelicht werk"
|
|
aria-roledescription="carousel"
|
|
position="relative"
|
|
// Eigen stacking context: de z-indexen hieronder gelden alleen
|
|
// binnen de hero en botsen niet met de navigatiebalk.
|
|
isolation="isolate"
|
|
h="100svh"
|
|
minH="560px"
|
|
overflow="hidden"
|
|
bg="ink"
|
|
touchAction="pan-y"
|
|
{...handlers}
|
|
>
|
|
{/* Slides: crossfade met een langzame inzoom */}
|
|
<Box position="absolute" inset={0}>
|
|
{slides.map((slide, i) => (
|
|
<Box
|
|
key={slide.id}
|
|
role="group"
|
|
aria-roledescription="slide"
|
|
aria-label={`${i + 1} van ${slides.length}`}
|
|
aria-hidden={i !== active}
|
|
position="absolute"
|
|
inset={0}
|
|
opacity={i === active ? 1 : 0}
|
|
transitionProperty="opacity"
|
|
transitionDuration="fade"
|
|
transitionTimingFunction="smooth"
|
|
>
|
|
{loaded.includes(i) && (
|
|
<Image
|
|
src={slide.src}
|
|
alt={slide.alt}
|
|
fetchPriority={i === 0 ? 'high' : undefined}
|
|
onLoad={
|
|
firstPainted ? undefined : onFirstLoaded
|
|
}
|
|
onError={
|
|
firstPainted ? undefined : onFirstLoaded
|
|
}
|
|
w="100%"
|
|
h="100%"
|
|
objectFit="cover"
|
|
transform={
|
|
reducedMotion || i === active
|
|
? 'scale(1)'
|
|
: 'scale(1.06)'
|
|
}
|
|
transition="transform 9s linear"
|
|
/>
|
|
)}
|
|
</Box>
|
|
))}
|
|
</Box>
|
|
|
|
{/* Scrim */}
|
|
<Box aria-hidden position="absolute" inset={0} bgGradient="scrim" />
|
|
|
|
<Container
|
|
position="relative"
|
|
zIndex={1}
|
|
h="100%"
|
|
pt="header"
|
|
display="flex"
|
|
flexDirection="column"
|
|
alignItems="center"
|
|
justifyContent="center"
|
|
textAlign="center"
|
|
color="white"
|
|
>
|
|
{/* Tagline en naam samen in één h1: zo staan de zoekwoorden
|
|
(wat en waar) in de belangrijkste kop van de pagina */}
|
|
<Heading as="h1" mb={9} color="white">
|
|
<chakra.span
|
|
display="block"
|
|
mb={4}
|
|
fontFamily="body"
|
|
textStyle="eyebrow"
|
|
// Zelfde regelhoogte als lopende tekst, niet die van de kop
|
|
lineHeight="1.5"
|
|
color="white/80"
|
|
>
|
|
{tagline}
|
|
</chakra.span>{' '}
|
|
<chakra.span display="block" textStyle="display">
|
|
{title}
|
|
</chakra.span>
|
|
</Heading>
|
|
<LinkButton to={cta.to} variant="light">
|
|
{cta.label}
|
|
</LinkButton>
|
|
</Container>
|
|
|
|
{slides.length > 1 && <HeroArrows onPrev={prev} onNext={next} />}
|
|
<HeroSocials socials={socials} />
|
|
{autoplay && (
|
|
<HeroPauseButton stopped={stopped} onToggle={toggleStopped} />
|
|
)}
|
|
|
|
{/* Meldt een wissel of pauze door de bezoeker; staat er altijd, want een
|
|
live-gebied moet al bestaan voordat de tekst verandert. Leeg na
|
|
een automatische wissel, zodat er geen oude melding blijft. */}
|
|
<VisuallyHidden
|
|
aria-live="polite"
|
|
aria-atomic="true"
|
|
data-testid="hero-announcement"
|
|
>
|
|
{announcementText(
|
|
announcement,
|
|
`Foto ${active + 1} van ${slides.length}: ${slides[active].alt}`,
|
|
)}
|
|
</VisuallyHidden>
|
|
|
|
{/* Voortgangsbalk: als de animatie klaar is, schuift de slider door.
|
|
Door de key start hij opnieuw bij elke slidewissel. */}
|
|
{autoplay && (
|
|
<Box
|
|
key={active}
|
|
aria-hidden
|
|
data-testid="hero-progress"
|
|
data-requires-js
|
|
data-state={paused ? 'paused' : 'running'}
|
|
position="absolute"
|
|
left={0}
|
|
bottom={0}
|
|
zIndex={2}
|
|
h="2px"
|
|
bg="white"
|
|
animationName="expand-width"
|
|
animationDuration={SLIDE_DURATION}
|
|
animationTimingFunction="linear"
|
|
animationFillMode="forwards"
|
|
animationPlayState={paused ? 'paused' : 'running'}
|
|
css={{ '--width': '100%' }}
|
|
onAnimationEnd={advance}
|
|
/>
|
|
)}
|
|
</Box>
|
|
);
|
|
}
|