Skip to content

Commit bb87e65

Browse files
authored
feat(framework): styles and staticAreaStyles may now be nested arrays (#2058)
1 parent bb624ae commit bb87e65

10 files changed

+26
-15
lines changed

packages/base/src/StaticAreaItem.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { getStaticAreaInstance, removeStaticArea } from "./StaticArea.js";
22
import RenderScheduler from "./RenderScheduler.js";
3+
import getStylesString from "./theming/getStylesString.js";
34

45
/**
56
* @class
@@ -22,7 +23,7 @@ class StaticAreaItem {
2223
*/
2324
_updateFragment() {
2425
const renderResult = this.ui5ElementContext.constructor.staticAreaTemplate(this.ui5ElementContext),
25-
stylesToAdd = window.ShadyDOM ? false : this.ui5ElementContext.constructor.staticAreaStyles;
26+
stylesToAdd = window.ShadyDOM ? false : getStylesString(this.ui5ElementContext.constructor.staticAreaStyles);
2627

2728
if (!this.staticAreaItemDomRef) {
2829
// Initial rendering of fragment
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,12 @@
11
import { getCustomCSS } from "./CustomStyle.js";
2+
import getStylesString from "./getStylesString.js";
23

34
const getEffectiveStyle = ElementClass => {
45
const tag = ElementClass.getMetadata().getTag();
56
const customStyle = getCustomCSS(tag) || "";
6-
let componentStyles = ElementClass.styles;
77

8-
if (Array.isArray(componentStyles)) {
9-
componentStyles = componentStyles.join(" ");
10-
}
11-
return `${componentStyles} ${customStyle}`;
8+
const builtInStyles = getStylesString(ElementClass.styles);
9+
return `${builtInStyles} ${customStyle}`;
1210
};
1311

14-
1512
export default getEffectiveStyle;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
const getStylesString = styles => {
2+
if (Array.isArray(styles)) {
3+
return flatten(styles).join(" ");
4+
}
5+
6+
return styles;
7+
};
8+
9+
const flatten = arr => {
10+
return arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flatten(val) : val), []);
11+
};
12+
13+
export default getStylesString;

packages/fiori/src/UploadCollectionItem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ class UploadCollectionItem extends ListItem {
242242
}
243243

244244
static get styles() {
245-
return [...ListItem.styles, UploadCollectionItemCss];
245+
return [ListItem.styles, UploadCollectionItemCss];
246246
}
247247

248248
static get template() {

packages/main/src/CustomListItem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CustomListItem extends ListItem {
5050
}
5151

5252
static get styles() {
53-
return [...ListItem.styles, customListItemCss];
53+
return [ListItem.styles, customListItemCss];
5454
}
5555

5656
get classes() {

packages/main/src/DateRangePicker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class DateRangePicker extends DatePicker {
8282
}
8383

8484
static get styles() {
85-
return [...DatePicker.styles, DateRangePickerCss];
85+
return [DatePicker.styles, DateRangePickerCss];
8686
}
8787

8888
static get template() {

packages/main/src/DateTimePicker.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ class DateTimePicker extends DatePicker {
176176
}
177177

178178
static get staticAreaStyles() {
179-
return [...super.staticAreaStyles, DateTimePickerPopoverCss];
179+
return [super.staticAreaStyles, DateTimePickerPopoverCss];
180180
}
181181

182182
static async onDefine() {

packages/main/src/ResponsivePopover.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class ResponsivePopover extends Popover {
8080
}
8181

8282
static get styles() {
83-
return [...Popover.styles, ResponsivePopoverCss];
83+
return [Popover.styles, ResponsivePopoverCss];
8484
}
8585

8686
static get template() {

packages/main/src/TabContainer.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -222,11 +222,11 @@ class TabContainer extends UI5Element {
222222
}
223223

224224
static get styles() {
225-
return [...tabStyles, tabContainerCss];
225+
return [tabStyles, tabContainerCss];
226226
}
227227

228228
static get staticAreaStyles() {
229-
return [ResponsivePopoverCommonCss, ...staticAreaTabStyles];
229+
return [ResponsivePopoverCommonCss, staticAreaTabStyles];
230230
}
231231

232232
static get render() {

packages/main/src/TreeListItem.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ class TreeListItem extends ListItem {
161161
}
162162

163163
static get styles() {
164-
return [...ListItem.styles, treeListItemCss];
164+
return [ListItem.styles, treeListItemCss];
165165
}
166166

167167
static get metadata() {

0 commit comments

Comments
 (0)