MCPcopy Create free account
hub / github.com/UI5/webcomponents / updateStyle

Function updateStyle

packages/base/src/ManagedStyles.ts:29–52  ·  view source on GitHub ↗
(content: string, name: string, value = "", theme?: string)

Source from the content-addressed store, hash-verified

27};
28
29const updateStyle = (content: string, name: string, value = "", theme?: string) => {
30 if (isSSR) {
31 return;
32 }
33
34 const currentRuntimeIndex = getCurrentRuntimeIndex();
35
36 const stylesheet = document.adoptedStyleSheets.find(sh => (sh as Record<string, any>)._ui5StyleId === getStyleId(name, value));
37 if (!stylesheet) {
38 return;
39 }
40
41 if (!theme) {
42 stylesheet.replaceSync(content || "");
43 } else {
44 const stylesheetRuntimeIndex: string | undefined = (stylesheet as Record<string, any>)._ui5RuntimeIndex;
45 const stylesheetTheme: string | undefined = (stylesheet as Record<string, any>)._ui5Theme;
46 if (stylesheetTheme !== theme || shouldUpdate(stylesheetRuntimeIndex)) {
47 stylesheet.replaceSync(content || "");
48 (stylesheet as Record<string, any>)._ui5RuntimeIndex = String(currentRuntimeIndex);
49 (stylesheet as Record<string, any>)._ui5Theme = theme;
50 }
51 }
52};
53
54const hasStyle = (name: string, value = ""): boolean => {
55 if (isSSR) {

Callers 1

createOrUpdateStyleFunction · 0.85

Calls 3

getCurrentRuntimeIndexFunction · 0.85
getStyleIdFunction · 0.85
shouldUpdateFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…