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>
93 lines
3.4 KiB
TypeScript
93 lines
3.4 KiB
TypeScript
import { lazy, Suspense } from 'react';
|
|
import { Box } from '@chakra-ui/react';
|
|
import { 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, 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';
|
|
|
|
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 (
|
|
<PageSection
|
|
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={
|
|
<CarouselPlaceholder testimonials={shown} />
|
|
}
|
|
>
|
|
<TestimonialCarousel testimonials={shown} />
|
|
</Suspense>
|
|
) : (
|
|
<CarouselPlaceholder testimonials={shown} />
|
|
)}
|
|
</Box>
|
|
)}
|
|
</Reveal>
|
|
</PageSection>
|
|
);
|
|
}
|
|
|
|
// Stands in for the carousel until it has loaded: the longest review laid
|
|
// out exactly like a slide (same padding), plus the controls' height. That
|
|
// makes it as tall as the carousel at every screen width, so nothing below
|
|
// moves when the carousel takes its place, not even during a scroll to
|
|
// #contact that passes this section while it loads.
|
|
function CarouselPlaceholder({
|
|
testimonials,
|
|
}: {
|
|
testimonials: Testimonial[];
|
|
}) {
|
|
const longest = testimonials.reduce((a, b) =>
|
|
b.quote.length > a.quote.length ? b : a,
|
|
);
|
|
return (
|
|
<Box>
|
|
<Box ps={{ base: 0, sm: '1.5rem' }} pb={{ base: 0, sm: '1.5rem' }}>
|
|
<TestimonialSlide testimonial={longest} />
|
|
</Box>
|
|
{/* The control bar: 48px buttons below the same margin */}
|
|
<Box mt="clamp(2.5rem, 5vw, 4rem)" h="48px" />
|
|
</Box>
|
|
);
|
|
}
|