forked from JetBrains/kotlin-wrappers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTodo.kt
More file actions
73 lines (60 loc) · 1.61 KB
/
Todo.kt
File metadata and controls
73 lines (60 loc) · 1.61 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
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
package example
import react.*
import react.dom.html.InputType
import react.dom.html.ReactHTML.button
import react.dom.html.ReactHTML.div
import react.dom.html.ReactHTML.h3
import react.dom.html.ReactHTML.input
import react.dom.html.ReactHTML.li
import react.dom.html.ReactHTML.ul
/**
* A to-do list implementation by Scott_Huang@qq.com
*/
external interface TodoProps : Props {
var initialItems: List<String?>
}
val Todo = FC<TodoProps> { props ->
var items by useState(props.initialItems)
var text by useState("")
div {
input {
key = "itemText"
type = InputType.text
name = "itemText"
value = text
placeholder = "Add a to-do item"
onChange = { text = it.target.value }
}
button {
onClick = {
if (text.isNotEmpty()) {
items = items + text
text = ""
}
}
+"Add"
}
h3 {
ul {
for ((index, item) in items.withIndex()) {
li {
key = index.toString()
+item.toString()
button {
onClick = {
items = items.filterIndexed { i, _ -> i != index }
}
+"×"
}
}
}
}
}
}
}
val TodoApp = VFC {
val items = useMemo { listOf("Hello", "World") }
Todo {
initialItems = items
}
}