Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Theming: Use UI5 Web Components CSS Variables #46

Merged
merged 10 commits into from
Jul 1, 2019
5 changes: 3 additions & 2 deletions config/jest.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
const PATHS = require('./paths');
const path = require('path');
// const webComponentConfigMock = require('./webComponentConfigMock');

module.exports = {
preset: 'ts-jest',
Expand All @@ -26,7 +25,7 @@ module.exports = {
'!**/webComponents/**/*'
],
setupFilesAfterEnv: ['./config/jestsetup.ts'],
testEnvironment: 'jsdom-fourteen',
testEnvironment: 'jsdom-fifteen',
testMatch: ['<rootDir>/**/?(*.)(spec|test).{js,jsx,ts,tsx}'],
moduleNameMapper: {
'^@shared/(.*)$': '<rootDir>/shared/$1',
Expand All @@ -37,6 +36,8 @@ module.exports = {
'mock',
'webComponentConfigMock.js'
),
'^@ui5/webcomponents-base/src/boot': '<rootDir>/shared/tests/mock/WebComponentsBoot',
'^@ui5/webcomponents-base/src/theming/StyleInjection': '<rootDir>/shared/tests/mock/StyleInjection',
'\\.(css|less)$': 'identity-obj-proxy'
},
moduleFileExtensions: ['js', 'jsx', 'ts', 'tsx'],
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@
"istanbul-instrumenter-loader": "^3.0.1",
"jest": "^24.8.0",
"jest-canvas-mock": "^2.0.0-beta.1",
"jest-environment-jsdom-fourteen": "^0.1.0",
"jest-environment-jsdom-fifteen": "^1.0.0",
"jest-enzyme": "^7.0.2",
"jss-snapshot-serializer": "^1.0.0",
"karma": "^4.0.1",
Expand Down
22 changes: 22 additions & 0 deletions packages/base/scripts/cssVariables/parse.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
const { writeFileSync } = require('fs');
const { _: Fiori3ThemingVariables } = require('@ui5/webcomponents/dist/themes/sap_fiori_3/parameters-bundle.css.json');

const variables = Fiori3ThemingVariables.replace(':root{', '')
.replace(/}$/, '')
.split(';')
.filter((variable) => !/^--_?ui5/.test(variable))
.map((value) => value.split(':')[0]);

let fileContent = `/*
* ### WARNING ###
* This is an autogenerated file, do not change manually.
* In order to recreate this file, please run 'node packages/base/scripts/cssVariables/parse.js'
*/

`;

for (const variable of variables) {
fileContent += `export const ${variable.replace('--', '')} = 'var(${variable});';\n`;
}

writeFileSync('test.ts', fileContent);
19 changes: 0 additions & 19 deletions packages/base/src/HSLColor.test.ts

This file was deleted.

1,862 changes: 551 additions & 1,311 deletions packages/base/src/sap_fiori_3.ts

Large diffs are not rendered by default.

1,224 changes: 558 additions & 666 deletions packages/main/__karma_snapshots__/ObjectPage.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion packages/main/__karma_snapshots__/ObjectPageSubSection.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
#### `Render without Crashing`

```
<div class="ObjectPageSubSection-objectPageSubSectionHeader---"><div class="ObjectPageSubSection-objectPageSubSectionHeaderTitle---"></div></div><div class="ObjectPageSubSection-subSectionContent---"></div>
<div class="ObjectPageSubSection-objectPageSubSectionHeaderTitle---"></div><div class="ObjectPageSubSection-subSectionContent---"></div>
```

16 changes: 8 additions & 8 deletions packages/main/__karma_snapshots__/ProgressIndicator.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<WithStyles(ProgressIndicator) displayValue="sdf" width="50%" height="50%" percentValue={40} visible={true} state="None" theme={{...}} classes={{...}}>
<ProgressIndicator displayValue="sdf" width="50%" height="50%" percentValue={40} visible={true} state="None" theme={{...}} classes={{...}}>
<div className="ProgressIndicator-wrapper--- " style={{...}} title={[undefined]} data-ui5-slot={[undefined]}>
<div className="ProgressIndicator-progressbar--- ProgressIndicator-progressbar---" style={{...}} />
<div className="ProgressIndicator-progressbar--- ProgressIndicator-stateNone---" style={{...}} />
<div className="ProgressIndicator-progressBarRemaining---">
<span className="ProgressIndicator-progressBarText--- ProgressIndicator-progressBarTextColorLow--- ProgressIndicator-progressBarTextRight---">

