mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-12-22 08:37:24 +00:00
StandardInput improvements
This commit is contained in:
parent
36214aeba5
commit
17ae0b119b
@ -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`
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user