diff options
author | Robert Jaros <rjaros@finn.pl> | 2018-04-03 16:52:53 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2018-04-03 16:52:53 +0200 |
commit | 28c3db7e059982607b56efa71c3aece07f3e2794 (patch) | |
tree | c2053c5073bf6b51f06aad1e547153ec4319ce97 /src/main/kotlin/pl/treksoft/kvision | |
parent | 447a1e59796c42e1c274ea23eb6afc410d624611 (diff) | |
download | kvision-28c3db7e059982607b56efa71c3aece07f3e2794.tar.gz kvision-28c3db7e059982607b56efa71c3aece07f3e2794.tar.bz2 kvision-28c3db7e059982607b56efa71c3aece07f3e2794.zip |
Support for dropdown button without caret.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt | 40 |
1 files changed, 30 insertions, 10 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt index 70b63c9f..5f5f789c 100644 --- a/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt +++ b/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt @@ -58,12 +58,13 @@ enum class DD(val option: String) { * @param style the style of the dropdown button * @param disabled determines if the component is disabled on start * @param forNavbar determines if the component will be used in a navbar + * @param withCaret determines if the dropdown button renders caret * @param classes a set of CSS class names */ open class DropDown( text: String, elements: List<StringPair>? = null, icon: String? = null, style: ButtonStyle = ButtonStyle.DEFAULT, disabled: Boolean = false, val forNavbar: Boolean = false, - classes: Set<String> = setOf() + withCaret: Boolean = true, classes: Set<String> = setOf() ) : SimplePanel(classes) { /** * Label of the dropdown button. @@ -139,7 +140,7 @@ open class DropDown( private val idc = "kv_dropdown_$counter" internal val button: DropDownButton = DropDownButton( idc, text, icon, style, - disabled, forNavbar, setOf("dropdown") + disabled, forNavbar, withCaret, setOf("dropdown") ) internal val list: DropDownListTag = DropDownListTag(idc, setOf("dropdown-menu")) @@ -244,10 +245,19 @@ open class DropDown( fun Container.dropDown( text: String, elements: List<StringPair>? = null, icon: String? = null, style: ButtonStyle = ButtonStyle.DEFAULT, disabled: Boolean = false, forNavbar: Boolean = false, - classes: Set<String> = setOf(), init: (DropDown.() -> Unit)? = null + withCaret: Boolean = true, classes: Set<String> = setOf(), init: (DropDown.() -> Unit)? = null ): DropDown { val dropDown = - DropDown(text, elements, icon, style, disabled, forNavbar, classes).apply { init?.invoke(this) } + DropDown( + text, + elements, + icon, + style, + disabled, + forNavbar, + withCaret, + classes + ).apply { init?.invoke(this) } this.add(dropDown) return dropDown } @@ -255,8 +265,14 @@ open class DropDown( } internal class DropDownButton( - id: String, text: String, icon: String? = null, style: ButtonStyle = ButtonStyle.DEFAULT, - disabled: Boolean = false, val forNavbar: Boolean = false, classes: Set<String> = setOf() + id: String, + text: String, + icon: String? = null, + style: ButtonStyle = ButtonStyle.DEFAULT, + disabled: Boolean = false, + val forNavbar: Boolean = false, + val withCaret: Boolean = true, + classes: Set<String> = setOf() ) : Button(text, icon, style, ButtonType.BUTTON, disabled, classes) { @@ -273,10 +289,14 @@ internal class DropDownButton( override fun render(): VNode { val text = createLabelWithIcon(text, icon, image) return if (forNavbar) { - val textWithCarret = text.toMutableList() - textWithCarret.add(" ") - textWithCarret.add(KVManager.virtualize("<span class='caret'></span>")) - render("a", textWithCarret.toTypedArray()) + if (withCaret) { + val textWithCarret = text.toMutableList() + textWithCarret.add(" ") + textWithCarret.add(KVManager.virtualize("<span class='caret'></span>")) + render("a", textWithCarret.toTypedArray()) + } else { + render("a", text) + } } else { render("button", text) } |