kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Break out MediaItemThumbnail into a separate component
rodzic
c5cf252668
commit
4167a1de05
|
@ -1,4 +1,4 @@
|
||||||
import classNames from 'clsx';
|
import classNames, { clsx } from 'clsx';
|
||||||
import React, { useState, useRef, useLayoutEffect } from 'react';
|
import React, { useState, useRef, useLayoutEffect } from 'react';
|
||||||
|
|
||||||
import Blurhash from 'soapbox/components/blurhash';
|
import Blurhash from 'soapbox/components/blurhash';
|
||||||
|
@ -153,22 +153,20 @@ const Item: React.FC<IItem> = ({
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className={classNames('media-gallery__item', { standalone })} key={attachment.id} style={{ position, float, left, top, right, bottom, height, width: `${width}%` }}>
|
<div className={classNames('media-gallery__item', { standalone })} key={attachment.id} style={{ position, float, left, top, right, bottom, height, width: `${width}%` }}>
|
||||||
<a className='media-gallery__item-thumbnail' href={attachment.url} target='_blank' style={{ cursor: 'pointer' }}>
|
<MediaItemThumbnail href={attachment.url} pointer>
|
||||||
<Blurhash hash={attachment.blurhash} className='media-gallery__preview' />
|
<Blurhash hash={attachment.blurhash} className='media-gallery__preview' />
|
||||||
<span className='media-gallery__item__icons'>{attachmentIcon}</span>
|
<span className='media-gallery__item__icons'>{attachmentIcon}</span>
|
||||||
<span className='media-gallery__filename__label'>{filename}</span>
|
<span className='media-gallery__filename__label'>{filename}</span>
|
||||||
</a>
|
</MediaItemThumbnail>
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else if (attachment.type === 'image') {
|
} else if (attachment.type === 'image') {
|
||||||
const letterboxed = total === 1 && shouldLetterbox(attachment);
|
const letterboxed = total === 1 && shouldLetterbox(attachment);
|
||||||
|
|
||||||
thumbnail = (
|
thumbnail = (
|
||||||
<a
|
<MediaItemThumbnail
|
||||||
className='media-gallery__item-thumbnail'
|
|
||||||
href={attachment.url}
|
href={attachment.url}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
target='_blank'
|
|
||||||
>
|
>
|
||||||
<StillImage
|
<StillImage
|
||||||
className='w-full h-full'
|
className='w-full h-full'
|
||||||
|
@ -177,7 +175,7 @@ const Item: React.FC<IItem> = ({
|
||||||
letterboxed={letterboxed}
|
letterboxed={letterboxed}
|
||||||
showExt
|
showExt
|
||||||
/>
|
/>
|
||||||
</a>
|
</MediaItemThumbnail>
|
||||||
);
|
);
|
||||||
} else if (attachment.type === 'gifv') {
|
} else if (attachment.type === 'gifv') {
|
||||||
const conditionalAttributes: React.VideoHTMLAttributes<HTMLVideoElement> = {};
|
const conditionalAttributes: React.VideoHTMLAttributes<HTMLVideoElement> = {};
|
||||||
|
@ -210,25 +208,21 @@ const Item: React.FC<IItem> = ({
|
||||||
} else if (attachment.type === 'audio') {
|
} else if (attachment.type === 'audio') {
|
||||||
const ext = attachment.url.split('.').pop()?.toUpperCase();
|
const ext = attachment.url.split('.').pop()?.toUpperCase();
|
||||||
thumbnail = (
|
thumbnail = (
|
||||||
<a
|
<MediaItemThumbnail
|
||||||
className={classNames('media-gallery__item-thumbnail')}
|
|
||||||
href={attachment.url}
|
href={attachment.url}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
target='_blank'
|
|
||||||
title={attachment.description}
|
title={attachment.description}
|
||||||
>
|
>
|
||||||
<span className='media-gallery__item__icons'><Icon src={require('@tabler/icons/volume.svg')} /></span>
|
<span className='media-gallery__item__icons'><Icon src={require('@tabler/icons/volume.svg')} /></span>
|
||||||
<span className='media-gallery__file-extension__label'>{ext}</span>
|
<span className='media-gallery__file-extension__label'>{ext}</span>
|
||||||
</a>
|
</MediaItemThumbnail>
|
||||||
);
|
);
|
||||||
} else if (attachment.type === 'video') {
|
} else if (attachment.type === 'video') {
|
||||||
const ext = attachment.url.split('.').pop()?.toUpperCase();
|
const ext = attachment.url.split('.').pop()?.toUpperCase();
|
||||||
thumbnail = (
|
thumbnail = (
|
||||||
<a
|
<MediaItemThumbnail
|
||||||
className={classNames('media-gallery__item-thumbnail')}
|
|
||||||
href={attachment.url}
|
href={attachment.url}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
target='_blank'
|
|
||||||
title={attachment.description}
|
title={attachment.description}
|
||||||
>
|
>
|
||||||
<video
|
<video
|
||||||
|
@ -240,7 +234,7 @@ const Item: React.FC<IItem> = ({
|
||||||
<source src={attachment.url} />
|
<source src={attachment.url} />
|
||||||
</video>
|
</video>
|
||||||
<span className='media-gallery__file-extension__label'>{ext}</span>
|
<span className='media-gallery__file-extension__label'>{ext}</span>
|
||||||
</a>
|
</MediaItemThumbnail>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -552,4 +546,27 @@ const MediaGallery: React.FC<IMediaGallery> = (props) => {
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
interface IMediaItemThumbnail extends Pick<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'href' | 'onClick' | 'title'> {
|
||||||
|
children: React.ReactNode
|
||||||
|
pointer?: boolean
|
||||||
|
}
|
||||||
|
|
||||||
|
const MediaItemThumbnail: React.FC<IMediaItemThumbnail> = ({
|
||||||
|
children,
|
||||||
|
pointer = false,
|
||||||
|
...rest
|
||||||
|
}) => {
|
||||||
|
return (
|
||||||
|
<a
|
||||||
|
className={clsx('media-gallery__item-thumbnail', {
|
||||||
|
'cursor-pointer': pointer,
|
||||||
|
})}
|
||||||
|
target='_blank'
|
||||||
|
{...rest}
|
||||||
|
>
|
||||||
|
{children}
|
||||||
|
</a>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
export default MediaGallery;
|
export default MediaGallery;
|
||||||
|
|
Ładowanie…
Reference in New Issue