Skip to content
This repository was archived by the owner on Mar 4, 2020. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ This project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.htm
- Export `broadcast` icon in Teams theme @miroslavstastny ([#1737](https://github.com/stardust-ui/react/pull/1737))
- Ensure `actionsMenu` is not cut-off by the edge of viewport for `ChatMessage` @kuzhelov ([#1739](https://github.com/stardust-ui/react/pull/1739))
- `FocusZone` should respect elements with `contenteditable` attribute on Home/End key press @sophieH29 ([#1749](https://github.com/stardust-ui/react/pull/1749))
- Fix incorrect order of plugin execution in `felaRenderer` @lucivpav ([#1741](https://github.com/stardust-ui/react/pull/1741))

### Features
- Expose `isFromKeyboard` in `Grid` component @sophieH29 ([#1729](https://github.com/stardust-ui/react/pull/1729))
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@
"merge2": "^1.2.2",
"normalize.css": "^8.0.0",
"portfinder": "^1.0.20",
"prettier": "1.18.2",
"prettier": "^1.18.2",
"progress": "^2.0.3",
"puppeteer": "^1.11.0",
"react": "^16.8.6",
Expand Down
5 changes: 4 additions & 1 deletion packages/internal-tooling/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,11 @@
"eslint-plugin-jsx-a11y": "^6.2.1",
"eslint-plugin-react": "^7.12.4",
"eslint-plugin-react-hooks": "^1.6.0",
"fela": "^10.6.1",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should wait for #1743 to be merged first and remove this change here.
@layershifter Do you agree?

"jest": "^24.5.0",
"jest-axe": "^3.1.1"
"jest-axe": "^3.1.1",
"jest-react-fela": "^10.6.1",
"react-fela": "^10.6.1"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same here

},
"files": [
"babel",
Expand Down
2 changes: 1 addition & 1 deletion packages/react/jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ module.exports = {
'docs/(.*)$': `<rootDir>/../../docs/$1`,

// Legacy aliases, they should not be used in new tests
'src/(.*)$': `<rootDir>/src/$1`,
'^src/(.*)$': `<rootDir>/src/$1`,
'test/(.*)$': `<rootDir>/test/$1`,
},
}
23 changes: 12 additions & 11 deletions packages/react/src/lib/felaInvokeKeyframesPlugin.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import callable from './callable'
import * as _ from 'lodash'

/**
* Fela plugin for invoking keyframes with params. The keyframes, defined in the animationName prop,
Expand All @@ -12,20 +13,20 @@ export default () => {
return Object.keys(styles).reduce((acc, cssPropertyName) => {
const cssPropertyValue = styles[cssPropertyName]

if (cssPropertyName === 'animationName' && typeof cssPropertyValue === 'object') {
if (cssPropertyValue.keyframe) {
styles[cssPropertyName] = callable(cssPropertyValue.keyframe)(
cssPropertyValue.params || {},
)
}
if (_.isPlainObject(cssPropertyValue)) {
if (cssPropertyName === 'animationName') {
if (cssPropertyValue.keyframe) {
styles[cssPropertyName] = callable(cssPropertyValue.keyframe)(
cssPropertyValue.params || {},
)
}

return {
...acc,
[cssPropertyName]: styles[cssPropertyName],
return {
...acc,
[cssPropertyName]: styles[cssPropertyName],
}
}
}

if (typeof cssPropertyValue === 'object') {
return {
...acc,
[cssPropertyName]: invokeKeyframes(cssPropertyValue),
Expand Down
7 changes: 4 additions & 3 deletions packages/react/src/lib/felaRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,23 +52,24 @@ const rendererConfig = {
filterClassName,
enhancers: [],
plugins: [
felaDisableAnimationsPlugin(),

// is necessary to prevent accidental style typos
// from breaking ALL the styles on the page
felaSanitizeCss({
skip: ['content', 'keyframe'],
}),

felaPluginPlaceholderPrefixer(),
felaInvokeKeyframesPlugin(),
felaPluginEmbedded(),
felaPluginPrefixer(),

// Heads up!
// This is required after fela-plugin-prefixer to resolve the array of fallback values prefixer produces.
felaPluginFallbackValue(),

felaExpandCssShorthandsPlugin(),
felaDisableAnimationsPlugin(),
felaInvokeKeyframesPlugin(),
felaPluginEmbedded(),

felaPluginRtl(),
],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,123 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`CSS fallback values are rendered 1`] = `
".a {
color: red;
color: blue;
}


<div className=ui-box a />;
"
`;

exports[`array returned by keyframe results in CSS fallback values 1`] = `
"@-webkit-keyframes k1 {
0% {
color: blue;
color: red;
color: yellow;
}
100% {
color: blue;
color: red;
color: yellow;
}
}
@-moz-keyframes k1 {
0% {
color: blue;
color: red;
color: yellow;
}
100% {
color: blue;
color: red;
color: yellow;
}
}
@keyframes k1 {
0% {
color: blue;
color: red;
color: yellow;
}
100% {
color: blue;
color: red;
color: yellow;
}
}
.a {
animation-name: k1;
}


<div className=ui-provider__box dir=ltr>
<div className=ui-box a />
</div>;
"
`;

exports[`basic styles are rendered 1`] = `
".a {
color: red;
}


<div className=ui-box a />;
"
`;

exports[`keyframe colors are rendered 1`] = `
"@-webkit-keyframes k1 {
from {
color: red;
}
to {
color: blue;
}
}
@-moz-keyframes k1 {
from {
color: red;
}
to {
color: blue;
}
}
@keyframes k1 {
from {
color: red;
}
to {
color: blue;
}
}
.a {
animation-name: k1;
}
.b {
animation-duration: 5s;
}


<div className=ui-provider__box dir=ltr>
<div className=ui-box a b />
</div>;
"
`;

exports[`marginLeft is rendered into marginRight due to RTL 1`] = `
".a {
margin-right: 10px;
}


<div className=ui-provider__box dir=rtl>
<span className=ui-text a dir=auto>
Hello
</span>
</div>;
"
`;
Original file line number Diff line number Diff line change
Expand Up @@ -56,4 +56,12 @@ describe('felaRenderKeyframesPlugin', () => {
animationDuration: '2s',
})
})

test('does not transform a list of strings', () => {
Copy link
Contributor Author

@lucivpav lucivpav Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe the felaInvokeKeyframesPlugin fix and test should be moved into a separate commit? The reason for this fix is that screener tests are failing, if the order of plugins is changed.

Copy link
Contributor Author

@lucivpav lucivpav Aug 2, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The checkboxStyles definition contains root: display: ['inline-grid', '-ms-inline-grid']. This gets processed by felaInvokeKeyframesPlugin incorrectly, rendering it as root: display: { 0: 'inline-grid', 1: '-ms-inline-grid' }.

const style = {
display: ['inline-grid', '-ms-inline-grid'],
}

expect(renderInvokeKeyframes(style, 'RULE', felaRenderer)).toMatchObject(style)
})
})
91 changes: 91 additions & 0 deletions packages/react/test/specs/lib/felaRenderer-test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
import * as React from 'react'
import { createSnapshot } from 'jest-react-fela'
import { EmptyThemeProvider } from 'test/utils'
import Box from 'src/components/Box/Box'
import Provider from 'src/components/Provider/Provider'
import Text from 'src/components/Text/Text'
import { felaRenderer } from 'src/lib'

test('basic styles are rendered', () => {
const snapshot = createSnapshot(
<EmptyThemeProvider>
<Box styles={{ color: 'red' }} />
</EmptyThemeProvider>,
{},
felaRenderer,
)
expect(snapshot).toMatchSnapshot()
})

test('CSS fallback values are rendered', () => {
const snapshot = createSnapshot(
<EmptyThemeProvider>
<Box styles={{ color: ['red', 'blue'] }} />
</EmptyThemeProvider>,
{},
felaRenderer,
)
expect(snapshot).toMatchSnapshot()
})

test('keyframe colors are rendered', () => {
const spinner = {
keyframe: ({ fromColor, toColor }) => ({
from: {
color: fromColor,
},
to: {
color: toColor,
},
}),
keyframeParams: {
fromColor: 'red',
toColor: 'blue',
},
duration: '5s',
}

const snapshot = createSnapshot(
<Provider theme={{ animations: { spinner } }}>
<Box animation="spinner" />
</Provider>,
{},
felaRenderer,
)
expect(snapshot).toMatchSnapshot()
})

test('array returned by keyframe results in CSS fallback values', () => {
const steps = ['0%', '100%']

const spinner = {
keyframe: ({ steps }) => {
const obj = {}
steps.forEach((step: string, index) => {
;(obj as any)[step] = { color: ['blue', 'red', 'yellow'] }
})
return obj
},
keyframeParams: { steps },
}

const snapshot = createSnapshot(
<Provider theme={{ animations: { spinner } }}>
<Box animation="spinner" />
</Provider>,
{},
felaRenderer,
)
expect(snapshot).toMatchSnapshot()
})

test('marginLeft is rendered into marginRight due to RTL', () => {
const snapshot = createSnapshot(
<Provider rtl={true}>
<Text content="Hello" styles={{ marginLeft: '10px' }} />
</Provider>,
{},
felaRenderer,
)
expect(snapshot).toMatchSnapshot()
})
Loading