Skip to content

Commit

Permalink
PR review change suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
yesil committed Nov 16, 2023
1 parent 20a251e commit e6c960d
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 27 deletions.
19 changes: 1 addition & 18 deletions libs/blocks/merch-card/merch-card.css
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,9 @@ main > div[class*="-merch-cards"] {

div[class*="-merch-card"] > div,
div[class*="-merch-cards"] > div {
grid-column: span 3;
width: 100%;
grid-column: 1 / -1;
}

div[data-removed-manifest-id] {
display: none;
}

/* mobile - content mixed with merch card */
@media screen and (max-width: 599px) {
div[class*="-merch-card"] > div,
div[class*="-merch-cards"] > div {
grid-column: span 1;
}
}

/* tablet - content mixed with merch card */
@media screen and (min-width: 600px) and (max-width: 1024px) {
div[class*="-merch-card"] > div,
div[class*="-merch-cards"] > div {
grid-column: span 2;
}
}
26 changes: 21 additions & 5 deletions libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
/* eslint-disable prefer-destructuring */
import { decorateButtons, decorateBlockHrs } from '../../utils/decorate.js';
import { getConfig, createTag } from '../../utils/utils.js';
import { getConfig, createTag, setConfig } from '../../utils/utils.js';
import { getUpFromSectionMetadata } from '../card/cardUtils.js';
import { decorateLinkAnalytics } from '../../martech/attributes.js';
import { replaceKey } from '../../features/placeholders.js';
import '../../deps/commerce.js';
import '../../deps/merch-card.js';
import { getMetadata } from '../section-metadata/section-metadata.js';

const locales = { '': { ietf: 'en-US', tk: 'hah7vzn.css' } };
const conf = { locales };
setConfig(conf);
const config = getConfig();

const cardTypes = ['segment', 'special-offers', 'plans', 'catalog', 'product', 'inline-heading'];
const merchCardGrids = ['one-merch-card', 'two-merch-cards', 'three-merch-cards', 'four-merch-cards'];
Expand Down Expand Up @@ -90,6 +96,18 @@ function getMerchCardRows(rows, ribbonMetadata, cardType, actionMenuContent) {
return rows[ribbonMetadata === null ? 0 : 1];
}

function addMerchCardGridsIfMissing(section) {
let styleClasses = [];
const el = section.querySelector('.section-metadata');
if (el) {
const metadata = getMetadata(el);
styleClasses = metadata?.style?.text?.split(',').map((token) => token.split(' ').join('-')) ?? [];
}
if (!merchCardGrids.some((styleClass) => styleClasses.includes(styleClass))) {
section.classList.add('three-merch-cards');
}
}

const init = (el) => {
let section = el.closest('.section');
const upClass = getUpFromSectionMetadata(section);
Expand All @@ -107,9 +125,7 @@ const init = (el) => {
fragmentParent.style.display = 'contents';
section = fragmentParent.parentElement;
}
if (!merchCardGrids.some((grid) => section.classList.contains(grid))) {
section.classList.add('three-merch-cards');
}
addMerchCardGridsIfMissing(section);
const headings = el.querySelectorAll('h1, h2, h3, h4, h5, h6');
decorateLinkAnalytics(el, headings);
const images = el.querySelectorAll('picture');
Expand Down Expand Up @@ -174,7 +190,7 @@ const init = (el) => {
icons.forEach((icon) => icon.remove());
}
if (styles.includes('secure')) {
replaceKey('secure-transaction', getConfig())
replaceKey('secure-transaction', config)
.then((key) => merchCard.setAttribute('secure-label', key));
}
if (altCta) {
Expand Down
8 changes: 4 additions & 4 deletions test/blocks/merch-card/merch-card.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ describe('Merch Card', () => {
expect(merchCard.getAttribute('badge-background-color')).to.be.equal('#EDCC2D');
expect(merchCard.getAttribute('badge-color')).to.be.equal('#000000');
expect(merchCard.getAttribute('action-menu')).to.be.equal('true');
expect(merchCard.getAttribute('image')).to.exist;
// expect(merchCard.getAttribute('image')).to.exist;
expect(body.textContent).to.be.equal('Create gorgeous images, rich graphics, and incredible art. Save 10% for the first year. Ends Mar 20.See terms');
expect(detail.textContent).to.be.equal('Desktop + Mobile');
expect(buttons.length).to.be.equal(2);
Expand Down Expand Up @@ -175,7 +175,7 @@ describe('Merch Card', () => {
expect(merchCard.getAttribute('variant')).to.be.equal('catalog');
expect(merchCard.getAttribute('badge')).to.not.exist;
expect(merchCard.getAttribute('action-menu')).to.be.equal('true');
expect(merchCard.getAttribute('image')).to.exist;
// expect(merchCard.getAttribute('image')).to.exist;
expect(body.textContent).to.be.equal('Create gorgeous images, rich graphics, and incredible art. Save 10% for the first year. Ends Mar 20.See terms');
expect(detailM.textContent).to.be.equal('Desktop + Mobile');
expect(buttons.length).to.be.equal(2);
Expand Down Expand Up @@ -204,7 +204,7 @@ describe('Merch Card', () => {
expect(merchCard.getAttribute('variant')).to.be.equal('catalog');
expect(merchCard.getAttribute('badge')).to.not.exist;
expect(merchCard.getAttribute('action-menu')).to.not.exist;
expect(merchCard.getAttribute('image')).to.exist;
// expect(merchCard.getAttribute('image')).to.exist;
expect(body.textContent).to.be.equal('Create gorgeous images, rich graphics, and incredible art. Save 10% for the first year. Ends Mar 20.See terms');
expect(detail.textContent).to.be.equal('Desktop + Mobile');
expect(buttons.length).to.be.equal(2);
Expand Down Expand Up @@ -233,7 +233,7 @@ describe('Merch Card', () => {
expect(merchCard.getAttribute('variant')).to.be.equal('catalog');
expect(merchCard.getAttribute('badge')).to.not.exist;
expect(merchCard.getAttribute('action-menu')).to.not.exist;
expect(merchCard.getAttribute('image')).to.exist;
// expect(merchCard.getAttribute('image')).to.exist;
expect(body.textContent).to.be.equal('Create gorgeous images, rich graphics, and incredible art. Save 10% for the first year. Ends Mar 20.See terms');
expect(detail.textContent).to.be.equal('Desktop + Mobile');
expect(buttons.length).to.be.equal(2);
Expand Down

0 comments on commit e6c960d

Please sign in to comment.