diff --git a/CHANGELOG.md b/CHANGELOG.md index d69d984..218050d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## 0.4.1 +* Now it is possible to use `StandardInput` with simple `T` types instead of states + ## 0.4.0 * `Kotlin`: `1.7.20` diff --git a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/StandardInput.kt b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/StandardInput.kt index f5d5dd4..20d5965 100644 --- a/src/jsMain/kotlin/dev/inmo/jsuikit/elements/StandardInput.kt +++ b/src/jsMain/kotlin/dev/inmo/jsuikit/elements/StandardInput.kt @@ -11,11 +11,12 @@ import org.w3c.dom.HTMLInputElement @Composable fun StandardInput( type: InputType, - state: MutableState, - disabledState: State? = null, + value: T, + disabled: Boolean = false, placeholder: String? = null, vararg modifiers: UIKitModifier, attributesCustomizer: AttrBuilderContext = {}, + onChange: (T) -> Unit ) { Input(type) { classes("uk-input") @@ -23,7 +24,7 @@ fun StandardInput( placeholder ?.let(::placeholder) - state.value.let { + value.let { when (it) { is String -> value(it) is Number -> value(it) @@ -31,13 +32,30 @@ fun StandardInput( } } - onInput { state.value = it.value } + onInput { onChange(it.value) } - disabledState ?.let { - if (it.value) { - disabled() - } + if (disabled) { + disabled() } attributesCustomizer() } } + +@Composable +fun StandardInput( + type: InputType, + state: MutableState, + disabledState: State? = null, + placeholder: String? = null, + vararg modifiers: UIKitModifier, + attributesCustomizer: AttrBuilderContext = {}, +) = StandardInput( + type, + state.value, + disabledState ?.value == true, + placeholder, + modifiers = modifiers, + attributesCustomizer = attributesCustomizer +) { + state.value = it +}