Browse Source

CSS API - disallow String parameters for colors

See #891 - Still not closing though since I want to revisit it after CSS Grid and propert keywrods typing
pull/883/merge
Shagen Ogandzhanian 3 years ago
parent
commit
a5cffc44ca
  1. 4
      web/benchmark-core/src/jsMain/kotlin/com/sample/content/CodeSamplesSwitcher.kt
  2. 4
      web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtCard.kt
  3. 6
      web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtSection.kt
  4. 24
      web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtText.kt
  5. 4
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/background.kt
  6. 4
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/box.kt
  7. 4
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/color.kt
  8. 4
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/text.kt
  9. 8
      web/core/src/jsTest/kotlin/CSSStylesheetTests.kt
  10. 10
      web/core/src/jsTest/kotlin/InlineStyleTests.kt
  11. 16
      web/core/src/jsTest/kotlin/StaticComposableTests.kt
  12. 4
      web/core/src/jsTest/kotlin/css/CSSBackgroundTests.kt
  13. 4
      web/core/src/jsTest/kotlin/css/CSSBoxTests.kt
  14. 2
      web/core/src/jsTest/kotlin/css/CSSTextTests.kt
  15. 2
      web/core/src/jsTest/kotlin/elements/AttributesTests.kt
  16. 20
      web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/Sample.kt
  17. 12
      web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/tests/EventsTests.kt
  18. 6
      web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/tests/TestCases1.kt

4
web/benchmark-core/src/jsMain/kotlin/com/sample/content/CodeSamplesSwitcher.kt

@ -37,7 +37,7 @@ object SwitcherStylesheet : StyleSheet(AppStylesheet) {
color(Color.transparent) color(Color.transparent)
borderRadius(20.px, 20.px, 20.px) borderRadius(20.px, 20.px, 20.px)
} }
color("#aaa") color(Color("#aaa"))
} }
border { border {
@ -59,7 +59,7 @@ object SwitcherStylesheet : StyleSheet(AppStylesheet) {
color(Color("#167dff")) color(Color("#167dff"))
borderRadius(20.px, 20.px, 20.px) borderRadius(20.px, 20.px, 20.px)
} }
color("#000") color(Color("#000"))
} }
} }
} }

4
web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtCard.kt

@ -13,8 +13,8 @@ object WtCards : StyleSheet(AppStylesheet) {
val wtCardThemeLight by style { val wtCardThemeLight by style {
border(color = rgba(39, 40, 44, .2)) border(color = rgba(39, 40, 44, .2))
color("#27282c") color(Color("#27282c"))
backgroundColor("white") backgroundColor(Color.white)
} }
val wtCardThemeDark by style { val wtCardThemeDark by style {

6
web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtSection.kt

@ -16,16 +16,16 @@ object WtSections : StyleSheet(AppStylesheet) {
propertyName = "padding-bottom", propertyName = "padding-bottom",
value = "calc(4*${AppCSSVariables.wtOffsetTopUnit.value(24.px)})" value = "calc(4*${AppCSSVariables.wtOffsetTopUnit.value(24.px)})"
) )
backgroundColor("#fff") backgroundColor(Color("#fff"))
} }
val wtSectionBgGrayLight by style { val wtSectionBgGrayLight by style {
backgroundColor("#f4f4f4") backgroundColor(Color("#f4f4f4"))
backgroundColor(AppCSSVariables.wtColorGreyLight.value()) backgroundColor(AppCSSVariables.wtColorGreyLight.value())
} }
val wtSectionBgGrayDark by style { val wtSectionBgGrayDark by style {
backgroundColor("#323236") backgroundColor(Color("#323236"))
backgroundColor(AppCSSVariables.wtColorGreyDark.value()) backgroundColor(AppCSSVariables.wtColorGreyDark.value())
} }
} }

24
web/benchmark-core/src/jsMain/kotlin/com/sample/style/WtText.kt

