Skip to content

Commit

Permalink
[MWPW-158015] [Mini Compare Merch Card] Redesign mini compare card fo…
Browse files Browse the repository at this point in the history
…r testing (#3147)

* Redesign mini-compare chart. Added checkmarks for icons. Backward compatibility using "checkmark" class. Horizontal line added.

* implemented cheveron up and down functionality for checkmark copy list

* added isMobile check

* Fix backward compatibility issues

* minor

* minor css fixes as per figma

* refactored large "decorateFooterRows" method

* remove duplicate css
review comment

* review comments

* UT added

* fix post merge conflict

* npm run build

* linter

* UT coverage

* mini compare covergae

* review comment

* fix post merge. margin was affected due to ul change

* fixed ul after merge conflict with the other fix PR

* linter

* resolved conflicts

* fixed mini-compare-chart footer cta alignment

* decreased footer rows height to match the design

* fixed mini-compare footer alignment

* fixed footer horizontal padding and mobile breakpoint

* updated unit tests

* corrected paddings, font sizes and other

* corrected slots

* corrected padding

* footer padding corrected

* corrected heading-m-price padding

---------

Co-authored-by: Rohit Sahu <rosahu@adobe.com>
Co-authored-by: Mira <myrosvas@gmail.com>
  • Loading branch information
3 people authored Jan 2, 2025
1 parent a33a005 commit e4ad9d4
Show file tree
Hide file tree
Showing 22 changed files with 1,151 additions and 295 deletions.
12 changes: 12 additions & 0 deletions libs/blocks/merch-card/img/chevron.js

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

105 changes: 90 additions & 15 deletions libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -391,23 +391,98 @@ const getMiniCompareChartFooterRows = (el) => {
return footerRows;
};

const decorateFooterRows = (merchCard, footerRows) => {
if (footerRows) {
const footerRowsSlot = createTag('div', { slot: 'footer-rows' });
footerRows.forEach((row) => {
const rowIcon = row.firstElementChild.querySelector('picture');
const rowText = row.querySelector('div > div:nth-child(2)').innerHTML;
const rowTextParagraph = createTag('div', { class: 'footer-row-cell-description' }, rowText);
const footerRowCell = createTag('ul', { class: 'footer-row-cell' });
if (rowIcon) {
rowIcon.classList.add('footer-row-icon');
footerRowCell.appendChild(rowIcon);
const createFirstRow = async (firstRow, isMobile, checkmarkCopyContainer, defaultChevronState) => {
const firstRowText = firstRow.querySelector('div > div:last-child').innerHTML;
let firstRowTextParagraph;

if (isMobile) {
const { chevronDownSVG, chevronUpSVG } = await import('./img/chevron.js');
const chevronIcon = createTag('span', { class: 'chevron-icon' }, chevronDownSVG);
firstRowTextParagraph = createTag('div', { class: 'footer-rows-title' }, firstRowText);
firstRowTextParagraph.appendChild(chevronIcon);

if (defaultChevronState === 'open') {
checkmarkCopyContainer.classList.add('open');
}

firstRowTextParagraph.addEventListener('click', () => {
const isOpen = checkmarkCopyContainer.classList.toggle('open');
chevronIcon.innerHTML = isOpen ? chevronUpSVG : chevronDownSVG;
});
} else {
firstRowTextParagraph = createTag('div', { class: 'footer-rows-title' }, firstRowText);
checkmarkCopyContainer.classList.add('open');
}

return firstRowTextParagraph;
};

const createFooterRowCell = (row, isCheckmark) => {
const rowIcon = row.firstElementChild.querySelector('picture');
const rowText = row.querySelector('div > div:nth-child(2)').innerHTML;
const rowTextParagraph = createTag('div', { class: 'footer-row-cell-description' }, rowText);
const footerRowCellClass = isCheckmark ? 'footer-row-cell-checkmark' : 'footer-row-cell';
const footerRowIconClass = isCheckmark ? 'footer-row-icon-checkmark' : 'footer-row-icon';
const footerRowCell = createTag('li', { class: footerRowCellClass });

if (rowIcon) {
rowIcon.classList.add(footerRowIconClass);
footerRowCell.appendChild(rowIcon);
}
footerRowCell.appendChild(rowTextParagraph);

return footerRowCell;
};

const decorateFooterRows = async (merchCard, footerRows) => {
if (!footerRows) return;

const footerRowsSlot = createTag('div', { slot: 'footer-rows' });
const isCheckmark = merchCard.classList.contains('bullet-list');
const isMobile = window.matchMedia('(max-width: 767px)').matches;

const ulContainer = createTag('ul');
if (isCheckmark) {
const firstRow = footerRows[0];
const firstRowContent = firstRow.querySelector('div > div:first-child').innerHTML.split(',');
let bgStyle = '#E8E8E8';
let defaultChevronState = 'close';

firstRowContent.forEach((item) => {
const trimmedItem = item.trim();
if (trimmedItem.startsWith('#')) {
bgStyle = trimmedItem;
} else if (trimmedItem === 'open' || trimmedItem === 'close') {
defaultChevronState = trimmedItem;
}
footerRowCell.appendChild(rowTextParagraph);
footerRowsSlot.appendChild(footerRowCell);
});
merchCard.appendChild(footerRowsSlot);

const hrElem = createTag('hr', { style: `background: ${bgStyle};` });
footerRowsSlot.appendChild(hrElem);
merchCard.classList.add('has-divider');

ulContainer.classList.add('checkmark-copy-container');
const firstRowTextParagraph = await createFirstRow(
firstRow,
isMobile,
ulContainer,
defaultChevronState,
);

footerRowsSlot.appendChild(firstRowTextParagraph);

footerRows.splice(0, 1);
footerRowsSlot.style.padding = '0px var(--consonant-merch-spacing-xs)';
footerRowsSlot.style.marginBlockEnd = 'var(--consonant-merch-spacing-xs)';
}
footerRowsSlot.appendChild(ulContainer);

footerRows.forEach((row) => {
const footerRowCell = createFooterRowCell(row, isCheckmark);
ulContainer.appendChild(footerRowCell);
});

merchCard.appendChild(footerRowsSlot);
};

const setMiniCompareOfferSlot = (merchCard, offers) => {
Expand Down Expand Up @@ -624,7 +699,7 @@ export default async function init(el) {
decorateBlockHrs(merchCard);
simplifyHrs(merchCard);
if (merchCard.classList.contains('has-divider')) merchCard.setAttribute('custom-hr', true);
decorateFooterRows(merchCard, footerRows);
await decorateFooterRows(merchCard, footerRows);
} else {
parseTwpContent(el, merchCard);
}
Expand Down
4 changes: 2 additions & 2 deletions libs/deps/mas/commerce.js

Large diffs are not rendered by default.

264 changes: 185 additions & 79 deletions libs/deps/mas/mas.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion libs/deps/mas/merch-card-collection.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
var N=Object.defineProperty;var y=(s,e,t)=>e in s?N(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var E=(s,e,t)=>(y(s,typeof e!="symbol"?e+"":e,t),t);import{html as l,LitElement as O}from"../lit-all.min.js";var f=class{constructor(e,t){this.key=Symbol("match-media-key"),this.matches=!1,this.host=e,this.host.addController(this),this.media=window.matchMedia(t),this.matches=this.media.matches,this.onChange=this.onChange.bind(this),e.addController(this)}hostConnected(){var e;(e=this.media)==null||e.addEventListener("change",this.onChange)}hostDisconnected(){var e;(e=this.media)==null||e.removeEventListener("change",this.onChange)}onChange(e){this.matches!==e.matches&&(this.matches=e.matches,this.host.requestUpdate(this.key,!this.matches))}};var x="hashchange";function L(s=window.location.hash){let e=[],t=s.replace(/^#/,"").split("&");for(let o of t){let[n,i=""]=o.split("=");n&&e.push([n,decodeURIComponent(i.replace(/\+/g," "))])}return Object.fromEntries(e)}function d(s){let e=new URLSearchParams(window.location.hash.slice(1));Object.entries(s).forEach(([n,i])=>{i?e.set(n,i):e.delete(n)}),e.sort();let t=e.toString();if(t===window.location.hash)return;let o=window.scrollY||document.documentElement.scrollTop;window.location.hash=t,window.scrollTo(0,o)}function T(s){let e=()=>{if(window.location.hash&&!window.location.hash.includes("="))return;let t=L(window.location.hash);s(t)};return e(),window.addEventListener(x,e),()=>{window.removeEventListener(x,e)}}var g="merch-card-collection:sort",S="merch-card-collection:showmore";var A="(max-width: 1199px)",R="(min-width: 768px)",C="(min-width: 1200px)";import{css as M,unsafeCSS as w}from"../lit-all.min.js";var b=M`
var N=Object.defineProperty;var y=(s,e,t)=>e in s?N(s,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):s[e]=t;var E=(s,e,t)=>y(s,typeof e!="symbol"?e+"":e,t);import{html as l,LitElement as O}from"../lit-all.min.js";var f=class{constructor(e,t){this.key=Symbol("match-media-key"),this.matches=!1,this.host=e,this.host.addController(this),this.media=window.matchMedia(t),this.matches=this.media.matches,this.onChange=this.onChange.bind(this),e.addController(this)}hostConnected(){var e;(e=this.media)==null||e.addEventListener("change",this.onChange)}hostDisconnected(){var e;(e=this.media)==null||e.removeEventListener("change",this.onChange)}onChange(e){this.matches!==e.matches&&(this.matches=e.matches,this.host.requestUpdate(this.key,!this.matches))}};var x="hashchange";function L(s=window.location.hash){let e=[],t=s.replace(/^#/,"").split("&");for(let o of t){let[n,i=""]=o.split("=");n&&e.push([n,decodeURIComponent(i.replace(/\+/g," "))])}return Object.fromEntries(e)}function d(s){let e=new URLSearchParams(window.location.hash.slice(1));Object.entries(s).forEach(([n,i])=>{i?e.set(n,i):e.delete(n)}),e.sort();let t=e.toString();if(t===window.location.hash)return;let o=window.scrollY||document.documentElement.scrollTop;window.location.hash=t,window.scrollTo(0,o)}function T(s){let e=()=>{if(window.location.hash&&!window.location.hash.includes("="))return;let t=L(window.location.hash);s(t)};return e(),window.addEventListener(x,e),()=>{window.removeEventListener(x,e)}}var g="merch-card-collection:sort",S="merch-card-collection:showmore";var A="(max-width: 1199px)",R="(min-width: 768px)",C="(min-width: 1200px)";import{css as M,unsafeCSS as w}from"../lit-all.min.js";var b=M`
#header,
#resultText,
#footer {
Expand Down
Loading

0 comments on commit e4ad9d4

Please sign in to comment.