class CustomSidebar extends HTMLElement { connectedCallback() { this.attachShadow({ mode: 'open' }); this.shadowRoot.innerHTML = `
`; // Add event listener for the toggle button this.shadowRoot.querySelector('.sidebar-toggle').addEventListener('click', () => { const sidebar = this.shadowRoot.querySelector('.sidebar'); sidebar.classList.toggle('collapsed'); // Change the icon based on state const icon = this.shadowRoot.querySelector('.sidebar-toggle i'); if (sidebar.classList.contains('collapsed')) { icon.classList.replace('fa-chevron-left', 'fa-chevron-right'); } else { icon.classList.replace('fa-chevron-right', 'fa-chevron-left'); } }); } } customElements.define('custom-sidebar', CustomSidebar);