pull/264/merge
Richa Rani 9 months ago committed by GitHub
commit 5fb2cb7b40
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

3
.gitignore vendored

@ -1 +1,2 @@
.DS_Store .DS_Store
.vscode/

@ -1,20 +1,33 @@
<!DOCTYPE html> <!DOCTYPE html>
<html lang="en"> <html lang="en">
<head> <head>
<meta charset="UTF-8" /> <meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="stylesheet" href="style.css" /> <title>Todo App</title>
<title>Todo List</title> <link rel="stylesheet" href="style.css" />
</head> </head>
<body> <body>
<h1>todos</h1>
<form id="form"> <div class="app">
<input type="text" class="input" id="input" placeholder="Enter your todo" autocomplete="off"> <h1>Todo List</h1>
<ul class="todos" id="todos"></ul> <form id="form">
<input
type="text"
id="input"
placeholder="✍️ Add a new task..."
autocomplete="off"
/>
</form> </form>
<small>Left click to toggle completed. <br> Right click to delete todo</small>
<script src="script.js"></script> <ul id="todos"></ul>
</body>
<div class="footer">
<span id="count">0 tasks</span>
<button id="clear">Clear Completed</button>
</div>
</div>
<script src="script.js"></script>
</body>
</html> </html>

@ -1,65 +1,67 @@
const form = document.getElementById('form') const form = document.getElementById("form");
const input = document.getElementById('input') const input = document.getElementById("input");
const todosUL = document.getElementById('todos') const todosUL = document.getElementById("todos");
const countEl = document.getElementById("count");
const clearBtn = document.getElementById("clear");
const todos = JSON.parse(localStorage.getItem('todos')) let todos = JSON.parse(localStorage.getItem("todos")) || [];
if(todos) { renderTodos();
todos.forEach(todo => addTodo(todo))
}
form.addEventListener('submit', (e) => {
e.preventDefault()
addTodo() form.addEventListener("submit", (e) => {
}) e.preventDefault();
function addTodo(todo) { if (input.value.trim() === "") {
let todoText = input.value alert("Todo empty nahi ho sakta 😅");
return;
}
if(todo) { todos.push({
todoText = todo.text text: input.value,
} completed: false
});
if(todoText) { input.value = "";
const todoEl = document.createElement('li') saveAndRender();
if(todo && todo.completed) { });
todoEl.classList.add('completed')
}
todoEl.innerText = todoText function renderTodos() {
todosUL.innerHTML = "";
todoEl.addEventListener('click', () => { todos.forEach((todo, index) => {
todoEl.classList.toggle('completed') const li = document.createElement("li");
updateLS() li.innerText = todo.text;
})
todoEl.addEventListener('contextmenu', (e) => { if (todo.completed) li.classList.add("completed");
e.preventDefault()
todoEl.remove() li.addEventListener("click", () => {
updateLS() todo.completed = !todo.completed;
}) saveAndRender();
});
todosUL.appendChild(todoEl) li.addEventListener("contextmenu", (e) => {
e.preventDefault();
todos.splice(index, 1);
saveAndRender();
});
input.value = '' todosUL.appendChild(li);
});
updateLS() updateCount();
}
} }
function updateLS() { function updateCount() {
todosEl = document.querySelectorAll('li') const pending = todos.filter(t => !t.completed).length;
countEl.innerText = `${pending} tasks left`;
const todos = [] }
todosEl.forEach(todoEl => { clearBtn.addEventListener("click", () => {
todos.push({ todos = todos.filter(todo => !todo.completed);
text: todoEl.innerText, saveAndRender();
completed: todoEl.classList.contains('completed') });
})
})
localStorage.setItem('todos', JSON.stringify(todos)) function saveAndRender() {
} localStorage.setItem("todos", JSON.stringify(todos));
renderTodos();
}

@ -1,72 +1,92 @@
@import url('https://fonts.googleapis.com/css2?family=Poppins:wght@200;400&display=swap'); @import url('https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;600&display=swap');
* { * {
box-sizing: border-box; box-sizing: border-box;
} }
body { body {
background-color: #f5f5f5;
color: #444;
font-family: 'Poppins', sans-serif; font-family: 'Poppins', sans-serif;
background: linear-gradient(135deg, #c3cfe2, #f5f7fa);
min-height: 100vh;
display: flex; display: flex;
flex-direction: column;
align-items: center;
justify-content: center; justify-content: center;
height: 100vh; align-items: center;
margin: 0;
} }
h1 { .app {
color: rgb(179, 131, 226); background: #fff;
font-size: 10rem; width: 380px;
text-align: center; border-radius: 12px;
opacity: 0.4; box-shadow: 0 10px 30px rgba(0,0,0,0.15);
padding: 20px;
} }
form { h1 {
box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1); text-align: center;
max-width: 100%; margin-bottom: 15px;
width: 400px; color: #6a5acd;
} }
.input { #input {
border: none;
color: #444;
font-size: 2rem;
padding: 1rem 2rem;
display: block;
width: 100%; width: 100%;
padding: 12px 15px;
font-size: 1rem;
border-radius: 8px;
border: 1px solid #ddd;
} }
.input::placeholder { #input:focus {
color: #d5d5d5; outline: none;
} border-color: #6a5acd;
.input:focus {
outline-color: rgb(179, 131, 226);
} }
.todos { #todos {
background-color: #fff; list-style: none;
padding: 0; padding: 0;
margin: 0; margin-top: 15px;
list-style-type: none;
} }
.todos li { #todos li {
border-top: 1px solid #e5e5e5; padding: 12px;
background: #f8f8f8;
margin-bottom: 8px;
border-radius: 8px;
cursor: pointer; cursor: pointer;
font-size: 1.5rem; transition: 0.3s;
padding: 1rem 2rem; }
#todos li:hover {
background: #ececff;
} }
.todos li.completed { #todos li.completed {
color: #b6b6b6;
text-decoration: line-through; text-decoration: line-through;
color: #999;
background: #e0e0e0;
} }
small { .footer {
color: #b5b5b5; display: flex;
margin-top: 3rem; justify-content: space-between;
text-align: center; align-items: center;
margin-top: 15px;
}
.footer span {
font-size: 0.9rem;
color: #555;
}
.footer button {
border: none;
background: #ff6b6b;
color: #fff;
padding: 6px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 0.85rem;
}
.footer button:hover {
background: #ff4c4c;
} }

Loading…
Cancel
Save