generated from adobe/aem-boilerplate
-
Notifications
You must be signed in to change notification settings - Fork 176
/
Copy pathccd-suggested.js
190 lines (164 loc) · 5.9 KB
/
ccd-suggested.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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
import { html, css } from 'lit';
import { VariantLayout } from './variant-layout.js';
import { CSS } from './ccd-suggested.css.js';
const AEM_FRAGMENT_MAPPING = {
mnemonics: { size: 'l' },
subtitle: { tag: 'h4', slot: 'detail-s' },
backgroundImage: { attribute: 'background-image' },
title: { tag: 'h3', slot: 'heading-xs' },
prices: { tag: 'p', slot: 'price' },
description: { tag: 'div', slot: 'body-xs' },
ctas: { slot: 'cta', size: 'M' },
};
export class CCDSuggested extends VariantLayout {
getGlobalCSS() {
return CSS;
}
/* c8 ignore next 3 */
get aemFragmentMapping() {
return AEM_FRAGMENT_MAPPING;
}
get stripStyle() {
if (!this.card.backgroundImage) return '';
return `
background: url("${this.card.backgroundImage}");
background-size: auto 100%;
background-repeat: no-repeat;
background-position: ${this.card.dir === 'ltr' ? 'left' : 'right'};
`;
}
renderLayout() {
return html` <div style="${this.stripStyle}" class="body">
<div class="header">
<div class="top-section">
<slot name="icons"></slot>
${this.badge}
</div>
<div class="headings">
<slot name="detail-s"></slot>
<slot name="heading-xs"></slot>
</div>
</div>
<slot name="body-xs"></slot>
<div class="footer">
<slot name="price"></slot>
<slot name="cta"></slot>
</div>
</div>
<slot></slot>`;
}
postCardUpdateHook(changedProperties) {
if (changedProperties.has('backgroundImage'))
this.styleBackgroundImage();
}
styleBackgroundImage() {
this.card.classList.remove('thin-strip');
this.card.classList.remove('wide-strip');
if (!this.card.backgroundImage) {
// c8 ignore next 2 */
return;
}
const img = new Image();
img.src = this.card.backgroundImage;
img.onload = () => {
if (img.width > 8) {
/* c8 ignore next 4 */
this.card.classList.add('wide-strip');
} else if (img.width === 8) {
this.card.classList.add('thin-strip');
}
};
}
static variantStyle = css`
:host([variant='ccd-suggested']) {
--consonant-merch-card-background-color: rgb(245, 245, 245);
--consonant-merch-card-body-xs-color: rgb(75, 75, 75);
--consonant-merch-card-border-color: rgb(225, 225, 225);
--consonant-merch-card-detail-s-color: rgb(110, 110, 110);
--consonant-merch-card-heading-xs-color: rgb(44, 44, 44);
--merch-color-inline-price-strikethrough: var(--spectrum-gray-600);
--mod-img-height: 38px;
box-sizing: border-box;
width: 100%;
max-width: 305px;
min-width: 270px;
min-height: 205px;
border-radius: 4px;
display: flex;
flex-flow: wrap;
overflow: hidden;
}
:host([variant='ccd-slice']) * {
overflow: hidden;
}
:host([variant='ccd-suggested']:hover) {
--consonant-merch-card-border-color: #cacaca;
}
:host([variant='ccd-suggested']) .body {
height: auto;
padding: 20px;
gap: 0;
}
:host([variant='ccd-suggested'].thin-strip) .body {
padding: 20px 20px 20px 28px;
}
:host([variant='ccd-suggested']) .header {
display: flex;
flex-flow: wrap;
place-self: flex-start;
flex-wrap: nowrap;
}
:host([variant='ccd-suggested']) .headings {
padding-inline-start: var(--consonant-merch-spacing-xxs);
display: flex;
flex-direction: column;
justify-content: space-between;
}
:host([variant='ccd-suggested']) ::slotted([slot='icons']) {
place-self: center;
}
:host([variant='ccd-suggested']) ::slotted([slot='heading-xs']) {
font-size: var(--consonant-merch-card-heading-xxs-font-size);
line-height: var(--consonant-merch-card-heading-xxs-line-height);
}
:host([variant='ccd-suggested']) ::slotted([slot='detail-m']) {
line-height: var(--consonant-merch-card-detail-m-line-height);
}
:host([variant='ccd-suggested']) ::slotted([slot='body-xs']) {
color: var(--ccd-gray-700-dark);
padding-top: 8px;
flex-grow: 1;
}
:host([variant='ccd-suggested'].wide-strip)
::slotted([slot='body-xs']) {
padding-inline-start: 48px;
}
:host([variant='ccd-suggested'].wide-strip) ::slotted([slot='price']) {
padding-inline-start: 48px;
}
:host([variant='ccd-suggested']) ::slotted([slot='price']) {
font-size: var(--consonant-merch-card-body-xs-font-size);
line-height: var(--consonant-merch-card-body-xs-line-height);
min-width: fit-content;
}
:host([variant='ccd-suggested']) ::slotted([slot='cta']) {
display: flex;
align-items: center;
min-width: fit-content;
}
:host([variant='ccd-suggested']) .footer {
display: flex;
justify-content: space-between;
flex-grow: 0;
margin-top: 6px;
align-items: center;
}
:host([variant='ccd-suggested']) div[class$='-badge'] {
position: static;
border-radius: 4px;
}
:host([variant='ccd-suggested']) .top-section {
align-items: center;
}
`;
}