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
## 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
* `Kotlin`: `1.7.20`

View File

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

View File

@ -202,14 +202,19 @@ sealed class Icon(val name: String) {
object Youtube : Brands("youtube")
}
@Composable
operator fun invoke(
class Custom(name: String) : Icon(name)
companion object {
}
}
@Composable
operator fun Icon.invoke(
vararg modifiers: UIKitModifier,
type: UIKitIconType = UIKitIconType.Default,
ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null
) {
) {
val configurer: AttrBuilderContext<out HTMLElement> = {
include(*modifiers, type, UIKitIcon)
attr("uk-icon", "icon: $name${if (ratio != null) { "; ratio: $ratio" } else ""}")
@ -223,39 +228,36 @@ sealed class Icon(val name: String) {
UIKitIconType.Link -> A(href = "#", configurer)
UIKitIconType.Button -> Button(configurer)
}
}
class Custom(name: String) : Icon(name)
@Composable
fun drawAsButton(
vararg modifiers: UIKitModifier,
ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null
) = invoke(*modifiers, type = UIKitIconType.Button, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable
fun drawAsIcon(
vararg modifiers: UIKitModifier,
ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null
) = invoke(*modifiers, type = UIKitIconType.Default, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable
fun drawAsLink(
vararg modifiers: UIKitModifier,
ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null
) = invoke(*modifiers, type = UIKitIconType.Link, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable
fun drawAsFormInputPart(
vararg modifiers: UIKitModifier,
ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null
) = invoke(*modifiers, UIKitForm.Icon, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
}
@Composable
fun Icon.drawAsButton(
vararg modifiers: UIKitModifier,
ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null
) = invoke(*modifiers, type = UIKitIconType.Button, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable
fun Icon.drawAsIcon(
vararg modifiers: UIKitModifier,
ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null
) = invoke(*modifiers, type = UIKitIconType.Default, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable
fun Icon.drawAsLink(
vararg modifiers: UIKitModifier,
ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null
) = invoke(*modifiers, type = UIKitIconType.Link, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)
@Composable
fun Icon.drawAsFormInputPart(
vararg modifiers: UIKitModifier,
ratio: Float? = null,
attributesCustomizer: AttrBuilderContext<out HTMLElement> = {},
onClick: ((Event) -> Unit)? = null
) = invoke(*modifiers, UIKitForm.Icon, ratio = ratio, onClick = onClick, attributesCustomizer = attributesCustomizer)

View File

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

View File

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