-
Notifications
You must be signed in to change notification settings - Fork 274
/
Copy pathupdateShadowRoot.ts
29 lines (24 loc) · 995 Bytes
/
updateShadowRoot.ts
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
import getConstructableStyle from "./theming/getConstructableStyle.js";
import type UI5Element from "./UI5Element.js";
/**
* Updates the shadow root of a UI5Element or its static area item
* @param element
* @param forStaticArea
*/
const updateShadowRoot = (element: UI5Element, forStaticArea = false) => {
const ctor = element.constructor as typeof UI5Element;
const shadowRoot = forStaticArea ? element.staticAreaItem!.shadowRoot : element.shadowRoot;
let renderResult;
if (forStaticArea) {
renderResult = element.renderStatic(); // this is checked before calling updateShadowRoot
} else {
renderResult = element.render(); // this is checked before calling updateShadowRoot
}
if (!shadowRoot) {
console.warn(`There is no shadow root to update`); // eslint-disable-line
return;
}
shadowRoot.adoptedStyleSheets = getConstructableStyle(ctor, forStaticArea);
ctor.renderer(renderResult, shadowRoot, forStaticArea, { host: element });
};
export default updateShadowRoot;