2022-01-12 10:27:49 +00:00
|
|
|
package dev.inmo.jsuikit.elements
|
2021-12-22 08:38:12 +00:00
|
|
|
|
|
|
|
import androidx.compose.runtime.Composable
|
|
|
|
import androidx.compose.runtime.snapshots.SnapshotStateList
|
2022-04-27 10:13:58 +00:00
|
|
|
import dev.inmo.jsuikit.modifiers.*
|
|
|
|
import dev.inmo.jsuikit.utils.Attrs
|
2021-12-22 08:38:12 +00:00
|
|
|
import org.jetbrains.compose.web.dom.*
|
2022-01-13 05:55:08 +00:00
|
|
|
import org.w3c.dom.HTMLHeadingElement
|
2021-12-22 08:38:12 +00:00
|
|
|
import org.w3c.dom.HTMLUListElement
|
|
|
|
|
2022-04-27 10:13:58 +00:00
|
|
|
@Composable
|
|
|
|
fun <T> List(
|
2022-11-15 18:45:10 +00:00
|
|
|
data: Iterable<T>,
|
2022-04-27 10:13:58 +00:00
|
|
|
ukAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
|
|
|
elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit
|
|
|
|
) {
|
|
|
|
Ul(
|
|
|
|
{
|
|
|
|
include(UIKitList)
|
|
|
|
ukAttrs.builder(this)
|
|
|
|
}
|
|
|
|
) {
|
|
|
|
data.forEach {
|
|
|
|
elementAllocator(it)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-22 08:38:12 +00:00
|
|
|
@Composable
|
2022-04-27 10:24:57 +00:00
|
|
|
fun <T> ListWithTitle(
|
2021-12-22 08:38:12 +00:00
|
|
|
title: String,
|
2022-11-15 18:45:10 +00:00
|
|
|
data: Iterable<T>,
|
2022-01-13 13:56:39 +00:00
|
|
|
vararg titleModifiers: UIKitModifier,
|
2021-12-22 08:38:12 +00:00
|
|
|
ulModifiers: Array<UIKitModifier> = emptyArray(),
|
|
|
|
besidesTitleAndList: (@Composable () -> Unit)? = null,
|
2022-01-13 07:49:58 +00:00
|
|
|
titleCustomizer: AttrBuilderContext<HTMLHeadingElement> = {},
|
|
|
|
ulCustomizer: AttrBuilderContext<HTMLUListElement> = {},
|
2021-12-22 08:38:12 +00:00
|
|
|
elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit
|
|
|
|
) {
|
2022-01-13 05:55:08 +00:00
|
|
|
H4({ include(*titleModifiers); titleCustomizer() }) {
|
2021-12-22 08:38:12 +00:00
|
|
|
Text(title)
|
|
|
|
}
|
|
|
|
besidesTitleAndList ?.invoke()
|
2022-04-27 10:13:58 +00:00
|
|
|
List(data, Attrs(*ulModifiers) { ulCustomizer(this) }, elementAllocator)
|
2021-12-22 08:38:12 +00:00
|
|
|
}
|