diff options
author | Robert Jaros <rjaros@finn.pl> | 2020-05-14 19:42:40 +0200 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2020-05-14 19:42:40 +0200 |
commit | 07822bb3820629d86af637a05d656f9fb0a15a9f (patch) | |
tree | d483ad119e3b2748335740b38e7d0f998d49aa3d /src/main/kotlin/pl/treksoft/kvision/html | |
parent | abc4258620bacec9771ddd7d0d75f5a7e94e989c (diff) | |
download | kvision-07822bb3820629d86af637a05d656f9fb0a15a9f.tar.gz kvision-07822bb3820629d86af637a05d656f9fb0a15a9f.tar.bz2 kvision-07822bb3820629d86af637a05d656f9fb0a15a9f.zip |
Make Button component a container.
Diffstat (limited to 'src/main/kotlin/pl/treksoft/kvision/html')
-rw-r--r-- | src/main/kotlin/pl/treksoft/kvision/html/Button.kt | 33 |
1 files changed, 27 insertions, 6 deletions
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 } |