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

org.bklab.flow.components.textfield.KeywordField Maven / Gradle / Ivy

There is a newer version: 22.0.1
Show newest version
package org.bklab.flow.components.textfield;

import com.vaadin.flow.component.ComponentEvent;
import com.vaadin.flow.component.Key;
import com.vaadin.flow.component.button.Button;
import com.vaadin.flow.component.icon.VaadinIcon;
import com.vaadin.flow.component.textfield.TextField;
import com.vaadin.flow.component.textfield.TextFieldVariant;
import org.bklab.flow.factory.ButtonFactory;
import org.bklab.flow.factory.TextFieldFactory;

import java.util.function.BiConsumer;


public class KeywordField extends TextField {

    private final Button keywordButton = new ButtonFactory()
            .icon(VaadinIcon.SEARCH).lumoSmall().lumoTertiaryInline().get();

    {
        setPlaceholder("关键字(按回车搜索)");
        setSuffixComponent(keywordButton);
        addThemeVariants(TextFieldVariant.LUMO_SMALL);
    }

    public KeywordField(BiConsumer> eventConsumer) {
        addKeyPressListener(Key.ENTER, t -> eventConsumer.accept(this, t));
        keywordButton.addClickListener(t -> eventConsumer.accept(this, t));
    }

    public TextFieldFactory asFactory() {
        return new TextFieldFactory(this);
    }

    public ButtonFactory asButtonFactory() {
        return new ButtonFactory(keywordButton);
    }

    public Button getKeywordButton() {
        return keywordButton;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy