Browse Source

Move backgroundColor to a separate file and introduce dedicated test

pull/864/head
Shagen Ogandzhanian 3 years ago
parent
commit
6e2514fd88
  1. 8
      web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt
  2. 18
      web/core/src/jsMain/kotlin/androidx/compose/web/css/properties/background.kt
  3. 32
      web/core/src/jsTest/kotlin/css/CSSBackgroundTests.kt

8
web/core/src/jsMain/kotlin/androidx/compose/web/css/CSSProperties.kt

@ -33,14 +33,6 @@ fun StyleBuilder.color(value: CSSColorValue) {
property("color", value)
}
fun StyleBuilder.backgroundColor(value: CSSColorValue) {
property("background-color", value)
}
fun StyleBuilder.backgroundColor(value: String) {
property("background-color", value)
}
@Suppress("EqualsOrHashCode")
class CSSBorder : CSSStyleValue {
var width: CSSNumeric? = null

18
web/core/src/jsMain/kotlin/androidx/compose/web/css/properties/background.kt

@ -0,0 +1,18 @@
/*
* 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
fun StyleBuilder.backgroundColor(value: String) {
property("background-color", value)
}
fun StyleBuilder.backgroundColor(value: CSSColorValue) {
property("background-color", value)
}
fun StyleBuilder.backgroundColor(value: String) {
property("background-color", value)
}

32
web/core/src/jsTest/kotlin/css/CSSBackgroundTests.kt

@ -0,0 +1,32 @@
/*
* 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 kotlinx.browser.window
import org.jetbrains.compose.web.core.tests.runTest
import org.jetbrains.compose.web.css.backgroundColor
import org.jetbrains.compose.web.dom.Div
import org.w3c.dom.HTMLElement
import org.w3c.dom.get
import kotlin.test.Test
import kotlin.test.assertEquals
class CSSBackgroundTests {
@Test
fun backgroundColor() = runTest {
composition {
Div({style {
backgroundColor("rgb(0, 128, 0)")
}})
Div({style {
backgroundColor("rgba(0, 129, 0, 0.2)")
}})
}
assertEquals("rgb(0, 128, 0)", window.getComputedStyle(root.children[0] as HTMLElement).backgroundColor)
assertEquals("rgba(0, 129, 0, 0.2)", window.getComputedStyle(root.children[1] as HTMLElement).backgroundColor)
}
}
Loading…
Cancel
Save