StillImage: make it play nice with Tailwind, remove still-image.scss

This commit is contained in:
Alex Gleason 2022-11-20 14:23:18 -06:00
parent 9df92e91e7
commit f7d75f57ea
No known key found for this signature in database
GPG Key ID: 7211D1F99744FBB7
4 changed files with 44 additions and 8 deletions

View File

@ -160,16 +160,21 @@ const Item: React.FC<IItem> = ({
</div>
);
} else if (attachment.type === 'image') {
const letterboxed = shouldLetterbox(attachment);
const letterboxed = total === 1 && shouldLetterbox(attachment);
thumbnail = (
<a
className={classNames('media-gallery__item-thumbnail', { letterboxed })}
className={classNames('media-gallery__item-thumbnail')}
href={attachment.url}
onClick={handleClick}
target='_blank'
>
<StillImage src={attachment.url} alt={attachment.description} />
<StillImage
className='w-full h-full'
src={attachment.url}
alt={attachment.description}
letterboxed={letterboxed}
/>
</a>
);
} else if (attachment.type === 'gifv') {

View File

@ -12,10 +12,12 @@ interface IStillImage {
src: string,
/** Extra CSS styles on the outer <div> element. */
style?: React.CSSProperties,
/** Whether to display the image contained vs filled in its container. */
letterboxed?: boolean,
}
/** Renders images on a canvas, only playing GIFs if autoPlayGif is enabled. */
const StillImage: React.FC<IStillImage> = ({ alt, className, src, style }) => {
const StillImage: React.FC<IStillImage> = ({ alt, className, src, style, letterboxed = false }) => {
const settings = useSettings();
const autoPlayGif = settings.get('autoPlayGif');
@ -34,10 +36,38 @@ const StillImage: React.FC<IStillImage> = ({ alt, className, src, style }) => {
}
};
/** ClassNames shared between the `<img>` and `<canvas>` elements. */
const baseClassName = classNames('w-full h-full block', {
'object-contain': letterboxed,
'object-cover': !letterboxed,
});
return (
<div data-testid='still-image-container' className={classNames(className, 'still-image', { 'still-image--play-on-hover': hoverToPlay })} style={style}>
<img src={src} alt={alt} ref={img} onLoad={handleImageLoad} />
{hoverToPlay && <canvas ref={canvas} />}
<div
data-testid='still-image-container'
className={classNames(className, 'group overflow-hidden')}
style={style}
>
<div className='relative w-full h-full'>
<img
src={src}
alt={alt}
ref={img}
onLoad={handleImageLoad}
className={classNames(baseClassName, {
'absolute invisible group-hover:visible': hoverToPlay,
})}
/>
{hoverToPlay && (
<canvas
ref={canvas}
className={classNames(baseClassName, {
'group-hover:invisible': hoverToPlay,
})}
/>
)}
</div>
</div>
);
};

View File

@ -74,6 +74,7 @@ const MediaItem: React.FC<IMediaItem> = ({ attachment, displayWidth, onOpenMedia
src={attachment.preview_url}
alt={attachment.description}
style={{ objectPosition: `${x}% ${y}%` }}
className='w-full h-full rounded-lg overflow-hidden'
/>
);
} else if (['gifv', 'video'].indexOf(attachment.type) !== -1) {

View File

@ -577,7 +577,7 @@ const Header: React.FC<IHeader> = ({ account }) => {
<Avatar
src={account.avatar}
size={96}
className='h-24 w-24 rounded-full ring-4 ring-white dark:ring-primary-900'
className='relative h-24 w-24 rounded-full ring-4 ring-white dark:ring-primary-900'
/>
</a>
</div>