Skip to content

Commit d36c19e

Browse files
authored
Merge pull request #15 from aemsites/action
feat: action columns variant
2 parents 0dc2d1d + bf3bc13 commit d36c19e

4 files changed

Lines changed: 93 additions & 4 deletions

File tree

blocks/columns/columns.css

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,36 @@
106106
}
107107
}
108108

109+
/* action variant */
110+
.columns.action .action-wrapper .button {
111+
width: 100%;
112+
}
113+
114+
.columns.action .body-wrapper h1::after,
115+
.columns.action .body-wrapper h2::after,
116+
.columns.action .body-wrapper h3::after,
117+
.columns.action .body-wrapper h4::after,
118+
.columns.action .body-wrapper h5::after,
119+
.columns.action .body-wrapper h6::after {
120+
content: none;
121+
}
122+
123+
@media (width >= 600px) {
124+
.columns.action > div {
125+
display: flex;
126+
}
127+
128+
.columns.action .action-wrapper {
129+
flex: 0 0 max-content;
130+
align-self: self-end;
131+
}
132+
133+
.columns.action .action-wrapper .button {
134+
width: unset;
135+
min-width: 200px;
136+
}
137+
}
138+
109139
/* portrait variant */
110140
.columns.portrait .media-wrapper {
111141
min-height: unset;

blocks/columns/columns.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,29 @@ function optimizeImages(block) {
2424
});
2525
}
2626

27+
/**
28+
* Marks body-only blocks whose last column is links-only with `action` and `action-wrapper`.
29+
* @param {Element} block The columns block element
30+
*/
31+
function detectAction(block) {
32+
const rows = [...block.children];
33+
if (!rows.length) return;
34+
const matches = rows.every((row) => {
35+
const cols = [...row.children];
36+
if (cols.some((col) => col.classList.contains('media-wrapper'))) return false;
37+
const last = cols[cols.length - 1];
38+
return [...last.children].every(
39+
(el) => el.tagName === 'P' && el.children.length === 1 && el.firstElementChild.tagName === 'A',
40+
);
41+
});
42+
if (!matches) return;
43+
block.classList.add('action');
44+
rows.forEach((row) => {
45+
const last = row.children[row.children.length - 1];
46+
last.classList.replace('body-wrapper', 'action-wrapper');
47+
});
48+
}
49+
2750
/** @param {Element} block */
2851
export default function decorate(block) {
2952
[...block.children].forEach((row) => {
@@ -35,6 +58,8 @@ export default function decorate(block) {
3558
if (row.querySelector('.media-wrapper')) row.dataset.row = 'media';
3659
});
3760

61+
detectAction(block);
62+
3863
const colCount = getColCount(block);
3964
if (colCount && ![...block.classList].some((c) => c.startsWith('cols-'))) {
4065
block.classList.add(`cols-${colCount}`);

styles/styles.css

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,6 +531,38 @@ main > .section.dark:has(+ .section.dark) {
531531
margin-bottom: 0;
532532
}
533533

534+
main .section.dark a.button.primary,
535+
main .section.dark button.button.primary {
536+
border-color: var(--color-bg);
537+
background-color: var(--color-bg);
538+
color: var(--color-text);
539+
}
540+
541+
main .section.dark a.button.primary:hover,
542+
main .section.dark a.button.primary:focus-visible,
543+
main .section.dark button.button.primary:hover,
544+
main .section.dark button.button.primary:focus-visible {
545+
border-color: var(--color-bg-light);
546+
background-color: var(--color-bg-light);
547+
color: var(--color-muted);
548+
}
549+
550+
main .section.dark a.button.secondary,
551+
main .section.dark button.button.secondary {
552+
border-color: var(--color-bg);
553+
background-color: transparent;
554+
color: var(--color-bg);
555+
}
556+
557+
main .section.dark a.button.secondary:hover,
558+
main .section.dark a.button.secondary:focus-visible,
559+
main .section.dark button.button.secondary:hover,
560+
main .section.dark button.button.secondary:focus-visible {
561+
border-color: var(--color-bg-light);
562+
background-color: transparent;
563+
color: var(--color-bg-light);
564+
}
565+
534566
@media (width >= 900px) {
535567
main .section.light,
536568
main .section.dark {

tools/import/transform-page.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ function carouselBlock($car) {
341341
return `<div class="carousel">${rows.join("")}</div>`;
342342
}
343343

344-
// teaser--banner -> default content (heading/text/CTA) for a dedicated dark section
344+
// teaser--banner -> columns block (heading+text | CTA) for a dedicated dark section
345345
function bannerSectionContent($t) {
346346
const h = $t.find(".teaserHeading").first().text().trim();
347347
const seen = new Set();
@@ -351,9 +351,11 @@ function bannerSectionContent($t) {
351351
if (t && !/^\d{4}-\d{2}-\d{2}$/.test(t) && !seen.has(t)) { seen.add(t); ps.push(t); }
352352
});
353353
const cta = teaserCTA($t);
354-
const parts = [`<h2>${h}</h2>`, ...ps.map((p) => `<p>${p}</p>`)];
355-
if (cta && cta.text) parts.push(`<p><a href="${cta.href}">${cta.text}</a></p>`);
356-
return parts.join("");
354+
const textCol = [`<h2>${h}</h2>`, ...ps.map((p) => `<p>${p}</p>`)].join("");
355+
if (cta && cta.text) {
356+
return `<div class="columns"><div><div>${textCol}</div><div><p><a href="${cta.href}">${cta.text}</a></p></div></div></div>`;
357+
}
358+
return textCol;
357359
}
358360

359361
// multimedia / media-youtube slider -> default content:

0 commit comments

Comments
 (0)