-
Notifications
You must be signed in to change notification settings - Fork 298
Expand file tree
/
Copy pathModalGallery.tsx
More file actions
58 lines (51 loc) · 1.58 KB
/
ModalGallery.tsx
File metadata and controls
58 lines (51 loc) · 1.58 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { useMemo } from 'react';
import type { ReactImageGalleryItem } from 'react-image-gallery';
import ImageGallery from 'react-image-gallery';
import { BaseImage } from './BaseImage';
import { useTranslationContext } from '../../context';
import type { Attachment } from 'stream-chat';
export type ModalGalleryProps = {
/** The images for the Carousel component */
images: Attachment[];
/** The index for the component */
index?: number;
};
const onError: React.ReactEventHandler<HTMLImageElement> = (e) => {
// Prevent having alt attribute on img as the img takes the height of the alt text
// instead of the CSS / element width & height when the CSS mask (fallback) is applied.
(e.target as HTMLImageElement).alt = '';
};
const renderItem = ({ original, originalAlt }: ReactImageGalleryItem) => (
<BaseImage
alt={originalAlt}
className='image-gallery-image'
onError={onError}
src={original}
/>
);
export const ModalGallery = (props: ModalGalleryProps) => {
const { images, index } = props;
const { t } = useTranslationContext('ModalGallery');
const formattedArray = useMemo(
() =>
images.map((image) => {
const imageSrc = image.image_url || image.thumb_url || '';
return {
original: imageSrc,
originalAlt: t('User uploaded content'),
source: imageSrc,
};
}),
[images, t],
);
return (
<ImageGallery
items={formattedArray}
renderItem={renderItem}
showIndex={true}
showPlayButton={false}
showThumbnails={false}
startIndex={index}
/>
);
};