-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.html
112 lines (101 loc) · 2.91 KB
/
demo.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
106
107
108
109
110
111
112
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>todos</title>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap@5.2.3/dist/css/bootstrap.min.css"
integrity="sha384-rbsA2VBKQhggwzxH7pPCaAqO46MgnOM80zW1RWuH61DGLwZJEdK2Kadq2F9CUG65"
crossorigin="anonymous"
/>
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.2/font/bootstrap-icons.css"
integrity="sha384-b6lVK+yci+bfDmaY1u0zE8YYJt0TZxLEAFyYSLHId4xoVvsrQu3INevFKo+Xir8e"
crossorigin="anonymous"
/>
<!-- Blank favicon -->
<link rel="icon" href="data:;base64,iVBORw0KGgo=" />
</head>
<body>
<script type="module">
import { h, repeat } from './';
const items = new Map();
const itemsContainer = h/*html*/ `
<ol class="list-group list-group-numbered text-start"></ol>
`;
const updateItemsContainer = () => {
repeat({
container: itemsContainer,
items,
element: ({ item, key }) => h/*html*/ `
<li class="list-group-item">
<button
class="btn btn-outline-danger btn-sm"
${{
style: {
border: 'none',
borderRadius: '30px',
marginRight: '5px',
marginLeft: '5px',
},
onclick: () => {
items.delete(key);
updateItemsContainer();
},
}}
>
<i class="bi bi-trash3"></i>
</button>
${item}
</li>
`,
});
};
const input = h/*html*/ `
<input
class="form-control form-control-lg"
type="text"
placeholder="Text..."
/>
`;
const submitBtn = h/*html*/ `
<button
type="submit"
class="btn btn-outline-secondary"
${{
style: {
visibility: 'hidden',
position: 'absolute',
},
onclick: (e) => {
e.preventDefault();
if (input.value.trim()) {
items.set(performance.now(), input.value);
input.value = '';
updateItemsContainer();
}
},
}}
>
<i class="bi bi-plus-circle"></i> Add
</button>
`;
const form = h/*html*/ `
<form>
<p>${input}</p>
<p>${submitBtn}</p>
</form>
`;
document.body.append(h/*html*/ `
<div class="container text-center" style="max-width: 800px">
<h1 class="display-1">todos</h1>
${form}
${itemsContainer}
</div>
`);
</script>
</body>
</html>