diff --git a/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/utils/stylsheet.kt b/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/utils/stylsheet.kt new file mode 100644 index 0000000000..6a6bc42bf9 --- /dev/null +++ b/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/utils/stylsheet.kt @@ -0,0 +1,14 @@ +/* + * Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers. + * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. + */ + +package org.jetbrains.compose.web.css.utils + +import org.jetbrains.compose.web.css.StyleSheet +import org.jetbrains.compose.web.dom.stringPresentation + + +fun StyleSheet.serializeRules(): List { + return cssRules.map { it.stringPresentation(indent = " ", delimiter = "") } +} \ No newline at end of file diff --git a/web/core/src/jsTest/kotlin/css/AnimationTests.kt b/web/core/src/jsTest/kotlin/css/AnimationTests.kt index 73822e0245..629149f066 100644 --- a/web/core/src/jsTest/kotlin/css/AnimationTests.kt +++ b/web/core/src/jsTest/kotlin/css/AnimationTests.kt @@ -5,9 +5,9 @@ package org.jetbrains.compose.web.core.tests.css import org.jetbrains.compose.web.ExperimentalComposeWebApi -import org.jetbrains.compose.web.testutils.* import org.jetbrains.compose.web.css.* -import org.jetbrains.compose.web.dom.stringPresentation +import org.jetbrains.compose.web.css.utils.serializeRules +import org.jetbrains.compose.web.testutils.runTest import org.w3c.dom.HTMLStyleElement import org.w3c.dom.css.CSSStyleSheet import org.w3c.dom.get @@ -39,7 +39,7 @@ object AnimationsStyleSheet : StyleSheet() { class AnimationTests { @Test fun animationClassGenerated() = runTest { - val generatedRules = AnimationsStyleSheet.cssRules.map { it.stringPresentation(indent = " ", delimiter = "") } + val generatedRules = AnimationsStyleSheet.serializeRules() assertContentEquals( diff --git a/web/core/src/jsTest/kotlin/css/StyleSheetTests.kt b/web/core/src/jsTest/kotlin/css/StyleSheetTests.kt new file mode 100644 index 0000000000..ac0278b48e --- /dev/null +++ b/web/core/src/jsTest/kotlin/css/StyleSheetTests.kt @@ -0,0 +1,45 @@ +/* + * Copyright 2020-2021 JetBrains s.r.o. and respective authors and developers. + * Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE.txt file. + */ + +package org.jetbrains.compose.web.core.tests.css + +import org.jetbrains.compose.web.css.Color +import org.jetbrains.compose.web.css.StyleSheet +import org.jetbrains.compose.web.css.color +import org.jetbrains.compose.web.css.utils.serializeRules +import kotlin.test.Test +import kotlin.test.assertContentEquals + + +class StyleSheetTests { + + @Test + fun extendExistingStyleSheet() { + val styleSheet = object : StyleSheet(usePrefix = false) { + val someClassName by style { + color(Color.red) + } + } + + val childStyleSheet = object : StyleSheet(styleSheet, usePrefix = false) { + val someClassName by style { + color(Color.green) + } + } + + assertContentEquals( + listOf(".someClassName { color: red;}", ".someClassName { color: green;}"), + styleSheet.serializeRules(), + "styleSheet rules" + ) + + assertContentEquals( + listOf(".someClassName { color: red;}", ".someClassName { color: green;}"), + childStyleSheet.serializeRules(), + "childStyleSheet rules" + ) + } + +} \ No newline at end of file