-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
67 lines (63 loc) · 1.49 KB
/
index.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
class bCard extends HTMLElement {
constructor() {
super();
this.attachShadow({mode: 'open'});
this.template = document.createElement('template');
}
static get observedAttributes() {
return ['title', 'description'];
}
attributeChangedCallback(attrName, oldVal, newVal) {
if (attrName == 'title') {
this.title = newVal;
} else if (attrName == 'description') {
this.description = newVal;
}
}
getTemplate() {
this.template.innerHTML = `
<div class='card'>
<h1>${this.title}</h1>
<p>${this.description}</p>
</div>
${this.getStyles()}
`;
return this.template;
}
getStyles() {
return `
<style>
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
.card {
border: 1px solid #ccc;
border-radius: 4px;
background-color: #fafafa;
box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
margin: 0 auto;
padding: 6px;
width: 35%;
display: flex;
flex-direction: column;
justify-content: center;
align-items: center;
}
.card h1 {
width: 100%;
border-bottom: 0.75px solid #ccc;
padding: 4px;
}
.card p {
padding: 8px;
}
</style>
`;
}
connectedCallback() {
this.shadowRoot.appendChild(this.getTemplate().content.cloneNode(true));
}
}
customElements.define('b-card', bCard);