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

Media with content block #140 #210

Merged
merged 5 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
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
116 changes: 116 additions & 0 deletions blocks/v2-media-with-content/v2-media-with-content.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
.section.v2-media-with-content-container {
padding: 0 0 64px;
}

.redesign-v2 .section .v2-media-with-content-wrapper {
padding: 0;
}

.v2-media-with-content__content-wrapper {
display: flex;
}

.v2-media-with-content__content-wrapper.image-left {
SantiagoHomps-NC marked this conversation as resolved.
Show resolved Hide resolved
flex-direction: column;
}

.v2-media-with-content__content-wrapper.image-right {
SantiagoHomps-NC marked this conversation as resolved.
Show resolved Hide resolved
flex-direction: column-reverse;
}

.v2-media-with-content__column.column-with-text {
padding: 24px 16px 0;
}

.v2-media-with-content__column img {
display: block;
width: 100vw;
cogniSyb marked this conversation as resolved.
Show resolved Hide resolved
}

.v2-media-with-content__title {
font-family: var(--ff-headline-medium);
font-size: var(--heading-font-size-s);
margin: 0;
}

.v2-media-with-content__text {
font-size: var(--body-font-size-s);
margin: 24px 0 0;
}

.v2-media-with-content__icon-list {
display: flex;
flex-direction: row;
justify-content: center;
column-gap: 23px;
SantiagoHomps-NC marked this conversation as resolved.
Show resolved Hide resolved
}

li.v2-media-with-content__list-item {
width: 50%;
margin: 24px 0 0;
}

.v2-media-with-content__list-item figure {
display: flex;
flex-direction: column;
align-items: center;
margin: 0;
}

.v2-media-with-content__list-item img {
height: 110px;
width: auto;
margin: 0 0 12px;
}

.v2-media-with-content__list-item figcaption {
text-align: center;
font-size: var(--body-font-size-xxs);
font-family: var(--ff-body-bold);
max-width: 150px;
}

@media (min-width: 1200px) {
.section.v2-media-with-content-container {
padding: 80px 0;
}

.redesign-v2 .section .v2-media-with-content-wrapper {
max-width: unset;
}

.v2-media-with-content__content-wrapper.image-right,
.v2-media-with-content__content-wrapper.image-left {
SantiagoHomps-NC marked this conversation as resolved.
Show resolved Hide resolved
flex-direction: row;
}

.v2-media-with-content__content-wrapper.image-left {
justify-content: flex-end;
}

.v2-media-with-content__content-wrapper {
position: relative;
}

.v2-media-with-content__column.column-with-text {
display: flex;
flex-direction: column;
justify-content: center;
width: calc(45% + 90px);
}

.v2-media-with-content__content-wrapper.image-right .v2-media-with-content__column.column-with-text {
margin-left: calc(calc(100vw - var(--wrapper-width)) / 2);
padding: 54px 90px 54px 0;
}

.v2-media-with-content__content-wrapper.image-left .v2-media-with-content__column.column-with-text {
margin-right: calc(calc(100vw - var(--wrapper-width)) / 2);
padding: 54px 0 54px 90px;
}

.v2-media-with-content--with-icons .v2-media-with-content__content-wrapper.image-right .v2-media-with-content__column.column-with-text {
padding-top: 0;
padding-bottom: 0;
}
}
52 changes: 52 additions & 0 deletions blocks/v2-media-with-content/v2-media-with-content.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import { variantsClassesToBEM, createElement, unwrapDivs } from '../../scripts/common.js';

export default async function decorate(block) {
const blockName = 'v2-media-with-content';
const variantClasses = ['with-icons'];
variantsClassesToBEM(block.classList, variantClasses, blockName);

const contentWrapper = block.querySelector(':scope > div');
contentWrapper.classList.add(`${blockName}__content-wrapper`);

const content = [...block.querySelectorAll(':scope > div > div')];
content.forEach((col) => {
col.classList.add(`${blockName}__column`);
if (col.firstElementChild.tagName === 'PICTURE') {
col.classList.add('column-with-image');
} else {
col.classList.add('column-with-text');
}
});

const hasImageLeft = (content[0].firstElementChild.tagName === 'PICTURE');
SantiagoHomps-NC marked this conversation as resolved.
Show resolved Hide resolved
if (hasImageLeft) {
contentWrapper.classList.add('image-left');
} else {
contentWrapper.classList.add('image-right');
SantiagoHomps-NC marked this conversation as resolved.
Show resolved Hide resolved
}

const header = [...block.querySelectorAll('h1, h2, h3, h4, h5, h6')];
header.forEach((h) => { h.classList.add(`${blockName}__title`); });

const text = [...block.querySelectorAll('p')];
text.forEach((t) => { t.classList.add(`${blockName}__text`); });

if (block.classList.contains(`${blockName}--with-icons`)) {
const iconList = block.querySelector('ul');
iconList.classList.add(`${blockName}__icon-list`);

const items = iconList.querySelectorAll('li');
items.forEach((item) => {
item.classList.add(`${blockName}__list-item`);
const figure = createElement('figure');
const image = item.querySelector('picture');
const pElmt = createElement('figcaption');
const liText = item.innerText.trim();
pElmt.textContent = liText;
figure.append(image, pElmt);
item.textContent = '';
item.append(figure);
});
}
unwrapDivs(block);
}
Loading