@ -6,7 +6,7 @@ import org.jetbrains.compose.web.css.selectors.*
object WtTexts : StyleSheet(AppStylesheet) { object WtTexts : StyleSheet(AppStylesheet) {
val wtHero by style { val wtHero by style {
color("#27282c") color(Color("#27282c"))
fontSize(60.px) fontSize(60.px)
property("font-size", AppCSSVariables.wtHeroFontSize.value(60.px)) property("font-size", AppCSSVariables.wtHeroFontSize.value(60.px))
property("letter-spacing", (-1.5).px) property("letter-spacing", (-1.5).px)
@ -28,7 +28,7 @@ object WtTexts : StyleSheet(AppStylesheet) {
} }
val wtSubtitle2 by style { val wtSubtitle2 by style {
color("#27282c") color(Color("#27282c"))
fontSize(28.px) fontSize(28.px)
property("font-size", AppCSSVariables.wtSubtitle2FontSize.value(28.px)) property("font-size", AppCSSVariables.wtSubtitle2FontSize.value(28.px))
property("letter-spacing", "normal") property("letter-spacing", "normal")
@ -107,7 +107,7 @@ object WtTexts : StyleSheet(AppStylesheet) {
val wtLink by style { val wtLink by style {
property("border-bottom", "1px solid transparent") property("border-bottom", "1px solid transparent")
property("text-decoration", "none") property("text-decoration", "none")
color("#167dff") color(Color("#167dff"))
hover(self) style { hover(self) style {
property("border-bottom-color", "#167dff") property("border-bottom-color", "#167dff")
@ -115,7 +115,7 @@ object WtTexts : StyleSheet(AppStylesheet) {
} }
val wtH2 by style { val wtH2 by style {
color("#27282c") color(Color("#27282c"))
fontSize(31.px) fontSize(31.px)
property("font-size", AppCSSVariables.wtH2FontSize.value(31.px)) property("font-size", AppCSSVariables.wtH2FontSize.value(31.px))
property("letter-spacing", (-.5).px) property("letter-spacing", (-.5).px)
@ -137,11 +137,11 @@ object WtTexts : StyleSheet(AppStylesheet) {
} }
val wtH2ThemeDark by style { val wtH2ThemeDark by style {
color("#fff") color(Color("#fff"))
} }
val wtH3 by style { val wtH3 by style {
color("#27282c") color(Color("#27282c"))
fontSize(21.px) fontSize(21.px)
property("font-size", AppCSSVariables.wtH3FontSize.value(20.px)) property("font-size", AppCSSVariables.wtH3FontSize.value(20.px))
property("letter-spacing", "normal") property("letter-spacing", "normal")
@ -156,12 +156,12 @@ object WtTexts : StyleSheet(AppStylesheet) {
} }
val wtH3ThemeDark by style { val wtH3ThemeDark by style {
color("#fff") color(Color("#fff"))
} }
val wtButton by style { val wtButton by style {
color("white") color(Color.white)
backgroundColor("#167dff") backgroundColor(Color("#167dff"))
fontSize(15.px) fontSize(15.px)
display(DisplayStyle.InlineBlock) display(DisplayStyle.InlineBlock)
property("text-decoration", "none") property("text-decoration", "none")
@ -191,8 +191,8 @@ object WtTexts : StyleSheet(AppStylesheet) {
} }
val wtButtonContrast by style { val wtButtonContrast by style {
color("white") color(Color.white)
backgroundColor("#27282c") backgroundColor(Color("#27282c"))
hover(self) style { hover(self) style {
backgroundColor(rgba(39, 40, 44, .7)) backgroundColor(rgba(39, 40, 44, .7))
@ -203,7 +203,7 @@ object WtTexts : StyleSheet(AppStylesheet) {
property("margin-right", 16.px) property("margin-right", 16.px)
marginLeft(16.px) marginLeft(16.px)
padding(12.px) padding(12.px)
backgroundColor("transparent") backgroundColor(Color.transparent)
display(DisplayStyle.LegacyInlineFlex) display(DisplayStyle.LegacyInlineFlex)
hover(self) style { hover(self) style {

4
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/background.kt

@ -14,10 +14,6 @@ fun StyleBuilder.backgroundClip(value: String) {
property("background-clip", value) property("background-clip", value)
} }
fun StyleBuilder.backgroundColor(value: String) {
property("background-color", value)
}
fun StyleBuilder.backgroundColor(value: CSSColorValue) { fun StyleBuilder.backgroundColor(value: CSSColorValue) {
property("background-color", value) property("background-color", value)
} }

4
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/box.kt

@ -38,10 +38,6 @@ fun StyleBuilder.outlineWidth(value: CSSNumeric) {
} }
// https://developer.mozilla.org/en-US/docs/Web/CSS/outline-color // https://developer.mozilla.org/en-US/docs/Web/CSS/outline-color
fun StyleBuilder.outlineColor(value: String) {
property("outline-color", value)
}
fun StyleBuilder.outlineColor(value: CSSColorValue) { fun StyleBuilder.outlineColor(value: CSSColorValue) {
property("outline-color", value) property("outline-color", value)
} }

4
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/color.kt

@ -5,10 +5,6 @@
package org.jetbrains.compose.web.css package org.jetbrains.compose.web.css
fun StyleBuilder.color(value: String) {
property("color", value)
}
fun StyleBuilder.color(value: CSSColorValue) { fun StyleBuilder.color(value: CSSColorValue) {
// color hasn't Typed OM yet // color hasn't Typed OM yet
property("color", value) property("color", value)

4
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/properties/text.kt

@ -58,10 +58,6 @@ fun StyleBuilder.textAlign(value: String) {
} }
// https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration-color // https://developer.mozilla.org/en-US/docs/Web/CSS/text-decoration-color
fun StyleBuilder.textDecorationColor(value: String) {
property("text-decoration-color", value)
}
fun StyleBuilder.textDecorationColor(value: CSSColorValue) { fun StyleBuilder.textDecorationColor(value: CSSColorValue) {
property("text-decoration-color", value) property("text-decoration-color", value)
} }

8
web/core/src/jsTest/kotlin/CSSStylesheetTests.kt

@ -51,18 +51,18 @@ object AppStylesheet : StyleSheet() {
} }
val withMedia by style { val withMedia by style {
color("lime") color(Color.lime)
backgroundColor("lime") backgroundColor(Color.lime)
media(mediaMinWidth(20000.px)) { media(mediaMinWidth(20000.px)) {
self style { self style {
color("red") color(Color.red)
} }
} }
media(mediaMinWidth(20.px)) { media(mediaMinWidth(20.px)) {
self style { self style {
backgroundColor("green") backgroundColor(Color.green)
} }
} }

10
web/core/src/jsTest/kotlin/InlineStyleTests.kt

@ -21,9 +21,9 @@ class InlineStyleTests {
{ {
style { style {
if (isRed) { if (isRed) {
color("red") color(Color.red)
} else { } else {
color("green") color(Color.green)
} }
} }
} }
@ -54,7 +54,7 @@ class InlineStyleTests {
{ {
style { style {
if (isRed) { if (isRed) {
color("red") color(Color.red)
} }
} }
} }
@ -85,7 +85,7 @@ class InlineStyleTests {
{ {
style { style {
if (isRed) { if (isRed) {
color("red") color(Color.red)
} }
} }
} }
@ -116,7 +116,7 @@ class InlineStyleTests {
{ {
style { style {
if (isRed) { if (isRed) {
color("red") color(Color.red)
} }
} }
} }

16
web/core/src/jsTest/kotlin/StaticComposableTests.kt

@ -1,16 +1,6 @@
package org.jetbrains.compose.web.core.tests package org.jetbrains.compose.web.core.tests
import org.jetbrains.compose.web.css.Position import org.jetbrains.compose.web.css.*
import org.jetbrains.compose.web.css.bottom
import org.jetbrains.compose.web.css.color
import org.jetbrains.compose.web.css.left
import org.jetbrains.compose.web.css.opacity
import org.jetbrains.compose.web.css.percent
import org.jetbrains.compose.web.css.position
import org.jetbrains.compose.web.css.px
import org.jetbrains.compose.web.css.right
import org.jetbrains.compose.web.css.top
import org.jetbrains.compose.web.css.value
import org.jetbrains.compose.web.dom.Div import org.jetbrains.compose.web.dom.Div
import org.jetbrains.compose.web.dom.Span import org.jetbrains.compose.web.dom.Span
import org.jetbrains.compose.web.dom.Text import org.jetbrains.compose.web.dom.Text
@ -77,9 +67,9 @@ class StaticComposableTests {
{ {
style { style {
opacity(0.3) opacity(0.3)
color("red") color(Color.red)
opacity(0.2) opacity(0.2)
color("green") color(Color.green)
} }
} }
) )

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

@ -19,10 +19,10 @@ class CSSBackgroundTests {
fun backgroundColor() = runTest { fun backgroundColor() = runTest {
composition { composition {
Div({style { Div({style {
backgroundColor("rgb(0, 128, 0)") backgroundColor(rgb(0, 128, 0))
}}) }})
Div({style { Div({style {
backgroundColor("rgba(0, 129, 0, 0.2)") backgroundColor(rgba(0, 129, 0, 0.2))
}}) }})
} }

4
web/core/src/jsTest/kotlin/css/CSSBoxTests.kt

@ -122,12 +122,12 @@ class CSSBoxTests {
composition { composition {
Div({ Div({
style { style {
outlineColor("red") outlineColor(Color.red)
} }
}) })
Div({ Div({
style { style {
outlineColor("#32a1ce") outlineColor(Color("#32a1ce"))
} }
}) })
} }

2
web/core/src/jsTest/kotlin/css/CSSTextTests.kt

@ -204,7 +204,7 @@ class CSSTextTests {
composition { composition {
Div({ Div({
style { style {
textDecorationColor("red") textDecorationColor(Color.red)
} }
}) })
Div({ Div({

2
web/core/src/jsTest/kotlin/elements/AttributesTests.kt

@ -48,7 +48,7 @@ class AttributesTests {
ref { onDispose { } } ref { onDispose { } }
style { style {
width(500.px) width(500.px)
backgroundColor("red") backgroundColor(Color.red)
} }
onClick { } onClick { }

20
web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/Sample.kt

@ -55,7 +55,7 @@ object AppStyleSheet : StyleSheet() {
} }
val myClass by style { val myClass by style {
color("green") color(Color.green)
animation(bounce) { animation(bounce) {
duration(2.s) duration(2.s)
timingFunction(AnimationTimingFunction.EaseIn) timingFunction(AnimationTimingFunction.EaseIn)
@ -64,13 +64,13 @@ object AppStyleSheet : StyleSheet() {
} }
val classWithNested by style { val classWithNested by style {
color("green") color(Color.green)
MyCSSVariables.myVar(Color("blue")) MyCSSVariables.myVar(Color("blue"))
MyCSSVariables.myVar2("red") MyCSSVariables.myVar2("red")
hover(self) style { hover(self) style {
color("red") color(Color.red)
} }
border { border {
@ -99,7 +99,7 @@ fun CounterApp(counter: MutableState<Int>) {
Button( Button(
{ {
style { style {
color(if (counter.value % 2 == 0) "green" else "red") color(if (counter.value % 2 == 0) Color.green else Color.red)
width((counter.value + 200).px) width((counter.value + 200).px)
fontSize(if (counter.value % 2 == 0) 25.px else 30.px) fontSize(if (counter.value % 2 == 0) 25.px else 30.px)
margin(15.px) margin(15.px)
@ -123,7 +123,7 @@ fun Counter(value: Int) {
onDrag { println("DRAGGING NOW!!!!") } onDrag { println("DRAGGING NOW!!!!") }
style { style {
color("red") color(Color.red)
} }
} }
) { ) {
@ -177,7 +177,7 @@ fun main() {
} }
".${AppStyleSheet.myClass}:hover" { ".${AppStyleSheet.myClass}:hover" {
color("red") color(Color.red)
} }
media(mediaMinWidth(500.px) and mediaMaxWidth(700.px)) { media(mediaMinWidth(500.px) and mediaMaxWidth(700.px)) {
@ -222,9 +222,9 @@ fun main() {
attrs = { attrs = {
classes( classes(
Auto.css { Auto.css {
color("pink") color(Color.pink)
hover(self) style { hover(self) style {
color("blue") color(Color.blue)
} }
} }
) )
@ -343,9 +343,9 @@ fun smallColoredText(text: String) {
style { style {
if (globalState.isDarkTheme) { if (globalState.isDarkTheme) {
color("black") color(Color.black)
} else { } else {
color("green") color(Color.green)
} }
} }
}, },

12
web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/tests/EventsTests.kt

@ -21,7 +21,7 @@ class EventsTests {
style { style {
width(100.px) width(100.px)
height(100.px) height(100.px)
backgroundColor("red") backgroundColor(Color.red)
} }
onDoubleClick { state = "Double Click Works!" } onDoubleClick { state = "Double Click Works!" }
} }
@ -130,7 +130,7 @@ class EventsTests {
Div(attrs = { Div(attrs = {
id("box") id("box")
style { style {
backgroundColor("red") backgroundColor(Color.red)
padding(50.px) padding(50.px)
width(300.px) width(300.px)
} }
@ -176,7 +176,7 @@ class EventsTests {
style { style {
width(200.px) width(200.px)
height(200.px) height(200.px)
backgroundColor("red") backgroundColor(Color.red)
} }
onMouseMove { onMouseMove {
state = "${it.x},${it.y}|${it.offsetX},${it.offsetY}" state = "${it.x},${it.y}|${it.offsetX},${it.offsetY}"
@ -301,7 +301,7 @@ class EventsTests {
style { style {
width(300.px) width(300.px)
height(300.px) height(300.px)
backgroundColor("red") backgroundColor(Color.red)
} }
}) { }) {
Text("Touch me and move the pointer") Text("Touch me and move the pointer")
@ -338,7 +338,7 @@ class EventsTests {
animationEnd = "ENDED" animationEnd = "ENDED"
} }
style { style {
backgroundColor("red") backgroundColor(Color.red)
} }
}) { }) {
Text("Click to Animate") Text("Click to Animate")
@ -399,7 +399,7 @@ object AppStyleSheetWithAnimation : StyleSheet() {
} }
val bounceClass by style { val bounceClass by style {
color("green") color(Color.green)
animation(bounce) { animation(bounce) {
duration(500.ms) duration(500.ms)
timingFunction(AnimationTimingFunction.EaseIn) timingFunction(AnimationTimingFunction.EaseIn)

6
web/integration-core/src/jsMain/kotlin/androidx/compose/web/sample/tests/TestCases1.kt

@ -50,7 +50,7 @@ class TestCases1 {
style { style {
width(100.px) width(100.px)
height(100.px) height(100.px)
backgroundColor("red") backgroundColor(Color.red)
} }
} }
) {} ) {}
@ -70,10 +70,10 @@ class TestCases1 {
private object AppStyleSheet : StyleSheet() { private object AppStyleSheet : StyleSheet() {
val textClass by style { val textClass by style {
color("rgba(0, 200, 0, 0.92)") color(rgba(0, 200, 0, 0.92))
media(mediaMaxWidth(600.px)) { media(mediaMaxWidth(600.px)) {
self style { self style {
color("rgba(255, 200, 0, 0.99)") color(rgba(255, 200, 0, 0.99))
} }
CSSSelector.Child(self, CSSSelector.Type("span")) style { CSSSelector.Child(self, CSSSelector.Type("span")) style {

Loading…
Cancel
Save