Restricted

abstract class Restricted(init: CssStyleScope.() -> Unit, extraModifier: @Composable () -> Modifier = { Modifier }) : CssStyle<RestrictedKind> (source)

A CssStyle for creating custom style types restricted to fixed parameters.

Whereas CSS styles are by default open-ended and let you define any combination of modifiers that you want, it can sometimes be useful to present a user with a constructor of fixed parameters, having the style then created for it behind the scenes.

For example:

class MyButtonBehavior(fontSize: CSSLengthNumericValue, hoverColor: CSSColorValue) : CssStyle.Restricted(init = {
base { Modifier.fontSize(fontSize) }
hover { Modifier.backgroundColor(hoverColor) }
}) {
companion object {
val Quiet = MyButtonBehavior(1.cssRem, Colors.Gray)
val Loud = MyButtonBehavior(2.cssRem, Colors.Red)
}
}

A user can declare an instance of this class in their own code:

val UserButtonBehavior = MyButtonBehavior(1.5.cssRem, Colors.Blue)

which will automatically create a CSS class corresponding to the property.

Inheritors

Constructors

Link copied to clipboard
constructor(init: CssStyleScope.() -> Unit, extraModifier: @Composable () -> Modifier = { Modifier })

Types

Link copied to clipboard
abstract class Base(init: CssStyleBaseScope.() -> Modifier, extraModifier: @Composable () -> Modifier = { Modifier }) : CssStyle.Restricted

Like Restricted but when you know you only want to specify the base style.

Properties

Link copied to clipboard

Return the class name associated with the given CssStyle.

Functions

Link copied to clipboard
fun <K : ComponentKind> CssStyle<K>.addVariant(extraModifier: Modifier = Modifier, init: CssStyleScope.() -> Unit): CssStyleVariant<K>
fun <K : ComponentKind> CssStyle<K>.addVariant(extraModifier: @Composable () -> Modifier, init: CssStyleScope.() -> Unit): CssStyleVariant<K>
Link copied to clipboard
fun <K : ComponentKind> CssStyle<K>.addVariantBase(extraModifier: Modifier = Modifier, init: CssStyleBaseScope.() -> Modifier): CssStyleVariant<K>
fun <K : ComponentKind> CssStyle<K>.addVariantBase(extraModifier: @Composable () -> Modifier, init: CssStyleBaseScope.() -> Modifier): CssStyleVariant<K>

Convenience method when you only care about registering the base style, which can help avoid a few extra lines.

Link copied to clipboard
fun CssStyle<GeneralKind>.extendedBy(extraModifier: Modifier = Modifier, init: CssStyleScope.() -> Unit): CssStyle<GeneralKind>
fun CssStyle<GeneralKind>.extendedBy(extraModifier: @Composable () -> Modifier, init: CssStyleScope.() -> Unit): CssStyle<GeneralKind>
Link copied to clipboard
fun CssStyle<GeneralKind>.extendedByBase(extraModifier: @Composable () -> Modifier, init: CssStyleBaseScope.() -> Modifier): CssStyle<GeneralKind>
Link copied to clipboard
@Composable
fun <A : AttrsScope<*>> CssStyle<GeneralKind>.toAttrs(finalHandler: A.() -> Unit? = null): A.() -> Unit
Link copied to clipboard
@Composable
fun <K : ComponentKind> CssStyle<K>.toModifier(vararg variants: CssStyleVariant<K>?): Modifier