Component

abstract class Component<TConfig : Any>(configCreator: ConfigCreator<TConfig>? = null)

This class defines a very simple UI component abstraction. Every Component is supposed to be rendered inside other Components forming a tree where the head is Component.Root.

Components are being rendered through render extension function.

Example usage:

object MessageComponent : Component<MessageComponent.MyComponentConfig>(::MyComponentConfig) {

override fun SimplePanel.render(): Effect {
h1(config.message)
return Effect.Success
}

class MyComponentConfig {

var message: String = "Hello, World!"
}
}

object RootComponent : Component.Root() {

override fun SimplePanel.render(): Effect {
render(MessageComponent) {
message = "Bye, World!"
}

return Effect.Success
}
}

class MyApplication : Application() {

override fun start() {
root("root") {
render(RootComponent)
}
}
}

Parameters

TConfig

defines any configuration class to be used to configure this component. This must be Unit if you don't introduce any configuration for this component. Also note that config property must be implemented with not-null value in case you want to make this component configurable.

configCreator

creator of the provided TConfig.

See also

Inheritors

Constructors

Link copied to clipboard
constructor(configCreator: ConfigCreator<TConfig>? = null)

Types

Link copied to clipboard
abstract class Root : Component<Unit>

Root component. Supposed to be rendered right in the Root panel. Note that Component.Root can not be configured.

Functions

Link copied to clipboard
fun apply(block: TConfig.() -> Unit)

Applies TConfig configuration for this component.

Link copied to clipboard
abstract fun SimplePanel.render(): Effect

Renders this component on SimplePanel and returns an effect of rendering.