wealth/packages/island/src/molecules/media-carousel/MediaCarousel.tsx

49 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { MediaSlide } from './components/MediaSlide';
import { MediaTrack } from './components/MediaTrack';
import { MAX_MEDIA } from './constants';
import type { MediaCarouselProps } from './types';
/**
* A post's images. One shows full width at its own ratio, letterboxed at 400px on
* `surface-sunken`; 2–4 swipe in 280px slides with dots and a «۱ / ۳» count. Server-renderable:
* a single image ships no JavaScript, and only the swipe track is a client component, so every
* prop it takes is serializable except `onOpen`, which only a client caller can pass.
*/
export function MediaCarousel({
items,
slideLabels,
href,
onOpen,
label,
className,
}: MediaCarouselProps) {
const shown = items.slice(0, MAX_MEDIA);
if (shown.length === 0) return null;
if (shown.length === 1) {
return (
<MediaSlide
item={shown[0]}
index={0}
single
label={slideLabels?.[0]}
href={href}
onOpen={onOpen}
className={className}
/>
);
}
return (
<MediaTrack
items={shown}
slideLabels={slideLabels}
href={href}
onOpen={onOpen}
label={label}
className={className}
/>
);
}