MenuComponent

open class MenuComponent(scope: Scope) : MenuContext, 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.

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

class MyMenuEntry : MenuChild {
override fun render(context: RenderContext) {
context.apply {
//...
}
}
}

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

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

Constructors

MenuComponent
Link copied to clipboard
js
fun MenuComponent(scope: Scope)

Functions

addChild
Link copied to clipboard
js
fun addChild(child: MenuChild): Boolean
custom
Link copied to clipboard
js
fun custom(build: RenderContext.() -> Unit)
Adds a custom fritz2-component to the menu.
fun custom(styling: Style<BoxParams>, build: RenderContext.() -> Unit)
Adds a custom fritz2-component to the menu.
divider
Link copied to clipboard
js
fun divider(styling: Style<BoxParams> = {})
Adds a MenuDivider to the menu.
entry
Link copied to clipboard
js
fun entry(build: MenuEntry.() -> Unit)
Configures and adds a MenuEntry to the menu.
fun entry(styling: Style<BoxParams>, build: MenuEntry.() -> Unit)
Configures and adds a MenuEntry to the menu.
header
Link copied to clipboard
js
fun header(text: String)
Configures and adds a MenuHeader to the menu.
fun header(styling: Style<BoxParams>, text: String)
Configures and adds a MenuHeader to the menu.
link
Link copied to clipboard
js
fun link(build: MenuLink.() -> Unit)
Configures and adds a MenuLink to the menu.
fun link(styling: Style<BoxParams>, build: MenuLink.() -> Unit)
Configures and adds a MenuLink 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.
submenu
Link copied to clipboard
js
fun submenu(styling: BoxParams.() -> Unit = {}, value: Store<Boolean>? = null, baseClass: StyleClass = StyleClass.None, id: String? = null, prefix: String = "submenu", build: SubMenuComponent.() -> Unit): Boolean
Creates a submenu.

Properties

styles
Link copied to clipboard
js
val styles: MenuStyles