-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreateTodoItem.js
43 lines (42 loc) · 1.7 KB
/
createTodoItem.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { createElementButton, createElementInput } from './elements.js';
import { toggleTodoItem, removeTodoItem } from './taskActions.js';
export const createTodoItem = (task, isComplited, id, date, tasks) => {
const todoItem = document.createElement('ul');
todoItem.className = 'todo-list';
const itemDiv = document.createElement('div');
itemDiv.className = 'todo';
const newItem = document.createElement('li');
newItem.className = 'todo-item';
itemDiv.appendChild(newItem);
todoItem.appendChild(itemDiv);
// checkbox
const checkbox = document.createElement('input');
checkbox.type = 'checkbox';
checkbox.className = 'checkbox';
checkbox.checked = isComplited;
checkbox.addEventListener('change', () => toggleTodoItem(id, tasks));
newItem.appendChild(checkbox);
// span task
const todoText = document.createElement('span');
todoText.className = 'todo-text';
todoText.id = id;
todoText.textContent = task;
if (checkbox.checked || isComplited) {
todoText.style.textDecoration = 'line-through';
todoText.style.color = 'red';
todoItem.style.accentColor = 'red';
}
newItem.appendChild(todoText);
// buttonX
const itemButtonDate = document.createElement('div');
itemButtonDate.className = 'button-date';
const buttonX = itemButtonDate.appendChild(createElementButton('X', 'button', 'button-x'));
buttonX.addEventListener('click', () => removeTodoItem(id, tasks));
itemDiv.appendChild(itemButtonDate);
// date
const todoDate = document.createElement('time');
todoDate.className = 'todo-date';
todoDate.textContent = date;
itemButtonDate.appendChild(todoDate);
return todoItem;
}