/
UI2.js
95 lines (74 loc) · 2.16 KB
/
UI2.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
/////////////////
//merced-container
/////////////////
const containerTemplate = document.createElement('template');
containerTemplate.innerHTML = `
<div style="
display: flex;
width: 90%;
flex-wrap: wrap;
margin: 20px auto;
" id="cont">
<slot></slot>
</div>
`;
class MercedContainer extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this.shadowRoot.appendChild(containerTemplate.content.cloneNode(true));
const theDiv = this.shadowRoot.getElementById('cont');
theDiv.style.justifyContent = this.getAttribute('justify');
theDiv.style.alignItems = this.getAttribute('align');
theDiv.style.height = this.getAttribute('height');
}
toggle() {
const theDiv = this.shadowRoot.getElementById('cont');
if (theDiv.style.display === 'flex') {
theDiv.style.display = 'none';
} else {
theDiv.style.display = 'flex';
}
}
}
window.customElements.define('merced-container', MercedContainer);
/////////////////
//merced-card
/////////////////
const cardTemplate = document.createElement('template');
cardTemplate.innerHTML = `
<div style="
display: flex;
width: 300px;
flex-direction: column;
flex-wrap: wrap;
margin: 20px auto;
" id="card">
<slot></slot>
</div>
`;
class MercedCard extends HTMLElement {
constructor() {
super();
this.attachShadow({ mode: 'open' });
}
connectedCallback() {
this.shadowRoot.appendChild(cardTemplate.content.cloneNode(true));
const theDiv = this.shadowRoot.getElementById('card');
theDiv.style.justifyContent = this.getAttribute('justify');
theDiv.style.alignItems = this.getAttribute('align');
theDiv.style.height = this.getAttribute('height');
theDiv.style.border = this.getAttribute('theBorder');
}
toggle() {
const theDiv = this.shadowRoot.getElementById('card');
if (theDiv.style.display === 'flex') {
theDiv.style.display = 'none';
} else {
theDiv.style.display = 'flex';
}
}
}
window.customElements.define('merced-card', MercedCard);