Skip to content

Commit c23f181

Browse files
authoredOct 16, 2021
Merge pull request #308 from eshabaweja/todolist-eshabaweja-branch
a simple todo list
2 parents e5f21de + f9076a6 commit c23f181

File tree

5 files changed

+168
-0
lines changed

5 files changed

+168
-0
lines changed
 

‎ToDoList/eshabaweja/README.md

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# todos
2+
3+
A simple checklist page in which we can store (type and press enter), strike out (left click), and delete (right click) items.
4+
5+
6+
7+
![To-do app screenshot](assets/todo.png)
8+

‎ToDoList/eshabaweja/assets/script.js

+65
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
const form = document.getElementById('form')
2+
const input = document.getElementById('input')
3+
const todosUL = document.getElementById('todos')
4+
5+
const todos = JSON.parse(localStorage.getItem('todos'))
6+
7+
if(todos) {
8+
todos.forEach(todo => addTodo(todo))
9+
}
10+
11+
form.addEventListener('submit', (e) => {
12+
e.preventDefault()
13+
14+
addTodo()
15+
})
16+
17+
function addTodo(todo) {
18+
let todoText = input.value
19+
20+
if(todo) {
21+
todoText = todo.text
22+
}
23+
24+
if(todoText) {
25+
const todoEl = document.createElement('li')
26+
if(todo && todo.completed) {
27+
todoEl.classList.add('completed')
28+
}
29+
30+
todoEl.innerText = todoText
31+
32+
todoEl.addEventListener('click', () => {
33+
todoEl.classList.toggle('completed')
34+
updateLS()
35+
})
36+
37+
todoEl.addEventListener('contextmenu', (e) => {
38+
e.preventDefault()
39+
40+
todoEl.remove()
41+
updateLS()
42+
})
43+
44+
todosUL.appendChild(todoEl)
45+
46+
input.value = ''
47+
48+
updateLS()
49+
}
50+
}
51+
52+
function updateLS() {
53+
todosEl = document.querySelectorAll('li')
54+
55+
const todos = []
56+
57+
todosEl.forEach(todoEl => {
58+
todos.push({
59+
text: todoEl.innerText,
60+
completed: todoEl.classList.contains('completed')
61+
})
62+
})
63+
64+
localStorage.setItem('todos', JSON.stringify(todos))
65+
}

‎ToDoList/eshabaweja/assets/style.css

+72
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
@import url('https://fonts.googleapis.com/css2?family=Roboto');
2+
3+
*{
4+
box-sizing: border-box;
5+
}
6+
7+
body{
8+
background-color: #ebebeb;
9+
color: #444444;
10+
font-family:Roboto, sans-serif;
11+
display: flex;
12+
align-items: center;
13+
flex-direction: column;
14+
justify-content: center;
15+
height: 100vh;
16+
margin: 0;
17+
}
18+
19+
h1{
20+
color: #625fff;
21+
font-size: 10rem;
22+
text-align: center;
23+
opacity: 0.4;
24+
}
25+
26+
form{
27+
box-shadow: 0 4px 10px #00000025;
28+
max-width: 100%;
29+
width: 400px;
30+
}
31+
32+
.input{
33+
border: none;
34+
color: #444444;
35+
font-size: 2rem;
36+
padding: 1rem 2rem;
37+
display: block;
38+
width: 100%;
39+
}
40+
41+
.input::placeholder{
42+
color: #d5d5d5;
43+
}
44+
45+
.input:focus{
46+
outline: 2px solid #625fff;
47+
}
48+
49+
.todos{
50+
background-color: #ffffff;
51+
padding: 0%;
52+
list-style-type: none;
53+
margin: 0;
54+
}
55+
56+
.todos li{
57+
border-top: 1px solid #e5e5e5;
58+
cursor: pointer;
59+
font-size: 1.5rem;
60+
padding: 1rem 2rem;
61+
}
62+
63+
.todos li.completed{
64+
color: #b6b6b6;
65+
text-decoration: line-through;
66+
}
67+
68+
small{
69+
color: #b5b5b5;
70+
margin-top: 3rem;
71+
text-align: center;
72+
}

‎ToDoList/eshabaweja/assets/todo.png

42.9 KB
Loading

‎ToDoList/eshabaweja/index.html

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Todo List</title>
8+
9+
<link rel="stylesheet" href="assets/style.css">
10+
</head>
11+
<body>
12+
13+
<h1>todos</h1>
14+
<form id="form">
15+
<input type="text" class="input" id="input" placeholder="Enter your todo" autocapitalize="off" autocomplete="off">
16+
<ul class="todos" id="todos"></ul>
17+
</form>
18+
<small>Left click to toggle completed. <br>
19+
Right click to delete to-do.</small>
20+
21+
<script src="assets/script.js"></script>
22+
</body>
23+
</html>

0 commit comments

Comments
 (0)
Please sign in to comment.