Type-safe CSS properties
Every Kilua component has a full range of properties based on CSS specification. Most of them are 100% type-safe - based on enumeration values, dedicated classes and functions. You can of course use custom CSS stylesheets and assign predefined classes to your components, but Kilua gives you a choice. With CSS properties you can style any component's size, position, margins, paddings, borders, colors, backgrounds, text and fonts with pure Kotlin code.
Custom properties
Not all CSS properties are supported with dedicated functions. Some, less frequently used, newly added to the specification or those whose values ​​cannot be easily described in a type-safe manner, can be accessed using the style()
function with raw String
parameters:
CSS units
Kilua supports all CSS units as an extension properties on Number
type. So you can specify dimensions, sizes, position and thickness with such example notations: 50.px
, 12.pt
, 2.em
, 90.perc
, 100.vh
, 1.49.em
etc. In addition auto
, normal
, initial
and inherit
values are also supported.
Colors
Kilua offers a few convenient ways to specify colors. You can use methods defined in the Color
class to create values with hexadecimal Int
literals or direct RGB(A) values. You can also use predefined constants for all CSS color names.
CSS helper classes
To specify borders, backgrounds, text decorations, text shadows, box shadows, transitions and list styles you can use the dedicated classes.
There are also some extension functions declared, that can be imported to write the same code easier:
Global style functions
When the CSS properties are set directly inside the component, the corresponding style attributes are inlined in the generated HTML code. Sometimes it's better to define a CSS class, which can be reused by other parts of the UI. In Kilua you can do this by using the globalStyle()
function. It creates a CSS class which can be used by other components.
By default the class name is automatically generated, but you can use your own with optional parameters.
Styles can also be nested with a style()
calls to create CSS subclasses.
You can also easily use CSS pseudo-classes or media queries.
Local style functions
Sometimes you want to create a style dedicated for a single component, but can't use inline styles because you need to use features only available in the CSS stylesheet (like pseudo classes, pseudo elements or media queries). You can generate a CSS rule and apply that rule to your component by using style()
function.
Last updated