1- import kotlinext.js.Object
21import kotlinx.browser.window
32import kotlinx.css.*
4- import kotlinx.html.Tag
53import kotlinx.html.js.onClickFunction
64import react.RProps
75import react.dom.tr
@@ -12,49 +10,51 @@ import react.table.useTable
1210import styled.*
1311
1412external interface UserTableProps : RProps {
15- var headers: Array <String >
16- var users: Array <User >
13+ var data: Array <out User >
1714}
1815
19- data class User (
20- val name : String ,
21- val age : Int ,
22- )
23-
2416val UserTable = functionalComponent<UserTableProps > { props ->
25- val onRowClick = { user : User ->
26- window.alert(user.name)
17+ val onRowClick = useCallback {
18+ { user : User -> window.alert(user.name) }
2719 }
2820
29- val table = useTable<User > {
30- data = props.users
31- columns = columns {
21+ val columns = useMemo {
22+ columns<User > {
3223 column<String > {
33- header = props.headers[ 0 ]
24+ header = " Name "
3425 accessorFunction = { it.name }
3526 }
3627 column<Int > {
37- header = props.headers[ 1 ]
28+ header = " Age "
3829 accessorFunction = { it.age }
3930 }
4031 }
4132 }
4233
34+ val table = useTable<User > {
35+ this .data = props.data
36+ this .columns = columns
37+ }
38+
4339 styledDiv {
4440 styledTable {
4541 css {
46- width = 100 .pct
42+ width = 400 .px
4743 borderSpacing = 0 .px
4844 borderCollapse = BorderCollapse .collapse
4945 whiteSpace = WhiteSpace .nowrap
46+ borderWidth = 2 .px
47+ borderStyle = BorderStyle .solid
48+ borderColor = Colors .Stroke .Gray
49+ margin(LinearDimension .auto)
5050 }
5151 attrs {
5252 extraAttrs = table.getTableProps()
5353 }
5454 styledThead {
5555 css {
5656 color = Colors .Text .Gray
57- fontSize = 12 .px
57+ fontSize = 18 .px
5858 backgroundColor = Colors .Background .Gray
5959 }
6060
@@ -109,7 +109,7 @@ val UserTable = functionalComponent<UserTableProps> { props ->
109109
110110 styledTr {
111111 css {
112- fontSize = 14 .px
112+ fontSize = 16 .px
113113 cursor = Cursor .pointer
114114 borderBottom = solid(Colors .Stroke .LightGray )
115115 hover {
@@ -119,7 +119,7 @@ val UserTable = functionalComponent<UserTableProps> { props ->
119119
120120 attrs {
121121 extraAttrs = row.getRowProps()
122- onClickFunction = { onRowClick(row.original) }
122+ onClickFunction = { onRowClick()( row.original) }
123123 }
124124
125125 for (cell in row.cells) {
@@ -142,35 +142,8 @@ val UserTable = functionalComponent<UserTableProps> { props ->
142142 }
143143}
144144
145- object Colors {
146- object Text {
147- val Black : Color = Color (" #2E2E2E" )
148- val Gray : Color = Color (" #75829E" )
149- }
150-
151- object Background {
152- val Gray : Color = Color (" #EDEDF3" )
153- val White : Color = Color (" #FFFFFF" )
154- }
155-
156- object Stroke {
157- val LightGray : Color = Color (" #F4F4F4" )
158- val Gray : Color = Color (" #DEE1E9" )
159- }
160- }
161-
162- fun solid (
145+ private fun solid (
163146 color : Color ,
164147 thickness : Int = 1,
165148): String =
166149 " ${thickness} px solid $color "
167-
168- var Tag .extraAttrs: RProps
169- @Deprecated(level = DeprecationLevel .HIDDEN , message = " write only" )
170- get() = error(" write only" )
171- set(value) {
172- for (key in Object .keys(value)) {
173- @Suppress(" UnsafeCastFromDynamic" )
174- attributes[key] = value.asDynamic()[key]
175- }
176- }
0 commit comments