diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-02-12 10:50:42 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-02-12 10:50:42 +0100 |
commit | bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c (patch) | |
tree | 39288bdcb59ec48cb70f1c5820fc1854949744da /src/main/kotlin/pl/treksoft/kvision/dropdown | |
parent | 2feea5e7cf8d492663e826ebcfb0a58e61820352 (diff) | |
download | kvision-bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c.tar.gz kvision-bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c.tar.bz2 kvision-bafcdb6fc3f1d4ec4f1a0f4fcce776ba10d8136c.zip |
Type safe DSL builders
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/dropdown')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt index b80c6dc5..1af71dc8 100644 --- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt @@ -23,6 +23,7 @@ package pl.treksoft.kvision.dropdown import com.github.snabbdom.VNode import pl.treksoft.kvision.core.Component +import pl.treksoft.kvision.core.Container import pl.treksoft.kvision.core.CssSize import pl.treksoft.kvision.core.StringBoolPair import pl.treksoft.kvision.core.StringPair @@ -154,10 +155,6 @@ open class DropDown( counter++ } - companion object { - internal var counter = 0 - } - override fun add(child: Component): SimplePanel { list.add(child) return this @@ -237,6 +234,23 @@ open class DropDown( open fun toggle() { this.list.getElementJQueryD()?.dropdown("toggle") } + + companion object { + internal var counter = 0 + + /** + * DSL builder extension function + * + * It takes the same parameters as the constructor of the built component. + */ + fun Container.dropDown( + text: String, elements: List<StringPair>? = null, icon: String? = null, + style: BUTTONSTYLE = BUTTONSTYLE.DEFAULT, disabled: Boolean = false, + classes: Set<String> = setOf(), init: (DropDown.() -> Unit)? = null + ) { + this.add(DropDown(text, elements, icon, style, disabled, classes).apply { init?.invoke(this) }) + } + } } internal class DropDownButton( |