Expand All @@ -34,8 +34,8 @@
<WithStyles(ProgressIndicator) percentValue={85} state="Error" displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<ProgressIndicator percentValue={85} state="Error" displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<div className="ProgressIndicator-wrapper--- " style={{...}} title={[undefined]} data-ui5-slot={[undefined]}>
<div className="ProgressIndicator-progressbar--- ProgressIndicator-progressbar---" style={{...}}>
<span className="ProgressIndicator-progressBarText--- ProgressIndicator-progressBarTextColorHigh--- ProgressIndicator-progressBarTextColorHigh--- ProgressIndicator-progressBarTextLeft---">
<div className="ProgressIndicator-progressbar--- ProgressIndicator-stateError---" style={{...}}>
<span className="ProgressIndicator-progressBarText--- ProgressIndicator-progressBarTextColorHigh--- ProgressIndicator-progressBarTextLeft---">


</span>
Expand All @@ -58,7 +58,7 @@
<WithStyles(ProgressIndicator) state="Error" percentValue={0} displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<ProgressIndicator state="Error" percentValue={0} displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<div className="ProgressIndicator-wrapper--- " style={{...}} title={[undefined]} data-ui5-slot={[undefined]}>
<div className="ProgressIndicator-progressbar--- ProgressIndicator-progressbar---" style={{...}} />
<div className="ProgressIndicator-progressbar--- ProgressIndicator-stateError---" style={{...}} />
<div className="ProgressIndicator-progressBarRemaining---">
<span className="ProgressIndicator-progressBarText--- ProgressIndicator-progressBarTextColorLow--- ProgressIndicator-progressBarTextRight---">

Expand All @@ -82,7 +82,7 @@
<WithStyles(ProgressIndicator) state="None" percentValue={0} displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<ProgressIndicator state="None" percentValue={0} displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<div className="ProgressIndicator-wrapper--- " style={{...}} title={[undefined]} data-ui5-slot={[undefined]}>
<div className="ProgressIndicator-progressbar--- ProgressIndicator-progressbar---" style={{...}} />
<div className="ProgressIndicator-progressbar--- ProgressIndicator-stateNone---" style={{...}} />
<div className="ProgressIndicator-progressBarRemaining---">
<span className="ProgressIndicator-progressBarText--- ProgressIndicator-progressBarTextColorLow--- ProgressIndicator-progressBarTextRight---">

Expand All @@ -106,7 +106,7 @@
<WithStyles(ProgressIndicator) state="Success" percentValue={0} displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<ProgressIndicator state="Success" percentValue={0} displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<div className="ProgressIndicator-wrapper--- " style={{...}} title={[undefined]} data-ui5-slot={[undefined]}>
<div className="ProgressIndicator-progressbar--- ProgressIndicator-progressbar---" style={{...}} />
<div className="ProgressIndicator-progressbar--- ProgressIndicator-stateSuccess---" style={{...}} />
<div className="ProgressIndicator-progressBarRemaining---">
<span className="ProgressIndicator-progressBarText--- ProgressIndicator-progressBarTextColorLow--- ProgressIndicator-progressBarTextRight---">

Expand All @@ -130,7 +130,7 @@
<WithStyles(ProgressIndicator) state="Warning" percentValue={0} displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<ProgressIndicator state="Warning" percentValue={0} displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<div className="ProgressIndicator-wrapper--- " style={{...}} title={[undefined]} data-ui5-slot={[undefined]}>
<div className="ProgressIndicator-progressbar--- ProgressIndicator-progressbar---" style={{...}} />
<div className="ProgressIndicator-progressbar--- ProgressIndicator-stateWarning---" style={{...}} />
<div className="ProgressIndicator-progressBarRemaining---">
<span className="ProgressIndicator-progressBarText--- ProgressIndicator-progressBarTextColorLow--- ProgressIndicator-progressBarTextRight---">

