CssPrefix

annotation class CssPrefix(val prefix: String)(source)

An annotation that can be applied to a CssStyle or CssStyleVariant property to add a prefix to the generated CSS class name.

As an example, imagine we are developing a library called "kobweb-material-design". We might then choose a prefix (say, "kmd") which, when applied to our style, would significantly reduce the chance of a name collision with a user's style declared in their own project.

The following code will generate a CSS class named "kmd-button":

@CssPrefix("kmd")
val ButtonStyle = CssStyle { ... }

This also makes it easy for users debugging their site to see at a glance which styles are coming from the library.

NOTE: Library authors should prefer setting a global prefix in their build script instead of using this annotation:

kobweb { library { cssPrefix.set("kmd") } }

Using this annotation will override the global prefix on the targeted style. Additionally, prefix can be set to an empty string to remove the prefix entirely.

Properties

Link copied to clipboard