diff --git a/modules/ai/assets/js/editor/pages/form-layout/components/attachments/thumbnail-url.js b/modules/ai/assets/js/editor/pages/form-layout/components/attachments/thumbnail-url.js index 7ab88c7636d1..14b5ab308432 100644 --- a/modules/ai/assets/js/editor/pages/form-layout/components/attachments/thumbnail-url.js +++ b/modules/ai/assets/js/editor/pages/form-layout/components/attachments/thumbnail-url.js @@ -1,4 +1,4 @@ -import { Thumbnail } from './thumbnail'; +import { Thumbnail, THUMBNAIL_SIZE } from './thumbnail'; import { __ } from '@wordpress/i18n'; import PropTypes from 'prop-types'; import { Box, IconButton } from '@elementor/ui'; @@ -18,6 +18,8 @@ export const ThumbnailUrl = ( props ) => { position: 'relative', borderRadius: 1, overflow: 'hidden', + minWidth: THUMBNAIL_SIZE, + '&:hover::before': { content: '""', position: 'absolute', @@ -34,7 +36,7 @@ export const ThumbnailUrl = ( props ) => { { event.stopPropagation(); diff --git a/modules/ai/assets/js/editor/pages/form-layout/components/attachments/thumbnail.js b/modules/ai/assets/js/editor/pages/form-layout/components/attachments/thumbnail.js index 75add500f13f..e74049cd64f5 100644 --- a/modules/ai/assets/js/editor/pages/form-layout/components/attachments/thumbnail.js +++ b/modules/ai/assets/js/editor/pages/form-layout/components/attachments/thumbnail.js @@ -2,7 +2,7 @@ import { useEffect, useRef } from 'react'; import { Box } from '@elementor/ui'; import PropTypes from 'prop-types'; -const THUMBNAIL_SIZE = 64; +export const THUMBNAIL_SIZE = 64; export const Thumbnail = ( props ) => { const previewRef = useRef( null ); @@ -10,9 +10,17 @@ export const Thumbnail = ( props ) => { useEffect( () => { if ( previewRef.current ) { const previewRoot = previewRef.current.firstElementChild; + const width = previewRoot?.offsetWidth || THUMBNAIL_SIZE; const height = previewRoot?.offsetHeight || THUMBNAIL_SIZE; + // Keep the aspect ratio + previewRoot.style.width = `${ width }px`; + previewRoot.style.height = `${ height }px`; + + previewRef.current.style.width = `${ THUMBNAIL_SIZE }px`; + previewRef.current.style.height = `${ THUMBNAIL_SIZE }px`; + const scaleFactor = Math.min( height, width ); const scale = THUMBNAIL_SIZE / scaleFactor; @@ -32,12 +40,6 @@ export const Thumbnail = ( props ) => { return ( { sx={ { pointerEvents: 'none', transformOrigin: 'center', - width: THUMBNAIL_SIZE, - height: THUMBNAIL_SIZE, } } dangerouslySetInnerHTML={ { __html: props.html,