-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathBoard.kt
46 lines (40 loc) · 1.13 KB
/
Board.kt
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
package tictactoe
import react.RBuilder
import react.RComponent
import react.RProps
import react.RState
import react.dom.div
class Board(): RComponent<Board.Props, RState>() {
fun RBuilder.renderSquare(i: Int) {
square(
value = props.squares[i],
onClickFunction = { props.onClickFunction(i) })
}
override fun RBuilder.render() {
div {
div(classes = "board-row") {
renderSquare(0)
renderSquare(1)
renderSquare(2)
}
div(classes = "board-row") {
renderSquare(3)
renderSquare(4)
renderSquare(5)
}
div(classes = "board-row") {
renderSquare(6)
renderSquare(7)
renderSquare(8)
}
}
}
interface Props: RProps {
var squares: Array<String?>
var onClickFunction: (Int) -> Unit
}
}
fun RBuilder.board(squares: Array<String?>, onClickFunction: (Int) -> Unit) = child(Board::class) {
attrs.squares = squares
attrs.onClickFunction = onClickFunction
}