-
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.
fix: apply CssImport to exported webcomponent (#19740)
CssImport annotation with just a value attribute can be injected automatically to shadow root of all exported web components (embedded applications) using Constructable StyleSheets. WebComponentExporter should have a theme to make automation work properly in theme-generator.js. Theme property "autoInjectGlobalCssImports": true in theme.json enable auto injection. Disabled by default. Fixes: #19700 Co-authored-by: Marco Collovati <[email protected]>
- Loading branch information
1 parent
cff6c42
commit b817168
Showing
11 changed files
with
193 additions
and
25 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
3 changes: 3 additions & 0 deletions
3
...est-embedding/test-embedding-application-theme/src/main/frontend/css-import-component.css
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,3 @@ | ||
DIV.cssimport { | ||
color: gold | ||
} |
1 change: 1 addition & 0 deletions
1
...dding/test-embedding-application-theme/src/main/frontend/themes/embedded-theme/theme.json
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
34 changes: 34 additions & 0 deletions
34
...ding-application-theme/src/main/java/com/vaadin/flow/webcomponent/CssImportComponent.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,34 @@ | ||
/* | ||
* Copyright 2000-2024 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.webcomponent; | ||
|
||
import com.vaadin.flow.component.Tag; | ||
import com.vaadin.flow.component.dependency.CssImport; | ||
import com.vaadin.flow.component.html.Div; | ||
|
||
@Tag("css-import-component") | ||
@CssImport("./css-import-component.css") | ||
public class CssImportComponent extends Div { | ||
|
||
public CssImportComponent(String id) { | ||
setId(id); | ||
Div div = new Div( | ||
"Global CssImport styles should be applied inside embedded web component, this should not be black"); | ||
div.setClassName("cssimport"); | ||
add(div); | ||
} | ||
} |
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
35 changes: 19 additions & 16 deletions
35
flow-tests/test-embedding/test-embedding-application-theme/src/main/webapp/index.html
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 |
---|---|---|
@@ -1,17 +1,20 @@ | ||
<!doctype html> | ||
|
||
<head> | ||
<script type="module" src="web-component/themed-component.js"></script> | ||
</head> | ||
|
||
<body> | ||
|
||
<h1>Lumo styles should not be applied</h1> | ||
<div class="internal" id="internal">Internal should not apply, this should be black</div> | ||
<div class="global" id="global">Document styles should apply, this should be blue</div> | ||
|
||
|
||
<themed-component id="first"></themed-component> | ||
<themed-component id="second"></themed-component> | ||
|
||
</body> | ||
<html> | ||
<head> | ||
<script type="module" src="web-component/themed-component.js"></script> | ||
</head> | ||
<body> | ||
<h1>Lumo styles should not be applied</h1> | ||
<div class="internal" id="internal"> | ||
Internal should not apply, this should be black | ||
</div> | ||
<div class="cssimport" id="cssimport"> | ||
CssImport styles should apply, this should not be black | ||
</div> | ||
<div class="global" id="global"> | ||
Document styles should apply, this should be blue | ||
</div> | ||
<themed-component id="first"></themed-component> | ||
<themed-component id="second"></themed-component> | ||
</body> | ||
</html> |
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