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

com.vaadin.flow.component.button.GeneratedVaadinButton Maven / Gradle / Ivy

There is a newer version: 24.5.5
Show newest version
/**
 * Copyright 2000-2024 Vaadin Ltd.
 *
 * This program is available under Vaadin Commercial License and Service Terms.
 *
 * See  {@literal }  for the full
 * license.
 */
package com.vaadin.flow.component.button;

import java.util.stream.Collectors;
import java.util.stream.Stream;

import com.vaadin.flow.component.ClickNotifier;
import com.vaadin.flow.component.Component;
import com.vaadin.flow.component.Focusable;
import com.vaadin.flow.component.HasStyle;
import com.vaadin.flow.component.HasText;
import com.vaadin.flow.component.HasTheme;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.JsModule;
import com.vaadin.flow.component.dependency.NpmPackage;
import com.vaadin.flow.dom.Element;

/**
 * 

* Description copied from corresponding location in WebComponent: *

*

* {@code } is a Web Component providing an accessible and * customizable button. *

*

* <vaadin-button> </vaadin-button> *

*

* {@code document.querySelector('vaadin-button').addEventListener('click', () => alert('Hello World!'));} *

*

Styling

*

* The following shadow DOM parts are exposed for styling: *

* * * * * * * * * * * * * * * * * * * * *
Part nameDescription
{@code label}The label (text) inside the button
{@code prefix}A slot for e.g. an icon before the label
{@code suffix}A slot for e.g. an icon after the label
*

* The following attributes are exposed for styling: *

* * * * * * * * * * * * * * * * * * * * * * * * *
AttributeDescription
{@code active}Set when the button is pressed down, either with mouse, touch or the * keyboard.
{@code disabled}Set when the button is disabled.
{@code focus-ring}Set when the button is focused using the keyboard.
{@code focused}Set when the button is focused.
*

* See * ThemableMixin * – how to apply styles for shadow parts *

*/ @Tag("vaadin-button") @NpmPackage(value = "@vaadin/vaadin-button", version = "2.4.0") @JsModule("@vaadin/vaadin-button/src/vaadin-button.js") public abstract class GeneratedVaadinButton> extends Component implements HasStyle, ClickNotifier, HasText, Focusable, HasTheme { /** * Adds theme variants to the component. * * @param variants * theme variants to add */ public void addThemeVariants(ButtonVariant... variants) { getThemeNames() .addAll(Stream.of(variants).map(ButtonVariant::getVariantName) .collect(Collectors.toList())); } /** * Removes theme variants from the component. * * @param variants * theme variants to remove */ public void removeThemeVariants(ButtonVariant... variants) { getThemeNames().removeAll( Stream.of(variants).map(ButtonVariant::getVariantName) .collect(Collectors.toList())); } /** *

* Description copied from corresponding location in WebComponent: *

*

* Specify that this control should have input focus when the page loads. *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code autofocus} property from the webcomponent */ protected boolean isAutofocusBoolean() { return getElement().getProperty("autofocus", false); } /** *

* Description copied from corresponding location in WebComponent: *

*

* Specify that this control should have input focus when the page loads. *

* * @param autofocus * the boolean value to set */ protected void setAutofocus(boolean autofocus) { getElement().setProperty("autofocus", autofocus); } /** *

* Description copied from corresponding location in WebComponent: *

*

* If true, the user cannot interact with this element. *

* This property is not synchronized automatically from the client side, so * the returned value may not be the same as in client side. *

* * @return the {@code disabled} property from the webcomponent */ protected boolean isDisabledBoolean() { return getElement().getProperty("disabled", false); } /** *

* Description copied from corresponding location in WebComponent: *

*

* If true, the user cannot interact with this element. *

* * @param disabled * the boolean value to set */ protected void setDisabled(boolean disabled) { getElement().setProperty("disabled", disabled); } /** * Adds the given components as children of this component at the slot * 'prefix'. * * @param components * The components to add. * @see MDN * page about slots * @see Spec * website about slots */ protected void addToPrefix(Component... components) { for (Component component : components) { component.getElement().setAttribute("slot", "prefix"); getElement().appendChild(component.getElement()); } } /** * Adds the given components as children of this component at the slot * 'suffix'. * * @param components * The components to add. * @see MDN * page about slots * @see Spec * website about slots */ protected void addToSuffix(Component... components) { for (Component component : components) { component.getElement().setAttribute("slot", "suffix"); getElement().appendChild(component.getElement()); } } /** * Removes the given child components from this component. * * @param components * The components to remove. * @throws IllegalArgumentException * if any of the components is not a child of this component. */ protected void remove(Component... components) { for (Component component : components) { if (getElement().equals(component.getElement().getParent())) { component.getElement().removeAttribute("slot"); getElement().removeChild(component.getElement()); } else { throw new IllegalArgumentException("The given component (" + component + ") is not a child of this component"); } } } /** * Removes all contents from this component, this includes child components, * text content as well as child elements that have been added directly to * this component using the {@link Element} API. */ protected void removeAll() { getElement().getChildren() .forEach(child -> child.removeAttribute("slot")); getElement().removeAllChildren(); } /** * Sets the given string as the content of this component. * * @param text * the text content to set * @see HasText#setText(String) */ public GeneratedVaadinButton(String text) { setText(text); } /** * Default constructor. */ public GeneratedVaadinButton() { } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy