Skip to content

Commit

Permalink
Merge pull request #2029 from styled-components/fix-cgs-keyframes
Browse files Browse the repository at this point in the history
fix createGlobalStyles + keyframes
  • Loading branch information
quantizor committed Sep 24, 2018
2 parents 88b1f54 + 0c28b1a commit a0549a9
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 1 deletion.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
.*/dist/.*
.*/lib/.*
.*/src/test/.*
.*/src/vendor/.*
.*/src/.*/test/.*
.*/example/.*
.*/integration-test/.*
Expand Down
1 change: 1 addition & 0 deletions src/constructors/createGlobalStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import StyleSheet from '../models/StyleSheet';
import { StyleSheetConsumer } from '../models/StyleSheetManager';
import determineTheme from '../utils/determineTheme';
import { ThemeConsumer, type Theme } from '../models/ThemeProvider';
// $FlowFixMe
import hashStr from '../vendor/glamor/hash';
import css from './css';

Expand Down
1 change: 1 addition & 0 deletions src/constructors/keyframes.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import css from './css';
import generateAlphabeticName from '../utils/generateAlphabeticName';
import stringifyRules from '../utils/stringifyRules';
// $FlowFixMe
import hashStr from '../vendor/glamor/hash';
import Keyframes from '../models/Keyframes';

Expand Down
38 changes: 38 additions & 0 deletions src/constructors/test/createGlobalStyle.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import ServerStyleSheet from '../../models/ServerStyleSheet';
import StyleSheetManager from '../../models/StyleSheetManager';

import createGlobalStyle from '../createGlobalStyle';
import keyframes from '../keyframes';

let context;

Expand Down Expand Up @@ -338,6 +339,43 @@ body{background:red;}"
`"The global style component sc-global-2176982909 was given child JSX. createGlobalStyle does not render children."`
);
});

it('works with keyframes', () => {
const { render } = setup();

const rotate360 = keyframes`
from {
transform: rotate(0deg);
}
to {
transform: rotate(360deg);
}
`;

const GlobalStyle = createGlobalStyle`
div {
display: inline-block;
animation: ${rotate360} 2s linear infinite;
padding: 2rem 1rem;
font-size: 1.2rem;
}
`;

render(
<div>
<GlobalStyle />
<div>&lt; 💅 &gt;</div>
</div>
);

expect(getCSS(document).trim()).toMatchInlineSnapshot(`
"/* sc-component-id:sc-global-2592835591 */
div{display:inline-block;-webkit-animation:a 2s linear infinite;animation:a 2s linear infinite;padding:2rem 1rem;font-size:1.2rem;}
/* sc-component-id:sc-keyframes-a */
@-webkit-keyframes a{from{-webkit-transform:rotate(0deg);-ms-transform:rotate(0deg);transform:rotate(0deg);}to{-webkit-transform:rotate(360deg);-ms-transform:rotate(360deg);transform:rotate(360deg);}} @keyframes a{from{-webkit-transform:rotate(0deg);-ms-transform:rotate(0deg);transform:rotate(0deg);}to{-webkit-transform:rotate(360deg);-ms-transform:rotate(360deg);transform:rotate(360deg);}}"
`);
});
});

function setup() {
Expand Down
1 change: 1 addition & 0 deletions src/models/ComponentStyle.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// @flow
// $FlowFixMe
import hashStr from '../vendor/glamor/hash';
import flatten from '../utils/flatten';
import generateAlphabeticName from '../utils/generateAlphabeticName';
Expand Down
2 changes: 1 addition & 1 deletion src/models/GlobalStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ export default class GlobalStyle {
}

createStyles(executionContext: Object, styleSheet: StyleSheet) {
const flatCSS = flatten(this.rules, executionContext);
const flatCSS = flatten(this.rules, executionContext, styleSheet);
const css = stringifyRules(flatCSS, '');

styleSheet.inject(this.componentId, css);
Expand Down
2 changes: 2 additions & 0 deletions src/models/InlineStyle.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@
/* eslint-disable import/no-unresolved */
import transformDeclPairs from 'css-to-react-native';

// $FlowFixMe
import hashStr from '../vendor/glamor/hash';
import type { RuleSet, StyleSheet } from '../types';
import flatten from '../utils/flatten';
// $FlowFixMe
import parse from '../vendor/postcss-safe-parser/parse';

let generated = {};
Expand Down

0 comments on commit a0549a9

Please sign in to comment.