StyleVariable
A class for declaring a CSS style property (i.e. a variable value that can be used inside CSS styles).
You can declare one, set it, and use it in your styles like this:
val bgColor by StyleVariable<Color>()
val MainAreaStyle = CssStyle.base {
Modifier.setVariable(bgColor, Colors.Black)
}
val InvertedAreaStyle = CssStyle.base {
Modifier.setVariable(bgColor, Colors.White)
}
// Box style is expected to be applied underneath a root element using either MainAreaStyle or InvertedAreaStyle
val BoxStyle = CssStyle.base {
// Will be black if rendered in the main area or white in the inverted area.
Modifier.backgroundColor(bgColor.value())
}
Content copied to clipboard
Parameters
name
The (globally unique) name for this variable.
defaultFallback
When you query a variable, you can specify a fallback at that time. However, if not specified, then you can provide this default fallback to be used instead. See also: value.
T
The underlying type of the variable.
V
The type used for querying and setting the variable. This is especially useful for exposing direct Number
and String
values to the user, as these cannot be the underlying type.
Inheritors
Types
Link copied to clipboard
class NumberValue<T : Number>(name: String, defaultFallback: T? = null, prefix: String? = null) : StyleVariable<StylePropertyNumber, T>
Represents a StyleVariable of a number.
Link copied to clipboard
class PropertyValue<T : StylePropertyValue>(name: String, defaultFallback: T? = null, prefix: String? = null) : StyleVariable<T, T>
Represents a StyleVariable of a custom type.
Link copied to clipboard
class StringValue(name: String, defaultFallback: String? = null, prefix: String? = null) : StyleVariable<StylePropertyString, String>
Represents a StyleVariable of a string.