Skip to content

Commit

Permalink
Add alignment option to images without captions
Browse files Browse the repository at this point in the history
  • Loading branch information
danielfdsilva committed Jun 16, 2023
1 parent a44d741 commit 8e7f0c4
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 11 deletions.
31 changes: 20 additions & 11 deletions app/scripts/components/common/blocks/images/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,17 +29,26 @@ Caption.propTypes = {
export default function Image(props) {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const { align, caption, attrAuthor, ...propsWithoutAttrs } = props;
const imageAlign = align ? align : 'center';
return caption || attrAuthor ? (
// if it is an inline image with a caption
<Figure className={`align-${imageAlign}`}>
<img loading='lazy' {...propsWithoutAttrs} />
<Caption attrAuthor={attrAuthor} attrUrl={props.attrUrl}>
{caption}
</Caption>
</Figure>
) : (
<img loading='lazy' {...propsWithoutAttrs} />
if (caption || attrAuthor) {
const imageAlign = align ? align : 'center';
return (
// if it is an inline image with a caption
<Figure className={`align-${imageAlign}`}>
<img loading='lazy' {...propsWithoutAttrs} />
<Caption attrAuthor={attrAuthor} attrUrl={props.attrUrl}>
{caption}
</Caption>
</Figure>
);
}

const imageAlign = align ? align : 'left';
return (
<img
className={`img-align-${imageAlign}`}
loading='lazy'
{...propsWithoutAttrs}
/>
);
}

Expand Down
9 changes: 9 additions & 0 deletions app/scripts/styles/content-block.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,15 @@ const ContentBlockProse = styled(VarProse)`
text-align: center;
}
}
.img-align-right {
margin-left: auto;
}
.img-align-center {
margin-left: auto;
margin-right: auto;
}
`;

// assign displayName that a block can tell
Expand Down

0 comments on commit 8e7f0c4

Please sign in to comment.