HTML
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>TODO App</title>
<link rel="icon" type="image/png" href="./assets/rocket.svg" />
<link rel="preconnect" href="https://fonts.gstatic.com" />
<link
href="https://fonts.googleapis.com/css2?family=Dosis&family=Open+Sans&family=Parisienne&display=swap"
rel="stylesheet"
/>
<link
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css"
rel="stylesheet"
/>
<link rel="stylesheet" href="styles.css" />
</head>
<body>
<main>
<div class="mainCard">
<div class="title"><img src="./assets/rocket.svg" /></div>
<div>
<form action="">
<input
type="text"
name="task"
placeholder="Nombre de la tarea"
class="inputForm"
autocomplete="off"
data-form-input
/>
<input
type="datetime-local"
data-form-date
placeholder="YYYY/MM/DD"
/>
<button type="submit" class="btnCreate" data-form-btn>
Agregar <i class="fas fa-plus-circle"></i>
</button>
</form>
</div>
<ul class="cardsList" data-list>
</ul>
</div>
</main>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.29.3/moment.min.js"></script>
<script type="module" src="script.js"></script>
</body>
</html>
JAVASCRIPT
import checkComplete from './components/checkComplete.js';
import deleteIcon from './components/deleteIcon.js';
const btn = document.querySelector('[data-form-btn]');
const createTask = (evento) => {
evento.preventDefault();
const input = document.querySelector('[data-form-input]');
const calendar = document.querySelector('[data-form-date]');
const value = input.value;
const date = calendar.value;
const dateFormat = moment(date).format("DD/MM/YYYY");
console.log(dateFormat);
const list = document.querySelector('[data-list]');
const task = document.createElement('li');
task.classList.add('card');
input.value = '';
//backticks
const taskContent = document.createElement('div');
const titleTask = document.createElement('span');
titleTask.classList.add('task');
titleTask.innerText = value;
taskContent.appendChild(checkComplete());
taskContent.appendChild(titleTask);
task.appendChild(taskContent);
task.appendChild(deleteIcon());
list.appendChild(task);
};
btn.addEventListener('click', createTask);
checkComplete.js
const checkComplete = () => {
const i = document.createElement('i');
i.classList.add('far', 'fa-check-square', 'icon');
i.addEventListener('click', completeTask);
return i;
};
// Immediately invoked function expression IIFE
const completeTask = (event) => {
const element = event.target;
element.classList.toggle('fas');
element.classList.toggle('completeIcon');
element.classList.toggle('far');
};
export default checkComplete;
deleteIcon.js
const deleteIcon = () => {
const i = document.createElement('i');
i.classList.add('fas', 'fa-trash-alt', 'trashIcon', 'icon');
i.addEventListener('click', deleteTask);
return i;
};
const deleteTask = (event) => {
const parent = event.target.parentElement;
parent.remove();
};
export default deleteIcon;