Browse Source

CSSStyleRuleBuilder is de-facto variable builder

STYLEBUILDER_SIMPLIFICATION
Shagen Ogandzhanian 3 years ago
parent
commit
50a0afe471
  1. 18
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSRules.kt
  2. 17
      web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StylePropertyBuilder.kt

18
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSRules.kt

@ -2,7 +2,23 @@ package org.jetbrains.compose.web.css
import org.jetbrains.compose.web.css.selectors.CSSSelector
interface CSSStyleRuleBuilder : StylePropertyBuilder
interface CSSStyleRuleBuilder : StylePropertyBuilder {
fun variable(variableName: String, value: StylePropertyValue)
fun variable(variableName: String, value: String) = variable(variableName, StylePropertyValue(value))
fun variable(variableName: String, value: Number) = variable(variableName, StylePropertyValue(value))
operator fun <TValue: StylePropertyValue> CSSStyleVariable<TValue>.invoke(value: TValue) {
variable(name, value.toString())
}
operator fun CSSStyleVariable<StylePropertyString>.invoke(value: String) {
variable(name, value)
}
operator fun CSSStyleVariable<StylePropertyNumber>.invoke(value: Number) {
variable(name, value)
}
}
open class CSSRuleBuilderImpl : CSSStyleRuleBuilder, StyleBuilderImpl()

17
web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StylePropertyBuilder.kt

@ -11,24 +11,9 @@ import kotlin.properties.ReadOnlyProperty
interface StylePropertyBuilder {
fun property(propertyName: String, value: StylePropertyValue)
fun variable(variableName: String, value: StylePropertyValue)
fun property(propertyName: String, value: String) = property(propertyName, StylePropertyValue(value))
fun property(propertyName: String, value: Number) = property(propertyName, StylePropertyValue(value))
fun variable(variableName: String, value: String) = variable(variableName, StylePropertyValue(value))
fun variable(variableName: String, value: Number) = variable(variableName, StylePropertyValue(value))
operator fun <TValue: StylePropertyValue> CSSStyleVariable<TValue>.invoke(value: TValue) {
variable(name, value.toString())
}
operator fun CSSStyleVariable<StylePropertyString>.invoke(value: String) {
variable(name, value)
}
operator fun CSSStyleVariable<StylePropertyNumber>.invoke(value: Number) {
variable(name, value)
}
}
inline fun variableValue(variableName: String, fallback: StylePropertyValue? = null) =
@ -87,7 +72,7 @@ interface StyleHolder {
}
@Suppress("EqualsOrHashCode")
open class StyleBuilderImpl : StylePropertyBuilder, StyleHolder {
open class StyleBuilderImpl : StylePropertyBuilder, CSSStyleRuleBuilder, StyleHolder {
override val properties: MutableStylePropertyList = mutableListOf()
override val variables: MutableStylePropertyList = mutableListOf()

Loading…
Cancel
Save