class CustomTabGroup extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
`;
// Add click handlers for tabs
setTimeout(() => {
const tabs = this.shadowRoot.querySelectorAll('slot[name="tabs"]').item(0).assignedElements();
const contents = this.shadowRoot.querySelectorAll('slot[name="contents"]').item(0).assignedElements();
tabs.forEach((tab, index) => {
tab.addEventListener('click', () => {
// Remove active class from all tabs and contents
tabs.forEach(t => t.classList.remove('active'));
contents.forEach(c => c.classList.remove('active'));
// Add active class to clicked tab and corresponding content
tab.classList.add('active');
if (contents[index]) {
contents[index].classList.add('active');
}
});
// Set first tab as active by default
if (index === 0) {
tab.classList.add('active');
if (contents[0]) {
contents[0].classList.add('active');
}
}
});
});
}
}
customElements.define('custom-tab-group', CustomTabGroup);