Skip to content

Commit 1b801f9

Browse files
committed
Merge branch 'master' into chore/update-storybook
2 parents 1106f34 + 826ef49 commit 1b801f9

Some content is hidden

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

44 files changed

+2854
-667
lines changed

.storybook/main.js

Lines changed: 34 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1+
const { highlightLog } = require('../scripts/utils');
12
const path = require('path');
23
const PATHS = require('../config/paths');
4+
const dedent = require('dedent');
35
require('dotenv').config({
46
path: path.join(PATHS.root, '.env')
57
});
@@ -13,12 +15,7 @@ const DEPENDENCY_REGEX = BUILD_FOR_IE11
1315

1416
module.exports = {
1517
stories: ['../docs/**/*.stories.mdx', '../packages/**/*.stories.mdx', '../packages/**/*.stories.[tj]sx'],
16-
addons: [
17-
'@storybook/addon-toolbars',
18-
'@storybook/addon-docs',
19-
'@storybook/addon-controls',
20-
'@storybook/addon-actions'
21-
],
18+
addons: ['@storybook/addon-knobs', '@storybook/addon-docs', '@storybook/addon-actions'],
2219
webpack: async (config, { configType }) => {
2320
// `configType` has a value of 'DEVELOPMENT' or 'PRODUCTION'
2421
// You can change the configuration based on that.
@@ -30,6 +27,35 @@ module.exports = {
3027
type: 'javascript/auto'
3128
});
3229

30+
const tsLoader = {
31+
test: /\.tsx?$/,
32+
include: PATHS.packages,
33+
use: [
34+
{
35+
loader: require.resolve('babel-loader'),
36+
options: {
37+
envName: 'esm',
38+
configFile: path.resolve(PATHS.root, 'babel.config.js')
39+
}
40+
}
41+
]
42+
};
43+
44+
if (IS_RELEASE_BUILD) {
45+
highlightLog('Warning: Prop Types Table Generation is active');
46+
tsLoader.use.push(require.resolve('react-docgen-typescript-loader'));
47+
} else {
48+
highlightLog('Info: Prop Types Table Generation is disabled');
49+
console.log(dedent`
50+
The Prop Table Generation is very expensive during build-time and therefore disabled by default.
51+
If you need Prop-Tables, you can activate it by adding a '.env' file to the root of the project with the following content:
52+
53+
UI5_WEBCOMPONENTS_FOR_REACT_RELEASE_BUILD=true\n\n
54+
`);
55+
}
56+
57+
config.module.rules.push(tsLoader);
58+
3359
if ((IS_RELEASE_BUILD && configType === 'PRODUCTION') || BUILD_FOR_IE11) {
3460
config.module.rules.push({
3561
test: /\.(js|mjs)$/,
@@ -76,6 +102,8 @@ module.exports = {
76102
}
77103
});
78104
}
105+
106+
config.resolve.extensions.push('.ts', '.tsx');
79107
config.resolve.alias = {
80108
...config.resolve.alias,
81109
'@shared': path.join(PATHS.root, 'shared'),

.storybook/preview.js

Lines changed: 10 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import { select, withKnobs } from '@storybook/addon-knobs';
12
import { makeDecorator } from '@storybook/addons';
23
import { addDecorator, addParameters } from '@storybook/react';
34
import { setTheme } from '@ui5/webcomponents-base/dist/config/Theme';
@@ -22,11 +23,11 @@ addParameters({
2223
: a[1].id.localeCompare(b[1].id, undefined, { numeric: true, caseFirst: 'upper' });
2324
},
2425
showRoots: true
25-
},
26-
passArgsFirst: true,
27-
actions: { argTypesRegex: '^on.*' }
26+
}
2827
});
2928

