Hello,
i would like to add the content of a .css file to the shadow dom of a custom component derived from Composite<Div>
.
for Example my code is as follow:
package AAA.BB.CCCCC.client.components;
import com.vaadin.flow.component.Composite;
import com.vaadin.flow.component.HasSize;
import com.vaadin.flow.component.Tag;
import com.vaadin.flow.component.dependency.CssImport;
import com.vaadin.flow.component.dependency.StyleSheet;
import com.vaadin.flow.component.html.H3;
import com.vaadin.flow.component.html.Div;
import com.vaadin.flow.component.html.H1;
@Tag("microitem-component")
//@CssImport(value = "./css/microItem.css", themeFor="Div")
@StyleSheet("microItem.css")
public class MicroItemComponent extends Composite<Div> implements HasSize {
private H1 property;
private H3 title;
public MicroItemComponent() {
property = new H1();
title = new H3();
property.setClassName("property");
title.setClassName("title");
getContent().add(title, property);
}
public void setContent(String title1, String prop1)
{
this.title.setText(title1);
this.property.setText(prop1);
}
public void setTitle(String title)
{
this.title.setText(title);
}
public void setProperty(String prop)
{
this.property.setText(prop);
}
public void setPropertyColor(String color)
{
this.property.getElement().getStyle().set("color", color);
}
public void setPropertyColorDefault()
{
this.property.getElement().getStyle().remove("color");
}
}
as you can see, i have tried @CssImport
and @StyleSheet
, but both metodes do not add the styles to the shadow dom of this component. Is there a way to do this by using a file, or do i have to do this all in java, by setting the styles with getStyle().set()
?
Thank you!