From 481bb539d0ca88132f60eb5898705b9ba2ef6c59 Mon Sep 17 00:00:00 2001 From: InsanusMokrassar Date: Tue, 13 Aug 2024 20:19:06 +0600 Subject: [PATCH] compose.html: Add visibility property (#2079) By this PR I am adding opportunity to use visibility property according to the [visibility references](https://developer.mozilla.org/en-US/docs/Web/CSS/visibility) --- .../org/jetbrains/compose/web/css/CSSEnums.kt | 20 ++++++++- .../compose/web/css/properties/visibility.kt | 12 ++++++ html/core/src/jsTest/kotlin/CSSEnums.kt | 11 +++++ .../jsTest/kotlin/css/CSSVisibilityTests.kt | 43 +++++++++++++++++++ 4 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 html/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/visibility.kt create mode 100644 html/core/src/jsTest/kotlin/css/CSSVisibilityTests.kt diff --git a/html/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSEnums.kt b/html/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSEnums.kt index 4cbdd24652..7fdcf35684 100644 --- a/html/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSEnums.kt +++ b/html/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSEnums.kt @@ -260,4 +260,22 @@ object GridAutoFlow : StylePropertyString { inline val Dense get() = "dense".unsafeCast() inline val RowDense get() = "row dense".unsafeCast() inline val ColumnDense get() = "column dense".unsafeCast() -} \ No newline at end of file +} + +interface VisibilityStyle: StylePropertyEnum { + companion object { + inline val Visible get() = VisibilityStyle("visible") + inline val Hidden get() = VisibilityStyle("hidden") + inline val Collapse get() = VisibilityStyle("collapse") + + + inline val Inherit get() = VisibilityStyle("inherit") + inline val Initial get() = VisibilityStyle("initial") + + inline val Revert get() = VisibilityStyle("revert") + inline val RevertLayer get() = VisibilityStyle("revert-layer") + + inline val Unset get() = VisibilityStyle("unset") + } +} +inline fun VisibilityStyle(value: String) = value.unsafeCast() diff --git a/html/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/visibility.kt b/html/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/visibility.kt new file mode 100644 index 0000000000..de0fc6fc00 --- /dev/null +++ b/html/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/visibility.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2020-2024 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. + */ + +@file:Suppress("Unused", "NOTHING_TO_INLINE", "NESTED_CLASS_IN_EXTERNAL_INTERFACE", "INLINE_EXTERNAL_DECLARATION", "WRONG_BODY_OF_EXTERNAL_DECLARATION", "NESTED_EXTERNAL_DECLARATION") + +package org.jetbrains.compose.web.css + +fun StyleScope.visibility(visibilityStyle: VisibilityStyle) { + property("visibility", visibilityStyle.value) +} diff --git a/html/core/src/jsTest/kotlin/CSSEnums.kt b/html/core/src/jsTest/kotlin/CSSEnums.kt index 4f430db8f9..87923a6ac6 100644 --- a/html/core/src/jsTest/kotlin/CSSEnums.kt +++ b/html/core/src/jsTest/kotlin/CSSEnums.kt @@ -114,3 +114,14 @@ fun Position.Companion.values() = listOf( Position.Sticky, Position.Fixed ) + +fun VisibilityStyle.Companion.values() = listOf( + VisibilityStyle.Visible, + VisibilityStyle.Hidden, + VisibilityStyle.Collapse, + VisibilityStyle.Inherit, + VisibilityStyle.Initial, + VisibilityStyle.Revert, + VisibilityStyle.RevertLayer, + VisibilityStyle.Unset +) diff --git a/html/core/src/jsTest/kotlin/css/CSSVisibilityTests.kt b/html/core/src/jsTest/kotlin/css/CSSVisibilityTests.kt new file mode 100644 index 0000000000..359deb302e --- /dev/null +++ b/html/core/src/jsTest/kotlin/css/CSSVisibilityTests.kt @@ -0,0 +1,43 @@ +/* + * 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.testutils.* +import org.jetbrains.compose.web.core.tests.values +import org.jetbrains.compose.web.css.VisibilityStyle +import org.jetbrains.compose.web.css.visibility +import org.jetbrains.compose.web.css.value +import org.jetbrains.compose.web.dom.Div +import kotlin.test.Test +import kotlin.test.assertEquals + +class CSSVisibilityTests { + + @Test + fun stylesDisplay() = runTest { + val enumValues = VisibilityStyle.values() + + composition { + enumValues.forEach { displayStyle -> + Div( + { + style { + visibility(displayStyle) + } + } + ) + } + } + + enumValues.forEach { visibilityStyle -> + assertEquals( + visibilityStyle.value, + (nextChild()).style.visibility + ) + } + } + +}