Skip to content

Commit ee4a97d

Browse files
committed
to do logic
1 parent 03acc3c commit ee4a97d

File tree

5 files changed

+100
-48
lines changed

5 files changed

+100
-48
lines changed

blocks/to-do-list.css

Lines changed: 15 additions & 8 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blocks/to-do-list.css.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

blocks/to-do-list.scss

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
display: flex;
4343
justify-content: space-between;
4444
gap: 20px;
45-
margin-bottom: 20px;
4645
}
4746

4847
&__input {
@@ -61,21 +60,31 @@
6160
}
6261
}
6362

64-
&__list:not(:last-child) {
65-
margin-bottom: 10px;
66-
}
67-
6863
&__item {
6964
display: flex;
7065
justify-content: space-between;
7166
align-items: flex-start;
7267
background-color: rgba(175, 175, 175, 0.1);
7368
padding: 10px 20px;
7469
border-radius: 15px;
70+
71+
&:first-child {
72+
margin-top: 20px;
73+
}
74+
75+
&:not(:last-child) {
76+
margin-bottom: 10px;
77+
}
78+
79+
&.completed .to-do__text {
80+
text-decoration: line-through;
81+
color: #b6b6b6;
82+
}
7583
}
7684

7785
&__text {
7886
margin-right: 5px;
87+
padding-top: 3px;
7988
}
8089

8190
/**/
@@ -87,7 +96,7 @@
8796

8897
/**/
8998
&__button {
90-
&_accept {
99+
&_complete {
91100
@include icon-button;
92101
&:hover {
93102
color: #29ff29;
@@ -98,8 +107,8 @@
98107
&_edit {
99108
@include icon-button;
100109
&:hover {
101-
color: #80acff;
102-
background-color: rgba(128, 172, 255, 0.2);
110+
color: #2474ff;
111+
background-color: rgba(36, 116, 255, 0.2);
103112
}
104113
}
105114

pages/to-do-list.html

Lines changed: 3 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,41 +15,13 @@ <h1 class="main__title">To Do List</h1>
1515
<div class="main__to-do to-do">
1616
<form class="to-do__form">
1717
<input type="text" class="to-do__input"
18-
placeholder="Write here...">
18+
placeholder="Write here..." name="activity"
19+
id="activity" required>
1920
<button class="to-do__submit-button" type="submit">Add
2021
</button>
2122
</form>
2223
<div class="to-do__list">
23-
<div class="to-do__item">
24-
<div class="to-do__text">text</div>
25-
<div class="to-do__buttons">
26-
<button type="button" class="to-do__button_accept">
27-
<i class="fa-solid fa-check"></i>
28-
</button>
29-
<button type="button" class="to-do__button_edit">
30-
<i class="fa-regular fa-pen-to-square"></i>
31-
</button>
32-
<button type="button" class="to-do__button_delete">
33-
<i class="fa-regular fa-trash-can"></i>
34-
</button>
35-
</div>
36-
</div>
37-
</div>
38-
<div class="to-do__list">
39-
<div class="to-do__item">
40-
<div class="to-do__text">text</div>
41-
<div class="to-do__buttons">
42-
<button type="button" class="to-do__button_accept">
43-
<i class="fa-solid fa-check"></i>
44-
</button>
45-
<button type="button" class="to-do__button_edit">
46-
<i class="fa-regular fa-pen-to-square"></i>
47-
</button>
48-
<button type="button" class="to-do__button_delete">
49-
<i class="fa-regular fa-trash-can"></i>
50-
</button>
51-
</div>
52-
</div>
24+
5325
</div>
5426
</div>
5527
</div>

scripts/to-do-list.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// Create buttons and append it to each list item
2+
3+
function createAndAppendButtons(arr, index = 0) {
4+
const buttons = document.createElement('div')
5+
buttons.className = 'to-do__buttons'
6+
7+
const btnComplete = document.createElement('button')
8+
btnComplete.className = 'to-do__button_complete'
9+
const btnContentCheck = document.createElement('i')
10+
btnContentCheck.className = 'fa-solid fa-check'
11+
btnComplete.appendChild(btnContentCheck)
12+
buttons.appendChild(btnComplete)
13+
14+
const btnDelete = document.createElement('button')
15+
btnDelete.className = 'to-do__button_delete'
16+
const btnContentDelete = document.createElement('i')
17+
btnContentDelete.className = 'fa-regular fa-trash-can'
18+
btnDelete.appendChild(btnContentDelete)
19+
buttons.appendChild(btnDelete)
20+
21+
arr[index].appendChild(buttons)
22+
}
23+
24+
const nodeList = Array.from(document.querySelectorAll('.to-do__item'))
25+
for (let i = 0; i <nodeList.length; i++) {
26+
createAndAppendButtons(nodeList, i)
27+
}
28+
29+
//Add button handlers
30+
const list = document.querySelector('.to-do__list')
31+
list.addEventListener('click', function (ev) {
32+
if (ev.target.closest('.to-do__button_complete')) {
33+
ev.target.parentElement.parentElement.parentElement.classList.toggle('completed')
34+
}
35+
if (ev.target.closest('.to-do__button_delete')) {
36+
console.log(false)
37+
const div = ev.target.parentElement.parentElement.parentElement
38+
div.remove()
39+
}
40+
}, false)
41+
42+
const form = document.querySelector('.to-do__form')
43+
44+
form.addEventListener('submit', (e) => {
45+
e.preventDefault()
46+
47+
const listItem = document.createElement('div')
48+
listItem.className = 'to-do__item'
49+
50+
const listText = document.createElement('div')
51+
listText.className = 'to-do__text'
52+
53+
const input = document.querySelector('.to-do__input').value
54+
55+
const text = document.createTextNode(input)
56+
57+
listItem.appendChild(listText)
58+
listText.appendChild(text)
59+
60+
createAndAppendButtons([listItem])
61+
list.appendChild(listItem)
62+
document.querySelector('.to-do__input').value = ''
63+
})
64+

0 commit comments

Comments
 (0)