@@ -18,6 +18,7 @@ interface Props extends HTMLAttributes<HTMLElement> {
1818 node : GalleryNode ;
1919 onImageDownload ?: ( image : UploadcareImage ) => void ;
2020 onPreviewOpen ?: ( image : UploadcareImage ) => void ;
21+ baseCdnUrl ?: string ;
2122}
2223
2324interface Tile {
@@ -26,12 +27,19 @@ interface Tile {
2627 height : number ;
2728}
2829
29- export function Gallery ( { className, node, onImageDownload, onPreviewOpen, ...props } : Props ) {
30+ export function Gallery ( {
31+ className,
32+ node,
33+ onImageDownload,
34+ onPreviewOpen,
35+ baseCdnUrl,
36+ ...props
37+ } : Props ) {
3038 const [ rect , ref ] = useMeasure < HTMLDivElement > ( ) ;
3139 const galleryWidth = rect ?. width || DEFAULT_GALLERY_WIDTH_SSR [ node . layout ] ;
3240 const margin = IMAGE_PADDING [ node . padding ] ;
3341 const idealHeight = IMAGE_SIZE [ node . thumbnail_size ] + 2 * margin ;
34- const originalImages = useMemo ( ( ) => extractImages ( node ) , [ node ] ) ;
42+ const originalImages = useMemo ( ( ) => extractImages ( node , baseCdnUrl ) , [ node , baseCdnUrl ] ) ;
3543 const calculatedLayout = calculateLayout ( {
3644 idealHeight,
3745 images : originalImages ,
@@ -120,9 +128,13 @@ function Row(props: {
120128 ) ;
121129}
122130
123- function extractImages ( node : GalleryNode ) : UploadcareImage [ ] {
131+ function extractImages ( node : GalleryNode , baseCdnUrl : string | undefined ) : UploadcareImage [ ] {
124132 return node . images . map ( ( { caption, file } ) =>
125- UploadcareImage . createFromPrezlyStoragePayload ( file , caption ) ,
133+ baseCdnUrl
134+ ? UploadcareImage . createFromPrezlyStoragePayload ( file , caption ) . withBaseCdnUrl (
135+ baseCdnUrl ,
136+ )
137+ : UploadcareImage . createFromPrezlyStoragePayload ( file , caption ) ,
126138 ) ;
127139}
128140
0 commit comments