From 4a7101697af8ab7c5770a69b5c9bcd6e6af17bc9 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Wed, 26 Jan 2022 00:51:26 +0600 Subject: [PATCH] TextField -> StandardInput + fixes in it --- CHANGELOG.md | 3 +++ .../{TextField.kt => StandardInput.kt} | 24 +++++++++++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) rename src/jsMain/kotlin/dev/inmo/jsuikit/elements/{TextField.kt => StandardInput.kt} (55%) diff --git a/CHANGELOG.md b/CHANGELOG.md index 73eb88c..56c5668 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,9 @@ ## 0.0.27 +* `TextField` has been renamed to `StandardInput` +* `StandardInput` now will look for changes in state + ## 0.0.26 * Add UIKitColumn diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/TextField.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/StandardInput.kt similarity index 55% rename from src/jsMain/kotlin/dev/inmo/jsuikit/elements/TextField.kt rename to src/jsMain/kotlin/dev/inmo/jsuikit/elements/StandardInput.kt index af8a0a2..85044fa 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/TextField.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/StandardInput.kt @@ -9,7 +9,7 @@ import org.jetbrains.compose.web.dom.Input import org.w3c.dom.HTMLInputElement @Composable -fun TextField( +fun StandardInput( type: InputType, state: MutableState, disabledState: State? = null, @@ -23,7 +23,16 @@ fun TextField( placeholder ?.let(::placeholder) - onChange { state.value = it.value } + state.value.let { + when (it) { + is String -> value(it) + is Number -> value(it) + else -> {} + } + } + + onInput { state.value = it.value } + disabledState ?.let { if (it.value) { disabled() @@ -32,3 +41,14 @@ fun TextField( attributesCustomizer() } } + +@Composable +@Deprecated("Renamed", ReplaceWith("StandardInput", "dev.inmo.jsuikit.elements.StandardInput")) +fun TextField( + type: InputType, + state: MutableState, + disabledState: State? = null, + placeholder: String? = null, + vararg modifiers: UIKitModifier, + attributesCustomizer: AttrBuilderContext = {}, +) = StandardInput(type, state, disabledState, placeholder, modifiers = modifiers, attributesCustomizer)