diff --git a/CHANGELOG.md b/CHANGELOG.md index 8e77a6d..be2f8e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/gradle.properties b/gradle.properties index 16a4a5c..5d89877 100644 --- a/gradle.properties +++ b/gradle.properties @@ -9,4 +9,4 @@ android.enableJetifier=true # Project data group=dev.inmo -version=0.0.47 +version=0.0.48 diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Breadcrumb.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Breadcrumb.kt new file mode 100644 index 0000000..ab2751d --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Breadcrumb.kt @@ -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 Breadcrumb( + data: Iterable, + rootAttrs: Attrs = Attrs.empty(), + elementAttrs: Attrs = Attrs.empty(), + elementContent: @Composable ElementScope.(T) -> Unit = {}, +) { + Ul( + { + include(UIKitBreadcrumb) + rootAttrs.builder(this) + } + ) { + data.forEach { + Li({ elementAttrs.builder(this) }) { + elementContent(it) + } + } + } +} + +@Composable +fun BreadcrumbActiveElement( + href: String? = "#", + elementAttrs: Attrs = Attrs.empty(), + elementContent: @Composable ElementScope.() -> Unit = {}, +) { + A(href, { elementAttrs.builder(this) }) { + elementContent() + } +} + +@Composable +fun BreadcrumbInactiveElement( + elementAttrs: Attrs = Attrs.empty(), + elementContent: @Composable ElementScope.() -> Unit = {}, +) { + Span({ elementAttrs.builder(this) }) { + elementContent() + } +} diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/AttributeValue.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/AttributeValue.kt index 1db9ac2..7bf209c 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/AttributeValue.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/AttributeValue.kt @@ -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 +} diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitBreadcrumb.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitBreadcrumb.kt new file mode 100644 index 0000000..42c9ad9 --- /dev/null +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitBreadcrumb.kt @@ -0,0 +1,8 @@ +package dev.inmo.jsuikit.modifiers + +sealed class UIKitBreadcrumb( + override val classes: Array = emptyArray(), + override val otherAttrs: Map = emptyMap() +) : UIKitModifier { + companion object : UIKitBreadcrumb(arrayOf("uk-breadcrumb")) +} diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitDropdown.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitDropdown.kt index b1374b0..b1f4f1b 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitDropdown.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitDropdown.kt @@ -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) { diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitModifier.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitModifier.kt index 0e826e0..bfffeb6 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitModifier.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/modifiers/UIKitModifier.kt @@ -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 @@ -15,3 +18,16 @@ fun AttrsScope<*>.include(vararg container: UIKitModifier?) { it ?.otherAttrs ?.let { attrs -> attrs.forEach { (k, v) -> attr(k, v) } } } } + +fun UIKitModifier.asAttributesBuilder(): AttrBuilderContext = { + include(this@asAttributesBuilder) +} +operator fun UIKitModifier.plus(other: UIKitModifier): UIKitModifier = UIKitCustom( + classes + other.classes, + otherAttrs + other.otherAttrs +) +fun UIKitModifier.builder() = Attrs(this).builder +fun Array.builder() = Attrs(*this).builder +inline fun attrsBuilder(vararg modifiers: UIKitModifier) = modifiers.builder() +@JsName("plusBuilder") +operator fun UIKitModifier.plus(other: UIKitModifier): AttrBuilderContext = Attrs(this@plus, other).builder