-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
70 lines (64 loc) · 3.05 KB
/
index.html
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
<!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>Facilito List</title>
<script src="https://cdn.jsdelivr.net/gh/alpinejs/[email protected]/dist/alpine.min.js" defer></script>
<link href="https://unpkg.com/tailwindcss@^2/dist/tailwind.min.css" rel="stylesheet">
</head>
<body>
<h1 class="text-4xl text-green-700 text-center">Facilito List</h1>
<hr>
<div class="container mx-auto" x-data="data()">
<div class="grid grid-cols-2 gap-2 pt-4">
<input x-model="task" type="text" name="task" class="border focus:outline-none focus:ring-2 focus:ring-green-600 rounded" placeholder="Escribe una nueva tarea">
<button @click="addTask()" class="text-white bg-green-500 rounded p-2 hover:bg-green-600">Agregar</button>
</div>
<h5 class="text-green-600 text-center pt-2 text-4xl">Mis tareas</h5>
<template x-for="(item, index) in tasks" :key="index">
<div class="mt-4 space-y-4" x-show="!item.completed">
<div class="flex items-start">
<div class="flex items-center h-5">
<input @click="item.completed = true" type="checkbox" class="focus:ring-indigo-500 h-4 w-4 text-indigo-600 border-gray-300 rounded">
</div>
<div class="ml-3 text-sm h-5">
<label x-show="!item.edit" class="font-medium text-gray-700" x-text="item.title"></label>
<input x-show="item.edit" type="text" x-model="item.title">
</div>
<div class="ml-3 flex items-center">
<button class="text-white bg-blue-700 rounded pr-2 pl-2" @click="!item.edit ? item.edit = true : item.edit = false" x-text="item.edit ? 'Guardar': 'Editar'">Editar</button>
<button class="text-white bg-red-700 rounded pr-2 pl-2 ml-4" @click="deleteTask(index)">Eliminar</button>
</div>
</div>
</div>
</template>
<h5 class="text-green-600 text-center pt-2 text-4xl" x-show="hasTasksCompleted()">Tareas Completadas</h5>
<template x-for="item in tasksCompleted()">
<li x-text="item.title" class="line-through"></li>
</template>
</div>
<script>
function data() {
return {
task: '',
tasks: [],
addTask() {
this.tasks.push({ title: this.task, completed: false, edit: false});
this.task = '';
},
deleteTask(index) {
this.tasks.splice(index, 1);
},
tasksCompleted() {
return this.tasks.filter((item) => item.completed);
},
hasTasksCompleted() {
return this.tasksCompleted().length > 0;
}
};
}
</script>
</body>
</html>