Skip to content

Commit

Permalink
Image: set width if aligned but unresized (#4356)
Browse files Browse the repository at this point in the history
  • Loading branch information
ellatrix authored and mtias committed Jan 12, 2018
1 parent cd7aa52 commit 66303b3
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion blocks/library/image/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -155,9 +155,16 @@ registerBlockType( 'core/image', {
save( { attributes } ) {
const { url, alt, caption, align, href, width, height } = attributes;
const extraImageProps = width || height ? { width, height } : {};
const figureStyle = width ? { width } : {};
const image = <img src={ url } alt={ alt } { ...extraImageProps } />;

let figureStyle = {};

if ( width ) {
figureStyle = { width };
} else if ( align === 'left' || align === 'right' ) {
figureStyle = { maxWidth: '50%' };
}

return (
<figure className={ align ? `align${ align }` : null } style={ figureStyle }>
{ href ? <a href={ href }>{ image }</a> : image }
Expand Down

0 comments on commit 66303b3

Please sign in to comment.