Skip to content

Commit

Permalink
Mwpw-142267: Merch What's Included and Merch Mnemonic List (TwP) (#2554)
Browse files Browse the repository at this point in the history
* MWPW-142267: What's Included screen (TwP)

* Update merch-whats-included.css

* Update merch-whats-included.css

* Update merch-whats-included.css

* updated libs from main

* Update merch-whats-included.js

* updated deps

* address review comments. 'HEAD' branch instead of main because I had to reset to Axels commit to avoid 'callout' change

* Update merch-whats-included.css

* Update merch-whats-included.css

* Update merch-whats-included.css

* Update merch-whats-included.css

* Update merch-whats-included.css

* style fixes

* updated deps

* h3 styles

* responsive width

* Update merch-whats-included.css

* removed event listener

* unit tests

---------

Co-authored-by: Mariia Lukianets <mariia.lukianets@gmail.com>
  • Loading branch information
Axelcureno and 3ch023 authored Jul 16, 2024
1 parent f160c4d commit d932b35
Show file tree
Hide file tree
Showing 11 changed files with 355 additions and 70 deletions.
5 changes: 5 additions & 0 deletions libs/blocks/merch-card/merch-card.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@ const parseTwpContent = async (el, merchCard) => {
const content = group.filter((e) => e.tagName.toLowerCase() === 'p' || e.tagName.toLowerCase() === 'ul');
const bodySlot = createTag('div', { slot: 'body-xs' }, content);
merchCard.append(bodySlot);

const whatsIncludedLink = bodySlot.querySelector('a[href*="merch-whats-included"]');
if (whatsIncludedLink) {
whatsIncludedLink.classList.add('merch-whats-included');
}
} else if (index === 2) { // Footer section
const footerContent = group.filter((e) => ['h5', 'p'].includes(e.tagName.toLowerCase()));
const footer = createTag('div', { slot: 'footer' }, footerContent);
Expand Down
6 changes: 6 additions & 0 deletions libs/blocks/merch-mnemonic-list/merch-mnemonic-list.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.merch-mnemonic-list {
display: flex;
height: 380px;
flex-flow: column;
flex-wrap: wrap;
}
21 changes: 21 additions & 0 deletions libs/blocks/merch-mnemonic-list/merch-mnemonic-list.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import '../../deps/merch-mnemonic-list.js';
import '../../deps/merch-card.js';
import { createTag } from '../../utils/utils.js';

const init = async (el) => {
const rows = el.querySelectorAll(':scope p:not([class])');
if (rows.length < 1) return;
[...rows].forEach((paragraph) => {
const merchMnemonicList = createTag('merch-mnemonic-list');
paragraph.setAttribute('slot', 'description');
const picture = paragraph.querySelector('picture');
const img = picture.querySelector('img');
const icon = createTag('merch-icon', { slot: 'icon', size: 's', src: img.src });
picture.remove();
if (icon) merchMnemonicList.appendChild(icon);
if (paragraph) merchMnemonicList.appendChild(paragraph);
el.appendChild(merchMnemonicList);
});
};

export default init;
13 changes: 13 additions & 0 deletions libs/blocks/merch-twp/merch-twp.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,19 @@ export default async function init(el) {
content.querySelector('h4').setAttribute('slot', 'detail-xl');
twp.append(...[...content.querySelectorAll(':scope > h4, merch-card')]);

const whatsIncludedFragment = el.querySelector('.fragment[data-path*="merch-whats-included"]');
if (whatsIncludedFragment) {
const whatsIncludedSlot = createTag(
'div',
{
slot: 'merch-whats-included',
class: 'hidden merch-whats-included-container',
},
whatsIncludedFragment,
);
twp.append(whatsIncludedSlot);
}

const cciFooter = createTag('div', { slot: 'cci-footer' });
cciFooter.append(...[...content.querySelectorAll('p:not(hr ~ p)')]);
const cctFooter = createTag('div', { slot: 'cct-footer' });
Expand Down
37 changes: 37 additions & 0 deletions libs/blocks/merch-whats-included/merch-whats-included.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
.merch-whats-included-container > .fragment {
width: inherit;
height: inherit;
max-height: 100%;
display: block;
}

.merch-whats-included-container .content h3 {
margin: 0;
}

.merch-whats-included-container .fragment .container {
display: contents;
}

.merch-whats-included-container .fragment .content {
float: right;
}

.merch-whats-included-container .fragment .content a[is="checkout-link"] {
margin-inline-start: var(--spacing-xxs);
}

@media screen and (max-width: 767px) {
.merch-whats-included-container {
position: fixed;
overflow: hidden scroll;
}

.merch-mnemonic-list {
height: auto;
}

.merch-whats-included-container .fragment .container {
grid-auto-flow: row;
}
}
30 changes: 30 additions & 0 deletions libs/blocks/merch-whats-included/merch-whats-included.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import '../../deps/merch-whats-included.js';
import { createTag } from '../../utils/utils.js';

const init = async (el) => {
const styles = Array.from(el.classList);
const mobileRows = styles.find((style) => /\d/.test(style));
const heading = el.querySelector('h3, h4');
const content = el.querySelector('.section');

const contentSlot = createTag(
'div',
{ slot: 'content' },
content.innerHTML,
);
const whatsIncluded = createTag(
'merch-whats-included',
{ mobileRows: mobileRows || 1 },
);
if (heading) {
heading.setAttribute('slot', 'heading');
whatsIncluded.appendChild(heading);
}

whatsIncluded.appendChild(contentSlot);
const divsWithoutClass = contentSlot.querySelectorAll('div:not([class])');
divsWithoutClass.forEach((div) => div.remove());
el.replaceWith(whatsIncluded);
};

export default init;
Loading

0 comments on commit d932b35

Please sign in to comment.