aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/panel
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2018-03-22 20:23:54 +0100
committerRobert Jaros <rjaros@finn.pl>2018-03-22 20:23:54 +0100
commit7081cfaed23fe8b34bfdf15918775a846d7649e0 (patch)
tree15458e3d7fb2cc0ebf32281362ba44f82d27fa0b /src/main/kotlin/pl/treksoft/kvision/panel
parent6ba1eefc59a2940a7258655da4e88b4118e61746 (diff)
downloadkvision-7081cfaed23fe8b34bfdf15918775a846d7649e0.tar.gz
kvision-7081cfaed23fe8b34bfdf15918775a846d7649e0.tar.bz2
kvision-7081cfaed23fe8b34bfdf15918775a846d7649e0.zip
Context menu component based on Bootstrap dropdown.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/panel')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/panel/Root.kt22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
index a51191d4..7ab68fdd 100644
--- a/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/panel/Root.kt
@@ -25,6 +25,7 @@ import com.github.snabbdom.VNode
import com.github.snabbdom.h
import pl.treksoft.kvision.KVManager
import pl.treksoft.kvision.core.StringBoolPair
+import pl.treksoft.kvision.dropdown.ContextMenu
import pl.treksoft.kvision.modal.Modal
import pl.treksoft.kvision.utils.snClasses
import pl.treksoft.kvision.utils.snOpt
@@ -44,6 +45,7 @@ import pl.treksoft.kvision.utils.snOpt
*/
class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Unit)? = null) : SimplePanel() {
private val modals: MutableList<Modal> = mutableListOf()
+ private val contextMenus: MutableList<ContextMenu> = mutableListOf()
private var rootVnode: VNode = renderVNode()
internal var renderDisabled = false
@@ -60,9 +62,9 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni
return if (!fixed) {
render("div#$id", arrayOf(h("div", snOpt {
`class` = snClasses(listOf("row" to true))
- }, childrenVNodes() + modalsVNodes())))
+ }, childrenVNodes() + modalsVNodes() + contextMenusVNodes())))
} else {
- render("div#$id", childrenVNodes() + modalsVNodes())
+ render("div#$id", childrenVNodes() + modalsVNodes() + contextMenusVNodes())
}
}
@@ -72,10 +74,26 @@ class Root(id: String, private val fixed: Boolean = false, init: (Root.() -> Uni
refresh()
}
+ internal fun addContextMenu(contextMenu: ContextMenu) {
+ contextMenus.add(contextMenu)
+ contextMenu.parent = this
+ this.setInternalEventListener<Root> {
+ click = { e ->
+ @Suppress("UnsafeCastFromDynamic")
+ if (!e.asDynamic().dropDownCM) contextMenu.hide()
+ }
+ }
+ refresh()
+ }
+
private fun modalsVNodes(): Array<VNode> {
return modals.filter { it.visible }.map { it.renderVNode() }.toTypedArray()
}
+ private fun contextMenusVNodes(): Array<VNode> {
+ return contextMenus.filter { it.visible }.map { it.renderVNode() }.toTypedArray()
+ }
+
override fun getSnClass(): List<StringBoolPair> {
val css = if (!fixed) "container-fluid" else "container"
return super.getSnClass() + (css to true)