class CustomCommentsSection extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
`;
// Comment form submission
this.shadowRoot.querySelector('.comment-form button').addEventListener('click', () => {
const text = this.shadowRoot.querySelector('.comment-form textarea').value;
if (text.trim()) {
const comment = document.createElement('div');
comment.className = 'comment';
comment.innerHTML = `
`;
this.shadowRoot.querySelector('.comments-list').prepend(comment);
this.shadowRoot.querySelector('.comment-form textarea').value = '';
}
});
}
}
customElements.define('custom-comments-section', CustomCommentsSection);