class CustomNavbar extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
`;
// Initialize mobile menu toggle
const mobileMenuBtn = this.shadowRoot.querySelector('.mobile-menu-btn');
const navLinks = this.shadowRoot.querySelector('.nav-links');
mobileMenuBtn.addEventListener('click', () => {
navLinks.classList.toggle('active');
const icon = mobileMenuBtn.querySelector('i');
if (navLinks.classList.contains('active')) {
icon.setAttribute('data-feather', 'x');
} else {
icon.setAttribute('data-feather', 'menu');
}
feather.replace();
});
// Close mobile menu when a link is clicked
this.shadowRoot.querySelectorAll('.nav-link').forEach(link => {
link.addEventListener('click', () => {
navLinks.classList.remove('active');
const icon = mobileMenuBtn.querySelector('i');
icon.setAttribute('data-feather', 'menu');
feather.replace();
});
});
}
}
customElements.define('custom-navbar', CustomNavbar);