mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-11-26 20:18:49 +00:00
add support of notifications
This commit is contained in:
parent
7c33efa121
commit
2e28334b41
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
## 0.0.39
|
## 0.0.39
|
||||||
|
|
||||||
|
* Add support of `Notifications`
|
||||||
|
|
||||||
## 0.0.38
|
## 0.0.38
|
||||||
|
|
||||||
* Add support of `Toggle`
|
* Add support of `Toggle`
|
||||||
|
15
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Notification.kt
Normal file
15
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Notification.kt
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
package dev.inmo.jsuikit.elements
|
||||||
|
|
||||||
|
import dev.inmo.jsuikit.modifiers.UIKit
|
||||||
|
import dev.inmo.jsuikit.types.UIKitNotificationParameter
|
||||||
|
import dev.inmo.jsuikit.types.NotificationsGroup
|
||||||
|
import dev.inmo.jsuikit.types.invoke
|
||||||
|
import dev.inmo.jsuikit.utils.Milliseconds
|
||||||
|
|
||||||
|
fun Notification(
|
||||||
|
message: String,
|
||||||
|
status: UIKitNotificationParameter.Style? = null,
|
||||||
|
timeout: Milliseconds? = null,
|
||||||
|
group: NotificationsGroup? = null,
|
||||||
|
position: UIKitNotificationParameter.Position? = null
|
||||||
|
) = UIKit.notification.invoke(message, status, timeout, group, position)
|
@ -1,4 +1,6 @@
|
|||||||
package dev.inmo.jsuikit.modifiers
|
package dev.inmo.jsuikit.modifiers
|
||||||
|
|
||||||
inline val UIKit
|
import dev.inmo.jsuikit.types.UIKit
|
||||||
get() = js("UIkit")
|
|
||||||
|
inline val UIKit: UIKit
|
||||||
|
get() = js("UIkit").unsafeCast<UIKit>()
|
||||||
|
5
src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt
Normal file
5
src/jsMain/kotlin/dev/inmo/jsuikit/types/UIKit.kt
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
package dev.inmo.jsuikit.types
|
||||||
|
|
||||||
|
external interface UIKit {
|
||||||
|
val notification: UIKitNotifications
|
||||||
|
}
|
@ -0,0 +1,39 @@
|
|||||||
|
package dev.inmo.jsuikit.types
|
||||||
|
|
||||||
|
sealed class UIKitNotificationParameter {
|
||||||
|
abstract val parameterName: String
|
||||||
|
abstract val parameterValue: String
|
||||||
|
|
||||||
|
sealed class Style(override val parameterValue: String) : UIKitNotificationParameter() {
|
||||||
|
override val parameterName: String
|
||||||
|
get() = "status"
|
||||||
|
|
||||||
|
object Primary : Style("primary")
|
||||||
|
object Success : Style("success")
|
||||||
|
object Warning : Style("warning")
|
||||||
|
object Danger : Style("danger")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class Position(override val parameterValue: String) : UIKitNotificationParameter() {
|
||||||
|
override val parameterName: String
|
||||||
|
get() = "pos"
|
||||||
|
|
||||||
|
sealed class Top(parameterValue: String) : Position("top-$parameterValue") {
|
||||||
|
|
||||||
|
object Left : Top("left")
|
||||||
|
object Center : Top("center")
|
||||||
|
object Right : Top("right")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
sealed class Bottom(parameterValue: String) : Position("bottom-$parameterValue") {
|
||||||
|
|
||||||
|
object Left : Bottom("left")
|
||||||
|
object Center : Bottom("center")
|
||||||
|
object Right : Bottom("right")
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
package dev.inmo.jsuikit.types
|
||||||
|
|
||||||
|
import dev.inmo.jsuikit.utils.Milliseconds
|
||||||
|
import org.w3c.dom.Element
|
||||||
|
import kotlin.js.Json
|
||||||
|
import kotlin.js.json
|
||||||
|
|
||||||
|
typealias NotificationsGroup = String
|
||||||
|
|
||||||
|
external interface UIKitNotifications {
|
||||||
|
|
||||||
|
fun closeAll(group: NotificationsGroup)
|
||||||
|
|
||||||
|
operator fun invoke(message: String, parameters: Json)
|
||||||
|
|
||||||
|
operator fun invoke(element: Element): UIKitNotification?
|
||||||
|
}
|
||||||
|
|
||||||
|
external interface UIKitNotification {
|
||||||
|
fun close(immediate: Boolean)
|
||||||
|
}
|
||||||
|
|
||||||
|
data class UIKitNotificationsParameters(
|
||||||
|
val status: UIKitNotificationParameter.Style? = null,
|
||||||
|
val timeout: Milliseconds? = null,
|
||||||
|
val group: NotificationsGroup? = null,
|
||||||
|
val position: UIKitNotificationParameter.Position? = null
|
||||||
|
) {
|
||||||
|
fun parametersJson() = json(
|
||||||
|
*listOfNotNull(
|
||||||
|
status ?.let { it.parameterName to it.parameterValue },
|
||||||
|
timeout ?.let { "timeout" to timeout.toString() },
|
||||||
|
group ?.let { "group" to it },
|
||||||
|
position ?.let { it.parameterName to it.parameterValue },
|
||||||
|
).toTypedArray()
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
operator fun UIKitNotifications.invoke(
|
||||||
|
message: String,
|
||||||
|
parameters: UIKitNotificationsParameters
|
||||||
|
) = invoke(message, parameters.parametersJson())
|
||||||
|
|
||||||
|
operator fun UIKitNotifications.invoke(
|
||||||
|
message: String,
|
||||||
|
status: UIKitNotificationParameter.Style? = null,
|
||||||
|
timeout: Milliseconds? = null,
|
||||||
|
group: NotificationsGroup? = null,
|
||||||
|
position: UIKitNotificationParameter.Position? = null
|
||||||
|
) = invoke(message, UIKitNotificationsParameters(status, timeout, group, position))
|
Loading…
Reference in New Issue
Block a user