Skip to content

Commit e213837

Browse files
committed
Add demo for <link>/<style> in shadow vs CSS module
1 parent 6cf4a91 commit e213837

File tree

8 files changed

+45444
-0
lines changed

8 files changed

+45444
-0
lines changed

demo4/cssModuleElement.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import sheet from "./styles.css";
2+
3+
class CSSModuleTestElement extends HTMLElement {
4+
constructor() {
5+
super();
6+
this.shadow = this.attachShadow({mode: "closed"});
7+
this.shadow.adoptedStyleSheets = [sheet];
8+
9+
this.shadow.innerHTML =
10+
`<div class="outer-container"><div class="text-container">This text should be styled</div></div>`;
11+
}
12+
}
13+
export {CSSModuleTestElement};

demo4/index.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<h2>Demo 4: Overhead of &lt;link&gt; elements for styles in shadow root</h2>
2+
<br>
3+
<ul>
4+
<li><a href="./noModule.html">With &lt;link rel="stylesheet"&gt; in shadow root</a></li>
5+
<li><a href="./module.html">With CSS Module</a> (no browser support yet...)</li>
6+
</ul>
7+
<a href="../">[Back to main page]</a>

demo4/linkInShadowElement.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class LinkTestElement extends HTMLElement {
2+
constructor() {
3+
super();
4+
this.shadow = this.attachShadow({mode: "closed"});
5+
6+
this.shadow.innerHTML =
7+
`<link rel="stylesheet" href="styles.css" /><div class="outer-container"><div class="text-container">This text should be styled</div></div>`;
8+
}
9+
}
10+
export {LinkTestElement};

demo4/module.html

Lines changed: 15123 additions & 0 deletions
Large diffs are not rendered by default.

demo4/noModuleLink.html

Lines changed: 15123 additions & 0 deletions
Large diffs are not rendered by default.

demo4/noModuleStyle.html

Lines changed: 15123 additions & 0 deletions
Large diffs are not rendered by default.

demo4/styleInShadowElement.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
class StyleTestElement extends HTMLElement {
2+
constructor() {
3+
super();
4+
this.shadow = this.attachShadow({mode: "closed"});
5+
6+
this.shadow.innerHTML =
7+
`<style>
8+
.outer-container {
9+
display:inline-block;
10+
margin: 0.2em;
11+
border: 2px solid red;
12+
}
13+
14+
.text-container {
15+
padding-right: 0.3em;
16+
font-size: 2em;
17+
font-style: italic;
18+
font-family: 'Impact';
19+
background: linear-gradient(to right, orange , yellow, green, cyan, blue, violet);
20+
background-clip: text;
21+
-webkit-background-clip: text;
22+
text-fill-color: transparent;
23+
-webkit-text-fill-color: transparent;
24+
}
25+
</style><div class="outer-container"><div class="text-container">This text should be styled</div></div>`;
26+
}
27+
}
28+
export {StyleTestElement};

demo4/styles.css

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
.outer-container {
2+
display:inline-block;
3+
margin: 0.2em;
4+
border: 2px solid red;
5+
}
6+
7+
.text-container {
8+
padding-right: 0.3em;
9+
font-size: 2em;
10+
font-style: italic;
11+
font-family: 'Impact';
12+
background: linear-gradient(to right, orange , yellow, green, cyan, blue, violet);
13+
background-clip: text;
14+
-webkit-background-clip: text;
15+
text-fill-color: transparent;
16+
-webkit-text-fill-color: transparent;
17+
}

0 commit comments

Comments
 (0)