From c81c1125a039f34af71cfdb2d515011ab8f5d11a Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 1 Mar 2022 00:14:17 +0600 Subject: [PATCH] add UIKitDialog --- .../dev/inmo/jsuikit/elements/Dialog.kt | 4 +- .../kotlin/dev/inmo/jsuikit/types/UIKit.kt | 1 + .../dev/inmo/jsuikit/types/UIKitDialog.kt | 40 +++++++++++++++++++ 3 files changed, 42 insertions(+), 3 deletions(-) create mode 100644 src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt index f6df0e2..996e98c 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dialog.kt @@ -99,9 +99,7 @@ fun Dialog( } htmlElement.addEventListener("hidden", wrapper) - val dialog = UIKit.modal("#${htmlElement.id}") - dialog.show() - Unit + UIKit.modal("#${htmlElement.id}").show() } } } diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt index dafeed0..8dc1d93 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt @@ -2,4 +2,5 @@ package dev.inmo.jsuikit.types external interface UIKit { val notification: UIKitNotifications + val modal: UIKitDialogs } diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt new file mode 100644 index 0000000..c45b373 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKitDialog.kt @@ -0,0 +1,40 @@ +package dev.inmo.jsuikit.types + +import org.w3c.dom.Element +import kotlin.js.Promise + +external interface UIKitDialogs { + operator fun invoke(element: Element): UIKitDialog + operator fun invoke(selector: String): UIKitDialog + fun alert(text: String): UIKitDialogPromiseAlert + fun confirm(text: String): UIKitDialogPromiseConfirm + fun prompt(title: String): UIKitDialogPromisePrompt + fun prompt(title: String, preset: String): UIKitDialogPromisePrompt + fun dialog(element: Element): UIKitDialog +} + +external class UIKitDialogPromiseConfirm : Promise { + val dialog: UIKitDialog + + fun then( + onConfirm: () -> Unit = definedExternally, + onRejected: () -> Unit = definedExternally, + ) +} + +external class UIKitDialogPromisePrompt : Promise { + val dialog: UIKitDialog + + fun then(onResult: (data: String?) -> Unit) +} + +external class UIKitDialogPromiseAlert : Promise { + val dialog: UIKitDialog + + fun then(onClose: () -> Unit) +} + +external interface UIKitDialog { + fun show() + fun hide() +}