Skip to content

Commit

Permalink
feat(framework): styles and staticAreaStyles may now be nested arrays (
Browse files Browse the repository at this point in the history
  • Loading branch information
vladitasev authored Aug 3, 2020
1 parent bb624ae commit bb87e65
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 15 deletions.
3 changes: 2 additions & 1 deletion packages/base/src/StaticAreaItem.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { getStaticAreaInstance, removeStaticArea } from "./StaticArea.js";
import RenderScheduler from "./RenderScheduler.js";
import getStylesString from "./theming/getStylesString.js";

/**
* @class
Expand All @@ -22,7 +23,7 @@ class StaticAreaItem {
*/
_updateFragment() {
const renderResult = this.ui5ElementContext.constructor.staticAreaTemplate(this.ui5ElementContext),
stylesToAdd = window.ShadyDOM ? false : this.ui5ElementContext.constructor.staticAreaStyles;
stylesToAdd = window.ShadyDOM ? false : getStylesString(this.ui5ElementContext.constructor.staticAreaStyles);

if (!this.staticAreaItemDomRef) {
// Initial rendering of fragment
Expand Down
9 changes: 3 additions & 6 deletions packages/base/src/theming/getEffectiveStyle.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import { getCustomCSS } from "./CustomStyle.js";
import getStylesString from "./getStylesString.js";

const getEffectiveStyle = ElementClass => {
const tag = ElementClass.getMetadata().getTag();
const customStyle = getCustomCSS(tag) || "";
let componentStyles = ElementClass.styles;

if (Array.isArray(componentStyles)) {
componentStyles = componentStyles.join(" ");
}
return `${componentStyles} ${customStyle}`;
const builtInStyles = getStylesString(ElementClass.styles);
return `${builtInStyles} ${customStyle}`;
};


export default getEffectiveStyle;
13 changes: 13 additions & 0 deletions packages/base/src/theming/getStylesString.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const getStylesString = styles => {
if (Array.isArray(styles)) {
return flatten(styles).join(" ");
}

return styles;
};

const flatten = arr => {
return arr.reduce((acc, val) => acc.concat(Array.isArray(val) ? flatten(val) : val), []);
};

export default getStylesString;
2 changes: 1 addition & 1 deletion packages/fiori/src/UploadCollectionItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class UploadCollectionItem extends ListItem {
}

static get styles() {
return [...ListItem.styles, UploadCollectionItemCss];
return [ListItem.styles, UploadCollectionItemCss];
}

static get template() {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/CustomListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ class CustomListItem extends ListItem {
}

static get styles() {
return [...ListItem.styles, customListItemCss];
return [ListItem.styles, customListItemCss];
}

get classes() {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/DateRangePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class DateRangePicker extends DatePicker {
}

static get styles() {
return [...DatePicker.styles, DateRangePickerCss];
return [DatePicker.styles, DateRangePickerCss];
}

static get template() {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/DateTimePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ class DateTimePicker extends DatePicker {
}

static get staticAreaStyles() {
return [...super.staticAreaStyles, DateTimePickerPopoverCss];
return [super.staticAreaStyles, DateTimePickerPopoverCss];
}

static async onDefine() {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/ResponsivePopover.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class ResponsivePopover extends Popover {
}

static get styles() {
return [...Popover.styles, ResponsivePopoverCss];
return [Popover.styles, ResponsivePopoverCss];
}

static get template() {
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/TabContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,11 +222,11 @@ class TabContainer extends UI5Element {
}

static get styles() {
return [...tabStyles, tabContainerCss];
return [tabStyles, tabContainerCss];
}

static get staticAreaStyles() {
return [ResponsivePopoverCommonCss, ...staticAreaTabStyles];
return [ResponsivePopoverCommonCss, staticAreaTabStyles];
}

static get render() {
Expand Down
2 changes: 1 addition & 1 deletion packages/main/src/TreeListItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ class TreeListItem extends ListItem {
}

static get styles() {
return [...ListItem.styles, treeListItemCss];
return [ListItem.styles, treeListItemCss];
}

static get metadata() {
Expand Down

0 comments on commit bb87e65

Please sign in to comment.