Redesigns the testimonials section

A landscape photo overlaps a card with the shoot type, quote and names. The controls are two arrows with an X / Y counter; the dots are gone and nothing moves by itself. A change slides the whole slide horizontally, also on a swipe. Reviews get an optional imagePosition for the crop, normalised by normalizeImagePosition; slideCounter writes the counter. Both helpers have property tests next to example tests.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-06 01:24:14 +01:00
co-authored by Claude Sonnet 5.5
parent 9a2e84e4b2
commit b03b18f58e
14 changed files with 607 additions and 159 deletions
@@ -4,6 +4,7 @@ import {
Carousel,
chakra,
Flex,
Text,
useCarousel,
useMediaQuery,
useRecipe,
@@ -13,14 +14,16 @@ import { Icon } from '@iconify/react/offline';
import leftOutlined from '@iconify-icons/ant-design/left-outlined';
import rightOutlined from '@iconify-icons/ant-design/right-outlined';
import type { Testimonial } from '@/content/types';
import { slideCounter } from '@/lib/slideCounter';
import { slideLabel } from '@/lib/slideLabel';
import TestimonialSlide from './TestimonialSlide';
// The carousel itself. Chakra's carousel (Zag) handles paging, snapping,
// looping, swiping and hiding off-screen slides. The buttons, dots and arrow
// keys are our own: the built-in ones always scroll smoothly from
// JavaScript, which CSS cannot switch off for visitors who prefer reduced
// motion; ours pass the API's `instant` flag instead (BR-REV-06).
// looping, swiping and hiding off-screen slides. The buttons and arrow keys
// are our own: the built-in ones always scroll smoothly from JavaScript,
// which CSS cannot switch off for visitors who prefer reduced motion; ours
// pass the API's `instant` flag instead (BR-REV-06). The review only changes
// by those buttons and keys or by swiping: nothing moves by itself.
export default function TestimonialCarousel({
testimonials,
}: {
@@ -34,8 +37,8 @@ export default function TestimonialCarousel({
slideCount: count,
loop: true,
allowMouseDrag: true,
// Room between slides, so the next one never peeks in
spacing: '4rem',
// The slides follow each other directly, as in the design
spacing: '0px',
translations: { item: slideLabel },
onPageChange: ({ page }) => setAnnouncement(slideLabel(page, count)),
});
@@ -50,30 +53,39 @@ export default function TestimonialCarousel({
aria-label="Reviews"
aria-roledescription="carrousel"
gap={0}
// The control bar lies over the bottom right of the slides
position="relative"
maxW={{ lg: '1120px' }}
mx="auto"
>
{/* Our own live region announces changes, so the item group's
built-in one is switched off to avoid hearing it twice */}
<Carousel.ItemGroup aria-live="off">
{testimonials.map((testimonial, index) => (
// The photo's sand block sticks out 1.5rem to the left
// and below (FramedImage); the item group clips
// everything outside a slide, so each slide makes room
<Carousel.Item
key={testimonial.id}
index={index}
ps={{ base: 0, sm: '1.5rem' }}
pb={{ base: 0, sm: '1.5rem' }}
>
<TestimonialSlide testimonial={testimonial} />
<Carousel.Item key={testimonial.id} index={index}>
<TestimonialSlide
testimonial={testimonial}
withControls
near
/>
</Carousel.Item>
))}
</Carousel.ItemGroup>
{/* From lg the bar sits in the room under the card, in line with
the card's text; below lg it follows the slides, centred.
The 25% and 44px match the card's padding. */}
<Flex
position={{ lg: 'absolute' }}
bottom={{ lg: 0 }}
right={{ lg: 0 }}
w={{ lg: '56%' }}
ps={{ lg: '25%' }}
pe={{ lg: '44px' }}
mt={{ base: 7, lg: 0 }}
justifyContent="center"
alignItems="center"
gap={6}
mt="clamp(2.5rem, 5vw, 4rem)"
gap={3}
onKeyDown={(event) => {
if (event.key === 'ArrowLeft') previous();
else if (event.key === 'ArrowRight') next();
@@ -90,23 +102,19 @@ export default function TestimonialCarousel({
>
<Icon icon={leftOutlined} aria-hidden />
</chakra.button>
<Flex gap={1}>
{testimonials.map((testimonial, index) => (
<chakra.button
key={testimonial.id}
type="button"
aria-label={`Review ${index + 1}`}
aria-current={
carousel.page === index ? 'true' : undefined
}
data-testid={`testimonials-dot-${index + 1}`}
css={control({ kind: 'dot' })}
onClick={() =>
carousel.scrollTo(index, reducedMotion)
}
/>
))}
</Flex>
{/* Visible text only: the live region below says it aloud */}
<Text
aria-hidden="true"
data-testid="testimonials-counter"
minW="56px"
textAlign="center"
fontFamily="heading"
fontSize="16px"
letterSpacing="0.08em"
color="ink.soft"
>
{slideCounter(carousel.page, count)}
</Text>
<chakra.button
type="button"
aria-label="Volgende review"