54 lines
1.3 KiB
TypeScript
54 lines
1.3 KiB
TypeScript
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, and from 480px wide
|
||
* also move with ‹ › buttons on the image. 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,
|
||
previousLabel,
|
||
nextLabel,
|
||
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}
|
||
previousLabel={previousLabel}
|
||
nextLabel={nextLabel}
|
||
className={className}
|
||
/>
|
||
);
|
||
}
|