aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/dropdown
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/dropdown')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt34
1 files changed, 12 insertions, 22 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
index eef229e4..1a3f63c9 100644
--- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
@@ -1,23 +1,27 @@
package pl.treksoft.kvision.dropdown
-import com.github.snabbdom.VNode
-import com.github.snabbdom.h
import pl.treksoft.kvision.core.Container
-import pl.treksoft.kvision.core.KVManager
import pl.treksoft.kvision.core.ResString
import pl.treksoft.kvision.html.*
import pl.treksoft.kvision.snabbdom.StringPair
-open class DropDown(text: String, elements: List<String>, icon: String? = null, style: BUTTON_STYLE = BUTTON_STYLE.DEFAULT, size: BUTTON_SIZE? = null,
+open class DropDown(text: String, elements: List<StringPair>, icon: String? = null, style: BUTTON_STYLE = BUTTON_STYLE.DEFAULT, size: BUTTON_SIZE? = null,
block: Boolean = false, disabled: Boolean = false, image: ResString? = null, classes: Set<String> = setOf()) : Container(classes) {
- val idk = "abc"
- val button: DropDownButton = DropDownButton(idk, text, icon, style, size, block, disabled, image, setOf("dropdown"))
- val list: DropDownListTag = DropDownListTag(idk, elements, setOf("dropdown-menu"))
+ val idc = "kv_dropdown_" + counter
+ val button: DropDownButton = DropDownButton(idc, text, icon, style, size, block, disabled, image, setOf("dropdown"))
+ val list: DropDownListTag = DropDownListTag(idc, setOf("dropdown-menu"))
init {
this.addCssClass("dropdown")
+ val children = elements.map { Link(it.first, it.second) }
+ list.addAll(children)
this.add(button)
this.add(list)
+ counter++
+ }
+
+ companion object {
+ var counter = 0
}
}
@@ -34,21 +38,7 @@ open class DropDownButton(id: String, text: String, icon: String? = null, style:
}
}
-open class DropDownListTag(val ariaId: String, elements: List<String>, classes: Set<String> = setOf()) : ListTag(LIST.UL, elements, true, classes) {
-
- override fun render(): VNode {
- val children = elements.map { el -> element("li", el, true) }.toTypedArray()
- return kvh(type.tagName, children)
- }
-
- private fun element(name: String, value: String, rich: Boolean): VNode {
- if (rich) {
- return h(name, arrayOf(KVManager.virtualize("<a href='#'>$value</a>")))
- } else {
- return h(name, value)
- }
- }
-
+open class DropDownListTag(val ariaId: String, classes: Set<String> = setOf()) : ListTag(LIST.UL, null, false, classes) {
override fun getSnAttrs(): List<StringPair> {
return super.getSnAttrs() + listOf("aria-labelledby" to ariaId)
}