-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
105 lines (101 loc) · 2.5 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
103
104
105
<!DOCTYPE html>
<html lang="fa">
<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>Alpine.js اپ چک لیست با</title>
<style>
body {
text-align: right;
direction: rtl;
line-height: 1.7;
}
main {
margin: 1rem .25rem;
display: flex;
justify-content: center;
}
ul {
padding: 0;
}
li {
margin-bottom: .5rem;
display: flex;
align-items: center;
justify-content: space-between;
}
.inactive {
opacity: 0.5;
text-decoration: line-through;
}
input, button {
padding: .25rem .5rem;
font-size: inherit;
}
li button {
padding: 0 .125rem;
line-height: 1;
}
small {
padding: 0 .25rem;
}
</style>
<script src="alpine.min.js" async defer></script>
</head>
<body>
<main>
<div
x-data="{
items: [],
get checkedItems () {
return this.items.filter(i => i.checked);
},
newItemText: '',
add () {
if (!this.newItemText) return;
this.items.unshift({
id: Math.random().toString(),
text: this.newItemText,
checked: false
});
this.newItemText = '';
},
remove (index) {
this.items.splice(index, 1);
},
check (index) {
const item = this.items[index];
item.checked = !item.checked;
this.items.splice(index, 1, { ...item });
},
}"
x-init="items = JSON.parse(localStorage.items || '[]')"
x-effect="localStorage.items = JSON.stringify(items)"
>
<input type="text" placeholder="ایتم جدید..." x-model="newItemText" @keydown.enter="add" autofocus>
<button @click="add" :disabled="!newItemText">
افزودن
</button>
<ul>
<template x-for="(item, i) in items" :key="item.id">
<li>
<label :class="{ 'inactive': item.checked }">
<input type="checkbox" x-model="item.checked">
<span x-text="item.text"></span>
</label>
<button @click="remove(i)"> × </button>
</li>
</template>
</ul>
<hr>
<small>
تعداد: <span x-text="items.length"></span>
</small>
<small>
تکمیل: <span x-text="checkedItems.length"></span>
</small>
</div>
</main>
</body>
</html>