Search in sources :

Example 1 with AbstractTheme

use of com.vaadin.flow.theme.AbstractTheme in project flow by vaadin.

the class BootstrapUtils method getThemeSettings.

static Map<TargetElement, List<JsonObject>> getThemeSettings(BootstrapHandler.BootstrapContext context) {
    Optional<Theme> themeAnnotation = context.getPageConfigurationAnnotation(Theme.class);
    if (themeAnnotation.isPresent()) {
        Map<TargetElement, List<JsonObject>> themeContents = new EnumMap<>(TargetElement.class);
        Class<? extends AbstractTheme> themeClass = themeAnnotation.get().value();
        AbstractTheme theme = ReflectTools.createInstance(themeClass);
        if (!context.isProductionMode()) {
            List<JsonObject> head = Stream.of(themeClass.getAnnotationsByType(HtmlImport.class)).map(HtmlImport::value).map(url -> createImportLink(context.getUriResolver(), url)).map(BootstrapUtils::createInlineDependencyObject).collect(Collectors.toList());
            themeContents.put(TargetElement.HEAD, head);
        }
        List<JsonObject> body = theme.getBodyInlineContents().stream().map(BootstrapUtils::createInlineDependencyObject).collect(Collectors.toList());
        themeContents.put(TargetElement.BODY, body);
        return themeContents;
    }
    return Collections.emptyMap();
}
Also used : HtmlImport(com.vaadin.flow.component.dependency.HtmlImport) AbstractTheme(com.vaadin.flow.theme.AbstractTheme) Theme(com.vaadin.flow.theme.Theme) AbstractTheme(com.vaadin.flow.theme.AbstractTheme) JsonObject(elemental.json.JsonObject) List(java.util.List) EnumMap(java.util.EnumMap) TargetElement(com.vaadin.flow.component.page.TargetElement)

Aggregations

HtmlImport (com.vaadin.flow.component.dependency.HtmlImport)1 TargetElement (com.vaadin.flow.component.page.TargetElement)1 AbstractTheme (com.vaadin.flow.theme.AbstractTheme)1 Theme (com.vaadin.flow.theme.Theme)1 JsonObject (elemental.json.JsonObject)1 EnumMap (java.util.EnumMap)1 List (java.util.List)1