-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtodo.ts
112 lines (80 loc) · 3.51 KB
/
todo.ts
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
const todosListEl = document.querySelector('[data-todo-list]') !as HTMLDivElement
const defaultItem = document.querySelector('[data-todo-item-def]') !as HTMLDivElement
const defaultItemData = document.querySelector("[data-todo]") !as HTMLInputElement
const updateInput = (element: HTMLInputElement) => {
element.value = ""
}
const toggleDetail = (e: any) => {
e.parentElement.parentElement.lastElementChild.classList.toggle("flex")
}
const create = (e: any) => {
let inputValue = defaultItemData.value
if ((e.keyCode === 13 || e.which === 13) && inputValue != "") {
const Object = `
<div class="todo__item" data-todo-item>
<div class="todo__item__main">
<button onClick="deleteItem(this)" >
<img src="img/done.svg" />
</button>
<input placeholder="New task...." type="text" value="${inputValue}" spellcheck = "false"></input>
<span onClick='toggleDetail(this)' btn-todo-item>
<img src="img/expand.svg" />
</span>
</div>
<div class="details flex" data-todo-item-detail>
<div class="details-info--1">
<p>Notes</p>
<textarea maxlength="270" data-todo-item-note></textarea>
</div>
<div class="details-info--2">
<div class="details-info--2__date">
<div>
<input type="radio" name="date" id="Today"></input>
<label for="Today">
Today
</label>
</div>
<div>
<input type="radio" name="date" id="Tommorow"></input>
<label for="Tommorow">
Tommorow
</label>
</div>
<div>
<input type="date" name="date" id="calender"></input>
<label for="calender">
Set date
</label>
</div>
</div>
<button data-todo-item-del>Delete</button>
</div>
</div>
</div>
`
todosListEl.insertAdjacentHTML("afterbegin", Object)
updateInput(defaultItemData)
}
}
const deleteItem = (e: any) => {
e.parentElement.parentElement.remove();
};
document.addEventListener("keypress", e => {
create(e)
})
// todosItem = document.querySelectorAll('[data-todo-item]');
// todosNote = document.querySelectorAll("[data-todo-item-note]")
// deleteItem = document.querySelectorAll('[data-todo-item-del]');
// toggleDetail = document.querySelectorAll('[btn-todo-item]')
// detail = document.querySelectorAll('[data-todo-item-detail]');
// toggleDetail.forEach((curr: Node) => {
// curr.addEventListener("click", () => {
// console.log("a")
// })
// })
defaultItemData.addEventListener('focus', () => {
defaultItem.style.border = "2px solid goldenrod"
setTimeout(() => {
defaultItem.style.border = "2px solid transparent"
}, 3000);
})