aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2020-05-09 23:53:57 +0200
committerRobert Jaros <rjaros@finn.pl>2020-05-09 23:53:57 +0200
commit134cb687c4e05fd81a03b682505f9fb9d741a8d7 (patch)
treef9f41f28c01dc29d1d4fdd576cc9b21958fd9c3b /kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar
parent4a2aa49e0e561c1bc25aa962449fa2fcce9207ba (diff)
downloadkvision-134cb687c4e05fd81a03b682505f9fb9d741a8d7.tar.gz
kvision-134cb687c4e05fd81a03b682505f9fb9d741a8d7.tar.bz2
kvision-134cb687c4e05fd81a03b682505f9fb9d741a8d7.zip
Add new className parameter to all DSL builder functions.
Diffstat (limited to 'kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar')
-rw-r--r--kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt26
-rw-r--r--kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt8
-rw-r--r--kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt19
3 files changed, 41 insertions, 12 deletions
diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt
index 1254e0c9..98383141 100644
--- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt
+++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt
@@ -25,6 +25,7 @@ import pl.treksoft.kvision.core.ResString
import pl.treksoft.kvision.core.StringBoolPair
import pl.treksoft.kvision.html.Div
import pl.treksoft.kvision.html.Link
+import pl.treksoft.kvision.utils.set
/**
* The Bootstrap Nav container.
@@ -63,9 +64,12 @@ open class Nav(rightAlign: Boolean = false, classes: Set<String> = setOf(), init
* It takes the same parameters as the constructor of the built component.
*/
fun Navbar.nav(
- rightAlign: Boolean = false, classes: Set<String> = setOf(), init: (Nav.() -> Unit)? = null
+ rightAlign: Boolean = false,
+ classes: Set<String>? = null,
+ className: String? = null,
+ init: (Nav.() -> Unit)? = null
): Nav {
- val nav = Nav(rightAlign, classes).apply { init?.invoke(this) }
+ val nav = Nav(rightAlign, classes ?: className.set).apply { init?.invoke(this) }
this.add(nav)
return nav
}
@@ -77,9 +81,11 @@ fun Navbar.nav(
*/
fun Nav.navLink(
label: String, url: String? = null, icon: String? = null, image: ResString? = null,
- classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
+ classes: Set<String>? = null,
+ className: String? = null,
+ init: (Link.() -> Unit)? = null
): Link {
- val link = Link(label, url, icon, image, classes + "nav-item" + "nav-link").apply {
+ val link = Link(label, url, icon, image, null, true, (classes ?: className.set) + "nav-item" + "nav-link").apply {
init?.invoke(this)
}
this.add(link)
@@ -93,10 +99,18 @@ fun Nav.navLink(
*/
fun Nav.navLinkDisabled(
label: String, icon: String? = null, image: ResString? = null,
- classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
+ classes: Set<String>? = null,
+ className: String? = null,
+ init: (Link.() -> Unit)? = null
): Link {
val link =
- Link(label, "javascript:void(0)", icon, image, classes + "nav-item" + "nav-link" + "disabled").apply {
+ Link(
+ label,
+ "javascript:void(0)",
+ icon,
+ image, null, true,
+ (classes ?: className.set) + "nav-item" + "nav-link" + "disabled"
+ ).apply {
tabindex = -1
setAttribute("aria-disabled", "true")
init?.invoke(this)
diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt
index 6cbf6274..37bd566e 100644
--- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt
+++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt
@@ -24,6 +24,7 @@ package pl.treksoft.kvision.navbar
import pl.treksoft.kvision.core.StringBoolPair
import pl.treksoft.kvision.html.TAG
import pl.treksoft.kvision.html.Tag
+import pl.treksoft.kvision.utils.set
/**
* The Bootstrap Nav form container.
@@ -62,9 +63,12 @@ open class NavForm(rightAlign: Boolean = false, classes: Set<String> = setOf(),
* It takes the same parameters as the constructor of the built component.
*/
fun Navbar.navForm(
- rightAlign: Boolean = false, classes: Set<String> = setOf(), init: (NavForm.() -> Unit)? = null
+ rightAlign: Boolean = false,
+ classes: Set<String>? = null,
+ className: String? = null,
+ init: (NavForm.() -> Unit)? = null
): NavForm {
- val navForm = NavForm(rightAlign, classes).apply { init?.invoke(this) }
+ val navForm = NavForm(rightAlign, classes ?: className.set).apply { init?.invoke(this) }
this.add(navForm)
return navForm
}
diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt
index 81e061e8..6ba85b63 100644
--- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt
+++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt
@@ -32,6 +32,7 @@ import pl.treksoft.kvision.html.Link
import pl.treksoft.kvision.html.Span
import pl.treksoft.kvision.html.span
import pl.treksoft.kvision.panel.SimplePanel
+import pl.treksoft.kvision.utils.set
/**
* Navbar types.
@@ -99,6 +100,7 @@ open class Navbar(
brandLink.hide()
}
}
+
/**
* The navbar header link.
*/
@@ -112,14 +114,17 @@ open class Navbar(
* The navbar type.
*/
var type by refreshOnUpdate(type)
+
/**
* The navbar responsive behavior.
*/
var expand by refreshOnUpdate(expand)
+
/**
* The navbar color.
*/
var nColor by refreshOnUpdate(nColor)
+
/**
* The navbar background color.
*/
@@ -215,15 +220,21 @@ fun Container.navbar(
nColor: NavbarColor = NavbarColor.LIGHT,
bgColor: BsBgColor = BsBgColor.LIGHT,
collapseOnClick: Boolean = false,
- classes: Set<String> = setOf(), init: (Navbar.() -> Unit)? = null
+ classes: Set<String>? = null,
+ className: String? = null,
+ init: (Navbar.() -> Unit)? = null
): Navbar {
- val navbar = Navbar(label, link, type, expand, nColor, bgColor, collapseOnClick, classes, init)
+ val navbar = Navbar(label, link, type, expand, nColor, bgColor, collapseOnClick, classes ?: className.set, init)
this.add(navbar)
return navbar
}
-fun Navbar.navText(label: String, classes: Set<String> = setOf()): Span {
- val text = Span(label, classes = classes + "navbar-text")
+fun Navbar.navText(
+ label: String,
+ classes: Set<String>? = null,
+ className: String? = null
+): Span {
+ val text = Span(label, classes = (classes ?: className.set) + "navbar-text")
this.add(text)
return text
}