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

Images grid block #68

Merged
merged 8 commits into from
Sep 6, 2023
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
95 changes: 95 additions & 0 deletions blocks/v2-images-grid/v2-images-grid.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
:root {
--v2-images-grid-gutter: 8px;
--v2-images-grid-big-height: 168px;
--v2-images-grid-small-height: 125px;
--v2-images-grid-padding-space: 24px;
}

cogniSyb marked this conversation as resolved.
Show resolved Hide resolved
.redesign-v2 .v2-images-grid-container .v2-images-grid-wrapper {
padding: 0 100px;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We need to remove the padding: 0 200px from styles and use max-width: var(--wrapper-width) instead. So all the blocks follow the same size.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed that

}

.v2-images-grid-container .with-marker::before {
TomaszDziezykNetcentric marked this conversation as resolved.
Show resolved Hide resolved
width: 37px;
}

.v2-images-grid-title {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use BEM for the classnames? 🙏🏻

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the title should be part of the image grid or text block, but in case it is, the designs are using H2 font, not h1.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we use BEM for the classnames? 🙏🏻

Done

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not sure if the title should be part of the image grid or text block, but in case it is, the designs are using H2 font, not h1.

I have removed it as Tomas mentioned it's part cards block

font: var(--headline-1-font-size)/var(--headline-1-line-height) var(--ff-headline-medium);
}

.v2-images-grid-items {
padding-left: 0;
display: grid;
grid-template-columns: 50%;
gap: var(--v2-images-grid-gutter);
grid-template-areas:
'area1 area2'
'area1 area4'
'area3 area4';
list-style: none;
margin-bottom: var(--v2-images-grid-padding-space);
}

.v2-images-grid-item {
margin: 0;
width: auto;
}

.v2-images-grid-item:nth-child(1) { grid-area: area1; }
.v2-images-grid-item:nth-child(2) { grid-area: area2; }
.v2-images-grid-item:nth-child(3) { grid-area: area3; }
.v2-images-grid-item:nth-child(4) { grid-area: area4; }

.v2-images-grid-item img {
height: var(--v2-images-grid-big-height);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Set the height to 100%

object-fit: cover;
width: 100%;
cogniSyb marked this conversation as resolved.
Show resolved Hide resolved
}

.v2-images-grid-item:nth-child(2) img, .v2-images-grid-item:nth-child(3) img {
height: var(--v2-images-grid-small-height);
}

.v2-images-grid-picture {
display: block;
position: relative;
}

.v2-images-grid-figcaption {
display: none;
}

@media screen and (min-width: 700px) {
TomaszDziezykNetcentric marked this conversation as resolved.
Show resolved Hide resolved
:root {
--v2-images-grid-big-height: 300px;
--v2-images-grid-small-height: 200px;
}
}

@media screen and (min-width: 1200px) {
:root {
cogniSyb marked this conversation as resolved.
Show resolved Hide resolved
--v2-images-grid-gutter: 16px;
--v2-images-grid-big-height: 511px;
--v2-images-grid-small-height: 383px;
--v2-images-grid-max-width: 1040px;
--v2-images-grid-padding-space: 40px;
}

.v2-images-grid-item img {
vertical-align: top;
}

.v2-images-grid-figcaption {
display: block;
text-align: center;
position: absolute;
bottom: 10px;
padding: 9px;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be padding: 9px 9px 7px;

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did see that in figma, but rounded to 9px on all sides

color: var(--c-primary-white);
background-color: var(--c-secondary-graphite);
right: 10px;
text-transform: uppercase;
font: var(--body-2-font-size)/16px var(--ff-body);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Outcome should be font-size: 12px with var(--ff-body-bold) to achieve bold text

letter-spacing: 1.92px;
}
}
65 changes: 65 additions & 0 deletions blocks/v2-images-grid/v2-images-grid.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
import { createOptimizedPicture } from '../../scripts/lib-franklin.js';
import { createElement, removeEmptyTags, getTextLabel } from '../../scripts/common.js';

const blockClassName = 'v2-images-grid';
export default function decorate(block) {
const headings = [...block.querySelectorAll('h1, h2, h3, h4, h5, h6')];
headings.forEach((heading) => {
TomaszDziezykNetcentric marked this conversation as resolved.
Show resolved Hide resolved
heading.classList.add(`${blockClassName}-title`, 'with-marker');
heading.parentElement.parentElement.remove();
});
// all items are inside a ul list with classname called 'v2-images-grid-items'
const ul = createElement('ul', { classes: `${blockClassName}-items` });
[...block.querySelectorAll(':scope > div > div')].forEach((cell) => {
// If cell contain any element, we add them in the ul
if (cell.childElementCount) {
const li = createElement('li', { classes: [`${blockClassName}-item`] });
li.append(...cell.childNodes);
ul.append(li);
}
cell.remove();
});
block.parentElement.prepend(...headings);
block.append(ul);

// give format to the first 4 list items
[...ul.children].forEach((li, idx) => {
if (idx < 4) {
const section = createElement('div');
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get rid of this <div> that seemingly does nothing?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const captionEle = li.querySelector('p:not(:has(*))');
TomaszDziezykNetcentric marked this conversation as resolved.
Show resolved Hide resolved
let picture = li.querySelector('picture');

if (picture) {
const img = picture.lastElementChild;
// no width provided because we are using object-fit, we need the biggest option
const newPicture = createOptimizedPicture(img.src, captionEle.textContent, false);
picture.replaceWith(newPicture);
picture = newPicture;
picture.classList.add(`${blockClassName}-picture`);
// use figcaption for text
const figCaption = createElement('figcaption', { classes: `${blockClassName}-figcaption` });
figCaption.textContent = captionEle.textContent;
picture.append(figCaption);
}

// Move image outside of the wrapper
section.prepend(picture);

// Remove caption element
captionEle.remove();

li.append(section);
return;
}
li.remove();
});

const button = createElement('a', {
classes: ['button', 'button--large', 'button--primary'],
});
button.textContent = getTextLabel('Open Gallery');
block.append(button);

// remove empty tags
removeEmptyTags(block);
}
8 changes: 6 additions & 2 deletions placeholder.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"total": 21,
"total": 22,
"offset": 0,
"limit": 21,
"limit": 22,
"data": [
{
"Key": "Low resolution video message",
Expand Down Expand Up @@ -86,6 +86,10 @@
{
"Key": "channel aria label",
"Text": "channel"
},
{
"Key": "Open Gallery",
"Text": "Open Gallery"
}
],
":type": "sheet"
Expand Down