Remove redundant DList and other + add AttrsWithContentBuilder

This commit is contained in:
InsanusMokrassar 2022-05-19 12:13:13 +06:00
parent 9b992cbda0
commit 276eaddcac
4 changed files with 19 additions and 57 deletions

View File

@ -2,6 +2,9 @@
## 0.1.2 ## 0.1.2
* New typealias `AttrsWithContentBuilder`
* Old `DList` and related composable functions removed (they are built-in in compose)
## 0.1.1 ## 0.1.1
* `Compose`: `1.2.0-alpha01-dev686` * `Compose`: `1.2.0-alpha01-dev686`

View File

@ -4,8 +4,7 @@ import androidx.compose.runtime.Composable
import dev.inmo.jsuikit.modifiers.UIKitDescriptionList import dev.inmo.jsuikit.modifiers.UIKitDescriptionList
import dev.inmo.jsuikit.modifiers.include import dev.inmo.jsuikit.modifiers.include
import dev.inmo.jsuikit.utils.* import dev.inmo.jsuikit.utils.*
import org.jetbrains.compose.web.dom.ContentBuilder import org.jetbrains.compose.web.dom.*
import org.jetbrains.compose.web.dom.ElementScope
import org.w3c.dom.HTMLDListElement import org.w3c.dom.HTMLDListElement
import org.w3c.dom.HTMLElement import org.w3c.dom.HTMLElement

View File

@ -0,0 +1,15 @@
package dev.inmo.jsuikit.utils
import org.jetbrains.compose.web.dom.ContentBuilder
import org.w3c.dom.Element
typealias AttrsWithContentBuilder<T> = Pair<Attrs<T>, ContentBuilder<T>>
inline val <T : Element> AttrsWithContentBuilder<T>.attrs
get() = first
inline val <T : Element> AttrsWithContentBuilder<T>.attributesBuilderContext
get() = attrs.builder
inline val <T : Element> AttrsWithContentBuilder<T>.builder
get() = second

View File

@ -1,55 +0,0 @@
package dev.inmo.jsuikit.utils
import androidx.compose.runtime.Composable
import kotlinx.browser.document
import org.jetbrains.compose.web.dom.*
import org.w3c.dom.*
private object DListElementBuilder : ElementBuilder<HTMLDListElement> {
private val el: Element by lazy { document.createElement("dl") }
override fun create(): HTMLDListElement = el.cloneNode() as HTMLDListElement
}
private object DTermElementBuilder : ElementBuilder<HTMLElement> {
private val el: Element by lazy { document.createElement("dt") }
override fun create(): HTMLElement = el.cloneNode() as HTMLElement
}
private object DDescriptionElementBuilder : ElementBuilder<HTMLElement> {
private val el: Element by lazy { document.createElement("dd") }
override fun create(): HTMLElement = el.cloneNode() as HTMLElement
}
@Composable
fun DList(
attrs: AttrBuilderContext<HTMLDListElement>? = null,
content: ContentBuilder<HTMLDListElement>? = null
) {
TagElement(
DListElementBuilder,
attrs,
content
)
}
@Composable
fun DTerm(
attrs: AttrBuilderContext<HTMLElement>? = null,
content: ContentBuilder<HTMLElement>? = null
) {
TagElement(
DTermElementBuilder,
attrs,
content
)
}
@Composable
fun DDescription(
attrs: AttrBuilderContext<HTMLElement>? = null,
content: ContentBuilder<HTMLElement>? = null
) {
TagElement(
DDescriptionElementBuilder,
attrs,
content
)
}