-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from Netcentric/24-images-grid
Images grid block
- Loading branch information
Showing
4 changed files
with
137 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
:root { | ||
--v2-images-grid-gutter: 8px; | ||
--v2-images-grid-padding-space: 24px; | ||
} | ||
|
||
.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__picture { | ||
display: block; | ||
position: relative; | ||
height: 100%; | ||
} | ||
|
||
.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 { | ||
object-fit: cover; | ||
width: 100%; | ||
display: block; | ||
height: 100%; | ||
} | ||
|
||
.v2-images-grid__item:nth-child(1) img, | ||
.v2-images-grid__item:nth-child(4) img { | ||
aspect-ratio: 1/1; | ||
} | ||
|
||
.v2-images-grid__item:nth-child(2) img, | ||
.v2-images-grid__item:nth-child(3) img { | ||
aspect-ratio: 4/3; | ||
} | ||
|
||
.v2-images-grid__figcaption { | ||
display: none; | ||
} | ||
|
||
@media screen and (min-width: 1200px) { | ||
:root { | ||
--v2-images-grid-gutter: 16px; | ||
--v2-images-grid-padding-space: 40px; | ||
} | ||
|
||
.v2-images-grid__figcaption { | ||
display: block; | ||
text-align: center; | ||
position: absolute; | ||
bottom: 10px; | ||
padding: 9px 9px 7px; | ||
color: var(--c-primary-white); | ||
background-color: var(--c-secondary-graphite); | ||
right: 10px; | ||
text-transform: uppercase; | ||
font: 12px/16px var(--ff-body-bold); | ||
letter-spacing: 1.92px; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import { createOptimizedPicture } from '../../scripts/lib-franklin.js'; | ||
import { createElement, removeEmptyTags, getTextLabel } from '../../scripts/common.js'; | ||
import { getAllElWithChildren } from '../../scripts/scripts.js'; | ||
|
||
const blockClassName = 'v2-images-grid'; | ||
export default function decorate(block) { | ||
// 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.append(ul); | ||
|
||
// give format to the first 4 list items | ||
[...ul.children].forEach((li, idx) => { | ||
if (idx < 4) { | ||
const captionEle = getAllElWithChildren(li.querySelectorAll('p'), 'picture', true)[0]; | ||
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); | ||
} | ||
|
||
li.innerHTML = ''; | ||
|
||
li.append(picture); | ||
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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters