From 79a1a1573051649b7b2d7b3fcd57d8506eb26bcb Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 1 Sep 2017 16:15:38 +0200 Subject: Testing framework --- .../pl/treksoft/kvision/dropdown/DropDown.kt | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt (limited to 'src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt') diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt new file mode 100644 index 00000000..eef229e4 --- /dev/null +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt @@ -0,0 +1,55 @@ +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, icon: String? = null, style: BUTTON_STYLE = BUTTON_STYLE.DEFAULT, size: BUTTON_SIZE? = null, + block: Boolean = false, disabled: Boolean = false, image: ResString? = null, classes: Set = 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")) + + init { + this.addCssClass("dropdown") + this.add(button) + this.add(list) + } +} + +open class DropDownButton(id: String, text: String, icon: String? = null, style: BUTTON_STYLE = BUTTON_STYLE.DEFAULT, size: BUTTON_SIZE? = null, + block: Boolean = false, disabled: Boolean = false, image: ResString? = null, classes: Set = setOf()) : + Button(text, icon, style, size, block, disabled, image, classes) { + + init { + this.id = id + } + + override fun getSnAttrs(): List { + return super.getSnAttrs() + listOf("data-toggle" to "dropdown", "aria-haspopup" to "true", "aria-expanded" to "false") + } +} + +open class DropDownListTag(val ariaId: String, elements: List, classes: Set = 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("$value"))) + } else { + return h(name, value) + } + } + + override fun getSnAttrs(): List { + return super.getSnAttrs() + listOf("aria-labelledby" to ariaId) + } +} \ No newline at end of file -- cgit