class TaskForm extends HTMLElement {
connectedCallback() {
this.attachShadow({ mode: 'open' });
this.shadowRoot.innerHTML = `
`;
// Priority selection
this.shadowRoot.querySelectorAll('.priority-option').forEach(option => {
option.addEventListener('click', () => {
this.shadowRoot.querySelectorAll('.priority-option').forEach(opt =>
opt.classList.remove('selected')
);
option.classList.add('selected');
this.shadowRoot.getElementById('priority').value = option.dataset.value;
});
});
// Form submission
this.shadowRoot.getElementById('taskForm').addEventListener('submit', (e) => {
e.preventDefault();
const newTask = {
title: this.shadowRoot.getElementById('taskTitle').value,
description: this.shadowRoot.getElementById('taskDescription').value,
dueDate: this.shadowRoot.getElementById('dueDate').value,
priority: this.shadowRoot.getElementById('priority').value,
completed: false
};
this.dispatchEvent(new CustomEvent('task-added', { detail: newTask }));
this.shadowRoot.getElementById('taskForm').reset();
});
}
}
customElements.define('task-form', TaskForm);