fix: image zoom over 100% (#998)

This commit is contained in:
Aman Harwara
2022-04-25 19:51:39 +05:30
committed by GitHub
parent 46582b2577
commit d0d97a8dbc
3 changed files with 31 additions and 17 deletions

View File

@@ -115,8 +115,8 @@ export const FilePreviewModal: FunctionComponent<Props> = ({ application, file,
</button> </button>
</div> </div>
</div> </div>
<div className="flex flex-grow min-h-0 overflow-auto"> <div className="flex flex-grow min-h-0">
<div className="flex flex-grow items-center justify-center relative"> <div className="flex flex-grow items-center justify-center relative max-w-full">
{objectUrl ? ( {objectUrl ? (
<PreviewComponent file={file} objectUrl={objectUrl} /> <PreviewComponent file={file} objectUrl={objectUrl} />
) : isLoadingFile ? ( ) : isLoadingFile ? (

View File

@@ -13,21 +13,31 @@ export const ImagePreview: FunctionComponent<Props> = ({ objectUrl }) => {
const [imageZoomPercent, setImageZoomPercent] = useState(100) const [imageZoomPercent, setImageZoomPercent] = useState(100)
return ( return (
<div className="flex items-center justify-center w-full h-full overflow-auto"> <div className="flex items-center justify-center w-full h-full">
<img <div className="flex items-center justify-center w-full h-full relative overflow-auto">
src={objectUrl} <img
style={{ src={objectUrl}
'min-width': '100%', style={{
height: `${imageZoomPercent}%`, height: `${imageZoomPercent}%`,
'object-fit': 'contain', ...(imageZoomPercent <= 100
}} ? {
ref={(imgElement) => { 'min-width': '100%',
if (!initialImgHeightRef.current) { 'object-fit': 'contain',
initialImgHeightRef.current = imgElement?.height }
} : {
}} position: 'absolute',
/> inset: 0,
<div className="flex items-center absolute bottom-6 py-1 px-3 bg-default border-1 border-solid border-main rounded"> margin: 'auto',
}),
}}
ref={(imgElement) => {
if (!initialImgHeightRef.current) {
initialImgHeightRef.current = imgElement?.height
}
}}
/>
</div>
<div className="flex items-center absolute left-1/2 -translate-x-1/2 bottom-6 py-1 px-3 bg-default border-1 border-solid border-main rounded">
<span className="mr-1.5">Zoom:</span> <span className="mr-1.5">Zoom:</span>
<IconButton <IconButton
className="hover:bg-contrast p-1 rounded" className="hover:bg-contrast p-1 rounded"

View File

@@ -347,6 +347,10 @@
max-width: 35ch; max-width: 35ch;
} }
.max-w-full {
max-width: 100%;
}
.mb-4 { .mb-4 {
margin-bottom: 1rem; margin-bottom: 1rem;
} }