From ca8f927304458dac6be0b7d258a9fe5f1566398c Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 9 Feb 2022 01:18:51 +0600 Subject: [PATCH] updates and attributes buildings and fixes --- CHANGELOG.md | 2 ++ .../dev/inmo/jsuikit/UIKitAttributeValueBuilder.kt | 9 +++++++-- src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dropdown.kt | 1 + .../kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt | 4 ++-- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b17495f..e7cdd9a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.0.33 +* Fixes in attributes building and related things + ## 0.0.32 * Support of `UIKitHeight` diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/UIKitAttributeValueBuilder.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/UIKitAttributeValueBuilder.kt index a328eb9..4713631 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/UIKitAttributeValueBuilder.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/UIKitAttributeValueBuilder.kt @@ -1,8 +1,11 @@ package dev.inmo.jsuikit import dev.inmo.jsuikit.modifiers.AttributeValue +import dev.inmo.jsuikit.utils.AttributeBuilder +import dev.inmo.jsuikit.utils.buildAttribute import org.jetbrains.compose.web.attributes.AttrsBuilder +@Deprecated("Will be removed soon") class UIKitAttributeValueBuilder { private val attrs = mutableListOf>() @@ -21,7 +24,9 @@ class UIKitAttributeValueBuilder { fun AttrsBuilder<*>.buildAndAddAttribute( attributeName: String, - block: UIKitAttributeValueBuilder.() -> Unit + block: AttributeBuilder.() -> Unit ) { - attr(attributeName, UIKitAttributeValueBuilder().apply(block).build()) + buildAttribute(attributeName, block).let { + attr(it.first, it.second) + } } diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dropdown.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dropdown.kt index 43b1751..7d40b0f 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dropdown.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/Dropdown.kt @@ -4,6 +4,7 @@ import androidx.compose.runtime.Composable import dev.inmo.jsuikit.buildAndAddAttribute import dev.inmo.jsuikit.modifiers.* import dev.inmo.jsuikit.utils.Milliseconds +import dev.inmo.jsuikit.utils.buildAttribute import org.jetbrains.compose.web.dom.* import org.w3c.dom.HTMLDivElement diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt index 0b6674a..ea829b3 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/utils/AttributeBuilder.kt @@ -5,8 +5,8 @@ class AttributeBuilder ( private val parametersPreset: MutableMap = mutableMapOf() ) { - fun add(k: String, v: String? = null) = parametersPreset.set(k, v) - infix fun String.to(value: String?) = add(this, value) + fun add(k: String, v: Any? = null) = parametersPreset.set(k, v ?.toString()) + infix fun String.to(value: Any?) = add(this, value) operator fun String.unaryPlus() = add(this, null) fun build(): Pair = Pair(