-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Theme can be defined as string or class (#9349)
Add a string definition for theme that matches the "application theme" in the theme folder inside /frontend/theme/, loading the css automatically from there. This is based on Lumo theme, always. Change old class based theme to use themeClass for theme selection. Fixes #9281 # Conflicts: # flow-component-demo-helpers/src/main/java/com/vaadin/flow/demo/DemoView.java # flow-server/src/main/java/com/vaadin/flow/component/webcomponent/WebComponentUI.java # flow-server/src/main/java/com/vaadin/flow/server/frontend/NodeTasks.java # flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateImports.java # flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateWebpack.java # flow-server/src/main/java/com/vaadin/flow/theme/Theme.java # flow-server/src/main/resources/webpack.generated.js # flow-server/src/test/java/com/vaadin/flow/server/frontend/scanner/FrontendDependenciesTest.java # flow-server/src/test/java/com/vaadin/flow/server/startup/VaadinAppShellInitializerTest.java # flow-test-generic/src/main/java/com/vaadin/flow/testutil/ClassesSerializableTest.java # flow-tests/test-lumo-theme/pom.xml # flow-tests/test-lumo-theme/src/main/java/com/vaadin/flow/uitest/ui/lumo/ExplicitLumoTemplateView.java # flow-tests/test-material-theme/pom.xml # flow-tests/test-material-theme/src/main/java/com/vaadin/flow/uitest/ui/material/MaterialThemedTemplateView.java # flow-tests/test-misc/src/main/java/com/vaadin/flow/misc/ui/MiscelaneousView.java # flow-tests/test-themes/pom.xml # flow-tests/test-themes/src/test/java/com/vaadin/flow/uitest/ui/theme/NpmThemedComponentIT.java
- Loading branch information
Showing
74 changed files
with
1,068 additions
and
272 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
flow-server/src/main/java/com/vaadin/flow/server/frontend/TaskUpdateThemeImport.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
/* | ||
* Copyright 2000-2020 Vaadin Ltd. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not | ||
* use this file except in compliance with the License. You may obtain a copy of | ||
* the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT | ||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the | ||
* License for the specific language governing permissions and limitations under | ||
* the License. | ||
*/ | ||
package com.vaadin.flow.server.frontend; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
import java.util.Collections; | ||
|
||
import org.apache.commons.io.FileUtils; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import com.vaadin.flow.server.ExecutionFailedException; | ||
import com.vaadin.flow.theme.ThemeDefinition; | ||
|
||
/** | ||
* Task for generating the theme-generated.js file for importing application | ||
* theme. | ||
* | ||
* @since | ||
*/ | ||
public class TaskUpdateThemeImport implements FallibleCommand { | ||
|
||
private File themeImportFile; | ||
private ThemeDefinition theme; | ||
|
||
TaskUpdateThemeImport(File npmFolder, ThemeDefinition theme) { | ||
File generatedDir = new File(npmFolder, FrontendUtils.DEFAULT_GENERATED_DIR); | ||
this.themeImportFile = new File(new File(generatedDir, "theme"), | ||
"theme-generated.js"); | ||
this.theme = theme; | ||
} | ||
|
||
@Override | ||
public void execute() throws ExecutionFailedException { | ||
if (theme == null || theme.getName().isEmpty()) { | ||
return; | ||
} | ||
if (!themeImportFile.getParentFile().mkdirs()) { | ||
LoggerFactory.getLogger(getClass()).debug( | ||
"Didn't create folders as they probably already exist. " | ||
+ "If there is a problem check access rights for folder {}", | ||
themeImportFile.getParentFile().getAbsolutePath()); | ||
} | ||
|
||
try { | ||
FileUtils.write(themeImportFile, | ||
"import {applyTheme as _applyTheme} from 'theme/" + theme | ||
.getName() + "/" + theme.getName() | ||
+ ".js';\nexport const applyTheme = _applyTheme;\n", | ||
StandardCharsets.UTF_8); | ||
} catch (IOException e) { | ||
System.out.println("Throwing exception " + e.getMessage()); | ||
throw new ExecutionFailedException( | ||
"Unable to write theme import file", e); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.