diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-10-21 00:10:20 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-10-21 00:10:20 +0200 |
commit | 534b49cb411427388e9a1d52e32a7e601b49f312 (patch) | |
tree | f5eee1eb53dceb4c1cc6dc9f409e03fc8216055b /src | |
parent | a48be746f3bcfce57761f88cc009b5df802ed8cd (diff) | |
download | kvision-534b49cb411427388e9a1d52e32a7e601b49f312.tar.gz kvision-534b49cb411427388e9a1d52e32a7e601b49f312.tar.bz2 kvision-534b49cb411427388e9a1d52e32a7e601b49f312.zip |
Fix inline list type.
Diffstat (limited to 'src')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/html/List.kt | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/List.kt b/src/main/kotlin/pl/treksoft/kvision/html/List.kt index 1d26007c..af8957ce 100644 --- a/src/main/kotlin/pl/treksoft/kvision/html/List.kt +++ b/src/main/kotlin/pl/treksoft/kvision/html/List.kt @@ -28,6 +28,8 @@ import pl.treksoft.kvision.core.Component import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.StringBoolPair import pl.treksoft.kvision.panel.SimplePanel +import pl.treksoft.kvision.utils.snClasses +import pl.treksoft.kvision.utils.snOpt /** * HTML list types. @@ -79,10 +81,10 @@ open class ListTag( override fun render(): VNode { val childrenElements = when (type) { ListType.UL, ListType.OL, ListType.UNSTYLED, ListType.INLINE -> elements?.map { el -> - element("li", el, rich) + element("li", el, rich, type == ListType.INLINE) } ListType.DL, ListType.DL_HORIZ -> elements?.mapIndexed { index, el -> - element(if (index % 2 == 0) "dt" else "dd", el, rich) + element(if (index % 2 == 0) "dt" else "dd", el, rich, false) } }?.toTypedArray() return if (childrenElements != null) { @@ -100,7 +102,14 @@ open class ListTag( if (v is Tag && v.type == TAG.LI /*|| v is DropDown && v.forNavbar*/) { v.renderVNode() } else { - h("li", arrayOf(v.renderVNode())) + if (type == ListType.INLINE) { + val opt = snOpt { + `class` = snClasses(listOf("list-inline-item" to true)) + } + h("li", opt, arrayOf(v.renderVNode())) + } else { + h("li", arrayOf(v.renderVNode())) + } } } ListType.DL, ListType.DL_HORIZ -> childrenElements.mapIndexed { index, v -> @@ -114,12 +123,19 @@ open class ListTag( return res.toTypedArray() } - private fun element(name: String, value: String, rich: Boolean): VNode { + private fun element(name: String, value: String, rich: Boolean, inline: Boolean): VNode { val translatedValue = translate(value) + val opt = if (inline) { + snOpt { + `class` = snClasses(listOf("list-inline-item" to true)) + } + } else { + snOpt {} + } return if (rich) { - h(name, arrayOf(KVManager.virtualize("<span>$translatedValue</span>"))) + h(name, opt, arrayOf(KVManager.virtualize("<span>$translatedValue</span>"))) } else { - h(name, translatedValue) + h(name, opt, translatedValue) } } |