29+
addDecorator(withKnobs);
30+
3031
const ThemeContainer = ({ theme, contentDensity, children, direction }) => {
3132
useEffect(() => {
3233
if (contentDensity === ContentDensity.Compact) {
@@ -36,9 +37,9 @@ const ThemeContainer = ({ theme, contentDensity, children, direction }) => {
3637
}
3738
}, [contentDensity]);
3839

39-
useEffect(() => {
40-
document.querySelector('html').setAttribute('dir', direction);
41-
}, [direction]);
40+
// useEffect(() => {
41+
// document.querySelector('html').setAttribute('dir', direction.toLowerCase());
42+
// }, [direction]);
4243

4344
useEffect(() => {
4445
setTheme(theme);
@@ -53,9 +54,9 @@ const withQuery = makeDecorator({
5354
wrapper: (getStory, context) => {
5455
return (
5556
<ThemeContainer
56-
theme={context.globalArgs.theme || Themes.sap_fiori_3}
57-
contentDensity={context.globalArgs.contentDensity}
58-
direction={context.globalArgs.direction}
57+
theme={select('Theme', Themes, Themes.sap_fiori_3)}
58+
contentDensity={select('ContentDensity', ContentDensity, ContentDensity.Cozy)}
59+
direction={select('Text Direction', ['LTR', 'RTL'], 'LTR')}
5960
>
6061
{getStory(context)}
6162
</ThemeContainer>
@@ -64,74 +65,3 @@ const withQuery = makeDecorator({
6465
});
6566

6667
addDecorator(withQuery);
67-
68-
export const globalArgTypes = {
69-
theme: {
70-
name: 'Theme',
71-
description: 'Fiori Theme',
72-
defaultValue: Themes.sap_fiori_3,
73-
toolbar: {
74-
icon: 'paintbrush',
75-
items: [
76-
{
77-
value: Themes.sap_fiori_3,
78-
title: Themes.sap_fiori_3
79-
},
80-
{
81-
value: Themes.sap_fiori_3_dark,
82-
title: Themes.sap_fiori_3_dark
83-
},
84-
{
85-
value: Themes.sap_belize,
86-
title: Themes.sap_belize
87-
},
88-
{
89-
value: Themes.sap_belize_hcb,
90-
title: Themes.sap_belize_hcb
91-
},
92-
{
93-
value: Themes.sap_belize_hcw,
94-
title: Themes.sap_belize_hcw
95-
}
96-
]
97-
}
98-
},
99-
contentDensity: {
100-
name: 'Content Density',
101-
description: 'Content Density',
102-
defaultValue: ContentDensity.Cozy,
103-
toolbar: {
104-
icon: 'component',
105-
items: [
106-
{
107-
value: ContentDensity.Cozy,
108-
title: ContentDensity.Cozy
109-
},
110-
{
111-
value: ContentDensity.Compact,
112-
title: ContentDensity.Compact
113-
}
114-
]
115-
}
116-
},
117-
direction: {
118-
name: 'Direction',
119-
description: 'Text Direction',
120-
defaultValue: 'ltr',
121-
toolbar: {
122-
icon: 'transfer',
123-
items: [
124-
{
125-
value: 'ltr',
126-
title: 'LTR',
127-
icon: 'arrowrightalt'
128-
},
129-
{
130-
value: 'rtl',
131-
title: 'RTL',
132-
icon: 'arrowleftalt'
133-
}
134-
]
135-
}
136-
}
137-
};

CHANGELOG.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,23 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.10.0-rc.1](https://github.com/SAP/ui5-webcomponents-react/compare/v0.10.0-rc.0...v0.10.0-rc.1) (2020-05-25)
7+
8+
9+
### Bug Fixes
10+
11+
* **AnalyticalTable:** remove padding and scrollbar from select-all header cell ([#536](https://github.com/SAP/ui5-webcomponents-react/issues/536)) ([97158a3](https://github.com/SAP/ui5-webcomponents-react/commit/97158a39663cf40c424829a86962df7070a0dacb)), closes [#532](https://github.com/SAP/ui5-webcomponents-react/issues/532)
12+
* **DurationPicker:** use correct value for defaultProp maxValue ([#529](https://github.com/SAP/ui5-webcomponents-react/issues/529)) ([888d069](https://github.com/SAP/ui5-webcomponents-react/commit/888d069a86784c4833f9257abc67e569be3dd231))
13+
14+
15+
### Features
16+
17+
* **StyleClassHelper:** add putIfPresent method ([#539](https://github.com/SAP/ui5-webcomponents-react/issues/539)) ([0ae0785](https://github.com/SAP/ui5-webcomponents-react/commit/0ae078554dd0e7e6a1424de6755ec02fa15bb12e))
18+
19+
20+
21+
22+
623
# [0.10.0-rc.0](https://github.com/SAP/ui5-webcomponents-react/compare/v0.9.5...v0.10.0-rc.0) (2020-05-19)
724

825

config/jestsetup.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { createSerializer } from 'enzyme-to-json';
66
import ResizeObserver from 'resize-observer-polyfill';
77
import 'intersection-observer';
88
import '@ui5/webcomponents/dist/generated/json-imports/i18n';
9+
import 'whatwg-fetch';
910

1011
// React 16 Enzyme adapter
1112
Enzyme.configure({ adapter: new Adapter() });

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.10.0-rc.0",
5+
"version": "0.10.0-rc.1",
66
"npmClient": "yarn",
77
"useWorkspaces": true,
88
"command": {

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@
101101
"targz": "^1.0.1",
102102
"tmp": "^0.1.0",
103103
"tslint": "^6.1.2",
104-
"typescript": "^3.8.3"
104+
"typescript": "^3.8.3",
105+
"whatwg-fetch": "^3.0.0"
105106
},
106107
"resolutions": {
107108
"@types/react": "16.9.34",

packages/base/CHANGELOG.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,17 @@
33
All notable changes to this project will be documented in this file.
44
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
55

6+
# [0.10.0-rc.1](https://github.com/SAP/ui5-webcomponents-react/compare/v0.10.0-rc.0...v0.10.0-rc.1) (2020-05-25)
7+
8+
9+
### Features
10+
11+
* **StyleClassHelper:** add putIfPresent method ([#539](https://github.com/SAP/ui5-webcomponents-react/issues/539)) ([0ae0785](https://github.com/SAP/ui5-webcomponents-react/commit/0ae078554dd0e7e6a1424de6755ec02fa15bb12e))
12+
13+
14+
15+
16+
617
# [0.10.0-rc.0](https://github.com/SAP/ui5-webcomponents-react/compare/v0.9.5...v0.10.0-rc.0) (2020-05-19)
718

819

packages/base/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@ui5/webcomponents-react-base",
3-
"version": "0.10.0-rc.0",
3+
"version": "0.10.0-rc.1",
44
"description": "Base for ui5-webcomponents-react",
55
"main": "index.cjs.js",
66
"module": "index.esm.js",
Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,40 @@
11
import { fetchI18nBundle, getI18nBundle } from '@ui5/webcomponents-base/dist/i18nBundle';
22
import { useEffect, useState } from 'react';
33

4+
type TextWithDefault = { key: string; defaultText: string };
5+
type TextWithPlaceholders = [TextWithDefault, ...string[]];
6+
47
interface I18nBundle {
5-
getText: (textObj: { key: string; defaultText: string }, ...args: any) => string;
8+
getText: (textObj: TextWithDefault, ...args: any) => string;
69
}
710

8-
export const useI18nBundle = (bundleName): I18nBundle => {
9-
const [bundle, setBundle] = useState(getI18nBundle(bundleName));
11+
const resolveTranslations = (bundle, texts) => {
12+
return texts.map((text) => {
13+
if (Array.isArray(text)) {
14+
const [key, ...replacements] = text;
15+
return bundle.getText(key, replacements);
16+
}
17+
return bundle.getText(text);
18+
});
19+
};
20+
21+
export const useI18nText = (bundleName: string, ...texts: (TextWithDefault | TextWithPlaceholders)[]): string[] => {
22+
const i18nBundle: I18nBundle = getI18nBundle(bundleName);
23+
const [translations, setTranslations] = useState(resolveTranslations(i18nBundle, texts));
1024

1125
useEffect(() => {
1226
const fetchAndLoadBundle = async () => {
1327
await fetchI18nBundle(bundleName);
14-
setBundle(getI18nBundle(bundleName));
28+
setTranslations((prev) => {
29+
const next = resolveTranslations(i18nBundle, texts);
30+
if (prev.length === next.length && prev.every((translation, index) => next[index] === translation)) {
31+
return prev;
32+
}
33+
return next;
34+
});
1535
};
1636
fetchAndLoadBundle();
17-
}, []);
37+
}, [fetchI18nBundle, bundleName, texts]);
1838

19-
return bundle;
39+
return translations;
2040
};

packages/base/src/lib/hooks.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { useConsolidatedRef } from '../hooks/useConsolidatedRef';
2-
import { useI18nBundle } from '../hooks/useI18nBundle';
2+
import { useI18nText } from '../hooks/useI18nBundle';
33
import { usePassThroughHtmlProps } from '../hooks/usePassThroughHtmlProps';
44
import { useViewportRange } from '../hooks/useViewportRange';
55

6-
export { useConsolidatedRef, usePassThroughHtmlProps, useViewportRange, useI18nBundle };
6+
export { useConsolidatedRef, usePassThroughHtmlProps, useViewportRange, useI18nText };

packages/base/src/styling/CssSizeVariables.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export enum CssSizeVariablesNames {
1414
sapWcrAnalyticalTableTreePaddingLevel1 = 'sapWcrAnalyticalTableTreePaddingLevel1',
1515
sapWcrAnalyticalTableTreePaddingLevel2 = 'sapWcrAnalyticalTableTreePaddingLevel2',
1616
sapWcrAnalyticalTableTreePaddingLevel3 = 'sapWcrAnalyticalTableTreePaddingLevel3',
17+
sapWcrCheckBoxWidthHeight = 'sapWcrCheckBoxWidthHeight',
1718
sapWcrAnalyticalTableSelectionColumnWidth = 'sapWcrAnalyticalTableSelectionColumnWidth'
1819
}
1920

@@ -42,6 +43,7 @@ export const cssVariablesStyles = `
4243
--${CssSizeVariablesNames.sapWcrAnalyticalTableTreePaddingLevel1}:1.5rem;
4344
--${CssSizeVariablesNames.sapWcrAnalyticalTableTreePaddingLevel2}:2.25rem;
4445
--${CssSizeVariablesNames.sapWcrAnalyticalTableTreePaddingLevel3}:2.75rem;
46+
--${CssSizeVariablesNames.sapWcrCheckBoxWidthHeight}:2.75rem;
4547
--${CssSizeVariablesNames.sapWcrAnalyticalTableSelectionColumnWidth}:55px;
4648
4749
}
@@ -63,6 +65,7 @@ export const cssVariablesStyles = `
6365
--${CssSizeVariablesNames.sapWcrAnalyticalTableTreePaddingLevel1}:1rem;
6466
--${CssSizeVariablesNames.sapWcrAnalyticalTableTreePaddingLevel2}:1.5rem;
6567
--${CssSizeVariablesNames.sapWcrAnalyticalTableTreePaddingLevel3}:2rem;
68+
--${CssSizeVariablesNames.sapWcrCheckBoxWidthHeight}:2rem;
6669
--${CssSizeVariablesNames.sapWcrAnalyticalTableSelectionColumnWidth}:40px;
6770
}
6871
`;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { StyleClassHelper } from './StyleClassHelper';
2+
3+
describe('StyleClassHelper', () => {
4+
test('add class names', () => {
5+
const helper = StyleClassHelper.of('class1', 'class2');
6+
expect(helper.className).toEqual(`class1 class2`);
7+
});
8+
9+
test('put new classes', () => {
10+
const helper = StyleClassHelper.of('firstClass');
11+
helper.put('secondClass');
12+
expect(helper.className).toEqual(`firstClass secondClass`);
13+
});
14+
15+
test('putIfPresent', () => {
16+
const helper = StyleClassHelper.of('firstClass');
17+
helper.put('secondClass');
18+
helper.putIfPresent('ifPresent1');
19+
helper.putIfPresent('ifPresent2', 'ifPresent3');
20+
helper.putIfPresent(true === false && 'shouldNotBeThere1', 'a' === 'a' && 'ifPresent4');
21+
22+
expect(helper.className).toEqual('firstClass secondClass ifPresent1 ifPresent2 ifPresent3 ifPresent4');
23+
});
24+
25+
test('className, toString and valueOf return same value', () => {
26+
const helper = StyleClassHelper.of('class1', 'class2');
27+
expect(helper.toString()).toEqual(`class1 class2`);
28+
expect(helper.valueOf()).toEqual(`class1 class2`);
29+
expect(helper.className).toEqual(`class1 class2`);
30+
});
31+
});

0 commit comments

Comments
 (0)