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
|
## 0.4.1
|
||||||
|
|
||||||
|
* Now it is possible to use `StandardInput` with simple `T` types instead of states
|
||||||
|
|
||||||
## 0.4.0
|
## 0.4.0
|
||||||
|
|
||||||
* `Kotlin`: `1.7.20`
|
* `Kotlin`: `1.7.20`
|
||||||
|
@ -11,11 +11,12 @@ import org.w3c.dom.HTMLInputElement
|
|||||||
@Composable
|
@Composable
|
||||||
fun <T> StandardInput(
|
fun <T> StandardInput(
|
||||||
type: InputType<T>,
|
type: InputType<T>,
|
||||||
state: MutableState<T>,
|
value: T,
|
||||||
disabledState: State<Boolean>? = null,
|
disabled: Boolean = false,
|
||||||
placeholder: String? = null,
|
placeholder: String? = null,
|
||||||
vararg modifiers: UIKitModifier,
|
vararg modifiers: UIKitModifier,
|
||||||
attributesCustomizer: AttrBuilderContext<HTMLInputElement> = {},
|
attributesCustomizer: AttrBuilderContext<HTMLInputElement> = {},
|
||||||
|
onChange: (T) -> Unit
|
||||||
) {
|
) {
|
||||||
Input(type) {
|
Input(type) {
|
||||||
classes("uk-input")
|
classes("uk-input")
|
||||||
@ -23,7 +24,7 @@ fun <T> StandardInput(
|
|||||||
|
|
||||||
placeholder ?.let(::placeholder)
|
placeholder ?.let(::placeholder)
|
||||||
|
|
||||||
state.value.let {
|
value.let {
|
||||||
when (it) {
|
when (it) {
|
||||||
is String -> value(it)
|
is String -> value(it)
|
||||||
is Number -> 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 (disabled) {
|
||||||
if (it.value) {
|
|
||||||
disabled()
|
disabled()
|
||||||
}
|
}
|
||||||
}
|
|
||||||
attributesCustomizer()
|
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