MenuComponent

open class MenuComponent : Component<Unit>

This class combines the configuration and the core rendering of a menu.

A Menu consists of different types of children that are aligned vertically. By default the following types can be added to the menu:

It is also possible to add any other fritz2 component via the custom context. All menu items are created directly within the MenuComponent's build context.

Example usage:

menu {
entry {
icon { add }
text("Item")
}
divider()
header("A subsection starts here")
custom {
// custom content
spinner { }
}
}

The menu-entry-DSL can be extended via standard Kotlin extension methods. Custom entries must implement the Component<Unit> interface and are added to the Menu via the MenuComponent.addChild method which is accessible from within the extension method.

The following example adds an instance of MyMenuEntry to the Menu. Notice that addChild is invoked in the end; the entry wouldn't be added otherwise!

fun MenuComponent.example(build: MyMenuEntry.() -> Unit) = MyMenuEntry()
.apply(build)
.run(::addChild)

Constructors

MenuComponent
Link copied to clipboard
js
fun MenuComponent()

Functions

addChild
Link copied to clipboard
js
fun addChild(child: MenuChild): Boolean
custom
Link copied to clipboard
js
fun custom(build: RenderContext.() -> Unit): Boolean
Adds a custom fritz2-component to the menu.
fun custom(styling: Style<BoxParams>, build: RenderContext.() -> Unit): Boolean
Adds a custom fritz2-component to the menu.
divider
Link copied to clipboard
js
fun divider(styling: Style<BoxParams> = {}): Boolean
Adds a MenuDivider to the menu.
entry
Link copied to clipboard
js
fun entry(build: MenuEntry.() -> Unit): Boolean
Configures and adds a MenuEntry to the menu.
fun entry(styling: Style<BoxParams>, build: MenuEntry.() -> Unit): Boolean
Configures and adds a MenuEntry to the menu.
header
Link copied to clipboard
js
fun header(text: String): Boolean
Configures and adds a MenuHeader to the menu.
fun header(styling: Style<BoxParams>, text: String): Boolean
Configures and adds a MenuHeader to the menu.
render
Link copied to clipboard
js
open override fun render(context: RenderContext, styling: BoxParams.() -> Unit, baseClass: StyleClass, id: String?, prefix: String)
Central method that should do the actual rendering of a component.