StandardInput improvements

This commit is contained in:
InsanusMokrassar 2022-11-15 21:50:15 +06:00
parent 36214aeba5
commit 17ae0b119b
2 changed files with 28 additions and 8 deletions

View File

@ -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`

View File

@ -11,11 +11,12 @@ import org.w3c.dom.HTMLInputElement
@Composable
fun <T> StandardInput(
type: InputType<T>,
state: MutableState<T>,
disabledState: State<Boolean>? = null,
value: T,
disabled: Boolean = false,
placeholder: String? = null,
vararg modifiers: UIKitModifier,
attributesCustomizer: AttrBuilderContext<HTMLInputElement> = {},
onChange: (T) -> Unit
) {
Input(type) {
classes("uk-input")
@ -23,7 +24,7 @@ fun <T> StandardInput(
placeholder ?.let(::placeholder)
state.value.let {
value.let {
when (it) {
is String -> value(it)
is Number -> value(it)
@ -31,13 +32,30 @@ fun <T> StandardInput(
}
}
onInput { state.value = it.value }
onInput { onChange(it.value) }
disabledState ?.let {
if (it.value) {
disabled()
}
if (disabled) {
disabled()
}
attributesCustomizer()
}
}
@Composable
fun <T> StandardInput(
type: InputType<T>,
state: MutableState<T>,
disabledState: State<Boolean>? = null,
placeholder: String? = null,
vararg modifiers: UIKitModifier,
attributesCustomizer: AttrBuilderContext<HTMLInputElement> = {},
) = StandardInput(
type,
state.value,
disabledState ?.value == true,
placeholder,
modifiers = modifiers,
attributesCustomizer = attributesCustomizer
) {
state.value = it
}