Compare commits

...

16 Commits

Author SHA1 Message Date
a60fb67ad3 update compose 2023-02-28 12:35:34 +06:00
f8402b24d1 update dependencies 2023-02-28 12:21:43 +06:00
f70f4674ed start 0.6.0 2023-02-28 12:20:49 +06:00
7c81cea8af Merge pull request #77 from InsanusMokrassar/0.5.2
0.5.2
2023-01-26 22:44:37 +06:00
2aca51d742 Update CHANGELOG.md 2023-01-26 22:44:07 +06:00
d8be33d4f6 add inline support 2023-01-24 18:06:16 +06:00
1d6c0db692 add badge support 2023-01-24 13:44:01 +06:00
264bcae65e fixes in dialogs 2023-01-23 12:50:50 +06:00
ce5281c52d start 0.5.2 2023-01-23 12:50:03 +06:00
1349d253d7 Merge pull request #76 from InsanusMokrassar/0.5.1
0.5.1
2023-01-13 13:36:26 +06:00
dbf9efa8f5 fill changelog 2023-01-13 13:25:14 +06:00
c483bb67d8 potential fix of modals composition cancelling 2023-01-13 13:21:45 +06:00
7c5a9ecc3d start 0.5.1 2023-01-13 12:49:25 +06:00
05816f9a57 Merge pull request #75 from InsanusMokrassar/0.5.0
0.5.0
2023-01-12 14:51:06 +06:00
402af2445f temporarily remove UIKitConstants 2023-01-12 14:50:23 +06:00
71ccc74c94 fixes 2023-01-12 14:31:38 +06:00
10 changed files with 183 additions and 100 deletions

View File

@@ -1,5 +1,20 @@
# Changelog # Changelog
## 0.6.0
* `Kotlin`: `1.8.10`
* `Compose`: `1.3.1-rc01`
## 0.5.2
* More fixes in Dialogs
* Badge supported
* Inline creation support
## 0.5.1
* Fixes in new `Dialog`s
## 0.5.0 ## 0.5.0
* Fully rework `Dialog` elements * Fully rework `Dialog` elements

View File

@@ -9,4 +9,4 @@ android.enableJetifier=true
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.5.0 version=0.6.0

View File

@@ -1,7 +1,7 @@
[versions] [versions]
kt = "1.7.20" kt = "1.8.10"
jb-compose = "1.2.2" jb-compose = "1.3.1-rc01"
jb-dokka = "1.7.20" jb-dokka = "1.7.20"
gh-release = "2.4.1" gh-release = "2.4.1"

View File

@@ -0,0 +1,25 @@
package dev.inmo.jsuikit.elements
import androidx.compose.runtime.Composable
import dev.inmo.jsuikit.modifiers.UIKitBadge
import dev.inmo.jsuikit.modifiers.include
import org.jetbrains.compose.web.dom.AttrBuilderContext
import org.jetbrains.compose.web.dom.ContentBuilder
import org.jetbrains.compose.web.dom.Span
import org.jetbrains.compose.web.dom.Text
import org.w3c.dom.HTMLSpanElement
@Composable
fun Badge(
text: String,
onAfterText: ContentBuilder<HTMLSpanElement>? = null,
onBeforeText: ContentBuilder<HTMLSpanElement>? = null,
attrs: AttrBuilderContext<HTMLSpanElement>? = null
) = Span({
include(UIKitBadge)
attrs ?.invoke(this)
}) {
onAfterText ?.invoke(this)
Text(text)
onBeforeText ?.invoke(this)
}

View File

