-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.tsx
34 lines (28 loc) · 1.21 KB
/
content.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import Content from '@/components/content';
import renderRoot from '@/entryPoints/render/render-root.tsx';
import mainCSS from '@/entryPoints/main.css?inline';
import contentCSS from '@/components/content/content.css?inline';
function createShadow() {
// Inside content page html, will create a custom entry tag <ext-boilerplate-entry>
const sidebarTagName = 'ext-boilerplate-entry';
const sidebarElement = document.createElement(sidebarTagName);
document.documentElement.appendChild(sidebarElement);
const shadowRoot = sidebarElement.attachShadow({ mode: 'open' });
shadowRoot.adoptedStyleSheets = [];
if ('adoptedStyleSheets' in Document.prototype) {
[mainCSS, contentCSS].forEach((styleSheetContent) => {
const styleSheet = new CSSStyleSheet();
styleSheet.replaceSync(styleSheetContent);
shadowRoot.adoptedStyleSheets.push(styleSheet);
});
} else {
// Fallback: Use <style> tags for older browsers
[mainCSS, contentCSS].forEach((styleSheetContent) => {
const styleElement = document.createElement('style');
styleElement.textContent = styleSheetContent;
shadowRoot.appendChild(styleElement);
});
}
return shadowRoot;
}
renderRoot(createShadow(), <Content />);