Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix empty css layer name being registered as anonymous layer #580

Merged
merged 1 commit into from
Jul 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,10 @@ class MutableSilkTheme {
RestrictedKind::class -> SilkLayer.RESTRICTED_STYLES
GeneralKind::class -> SilkLayer.GENERAL_STYLES
else -> error("Unknown kind: $kind")
}.layerName.takeIf { it.isNotEmpty() } // In case user passes in ""
finalLayer?.let { _cssLayersFor[name] = it }
}.layerName
finalLayer
.takeIf { it.isNotEmpty() } // If the user passes in "", no layer should be registered
?.let { _cssLayersFor[name] = it }

if (style is ExtendingCssStyle) {
_cssStyleDependencies.getOrPut(style) { mutableListOf() }.add(style.baseStyle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,21 @@ class CssStyleTest {
.inOrder()
}


@Test
fun cssStyleEmptyLayerNameResultsInNoLayer() {
val stylesheet = StyleSheet()
// Styles must be non-empty to be registered
val BaseStyle = CssStyle.base<ComponentKind> { Modifier.color(Colors.Red) }
_SilkTheme = MutableSilkTheme().apply {
registerStyle("base-style", BaseStyle, layer = "")
}.let(::ImmutableSilkTheme)
SilkTheme.registerStylesInto(stylesheet)
val styleRule = stylesheet.cssRules.first()
assertThat(styleRule).isInstanceOf<CSSStyleRuleDeclaration>()
assertThat(styleRule.header).isEqualTo(".base-style")
}

@Test
fun cssStyleExtendedClasses() {
val BaseStyle = CssStyle { }
Expand Down