Skip to content

Commit

Permalink
Fixes media styles block error
Browse files Browse the repository at this point in the history
  • Loading branch information
ncoetzer committed Oct 6, 2023
1 parent e670cea commit 4dba3d1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions components/image/child-components/media.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import PropTypes from 'prop-types';
import { MediaPlaceholder, InspectorControls } from '@wordpress/block-editor';
import { useContext, createContext } from '@wordpress/element';
import { MediaPlaceholder, InspectorControls } from '@wordpress/block-editor';
import { Spinner, FocalPointPicker, PanelBody, Placeholder } from '@wordpress/components';
import { __ } from '@wordpress/i18n';

Expand All @@ -21,16 +21,13 @@ export const Media = (props) => {
hasImage,
} = useContext(ImageContext);

let focalPointStyle = {};

if (shouldDisplayFocalPointPicker) {
const focalPointStyle = {
focalPointStyle = {
objectFit: 'cover',
objectPosition: `${focalPoint.x * 100}% ${focalPoint.y * 100}%`,
};

props.styles = {
...style,
...focalPointStyle,
};
}

if (isResolvingMedia) {
Expand All @@ -55,7 +52,14 @@ export const Media = (props) => {
</PanelBody>
</InspectorControls>
)}
{hasImage && <img src={imageUrl} alt={altText} {...props} />}
{hasImage && (
<img
src={imageUrl}
alt={altText}
style={{ ...style, focalPointStyle }}
{...props}
/>
)}
{canEditImage && (
<MediaPlaceholder
labels={labels}
Expand Down

0 comments on commit 4dba3d1

Please sign in to comment.