From 870fd9ba525d117b1e9cc1227ea8ddc33204e747 Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Tue, 3 Apr 2018 17:22:17 +0200 Subject: Navigation bar fix. --- .../kotlin/pl/treksoft/kvision/navbar/Navbar.kt | 24 ++++++++++++++-------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt b/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt index 7e83c764..b2ab58da 100644 --- a/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt +++ b/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt @@ -33,7 +33,7 @@ enum class NavbarType(internal val navbarType: String) { * @param init an initializer extension function */ open class Navbar( - label: String = "", + label: String? = null, type: NavbarType? = null, inverted: Boolean = false, classes: Set = setOf(), init: (Navbar.() -> Unit)? = null @@ -43,9 +43,14 @@ open class Navbar( * The navbar header label. */ var label - get() = brandLink.label + get() = if (brandLink.visible) brandLink.label else null set(value) { - brandLink.label = value + if (value != null) { + brandLink.label = value + brandLink.show() + } else { + brandLink.hide() + } } /** @@ -59,7 +64,7 @@ open class Navbar( private val idc = "kv_navbar_$counter" - private val brandLink = Link(label, "#", classes = setOf("navbar-brand")) + private val brandLink = Link(label ?: "", "#", classes = setOf("navbar-brand")) internal val container = SimplePanel(setOf("collapse", "navbar-collapse")) { id = idc } @@ -73,6 +78,7 @@ open class Navbar( add(container) } addInternal(c) + if (label == null) brandLink.hide() counter++ @Suppress("LeakingThis") init?.invoke(this) @@ -128,15 +134,15 @@ open class Navbar( * * It takes the same parameters as the constructor of the built component. */ - fun Container.navbarPanel( - text: String = "", + fun Container.navbar( + label: String? = null, type: NavbarType? = null, inverted: Boolean = false, classes: Set = setOf(), init: (Navbar.() -> Unit)? = null ): Navbar { - val navbarPanel = Navbar(text, type, inverted, classes, init) - this.add(navbarPanel) - return navbarPanel + val navbar = Navbar(label, type, inverted, classes, init) + this.add(navbar) + return navbar } } } -- cgit