aboutsummaryrefslogtreecommitdiff
path: root/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2019-10-17 21:58:34 +0200
committerRobert Jaros <rjaros@finn.pl>2019-10-17 21:58:34 +0200
commit736b80835f67c9c34657074ebcfbe0752bef1c18 (patch)
tree82d1e18a9ec07692dfe5dd31f470b842a9950a89 /kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown
parent53b325d52208bfd44ba6a524ce3dda5379aed699 (diff)
downloadkvision-736b80835f67c9c34657074ebcfbe0752bef1c18.tar.gz
kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.tar.bz2
kvision-736b80835f67c9c34657074ebcfbe0752bef1c18.zip
Move DSL builder functions out of the companion objects (#93)
Diffstat (limited to 'kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown')
-rw-r--r--kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt55
-rw-r--r--kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt181
-rw-r--r--kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Header.kt44
-rw-r--r--kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Separator.kt43
4 files changed, 157 insertions, 166 deletions
diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt
index 4e20de81..656b63b5 100644
--- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt
+++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/ContextMenu.kt
@@ -76,37 +76,36 @@ open class ContextMenu(
}
companion object {
-
const val DEFAULT_FIXED_POS_X = 5
const val DEFAULT_FIXED_POS_Y = 5
+ }
+}
- /**
- * Sets context menu for the current widget.
- * @param contextMenu a context menu
- * @return current widget
- */
- fun Widget.setContextMenu(contextMenu: ContextMenu): Widget {
- this.setEventListener<Widget> {
- contextmenu = { e: MouseEvent ->
- e.preventDefault()
- contextMenu.positionMenu(e)
- }
- }
- return this
- }
-
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun Widget.contextMenu(
- fixedPosition: Boolean = false,
- classes: Set<String> = setOf(), init: (ContextMenu.() -> Unit)? = null
- ): ContextMenu {
- val contextMenu = ContextMenu(this, fixedPosition, classes).apply { init?.invoke(this) }
- this.setContextMenu(contextMenu)
- return contextMenu
+/**
+ * Sets context menu for the current widget.
+ * @param contextMenu a context menu
+ * @return current widget
+ */
+fun Widget.setContextMenu(contextMenu: ContextMenu): Widget {
+ this.setEventListener<Widget> {
+ contextmenu = { e: MouseEvent ->
+ e.preventDefault()
+ contextMenu.positionMenu(e)
}
}
+ return this
+}
+
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun Widget.contextMenu(
+ fixedPosition: Boolean = false,
+ classes: Set<String> = setOf(), init: (ContextMenu.() -> Unit)? = null
+): ContextMenu {
+ val contextMenu = ContextMenu(this, fixedPosition, classes).apply { init?.invoke(this) }
+ this.setContextMenu(contextMenu)
+ return contextMenu
}
diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
index 609a0a27..342a8e84 100644
--- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
+++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt
@@ -242,103 +242,102 @@ open class DropDown(
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.PRIMARY, direction: Direction = Direction.DROPDOWN,
- disabled: Boolean = false, forNavbar: Boolean = false, forDropDown: Boolean = false,
- classes: Set<String> = setOf(), init: (DropDown.() -> Unit)? = null
- ): DropDown {
- val dropDown =
- DropDown(
- text,
- elements,
- icon,
- style,
- direction,
- disabled,
- forNavbar,
- forDropDown,
- classes
- ).apply { init?.invoke(this) }
- this.add(dropDown)
- return dropDown
- }
-
- /**
- * DSL builder extension function for a link in a dropdown list.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun DropDown.ddLink(
- label: String, url: String? = null, icon: String? = null, image: ResString? = null,
- classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
- ): Link {
- val link = Link(label, url, icon, image, classes + "dropdown-item").apply {
- init?.invoke(this)
- }
- this.add(link)
- return link
- }
+/**
+ * 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.PRIMARY, direction: Direction = Direction.DROPDOWN,
+ disabled: Boolean = false, forNavbar: Boolean = false, forDropDown: Boolean = false,
+ classes: Set<String> = setOf(), init: (DropDown.() -> Unit)? = null
+): DropDown {
+ val dropDown =
+ DropDown(
+ text,
+ elements,
+ icon,
+ style,
+ direction,
+ disabled,
+ forNavbar,
+ forDropDown,
+ classes
+ ).apply { init?.invoke(this) }
+ this.add(dropDown)
+ return dropDown
+}
- /**
- * DSL builder extension function for a link in a context menu list.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun ContextMenu.cmLink(
- label: String, url: String? = null, icon: String? = null, image: ResString? = null,
- classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
- ): Link {
- val link = Link(label, url, icon, image, classes + "dropdown-item").apply {
- init?.invoke(this)
- }
- this.add(link)
- return link
- }
+/**
+ * DSL builder extension function for a link in a dropdown list.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun DropDown.ddLink(
+ label: String, url: String? = null, icon: String? = null, image: ResString? = null,
+ classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
+): Link {
+ val link = Link(label, url, icon, image, classes + "dropdown-item").apply {
+ init?.invoke(this)
+ }
+ this.add(link)
+ return link
+}
- /**
- * DSL builder extension function for a disabled link in a dropdown list.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun DropDown.ddLinkDisabled(
- label: String, icon: String? = null, image: ResString? = null,
- classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
- ): Link {
- val link = Link(label, "javascript:void(0)", icon, image, classes + "dropdown-item" + "disabled").apply {
- tabindex = -1
- setAttribute("aria-disabled", "true")
- init?.invoke(this)
- }
- this.add(link)
- return link
- }
+/**
+ * DSL builder extension function for a link in a context menu list.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun ContextMenu.cmLink(
+ label: String, url: String? = null, icon: String? = null, image: ResString? = null,
+ classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
+): Link {
+ val link = Link(label, url, icon, image, classes + "dropdown-item").apply {
+ init?.invoke(this)
+ }
+ this.add(link)
+ return link
+}
- /**
- * DSL builder extension function for a disabled link in a context menu list.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun ContextMenu.cmLinkDisabled(
- label: String, icon: String? = null, image: ResString? = null,
- classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
- ): Link {
- val link = Link(label, "javascript:void(0)", icon, image, classes + "dropdown-item" + "disabled").apply {
- tabindex = -1
- setAttribute("aria-disabled", "true")
- init?.invoke(this)
- }
- this.add(link)
- return link
- }
+/**
+ * DSL builder extension function for a disabled link in a dropdown list.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun DropDown.ddLinkDisabled(
+ label: String, icon: String? = null, image: ResString? = null,
+ classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
+): Link {
+ val link = Link(label, "javascript:void(0)", icon, image, classes + "dropdown-item" + "disabled").apply {
+ tabindex = -1
+ setAttribute("aria-disabled", "true")
+ init?.invoke(this)
+ }
+ this.add(link)
+ return link
+}
+/**
+ * DSL builder extension function for a disabled link in a context menu list.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun ContextMenu.cmLinkDisabled(
+ label: String, icon: String? = null, image: ResString? = null,
+ classes: Set<String> = setOf(), init: (Link.() -> Unit)? = null
+): Link {
+ val link = Link(label, "javascript:void(0)", icon, image, classes + "dropdown-item" + "disabled").apply {
+ tabindex = -1
+ setAttribute("aria-disabled", "true")
+ init?.invoke(this)
}
+ this.add(link)
+ return link
}
internal class DropDownButton(
diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Header.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Header.kt
index 13e0b2e4..b88a5955 100644
--- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Header.kt
+++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Header.kt
@@ -32,30 +32,26 @@ import pl.treksoft.kvision.html.Tag
* @param classes a set of CSS class names
*/
open class Header(content: String? = null, classes: Set<String> = setOf()) :
- Tag(TAG.H6, content, classes = classes + "dropdown-header") {
+ Tag(TAG.H6, content, classes = classes + "dropdown-header")
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun ContextMenu.header(content: String? = null, classes: Set<String> = setOf()): Header {
+ val header = Header(content, classes)
+ this.add(header)
+ return header
+}
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun ContextMenu.header(content: String? = null, classes: Set<String> = setOf()): Header {
- val header = Header(content, classes)
- this.add(header)
- return header
- }
-
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun DropDown.header(content: String? = null, classes: Set<String> = setOf()): Header {
- val header = Header(content, classes)
- this.add(header)
- return header
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun DropDown.header(content: String? = null, classes: Set<String> = setOf()): Header {
+ val header = Header(content, classes)
+ this.add(header)
+ return header
}
diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Separator.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Separator.kt
index dd2344bd..62abe588 100644
--- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Separator.kt
+++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/Separator.kt
@@ -29,29 +29,26 @@ import pl.treksoft.kvision.html.Div
* @constructor
* @param classes a set of CSS class names
*/
-open class Separator(classes: Set<String> = setOf()) : Div(classes = classes + "dropdown-divider") {
+open class Separator(classes: Set<String> = setOf()) : Div(classes = classes + "dropdown-divider")
- companion object {
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun ContextMenu.separator(classes: Set<String> = setOf()): Separator {
- val separator = Separator(classes)
- this.add(separator)
- return separator
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun ContextMenu.separator(classes: Set<String> = setOf()): Separator {
+ val separator = Separator(classes)
+ this.add(separator)
+ return separator
+}
- /**
- * DSL builder extension function.
- *
- * It takes the same parameters as the constructor of the built component.
- */
- fun DropDown.separator(classes: Set<String> = setOf()): Separator {
- val separator = Separator(classes)
- this.add(separator)
- return separator
- }
- }
+/**
+ * DSL builder extension function.
+ *
+ * It takes the same parameters as the constructor of the built component.
+ */
+fun DropDown.separator(classes: Set<String> = setOf()): Separator {
+ val separator = Separator(classes)
+ this.add(separator)
+ return separator
}