Skip to content
This repository has been archived by the owner on Dec 9, 2024. It is now read-only.

Commit

Permalink
Merge pull request #422 from Shinsina/add-image-wrapper-classes
Browse files Browse the repository at this point in the history
Add CSS classes to embedded image wrapping element depending on existence of caption and/or credit.
  • Loading branch information
zarathustra323 authored Sep 16, 2022
2 parents 3d95dc5 + 57be1dd commit 963c7a9
Showing 1 changed file with 10 additions and 0 deletions.
10 changes: 10 additions & 0 deletions packages/marko-web/utils/embedded-media/image.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@ const stringifyAttrs = attrs => Object.keys(attrs).reduce((arr, key) => {
return arr;
}, []).join(' ');

const buildWrapperClass = ({ caption, credit }) => {
const classes = [];
if (caption) classes.push('image-with-caption');
if (credit) classes.push('image-with-credit');
return classes.join(' ');
};

module.exports = (tag, { config } = {}, { lazyloadImages } = {}) => {
const lazyload = lazyloadImages == null ? config.lazyloadImages() : lazyloadImages;
const src = tag.get('src');
Expand All @@ -17,10 +24,13 @@ module.exports = (tag, { config } = {}, { lazyloadImages } = {}) => {
const width = tag.get('width');
const height = tag.get('height');

const wrapperClass = buildWrapperClass({ caption, credit });

const attrs = {
'data-embed-type': tag.type,
'data-embed-id': tag.id,
'data-embed-align': align,
...(wrapperClass && { class: wrapperClass }),
};

const minWidth = 400;
Expand Down

0 comments on commit 963c7a9

Please sign in to comment.