Merge pull request #71 from InsanusMokrassar/0.4.1

0.4.1
This commit is contained in:
InsanusMokrassar 2022-11-16 00:57:42 +06:00 committed by GitHub
commit 8c086eb3eb
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 91 additions and 66 deletions

View File

@ -1,5 +1,10 @@
# Changelog # Changelog
## 0.4.1
* Now it is possible to use `StandardInput` with simple `T` types instead of states
* `List` may accept any `Iterable`
## 0.4.0 ## 0.4.0
* `Kotlin`: `1.7.20` * `Kotlin`: `1.7.20`

View File

@ -9,4 +9,4 @@ android.enableJetifier=true
# Project data # Project data
group=dev.inmo group=dev.inmo
version=0.4.0 version=0.4.1

View File

@ -202,8 +202,13 @@ sealed class Icon(val name: String) {
object Youtube : Brands("youtube") object Youtube : Brands("youtube")
} }
class Custom(name: String) : Icon(name)
companion object {
}
}
@Composable @Composable
operator fun invoke( operator fun Icon.invoke(
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
type: UIKitIconType = UIKitIconType.Default, type: UIKitIconType = UIKitIconType.Default,
ratio: Float? = null, ratio: Float? = null,
@ -225,10 +230,8 @@ sealed class Icon(val name: String) {
} }
} }
class Custom(name: String) : Icon(name)
@Composable @Composable
fun drawAsButton( fun Icon.drawAsButton(
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
ratio: Float? = null, ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {}, attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
@ -236,7 +239,7 @@ sealed class Icon(val name: String) {
) = invoke(*modifiers, type = UIKitIconType.Button, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer) ) = invoke(*modifiers, type = UIKitIconType.Button, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable @Composable
fun drawAsIcon( fun Icon.drawAsIcon(
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
ratio: Float? = null, ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {}, attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
@ -244,7 +247,7 @@ sealed class Icon(val name: String) {
) = invoke(*modifiers, type = UIKitIconType.Default, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer) ) = invoke(*modifiers, type = UIKitIconType.Default, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable @Composable
fun drawAsLink( fun Icon.drawAsLink(
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
ratio: Float? = null, ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {}, attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
@ -252,10 +255,9 @@ sealed class Icon(val name: String) {
) = invoke(*modifiers, type = UIKitIconType.Link, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer) ) = invoke(*modifiers, type = UIKitIconType.Link, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable @Composable
fun drawAsFormInputPart( fun Icon.drawAsFormInputPart(
vararg modifiers: UIKitModifier, vararg modifiers: UIKitModifier,
ratio: Float? = null, ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {}, attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null onClick: ((Event) -> Unit)? = null
) = invoke(*modifiers, UIKitForm.Icon, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer) ) = invoke(*modifiers, UIKitForm.Icon, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
}

View File

@ -10,7 +10,7 @@ import org.w3c.dom.HTMLUListElement
@Composable @Composable
fun <T> List( fun <T> List(
data: SnapshotStateList<T>, data: Iterable<T>,
ukAttrs: Attrs<HTMLUListElement> = Attrs.empty(), ukAttrs: Attrs<HTMLUListElement> = Attrs.empty(),
elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit elementAllocator: @Composable ElementScope<HTMLUListElement>.(T) -> Unit
) { ) {
@ -29,7 +29,7 @@ fun <T> List(
@Composable @Composable
fun <T> ListWithTitle( fun <T> ListWithTitle(
title: String, title: String,
data: SnapshotStateList<T>, data: Iterable<T>,
vararg titleModifiers: UIKitModifier, vararg titleModifiers: UIKitModifier,
ulModifiers: Array<UIKitModifier> = emptyArray(), ulModifiers: Array<UIKitModifier> = emptyArray(),
besidesTitleAndList: (@Composable () -> Unit)? = null, besidesTitleAndList: (@Composable () -> Unit)? = null,

View File

@ -9,13 +9,14 @@ import org.jetbrains.compose.web.dom.Input
import org.w3c.dom.HTMLInputElement import org.w3c.dom.HTMLInputElement
@Composable @Composable
fun <T> StandardInput( fun <T> DefaultInput(
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> = {},
) = DefaultInput(
type,
state.value,
disabledState ?.value == true,
placeholder,
modifiers = modifiers,
attributesCustomizer = attributesCustomizer
) {
state.value = it
}