Merge pull request #49 from InsanusMokrassar/0.0.48

0.0.48
This commit is contained in:
InsanusMokrassar 2022-03-31 13:32:41 +06:00 committed by GitHub
commit a756bab2a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 87 additions and 2 deletions

View File

@ -1,5 +1,11 @@
# Changelog
## 0.0.48
* Added support of `Breadcrumb`
* Add opportunity to summarize `UIKitModifier`
* Add opportunity to simply create attributes builder using `UIKitModifier` of array of them
## 0.0.47
* Add support of `Close` element

View File

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

View File

@ -0,0 +1,50 @@
package dev.inmo.jsuikit.elements
import androidx.compose.runtime.Composable
import dev.inmo.jsuikit.modifiers.UIKitBreadcrumb
import dev.inmo.jsuikit.modifiers.include
import dev.inmo.jsuikit.utils.Attrs
import org.jetbrains.compose.web.dom.*
import org.w3c.dom.*
@Composable
fun <T> Breadcrumb(
data: Iterable<T>,
rootAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
elementAttrs: Attrs<HTMLLIElement> = Attrs.empty(),
elementContent: @Composable ElementScope<HTMLLIElement>.(T) -> Unit = {},
) {
Ul(
{
include(UIKitBreadcrumb)
rootAttrs.builder(this)
}
) {
data.forEach {
Li({ elementAttrs.builder(this) }) {
elementContent(it)
}
}
}
}
@Composable
fun BreadcrumbActiveElement(
href: String? = "#",
elementAttrs: Attrs<HTMLAnchorElement> = Attrs.empty(),
elementContent: @Composable ElementScope<HTMLAnchorElement>.() -> Unit = {},
) {
A(href, { elementAttrs.builder(this) }) {
elementContent()
}
}
@Composable
fun BreadcrumbInactiveElement(
elementAttrs: Attrs<HTMLSpanElement> = Attrs.empty(),
elementContent: @Composable ElementScope<HTMLSpanElement>.() -> Unit = {},
) {
Span({ elementAttrs.builder(this) }) {
elementContent()
}
}

View File

@ -1,3 +1,5 @@
package dev.inmo.jsuikit.modifiers
sealed class AttributeValue(val name: String)
sealed class AttributeValue(val name: String) {
override fun toString(): String = name
}

View File

@ -0,0 +1,8 @@
package dev.inmo.jsuikit.modifiers
sealed class UIKitBreadcrumb(
override val classes: Array<String> = emptyArray(),
override val otherAttrs: Map<String, String> = emptyMap()
) : UIKitModifier {
companion object : UIKitBreadcrumb(arrayOf("uk-breadcrumb"))
}

View File

@ -50,6 +50,9 @@ sealed class UIKitDropdown(classname: String) : UIKitModifier {
object Click : Mode("click")
object Hover : Mode("hover")
object None : Mode("")
object HoverAndClick : Mode("$Hover, $Click")
}
sealed class Flip(name: String) : AttributeValue(name) {

View File

@ -1,6 +1,9 @@
package dev.inmo.jsuikit.modifiers
import dev.inmo.jsuikit.utils.Attrs
import org.jetbrains.compose.web.attributes.AttrsScope
import org.jetbrains.compose.web.dom.AttrBuilderContext
import org.w3c.dom.Element
interface UIKitModifier {
val classes: Array<String>
@ -15,3 +18,16 @@ fun AttrsScope<*>.include(vararg container: UIKitModifier?) {
it ?.otherAttrs ?.let { attrs -> attrs.forEach { (k, v) -> attr(k, v) } }
}
}
fun <T : Element> UIKitModifier.asAttributesBuilder(): AttrBuilderContext<T> = {
include(this@asAttributesBuilder)
}
operator fun UIKitModifier.plus(other: UIKitModifier): UIKitModifier = UIKitCustom(
classes + other.classes,
otherAttrs + other.otherAttrs
)
fun <T: Element> UIKitModifier.builder() = Attrs<T>(this).builder
fun <T: Element> Array<out UIKitModifier>.builder() = Attrs<T>(*this).builder
inline fun <T: Element> attrsBuilder(vararg modifiers: UIKitModifier) = modifiers.builder<T>()
@JsName("plusBuilder")
operator fun <T: Element> UIKitModifier.plus(other: UIKitModifier): AttrBuilderContext<T> = Attrs<T>(this@plus, other).builder