Skip to content

Commit

Permalink
MWPW-135160: Mnemonics inside merch card (#2024)
Browse files Browse the repository at this point in the history
* MWPW-135160: Mnemonics inside merch card

* Update merch-card.js

---------

Co-authored-by: Blaine Gunn <Blainegunn@gmail.com>
  • Loading branch information
Axelcureno and Blainegunn authored Apr 30, 2024
1 parent be17d65 commit 3b3149a
Show file tree
Hide file tree
Showing 6 changed files with 91 additions and 14 deletions.
39 changes: 30 additions & 9 deletions libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { decorateButtons, decorateBlockHrs } from '../../utils/decorate.js';
import { getConfig, createTag } from '../../utils/utils.js';
import { getConfig, createTag, loadStyle } from '../../utils/utils.js';
import { getMetadata } from '../section-metadata/section-metadata.js';
import { processTrackingLabels } from '../../martech/attributes.js';
import { replaceKey } from '../../features/placeholders.js';
Expand All @@ -9,6 +9,8 @@ const TAG_PATTERN = /^[a-zA-Z0-9_-]+:[a-zA-Z0-9_-]+\/[a-zA-Z0-9_-].*$/;

const CARD_TYPES = ['segment', 'special-offers', 'plans', 'catalog', 'product', 'inline-heading', 'image', 'mini-compare-chart'];

const CARD_SIZES = ['wide', 'super-wide'];

const TEXT_STYLES = {
H5: 'detail-m',
H4: 'body-xxs',
Expand Down Expand Up @@ -52,10 +54,21 @@ const appendSlot = (slotEls, slotName, merchCard) => {
merchCard.append(newEl);
};

const parseContent = (el, merchCard) => {
const innerElements = [
...el.querySelectorAll('h2, h3, h4, h5, p, ul, em'),
];
export async function loadMnemonicList(foreground) {
try {
const { base } = getConfig();
const stylePromise = new Promise((resolve) => {
loadStyle(`${base}/blocks/mnemonic-list/mnemonic-list.css`, resolve);
});
const loadModule = import(`${base}/blocks/mnemonic-list/mnemonic-list.js`)
.then(({ decorateMnemonicList }) => decorateMnemonicList(foreground));
await Promise.all([stylePromise, loadModule]);
} catch (err) {
window.lana?.log(`Failed to load mnemonic list module: ${err}`);
}
}

Check warning on line 69 in libs/blocks/merch-card/merch-card.js

View check run for this annotation

Codecov / codecov/patch

libs/blocks/merch-card/merch-card.js#L58-L69

Added lines #L58 - L69 were not covered by tests

const parseContent = async (el, merchCard) => {
let bodySlotName = `body-${merchCard.variant !== MINI_COMPARE_CHART ? 'xs' : 'm'}`;
let headingMCount = 0;

Expand All @@ -69,7 +82,13 @@ const parseContent = (el, merchCard) => {

let headingSize = 3;
const bodySlot = createTag('div', { slot: bodySlotName });

const mnemonicList = el.querySelector('.mnemonic-list');
if (mnemonicList) {
await loadMnemonicList(mnemonicList);
}

Check warning on line 88 in libs/blocks/merch-card/merch-card.js

View check run for this annotation

Codecov / codecov/patch

libs/blocks/merch-card/merch-card.js#L87-L88

Added lines #L87 - L88 were not covered by tests
const innerElements = [
...el.querySelectorAll('h2, h3, h4, h5, p, ul, em'),
];
innerElements.forEach((element) => {
let { tagName } = element;
if (isHeadingTag(tagName)) {
Expand Down Expand Up @@ -103,6 +122,7 @@ const parseContent = (el, merchCard) => {
bodySlot.append(element);
merchCard.append(bodySlot);
}
if (mnemonicList) bodySlot.append(mnemonicList);
});

if (merchCard.variant === MINI_COMPARE_CHART && merchCard.childNodes[1]) {
Expand Down Expand Up @@ -283,6 +303,7 @@ const init = async (el) => {
}
const merchCard = createTag('merch-card', { class: styles.join(' '), 'data-block': '' });
merchCard.setAttribute('variant', cardType);
merchCard.setAttribute('size', styles.find((style) => CARD_SIZES.includes(style)) || '');
if (el.dataset.removedManifestId) {
merchCard.dataset.removedManifestId = el.dataset.removedManifestId;
}
Expand Down Expand Up @@ -322,10 +343,11 @@ const init = async (el) => {
intersectionObserver.observe(merchCard);
footerRows = getMiniCompareChartFooterRows(el);
}
const images = el.querySelectorAll('picture');
const allPictures = el.querySelectorAll('picture');
const pictures = Array.from(allPictures).filter((picture) => !picture.closest('.mnemonic-list'));
let image;
const icons = [];
images.forEach((img) => {
pictures.forEach((img) => {
const imgNode = img.querySelector('img');
const { width, height } = imgNode;
const isSquare = Math.abs(width - height) <= 10;
Expand Down Expand Up @@ -416,7 +438,6 @@ const init = async (el) => {
}
}
}

decorateBlockHrs(merchCard);
simplifyHrs(merchCard);
if (merchCard.classList.contains('has-divider')) {
Expand Down
10 changes: 10 additions & 0 deletions libs/blocks/mnemonic-list/mnemonic-list.css
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@
margin: var(--spacing-xs) 0 ;
}

.merch-card .mnemonic-list {
padding: var(--consonant-merch-spacing-xs) 0;
}

.merch-card .mnemonic-list .product-list {
justify-content: flex-start;
align-items: center;
}

.mnemonic-list .product-list {
display: inline-flex;
flex-wrap: wrap;
Expand All @@ -22,6 +31,7 @@
flex: none;
gap: var(--spacing-xxs);
min-height: 32px;
line-height: initial;
}

.mnemonic-list .product-list .product-item strong {
Expand Down
2 changes: 1 addition & 1 deletion libs/blocks/mnemonic-list/mnemonic-list.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { createTag } from '../../utils/utils.js';

export const decorateMnemonicList = (container) => {
export const decorateMnemonicList = async (container) => {
const mnemonicListElement = container.querySelector('.mnemonic-list');
const targetElement = mnemonicListElement || container;
const rows = targetElement.querySelectorAll(':scope p:not([class])');
Expand Down
4 changes: 3 additions & 1 deletion libs/deps/merch-card.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 0 additions & 3 deletions test/blocks/merch-card/merch-card.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ describe('Plans Card', () => {
expect(merchCard.getAttribute('badge-background-color')).to.be.equal('#EDCC2D');
expect(merchCard.getAttribute('badge-color')).to.be.equal('#000000');
expect(merchCard.getAttribute('badge-text')).to.be.equal('LOREM IPSUM DOLOR');
expect(JSON.parse(merchCard.getAttribute('icons'))).to.have.lengthOf(2);
expect(merchCard.getAttribute('checkbox-label')).to.be.equal('Add a 30-day free trial of Adobe Stock.*');
expect(body.textContent).to.be.equal('Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim.MaecenasSee terms about lorem ipsum');
expect(detail.textContent).to.be.equal('Maecenas porttitor enim.');
Expand Down Expand Up @@ -100,7 +99,6 @@ describe('Plans Card', () => {
expect(merchCard.getAttribute('badge-background-color')).to.be.equal('#EDCC2D');
expect(merchCard.getAttribute('badge-color')).to.be.equal('#000000');
expect(merchCard.getAttribute('badge-text')).to.be.equal('LOREM IPSUM DOLOR');
expect(JSON.parse(merchCard.getAttribute('icons'))).to.have.lengthOf(2);
expect(merchCard.getAttribute('checkbox-label')).to.be.equal('Add a 30-day free trial of Adobe Stock.*');
expect(body.textContent).to.be.equal('Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim.MaecenasSee terms about lorem ipsum');
expect(detail.textContent).to.be.equal('Maecenas porttitor enim.');
Expand All @@ -126,7 +124,6 @@ describe('Plans Card', () => {
expect(detail).to.exist;
expect(merchCard.getAttribute('variant')).to.be.equal('plans');
expect(merchCard.getAttribute('badge')).to.not.exist;
expect(JSON.parse(merchCard.getAttribute('icons'))).to.have.lengthOf(2);
expect(body.textContent).to.be.equal('Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim.See terms about lorem ipsum');
expect(detail.textContent).to.be.equal('Maecenas porttitor enim.');
expect(buttons.length).to.be.equal(2);
Expand Down
47 changes: 47 additions & 0 deletions test/blocks/merch-card/mocks/plans-card.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,4 +108,51 @@ <h5>Maecenas porttitor enim.</h5>
<div></div>
</div>
</div>
<div class="merch-card plans icons mnemonic">
<div>
<div> </div>
<div>LOREM IPSUM DOLOR</div>
</div>
<div>
<div>
<picture>
<source type="image/webp" srcset="" media="(min-width: 600px)">
<source type="image/webp" srcset="">
<source type="image/png" srcset="" media="(min-width: 600px)">
<img loading="lazy" alt="" src="" width="80" height="78">
</picture>
<picture>
<source type="image/webp" srcset="" media="(min-width: 600px)">
<source type="image/webp" srcset="">
<source type="image/png" srcset="" media="(min-width: 600px)">
<img loading="lazy" alt="" src="" width="80" height="78">
</picture>
<h2 id="lorem-ipsum-dolor-sit-amet"><em>Lorem ipsum dolor sit amet</em></h2>
<h3 id="lorem-ipsum-dolor">Lorem ipsum dolor</h3>
<h5>Maecenas porttitor enim.</h5>
<p>Maecenas porttitor congue massa. Fusce posuere, magna sed pulvinar ultricies, purus lectus malesuada libero, sit amet commodo magna eros quis urna. Nunc viverra imperdiet enim.</p>
<p><a href="https://adobe.com/">See terms about lorem ipsum</a></p>
<p>
<div class="mnemonic-list">
<div>
<div data-valign="middle">
<p><strong>Key apps:</strong></p>
<p><a href="/assets/img/acrobat-pro.svg">https://main--milo--adobecom.hlx.page/assets/img/acrobat-pro.svg | Acrobat Pro</a> <strong>Acrobat</strong></p>
<p><a href="/assets/img/photoshop.svg">https://main--milo--adobecom.hlx.page/assets/img/photoshop.svg | Photoshop</a> <strong>Photoshop</strong></p>
<p><a href="/assets/img/premiere.svg">https://main--milo--adobecom.hlx.page/assets/img/premiere.svg | Premiere Pro</a> <strong>Premiere Pro</strong></p>
<p><a href="/assets/img/illustrator.svg">https://main--milo--adobecom.hlx.page/assets/img/illustrator.svg | Illustrator</a> <strong>Illustrator</strong></p>
<p><a href="/assets/img/cc-express.svg">https://main--milo--adobecom.hlx.page/assets/img/cc-express.svg | Adobe Express</a> <strong>Adobe Express</strong></p>
<p><a href="/assets/img/mnemonic/lightroom.svg">https://main--milo--adobecom.hlx.page/assets/img/mnemonic/lightroom.svg | Lightroom</a> <strong>Lightroom</strong></p>
</div>
</div>
</div>
</p>
<p><em><a href="https://business.adobe.com/">Learn More</a></em> <strong><a href="https://business.adobe.com/">Save now</a></strong></p>
</div>
</div>
<div>
<div>Lorem ipsum dolor sit amet</div>
<div></div>
</div>
</div>
</div>

0 comments on commit 3b3149a

Please sign in to comment.