mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-12-22 08:37:24 +00:00
commit
8c086eb3eb
@ -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`
|
||||
|
@ -9,4 +9,4 @@ android.enableJetifier=true
|
||||
# Project data
|
||||
|
||||
group=dev.inmo
|
||||
version=0.4.0
|
||||
version=0.4.1
|
||||
|
@ -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)
|
||||
|
@ -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,
|
||||
|
@ -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
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user