-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtabs-component.js
63 lines (54 loc) · 2.19 KB
/
tabs-component.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
import { html, css, LitElement } from 'https://unpkg.com/lit-element?module';
class TabsComponent extends LitElement {
static styles = css`
/* Add your CSS styles here */
`;
constructor() {
super();
this.activeTab = 0;
}
setActiveTab(index) {
this.activeTab = index;
this.requestUpdate();
}
render() {
const tabs = [
{ label: 'Home', icon: 'fas fa-home', content: 'This is the content for the Home tab.' },
{ label: 'Profile', icon: 'fas fa-user', content: 'This is the content for the Profile tab.' },
{ label: 'Messages', icon: 'fas fa-envelope', content: 'This is the content for the Messages tab.' },
];
return html`
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<ul class="nav nav-tabs" role="tablist">
${tabs.map((tab, index) => html`
<li class="nav-item" role="presentation">
<button class="nav-link ${index === this.activeTab ? 'active' : ''}"
@click="${() => this.setActiveTab(index)}"
aria-selected="${index === this.activeTab}"
role="tab"
aria-controls="tab-${index}">
<i class="${tab.icon}"></i> ${tab.label}
</button>
</li>
`)}
</ul>
<div class="tab-content">
${tabs.map((tab, index) => html`
<div class="tab-pane fade ${index === this.activeTab ? 'show active' : ''}"
id="tab-${index}"
role="tabpanel"
aria-labelledby="tab-${index}">
<h2>${tab.label} Tab Content</h2>
<p>${tab.content}</p>
</div>
`)}
</div>
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl"
crossorigin="anonymous"></script>
`;
}
}
customElements.define('tabs-component', TabsComponent);