diff options
author | Robert Jaros <rjaros@finn.pl> | 2019-11-15 09:34:24 +0100 |
---|---|---|
committer | Robert Jaros <rjaros@finn.pl> | 2019-11-15 09:34:24 +0100 |
commit | 1a5c45c2a6e2e53712d70d731f85a6b990cc464b (patch) | |
tree | 952fab54123667bcd01da5d47f5017e1c0646893 /kvision-modules | |
parent | 2d5f5470653ed75d9479bd2e771792478458d36b (diff) | |
download | kvision-1a5c45c2a6e2e53712d70d731f85a6b990cc464b.tar.gz kvision-1a5c45c2a6e2e53712d70d731f85a6b990cc464b.tar.bz2 kvision-1a5c45c2a6e2e53712d70d731f85a6b990cc464b.zip |
Add "centered" property to all Modal dialogs.
Diffstat (limited to 'kvision-modules')
4 files changed, 37 insertions, 14 deletions
diff --git a/kvision-modules/kvision-bootstrap-dialog/src/main/kotlin/pl/treksoft/kvision/modal/Dialog.kt b/kvision-modules/kvision-bootstrap-dialog/src/main/kotlin/pl/treksoft/kvision/modal/Dialog.kt index e67a6f17..511dfd00 100644 --- a/kvision-modules/kvision-bootstrap-dialog/src/main/kotlin/pl/treksoft/kvision/modal/Dialog.kt +++ b/kvision-modules/kvision-bootstrap-dialog/src/main/kotlin/pl/treksoft/kvision/modal/Dialog.kt @@ -34,14 +34,15 @@ import kotlin.coroutines.resume * @param size modal window size * @param animation determines if animations are used * @param escape determines if dialog can be closed with Esc key + * @param centered determines if modal dialog is vertically centered * @param classes a set of CSS class names * @param init an initializer extension function */ open class Dialog<R>( caption: String? = null, closeButton: Boolean = true, - size: ModalSize? = null, animation: Boolean = true, escape: Boolean = true, + size: ModalSize? = null, animation: Boolean = true, centered: Boolean = false, escape: Boolean = true, classes: Set<String> = setOf(), init: (Dialog<R>.() -> Unit)? = null -) : Modal(caption, closeButton, size, animation, escape, classes) { +) : Modal(caption, closeButton, size, animation, escape, centered, classes) { internal var resultCallback: ((R?) -> Unit)? = null 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<String> = 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<StringBoolPair> { val cl = super.getSnClass().toMutableList() size?.let { cl.add(it.className to true) } + if (centered) { + cl.add("modal-dialog-centered" to true) + } return cl } } |