-
Notifications
You must be signed in to change notification settings - Fork 0
/
card_title.js
54 lines (49 loc) · 1.26 KB
/
card_title.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
class CardTitle extends HTMLElement {
constructor() {
super();
this.id = Date.now();
this.title = "Title";
this.popover_content = "";
this.caption = ""; // optional
}
// component attributes
static get observedAttributes() {
return ["id", "title", "popover_content", "caption"];
}
connectedCallback() {
const popoverHTML =
this.popover_content == ""
? ""
: `
<button
tabindex="0"
class="bbsButton bbsButton-tertiary small"
role="button"
data-bs-toggle="popover"
data-bs-title="${this.title}"
data-bs-trigger="focus"
data-bs-custom-class="help-popover"
data-bs-html="true"
data-bs-content="${this.popover_content}"
>
<span class="msicon notranslate">help</span>
</button>
`;
const innerHTML = `
<div>
<div class="tw-flex tw-items-center">
<h5 class="tw-flex-grow">${this.title}</h5>
${popoverHTML}
</div>
<p class="caption">${this.caption}</p>
</div>
`;
this.innerHTML = innerHTML;
}
// attribute change
attributeChangedCallback(property, oldValue, newValue) {
if (oldValue === newValue) return;
this[property] = newValue;
}
}
customElements.define("card-title", CardTitle);