From 1a5c45c2a6e2e53712d70d731f85a6b990cc464b Mon Sep 17 00:00:00 2001 From: Robert Jaros Date: Fri, 15 Nov 2019 09:34:24 +0100 Subject: Add "centered" property to all Modal dialogs. --- .../main/kotlin/pl/treksoft/kvision/modal/Alert.kt | 12 ++++++----- .../kotlin/pl/treksoft/kvision/modal/Confirm.kt | 10 +++++---- .../main/kotlin/pl/treksoft/kvision/modal/Modal.kt | 24 +++++++++++++++++++--- 3 files changed, 34 insertions(+), 12 deletions(-) (limited to 'kvision-modules/kvision-bootstrap') diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt index 852820af..cfdd36a9 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Alert.kt @@ -23,8 +23,8 @@ package pl.treksoft.kvision.modal import pl.treksoft.kvision.core.Widget import pl.treksoft.kvision.html.Align -import pl.treksoft.kvision.html.ButtonStyle import pl.treksoft.kvision.html.Button +import pl.treksoft.kvision.html.ButtonStyle import pl.treksoft.kvision.html.TAG import pl.treksoft.kvision.html.Tag import pl.treksoft.kvision.utils.ENTER_KEY @@ -39,13 +39,14 @@ import pl.treksoft.kvision.utils.ENTER_KEY * @param align text align * @param size modal window size * @param animation determines if animations are used + * @param centered determines if modal dialog is vertically centered * @param callback a function called after closing window with OK button */ open class Alert( caption: String? = null, text: String? = null, rich: Boolean = false, - align: Align? = null, size: ModalSize? = null, animation: Boolean = true, + align: Align? = null, size: ModalSize? = null, animation: Boolean = true, centered: Boolean = false, private val callback: (() -> Unit)? = null -) : Modal(caption, true, size, animation) { +) : Modal(caption, true, size, animation, centered) { /** * Window content text. @@ -107,15 +108,16 @@ open class Alert( * @param align text align * @param size modal window size * @param animation determines if animations are used + * @param centered determines if modal dialog is vertically centered * @param callback a function called after closing window with OK button */ @Suppress("LongParameterList") fun show( caption: String? = null, text: String? = null, rich: Boolean = false, align: Align? = null, size: ModalSize? = null, animation: Boolean = true, - callback: (() -> Unit)? = null + centered: Boolean = false, callback: (() -> Unit)? = null ) { - Alert(caption, text, rich, align, size, animation, callback).show() + Alert(caption, text, rich, align, size, animation, centered, callback).show() } } } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt index c464ea11..660c253c 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Confirm.kt @@ -37,6 +37,7 @@ import pl.treksoft.kvision.html.Tag * @param align text align * @param size modal window size * @param animation determines if animations are used + * @param centered determines if modal dialog is vertically centered * @param cancelVisible determines if Cancel button is visible * @param yesTitle yes button text * @param noTitle no button text @@ -46,11 +47,11 @@ import pl.treksoft.kvision.html.Tag */ open class Confirm( caption: String? = null, text: String? = null, rich: Boolean = false, - align: Align? = null, size: ModalSize? = null, animation: Boolean = true, + align: Align? = null, size: ModalSize? = null, animation: Boolean = true, centered: Boolean = false, cancelVisible: Boolean = false, yesTitle: String = "Yes", noTitle: String = "No", cancelTitle: String = "Cancel", private val noCallback: (() -> Unit)? = null, private val yesCallback: (() -> Unit)? = null -) : Modal(caption, false, size, animation, false) { +) : Modal(caption, false, size, animation, centered, false) { /** * Window content text. */ @@ -156,6 +157,7 @@ open class Confirm( * @param align text align * @param size modal window size * @param animation determines if animations are used + * @param centered determines if modal dialog is vertically centered * @param cancelVisible determines if Cancel button is visible * @param noCallback a function called after closing window with No button * @param yesCallback a function called after closing window with Yes button @@ -163,12 +165,12 @@ open class Confirm( @Suppress("LongParameterList") fun show( caption: String? = null, text: String? = null, rich: Boolean = false, - align: Align? = null, size: ModalSize? = null, animation: Boolean = true, + align: Align? = null, size: ModalSize? = null, animation: Boolean = true, centered: Boolean = false, cancelVisible: Boolean = false, yesTitle: String = "Yes", noTitle: String = "No", cancelTitle: String = "Cancel", noCallback: (() -> Unit)? = null, yesCallback: (() -> Unit)? = null ) { Confirm( - caption, text, rich, align, size, animation, cancelVisible, yesTitle, noTitle, cancelTitle, + caption, text, rich, align, size, animation, centered, cancelVisible, yesTitle, noTitle, cancelTitle, noCallback, yesCallback ).show() } diff --git a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt index 63035e76..baf1d4e0 100644 --- a/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt +++ b/kvision-modules/kvision-bootstrap/src/main/kotlin/pl/treksoft/kvision/modal/Modal.kt @@ -52,6 +52,7 @@ enum class ModalSize(val className: String) { * @param closeButton determines if Close button is visible * @param size modal window size * @param animation determines if animations are used + * @param centered determines if modal dialog is vertically centered * @param escape determines if dialog can be closed with Esc key * @param classes a set of CSS class names * @param init an initializer extension function @@ -59,7 +60,7 @@ enum class ModalSize(val className: String) { @Suppress("TooManyFunctions") open class Modal( caption: String? = null, closeButton: Boolean = true, - size: ModalSize? = null, animation: Boolean = true, private val escape: Boolean = true, + size: ModalSize? = null, animation: Boolean = true, centered: Boolean = false, private val escape: Boolean = true, classes: Set = setOf(), init: (Modal.() -> Unit)? = null ) : SimplePanel(classes) { @@ -95,8 +96,16 @@ open class Modal( * Determines if animations are used. */ var animation by refreshOnUpdate(animation) + /** + * Determines if modal dialog is vertically centered. + */ + var centered + get() = dialog.centered + set(value) { + dialog.centered = value + } - private val dialog = ModalDialog(size) + private val dialog = ModalDialog(size, centered) private val header = SimplePanel(setOf("modal-header")) /** * @suppress @@ -273,19 +282,28 @@ open class Modal( * * @constructor * @param size modal window size + * @param centered determines if modal dialog is vertically centered */ -internal class ModalDialog(size: ModalSize?) : SimplePanel(setOf("modal-dialog")) { +internal class ModalDialog(size: ModalSize?, centered: Boolean = false) : SimplePanel(setOf("modal-dialog")) { /** * Modal window size. */ var size by refreshOnUpdate(size) + /** + * Determines if modal dialog is vertically centered. + */ + var centered by refreshOnUpdate(centered) + override fun getSnClass(): List { val cl = super.getSnClass().toMutableList() size?.let { cl.add(it.className to true) } + if (centered) { + cl.add("modal-dialog-centered" to true) + } return cl } } -- cgit