-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathtodo-functional.html
More file actions
39 lines (35 loc) · 1.1 KB
/
todo-functional.html
File metadata and controls
39 lines (35 loc) · 1.1 KB
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
<!DOCTYPE html>
<html>
<head>
<link rel="icon" href="/logo.svg">
<title>TODO List (Functional/Reactive-Style)</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<style>
a { cursor: pointer; }
</style>
</head>
<body>
<script type="module">
import van from "./van-latest.min.js"
const {a, button, div, input, span, strike} = van.tags
const TodoItem = ({text}) => {
const done = van.state(false), deleted = van.state(false)
return () => deleted.val ? null : div(
input({type: "checkbox", checked: done, onclick: e => done.val = e.target.checked}),
() => (done.val ? strike : span)(text),
a({onclick: () => deleted.val = true}, "❌"),
)
}
const TodoList = () => {
const inputDom = input({type: "text"})
const dom = div(
inputDom,
button({onclick: () => van.add(dom, TodoItem({text: inputDom.value}))}, "Add"),
)
return dom
}
van.add(document.body, TodoList())
</script>
</body>
</html>