Search in sources :

Example 1 with Theme

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

the class WebComponentUI method assignThemeVariant.

private void assignThemeVariant() {
    WebComponentConfigurationRegistry registry = getConfigurationRegistry();
    Optional<Theme> theme = registry.getEmbeddedApplicationAnnotation(Theme.class);
    if (!theme.isPresent() || theme.get().themeClass().equals(AbstractTheme.class)) {
        return;
    }
    AbstractTheme themeInstance = Instantiator.get(this).getOrCreate(theme.get().themeClass());
    ThemeDefinition definition = new ThemeDefinition(theme.get());
    Map<String, String> attributes = themeInstance.getHtmlAttributes(definition.getVariant());
    registry.getConfigurations().forEach(config -> addAttributes(config.getTag(), attributes));
}
Also used : WebComponentConfigurationRegistry(com.vaadin.flow.server.webcomponent.WebComponentConfigurationRegistry) AbstractTheme(com.vaadin.flow.theme.AbstractTheme) Theme(com.vaadin.flow.theme.Theme) AbstractTheme(com.vaadin.flow.theme.AbstractTheme) ThemeDefinition(com.vaadin.flow.theme.ThemeDefinition)

Example 2 with Theme

use of com.vaadin.flow.theme.Theme 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

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