styled-components 2.1.1 → 2.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (85) hide show
  1. package/CHANGELOG.md +31 -1
  2. package/CODE_OF_CONDUCT.md +1 -1
  3. package/README.md +12 -67
  4. package/dist/styled-components.es.js +273 -110
  5. package/dist/styled-components.js +325 -119
  6. package/dist/styled-components.min.js +2 -2
  7. package/lib/hoc/withTheme.js +13 -7
  8. package/lib/models/BrowserStyleSheet.js +11 -0
  9. package/lib/models/ComponentStyle.js +45 -2
  10. package/lib/models/InlineStyle.js +1 -1
  11. package/lib/models/ServerStyleSheet.js +33 -17
  12. package/lib/models/StyleSheet.js +9 -0
  13. package/lib/models/StyledComponent.js +82 -38
  14. package/lib/models/StyledNativeComponent.js +31 -15
  15. package/lib/models/ThemeProvider.js +44 -12
  16. package/lib/native/index.js +1 -1
  17. package/lib/test/utils.js +5 -2
  18. package/lib/utils/create-broadcast.js +34 -24
  19. package/lib/utils/domElements.js +1 -1
  20. package/lib/utils/flatten.js +4 -1
  21. package/lib/utils/generateAlphabeticName.js +1 -1
  22. package/lib/utils/nonce.js +10 -0
  23. package/lib/utils/once.js +17 -0
  24. package/package.json +10 -10
  25. package/src/hoc/withTheme.js +14 -7
  26. package/src/models/BrowserStyleSheet.js +8 -0
  27. package/src/models/ComponentStyle.js +42 -2
  28. package/src/models/InlineStyle.js +1 -1
  29. package/src/models/ServerStyleSheet.js +27 -12
  30. package/src/models/StyleSheet.js +9 -0
  31. package/src/models/StyledComponent.js +81 -26
  32. package/src/models/StyledNativeComponent.js +30 -10
  33. package/src/models/ThemeProvider.js +38 -9
  34. package/src/models/test/ThemeProvider.test.js +7 -8
  35. package/src/native/index.js +1 -1
  36. package/src/native/test/native.test.js +14 -0
  37. package/src/test/__snapshots__/ssr.test.js.snap +147 -0
  38. package/src/test/expanded-api.test.js +24 -0
  39. package/src/test/props.test.js +14 -3
  40. package/src/test/ssr.test.js +90 -123
  41. package/src/test/styles.test.js +52 -0
  42. package/src/test/utils.js +5 -2
  43. package/src/utils/create-broadcast.js +31 -17
  44. package/src/utils/domElements.js +1 -0
  45. package/src/utils/flatten.js +16 -6
  46. package/src/utils/generateAlphabeticName.js +1 -1
  47. package/src/utils/nonce.js +6 -0
  48. package/src/utils/once.js +12 -0
  49. package/typings/styled-components.d.ts +15 -21
  50. package/typings/tests/issue1068.tsx +226 -0
  51. package/typings/tests/main-test.tsx +1 -1
  52. package/typings/tests/string-tags-test.tsx +62 -0
  53. package/typings/tests/themed-tests/issue1068.tsx +226 -0
  54. package/typings/tests/themed-tests/mytheme-styled-components.tsx +1 -1
  55. package/typings/tests/themed-tests/with-theme-test.tsx +2 -1
  56. package/typings/tests/with-theme-test.tsx +17 -0
  57. package/lib/constructors/test/injectGlobal.test.js +0 -63
  58. package/lib/constructors/test/keyframes.test.js +0 -48
  59. package/lib/constructors/test/styled.test.js +0 -19
  60. package/lib/models/AbstractStyledComponent.js +0 -43
  61. package/lib/models/test/ThemeProvider.test.js +0 -200
  62. package/lib/native/test/native.test.js +0 -290
  63. package/lib/no-parser/test/basic.test.js +0 -46
  64. package/lib/no-parser/test/flatten.test.js +0 -125
  65. package/lib/no-parser/test/keyframes.test.js +0 -45
  66. package/lib/primitives/test/primitives.test.js +0 -289
  67. package/lib/test/attrs.test.js +0 -158
  68. package/lib/test/basic.test.js +0 -267
  69. package/lib/test/css.test.js +0 -43
  70. package/lib/test/expanded-api.test.js +0 -90
  71. package/lib/test/extending.test.js +0 -198
  72. package/lib/test/overriding.test.js +0 -35
  73. package/lib/test/props.test.js +0 -38
  74. package/lib/test/rehydration.test.js +0 -306
  75. package/lib/test/ssr.test.js +0 -187
  76. package/lib/test/styles.test.js +0 -146
  77. package/lib/test/theme.test.js +0 -497
  78. package/lib/test/warnTooManyClasses.test.js +0 -71
  79. package/lib/utils/test/extractCompsFromCSS.test.js +0 -46
  80. package/lib/utils/test/flatten.test.js +0 -109
  81. package/lib/utils/test/generateAlphabeticName.test.js +0 -14
  82. package/lib/utils/test/interleave.test.js +0 -22
  83. package/lib/utils/test/validAttr.test.js +0 -560
  84. package/src/models/AbstractStyledComponent.js +0 -21
  85. package/typings/tags.d.ts +0 -137
