Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[MWPW-158015] [Mini Compare Merch Card] Redesign mini compare card for testing #3147

Open
wants to merge 35 commits into
base: stage
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 9 commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
6c6d3c9
Redesign mini-compare chart. Added checkmarks for icons. Backward com…
Nov 5, 2024
4c51f63
implemented cheveron up and down functionality for checkmark copy list
Nov 5, 2024
8a6c32e
added isMobile check
Nov 6, 2024
d725219
Fix backward compatibility issues
Nov 6, 2024
f0a65a6
minor
Nov 6, 2024
62e2ec2
minor css fixes as per figma
Nov 6, 2024
37b70b4
refactored large "decorateFooterRows" method
Nov 6, 2024
8dfa0e9
remove duplicate css
Nov 7, 2024
daadcbb
review comments
Nov 8, 2024
eb4ba26
UT added
Nov 11, 2024
5105249
Merge branch 'stage' into MWPW-158015
Nov 11, 2024
8e8ce9c
fix post merge conflict
Nov 11, 2024
7587c16
npm run build
Nov 11, 2024
28fbaea
linter
Nov 11, 2024
19f887a
UT coverage
Nov 13, 2024
5254abf
mini compare covergae
Nov 13, 2024
4407f37
review comment
Nov 13, 2024
08f60ba
fix post merge. margin was affected due to ul change
Nov 13, 2024
02e75a4
fixed ul after merge conflict with the other fix PR
Nov 14, 2024
b465d1c
Merge branch 'stage' into MWPW-158015
Nov 14, 2024
83b3004
linter
Nov 14, 2024
9bc6065
Merge branch 'stage' into MWPW-158015
Nov 27, 2024
dc5ee8e
Merge branch 'stage' into MWPW-158015
mirafedas Dec 11, 2024
11ee7bd
resolved conflicts
mirafedas Dec 11, 2024
ef3f6cd
fixed mini-compare-chart footer cta alignment
mirafedas Dec 11, 2024
4472303
decreased footer rows height to match the design
mirafedas Dec 11, 2024
5a56237
fixed mini-compare footer alignment
mirafedas Dec 13, 2024
16dee1a
fixed footer horizontal padding and mobile breakpoint
mirafedas Dec 16, 2024
f02ae16
updated unit tests
mirafedas Dec 16, 2024
882af05
corrected paddings, font sizes and other
mirafedas Dec 18, 2024
6c7342b
corrected slots
mirafedas Dec 18, 2024
4deca34
corrected padding
mirafedas Dec 18, 2024
e679d79
footer padding corrected
mirafedas Dec 18, 2024
385903e
Merge branch 'stage' into MWPW-158015
mirafedas Dec 20, 2024
4883637
corrected heading-m-price padding
mirafedas Dec 20, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.

108 changes: 93 additions & 15 deletions libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -387,23 +387,101 @@ 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('div', { 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', () => {
rohitsahu marked this conversation as resolved.
Show resolved Hide resolved
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('div', { 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('feature-list-item');
const isMobile = window.matchMedia('(max-width: 1199px)').matches;

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');

const checkmarkCopyContainer = createTag('div', { class: 'checkmark-copy-container' });
const firstRowTextParagraph = await createFirstRow(
firstRow,
isMobile,
checkmarkCopyContainer,
defaultChevronState
);

footerRowsSlot.appendChild(firstRowTextParagraph);
footerRowsSlot.appendChild(checkmarkCopyContainer);

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

footerRows.forEach((row) => {
const footerRowCell = createFooterRowCell(row, isCheckmark);
if (isCheckmark) {
footerRowsSlot.querySelector('.checkmark-copy-container').appendChild(footerRowCell);
} else {
footerRowsSlot.appendChild(footerRowCell);
}
});

merchCard.appendChild(footerRowsSlot);
};

const setMiniCompareOfferSlot = (merchCard, offers) => {
Expand Down Expand Up @@ -620,7 +698,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
143 changes: 97 additions & 46 deletions libs/deps/mas/mas.js

Large diffs are not rendered by default.

Loading