aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2017-09-01 16:15:38 +0200
committerRobert Jaros <rjaros@finn.pl>2017-09-01 16:15:38 +0200
commit79a1a1573051649b7b2d7b3fcd57d8506eb26bcb (patch)
tree5943cb30d71ccfaa0591edd2ce6204a181fd15e3 /src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
parentfce6a5dcd7804b4ef618484182f8e8ebc053c761 (diff)
downloadkvision-79a1a1573051649b7b2d7b3fcd57d8506eb26bcb.tar.gz
kvision-79a1a1573051649b7b2d7b3fcd57d8506eb26bcb.tar.bz2
kvision-79a1a1573051649b7b2d7b3fcd57d8506eb26bcb.zip
Testing framework
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt55
1 files changed, 55 insertions, 0 deletions
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<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<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"))
+
+ 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<String> = setOf()) :
+ Button(text, icon, style, size, block, disabled, image, classes) {
+
+ init {
+ this.id = id
+ }
+
+ override fun getSnAttrs(): List<StringPair> {
+ return super.getSnAttrs() + listOf("data-toggle" to "dropdown", "aria-haspopup" to "true", "aria-expanded" to "false")
+ }
+}
+
+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)
+ }
+ }
+
+ override fun getSnAttrs(): List<StringPair> {
+ return super.getSnAttrs() + listOf("aria-labelledby" to ariaId)
+ }
+} \ No newline at end of file