Skip to content

Commit d07d7d8

Browse files
authored
Merge pull request #6 from AdobeDevXSC/wip
Update columns block
2 parents 9de7ea5 + adb3ce3 commit d07d7d8

File tree

2 files changed

+56
-8
lines changed

2 files changed

+56
-8
lines changed

blocks/columns/columns.css

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
width: 100%;
88
}
99

10+
.columns p {
11+
margin: 0;
12+
}
13+
1014
.columns > div > div {
1115
order: 1;
1216
}
@@ -27,11 +31,27 @@
2731
.columns > div {
2832
align-items: center;
2933
flex-direction: unset;
30-
gap: 24px;
34+
/* gap: 24px; */
3135
}
3236

3337
.columns > div > div {
3438
flex: 1;
3539
order: unset;
3640
}
3741
}
42+
43+
/* multi col */
44+
.columns > div > .columns-multi-col {
45+
position: relative;
46+
padding: 0 !important;
47+
}
48+
49+
.columns > div > .columns-multi-col > .content-wrapper {
50+
position: absolute;
51+
bottom: 0;
52+
padding: 4rem;
53+
}
54+
55+
.columns > div > .columns-multi-col img {
56+
object-fit: contain;
57+
}

blocks/columns/columns.js

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,44 @@ export default function decorate(block) {
22
const cols = [...block.firstElementChild.children];
33
block.classList.add(`columns-${cols.length}-cols`);
44

5-
// setup image columns
65
[...block.children].forEach((row) => {
76
[...row.children].forEach((col) => {
8-
const pic = col.querySelector('picture');
9-
if (pic) {
10-
const picWrapper = pic.closest('div');
11-
if (picWrapper && picWrapper.children.length === 1) {
12-
// picture is only content in column
13-
picWrapper.classList.add('columns-img-col');
7+
let isMultiCol = false;
8+
const children = [...col.children];
9+
10+
children.forEach((child) => {
11+
const hasImg = child.querySelector('img');
12+
// Clean slate (optional but recommended)
13+
col.classList.remove(
14+
'columns-img-col',
15+
'columns-reg-col',
16+
'columns-multi-col',
17+
);
18+
19+
if (hasImg && children.length > 1) {
20+
col.classList.add('columns-multi-col');
21+
isMultiCol = true;
22+
} else if (hasImg) {
23+
col.classList.add('columns-img-col');
24+
} else {
25+
col.classList.add('columns-reg-col');
1426
}
27+
});
28+
29+
if (isMultiCol) {
30+
col.classList.remove('columns-img-col', 'columns-reg-col');
31+
col.classList.add('columns-multi-col');
32+
33+
const div = document.createElement('div');
34+
div.className = 'content-wrapper';
35+
36+
children.forEach((child) => {
37+
// console.log("child: ", child);
38+
if (!child.querySelector('img')) {
39+
div.appendChild(child);
40+
}
41+
});
42+
col.appendChild(div);
1543
}
1644
});
1745
});

0 commit comments

Comments
 (0)