fix: preserve result thumbnail aspect ratios
This commit is contained in:
@@ -11,7 +11,9 @@ type PreviewState = {
|
||||
|
||||
function parseRatio(aspectRatio?: string) {
|
||||
if (!aspectRatio || aspectRatio === 'long') return aspectRatio === 'long' ? 1 / 3 : 1;
|
||||
const [w, h] = aspectRatio.split(':').map(Number);
|
||||
const [w, h] = aspectRatio.includes('/')
|
||||
? aspectRatio.split('/').map(part => Number(part.trim()))
|
||||
: aspectRatio.split(':').map(Number);
|
||||
return w && h ? w / h : 1;
|
||||
}
|
||||
|
||||
@@ -42,11 +44,13 @@ export function HoverImagePreview({
|
||||
alt,
|
||||
imageClassName,
|
||||
aspectRatio,
|
||||
onImageLoad,
|
||||
}: {
|
||||
src: string;
|
||||
alt: string;
|
||||
imageClassName?: string;
|
||||
aspectRatio?: string;
|
||||
onImageLoad?: (image: HTMLImageElement) => void;
|
||||
}) {
|
||||
const [preview, setPreview] = useState<PreviewState | null>(null);
|
||||
|
||||
@@ -61,6 +65,7 @@ export function HoverImagePreview({
|
||||
setPreview(nextPreviewState(event, aspectRatio));
|
||||
}}
|
||||
onPointerLeave={() => setPreview(null)}
|
||||
onLoad={event => onImageLoad?.(event.currentTarget)}
|
||||
/>
|
||||
{preview && (
|
||||
<div
|
||||
|
||||
Reference in New Issue
Block a user