aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Jaros <rjaros@finn.pl>2020-05-14 19:42:40 +0200
committerRobert Jaros <rjaros@finn.pl>2020-05-14 19:42:40 +0200
commit07822bb3820629d86af637a05d656f9fb0a15a9f (patch)
treed483ad119e3b2748335740b38e7d0f998d49aa3d
parentabc4258620bacec9771ddd7d0d75f5a7e94e989c (diff)
downloadkvision-07822bb3820629d86af637a05d656f9fb0a15a9f.tar.gz
kvision-07822bb3820629d86af637a05d656f9fb0a15a9f.tar.bz2
kvision-07822bb3820629d86af637a05d656f9fb0a15a9f.zip
Make Button component a container.
-rw-r--r--kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/dropdown/DropDown.kt2
-rw-r--r--src/main/kotlin/pl/treksoft/kvision/html/Button.kt33
2 files changed, 28 insertions, 7 deletions
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 ed9a917c..f016126c 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
@@ -381,7 +381,7 @@ internal class DropDownButton(
val forDropDown: Boolean = false,
classes: Set<String> = setOf()
) :
- Button(text, icon, style, ButtonType.BUTTON, disabled, classes) {
+ Button(text, icon, style, ButtonType.BUTTON, disabled, null, true, classes) {
init {
this.id = id
diff --git a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt
index 65527f94..2911b272 100644
--- a/src/main/kotlin/pl/treksoft/kvision/html/Button.kt
+++ b/src/main/kotlin/pl/treksoft/kvision/html/Button.kt
@@ -27,7 +27,7 @@ import pl.treksoft.kvision.core.Container
import pl.treksoft.kvision.core.ResString
import pl.treksoft.kvision.core.StringBoolPair
import pl.treksoft.kvision.core.StringPair
-import pl.treksoft.kvision.core.Widget
+import pl.treksoft.kvision.panel.SimplePanel
import pl.treksoft.kvision.utils.set
/**
@@ -78,12 +78,15 @@ enum class ButtonType(internal val buttonType: String) {
* @param icon button icon
* @param style button style
* @param disabled button state
+ * @param separator a separator between label and icon/image (defaults to space)
+ * @param labelFirst determines if the label is put before children elements (defaults to true)
* @param classes a set of CSS class names
*/
open class Button(
text: String, icon: String? = null, style: ButtonStyle = ButtonStyle.PRIMARY, type: ButtonType = ButtonType.BUTTON,
- disabled: Boolean = false, classes: Set<String> = setOf()
-) : Widget(classes) {
+ disabled: Boolean = false, separator: String? = null, labelFirst: Boolean = true,
+ classes: Set<String> = setOf()
+) : SimplePanel(classes) {
/**
* Button label.
@@ -125,9 +128,23 @@ open class Button(
*/
var block by refreshOnUpdate(false)
+ /**
+ * A separator between label and icon/image.
+ */
+ var separator by refreshOnUpdate(separator)
+
+ /**
+ * Determines if the label is put before children elements.
+ */
+ var labelFirst by refreshOnUpdate(labelFirst)
+
override fun render(): VNode {
- val t = createLabelWithIcon(text, icon, image)
- return render("button", t)
+ val t = createLabelWithIcon(text, icon, image, separator)
+ return if (labelFirst) {
+ render("button", t + childrenVNodes())
+ } else {
+ render("button", childrenVNodes() + t)
+ }
}
override fun getSnClass(): List<StringBoolPair> {
@@ -190,11 +207,15 @@ fun Container.button(
style: ButtonStyle = ButtonStyle.PRIMARY,
type: ButtonType = ButtonType.BUTTON,
disabled: Boolean = false,
+ separator: String? = null,
+ labelFirst: Boolean = true,
classes: Set<String>? = null,
className: String? = null,
init: (Button.() -> Unit)? = null
): Button {
- val button = Button(text, icon, style, type, disabled, classes ?: className.set).apply { init?.invoke(this) }
+ val button = Button(text, icon, style, type, disabled, separator, labelFirst, classes ?: className.set).apply {
+ init?.invoke(this)
+ }
this.add(button)
return button
}