Skip to content

Commit d6b4ab5

Browse files
authored
refactor: make custom CSS theme independent (#386)
With the move to CSS custom properties, the CSS that is added to the shadow DOM is theme independent and never changed when the theme is changed. Theme dependent styling has to be achieved by use of CSS cutsom properties only. This method is adjusted to reflect the standard framework behaviour. BREAKING CHANGE: the signature of the addCustomCSS method exported by "@ui5/webcomponents-base/Theming.js" is changed from addCustomCSS(tag, theme, css) to addCustomCSS(tag, css)
1 parent eb4dcf2 commit d6b4ab5

File tree

2 files changed

+11
-15
lines changed

2 files changed

+11
-15
lines changed

packages/base/src/Theming.js

+1-2
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,8 @@ const setTheme = async theme => {
4141
};
4242

4343
const getEffectiveStyle = ElementClass => {
44-
const theme = getTheme();
4544
const tag = ElementClass.getMetadata().getTag();
46-
const customStyle = getCustomCSS(theme, tag) || "";
45+
const customStyle = getCustomCSS(tag) || "";
4746
let componentStyles = ElementClass.styles;
4847

4948
if (Array.isArray(componentStyles)) {
+10-13
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
const customCSSMap = new Map();
1+
const customCSSFor = {};
22

3-
const addCustomCSS = (tag, theme, css) => {
4-
let themeCustomCSS = customCSSMap.get(theme);
5-
6-
if (!themeCustomCSS) {
7-
customCSSMap.set(theme, {});
8-
themeCustomCSS = customCSSMap.get(theme);
3+
const addCustomCSS = (tag, css, ...rest) => {
4+
// TODO remove deprecation error after 1 release
5+
if (rest.length) {
6+
throw new Error("addCustomCSS no longer accepts theme specific CSS. new signature is `addCustomCSS(tag, css)`");
97
}
108

11-
if (!themeCustomCSS[tag]) {
12-
themeCustomCSS[tag] = [];
9+
if (!customCSSFor[tag]) {
10+
customCSSFor[tag] = [];
1311
}
1412

15-
themeCustomCSS[tag].push(css);
13+
customCSSFor[tag].push(css);
1614
};
1715

18-
const getCustomCSS = (theme, tag) => {
19-
const themeCustomCSS = customCSSMap.get(theme);
20-
return themeCustomCSS && themeCustomCSS[tag] ? themeCustomCSS[tag].join("") : "";
16+
const getCustomCSS = tag => {
17+
return customCSSFor[tag] ? customCSSFor[tag].join("") : "";
2118
};
2219

2320
export { addCustomCSS, getCustomCSS };

0 commit comments

Comments
 (0)