All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ysny.karibu-tools.karibu-tools.0.20.source-code.LabelWrapper.kt Maven / Gradle / Ivy

There is a newer version: 0.21
Show newest version
package com.github.mvysny.kaributools

import com.vaadin.flow.component.Component
import com.vaadin.flow.component.HasComponents
import com.vaadin.flow.component.HasSize
import com.vaadin.flow.component.customfield.CustomField

/**
 * Used to show a label on top of a component which doesn't show a [Component.label] itself.
 *
 * **Used in highly specific situations only:** for example when you need to add a label
 * to a `HorizontalLayout`.
 *
 * Whenever possible, you should add your components into a `FormLayout`
 * instead, via the `FormLayout.addFormItem()` which
 * supports labels for all components. Alternatively, you can emulate labels by wrapping labels in a `H2`/`H3`/`H4`/`H5`/`H6`
 * then styling them accordingly.
 */
public class LabelWrapper(label: String) : CustomField(), HasComponents, HasSize {
    init {
        setLabel(label)
    }

    override fun setPresentationValue(newPresentationValue: Void?) {
        // ignore; this component only serves to add a label to the wrapped contents
    }

    override fun generateModelValue(): Void? {
        // ignore - this component only serves to add a label to the wrapped contents")
        return null
    }

    public override fun add(vararg components: Component) {
        super.add(*components)
    }

    public override fun remove(vararg components: Component) {
        super.remove(*components)
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy