Browse Source

[web] Remove classes builder version from API

pull/712/head 0.4.0-rc2
Shagen Ogandzhanian 3 years ago
parent
commit
42ad7c7dcc
  1. 14
      web/core/src/jsMain/kotlin/androidx/compose/web/attributes/AttrsBuilder.kt
  2. 47
      web/core/src/jsTest/kotlin/elements/AttributesTests.kt

14
web/core/src/jsMain/kotlin/androidx/compose/web/attributes/AttrsBuilder.kt

@ -18,9 +18,6 @@ class AttrsBuilder<TTag : Tag> : EventsListenerBuilder() {
styleBuilder.apply(builder)
}
inline fun classes(builder: ClassesAttrBuilder.() -> Unit) =
prop(setClassList, ClassesAttrBuilder().apply(builder).asList().toTypedArray())
fun classes(vararg classes: String) = prop(setClassList, classes)
fun id(value: String) = attr(ID, value)
@ -70,17 +67,6 @@ class AttrsBuilder<TTag : Tag> : EventsListenerBuilder() {
}
}
class ClassesAttrBuilder {
private val classes = mutableListOf<String>()
operator fun String.unaryPlus() {
classes.add(this)
}
fun asList(): List<String> = classes
fun asString(): String = classes.joinToString(" ")
}
val setClassList: (HTMLElement, Array<out String>) -> Unit = { e, classList ->
e.classList.add(*classList)
}

47
web/core/src/jsTest/kotlin/elements/AttributesTests.kt

@ -99,52 +99,13 @@ class AttributesTests {
}
@Test
fun multipleClassesBuildersCallsAddMoreClasses() = runTest {
composition {
Div({
classes("a", "b")
classes {
+"c"
+"d"
}
}) {}
}
val div = root.firstChild as HTMLDivElement
assertEquals(
expected = "a b c d",
actual = div.getAttribute("class")
)
}
@Test
fun multipleClassesBuildersCallsAddMoreClasses2() = runTest {
composition {
Div({
classes {
+"c"
+"d"
}
classes("a", "b")
}) {}
}
val div = root.firstChild as HTMLDivElement
assertEquals(
expected = "c d a b",
actual = div.getAttribute("class")
)
}
@Test
fun multipleClassesBuildersCallsWithConditionsAddCorrectClasses() = runTest {
fun multipleClassesCallsWithConditionsAddCorrectClasses() = runTest {
val addClassD = mutableStateOf(true)
composition {
Div({
classes {
+"c"
if (addClassD.value) +"d"
classes("c")
if (addClassD.value) {
classes("d")
}
classes("a", "b")
}) {}

Loading…
Cancel
Save