StillImage: make it play nice with Tailwind, remove still-image.scss
This commit is contained in:
parent
9df92e91e7
commit
f7d75f57ea
|
@ -160,16 +160,21 @@ const Item: React.FC<IItem> = ({
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else if (attachment.type === 'image') {
|
} else if (attachment.type === 'image') {
|
||||||
const letterboxed = shouldLetterbox(attachment);
|
const letterboxed = total === 1 && shouldLetterbox(attachment);
|
||||||
|
|
||||||
thumbnail = (
|
thumbnail = (
|
||||||
<a
|
<a
|
||||||
className={classNames('media-gallery__item-thumbnail', { letterboxed })}
|
className={classNames('media-gallery__item-thumbnail')}
|
||||||
href={attachment.url}
|
href={attachment.url}
|
||||||
onClick={handleClick}
|
onClick={handleClick}
|
||||||
target='_blank'
|
target='_blank'
|
||||||
>
|
>
|
||||||
<StillImage src={attachment.url} alt={attachment.description} />
|
<StillImage
|
||||||
|
className='w-full h-full'
|
||||||
|
src={attachment.url}
|
||||||
|
alt={attachment.description}
|
||||||
|
letterboxed={letterboxed}
|
||||||
|
/>
|
||||||
</a>
|
</a>
|
||||||
);
|
);
|
||||||
} else if (attachment.type === 'gifv') {
|
} else if (attachment.type === 'gifv') {
|
||||||
|
|
|
@ -12,10 +12,12 @@ interface IStillImage {
|
||||||
src: string,
|
src: string,
|
||||||
/** Extra CSS styles on the outer <div> element. */
|
/** Extra CSS styles on the outer <div> element. */
|
||||||
style?: React.CSSProperties,
|
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. */
|
/** 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 settings = useSettings();
|
||||||
const autoPlayGif = settings.get('autoPlayGif');
|
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 (
|
return (
|
||||||
<div data-testid='still-image-container' className={classNames(className, 'still-image', { 'still-image--play-on-hover': hoverToPlay })} style={style}>
|
<div
|
||||||
<img src={src} alt={alt} ref={img} onLoad={handleImageLoad} />
|
data-testid='still-image-container'
|
||||||
{hoverToPlay && <canvas ref={canvas} />}
|
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>
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -74,6 +74,7 @@ const MediaItem: React.FC<IMediaItem> = ({ attachment, displayWidth, onOpenMedia
|
||||||
src={attachment.preview_url}
|
src={attachment.preview_url}
|
||||||
alt={attachment.description}
|
alt={attachment.description}
|
||||||
style={{ objectPosition: `${x}% ${y}%` }}
|
style={{ objectPosition: `${x}% ${y}%` }}
|
||||||
|
className='w-full h-full rounded-lg overflow-hidden'
|
||||||
/>
|
/>
|
||||||
);
|
);
|
||||||
} else if (['gifv', 'video'].indexOf(attachment.type) !== -1) {
|
} else if (['gifv', 'video'].indexOf(attachment.type) !== -1) {
|
||||||
|
|
|
@ -577,7 +577,7 @@ const Header: React.FC<IHeader> = ({ account }) => {
|
||||||
<Avatar
|
<Avatar
|
||||||
src={account.avatar}
|
src={account.avatar}
|
||||||
size={96}
|
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>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in New Issue