mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2025-12-04 13:26:27 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 415549b251 | |||
| 0d2672b679 | |||
| a511def014 | |||
| d783834aa4 | |||
| cf2b823765 | |||
| 0f6e2c9805 | |||
| 7b2810b206 | |||
| 0dff161ce6 | |||
| 0648ceed18 |
@@ -1,5 +1,14 @@
|
||||
# Changelog
|
||||
|
||||
## 0.2.2
|
||||
|
||||
* Add support of `Drop` component
|
||||
* Improve support of `Navbar`s
|
||||
|
||||
## 0.2.1
|
||||
|
||||
* `Tab` elements become supported
|
||||
|
||||
## 0.2.0
|
||||
|
||||
**ALL DEPRECATIONS HAVE BEEN REMOVED**
|
||||
|
||||
@@ -9,4 +9,4 @@ android.enableJetifier=true
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.2.0
|
||||
version=0.3.0
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
[versions]
|
||||
|
||||
kt = "1.7.0"
|
||||
jb-compose = "1.2.0-alpha01-dev753"
|
||||
jb-dokka = "1.7.0"
|
||||
kt = "1.7.10"
|
||||
jb-compose = "1.2.0-beta01"
|
||||
jb-dokka = "1.7.10"
|
||||
gh-release = "2.4.1"
|
||||
|
||||
[libraries]
|
||||
|
||||
24
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Drop.kt
Normal file
24
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Drop.kt
Normal file
@@ -0,0 +1,24 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitDrop
|
||||
import dev.inmo.jsuikit.modifiers.attrsBuilder
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
import org.jetbrains.compose.web.dom.Div
|
||||
import org.w3c.dom.HTMLButtonElement
|
||||
import org.w3c.dom.HTMLDivElement
|
||||
|
||||
@Composable
|
||||
fun Drop(
|
||||
buttonBuilder: AttrsWithContentBuilder<HTMLButtonElement>,
|
||||
dropBuilder: AttrsWithContentBuilder<HTMLDivElement>
|
||||
) {
|
||||
DefaultButton(
|
||||
attributesCustomizer = buttonBuilder.attributesBuilderContext,
|
||||
contentAllocator = buttonBuilder.builder
|
||||
)
|
||||
Div(
|
||||
(Attrs<HTMLDivElement>(UIKitDrop.Custom()) + dropBuilder.attrs).builder,
|
||||
dropBuilder.builder
|
||||
)
|
||||
}
|
||||
@@ -10,7 +10,7 @@ import org.w3c.dom.HTMLLIElement
|
||||
import org.w3c.dom.HTMLUListElement
|
||||
|
||||
@Composable
|
||||
fun <T> Iconnav(
|
||||
fun <T> IconNav(
|
||||
data: Iterable<T>,
|
||||
listAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
||||
elementAttrsBuilder: AttrsScope<HTMLLIElement>.(T) -> Unit = {},
|
||||
@@ -31,3 +31,11 @@ fun <T> Iconnav(
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
fun <T> Iconnav(
|
||||
data: Iterable<T>,
|
||||
listAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
||||
elementAttrsBuilder: AttrsScope<HTMLLIElement>.(T) -> Unit = {},
|
||||
elementBuilder: @Composable ElementScope<HTMLLIElement>.(T) -> Unit
|
||||
) = IconNav(data, listAttrs, elementAttrsBuilder, elementBuilder)
|
||||
|
||||
@@ -5,8 +5,7 @@ import dev.inmo.jsuikit.modifiers.*
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLLIElement
|
||||
import org.w3c.dom.HTMLUListElement
|
||||
import org.w3c.dom.*
|
||||
|
||||
@Composable
|
||||
fun NavbarNav(
|
||||
@@ -30,3 +29,17 @@ fun NavbarNav(
|
||||
vararg elements: AttrsWithContentBuilder<HTMLLIElement>,
|
||||
attrs: Attrs<HTMLUListElement> = Attrs.empty()
|
||||
) = NavbarNav(elements.toList(), attrs)
|
||||
|
||||
fun NavbarNavBuilder(
|
||||
elements: List<AttrsWithContentBuilder<HTMLLIElement>>,
|
||||
attrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
||||
containerAttrs: Attrs<HTMLDivElement> = Attrs.empty()
|
||||
) = AttrsWithContentBuilder<HTMLDivElement>(containerAttrs) {
|
||||
NavbarNav(elements, attrs)
|
||||
}
|
||||
|
||||
fun NavbarNavBuilder(
|
||||
vararg elements: AttrsWithContentBuilder<HTMLLIElement>,
|
||||
attrs: Attrs<HTMLUListElement> = Attrs.empty(),
|
||||
containerAttrs: Attrs<HTMLDivElement> = Attrs.empty()
|
||||
) = NavbarNavBuilder(elements.toList(), attrs, containerAttrs)
|
||||
|
||||
46
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Tabs.kt
Normal file
46
src/jsMain/kotlin/dev/inmo/jsuikit/elements/Tabs.kt
Normal file
@@ -0,0 +1,46 @@
|
||||
package dev.inmo.jsuikit.elements
|
||||
|
||||
import androidx.compose.runtime.Composable
|
||||
import dev.inmo.jsuikit.modifiers.UIKitTab
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import dev.inmo.jsuikit.utils.optionallyDraw
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.dom.*
|
||||
import org.w3c.dom.HTMLLIElement
|
||||
import org.w3c.dom.HTMLUListElement
|
||||
|
||||
@Composable
|
||||
fun <T> Tabs(
|
||||
data: Iterable<T>,
|
||||
tabsItemBuilder: @Composable ElementScope<HTMLLIElement>.(i: Int, data: T) -> Unit,
|
||||
tabsItemAttrs: AttrsScope<HTMLLIElement>.(i: Int, data: T) -> Unit = { _, _ -> },
|
||||
tabsContainerAttrs: AttrsScope<HTMLUListElement>.() -> Unit = {},
|
||||
contentContainerAttrs: (AttrsScope<HTMLUListElement>.() -> Unit)? = null,
|
||||
contentItemAttrs: (AttrsScope<HTMLLIElement>.(i: Int, data: T) -> Unit)? = null,
|
||||
contentItemBuilder: (@Composable ElementScope<HTMLLIElement>.(i: Int, data: T) -> Unit)? = null
|
||||
) {
|
||||
Ul({
|
||||
include(UIKitTab);
|
||||
tabsContainerAttrs()
|
||||
}) {
|
||||
data.forEachIndexed { i, data ->
|
||||
Li({ tabsItemAttrs(i, data) }) {
|
||||
tabsItemBuilder(i, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
optionallyDraw(contentItemAttrs != null, contentItemBuilder != null, contentContainerAttrs != null) {
|
||||
Ul({
|
||||
contentContainerAttrs ?.invoke(this)
|
||||
}) {
|
||||
optionallyDraw(contentItemAttrs != null, contentItemBuilder != null) {
|
||||
data.forEachIndexed { i, data ->
|
||||
Li({ contentItemAttrs ?.invoke(this, i, data) }) {
|
||||
contentItemBuilder ?.invoke(this, i, data)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
122
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitDrop.kt
Normal file
122
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitDrop.kt
Normal file
@@ -0,0 +1,122 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
import dev.inmo.jsuikit.utils.*
|
||||
import org.jetbrains.compose.web.css.selectors.CSSSelector
|
||||
|
||||
sealed class UIKitDrop(
|
||||
override val classes: Array<String> = emptyArray(),
|
||||
override val otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitModifier {
|
||||
sealed class Position(name: String) : AttributeValue(name) {
|
||||
|
||||
sealed class Bottom(name: String) : Position("bottom-$name") {
|
||||
|
||||
object Left : Bottom("left")
|
||||
object Center : Bottom("center")
|
||||
object Right : Bottom("right")
|
||||
object Justify : Bottom("justify")
|
||||
|
||||
}
|
||||
|
||||
sealed class Top(name: String) : Position("top-$name") {
|
||||
|
||||
object Left : Top("left")
|
||||
object Center : Top("center")
|
||||
object Right : Top("right")
|
||||
object Justify : Top("justify")
|
||||
|
||||
}
|
||||
|
||||
sealed class Left(name: String) : Position("left-$name") {
|
||||
|
||||
object Top : Left("top")
|
||||
object Center : Left("center")
|
||||
object Bottom : Left("bottom")
|
||||
|
||||
}
|
||||
|
||||
sealed class Right(name: String) : Position("right-$name") {
|
||||
|
||||
object Top : Right("top")
|
||||
object Center : Right("center")
|
||||
object Bottom : Right("bottom")
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
sealed class Stretch(name: String) : AttributeValue(name) {
|
||||
object True : Stretch("true")
|
||||
object X : Stretch("x")
|
||||
object Y : Stretch("y")
|
||||
}
|
||||
|
||||
sealed class Mode(name: String) : AttributeValue(name) {
|
||||
|
||||
object Click : Mode("click")
|
||||
object Hover : Mode("hover")
|
||||
|
||||
object None : Mode("")
|
||||
object HoverAndClick : Mode("$Hover, $Click")
|
||||
|
||||
}
|
||||
|
||||
class Custom internal constructor(
|
||||
classes: Array<String> = emptyArray(),
|
||||
otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitDrop(classes, otherAttrs)
|
||||
|
||||
companion object {
|
||||
operator fun invoke(
|
||||
toggle: CSSSelector? = null,
|
||||
position: Position? = null,
|
||||
stretch: Stretch? = null,
|
||||
mode: Mode? = null,
|
||||
delayShow: Milliseconds? = null,
|
||||
delayHide: Milliseconds? = null,
|
||||
autoUpdate: Boolean? = null,
|
||||
boundary: CSSSelector? = null,
|
||||
boundaryX: CSSSelector? = null,
|
||||
boundaryY: CSSSelector? = null,
|
||||
target: CSSSelector? = null,
|
||||
targetX: CSSSelector? = null,
|
||||
targetY: CSSSelector? = null,
|
||||
inset: Boolean? = null,
|
||||
flip: Boolean? = null,
|
||||
shift: Boolean? = null,
|
||||
offset: Pixels? = null,
|
||||
animation: UIKitAnimation? = null,
|
||||
animationOut: Boolean? = null,
|
||||
bgScroll: Boolean? = null,
|
||||
duration: Milliseconds? = null,
|
||||
container: Boolean? = null
|
||||
) = Custom(
|
||||
arrayOf("uk-drop"),
|
||||
mapOf(
|
||||
buildAttribute("uk-drop") {
|
||||
"toggle" to toggle
|
||||
"position" to position
|
||||
"stretch" to stretch
|
||||
"mode" to mode
|
||||
"delay-show" to delayShow
|
||||
"delay-hide" to delayHide
|
||||
"auto-update" to autoUpdate
|
||||
"boundary" to boundary
|
||||
"boundary-x" to boundaryX
|
||||
"boundary-y" to boundaryY
|
||||
"target" to target
|
||||
"target-x" to targetX
|
||||
"target-y" to targetY
|
||||
"inset" to inset
|
||||
"flip" to flip
|
||||
"shift" to shift
|
||||
"offset" to offset
|
||||
"animation" to animation
|
||||
"animation-out" to animationOut
|
||||
"bg-scroll" to bgScroll
|
||||
"duration" to duration
|
||||
"container" to container
|
||||
}
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
51
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitTab.kt
Normal file
51
src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitTab.kt
Normal file
@@ -0,0 +1,51 @@
|
||||
package dev.inmo.jsuikit.modifiers
|
||||
|
||||
import dev.inmo.jsuikit.utils.buildAttribute
|
||||
import org.jetbrains.compose.web.css.selectors.CSSSelector
|
||||
import kotlin.time.Duration
|
||||
|
||||
sealed class UIKitTab(
|
||||
override val classes: Array<String> = emptyArray(),
|
||||
override val otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitModifier {
|
||||
sealed class Position(
|
||||
classes: Array<String> = emptyArray(),
|
||||
otherAttrs: Map<String, String> = emptyMap()
|
||||
) : UIKitTab(classes, otherAttrs) {
|
||||
object Bottom : Position(arrayOf("uk-tab-bottom"))
|
||||
object Left : Position(arrayOf("uk-tab-left"))
|
||||
object Right : Position(arrayOf("uk-tab-right"))
|
||||
}
|
||||
|
||||
class Custom(
|
||||
connect: CSSSelector? = null,
|
||||
toggle: CSSSelector? = null,
|
||||
active: Int? = null,
|
||||
animationsIn: Array<UIKitAnimation>? = null,
|
||||
animationsOut: Array<UIKitAnimation>? = null,
|
||||
animationDuration: Duration? = null,
|
||||
swiping: Boolean? = null,
|
||||
media: String? = null
|
||||
) : UIKitTab(
|
||||
arrayOf("uk-tab"),
|
||||
mapOf(
|
||||
buildAttribute("uk-tab") {
|
||||
"connect" to connect
|
||||
"toggle" to toggle
|
||||
"active" to active
|
||||
"animation" to (
|
||||
(animationsIn ?.let {
|
||||
it.joinToString(" ") { it.name }
|
||||
} ?: "") + (animationsOut ?.let {
|
||||
it.joinToString(" ", ",") { it.name }
|
||||
} ?: "")
|
||||
).takeIf { it.isNotBlank() }
|
||||
"duration" to animationDuration
|
||||
"swiping" to swiping
|
||||
"media" to media
|
||||
}
|
||||
)
|
||||
)
|
||||
|
||||
companion object : UIKitTab(arrayOf("uk-tab"), mapOf("uk-tab" to ""))
|
||||
}
|
||||
@@ -3,7 +3,9 @@ package dev.inmo.jsuikit.utils
|
||||
import dev.inmo.jsuikit.modifiers.UIKitModifier
|
||||
import dev.inmo.jsuikit.modifiers.include
|
||||
import org.jetbrains.compose.web.attributes.AttrsScope
|
||||
import org.jetbrains.compose.web.attributes.HtmlAttrMarker
|
||||
import org.jetbrains.compose.web.attributes.builders.InputAttrsScope
|
||||
import org.jetbrains.compose.web.dom.AttrBuilderContext
|
||||
import org.w3c.dom.Element
|
||||
import org.w3c.dom.HTMLInputElement
|
||||
|
||||
|
||||
@@ -4,13 +4,19 @@ import androidx.compose.runtime.Composable
|
||||
import org.jetbrains.compose.web.dom.ContentBuilder
|
||||
import org.w3c.dom.Element
|
||||
|
||||
@Composable
|
||||
inline fun optionallyDraw (
|
||||
vararg bools: Boolean,
|
||||
whatToDraw: @Composable () -> Unit
|
||||
) {
|
||||
if (bools.any { it }) {
|
||||
whatToDraw()
|
||||
}
|
||||
}
|
||||
|
||||
@Composable
|
||||
inline fun <T : Element> optionallyDraw (
|
||||
attrs: Attrs<T>? = null,
|
||||
noinline contentBuilder: ContentBuilder<T>? = null,
|
||||
whatToDraw: @Composable () -> Unit
|
||||
) {
|
||||
if (attrs != null || contentBuilder != null) {
|
||||
whatToDraw()
|
||||
}
|
||||
}
|
||||
) = optionallyDraw(attrs != null || contentBuilder != null, whatToDraw = whatToDraw)
|
||||
|
||||
@@ -1,13 +1,17 @@
|
||||
package dev.inmo.jsuikit.utils
|
||||
|
||||
import dev.inmo.jsuikit.modifiers.AttributeValue
|
||||
|
||||
|
||||
class ParametersBuilder(
|
||||
val skipNullValues: Boolean = true,
|
||||
private val parameters: MutableMap<String, String?> = mutableMapOf()
|
||||
) {
|
||||
fun add(k: String, v: Any? = null) {
|
||||
if (v != null || !skipNullValues) {
|
||||
parameters[k] = v ?.toString()
|
||||
when {
|
||||
v is AttributeValue -> parameters[k] = v.name
|
||||
v == null && skipNullValues -> return
|
||||
else -> parameters[k] = v ?.toString()
|
||||
}
|
||||
}
|
||||
infix fun String.to(value: Any?) = add(this, value)
|
||||
|
||||
Reference in New Issue
Block a user