generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 177
/
Copy pathvariant-layout.js
150 lines (128 loc) · 3.85 KB
/
variant-layout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import { html } from 'lit';
export class VariantLayout {
static styleMap = {};
card;
#container;
getContainer() {
this.#container =
this.#container ??
this.card.closest('[class*="-merch-cards"]') ??
this.card.parentElement;
return this.#container;
}
insertVariantStyle() {
if (!VariantLayout.styleMap[this.card.variant]) {
VariantLayout.styleMap[this.card.variant] = true;
const styles = document.createElement('style');
styles.innerHTML = this.getGlobalCSS();
document.head.appendChild(styles);
}
}
updateCardElementMinHeight(el, name) {
if (!el) return;
const elMinHeightPropertyName = `--consonant-merch-card-${this.card.variant}-${name}-height`;
const height = Math.max(
0,
parseInt(window.getComputedStyle(el).height) || 0,
);
const maxMinHeight =
parseInt(
this.getContainer().style.getPropertyValue(
elMinHeightPropertyName,
),
) || 0;
if (height > maxMinHeight) {
this.getContainer().style.setProperty(
elMinHeightPropertyName,
`${height}px`,
);
}
}
constructor(card) {
this.card = card;
this.insertVariantStyle();
}
get badge() {
let additionalStyles;
if (
!this.card.badgeBackgroundColor ||
!this.card.badgeColor ||
!this.card.badgeText
) {
return;
}
if (this.evergreen) {
additionalStyles = `border: 1px solid ${this.card.badgeBackgroundColor}; border-right: none;`;
}
return html`
<div
id="badge"
class="${this.card.variant}-badge"
style="background-color: ${this.card.badgeBackgroundColor};
color: ${this.card.badgeColor};
${additionalStyles}"
>
${this.card.badgeText}
</div>
`;
}
get cardImage() {
return html` <div class="image">
<slot name="bg-image"></slot>
${this.badge}
</div>`;
}
/* c8 ignore next 3 */
getGlobalCSS() {
return '';
}
/* c8 ignore next 3 */
get theme() {
return document.querySelector('sp-theme');
}
get evergreen() {
return this.card.classList.contains('intro-pricing');
}
get promoBottom() {
return this.card.classList.contains('promo-bottom');
}
get headingSelector() {
return '[slot="heading-xs"]';
}
get secureLabelFooter() {
const secureLabel = this.card.secureLabel
? html`<span class="secure-transaction-label"
>${this.card.secureLabel}</span
>`
: '';
return html`<footer>${secureLabel}<slot name="footer"></slot></footer>`;
}
async adjustTitleWidth() {
const cardWidth = this.card.getBoundingClientRect().width;
const badgeWidth =
this.card.badgeElement?.getBoundingClientRect().width || 0;
if (cardWidth === 0 || badgeWidth === 0) return;
this.card.style.setProperty(
'--consonant-merch-card-heading-xs-max-width',
`${Math.round(cardWidth - badgeWidth - 16)}px`, // consonant-merch-spacing-xs
);
}
postCardUpdateHook() {
//nothing to do by default
}
connectedCallbackHook() {
//nothing to do by default
}
disconnectedCallbackHook() {
//nothing to do by default
}
/* c8 ignore next 3 */
renderLayout() {
//nothing to do by default
}
/* c8 ignore next 4 */
get aemFragmentMapping() {
//nothing to do by default
return undefined;
}
}