File tree Expand file tree Collapse file tree
jsMain/kotlin/com/varabyte/kobweb/compose/css
jsTest/kotlin/com/varabyte/kobweb/compose/css
kobweb-compose/src/jsMain/kotlin/com/varabyte/kobweb/compose/ui/modifiers Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -120,3 +120,14 @@ sealed class ColorInterpolationMethod private constructor(private val value: Str
120120 space.withHue(hueInterpolationMethod)
121121 }
122122}
123+
124+ sealed interface Opacity : StylePropertyValue {
125+ companion object : CssGlobalValues <Opacity > {
126+ fun of (value : Number ): Opacity = value.unsafeCast<Opacity >()
127+ fun of (value : CSSPercentageNumericValue ): Opacity = value.unsafeCast<Opacity >()
128+ }
129+ }
130+
131+ fun StyleScope.opacity (value : Opacity ) {
132+ property(" opacity" , value)
133+ }
Original file line number Diff line number Diff line change @@ -1781,6 +1781,18 @@ class CssStylePropertyTests {
17811781 assertThat(styleToText { objectFit(ObjectFit .Unset ) }).isEqualTo(" object-fit: unset" )
17821782 }
17831783
1784+ @Test
1785+ fun verifyOpacity () {
1786+ assertThat(styleToText { opacity(Opacity .of(0.5 )) }).isEqualTo(" opacity: 0.5" )
1787+ assertThat(styleToText { opacity(Opacity .of(50 .percent)) }).isEqualTo(" opacity: 50%" )
1788+
1789+ assertThat(styleToText { opacity(Opacity .Inherit ) }).isEqualTo(" opacity: inherit" )
1790+ assertThat(styleToText { opacity(Opacity .Initial ) }).isEqualTo(" opacity: initial" )
1791+ assertThat(styleToText { opacity(Opacity .Revert ) }).isEqualTo(" opacity: revert" )
1792+ assertThat(styleToText { opacity(Opacity .RevertLayer ) }).isEqualTo(" opacity: revert-layer" )
1793+ assertThat(styleToText { opacity(Opacity .Unset ) }).isEqualTo(" opacity: unset" )
1794+ }
1795+
17841796 @Test
17851797 fun verifyOrphans () {
17861798 assertThat(styleToText { orphans(Orphans .of(2 )) }).isEqualTo(" orphans: 2" )
Original file line number Diff line number Diff line change @@ -25,10 +25,14 @@ fun Modifier.colorScheme(colorScheme: ColorScheme) = styleModifier {
2525 colorScheme(colorScheme)
2626}
2727
28+ fun Modifier.opacity (opacity : Opacity ) = styleModifier {
29+ opacity(opacity)
30+ }
31+
2832fun Modifier.opacity (value : Number ) = styleModifier {
2933 opacity(value)
3034}
3135
3236fun Modifier.opacity (value : CSSPercentageNumericValue ) = styleModifier {
33- opacity(value.unsafeCast< CSSSizeValue < CSSUnit .percent>>( ))
37+ opacity(Opacity .of(value ))
3438}
You can’t perform that action at this time.
0 commit comments