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

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

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

import com.vaadin.flow.component.HasTheme
import com.vaadin.flow.component.html.Span

/**
 * The Badge component, see [Vaadin Badge Documentation](https://vaadin.com/docs/latest/components/badge)
 * for more details.
 */
public class Badge(text: String? = null) : Span(), HasTheme {
    init {
        setId(javaClass.simpleName)
        themeNames.add("badge")
        setText(text)
    }

    /**
     * Adds theme [variants] to the component.
     */
    public fun addThemeVariants(vararg variants: BadgeVariant) {
        themeNames.addAll(variants.map { it.variantName })
    }

    /**
     * Removes theme [variants] from the component.
     */
    public fun removeThemeVariants(vararg variants: BadgeVariant) {
        themeNames.removeAll(variants.map { it.variantName })
    }
}

/**
 * See [Vaadin Badge Documentation](https://vaadin.com/docs/latest/components/badge)
 * for examples for all variants and their combinations.
 */
public enum class BadgeVariant(public val variantName: String) {
    PRIMARY("primary"),
    SUCCESS("success"),
    ERROR("error"),
    CONTRAST("contrast"),
    PILL("pill"),
    SMALL("small")
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy