/
AssetRenderer.tsx
68 lines (64 loc) · 1.58 KB
/
AssetRenderer.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import classNames from 'classnames'
import {CtAsset} from 'lib/types'
import AssetImage from './AssetImage'
import AssetVideo from './AssetVideo'
import AssetSpinset from './AssetSpinset'
type AssetRendererProps = {
asset: CtAsset
width?: number
height?: number
isThumbnail?: boolean
forceImage?: boolean
className?: string
}
const AssetRenderer = ({
asset,
width,
height,
isThumbnail = false,
forceImage = false,
className,
}: AssetRendererProps) => {
const spinSetTags = asset.tags?.filter(x => x.includes('spinset')) ?? []
const isSpinset = spinSetTags.length > 0
const isVideo =
!isSpinset && asset.sources[0].contentType?.startsWith('video')
const isImage = !isSpinset && !isVideo
return (
<div
className={classNames(className, {
'w-full': !isThumbnail,
'relative w-full': isThumbnail,
})}
>
{isSpinset && (
<AssetSpinset
id={asset.id}
publicId={asset.sources[0].uri}
tags={asset.tags}
isThumbnail={isThumbnail}
/>
)}
{isImage && (
<AssetImage
publicId={asset.sources[0].uri}
format={asset.sources[0].contentType}
altText={asset.description?.['en-US']}
isThumbnail={isThumbnail}
width={width}
height={height}
/>
)}
{isVideo && (
<AssetVideo
publicId={asset.sources[0].uri}
isThumbnail={isThumbnail}
forceImage={forceImage}
width={width}
height={height}
/>
)}
</div>
)
}
export default AssetRenderer