forked from docker-ko/docker-ko.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcard-component.ts
More file actions
46 lines (40 loc) · 1.09 KB
/
Copy pathcard-component.ts
File metadata and controls
46 lines (40 loc) · 1.09 KB
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
class CardComponent extends HTMLElement {
static get observedAttributes() {
return ['imgsrc', 'href', 'title', 'description'];
}
constructor() {
super();
}
attributeChangedCallback() {
this.render();
}
connectedCallback() {
this.render();
}
render() {
const imgSrc = this.getAttribute('imgsrc'); // 없으면 null
const href = this.getAttribute('href') || '#';
const title = this.getAttribute('title') || '';
const description = this.getAttribute('description') || '';
this.innerHTML = `
<div class="card">
<a href="${href}" class="card-link">
${
imgSrc
? `<div class="card-icon">
<img class="card-img" src="${imgSrc}" alt="${title}" />
</div>`
: ''
}
<div class="card-content">
<p class="card-description">
<strong class="card-title">${title}</strong><br />
${description}
</p>
</div>
</a>
</div>
`;
}
}
customElements.define('card-component', CardComponent);