Skip to content

Commit

Permalink
feat(framework): Limited support for campact size on IE (#2230)
Browse files Browse the repository at this point in the history
  • Loading branch information
vladitasev committed Sep 23, 2020
1 parent 67c4d69 commit 4128216
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/base/src/UI5Element.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ const GLOBAL_DIR_CSS_VAR = "--_ui5_dir";
class UI5Element extends HTMLElement {
constructor() {
super();
this._propertyChangeListeners = new Set();
this._initializeState();
this._upgradeAllProperties();
this._initializeContainers();
Expand All @@ -59,7 +60,6 @@ class UI5Element extends HTMLElement {
this._domRefReadyPromise._deferredResolve = deferredResolve;

this._monitoredChildProps = new Map();
this._propertyChangeListeners = new Set();
this._shouldInvalidateParent = false;
}

Expand Down
24 changes: 24 additions & 0 deletions packages/base/src/theming/CSSVarsPonyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ const runPonyfill = () => {

window.CSSVarsPonyfill.cssVars({
rootElement: document.head,
variables: isCompact() ? getCompactModeVars() : {},
silent: true,
});
};
Expand All @@ -17,6 +18,29 @@ const schedulePonyfill = () => {
}
};

const isCompact = () => {
const b = document.body;
return b.hasAttribute("data-ui5-compact-size") || b.classList.contains("ui5-content-density-compact") || b.classList.contains("sapUiSizeCompact");
};

const getCompactModeVars = () => {
const compactVars = {};
[...document.querySelectorAll(`[data-ui5-theme-properties]`)].forEach(el => {
const cssContent = el.textContent.replace("\n", "");
let match;
const regExp = new RegExp("data-ui5-compact-size[^{]*{(.*?)}", "g");
while ((match = regExp.exec(cssContent)) !== null) { // eslint-disable-line
const compactCSS = match[1];
compactCSS.split(";").forEach(declaration => {
const pair = declaration.split(":");
compactVars[pair[0].trim()] = pair[1].trim();
});
}
});

return compactVars;
};

export {
ponyfillNeeded,
runPonyfill,
Expand Down

0 comments on commit 4128216

Please sign in to comment.