Skip to content

Commit efee11f

Browse files
vberschMarcusNotheis
authored andcommitted
feat(ThemeProvider): Read config from UI5 Web Components
BREAKING CHANGE Themes: rename Theme `sap_fiori3_light` to `sap_fiori_3` BREAKING CHANGE ThemeProvider: removed contentDensity and theme props. To set those, use the [ui5 WebComponents configuration script tag](https://github.com/SAP/ui5-webcomponents#configure).
1 parent e133e66 commit efee11f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

71 files changed

+244
-200
lines changed

README.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,12 @@ npm install @fiori-for-react/fiori3 --save
7676
In order to use `fiori-for-react` you have to wrap your application's root component into the `ThemeProvider`.<br/>
7777
You will find this component most likely in `src/App.js`:
7878
```jsx
79-
import { ContentDensity } from '@fiori-for-react/fiori3/lib/ContentDensity';
8079
import { ThemeProvider } from '@fiori-for-react/fiori3/lib/ThemeProvider';
81-
import { Themes } from '@fiori-for-react/fiori3/lib/Themes';
8280
...
8381
render() {
8482
return (
8583
<div>
86-
<ThemeProvider theme={Themes.sap_fiori3_light} contentDensity={ContentDensity.Compact} withToastContainer>
84+
<ThemeProvider withToastContainer>
8785
<MyApp />
8886
</ThemeProvider>
8987
</div>

config/jest.config.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
const PATHS = require('./paths');
22
const path = require('path');
3+
// const webComponentConfigMock = require('./webComponentConfigMock');
34

45
module.exports = {
56
preset: 'ts-jest',
@@ -29,6 +30,12 @@ module.exports = {
2930
moduleNameMapper: {
3031
'^@shared/(.*)$': '<rootDir>/shared/$1',
3132
'^@ui5/webcomponents/dist(.*)$': 'identity-obj-proxy', // ui5 web components can be mocked, not relevant for jest tests
33+
'^@ui5/webcomponents-base/src/Configuration(.*)$': path.resolve(
34+
PATHS.shared,
35+
'tests',
36+
'mock',
37+
'webComponentConfigMock.js'
38+
),
3239
'\\.(css|less)$': 'identity-obj-proxy'
3340
},
3441
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],

lerna.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"packages": [
33
"packages/*"
44
],
5-
"version": "0.3.1-rc.2",
5+
"version": "0.3.1",
66
"npmClient": "yarn",
77
"useWorkspaces": true,
88
"command": {

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@
6666
"filesize": "^4.1.2",
6767
"fs-extra": "^7.0.0",
6868
"glob": "^7.1.4",
69+
"global": "^4.4.0",
6970
"google-closure-compiler": "^20190415.0.0",
7071
"gzip-size": "^5.1.0",
7172
"husky": "^2.2.0",
@@ -97,6 +98,7 @@
9798
"nyc": "^13.3.0",
9899
"ora": "^3.4.0",
99100
"puppeteer": "^1.15.0",
101+
"qs": "^6.7.0",
100102
"react": "^16.8.6",
101103
"react-docgen-typescript-loader": "^3.1.0",
102104
"react-docgen-typescript-webpack-plugin": "^1.1.0",

packages/charts/src/util/populateData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import belizePlus from './../themes/sap_belize_plus';
44
const getMapForTheme = (theme) => {
55
switch (theme) {
66
case 'sap_belize':
7-
case 'sap_fiori3_light': // TODO This needs to change as soon there is a Fiori3 Color Map Available
7+
case 'sap_fiori_3': // TODO This needs to change as soon there is a Fiori3 Color Map Available
88
return belize;
99
case 'sap_belize_plus':
1010
return belizePlus;

packages/docs/.storybook/TableComponent.tsx

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,4 @@
1-
import {
2-
ContentDensity,
3-
Badge,
4-
Label,
5-
Table,
6-
TableCell,
7-
TableColumn,
8-
TableRow,
9-
Text,
10-
ThemeProvider,
11-
Themes
12-
} from '@fiori-for-react/fiori3';
1+
import { Badge, Label, Table, TableCell, TableColumn, TableRow, Text, ThemeProvider } from '@fiori-for-react/fiori3';
132
import React from 'react';
143

154
const columns = [
@@ -24,13 +13,13 @@ export const TableComponent = (props) => {
2413
const info = props.type.__docgenInfo;
2514
if (!info || !info.props) {
2615
return (
27-
<ThemeProvider theme={Themes.sap_fiori3_light} contentDensity={ContentDensity.Compact}>
16+
<ThemeProvider>
2817
<Text>Unfortunately, there are no prop types available for this component.</Text>
2918
</ThemeProvider>
3019
);
3120
}
3221
return (
33-
<ThemeProvider theme={Themes.sap_fiori3_light} contentDensity={ContentDensity.Compact}>
22+
<ThemeProvider>
3423
<Table
3524
columns={columns}
3625
rows={Object.values(info.props).map((componentInfo: any) => (

packages/docs/.storybook/config.js

Lines changed: 55 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import { withInfo } from '@storybook/addon-info';
77
import { TableComponent } from './TableComponent';
88
import { withStyleInfo } from './decorators/withStyleInfo';
99
import { Fiori4ReactTheme } from './theme';
10+
import { document, history, window } from 'global';
11+
import qs from 'qs';
1012

1113
export const propTablesExclude = [ThemeProvider];
1214

@@ -94,23 +96,66 @@ addParameters({
9496
}
9597
});
9698

97-
const themr = makeDecorator({
98-
name: 'themr',
99-
parameterName: 'themr',
100-
skipIfNoParametersOrOptions: false,
101-
wrapper: (getStory, context, { parameters }) => {
99+
class ThemeContainer extends React.PureComponent {
100+
componentDidUpdate(prevProps) {
101+
const { contentDensity, setQueryParam } = this.props;
102+
if (contentDensity !== prevProps.contentDensity) {
103+
setQueryParam({
104+
'sap-ui-compactSize': contentDensity === ContentDensity.Compact
105+
});
106+
}
107+
}
108+
109+
render() {
110+
return this.props.children;
111+
}
112+
}
113+
114+
const withQuery = makeDecorator({
115+
name: 'withQuery',
116+
parameterName: 'query',
117+
wrapper: (getStory, context) => {
118+
function setQueryParam(queryObj) {
119+
const iframe = window.parent.document.getElementById('storybook-preview-iframe');
120+
const [base, search] = iframe.src.split('?');
121+
const currentQuery = qs.parse(search, { ignoreQueryPrefix: true });
122+
iframe.src = `${base}?${qs.stringify({ ...currentQuery, ...queryObj })}`;
123+
}
124+
let contentDensity;
125+
try {
126+
const iframe = window.parent.document.getElementById('storybook-preview-iframe');
127+
const currentQuery = qs.parse(iframe.src.split('?')[1]);
128+
contentDensity =
129+
currentQuery['sap-ui-compactSize'] && currentQuery['sap-ui-compactSize'] !== 'false'
130+
? ContentDensity.Compact
131+
: ContentDensity.Cozy;
132+
} catch (e) {
133+
contentDensity = ContentDensity.Cozy;
134+
}
135+
102136
return (
103-
<ThemeProvider
104-
theme={select('Theme', [Themes.sap_fiori3_light], Themes.sap_fiori3_light)}
105-
contentDensity={select('ContentDensity', ContentDensity, ContentDensity.Compact)}
106-
withToastContainer
137+
<ThemeContainer
138+
theme={select('Theme', [Themes.sap_fiori_3], Themes.sap_fiori_3)}
139+
contentDensity={select('ContentDensity', ContentDensity, contentDensity)}
140+
setQueryParam={setQueryParam}
107141
>
108142
{getStory(context)}
109-
</ThemeProvider>
143+
</ThemeContainer>
110144
);
111145
}
112146
});
113147

148+
const themr = makeDecorator({
149+
name: 'themr',
150+
parameterName: 'themr',
151+
skipIfNoParametersOrOptions: false,
152+
wrapper: (getStory, context) => {
153+
// debugger;
154+
return <ThemeProvider withToastContainer>{getStory(context)}</ThemeProvider>;
155+
}
156+
});
157+
158+
addDecorator(withQuery);
114159
addDecorator(themr);
115160

116161
// Load all Stories

packages/docs/.storybook/decorators/withStyleInfo.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import React, { Component } from 'react';
2-
import { ContentDensity, Label, Text, ThemeProvider, Themes } from '@fiori-for-react/fiori3';
2+
import { Label, Text, ThemeProvider } from '@fiori-for-react/fiori3';
33

44
const withStyleContainer = {
55
fontFamily:
@@ -64,7 +64,7 @@ class WithStyleInfo extends Component<any> {
6464
<div>
6565
{children}
6666
<div style={withStyleContainer}>
67-
<ThemeProvider theme={Themes.sap_fiori3_light} contentDensity={ContentDensity.Compact}>
67+
<ThemeProvider>
6868
<h1 style={titleStyle}>Styling API</h1>
6969
<div style={{ display: 'flex', flexDirection: 'column', marginTop: '1rem' }}>
7070
{styleInfo.attributes.map((info) => (

packages/docs/Welcome.tsx

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,13 +91,11 @@ storiesOf(' Welcome | Fiori-for-React', module)
9191
</Text>
9292
<Highlight source="javascript">
9393
{dedent`...
94-
import { ContentDensity } from '@fiori-for-react/fiori3/lib/ContentDensity';
9594
import { ThemeProvider } from '@fiori-for-react/fiori3/lib/ThemeProvider';
96-
import { Themes } from '@fiori-for-react/fiori3/lib/Themes';
9795
...
9896
render() {
9997
return (
100-
<ThemeProvider theme={Themes.sap_fiori3_light} contentDensity={ContentDensity.Compact} withToastContainer>
98+
<ThemeProvider withToastContainer>
10199
<MyApp />
102100
</ThemeProvider>
103101
);

packages/fiori3/__karma_snapshots__/ActionSheet.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#### `Render without Crashing`
44

55
```
6-
<ThemeProvider theme="sap_fiori3_light" contentDensity="Compact" withToastContainer={false}>
6+
<ThemeProvider withToastContainer={false}>
77
<ThemeProvider jss={{...}} theme={{...}}>
88
<Jss(WithStyles(ActionSheet)) openBy={{...}} placement="Bottom">
99
<WithStyles(ActionSheet) openBy={{...}} placement="Bottom" classes={{...}}>

0 commit comments

Comments
 (0)