Skip to content

Commit

Permalink
compose.html: Add visibility property (#2079)
Browse files Browse the repository at this point in the history
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)
  • Loading branch information
InsanusMokrassar authored Aug 13, 2024
1 parent f6bf9e6 commit 481bb53
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -260,4 +260,22 @@ object GridAutoFlow : StylePropertyString {
inline val Dense get() = "dense".unsafeCast<GridAutoFlow>()
inline val RowDense get() = "row dense".unsafeCast<GridAutoFlow>()
inline val ColumnDense get() = "column dense".unsafeCast<GridAutoFlow>()
}
}

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<VisibilityStyle>()
Original file line number Diff line number Diff line change
@@ -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)
}
11 changes: 11 additions & 0 deletions html/core/src/jsTest/kotlin/CSSEnums.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
43 changes: 43 additions & 0 deletions html/core/src/jsTest/kotlin/css/CSSVisibilityTests.kt
Original file line number Diff line number Diff line change
@@ -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
)
}
}

}

0 comments on commit 481bb53

Please sign in to comment.