fixes in DropAre and new type of attrs

This commit is contained in:
InsanusMokrassar 2022-03-02 18:40:07 +06:00
parent c720973bfc
commit f77c21ac51
2 changed files with 15 additions and 8 deletions

View File

@ -3,6 +3,7 @@ package dev.inmo.jsuikit.elements
import androidx.compose.runtime.Composable
import dev.inmo.jsuikit.modifiers.*
import dev.inmo.jsuikit.utils.Attrs
import dev.inmo.jsuikit.utils.InputAttrs
import org.jetbrains.compose.web.attributes.InputType
import org.jetbrains.compose.web.dom.*
import org.w3c.dom.HTMLDivElement
@ -11,7 +12,7 @@ import org.w3c.dom.HTMLInputElement
@Composable
fun DropArea(
attrs: Attrs<HTMLDivElement> = Attrs.empty(),
inputAttrs: Attrs<HTMLInputElement> = Attrs.empty(),
inputAttrs: InputAttrs<String> = Attrs.empty(),
contentBuilder: ContentBuilder<HTMLDivElement> = {}
) = Div(
{
@ -19,6 +20,8 @@ fun DropArea(
attrs.builder(this)
}
) {
Input(InputType.File, attrs = { inputAttrs.builder.invoke(this) })
FileInput {
inputAttrs.builder.invoke(this)
}
contentBuilder(this)
}

View File

@ -3,19 +3,22 @@ package dev.inmo.jsuikit.utils
import dev.inmo.jsuikit.modifiers.UIKitModifier
import dev.inmo.jsuikit.modifiers.include
import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.attributes.InputType
import org.jetbrains.compose.web.attributes.builders.InputAttrsBuilder
import org.jetbrains.compose.web.dom.AttrBuilderContext
import org.w3c.dom.Element
import org.w3c.dom.HTMLInputElement
class AttributesCollection<T : Element> (
class AttributesCollection<T : Element, Builder : AttrsBuilder<T>> (
private vararg val modifiers: UIKitModifier,
private val attrs: AttrBuilderContext<T> = {}
private val attrs: Builder.() -> Unit = {}
) {
val builder: AttrBuilderContext<T> = {
val builder: Builder.() -> Unit = {
include(*modifiers)
attrs()
}
operator fun plus(other: AttributesCollection<T>) = AttributesCollection<T>(
operator fun plus(other: AttributesCollection<T, Builder>) = AttributesCollection<T, Builder>(
*(modifiers + other.modifiers).distinct().toTypedArray()
) {
this@AttributesCollection.attrs.invoke(this)
@ -26,8 +29,9 @@ class AttributesCollection<T : Element> (
val Empty = Attrs<Element>()
@Suppress("UNCHECKED_CAST")
fun <T : Element> empty() = Empty as Attrs<T>
fun <T : Element, Builder : AttrsBuilder<T>> empty() = Empty as AttributesCollection<T, Builder>
}
}
typealias Attrs<T> = AttributesCollection<T>
typealias Attrs<T> = AttributesCollection<T, AttrsBuilder<T>>
typealias InputAttrs<T> = AttributesCollection<HTMLInputElement, InputAttrsBuilder<T>>