Expand All @@ -154,7 +154,7 @@
<WithStyles(ProgressIndicator) state="Information" percentValue={0} displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<ProgressIndicator state="Information" percentValue={0} displayValue="" visible={true} width="auto" height="" theme={{...}} classes={{...}}>
<div className="ProgressIndicator-wrapper--- " style={{...}} title={[undefined]} data-ui5-slot={[undefined]}>
<div className="ProgressIndicator-progressbar--- ProgressIndicator-progressbar---" style={{...}} />
<div className="ProgressIndicator-progressbar--- ProgressIndicator-stateInformation---" style={{...}} />
<div className="ProgressIndicator-progressBarRemaining---">
<span className="ProgressIndicator-progressBarText--- ProgressIndicator-progressBarTextColorLow--- ProgressIndicator-progressBarTextRight---">

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fonts, HSLColor } from '@ui5/webcomponents-react-base';
import { fonts } from '@ui5/webcomponents-react-base';
import { JSSTheme } from '../../../interfaces/JSSTheme';

const styles = ({ theme, contentDensity, parameters }: JSSTheme) => ({
Expand All @@ -17,7 +17,7 @@ const styles = ({ theme, contentDensity, parameters }: JSSTheme) => ({
backgroundColor: parameters.sapUiTileBackground,
fontFamily: fonts.sapUiFontHeaderFamily,
'&:hover': {
backgroundColor: HSLColor.darken(parameters.sapUiTileBackground, 2).toString()
backgroundColor: parameters.sapUiTileBackgroundDarken20
}
},
arrowIndicatorShape: {
Expand Down
4 changes: 2 additions & 2 deletions packages/main/src/components/Avatar/Avatar.karma.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import React from 'react';
import sinon from 'sinon';
import { AvatarShape } from '../../lib/AvatarShape';
import { AvatarSize } from '../../lib/AvatarSize';
import { Avatar } from './index';
import { Avatar } from '../../lib/Avatar';

use(matchSnapshot);

Expand Down Expand Up @@ -48,7 +48,7 @@ describe('Avatar', () => {
<Avatar size={AvatarSize.XL} customDisplaySize="5rem" customFontSize="2rem" initials="JD" />
);
const el = wrapper.find(Avatar).getDOMNode() as HTMLElement;
expect(el.style.length).to.equal(0);
expect(el.style.fontSize).not.to.equal('2rem');
});

it('with Image', () => {
Expand Down
2 changes: 2 additions & 0 deletions packages/main/src/components/Avatar/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ export class Avatar extends PureComponent<AvatarPropTypes> {
cssClasses.push(classes[`size${size}`]);
}

inlineStyle['--sapUiContentNonInteractiveIconColor'] = 'var(--sapContent_ContrastIconColor)';

if (shape === AvatarShape.Circle) {
cssClasses.push(classes.circle);
}
Expand Down
18 changes: 9 additions & 9 deletions packages/main/src/components/Carousel/CarouselPagination.jss.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import { HSLColor } from '@ui5/webcomponents-react-base';
import { ZIndex } from '../../enums/ZIndex';
import { JSSTheme } from '../../interfaces/JSSTheme';

const lighten = HSLColor.lighten;

const styles = ({ theme, contentDensity, parameters }: JSSTheme) => ({
const styles = ({ parameters }: JSSTheme) => ({
pagination: {
display: 'flex',
width: 'calc(100% - 2rem)',
Expand Down Expand Up @@ -40,16 +37,19 @@ const styles = ({ theme, contentDensity, parameters }: JSSTheme) => ({
textDecoration: 'none',
overflow: 'hidden',
display: 'inline-block',
width: '0.5rem',
height: '0.5rem',
margin: '0 0.25rem',
margin: '0 0.375rem',
width: '0.25rem',
height: '0.25rem',
transition: 'background-color 0.1s ease-in',
borderRadius: '50%',
alignSelf: 'center',
boxSizing: 'border-box',
backgroundColor: lighten(parameters.sapUiContentForegroundColor, 50).hsl,
backgroundColor: parameters.sapUiContentNonInteractiveIconColor,
'&$paginationIconActive': {
backgroundColor: parameters.sapUiContentNonInteractiveIconColor
margin: '0 0.25rem',
width: '0.5rem',
height: '0.5rem',
backgroundColor: parameters.sapUiSelected
}
},
paginationIconActive: {},
Expand Down
41 changes: 41 additions & 0 deletions packages/main/src/components/ObjectPage/AnchorButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
import React from 'react';
import { Event, fonts, StyleClassHelper, withStyles } from '@ui5/webcomponents-react-base';
import { JSSTheme } from '../../interfaces/JSSTheme';

const anchorButtonStyles = ({ parameters }: JSSTheme) => ({
button: {
color: parameters.sapUiContentLabelColor,
fontFamily: fonts.sapUiFontFamily,
fontSize: fonts.sapMFontMediumSize
},
selected: {
color: parameters.sapUiSelected,
minWidth: '2rem',
textAlign: 'center',
'&:after': {
content: '""',
borderBottom: `0.188rem solid ${parameters.sapUiSelected}`,
width: '100%',
position: 'absolute',
bottom: 0,
left: 0
}
}
});

export const AnchorButton = withStyles(anchorButtonStyles)(({ onClick, children, classes, selected }) => {
const classNames = StyleClassHelper.of(classes.button);
if (selected) {
classNames.put(classes.selected);
}

const eventWrapper = (e) => {
onClick(Event.of(null, e, { text: true }));
};

return (
<span onClick={eventWrapper} className={classNames.valueOf()}>
{children}
</span>
);
});
51 changes: 10 additions & 41 deletions packages/main/src/components/ObjectPage/ObjectPage.jss.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import { fonts, HSLColor } from '@ui5/webcomponents-react-base';
import { ZIndex } from '../../enums/ZIndex';
import { fonts } from '@ui5/webcomponents-react-base';
import { JSSTheme } from '../../interfaces/JSSTheme';

const styles = ({ theme, contentDensity, parameters }: JSSTheme) => ({
const styles = ({ parameters }: JSSTheme) => ({
objectPage: {
width: '100%',
height: '100%',
Expand Down Expand Up @@ -104,7 +103,7 @@ const styles = ({ theme, contentDensity, parameters }: JSSTheme) => ({
hideHeaderContent: {
paddingTop: '0.5rem',
marginBottom: '0.5rem',
boxShadow: `inset 0 -1px 0 0 ${parameters.sapUiShellBorderColor}`,
boxShadow: `inset 0 -1px 0 0 ${parameters.sapUiObjectHeaderBorderColor}`,
display: 'flex',
justifyContent: 'center',
alignItems: 'center'
Expand All @@ -113,50 +112,20 @@ const styles = ({ theme, contentDensity, parameters }: JSSTheme) => ({
paddingLeft: '2rem',
backgroundColor: parameters.sapUiObjectHeaderBackground,
boxShadow: `inset 0 0.125rem ${parameters.sapUiObjectHeaderBackground}`,
display: 'flex',
margin: '0px',
height: '2.75rem',
padding: '0px',
listStyle: 'none',
'& $anchorButtonContainer': {
position: 'relative',
display: 'inline-flex',
'& $anchorButton': {
textTransform: 'uppercase',
'& > span:hover, & > span:active': {
backgroundColor: 'transparent',
borderColor: 'transparent',
color: parameters.sapUiButtonLiteTextColor,
'& span[data-icon-content]': {
color: parameters.sapUiButtonLiteTextColor
}
}
},
alignItems: 'center',
'&:not(:first-child)': {
marginLeft: '2rem'
}
},
'& $active': {
color: HSLColor.of(parameters.sapUiGroupTitleTextColor).lighten(20).hsl,
borderBottom: `0.125rem solid ${parameters.sapUiSelected}`
},
'& $active + div': {
color: HSLColor.of(parameters.sapUiGroupTitleTextColor).lighten(20).hsl,
borderBottom: `0.125rem solid ${parameters.sapUiSelected}`
}
},
anchorButtonModal: {
position: 'absolute',
minWidth: '6.25rem',
boxSizing: 'border-box',
outline: 'none',
maxWidth: '100%',
maxHeight: '100%',
border: 'none',
boxShadow: '0 0.625rem 1.875rem 0 rgba(0, 0, 0, 0.15), 0 0 0 1px rgba(0, 0, 0, 0.15)',
borderRadius: '0.25rem',
minHeight: '2rem',
margin: '0',
zIndex: ZIndex.InputModal
},
iconTabModeSelected: {
color: HSLColor.of(parameters.sapUiGroupTitleTextColor).lighten(20).hsl,
borderBottom: `0.125rem solid ${parameters.sapUiSelected}`
},
titleBar: {},
image: {},
container: {},
Expand Down
Loading