-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
102 lines (88 loc) · 3.37 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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="description" content="A simple to-do web application to test the alpine.js framework." />
<link rel="icon" type="image/x-icon" href="./favicon.ico" />
<title>To-do</title>
<link rel="preconnect" href="https://cdn.jsdelivr.net/npm/" crossorigin />
<link rel="preload" as="style" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css" />
<link rel="preload" as="script" href="https://cdn.jsdelivr.net/npm/@alpinejs/persist@3.x.x/dist/cdn.min.js" />
<link rel="preload" as="script" href="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@picocss/pico@1/css/pico.min.css" />
<script defer src="https://cdn.jsdelivr.net/npm/alpinejs@3.x.x/dist/cdn.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/@alpinejs/persist@3.x.x/dist/cdn.min.js"></script>
<script defer>
document.addEventListener("alpine:init", () => {
Alpine.store("todos", {
list: Alpine.$persist([]),
createNew(text) {
this.list.push({ text: text, checked: false });
},
deleteChecked() {
this.list = this.list.filter((t) => !t.checked);
},
deleteAll() {
this.list = [];
},
});
});
</script>
</head>
<body class="container">
<header>
<nav>
<ul>
<li><strong>To-do</strong></li>
</ul>
<ul x-data>
<li><button @click="$dispatch('open-create')" class="outline">New</button></li>
<li><button @click="$store.todos.deleteChecked()" class="outline">Delete Completed</button></li>
<li><button @click="$store.todos.deleteAll()" class="outline">Delete All</button></li>
</ul>
</nav>
<dialog
x-data="{ open: false, text: '' }"
@open-create.window="open = true; $nextTick(() => $refs.textInput.focus())"
@close-create.window="open = false; text = ''"
:open="open"
>
<form @submit.prevent="$store.todos.createNew(text); $dispatch('close-create')">
<article>
<header>
<div role="link" @click="open = false" class="close" aria-label="Close" tabindex="0"></div>
<strong>New To-do</strong>
</header>
<div>
<label>To-do text:</label>
<input x-ref="textInput" x-model="text" type="text" aria-label="To-do text" required />
</div>
<footer>
<a role="button" class="outline" aria-label="Create" href="">Confirm</a>
</footer>
</article>
</form>
</dialog>
</header>
<main style="padding: 0">
<ul>
<template x-data x-for="todo in $store.todos.list" x-key="todo.text">
<li style="list-style: none">
<input type="checkbox" x-model="todo.checked" />
<span x-text="todo.text"></span>
</li>
</template>
</ul>
</main>
<footer>
<progress
x-data
value="0"
:value="$store.todos.list.filter(t => t.checked).length"
:max="$store.todos.list.length"
aria-label="Progress bar"
></progress>
</footer>
</body>
</html>