mirror of
https://github.com/InsanusMokrassar/JSUIKitKBindings.git
synced 2024-11-04 15:33:49 +00:00
commit
8c086eb3eb
@ -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`
|
||||||
|
@ -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
|
||||||
|
@ -202,60 +202,62 @@ sealed class Icon(val name: String) {
|
|||||||
object Youtube : Brands("youtube")
|
object Youtube : Brands("youtube")
|
||||||
}
|
}
|
||||||
|
|
||||||
@Composable
|
|
||||||
operator fun 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 ""}")
|
|
||||||
onClick ?.let { _ ->
|
|
||||||
onClick { onClick(it.nativeEvent) }
|
|
||||||
}
|
|
||||||
attributesCustomizer()
|
|
||||||
}
|
|
||||||
when (type) {
|
|
||||||
UIKitIconType.Default -> Span(configurer)
|
|
||||||
UIKitIconType.Link -> A(href = "#", configurer)
|
|
||||||
UIKitIconType.Button -> Button(configurer)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
class Custom(name: String) : Icon(name)
|
class Custom(name: String) : Icon(name)
|
||||||
|
|
||||||
@Composable
|
companion object {
|
||||||
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
|
||||||
|
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 ""}")
|
||||||
|
onClick ?.let { _ ->
|
||||||
|
onClick { onClick(it.nativeEvent) }
|
||||||
|
}
|
||||||
|
attributesCustomizer()
|
||||||
|
}
|
||||||
|
when (type) {
|
||||||
|
UIKitIconType.Default -> Span(configurer)
|
||||||
|
UIKitIconType.Link -> A(href = "#", configurer)
|
||||||
|
UIKitIconType.Button -> Button(configurer)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@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
|
@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,
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user