Browse Source

Add missing content sectioning HTML elements

Namely: ADDRESS, ARTICLE, ASIDE, HEADER

see https://developer.mozilla.org/en-US/docs/Web/HTML/Element
MERGE_HTML_BUILDER
Shagen Ogandzhanian 3 years ago
parent
commit
08dc15182f
  1. 5
      web/core/src/jsMain/kotlin/androidx/compose/web/elements/Base.kt
  2. 48
      web/core/src/jsMain/kotlin/androidx/compose/web/elements/Elements.kt
  3. 10
      web/core/src/jsTest/kotlin/elements/ElementsTests.kt

5
web/core/src/jsMain/kotlin/androidx/compose/web/elements/Base.kt

@ -88,6 +88,11 @@ interface ElementBuilder<TElement : Element> {
return object : ElementBuilderImplementation<TElement>(tagName) {} return object : ElementBuilderImplementation<TElement>(tagName) {}
} }
val Address: ElementBuilder<HTMLElement> = ElementBuilderImplementation("address")
val Article: ElementBuilder<HTMLElement> = ElementBuilderImplementation("article")
val Aside: ElementBuilder<HTMLElement> = ElementBuilderImplementation("aside")
val Header: ElementBuilder<HTMLElement> = ElementBuilderImplementation("header")
val Div: ElementBuilder<HTMLDivElement> = ElementBuilderImplementation("div") val Div: ElementBuilder<HTMLDivElement> = ElementBuilderImplementation("div")
val A: ElementBuilder<HTMLAnchorElement> = ElementBuilderImplementation("a") val A: ElementBuilder<HTMLAnchorElement> = ElementBuilderImplementation("a")
val Input: ElementBuilder<HTMLInputElement> = ElementBuilderImplementation("input") val Input: ElementBuilder<HTMLInputElement> = ElementBuilderImplementation("input")

48
web/core/src/jsMain/kotlin/androidx/compose/web/elements/Elements.kt

@ -47,6 +47,54 @@ import org.w3c.dom.Text
typealias AttrBuilderContext<T> = AttrsBuilder<T>.() -> Unit typealias AttrBuilderContext<T> = AttrsBuilder<T>.() -> Unit
typealias ContentBuilder<T> = @Composable ElementScope<T>.() -> Unit typealias ContentBuilder<T> = @Composable ElementScope<T>.() -> Unit
@Composable
fun Address(
attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null
) {
TagElement(
elementBuilder = ElementBuilder.Address,
applyAttrs = attrs,
content = content
)
}
@Composable
fun Article(
attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null
) {
TagElement(
elementBuilder = ElementBuilder.Article,
applyAttrs = attrs,
content = content
)
}
@Composable
fun Aside(
attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null
) {
TagElement(
elementBuilder = ElementBuilder.Aside,
applyAttrs = attrs,
content = content
)
}
@Composable
fun Header(
attrs: AttrBuilderContext<HTMLElement> = {},
content: ContentBuilder<HTMLElement>? = null
) {
TagElement(
elementBuilder = ElementBuilder.Header,
applyAttrs = attrs,
content = content
)
}
@Composable @Composable
fun Text(value: String) { fun Text(value: String) {
ComposeNode<DomNodeWrapper, DomApplier>( ComposeNode<DomNodeWrapper, DomApplier>(

10
web/core/src/jsTest/kotlin/elements/ElementsTests.kt

@ -9,6 +9,9 @@ import androidx.compose.runtime.Composable
import org.jetbrains.compose.web.attributes.AttrsBuilder import org.jetbrains.compose.web.attributes.AttrsBuilder
import org.jetbrains.compose.web.core.tests.runTest import org.jetbrains.compose.web.core.tests.runTest
import org.jetbrains.compose.web.dom.A import org.jetbrains.compose.web.dom.A
import org.jetbrains.compose.web.dom.Address
import org.jetbrains.compose.web.dom.Article
import org.jetbrains.compose.web.dom.Aside
import org.jetbrains.compose.web.dom.B import org.jetbrains.compose.web.dom.B
import org.jetbrains.compose.web.dom.Br import org.jetbrains.compose.web.dom.Br
import org.jetbrains.compose.web.dom.Button import org.jetbrains.compose.web.dom.Button
@ -27,6 +30,7 @@ import org.jetbrains.compose.web.dom.H3
import org.jetbrains.compose.web.dom.H4 import org.jetbrains.compose.web.dom.H4
import org.jetbrains.compose.web.dom.H5 import org.jetbrains.compose.web.dom.H5
import org.jetbrains.compose.web.dom.H6 import org.jetbrains.compose.web.dom.H6
import org.jetbrains.compose.web.dom.Header
import org.jetbrains.compose.web.dom.Hr import org.jetbrains.compose.web.dom.Hr
import org.jetbrains.compose.web.dom.I import org.jetbrains.compose.web.dom.I
import org.jetbrains.compose.web.dom.Img import org.jetbrains.compose.web.dom.Img
@ -58,11 +62,15 @@ import org.w3c.dom.get
import kotlin.test.Test import kotlin.test.Test
import kotlin.test.assertEquals import kotlin.test.assertEquals
class ElementsTests { class ElementsTests {
@Test @Test
fun nodeNames() = runTest { fun nodeNames() = runTest {
val nodes = listOf<Pair<@Composable () -> Unit, String>>( val nodes = listOf<Pair<@Composable () -> Unit, String>>(
Pair({ Address() }, "ADDRESS"),
Pair({ Article() }, "ARTICLE"),
Pair({ Aside() }, "ASIDE"),
Pair({ Header() }, "HEADER"),
Pair({ Div() }, "DIV"), Pair({ Div() }, "DIV"),
Pair({ A() }, "A"), Pair({ A() }, "A"),
Pair({ Button() }, "BUTTON"), Pair({ Button() }, "BUTTON"),

Loading…
Cancel
Save