Adds the Lieve woorden section to the homepage
Shows client reviews one at a time with the framed photo, a large quotation mark, the shoot type and the names. Uses Chakra's carousel for paging, looping and swiping with our own controls, so visitors who prefer reduced motion get instant changes, and loads the carousel only when the section comes near the screen so the hero does not wait for it. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,71 @@
|
||||
import { lazy, Suspense } from 'react';
|
||||
import { Box } from '@chakra-ui/react';
|
||||
import { DEFERRED_LOAD_MARGIN } 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, Testimonial } from '@/content/types';
|
||||
import useInView from '@/hooks/useInView';
|
||||
import { visibleTestimonials } from '@/lib/visibleTestimonials';
|
||||
import TestimonialSlide from './TestimonialSlide';
|
||||
|
||||
// The carousel (Chakra/Zag) is the heaviest code on the page and sits far
|
||||
// below the hero. It is loaded only when this section comes near the screen,
|
||||
// so the hero (the largest contentful paint) never waits for it: loading it
|
||||
// with the page cost ±0.02 Lighthouse performance on mobile.
|
||||
const TestimonialCarousel = lazy(() => import('./TestimonialCarousel'));
|
||||
|
||||
const TITLE_ID = 'testimonials-title';
|
||||
|
||||
// Keeps about the space of the carousel while it loads, so the page below
|
||||
// does not jump when it arrives (measured: ±920px on phones and tablets,
|
||||
// ±570px at 1024px, ±790px at 1440px)
|
||||
const PLACEHOLDER_HEIGHT = { base: '920px', lg: '570px', xl: '790px' };
|
||||
|
||||
type TestimonialsProps = {
|
||||
content: HomeContent['testimonials'];
|
||||
testimonials: Testimonial[];
|
||||
};
|
||||
|
||||
// "Lieve woorden": client reviews, one at a time (design .testimonials).
|
||||
// Without a valid review the section is left out; a single review is shown
|
||||
// without carousel controls. The heading is always rendered.
|
||||
export default function Testimonials({
|
||||
content,
|
||||
testimonials,
|
||||
}: TestimonialsProps) {
|
||||
const shown = visibleTestimonials(testimonials);
|
||||
const { ref, inView } = useInView<HTMLDivElement>({
|
||||
rootMargin: DEFERRED_LOAD_MARGIN,
|
||||
});
|
||||
if (shown.length === 0) return null;
|
||||
|
||||
return (
|
||||
<HomeSection
|
||||
labelledBy={TITLE_ID}
|
||||
tone="alt"
|
||||
data-testid="testimonials"
|
||||
>
|
||||
<Reveal>
|
||||
<SectionHeading id={TITLE_ID} title={content.title} />
|
||||
</Reveal>
|
||||
<Reveal>
|
||||
{shown.length === 1 ? (
|
||||
<TestimonialSlide testimonial={shown[0]} />
|
||||
) : (
|
||||
<Box ref={ref}>
|
||||
{inView ? (
|
||||
<Suspense
|
||||
fallback={<Box minH={PLACEHOLDER_HEIGHT} />}
|
||||
>
|
||||
<TestimonialCarousel testimonials={shown} />
|
||||
</Suspense>
|
||||
) : (
|
||||
<Box minH={PLACEHOLDER_HEIGHT} />
|
||||
)}
|
||||
</Box>
|
||||
)}
|
||||
</Reveal>
|
||||
</HomeSection>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user