Search in sources :

Example 1 with Style

use of com.vaadin.flow.dom.Style in project flow by vaadin.

the class BasicComponentView method onShow.

@Override
protected void onShow() {
    getElement().getStyle().set("margin", "1em");
    getElement().setAttribute("id", "root");
    Text text = new Text(TEXT);
    Input input = new Input();
    input.setPlaceholder("Synchronized on change event");
    NativeButton button = new NativeButton(BUTTON_TEXT, e -> {
        Div greeting = new Div();
        greeting.addClassName("thankYou");
        String buttonText = e.getSource().getElement().getText();
        greeting.setText("Thank you for clicking \"" + buttonText + "\" at (" + e.getClientX() + "," + e.getClientY() + ")! The field value is " + input.getValue());
        greeting.addClickListener(e2 -> remove(greeting));
        add(greeting);
    });
    Div helloWorld = new Div();
    helloWorld.setText(DIV_TEXT);
    helloWorld.addClassName("hello");
    helloWorld.setId("hello-world");
    helloWorld.addClickListener(e -> {
        helloWorld.setText("Stop touching me!");
        helloWorld.getElement().getClassList().clear();
    });
    Style s = helloWorld.getElement().getStyle();
    s.set("color", "red");
    s.set("fontWeight", "bold");
    add(text, helloWorld, button, input);
}
Also used : Div(com.vaadin.flow.component.html.Div) NativeButton(com.vaadin.flow.component.html.NativeButton) Input(com.vaadin.flow.component.html.Input) Style(com.vaadin.flow.dom.Style) Text(com.vaadin.flow.component.Text)

Example 2 with Style

use of com.vaadin.flow.dom.Style in project flow by vaadin.

the class StyleAttributeHandler method setAttribute.

@Override
public void setAttribute(Element element, String attributeValue) {
    Style style = element.getStyle();
    style.clear();
    parseStyles(attributeValue).forEach(style::set);
}
Also used : Style(com.vaadin.flow.dom.Style)

Example 3 with Style

use of com.vaadin.flow.dom.Style in project flow by vaadin.

the class ElementTest method getMultipleStylesAsAttribute.

@Test
public void getMultipleStylesAsAttribute() {
    Element e = ElementFactory.createDiv();
    Style s = e.getStyle();
    s.set("border", "1px solid black");
    s.set("margin", "1em");
    Assert.assertTrue(e.hasAttribute("style"));
    assertEqualsOne(new String[] { "border:1px solid black;margin:1em", "margin:1em;border:1px solid black" }, e.getAttribute("style"));
}
Also used : Element(com.vaadin.flow.dom.Element) Style(com.vaadin.flow.dom.Style) Test(org.junit.Test)

Example 4 with Style

use of com.vaadin.flow.dom.Style in project flow by vaadin.

the class ElementTest method customPropertyStyle.

@Test
public void customPropertyStyle() {
    Element element = ElementFactory.createDiv();
    Style style = element.getStyle();
    style.set("--some-variable", "foo");
    Assert.assertEquals("foo", style.get("--some-variable"));
}
Also used : Element(com.vaadin.flow.dom.Element) Style(com.vaadin.flow.dom.Style) Test(org.junit.Test)

Example 5 with Style

use of com.vaadin.flow.dom.Style in project flow by vaadin.

the class ElementTest method removeSingleStyle.

@Test
public void removeSingleStyle() {
    Element e = ElementFactory.createDiv();
    Style s = e.getStyle();
    s.set("foo", "bar");
    s.remove("foo");
    Assert.assertEquals(null, s.get("foo"));
}
Also used : Element(com.vaadin.flow.dom.Element) Style(com.vaadin.flow.dom.Style) Test(org.junit.Test)

Aggregations

Style (com.vaadin.flow.dom.Style)22 Element (com.vaadin.flow.dom.Element)20 Test (org.junit.Test)17 Text (com.vaadin.flow.component.Text)1 Div (com.vaadin.flow.component.html.Div)1 Input (com.vaadin.flow.component.html.Input)1 NativeButton (com.vaadin.flow.component.html.NativeButton)1 ElementFactory (com.vaadin.flow.dom.ElementFactory)1 StateNode (com.vaadin.flow.internal.StateNode)1 ElementStylePropertyMap (com.vaadin.flow.internal.nodefeature.ElementStylePropertyMap)1 Route (com.vaadin.flow.router.Route)1 Registration (com.vaadin.flow.shared.Registration)1 ViewTestLayout (com.vaadin.flow.uitest.servlet.ViewTestLayout)1 JsonObject (elemental.json.JsonObject)1 Set (java.util.Set)1