Browse Source

Pass resolved with self selector to nested builder (#1298)

pull/1312/head
Abasov Akif 3 years ago committed by GitHub
parent
commit
984a26ce1d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 11
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSBuilder.kt
  2. 35
      web/core/src/jsTest/kotlin/CSSStylesheetTests.kt

11
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSBuilder.kt

@ -14,13 +14,14 @@ class CSSBuilderImpl(
rulesHolder: CSSRulesHolder
) : CSSRuleBuilderImpl(), CSSBuilder, CSSRulesHolder by rulesHolder {
override fun style(selector: CSSSelector, cssRule: CSSBuilder.() -> Unit) {
val (style, rules) = buildCSS(root, selector, cssRule)
rules.forEach { add(it) }
if (selector.contains(self, true) || selector.contains(root, true)) {
add(selector, style)
val resolvedSelector = if (selector.contains(self, true) || selector.contains(root, true)) {
selector
} else {
add(desc(self, selector), style)
desc(self, selector)
}
val (style, rules) = buildCSS(root, resolvedSelector, cssRule)
rules.forEach { add(it) }
add(resolvedSelector, style)
}
override fun buildRules(rulesBuild: GenericStyleSheetBuilder<CSSBuilder>.() -> Unit) =

35
web/core/src/jsTest/kotlin/CSSStylesheetTests.kt

@ -78,6 +78,17 @@ object AppStylesheet : StyleSheet() {
color(Color.lime)
}
}
val withNestedWithImplicitSelf2Layers by style {
color(Color.green)
"h1" {
color(Color.lime)
"span" {
color(Color.red)
}
}
}
val withNestedWithExplicitSelf by style {
color(Color.green)
desc(self, "h1") style {
@ -190,4 +201,28 @@ class CSSVariableTests {
"Nested selector with implicit self isn't generated correctly"
)
}
@Test
fun nestedStyleWithImplicitSelf2Layers() = runTest {
val generatedRules = AppStylesheet.cssRules.map { it.stringPresentation() }
assertContains(
generatedRules,
"""
.AppStylesheet-withNestedWithImplicitSelf2Layers h1 {
color: lime;
}
""".trimIndent(),
"Nested selector with implicit self isn't generated correctly"
)
assertContains(
generatedRules,
"""
.AppStylesheet-withNestedWithImplicitSelf2Layers h1 span {
color: red;
}
""".trimIndent(),
"Nested selector with implicit self isn't generated correctly"
)
}
}

Loading…
Cancel
Save