-
Notifications
You must be signed in to change notification settings - Fork 1
/
Images.tsx
49 lines (44 loc) · 1.36 KB
/
Images.tsx
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
import { CogsConnection } from '@clockworkdog/cogs-client';
import React from 'react';
import useImages from '../hooks/useImages';
import { useCogsConnection } from '../providers/CogsConnectionProvider';
export default function Images({
className,
style,
connection: customConnection,
fullscreen,
}: {
className?: string;
style?: React.CSSProperties;
// eslint-disable-next-line @typescript-eslint/no-explicit-any
connection?: CogsConnection<any>;
fullscreen?: boolean | { style: React.CSSProperties };
}): JSX.Element | null {
const connection = useCogsConnection(customConnection);
const images = useImages(connection);
const fullscreenCustomStyle = typeof fullscreen === 'object' ? fullscreen.style : undefined;
const imageElements = images.map((image, index) => (
<img
className={className}
key={index}
src={connection.getAssetUrl?.(image.file)}
alt={image.file}
style={{
objectFit: image.fit,
...(fullscreen ? { width: '100%', height: '100%', position: 'absolute', top: 0, left: 0 } : {}),
...style,
}}
/>
));
return (
<>
{fullscreen ? (
<div style={{ position: 'absolute', zIndex: 2, top: 0, left: 0, width: '100vw', height: '100vh', ...fullscreenCustomStyle }}>
{imageElements}
</div>
) : (
imageElements
)}
</>
);
}