mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-09-21 01:56:11 +00:00
64 lines
1.9 KiB
Kotlin
64 lines
1.9 KiB
Kotlin
package dev.inmo.jsuikit.elements
|
|
|
|
import androidx.compose.runtime.Composable
|
|
import androidx.compose.runtime.snapshots.SnapshotStateList
|
|
import dev.inmo.jsuikit.modifiers.*
|
|
import org.jetbrains.compose.web.attributes.AttrsBuilder
|
|
import org.jetbrains.compose.web.dom.*
|
|
import org.jetbrains.compose.web.dom.Text
|
|
import org.w3c.dom.*
|
|
|
|
@Composable
|
|
fun <T> DefaultTable(
|
|
heading: List<String>,
|
|
dataList: SnapshotStateList<T>,
|
|
vararg tableModifiers: UIKitModifier,
|
|
attributesCustomizer: AttrBuilderContext<HTMLTableElement> = {},
|
|
headerCellCustomizer: AttrsBuilder<HTMLTableCellElement>.(i: Int, title: String) -> Unit = { _, _ -> },
|
|
rowAttributes: AttrsBuilder<HTMLTableRowElement>.(t: T) -> Unit = {},
|
|
cellCustomizer: AttrsBuilder<HTMLTableCellElement>.(i: Int, t: T) -> Unit = { _, _ -> },
|
|
cellFiller: @Composable ElementScope<HTMLTableCellElement>.(i: Int, t: T) -> Unit
|
|
) {
|
|
val headingIndexes = heading.indices
|
|
Table(
|
|
{
|
|
classes("uk-table")
|
|
include(*tableModifiers)
|
|
attributesCustomizer()
|
|
}
|
|
) {
|
|
Thead {
|
|
Tr {
|
|
heading.forEachIndexed { i, t ->
|
|
Th(
|
|
{
|
|
headerCellCustomizer(i, t)
|
|
}
|
|
) {
|
|
Text(t)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
Tbody {
|
|
dataList.forEach {
|
|
Tr(
|
|
{
|
|
rowAttributes(it)
|
|
}
|
|
) {
|
|
headingIndexes.forEach { i ->
|
|
Td(
|
|
{
|
|
cellCustomizer(i, it)
|
|
}
|
|
) {
|
|
cellFiller(i, it)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|