@@ -1,14 +1,13 @@
package dev.inmo.jsuikit.elements package dev.inmo.jsuikit.elements
import androidx.compose.runtime.Composable import androidx.compose.runtime.Composable
import androidx.compose.runtime.DisposableEffect
import androidx.compose.runtime.mutableStateOf import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember import androidx.compose.runtime.remember
import dev.inmo.jsuikit.modifiers.* import dev.inmo.jsuikit.modifiers.*
import org.jetbrains.compose.web.dom.* import org.jetbrains.compose.web.dom.*
import org.jetbrains.compose.web.renderComposableInBody import org.jetbrains.compose.web.renderComposableInBody
import org.w3c.dom.HTMLDivElement import org.w3c.dom.HTMLDivElement
import org.w3c.dom.MutationObserver
import org.w3c.dom.MutationObserverInit
import kotlin.random.Random import kotlin.random.Random
import kotlin.random.nextUInt import kotlin.random.nextUInt
@@ -30,8 +29,11 @@ fun Dialog(
removeOnHide: Boolean = true, removeOnHide: Boolean = true,
bodyBuilder: ContentBuilder<HTMLDivElement> = {} bodyBuilder: ContentBuilder<HTMLDivElement> = {}
) { ) {
val drawDiv = remember { mutableStateOf(true) } val draw = remember { mutableStateOf(true) }
val composition = renderComposableInBody {
remember {
renderComposableInBody {
if (draw.value) {
Div( Div(
{ {
if (modifiers.none { it is UIKitModal.WithCustomAttributes }) { if (modifiers.none { it is UIKitModal.WithCustomAttributes }) {
@@ -40,42 +42,42 @@ fun Dialog(
id("dialog${Random.nextUInt()}") id("dialog${Random.nextUInt()}")
include(*modifiers) include(*modifiers)
ref { htmlElement ->
inline fun isShown() = htmlElement.classList.contains(UIKitUtility.Open.classes.first())
var latestStateIsShown = isShown()
val observer = MutationObserver { _, _ ->
val currentStateIsShown = isShown()
when (currentStateIsShown) {
latestStateIsShown -> return@MutationObserver
true -> onShown ?.invoke(htmlElement)
false -> onHidden ?.invoke(htmlElement)
}
latestStateIsShown = currentStateIsShown
if (removeOnHide && !currentStateIsShown) {
htmlElement.remove()
}
}
observer.observe(htmlElement, MutationObserverInit(attributes = true, attributeFilter = arrayOf("class")))
if (autoShow) {
UIKit.modal("#${htmlElement.id}") ?.show()
}
onDispose {
observer.disconnect()
drawDiv.value = false
}
}
attributesCustomizer() attributesCustomizer()
} }
) { ) {
DisposableEffect(true) {
val htmlElement = scopeElement
if (autoShow) {
UIKit.modal(htmlElement).show()
}
if (onHidden != null || removeOnHide) {
htmlElement.addEventListener("hidden", {
if (it.target != htmlElement) return@addEventListener
onHidden ?.invoke(htmlElement)
if (removeOnHide) {
htmlElement.remove()
}
})
}
onShown ?.let {
htmlElement.addEventListener("shown", {
if (it.target != htmlElement) return@addEventListener
onShown(htmlElement)
})
}
onDispose {
draw.value = false
}
}
Div( Div(
{ {
include(UIKitModal.Dialog) include(UIKitModal.Dialog)
@@ -115,19 +117,17 @@ fun Dialog(
} }
} }
} }
}
}
if (drawDiv.value) {
Div({ Div({
hidden() hidden()
ref { ref {
onDispose { onDispose {
composition.dispose() draw.value = false
} }
} }
}) })
} else {
runCatching { composition.dispose() }
}
} }
@Composable @Composable
@@ -150,23 +150,23 @@ fun Dialog(
bodyBuilder: ContentBuilder<HTMLDivElement> = {} bodyBuilder: ContentBuilder<HTMLDivElement> = {}
) = Dialog( ) = Dialog(
modifiers = modifiers, modifiers = modifiers,
attributesCustomizer, attributesCustomizer = attributesCustomizer,
onHidden, onHidden = onHidden,
onShown, onShown = onShown,
dialogAttrsBuilder, dialogAttrsBuilder = dialogAttrsBuilder,
headerAttrsBuilder, headerAttrsBuilder = headerAttrsBuilder,
headerBuilder = { headerBuilder = {
H2({ include(UIKitModal.Title) }) { H2({ include(UIKitModal.Title) }) {
Text(title) Text(title)
} }
headerBuilder ?.invoke(this) headerBuilder ?.invoke(this)
}, },
afterHeaderBuilder, afterHeaderBuilder = afterHeaderBuilder,
beforeFooterBuilder, beforeFooterBuilder = beforeFooterBuilder,
footerAttrsBuilder, footerAttrsBuilder = footerAttrsBuilder,
footerBuilder, footerBuilder = footerBuilder,
bodyAttrsBuilder, bodyAttrsBuilder = bodyAttrsBuilder,
autoShow, autoShow = autoShow,
removeOnHide, removeOnHide = removeOnHide,
bodyBuilder bodyBuilder = bodyBuilder
) )

View File

@@ -0,0 +1,18 @@
package dev.inmo.jsuikit.elements
import androidx.compose.runtime.Composable
import dev.inmo.jsuikit.modifiers.UIKitUtility
import dev.inmo.jsuikit.modifiers.include
import org.jetbrains.compose.web.dom.AttrBuilderContext
import org.jetbrains.compose.web.dom.ContentBuilder
import org.jetbrains.compose.web.dom.Div
import org.w3c.dom.HTMLDivElement
@Composable
fun Inline(
attrBuilderContext: AttrBuilderContext<HTMLDivElement>? = null,
contentBuilder: ContentBuilder<HTMLDivElement>
) = Div({
include(UIKitUtility.Inline)
attrBuilderContext ?.invoke(this)
}, contentBuilder)

View File

@@ -0,0 +1,7 @@
package dev.inmo.jsuikit.modifiers
sealed class UIKitBadge(classname: String) : UIKitModifier {
override val classes: Array<String> = arrayOf(classname)
companion object : UIKitBadge("uk-badge")
}

View File

@@ -6,6 +6,7 @@ import kotlin.js.Json
external interface UIKit { external interface UIKit {
val notification: UIKitNotifications val notification: UIKitNotifications
val modal: UIKitDialogs val modal: UIKitDialogs
val util: UIKitUtil
fun notification(message: String, parameters: Json) fun notification(message: String, parameters: Json)

View File

@@ -0,0 +1,8 @@
package dev.inmo.jsuikit.types
import org.w3c.dom.HTMLElement
external interface UIKitUtil {
fun on(selector: String, event: String, callback: () -> Unit)
fun on(element: HTMLElement, event: String, callback: () -> Unit)
}

View File

@@ -0,0 +1,9 @@
package dev.inmo.jsuikit.utils
import org.jetbrains.compose.web.dom.AttrBuilderContext
import org.w3c.dom.Element
operator fun <T : Element> AttrBuilderContext<T>.plus(other: AttrBuilderContext<T>): AttrBuilderContext<T> = {
this@plus()
other()
}