forked from adobecom/milo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmerch-whats-included.js
99 lines (84 loc) · 2.5 KB
/
merch-whats-included.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
import { html, css, LitElement } from 'lit';
export class MerchWhatsIncluded extends LitElement {
static styles = css`
:host {
display: inline-grid;
place-items: end start;
grid-auto-flow: row;
width: auto;
overflow: hidden;
place-content: stretch start;
box-sizing: border-box;
align-self: baseline;
margin-bottom: 16px;
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
grid-auto-rows: unset;
height: inherit;
}
::slotted([slot='heading']) {
grid-column: 1 / -1;
font-size: 18px;
margin: 0;
margin-bottom: 16px;
}
::slotted([slot='content']) {
display: contents;
}
.hidden {
display: none;
}
.see-more {
font-size: 14px;
text-decoration: underline;
color: var(--link-color-dark);
margin-top: 16px;
}
`;
static properties = {
heading: { type: String, attribute: true },
mobileRows: { type: Number, attribute: true },
};
updated() {
this.hideSeeMoreEls();
}
hideSeeMoreEls() {
if (this.isMobile) {
this.rows.forEach((node, index) => {
if (index >= 5) {
node.style.display = this.showAll ? 'flex' : 'none';
}
});
}
}
constructor() {
super();
this.showAll = false;
this.mobileRows = this.mobileRows === undefined ? 5 : this.mobileRows;
}
toggle() {
this.showAll = !this.showAll;
this.dispatchEvent(
new CustomEvent('hide-see-more-elements', {
bubbles: true,
composed: true,
})
);
this.requestUpdate();
}
render() {
return html`<slot name="heading"></slot>
<slot name="content"></slot>
${this.isMobile && this.rows.length > this.mobileRows
? html`<div @click=${this.toggle} class="see-more">
${this.showAll ? '- See less' : '+ See more'}
</div>`
: html``}`;
}
get isMobile() {
return window.matchMedia('(max-width: 767px)').matches;
}
get rows() {
return this.querySelectorAll('merch-mnemonic-list');
}
}
customElements.define('merch-whats-included', MerchWhatsIncluded);