aboutsummaryrefslogtreecommitdiff
path: root/src/main/kotlin/pl/treksoft/kvision/navbar
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-10-03 19:03:21 +0200
committerRobert Jaros <rjaros@finn.pl>2019-10-03 19:03:21 +0200
commit6b53324c97bfc80ed14dfca6a5dbc879950715b9 (patch)
tree55c7bb7d06e37470795a93e1f542e51ef3f1ace6 /src/main/kotlin/pl/treksoft/kvision/navbar
parent22a8d5c35db97d65a90b21d97e6835380191845d (diff)
downloadkvision-6b53324c97bfc80ed14dfca6a5dbc879950715b9.tar.gz
kvision-6b53324c97bfc80ed14dfca6a5dbc879950715b9.tar.bz2
kvision-6b53324c97bfc80ed14dfca6a5dbc879950715b9.zip
Upgrade to Bootstrap 4.
Upgrade to Font Awesome 5. Restructure modules.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/navbar')
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt73
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt74
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt195
3 files changed, 0 insertions, 342 deletions
diff --git a/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt b/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt
deleted file mode 100644
index 3bbb6eed..00000000
--- a/src/main/kotlin/pl/treksoft/kvision/navbar/Nav.kt
+++ /dev/null
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2017-present Robert Jaros
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package pl.treksoft.kvision.navbar
-
-import pl.treksoft.kvision.core.StringBoolPair
-import pl.treksoft.kvision.html.TAG
-import pl.treksoft.kvision.html.Tag
-
-/**
- * The Bootstrap Nav container.
- *
- * @constructor
- * @param rightAlign determines if the nav is aligned to the right
- * @param classes a set of CSS class names
- * @param init an initializer extension function
- */
-open class Nav(rightAlign: Boolean = false, classes: Set<String> = setOf(), init: (Nav.() -> Unit)? = null) :
- Tag(TAG.UL, classes = classes) {
-
- /**
- * Determines if the nav is aligned to the right.
- */
- var rightAlign by refreshOnUpdate(rightAlign)
-
- init {
- @Suppress("LeakingThis")
- init?.invoke(this)
- }
-
- override fun getSnClass(): List<StringBoolPair> {
- val cl = super.getSnClass().toMutableList()
- cl.add("nav" to true)
- cl.add("navbar-nav" to true)
- if (rightAlign) {
- cl.add("navbar-right" to true)
- }
- return cl
- }
-
- companion object {
- /**
- * DSL builder extension function.
- *
- * 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
- ): Nav {
- val nav = Nav(rightAlign, classes).apply { init?.invoke(this) }
- this.add(nav)
- return nav
- }
- }
-}
diff --git a/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt b/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt
deleted file mode 100644
index 725c298e..00000000
--- a/src/main/kotlin/pl/treksoft/kvision/navbar/NavForm.kt
+++ /dev/null
@@ -1,74 +0,0 @@
-/*
- * Copyright (c) 2017-present Robert Jaros
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package pl.treksoft.kvision.navbar
-
-import pl.treksoft.kvision.core.StringBoolPair
-import pl.treksoft.kvision.html.TAG
-import pl.treksoft.kvision.html.Tag
-
-/**
- * The Bootstrap Nav form container.
- *
- * @constructor
- * @param rightAlign determines if the nav form is aligned to the right
- * @param classes a set of CSS class names
- * @param init an initializer extension function
- */
-open class NavForm(rightAlign: Boolean = false, classes: Set<String> = setOf(), init: (NavForm.() -> Unit)? = null) :
- Tag(TAG.FORM, classes = classes) {
-
- /**
- * Determines if the nav form is aligned to the right.
- */
- var rightAlign by refreshOnUpdate(rightAlign)
-
- init {
- @Suppress("LeakingThis")
- init?.invoke(this)
- }
-
- override fun getSnClass(): List<StringBoolPair> {
- val cl = super.getSnClass().toMutableList()
- cl.add("navbar-form" to true)
- if (rightAlign) {
- cl.add("navbar-right" to true)
- } else {
- cl.add("navbar-left" to true)
- }
- return cl
- }
-
- companion object {
- /**
- * DSL builder extension function.
- *
- * 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
- ): NavForm {
- val navForm = NavForm(rightAlign, classes).apply { init?.invoke(this) }
- this.add(navForm)
- return navForm
- }
- }
-}
diff --git a/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt b/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt
deleted file mode 100644
index 2080bb8e..00000000
--- a/src/main/kotlin/pl/treksoft/kvision/navbar/Navbar.kt
+++ /dev/null
@@ -1,195 +0,0 @@
-/*
- * Copyright (c) 2017-present Robert Jaros
- *
- * Permission is hereby granted, free of charge, to any person obtaining a copy
- * of this software and associated documentation files (the "Software"), to deal
- * in the Software without restriction, including without limitation the rights
- * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
- * copies of the Software, and to permit persons to whom the Software is
- * furnished to do so, subject to the following conditions:
- *
- * The above copyright notice and this permission notice shall be included in all
- * copies or substantial portions of the Software.
- *
- * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
- * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
- * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
- * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
- * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
- * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
- * SOFTWARE.
- */
-package pl.treksoft.kvision.navbar
-
-import com.github.snabbdom.VNode
-import pl.treksoft.kvision.core.Component
-import pl.treksoft.kvision.core.Container
-import pl.treksoft.kvision.core.StringBoolPair
-import pl.treksoft.kvision.core.StringPair
-import pl.treksoft.kvision.html.Link
-import pl.treksoft.kvision.html.TAG
-import pl.treksoft.kvision.html.Tag.Companion.tag
-import pl.treksoft.kvision.panel.SimplePanel
-
-/**
- * Navbar types.
- */
-enum class NavbarType(internal val navbarType: String) {
- FIXEDTOP("navbar-fixed-top"),
- FIXEDBOTTOM("navbar-fixed-bottom"),
- STATICTOP("navbar-static-top")
-}
-
-/**
- * The Bootstrap Navbar container.
- *
- * @constructor
- * @param label the navbar label
- * @param type the navbar type
- * @param inverted determines if the navbar is inverted
- * @param classes a set of CSS class names
- * @param init an initializer extension function
- */
-open class Navbar(
- label: String? = null,
- type: NavbarType? = null,
- inverted: Boolean = false,
- classes: Set<String> = setOf(), init: (Navbar.() -> Unit)? = null
-) : SimplePanel(classes) {
-
- /**
- * The navbar header label.
- */
- var label
- get() = if (brandLink.visible) brandLink.label else null
- set(value) {
- if (value != null) {
- brandLink.label = value
- brandLink.show()
- } else {
- brandLink.hide()
- }
- }
-
- /**
- * The navbar type.
- */
- var type by refreshOnUpdate(type)
- /**
- * Determines if the navbar is inverted.
- */
- var inverted by refreshOnUpdate(inverted)
-
- private val idc = "kv_navbar_$counter"
-
- private val brandLink = Link(label ?: "", "#", classes = setOf("navbar-brand"))
- internal val container = SimplePanel(setOf("collapse", "navbar-collapse")) {
- id = idc
- }
-
- init {
- val c = SimplePanel(setOf("container-fluid")) {
- simplePanel(setOf("navbar-header")) {
- add(NavbarButton(idc))
- add(brandLink)
- }
- add(container)
- }
- addInternal(c)
- if (label == null) brandLink.hide()
- counter++
- @Suppress("LeakingThis")
- init?.invoke(this)
- }
-
- override fun render(): VNode {
- return render("nav", childrenVNodes())
- }
-
- override fun add(child: Component): Navbar {
- container.add(child)
- return this
- }
-
- override fun addAll(children: List<Component>): Navbar {
- container.addAll(children)
- return this
- }
-
- override fun remove(child: Component): Navbar {
- container.remove(child)
- return this
- }
-
- override fun removeAll(): Navbar {
- container.removeAll()
- return this
- }
-
- override fun getChildren(): List<Component> {
- return container.getChildren()
- }
-
- override fun getSnClass(): List<StringBoolPair> {
- val cl = super.getSnClass().toMutableList()
- cl.add("navbar" to true)
- type?.let {
- cl.add(it.navbarType to true)
- }
- if (inverted) {
- cl.add("navbar-inverse" to true)
- } else {
- cl.add("navbar-default" to true)
- }
- return cl
- }
-
- companion object {
- internal var counter = 0
-
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Container.navbar(
- label: String? = null,
- type: NavbarType? = null,
- inverted: Boolean = false,
- classes: Set<String> = setOf(), init: (Navbar.() -> Unit)? = null
- ): Navbar {
- val navbar = Navbar(label, type, inverted, classes, init)
- this.add(navbar)
- return navbar
- }
- }
-}
-
-/**
- * @suppress
- * Internal component.
- * The Bootstrap Navbar header button.
- */
-internal class NavbarButton(private val idc: String, toggle: String = "Toggle navigation") :
- SimplePanel(setOf("navbar-toggle", "collapsed")) {
-
- init {
- tag(TAG.SPAN, toggle, classes = setOf("sr-only"))
- tag(TAG.SPAN, classes = setOf("icon-bar"))
- tag(TAG.SPAN, classes = setOf("icon-bar"))
- tag(TAG.SPAN, classes = setOf("icon-bar"))
- }
-
- override fun render(): VNode {
- return render("button", childrenVNodes())
- }
-
- override fun getSnAttrs(): List<StringPair> {
- return super.getSnAttrs() + listOf(
- "type" to "button",
- "data-toggle" to "collapse",
- "data-target" to "#$idc",
- "aria-expanded" to "false"
- )
- }
-}