From 06205b400d69f755bcd99ade3042281fce6016e7 Mon Sep 17 00:00:00 2001 From: Shagen Ogandzhanian Date: Mon, 12 Jul 2021 11:26:17 +0200 Subject: [PATCH] CSSVariableBuilder --- .../org/jetbrains/compose/web/css/CSSRules.kt | 18 +----------------- .../compose/web/css/StylePropertyBuilder.kt | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 17 deletions(-) diff --git a/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSRules.kt b/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSRules.kt index e742daf33b..c591ec511a 100644 --- a/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSRules.kt +++ b/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/CSSRules.kt @@ -2,23 +2,7 @@ package org.jetbrains.compose.web.css import org.jetbrains.compose.web.css.selectors.CSSSelector -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 CSSStyleVariable.invoke(value: TValue) { - variable(name, value.toString()) - } - - operator fun CSSStyleVariable.invoke(value: String) { - variable(name, value) - } - - operator fun CSSStyleVariable.invoke(value: Number) { - variable(name, value) - } -} + interface CSSStyleRuleBuilder : StylePropertyBuilder, StyleVariableBuilder open class CSSRuleBuilderImpl : CSSStyleRuleBuilder, StyleBuilderImpl() diff --git a/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StylePropertyBuilder.kt b/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StylePropertyBuilder.kt index d6e7f2137c..78d6776843 100644 --- a/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StylePropertyBuilder.kt +++ b/web/core/src/jsMain/kotlin/org/jetbrains/compose/web/css/StylePropertyBuilder.kt @@ -16,6 +16,25 @@ interface StylePropertyBuilder { fun property(propertyName: String, value: Number) = property(propertyName, StylePropertyValue(value)) } +interface StyleVariableBuilder { + 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 CSSStyleVariable.invoke(value: TValue) { + variable(name, value.toString()) + } + + operator fun CSSStyleVariable.invoke(value: String) { + variable(name, value) + } + + operator fun CSSStyleVariable.invoke(value: Number) { + variable(name, value) + } +} + + inline fun variableValue(variableName: String, fallback: StylePropertyValue? = null) = "var(--$variableName${fallback?.let { ", $it" } ?: ""})"