2022-01-12 13:58:52 +00:00
|
|
|
package dev.inmo.jsuikit.modifiers
|
2021-12-22 08:38:12 +00:00
|
|
|
|
2022-03-31 03:12:01 +00:00
|
|
|
import dev.inmo.jsuikit.utils.Attrs
|
2022-03-06 10:18:21 +00:00
|
|
|
import org.jetbrains.compose.web.attributes.AttrsScope
|
2022-03-31 03:12:01 +00:00
|
|
|
import org.jetbrains.compose.web.dom.AttrBuilderContext
|
|
|
|
import org.w3c.dom.Element
|
2021-12-22 08:38:12 +00:00
|
|
|
|
|
|
|
interface UIKitModifier {
|
|
|
|
val classes: Array<String>
|
|
|
|
get() = emptyArray()
|
|
|
|
val otherAttrs: Map<String, String>
|
|
|
|
get() = emptyMap()
|
|
|
|
}
|
|
|
|
|
2022-03-06 10:18:21 +00:00
|
|
|
fun AttrsScope<*>.include(vararg container: UIKitModifier?) {
|
2021-12-22 08:38:12 +00:00
|
|
|
container.forEach {
|
|
|
|
it ?.classes ?.let { newClasses -> classes(*newClasses) }
|
|
|
|
it ?.otherAttrs ?.let { attrs -> attrs.forEach { (k, v) -> attr(k, v) } }
|
|
|
|
}
|
|
|
|
}
|
2022-03-31 03:12:01 +00:00
|
|
|
|
|
|
|
fun <T : Element> UIKitModifier.asAttributesBuilder(): AttrBuilderContext<T> = {
|
|
|
|
include(this@asAttributesBuilder)
|
|
|
|
}
|
|
|
|
operator fun UIKitModifier.plus(other: UIKitModifier): UIKitModifier = UIKitCustom(
|
|
|
|
classes + other.classes,
|
|
|
|
otherAttrs + other.otherAttrs
|
|
|
|
)
|
2022-04-26 08:54:26 +00:00
|
|
|
fun <T: Element> UIKitModifier?.builder() = Attrs<T>(this).builder
|
|
|
|
fun <T: Element> Array<out UIKitModifier?>.builder() = Attrs<T>(*this).builder
|
|
|
|
inline fun <T: Element> attrsBuilder(vararg modifiers: UIKitModifier?) = modifiers.builder<T>()
|
2022-03-31 03:12:01 +00:00
|
|
|
@JsName("plusBuilder")
|
2022-04-26 08:54:26 +00:00
|
|
|
operator fun <T: Element> UIKitModifier?.plus(other: UIKitModifier?): AttrBuilderContext<T> = Attrs<T>(this@plus, other).builder
|