Files
AndreaSlopFotografie/web/src/components/Hero/Hero.tsx
T
SluijsensandClaude Opus 5.5 614707bfff Builds the hero slider with arrows, swipe, and social icons
Replaces the placeholder hero with a crossfading slider (slow zoom, 6s per
slide) driven by the progress bar animation; it pauses on mouse hover,
keyboard focus, and hidden tabs, and skips autoplay with reduced motion.
Adds prev/next arrows and touch swipe, and Facebook/Instagram icons from a
fixed set of platforms using bundled Iconify data (@iconify/react/offline
and @iconify-icons/ant-design, so no runtime API calls).

Content (tagline, title, CTA, slides, socials) is plain data in
heroContent.ts and passed in as a prop, so it can come from the CMS API
later. The tagline sits inside the h1 together with the name.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-10-13 23:12:42 +02:00

135 lines
5.0 KiB
TypeScript

import { Box, chakra, Container, Heading, Image } from '@chakra-ui/react';
import LinkButton from '../LinkButton';
import HeroArrows from './HeroArrows';
import HeroSocials from './HeroSocials';
import useHeroSlider from './useHeroSlider';
import type { HeroContent } from './types';
const SLIDE_DURATION = '6s';
type HeroProps = {
content: HeroContent;
};
export default function Hero({ content }: HeroProps) {
const { title, tagline, cta, slides, socials } = content;
const { active, reducedMotion, autoplay, paused, next, prev, handlers } =
useHeroSlider(slides.length);
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"
>
<Image
src={slide.src}
alt={slide.alt}
fetchPriority={i === 0 ? 'high' : undefined}
loading={i === 0 ? undefined : 'lazy'}
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} />
{/* 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
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={next}
/>
)}
</Box>
);
}