Skip to content

Commit eff7a67

Browse files
committed
Update promotion block to take in new semantic html structure
1 parent 869eb9a commit eff7a67

File tree

2 files changed

+92
-39
lines changed

2 files changed

+92
-39
lines changed

blocks/promotion/promotion.css

Lines changed: 72 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@
1414
height: 100%;
1515
}
1616

17-
.promotion > div:first-child {
18-
position: relative;
19-
width: 100%;
20-
}
21-
2217
.promotion picture,
2318
.promotion img {
2419
display: block;
@@ -27,30 +22,6 @@
2722
object-fit: cover;
2823
}
2924

30-
/* Content block */
31-
.promotion > div:last-child {
32-
position: relative;
33-
z-index: 1;
34-
padding: 1.5rem;
35-
color: #000;
36-
background-color: #f6f6f9;
37-
}
38-
39-
.promotion > div:last-child > div em {
40-
color: rgba(90 35 185);
41-
font-style: normal;
42-
}
43-
44-
.promotion > div:last-child > div > ul {
45-
padding-left: 1rem;
46-
margin-left: 0;
47-
}
48-
49-
.promotion > div:last-child > div > ul > li h4 {
50-
line-height: normal;
51-
margin-bottom: 0;
52-
}
53-
5425
.promotion h2,
5526
.promotion h3,
5627
.promotion h4,
@@ -84,31 +55,83 @@
8455
font-size: 16px;
8556
}
8657

87-
.promotion > div:last-child > div > p strong a {
58+
.promotion p {
59+
margin: 0;
60+
}
61+
62+
/* Images */
63+
.promotion .desktop-image {
64+
display: none;
65+
}
66+
67+
.promotion .mobile-image {
68+
display: block;
69+
position: relative;
70+
width: 100%;
71+
}
72+
73+
.promotion .mobile-image img {
74+
max-height: 300px;
75+
}
76+
77+
/* Rich text content */
78+
.promotion .rich-text-content {
79+
position: relative;
80+
z-index: 1;
81+
padding: 1.5rem 1.5rem 0 1.5rem;
82+
color: #000;
83+
background-color: #f6f6f9;
84+
}
85+
86+
.promotion .rich-text-content > div em {
87+
color: rgba(90 35 185);
88+
font-style: normal;
89+
}
90+
91+
.promotion .rich-text-content > div > ul {
92+
padding-left: 1rem;
93+
margin-left: 0;
94+
}
95+
96+
.promotion .rich-text-content > div > ul > li h4 {
97+
line-height: normal;
98+
margin-bottom: 0;
99+
}
100+
101+
.promotion .rich-text-content strong a {
102+
display: inline-block;
88103
color: #fff;
89104
background-color: #000;
90105
border-radius: 4px;
91106
padding: 14px 28px;
92107
margin-right: 1rem;
93108
}
94109

95-
.promotion > div:last-child > div > p:last-of-type {
110+
/* Legal Copy Text */
111+
.promotion .legal-copy-text {
96112
font-size: 12px;
97-
margin-top: 2rem;
113+
padding-top: 2rem;
114+
color: #000;
115+
background-color: #f6f6f9;
116+
padding: 1.5rem;
98117
}
99118

100119
@media (width >= 900px) {
101120
.promotion {
102121
display: block;
103122
}
104123

105-
/* make image fill the container */
106-
.promotion > div:first-child {
124+
.promotion .desktop-image {
125+
display: block;
107126
position: absolute;
108127
inset: 0;
109128
z-index: 0;
110129
}
111130

131+
.promotion .mobile-image {
132+
display: none;
133+
}
134+
112135
.promotion picture,
113136
.promotion img {
114137
width: 100%;
@@ -121,23 +144,34 @@
121144
}
122145

123146
/* overlay content */
124-
.promotion > div:last-child {
147+
.promotion .rich-text-content{
125148
position: relative;
126149
z-index: 1;
127150
color: #fff;
128151
max-width: 600px;
129-
padding: 4rem;
152+
padding: 4rem 4rem 0 4rem;
130153
margin: 0;
131154
box-sizing: border-box;
132155
background-color: transparent;
133156
}
134157

135-
.promotion > div:last-child > div em {
158+
.promotion .rich-text-content > div em {
136159
color: rgba(189 167 227);
137160
}
138161

139-
.promotion > div:last-child > div > p strong a {
162+
.promotion .rich-text-content p strong a {
140163
color: #000;
141164
background-color: rgba(246 246 249);
142165
}
166+
167+
.promotion .legal-copy-text {
168+
position: relative;
169+
z-index: 1;
170+
color: #fff;
171+
padding: 0 4rem 4rem 4rem;
172+
max-width: 600px;
173+
box-sizing: border-box;
174+
background-color: transparent;
175+
margin-top: 1.5rem;
176+
}
143177
}

blocks/promotion/promotion.js

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,24 @@
11
import { createOptimizedPicture } from '../../scripts/aem.js';
22

33
export default function decorate(block) {
4-
block.querySelectorAll('picture > img').forEach((img) => img.closest('picture').replaceWith(createOptimizedPicture(img.src, img.alt, false, [{ width: '1440' }])));
4+
const elements = [...block.children];
5+
6+
const roleMap = {
7+
0: 'desktop-image',
8+
1: 'mobile-image',
9+
2: 'rich-text-content',
10+
3: 'legal-copy-text',
11+
};
12+
13+
elements.forEach((child, index) => {
14+
// Assign role (desktop/mobile) based on order
15+
const role = roleMap[index];
16+
if (role) child.classList.add(role);
17+
18+
// Process images for optimization
19+
const img = child.querySelector('picture > img');
20+
if (!img) return;
21+
const optimizedPicture = createOptimizedPicture(img.src, img.alt, false, [{ width: '1440' }]);
22+
img.closest('picture').replaceWith(optimizedPicture);
23+
});
524
}

0 commit comments

Comments
 (0)