mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-12-27 19:17:15 +00:00
DescriptionList
This commit is contained in:
parent
f77c21ac51
commit
b836fe744e
@ -6,6 +6,7 @@
|
||||
* Add `UIKitPlaceholder`
|
||||
* `UIKitForm#Custom` now have nullable param target
|
||||
* Add `UIKitUtility#Link`
|
||||
* Add `DescriptionList` and several support composable functions
|
||||
|
||||
## 0.0.40
|
||||
|
||||
|
@ -0,0 +1,57 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitDescriptionList
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
import org.jetbrains.compose.web.dom.ContentBuilder
|
||||
import org.jetbrains.compose.web.dom.ElementScope
|
||||
import org.w3c.dom.HTMLDListElement
|
||||
import org.w3c.dom.HTMLElement
|
||||
|
||||
@Composable
|
||||
fun DescriptionList(
|
||||
attrs: Attrs<HTMLDListElement>,
|
||||
contentBuilder: ContentBuilder<HTMLDListElement>
|
||||
) {
|
||||
DList(
|
||||
{
|
||||
include(UIKitDescriptionList)
|
||||
attrs.builder(this)
|
||||
},
|
||||
contentBuilder
|
||||
)
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> DescriptionList(
|
||||
data: Iterable<T>,
|
||||
attrs: Attrs<HTMLDListElement>,
|
||||
beforeTermContent: (@Composable ElementScope<HTMLElement>.(Int, T) -> Unit)? = null,
|
||||
itemTermAttrs: ((Int, T) -> Attrs<HTMLElement>?)? = null,
|
||||
itemTermContent: (@Composable ElementScope<HTMLElement>.(Int, T) -> Unit)? = null,
|
||||
betweenTermAndDescriptionContent: (@Composable ElementScope<HTMLElement>.(Int, T) -> Unit)? = null,
|
||||
afterDescriptionContent: (@Composable ElementScope<HTMLElement>.(Int, T) -> Unit)? = null,
|
||||
itemDescriptionAttrs: ((Int, T) -> Attrs<HTMLElement>?)? = null,
|
||||
itemDescriptionContent: (@Composable ElementScope<HTMLElement>.(Int, T) -> Unit)? = null
|
||||
) {
|
||||
DescriptionList(attrs) {
|
||||
data.forEachIndexed { i, t ->
|
||||
beforeTermContent ?.invoke(this, i, t)
|
||||
if (itemTermAttrs != null || itemTermContent != null) {
|
||||
DTerm(
|
||||
itemTermAttrs ?.let { { it(i, t) } },
|
||||
itemTermContent ?.let { { it(i, t) } },
|
||||
)
|
||||
}
|
||||
betweenTermAndDescriptionContent ?.invoke(this, i, t)
|
||||
if (itemDescriptionAttrs != null || itemDescriptionContent != null) {
|
||||
DDescription(
|
||||
itemDescriptionAttrs ?.let { { it(i, t) } },
|
||||
itemDescriptionContent ?.let { { it(i, t) } },
|
||||
)
|
||||
}
|
||||
afterDescriptionContent ?.invoke(this, i, t)
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,11 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
sealed class UIKitDescriptionList(
|
||||
override val classes: Array<String>
|
||||
) : UIKitModifier {
|
||||
|
||||
object Divider : UIKitDescriptionList(arrayOf("uk-description-list-divider"))
|
||||
|
||||
companion object : UIKitDescriptionList(arrayOf("uk-description-list"))
|
||||
|
||||
}
|
55
src/jsMain/kotlin/dev/inmo/jsuikit/utils/Dlist.kt
Normal file
55
src/jsMain/kotlin/dev/inmo/jsuikit/utils/Dlist.kt
Normal file
@ -0,0 +1,55 @@
|
||||
package dev.inmo.jsuikit.utils
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import kotlinx.browser.document
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.*
|
||||
|
||||
private object DListElementBuilder : ElementBuilder<HTMLDListElement> {
|
||||
private val el: Element by lazy { document.createElement("dl") }
|
||||
override fun create(): HTMLDListElement = el.cloneNode() as HTMLDListElement
|
||||
}
|
||||
|
||||
private object DTermElementBuilder : ElementBuilder<HTMLElement> {
|
||||
private val el: Element by lazy { document.createElement("dt") }
|
||||
override fun create(): HTMLElement = el.cloneNode() as HTMLElement
|
||||
}
|
||||
|
||||
private object DDescriptionElementBuilder : ElementBuilder<HTMLElement> {
|
||||
private val el: Element by lazy { document.createElement("dd") }
|
||||
override fun create(): HTMLElement = el.cloneNode() as HTMLElement
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun DList(
|
||||
attrs: AttrBuilderContext<HTMLDListElement>? = null,
|
||||
content: ContentBuilder<HTMLDListElement>? = null
|
||||
) {
|
||||
TagElement(
|
||||
DListElementBuilder,
|
||||
attrs,
|
||||
content
|
||||
)
|
||||
}
|
||||
@Composable
|
||||
fun DTerm(
|
||||
attrs: AttrBuilderContext<HTMLElement>? = null,
|
||||
content: ContentBuilder<HTMLElement>? = null
|
||||
) {
|
||||
TagElement(
|
||||
DTermElementBuilder,
|
||||
attrs,
|
||||
content
|
||||
)
|
||||
}
|
||||
@Composable
|
||||
fun DDescription(
|
||||
attrs: AttrBuilderContext<HTMLElement>? = null,
|
||||
content: ContentBuilder<HTMLElement>? = null
|
||||
) {
|
||||
TagElement(
|
||||
DDescriptionElementBuilder,
|
||||
attrs,
|
||||
content
|
||||
)
|
||||
}
|
Loading…
Reference in New Issue
Block a user