Skip to content

Commit

Permalink
fix(FeaturedImage): prevent simultaneous width and fill props usage (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
whoami-pwd authored Dec 17, 2024
1 parent 32c8cf7 commit 6cf7643
Showing 1 changed file with 16 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,25 +10,33 @@ export default function FeaturedImage({
...props
}) {
const src = image?.sourceUrl;
const { altText } = image || '';

width = width ? width : image?.mediaDetails?.width;
height = height ? height : image?.mediaDetails?.height;
if (!src) return null;

const { altText = '', mediaDetails = {} } = image ?? {};

layout = layout ?? 'fill';

return src && width && height ? (
const dimensions = {
width: layout === 'fill' ? undefined : width ?? mediaDetails?.width,
height: layout === 'fill' ? undefined : height ?? mediaDetails?.height
};

if (layout !== 'fill' && (!dimensions.width || !dimensions.height)) return null;

return (
<figure className={className}>
<Image
src={src}
alt={altText}
layout={layout}
width={width}
height={height}
fill={layout}
width={dimensions.width}
height={dimensions.height}
priority={priority}
{...props}
/>
</figure>
) : null;
);
}

FeaturedImage.fragments = {
Expand Down

0 comments on commit 6cf7643

Please sign in to comment.