Integrating Your Own Component Theme
To create your own component theme to be used with the wrapped Vaadin components you need to create a theme class that informs flow how to translate the base un-themed component html import to use your themed version.
The getBaseUrl
should return the part of the htmlImport that can be used to determine if it is an import that could be changed to a theme import. (for Vaadin components that is /src/
)
The getThemeUrl
should return what the base url part should be changed to to get the correct theme import. (for Vaadin components that /theme/[themeName]
is used)
Java
@HtmlImport("frontend://bower_components/vaadin-lumo-styles/color.html")
public class MyTheme implements AbstractTheme {
@Override
public String getBaseUrl() {
return "/src/";
}
@Override
public String getThemeUrl() {
return "/theme/myTheme/";
}
}
For more control there is getBodyInlineContents()
that returns a collection of html that will be inlined to the BootstrapPage body. For instance, it can be used to add a custom style to have the correct typography:
Java
@Override
public List<String> getHeaderInlineContents() {
return Collections.singletonList("<custom-style>\n"
+ " <style include=\"lumo-color lumo-typography\"></style>\n"
+ "</custom-style>");
}
Your theme can also support variants. For instance, Lumo theme supports both light and dark variants. To add support for variants, you can override the getBodyAttributes
method:
Java
@Override
public Map<String, String> getBodyAttributes(String variant) {
if ("dark".equals(variant)) {
// the <body> element will have the "theme" attribute set to
// "dark" when the dark variant is used
return Collections.singletonMap("theme", "dark");
}
return Collections.emptyMap();
}
Then you need to create the themed .html files for the elements for an example see: Themed Vaadin Button
Note | The themed files should be stored to ${frontend.working.directory}/bower_components/{component}/theme/myTheme which would by default for vaadin-button be src/main/webapp/frontend/bower_components/vaadin-button/theme/myTheme/vaadin-button.html |
If you need to import some theme-specific files, use @HtmlImport
as shown in the example above: @HtmlImport("frontend://bower_components/vaadin-lumo-styles/color.html")
Each of those html imports will be added to the BootstrapPage head.
Note | In the case where an exception navigation chain doesn’t get the used Theme the exception navigation target can be annotated with @NoTheme so that a warning is not logged for missing theme. |
Creating Your Own Component Theme
The theming for the Vaadin components is built using Vaadin.ThemableMixin
. See vaadin-themable-mixin wiki to learn how theming of Vaadin components is done.