@@ -1,306 +0,0 @@
1
- 'use strict';
2
-
3
- var _templateObject = _taggedTemplateLiteralLoose(['\n color: blue;\n '], ['\n color: blue;\n ']),
4
- _templateObject2 = _taggedTemplateLiteralLoose(['color: blue;'], ['color: blue;']),
5
- _templateObject3 = _taggedTemplateLiteralLoose([''], ['']),
6
- _templateObject4 = _taggedTemplateLiteralLoose(['color: red;'], ['color: red;']),
7
- _templateObject5 = _taggedTemplateLiteralLoose(['color: green;'], ['color: green;']),
8
- _templateObject6 = _taggedTemplateLiteralLoose(['\n color: ', ';\n '], ['\n color: ', ';\n ']),
9
- _templateObject7 = _taggedTemplateLiteralLoose(['\n body { color: tomato; }\n '], ['\n body { color: tomato; }\n ']),
10
- _templateObject8 = _taggedTemplateLiteralLoose(['color: tomato;'], ['color: tomato;']),
11
- _templateObject9 = _taggedTemplateLiteralLoose(['\n html { font-size: 16px; }\n '], ['\n html { font-size: 16px; }\n ']),
12
- _templateObject10 = _taggedTemplateLiteralLoose(['\n body { background: papayawhip; }\n '], ['\n body { background: papayawhip; }\n ']),
13
- _templateObject11 = _taggedTemplateLiteralLoose(['\n from { opacity: 0; }\n '], ['\n from { opacity: 0; }\n ']),
14
- _templateObject12 = _taggedTemplateLiteralLoose(['\n from { opacity: 1; }\n '], ['\n from { opacity: 1; }\n ']),
15
- _templateObject13 = _taggedTemplateLiteralLoose(['animation: ', ' 1s both;'], ['animation: ', ' 1s both;']);
16
-
17
- var _react = require('react');
18
-
19
- var _react2 = _interopRequireDefault(_react);
20
-
21
- var _enzyme = require('enzyme');
22
-
23
- var _utils = require('./utils');
24
-
25
- var _injectGlobal2 = require('../constructors/injectGlobal');
26
-
27
- var _injectGlobal3 = _interopRequireDefault(_injectGlobal2);
28
-
29
- var _stringifyRules = require('../utils/stringifyRules');
30
-
31
- var _stringifyRules2 = _interopRequireDefault(_stringifyRules);
32
-
33
- var _css = require('../constructors/css');
34
-
35
- var _css2 = _interopRequireDefault(_css);
36
-
37
- var _keyframes2 = require('../constructors/keyframes');
38
-
39
- var _keyframes3 = _interopRequireDefault(_keyframes2);
40
-
41
- var _StyleSheet = require('../models/StyleSheet');
42
-
43
- var _StyleSheet2 = _interopRequireDefault(_StyleSheet);
44
-
45
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
46
-
47
- function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
48
-
49
- var keyframes = (0, _keyframes3.default)(function (hash) {
50
- return 'keyframe_' + hash % 1000;
51
- }, _stringifyRules2.default, _css2.default);
52
- var injectGlobal = (0, _injectGlobal3.default)(_stringifyRules2.default, _css2.default);
53
-
54
- var getStyleTags = function getStyleTags() {
55
- return Array.from(document.querySelectorAll('style')).map(function (el) {
56
- return {
57
- isLocal: el.getAttribute('data-styled-components-is-local'),
58
- css: el.innerHTML.trim().replace(/\s+/mg, ' ')
59
- };
60
- });
61
- };
62
-
63
- var styled = void 0;
64
-
65
- describe('rehydration', function () {
66
- /**
67
- * Make sure the setup is the same for every test
68
- */
69
- beforeEach(function () {
70
- styled = (0, _utils.resetStyled)();
71
- });
72
-
73
- describe('with existing styled components', function () {
74
- beforeEach(function () {
75
- /* Hash 1323611362 is based on name TWO and contents color: red.
76
- * Change either and this will break. */
77
- document.head.innerHTML = '\n <style ' + _StyleSheet.SC_ATTR + '=\'b\' ' + _StyleSheet.LOCAL_ATTR + '=\'true\'>\n /* sc-component-id: TWO */\n .TWO {}\n .b { color: red; }\n </style>\n ';
78
- _StyleSheet2.default.reset();
79
- });
80
-
81
- it('should preserve the styles', function () {
82
- (0, _utils.expectCSSMatches)('.TWO {} .b { color: red; }');
83
- });
84
-
85
- it('should append a new component like normal', function () {
86
- var Comp = styled.div.withConfig({ componentId: 'ONE' })(_templateObject);
87
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
88
- (0, _utils.expectCSSMatches)('.TWO {} .b { color: red; } .ONE { } .a { color: blue; }');
89
- });
90
-
91
- it('should reuse a componentId', function () {
92
- var A = styled.div.withConfig({ componentId: 'ONE' })(_templateObject2);
93
- (0, _enzyme.shallow)(_react2.default.createElement(A, null));
94
- var B = styled.div.withConfig({ componentId: 'TWO' })(_templateObject3);
95
- (0, _enzyme.shallow)(_react2.default.createElement(B, null));
96
- (0, _utils.expectCSSMatches)('.TWO {} .b { color: red; } .ONE { } .a { color: blue; }');
97
- });
98
-
99
- it('should reuse a componentId and generated class', function () {
100
- var A = styled.div.withConfig({ componentId: 'ONE' })(_templateObject2);
101
- (0, _enzyme.shallow)(_react2.default.createElement(A, null));
102
- var B = styled.div.withConfig({ componentId: 'TWO' })(_templateObject4);
103
- (0, _enzyme.shallow)(_react2.default.createElement(B, null));
104
- (0, _utils.expectCSSMatches)('.TWO {} .b { color: red; } .ONE { } .a { color: blue; }');
105
- });
106
-
107
- it('should reuse a componentId and inject new classes', function () {
108
- var A = styled.div.withConfig({ componentId: 'ONE' })(_templateObject2);
109
- (0, _enzyme.shallow)(_react2.default.createElement(A, null));
110
- var B = styled.div.withConfig({ componentId: 'TWO' })(_templateObject4);
111
- (0, _enzyme.shallow)(_react2.default.createElement(B, null));
112
- var C = styled.div.withConfig({ componentId: 'TWO' })(_templateObject5);
113
- (0, _enzyme.shallow)(_react2.default.createElement(C, null));
114
- (0, _utils.expectCSSMatches)('.TWO {} .b { color: red; } .c { color: green; } .ONE { } .a { color: blue; }');
115
- });
116
- });
117
-
118
- describe('with styled components with props', function () {
119
- beforeEach(function () {
120
- /* Hash 1323611362 is based on name TWO and contents color: red.
121
- * Change either and this will break. */
122
- document.head.innerHTML = '\n <style ' + _StyleSheet.SC_ATTR + '=\'a b\' ' + _StyleSheet.LOCAL_ATTR + '=\'true\'>\n /* sc-component-id: ONE */\n .ONE {}\n .a { color: blue; }\n /* sc-component-id: TWO */\n .TWO {}\n .b { color: red; }\n </style>\n ';
123
- _StyleSheet2.default.reset();
124
- });
125
-
126
- it('should preserve the styles', function () {
127
- (0, _utils.expectCSSMatches)('\n .ONE { } .a { color: blue; }\n .TWO { } .b { color: red; }\n ');
128
- });
129
-
130
- it('should not inject new styles for a component already rendered', function () {
131
- var Comp = styled.div.withConfig({ componentId: 'ONE' })(_templateObject6, function (props) {
132
- return props.color;
133
- });
134
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, { color: 'blue' }));
135
- (0, _utils.expectCSSMatches)('\n .ONE { } .a { color: blue; }\n .TWO { } .b { color: red; }\n ');
136
- });
137
-
138
- it('should inject new styles for a new computed style of a component', function () {
139
- (0, _utils.seedNextClassnames)(['x']);
140
- var Comp = styled.div.withConfig({ componentId: 'ONE' })(_templateObject6, function (props) {
141
- return props.color;
142
- });
143
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, { color: 'green' }));
144
- (0, _utils.expectCSSMatches)('\n .ONE { } .a { color: blue; } .x { color: green; }\n .TWO { } .b { color: red; }\n ');
145
- });
146
- });
147
-
148
- describe('with inline styles that werent rendered by us', function () {
149
- beforeEach(function () {
150
- /* Same css as before, but without the data attributes we ignore it */
151
- document.head.innerHTML = '\n <style>\n /* sc-component-id: TWO */\n .TWO {}\n .b { color: red; }\n </style>\n ';
152
- _StyleSheet2.default.reset();
153
- });
154
-
155
- it('should leave the existing styles there', function () {
156
- (0, _utils.expectCSSMatches)('.TWO {} .b { color: red; }');
157
- });
158
-
159
- it('should generate new classes, even if they have the same name', function () {
160
- var A = styled.div.withConfig({ componentId: 'ONE' })(_templateObject2);
161
- (0, _enzyme.shallow)(_react2.default.createElement(A, null));
162
- var B = styled.div.withConfig({ componentId: 'TWO' })(_templateObject4);
163
- (0, _enzyme.shallow)(_react2.default.createElement(B, null));
164
- (0, _utils.expectCSSMatches)('.TWO {} .b { color: red; } .ONE { } .a { color: blue; } .TWO {} .b { color: red; } ');
165
- });
166
- });
167
-
168
- describe('with global styles', function () {
169
- beforeEach(function () {
170
- /* Adding a non-local stylesheet with a hash 557410406 which is
171
- * derived from "body { background: papayawhip; }" so be careful
172
- * changing it. */
173
- document.head.innerHTML = '\n <style ' + _StyleSheet.SC_ATTR + ' ' + _StyleSheet.LOCAL_ATTR + '=\'false\'>\n /* sc-component-id: sc-global-557410406 */\n body { background: papayawhip; }\n </style>\n <style ' + _StyleSheet.SC_ATTR + '=\'b\' ' + _StyleSheet.LOCAL_ATTR + '=\'true\'>\n /* sc-component-id: TWO */\n .TWO {}\n .b { color: red; }\n </style>\n ';
174
- _StyleSheet2.default.reset();
175
- });
176
-
177
- it('should leave the existing styles there', function () {
178
- (0, _utils.expectCSSMatches)('body { background: papayawhip; } .TWO {} .b { color: red; }');
179
- });
180
-
181
- it('should inject new global styles at the end', function () {
182
- injectGlobal(_templateObject7);
183
- (0, _utils.expectCSSMatches)('body { background: papayawhip; } .TWO {} .b { color: red; } body { color: tomato; }');
184
-
185
- expect(getStyleTags()).toEqual([{ isLocal: 'false', css: '/* sc-component-id: sc-global-557410406 */ body { background: papayawhip; }' }, { isLocal: 'true', css: '/* sc-component-id: TWO */ .TWO {} .b { color: red; }' }, { isLocal: 'false', css: '/* sc-component-id: sc-global-2299393384 */ body{color: tomato;}' }]);
186
- });
187
-
188
- it('should interleave global and local styles', function () {
189
- injectGlobal(_templateObject7);
190
- var A = styled.div.withConfig({ componentId: 'ONE' })(_templateObject2);
191
- (0, _enzyme.shallow)(_react2.default.createElement(A, null));
192
-
193
- (0, _utils.expectCSSMatches)('body { background: papayawhip; } .TWO {} .b { color: red; } body { color: tomato; } .ONE { } .a { color: blue; }');
194
- expect(getStyleTags()).toEqual([{ isLocal: 'false', css: '/* sc-component-id: sc-global-557410406 */ body { background: papayawhip; }' }, { isLocal: 'true', css: '/* sc-component-id: TWO */ .TWO {} .b { color: red; }' }, { isLocal: 'false', css: '/* sc-component-id: sc-global-2299393384 */ body{color: tomato;}' }, { isLocal: 'true', css: '/* sc-component-id: ONE */ .ONE {} .a{color: blue;}' }]);
195
- });
196
- });
197
-
198
- describe('with all styles already rendered', function () {
199
- var styleTags = void 0;
200
- beforeEach(function () {
201
- document.head.innerHTML = '\n <style ' + _StyleSheet.SC_ATTR + ' ' + _StyleSheet.LOCAL_ATTR + '=\'false\'>\n /* sc-component-id: sc-global-1455077013 */\n html { font-size: 16px; }\n /* sc-component-id: sc-global-557410406 */\n body { background: papayawhip; }\n </style>\n <style ' + _StyleSheet.SC_ATTR + '=\'a b\' ' + _StyleSheet.LOCAL_ATTR + '=\'true\'>\n /* sc-component-id: ONE */\n .ONE {}\n .a { color: blue; }\n /* sc-component-id: TWO */\n .TWO {}\n .b { color: red; }\n </style>\n ';
202
- styleTags = Array.from(document.querySelectorAll('style'));
203
- _StyleSheet2.default.reset();
204
- });
205
-
206
- it('should not touch existing styles', function () {
207
- (0, _utils.expectCSSMatches)('\n html { font-size: 16px; }\n body { background: papayawhip; }\n .ONE { } .a { color: blue; }\n .TWO { } .b { color: red; }\n ');
208
- });
209
-
210
- it('should replace stylesheets on-demand', function () {
211
- var tagsAfterReset = Array.from(document.querySelectorAll('style'));
212
- expect(tagsAfterReset[0]).toBe(styleTags[0]);
213
- expect(tagsAfterReset[1]).toBe(styleTags[1]);
214
-
215
- /* Rerendering existing tags doesn't touch the DOM */
216
- var A = styled.div.withConfig({ componentId: 'ONE' })(_templateObject2);
217
- (0, _enzyme.shallow)(_react2.default.createElement(A, null));
218
- var B = styled.div.withConfig({ componentId: 'TWO' })(_templateObject4);
219
- (0, _enzyme.shallow)(_react2.default.createElement(B, null));
220
- var styleTagsAfterRehydration = Array.from(document.querySelectorAll('style'));
221
- expect(styleTagsAfterRehydration[0]).toBe(styleTags[0]);
222
- expect(styleTagsAfterRehydration[1]).toBe(styleTags[1]);
223
-
224
- /* Only when new components are introduced (or a previous component
225
- * generates a new hash) does the style tag get replaced. */
226
- var C = styled.div.withConfig({ componentId: 'THREE' })(_templateObject5);
227
- (0, _enzyme.shallow)(_react2.default.createElement(C, null));
228
- var styleTagsAfterAddition = Array.from(document.querySelectorAll('style'));
229
-
230
- /* The first tag is unchanged */
231
- expect(styleTagsAfterAddition[0]).toBe(styleTags[0]);
232
- /* The local tag has been replaced */
233
- expect(styleTagsAfterAddition[1]).not.toBe(styleTags[1]);
234
- /* But it is identical, except for... */
235
- expect(styleTagsAfterAddition[1].outerHTML).toEqual(styleTags[1].outerHTML
236
- /* ...the new data attribute for the new classname "c"... */
237
- .replace(new RegExp(_StyleSheet.SC_ATTR + '="a b"'), _StyleSheet.SC_ATTR + '="a b c"')
238
- /* ...and the new CSS before the closing tag. */
239
- .replace(/(?=<\/style>)/, '\n/* sc-component-id: THREE */\n.THREE {}\n.c{color: green;}'));
240
-
241
- /* Note: any future additions don't replace the style tag */
242
- var D = styled.div.withConfig({ componentId: 'TWO' })(_templateObject8);
243
- (0, _enzyme.shallow)(_react2.default.createElement(D, null));
244
-
245
- expect(Array.from(document.querySelectorAll('style'))[1]).toBe(styleTagsAfterAddition[1]);
246
-
247
- /* The point being, now we have a style tag we can inject new styles in the middle! */
248
- (0, _utils.expectCSSMatches)('\n html { font-size: 16px; }\n body { background: papayawhip; }\n .ONE { } .a { color: blue; }\n .TWO { } .b { color: red; } .d { color: tomato; }\n .THREE { } .c { color: green; }\n ');
249
- });
250
-
251
- it('should not change styles if rendered in the same order they were created with', function () {
252
- injectGlobal(_templateObject9);
253
- injectGlobal(_templateObject10);
254
- var A = styled.div.withConfig({ componentId: 'ONE' })(_templateObject2);
255
- (0, _enzyme.shallow)(_react2.default.createElement(A, null));
256
- var B = styled.div.withConfig({ componentId: 'TWO' })(_templateObject4);
257
- (0, _enzyme.shallow)(_react2.default.createElement(B, null));
258
-
259
- (0, _utils.expectCSSMatches)('\n html { font-size: 16px; }\n body { background: papayawhip; }\n .ONE { } .a { color: blue; }\n .TWO { } .b { color: red; }\n ');
260
- });
261
-
262
- it('should still not change styles if rendered in a different order', function () {
263
- var B = styled.div.withConfig({ componentId: 'TWO' })(_templateObject4);
264
- (0, _enzyme.shallow)(_react2.default.createElement(B, null));
265
- injectGlobal(_templateObject10);
266
- var A = styled.div.withConfig({ componentId: 'ONE' })(_templateObject2);
267
- (0, _enzyme.shallow)(_react2.default.createElement(A, null));
268
- injectGlobal(_templateObject9);
269
-
270
- (0, _utils.expectCSSMatches)('\n html { font-size: 16px; }\n body { background: papayawhip; }\n .ONE { } .a { color: blue; }\n .TWO { } .b { color: red; }\n ');
271
- });
272
- });
273
-
274
- describe('with keyframes', function () {
275
- beforeEach(function () {
276
- document.head.innerHTML = '\n <style ' + _StyleSheet.SC_ATTR + '=\'keyframe_880\' ' + _StyleSheet.LOCAL_ATTR + '=\'false\'>\n /* sc-component-id: sc-keyframes-keyframe_880 */\n @-webkit-keyframes keyframe_880 {from {opacity: 0;}}@keyframes keyframe_880 {from {opacity: 0;}}\n </style>\n ';
277
- _StyleSheet2.default.reset();
278
- });
279
-
280
- it('should not touch existing styles', function () {
281
- (0, _utils.expectCSSMatches)('\n @-webkit-keyframes keyframe_880 {from {opacity: 0;}}@keyframes keyframe_880 {from {opacity: 0;}}\n ');
282
- });
283
-
284
- it('should not regenerate keyframes', function () {
285
- keyframes(_templateObject11);
286
- (0, _utils.expectCSSMatches)('\n @-webkit-keyframes keyframe_880 {from {opacity: 0;}}@keyframes keyframe_880 {from {opacity: 0;}}\n ');
287
- });
288
-
289
- it('should still inject new keyframes', function () {
290
- keyframes(_templateObject12);
291
- (0, _utils.expectCSSMatches)('\n @-webkit-keyframes keyframe_880 {from {opacity: 0;}}@keyframes keyframe_880 {from {opacity: 0;}}\n @-webkit-keyframes keyframe_144 {from {opacity: 1;}}@keyframes keyframe_144 {from {opacity: 1;}}\n ');
292
- });
293
-
294
- it('should pass the keyframes name along as well', function () {
295
- var fadeIn = keyframes(_templateObject11);
296
- var A = styled.div(_templateObject13, fadeIn);
297
- var fadeOut = keyframes(_templateObject12);
298
- var B = styled.div(_templateObject13, fadeOut);
299
- /* Purposely rendering out of order to make sure the output looks right */
300
- (0, _enzyme.shallow)(_react2.default.createElement(B, null));
301
- (0, _enzyme.shallow)(_react2.default.createElement(A, null));
302
-
303
- (0, _utils.expectCSSMatches)('\n @-webkit-keyframes keyframe_880 {from {opacity: 0;}}@keyframes keyframe_880 {from {opacity: 0;}}\n .sc-a { } .d { -webkit-animation:keyframe_880 1s both; animation:keyframe_880 1s both; }\n @-webkit-keyframes keyframe_144 {from {opacity: 1;}}@keyframes keyframe_144 {from {opacity: 1;}}\n .sc-b { } .c { -webkit-animation:keyframe_144 1s both; animation:keyframe_144 1s both; }\n ');
304
- });
305
- });
306
- });
@@ -1,187 +0,0 @@
1
- 'use strict';
2
-
3
- var _templateObject = _taggedTemplateLiteralLoose(['\n color: red;\n '], ['\n color: red;\n ']),
4
- _templateObject2 = _taggedTemplateLiteralLoose(['\n body { background: papayawhip; }\n '], ['\n body { background: papayawhip; }\n ']),
5
- _templateObject3 = _taggedTemplateLiteralLoose(['\n color: blue;\n '], ['\n color: blue;\n ']),
6
- _templateObject4 = _taggedTemplateLiteralLoose(['html::before { content: \'Before both renders\'; }'], ['html::before { content: \'Before both renders\'; }']),
7
- _templateObject5 = _taggedTemplateLiteralLoose(['html::before { content: \'During first render\'; }'], ['html::before { content: \'During first render\'; }']),
8
- _templateObject6 = _taggedTemplateLiteralLoose(['html::before { content: \'Between renders\'; }'], ['html::before { content: \'Between renders\'; }']),
9
- _templateObject7 = _taggedTemplateLiteralLoose(['html::before { content: \'During second render\'; }'], ['html::before { content: \'During second render\'; }']),
10
- _templateObject8 = _taggedTemplateLiteralLoose(['html::before { content: \'After both renders\'; }'], ['html::before { content: \'After both renders\'; }']),
11
- _templateObject9 = _taggedTemplateLiteralLoose(['\n animation: ', ' 1s both;\n '], ['\n animation: ', ' 1s both;\n ']),
12
- _templateObject10 = _taggedTemplateLiteralLoose(['0% { opacity: 0; }'], ['0% { opacity: 0; }']);
13
-
14
- var _react = require('react');
15
-
16
- var _react2 = _interopRequireDefault(_react);
17
-
18
- var _server = require('react-dom/server');
19
-
20
- var _ServerStyleSheet = require('../models/ServerStyleSheet');
21
-
22
- var _ServerStyleSheet2 = _interopRequireDefault(_ServerStyleSheet);
23
-
24
- var _utils = require('./utils');
25
-
26
- var _injectGlobal2 = require('../constructors/injectGlobal');
27
-
28
- var _injectGlobal3 = _interopRequireDefault(_injectGlobal2);
29
-
30
- var _keyframes2 = require('../constructors/keyframes');
31
-
32
- var _keyframes3 = _interopRequireDefault(_keyframes2);
33
-
34
- var _stringifyRules = require('../utils/stringifyRules');
35
-
36
- var _stringifyRules2 = _interopRequireDefault(_stringifyRules);
37
-
38
- var _css = require('../constructors/css');
39
-
40
- var _css2 = _interopRequireDefault(_css);
41
-
42
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
43
-
44
- function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
45
-
46
- var injectGlobal = (0, _injectGlobal3.default)(_stringifyRules2.default, _css2.default);
47
-
48
- var index = 0;
49
- var keyframes = (0, _keyframes3.default)(function () {
50
- return 'keyframe_' + index++;
51
- }, _stringifyRules2.default, _css2.default);
52
-
53
- var styled = void 0;
54
-
55
- var format = function format(css) {
56
- return (0, _utils.stripWhitespace)(css).replace(/ {/g, "{").replace(/(\*\/|[}>])/g, "$1\n").replace(/\n\s+/g, "\n");
57
- };
58
-
59
- describe('ssr', function () {
60
- beforeEach(function () {
61
- styled = (0, _utils.resetStyled)(true);
62
- });
63
-
64
- it('should extract the CSS in a simple case', function () {
65
- var Heading = styled.h1(_templateObject);
66
-
67
- var sheet = new _ServerStyleSheet2.default();
68
- var html = (0, _server.renderToString)(sheet.collectStyles(_react2.default.createElement(
69
- Heading,
70
- null,
71
- 'Hello SSR!'
72
- )));
73
- var css = format(sheet.getStyleTags());
74
-
75
- expect(html).toEqual('<h1 class="sc-a b" data-reactroot="" data-reactid="1" data-react-checksum="197727696">Hello SSR!</h1>');
76
- expect(css).toEqual(format('\n <style type="text/css" data-styled-components="b" data-styled-components-is-local="true">\n /* sc-component-id: sc-a */\n .sc-a {}\n .b { color: red; }\n\n </style>\n '));
77
- });
78
-
79
- it('should extract both global and local CSS', function () {
80
- injectGlobal(_templateObject2);
81
- var Heading = styled.h1(_templateObject);
82
-
83
- var sheet = new _ServerStyleSheet2.default();
84
- var html = (0, _server.renderToString)(sheet.collectStyles(_react2.default.createElement(
85
- Heading,
86
- null,
87
- 'Hello SSR!'
88
- )));
89
- var css = format(sheet.getStyleTags());
90
-
91
- expect(html).toEqual('<h1 class="sc-a b" data-reactroot="" data-reactid="1" data-react-checksum="197727696">Hello SSR!</h1>');
92
- expect(css).toEqual(format('\n <style type="text/css" data-styled-components="" data-styled-components-is-local="false">\n /* sc-component-id: sc-global-2303210225 */\n body { background: papayawhip; }\n\n </style>\n <style type="text/css" data-styled-components="b" data-styled-components-is-local="true">\n /* sc-component-id: sc-a */\n .sc-a {}\n .b { color: red; }\n\n </style>\n '));
93
- });
94
-
95
- it('should render CSS in the order the components were defined, not rendered', function () {
96
- var ONE = styled.h1.withConfig({ componentId: 'ONE' })(_templateObject);
97
- var TWO = styled.h2.withConfig({ componentId: 'TWO' })(_templateObject3);
98
-
99
- var sheet = new _ServerStyleSheet2.default();
100
- var html = (0, _server.renderToString)(sheet.collectStyles(_react2.default.createElement(
101
- 'div',
102
- null,
103
- _react2.default.createElement(TWO, null),
104
- _react2.default.createElement(ONE, null)
105
- )));
106
- var css = format(sheet.getStyleTags());
107
-
108
- expect(html).toEqual('<div data-reactroot="" data-reactid="1" data-react-checksum="275982144"><h2 class="TWO a" data-reactid="2"></h2><h1 class="ONE b" data-reactid="3"></h1></div>');
109
- expect(css).toEqual(format('\n <style type="text/css" data-styled-components="a b" data-styled-components-is-local="true">\n /* sc-component-id: ONE */\n .ONE {}\n .b {color: red;}\n /* sc-component-id: TWO */\n .TWO {}\n .a {color: blue;}\n\n </style>\n '));
110
- });
111
-
112
- it('should share global styles but keep renders separate', function () {
113
- injectGlobal(_templateObject2);
114
- var PageOne = styled.h1.withConfig({ componentId: 'PageOne' })(_templateObject);
115
- var PageTwo = styled.h2.withConfig({ componentId: 'PageTwo' })(_templateObject3);
116
-
117
- var sheetOne = new _ServerStyleSheet2.default();
118
- var htmlOne = (0, _server.renderToString)(sheetOne.collectStyles(_react2.default.createElement(
119
- PageOne,
120
- null,
121
- 'Camera One!'
122
- )));
123
- var cssOne = format(sheetOne.getStyleTags());
124
-
125
- var sheetTwo = new _ServerStyleSheet2.default();
126
- var htmlTwo = (0, _server.renderToString)(sheetTwo.collectStyles(_react2.default.createElement(
127
- PageTwo,
128
- null,
129
- 'Camera Two!'
130
- )));
131
- var cssTwo = format(sheetTwo.getStyleTags());
132
-
133
- expect(htmlOne).toEqual('<h1 class="PageOne a" data-reactroot="" data-reactid="1" data-react-checksum="2014320521">Camera One!</h1>');
134
- expect(cssOne).toEqual(format('\n <style type="text/css" data-styled-components="" data-styled-components-is-local="false">\n /* sc-component-id: sc-global-2303210225 */\n body { background: papayawhip; }\n </style>\n <style type="text/css" data-styled-components="a" data-styled-components-is-local="true">\n /* sc-component-id: PageOne */\n .PageOne {}\n .a { color: red; }\n </style>\n '));
135
-
136
- expect(htmlTwo).toEqual('<h2 class="PageTwo b" data-reactroot="" data-reactid="1" data-react-checksum="2124224444">Camera Two!</h2>');
137
- expect(cssTwo).toEqual(format('\n <style type="text/css" data-styled-components="" data-styled-components-is-local="false">\n /* sc-component-id: sc-global-2303210225 */\n body { background: papayawhip; }\n </style>\n <style type="text/css" data-styled-components="b" data-styled-components-is-local="true">\n /* sc-component-id: PageTwo */\n .PageTwo {}\n .b { color: blue; }\n </style>\n '));
138
- });
139
-
140
- it('should allow global styles to be injected during rendering', function () {
141
- injectGlobal(_templateObject4);
142
- var PageOne = styled.h1.withConfig({ componentId: 'PageOne' })(_templateObject);
143
- var PageTwo = styled.h2.withConfig({ componentId: 'PageTwo' })(_templateObject3);
144
-
145
- var sheetOne = new _ServerStyleSheet2.default();
146
- var htmlOne = (0, _server.renderToString)(sheetOne.collectStyles(_react2.default.createElement(
147
- PageOne,
148
- null,
149
- 'Camera One!'
150
- )));
151
- injectGlobal(_templateObject5);
152
- var cssOne = format(sheetOne.getStyleTags());
153
-
154
- injectGlobal(_templateObject6);
155
-
156
- var sheetTwo = new _ServerStyleSheet2.default();
157
- injectGlobal(_templateObject7);
158
- var htmlTwo = (0, _server.renderToString)(sheetTwo.collectStyles(_react2.default.createElement(
159
- PageTwo,
160
- null,
161
- 'Camera Two!'
162
- )));
163
- var cssTwo = format(sheetTwo.getStyleTags());
164
-
165
- injectGlobal(_templateObject8);
166
-
167
- expect(htmlOne).toEqual('<h1 class="PageOne a" data-reactroot="" data-reactid="1" data-react-checksum="2014320521">Camera One!</h1>');
168
- expect(cssOne).toEqual(format('\n <style type="text/css" data-styled-components="" data-styled-components-is-local="false">\n /* sc-component-id: sc-global-737874422 */\n html::before { content: \'Before both renders\'; }\n </style>\n <style type="text/css" data-styled-components="a" data-styled-components-is-local="true">\n /* sc-component-id: PageOne */\n .PageOne {}\n .a { color: red; }\n </style>\n <style type="text/css" data-styled-components="" data-styled-components-is-local="false">\n /* sc-component-id: sc-global-2914197427 */\n html::before { content: \'During first render\'; }\n </style>\n '));
169
-
170
- expect(htmlTwo).toEqual('<h2 class="PageTwo b" data-reactroot="" data-reactid="1" data-react-checksum="2124224444">Camera Two!</h2>');
171
- expect(cssTwo).toEqual(format('\n <style type="text/css" data-styled-components="" data-styled-components-is-local="false">\n /* sc-component-id: sc-global-737874422 */\n html::before { content: \'Before both renders\'; }\n </style>\n <style type="text/css" data-styled-components="b" data-styled-components-is-local="true">\n /* sc-component-id: PageTwo */\n .PageTwo {}\n .b { color: blue; }\n </style>\n <style type="text/css" data-styled-components="" data-styled-components-is-local="false">\n /* sc-component-id: sc-global-2914197427 */\n html::before { content: \'During first render\'; }\n /* sc-component-id: sc-global-1207956261 */\n html::before { content: \'Between renders\'; }\n /* sc-component-id: sc-global-3990873394 */\n html::before { content: \'During second render\'; }\n </style>\n '));
172
- });
173
-
174
- it('should dispatch global styles to each ServerStyleSheet', function () {
175
- injectGlobal(_templateObject2);
176
- var Header = styled.h1.withConfig({ componentId: 'Header' })(_templateObject9, function (props) {
177
- return props.animation;
178
- });
179
-
180
- var sheet = new _ServerStyleSheet2.default();
181
- var html = (0, _server.renderToString)(sheet.collectStyles(_react2.default.createElement(Header, { animation: keyframes(_templateObject10) })));
182
- var css = format(sheet.getStyleTags());
183
-
184
- expect(html).toEqual('<h1 class="Header a" data-reactroot="" data-reactid="1" data-react-checksum="1829114759"></h1>');
185
- expect(css).toEqual(format('\n <style type="text/css" data-styled-components="" data-styled-components-is-local="false">\n /* sc-component-id: sc-global-2303210225 */\n body { background: papayawhip; }\n </style>\n <style type="text/css" data-styled-components="a" data-styled-components-is-local="true">\n /* sc-component-id: Header */\n .Header {}\n .a { -webkit-animation:keyframe_0 1s both; animation:keyframe_0 1s both; }\n /* sc-component-id: sc-keyframes-keyframe_0 */\n @-webkit-keyframes keyframe_0 {0% {opacity: 0;}}@keyframes keyframe_0 {0% {opacity: 0;}}\n </style>\n '));
186
- });
187
- });
@@ -1,146 +0,0 @@
1
- 'use strict';
2
-
3
- var _templateObject = _taggedTemplateLiteralLoose(['\n ', '\n '], ['\n ', '\n ']),
4
- _templateObject2 = _taggedTemplateLiteralLoose(['\n ', '\n ', '\n '], ['\n ', '\n ', '\n ']),
5
- _templateObject3 = _taggedTemplateLiteralLoose(['\n ', '\n '], ['\n ', '\n ']);
6
-
7
- var _react = require('react');
8
-
9
- var _react2 = _interopRequireDefault(_react);
10
-
11
- var _enzyme = require('enzyme');
12
-
13
- var _utils = require('./utils');
14
-
15
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
16
-
17
- function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
18
-
19
- var styled = void 0;
20
-
21
- describe('with styles', function () {
22
- /**
23
- * Make sure the setup is the same for every test
24
- */
25
- beforeEach(function () {
26
- styled = (0, _utils.resetStyled)();
27
- });
28
-
29
- it('should append a style', function () {
30
- var rule = 'color: blue;';
31
- var Comp = styled.div(_templateObject, rule);
32
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
33
- (0, _utils.expectCSSMatches)('.sc-a {} .b { color: blue; }');
34
- });
35
-
36
- it('should append multiple styles', function () {
37
- var rule1 = 'color: blue;';
38
- var rule2 = 'background: red;';
39
- var Comp = styled.div(_templateObject2, rule1, rule2);
40
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
41
- (0, _utils.expectCSSMatches)('.sc-a {} .b { color: blue; background: red; }');
42
- });
43
-
44
- it('should handle inline style objects', function () {
45
- var rule1 = {
46
- backgroundColor: 'blue'
47
- };
48
- var Comp = styled.div(_templateObject, rule1);
49
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
50
- (0, _utils.expectCSSMatches)('.sc-a {} .b { background-color: blue; }');
51
- });
52
-
53
- it('should handle inline style objects with media queries', function () {
54
- var rule1 = {
55
- backgroundColor: 'blue',
56
- '@media screen and (min-width: 250px)': {
57
- backgroundColor: 'red'
58
- }
59
- };
60
- var Comp = styled.div(_templateObject, rule1);
61
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
62
- (0, _utils.expectCSSMatches)('.sc-a {} .b { background-color: blue; } @media screen and (min-width: 250px) { .b { background-color: red; } }');
63
- });
64
-
65
- it('should handle inline style objects with pseudo selectors', function () {
66
- var rule1 = {
67
- backgroundColor: 'blue',
68
- '&:hover': {
69
- textDecoration: 'underline'
70
- }
71
- };
72
- var Comp = styled.div(_templateObject3, rule1);
73
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
74
- (0, _utils.expectCSSMatches)('.sc-a {} .b { background-color: blue; } .b:hover { -webkit-text-decoration: underline; text-decoration: underline; }');
75
- });
76
-
77
- it('should handle inline style objects with pseudo selectors', function () {
78
- var rule1 = {
79
- backgroundColor: 'blue',
80
- '&:hover': {
81
- textDecoration: 'underline'
82
- }
83
- };
84
- var Comp = styled.div(_templateObject3, rule1);
85
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
86
- (0, _utils.expectCSSMatches)('.sc-a {} .b { background-color: blue; } .b:hover { -webkit-text-decoration: underline; text-decoration: underline; }');
87
- });
88
-
89
- it('should handle inline style objects with nesting', function () {
90
- var rule1 = {
91
- backgroundColor: 'blue',
92
- '> h1': {
93
- color: 'white'
94
- }
95
- };
96
- var Comp = styled.div(_templateObject3, rule1);
97
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
98
- (0, _utils.expectCSSMatches)('.sc-a {} .b { background-color: blue; } .b > h1 { color: white; }');
99
- });
100
-
101
- it('should handle inline style objects with contextual selectors', function () {
102
- var rule1 = {
103
- backgroundColor: 'blue',
104
- 'html.something &': {
105
- color: 'white'
106
- }
107
- };
108
- var Comp = styled.div(_templateObject3, rule1);
109
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
110
- (0, _utils.expectCSSMatches)('.sc-a {} .b { background-color: blue; } html.something .b { color: white; }');
111
- });
112
-
113
- it('should inject styles of multiple components', function () {
114
- var firstRule = 'background: blue;';
115
- var secondRule = 'background: red;';
116
- var FirstComp = styled.div(_templateObject, firstRule);
117
- var SecondComp = styled.div(_templateObject, secondRule);
118
-
119
- (0, _enzyme.shallow)(_react2.default.createElement(FirstComp, null));
120
- (0, _enzyme.shallow)(_react2.default.createElement(SecondComp, null));
121
-
122
- (0, _utils.expectCSSMatches)('.sc-a {} .c { background: blue; } .sc-b {} .d { background: red; }');
123
- });
124
-
125
- it('should inject styles of multiple components based on creation, not rendering order', function () {
126
- var firstRule = 'content: "first rule";';
127
- var secondRule = 'content: "second rule";';
128
- var FirstComp = styled.div(_templateObject, firstRule);
129
- var SecondComp = styled.div(_templateObject, secondRule);
130
-
131
- // Switch rendering order, shouldn't change injection order
132
- (0, _enzyme.shallow)(_react2.default.createElement(SecondComp, null));
133
- (0, _enzyme.shallow)(_react2.default.createElement(FirstComp, null));
134
-
135
- // Classes _do_ get generated in the order of rendering but that's ok
136
- (0, _utils.expectCSSMatches)('\n .sc-a {}\n .d { content: "first rule"; }\n .sc-b {}\n .c { content: "second rule"; }\n ');
137
- });
138
-
139
- it('should strip a JS-style (invalid) comment in the styles', function () {
140
- var comment = '// This is an invalid comment';
141
- var rule = 'color: blue;';
142
- var Comp = styled.div(_templateObject2, comment, rule);
143
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
144
- (0, _utils.expectCSSMatches)('\n .sc-a {}\n .b {\n color: blue;\n }\n ');
145
- });
146
- });