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,267 +0,0 @@
1
- 'use strict';
2
-
3
- var _templateObject = _taggedTemplateLiteralLoose([''], ['']),
4
- _templateObject2 = _taggedTemplateLiteralLoose(['\n color: blue;\n '], ['\n color: blue;\n ']),
5
- _templateObject3 = _taggedTemplateLiteralLoose(['color: red;'], ['color: red;']),
6
- _templateObject4 = _taggedTemplateLiteralLoose(['color: blue;'], ['color: blue;']);
7
-
8
- var _react = require('react');
9
-
10
- var _react2 = _interopRequireDefault(_react);
11
-
12
- var _enzyme = require('enzyme');
13
-
14
- var _utils = require('./utils');
15
-
16
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
17
-
18
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
-
20
- function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; }
21
-
22
- function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; }
23
-
24
- function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
25
-
26
- var styled = void 0;
27
-
28
- describe('basic', function () {
29
- /**
30
- * Make sure the setup is the same for every test
31
- */
32
- beforeEach(function () {
33
- styled = (0, _utils.resetStyled)();
34
- });
35
-
36
- it('should not throw an error when called', function () {
37
- styled.div(_templateObject);
38
- });
39
-
40
- it('should throw a meaningful error when called with null', function () {
41
- var invalidComps = [undefined, null, 123, []];
42
- invalidComps.forEach(function (comp) {
43
- expect(function () {
44
- // $FlowInvalidInputTest
45
- var Comp = styled(comp);
46
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
47
- // $FlowInvalidInputTest
48
- }).toThrow('Cannot create styled-component for component: ' + comp);
49
- });
50
- });
51
-
52
- it('should not inject anything by default', function () {
53
- styled.div(_templateObject);
54
- (0, _utils.expectCSSMatches)('');
55
- });
56
-
57
- it('should inject component class when rendered even if no styles are passed', function () {
58
- var Comp = styled.div(_templateObject);
59
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
60
- (0, _utils.expectCSSMatches)('.sc-a {}');
61
- });
62
-
63
- it('should inject styles', function () {
64
- var Comp = styled.div(_templateObject2);
65
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
66
- (0, _utils.expectCSSMatches)('.sc-a { } .b { color: blue; }');
67
- });
68
-
69
- it('should inject only once for a styled component, no matter how often it\'s mounted', function () {
70
- var Comp = styled.div(_templateObject2);
71
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
72
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
73
- (0, _utils.expectCSSMatches)('.sc-a {} .b { color: blue; }');
74
- });
75
-
76
- it('Should have the correct styled(component) displayName', function () {
77
- var CompWithoutName = function CompWithoutName() {
78
- return function () {
79
- return _react2.default.createElement('div', null);
80
- };
81
- };
82
-
83
- var StyledTag = styled.div(_templateObject);
84
- expect(StyledTag.displayName).toBe('styled.div');
85
-
86
- var CompWithName = function CompWithName() {
87
- return _react2.default.createElement('div', null);
88
- };
89
- CompWithName.displayName = null;
90
- var StyledCompWithName = styled(CompWithName)(_templateObject);
91
- expect(StyledCompWithName.displayName).toBe('Styled(CompWithName)');
92
-
93
- var CompWithDisplayName = CompWithoutName();
94
- CompWithDisplayName.displayName = 'displayName';
95
- var StyledCompWithDisplayName = styled(CompWithDisplayName)(_templateObject);
96
- expect(StyledCompWithDisplayName.displayName).toBe('Styled(displayName)');
97
-
98
- var CompWithBoth = function CompWithBoth() {
99
- return _react2.default.createElement('div', null);
100
- };
101
- CompWithBoth.displayName = 'displayName';
102
- var StyledCompWithBoth = styled(CompWithBoth)(_templateObject);
103
- expect(StyledCompWithBoth.displayName).toBe('Styled(displayName)');
104
-
105
- var CompWithNothing = CompWithoutName();
106
- CompWithNothing.displayName = null;
107
- var StyledCompWithNothing = styled(CompWithNothing)(_templateObject);
108
- expect(StyledCompWithNothing.displayName).toBe('Styled(Component)');
109
- });
110
-
111
- describe('jsdom tests', function () {
112
- it('should pass the ref to the component', function () {
113
- var Comp = styled.div(_templateObject);
114
-
115
- var Wrapper = function (_Component) {
116
- _inherits(Wrapper, _Component);
117
-
118
- function Wrapper() {
119
- var _temp, _this, _ret;
120
-
121
- _classCallCheck(this, Wrapper);
122
-
123
- for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) {
124
- args[_key] = arguments[_key];
125
- }
126
-
127
- return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.innerRef = function (comp) {
128
- _this.testRef = comp;
129
- }, _temp), _possibleConstructorReturn(_this, _ret);
130
- }
131
-
132
- Wrapper.prototype.render = function render() {
133
- return _react2.default.createElement(Comp, { innerRef: this.innerRef });
134
- };
135
-
136
- return Wrapper;
137
- }(_react.Component);
138
-
139
- var wrapper = (0, _enzyme.mount)(_react2.default.createElement(Wrapper, null));
140
- var component = wrapper.find(Comp).first();
141
-
142
- // $FlowFixMe
143
- expect(wrapper.node.testRef).toBe(component.getDOMNode());
144
- expect(component.find('div').prop('innerRef')).toBeFalsy();
145
- });
146
-
147
- var InnerComponent = function (_Component2) {
148
- _inherits(InnerComponent, _Component2);
149
-
150
- function InnerComponent() {
151
- _classCallCheck(this, InnerComponent);
152
-
153
- return _possibleConstructorReturn(this, _Component2.apply(this, arguments));
154
- }
155
-
156
- InnerComponent.prototype.render = function render() {
157
- return null;
158
- };
159
-
160
- return InnerComponent;
161
- }(_react.Component);
162
-
163
- it('should not leak the innerRef prop to the wrapped child', function () {
164
- var OuterComponent = styled(InnerComponent)(_templateObject);
165
-
166
- var Wrapper = function (_Component3) {
167
- _inherits(Wrapper, _Component3);
168
-
169
- function Wrapper() {
170
- _classCallCheck(this, Wrapper);
171
-
172
- return _possibleConstructorReturn(this, _Component3.apply(this, arguments));
173
- }
174
-
175
- Wrapper.prototype.render = function render() {
176
- var _this4 = this;
177
-
178
- return _react2.default.createElement(OuterComponent, { innerRef: function innerRef(comp) {
179
- _this4.testRef = comp;
180
- } });
181
- };
182
-
183
- return Wrapper;
184
- }(_react.Component);
185
-
186
- var wrapper = (0, _enzyme.mount)(_react2.default.createElement(Wrapper, null));
187
- var innerComponent = wrapper.find(InnerComponent).first();
188
-
189
- // $FlowFixMe
190
- expect(wrapper.node.testRef).toBe(innerComponent.node);
191
- expect(innerComponent.prop('innerRef')).toBeFalsy();
192
- });
193
-
194
- it('should pass the full className to the wrapped child', function () {
195
- var OuterComponent = styled(InnerComponent)(_templateObject);
196
-
197
- var Wrapper = function (_Component4) {
198
- _inherits(Wrapper, _Component4);
199
-
200
- function Wrapper() {
201
- _classCallCheck(this, Wrapper);
202
-
203
- return _possibleConstructorReturn(this, _Component4.apply(this, arguments));
204
- }
205
-
206
- Wrapper.prototype.render = function render() {
207
- return _react2.default.createElement(OuterComponent, { className: 'test' });
208
- };
209
-
210
- return Wrapper;
211
- }(_react.Component);
212
-
213
- var wrapper = (0, _enzyme.mount)(_react2.default.createElement(Wrapper, null));
214
- expect(wrapper.find(InnerComponent).prop('className')).toBe('test sc-a b');
215
- });
216
-
217
- it('should pass the innerRef to the wrapped styled component', function () {
218
- var InnerComponent = styled.div(_templateObject);
219
- var OuterComponent = styled(InnerComponent)(_templateObject);
220
-
221
- var Wrapper = function (_Component5) {
222
- _inherits(Wrapper, _Component5);
223
-
224
- function Wrapper() {
225
- var _temp2, _this6, _ret2;
226
-
227
- _classCallCheck(this, Wrapper);
228
-
229
- for (var _len2 = arguments.length, args = Array(_len2), _key2 = 0; _key2 < _len2; _key2++) {
230
- args[_key2] = arguments[_key2];
231
- }
232
-
233
- return _ret2 = (_temp2 = (_this6 = _possibleConstructorReturn(this, _Component5.call.apply(_Component5, [this].concat(args))), _this6), _this6.innerRef = function (comp) {
234
- _this6.testRef = comp;
235
- }, _temp2), _possibleConstructorReturn(_this6, _ret2);
236
- }
237
-
238
- Wrapper.prototype.render = function render() {
239
- return _react2.default.createElement(OuterComponent, { innerRef: this.innerRef });
240
- };
241
-
242
- return Wrapper;
243
- }(_react.Component);
244
-
245
- var wrapper = (0, _enzyme.mount)(_react2.default.createElement(Wrapper, null));
246
- var innerComponent = wrapper.find(InnerComponent).first();
247
- var outerComponent = wrapper.find(OuterComponent).first();
248
-
249
- // $FlowFixMe
250
- expect(wrapper.node.testRef).toBe(innerComponent.getDOMNode());
251
-
252
- // $FlowFixMe
253
- expect(innerComponent.prop('innerRef')).toBe(wrapper.node.innerRef);
254
- });
255
-
256
- it('should respect the order of StyledComponent creation for CSS ordering', function () {
257
- var FirstComponent = styled.div(_templateObject3);
258
- var SecondComponent = styled.div(_templateObject4);
259
-
260
- // NOTE: We're mounting second before first and check if we're breaking their order
261
- (0, _enzyme.shallow)(_react2.default.createElement(SecondComponent, null));
262
- (0, _enzyme.shallow)(_react2.default.createElement(FirstComponent, null));
263
-
264
- (0, _utils.expectCSSMatches)('.sc-a {} .d { color: red; } .sc-b {} .c { color: blue; }');
265
- });
266
- });
267
- });
@@ -1,43 +0,0 @@
1
- 'use strict';
2
-
3
- var _templateObject = _taggedTemplateLiteralLoose(['\n transition: opacity 0.3s;\n '], ['\n transition: opacity 0.3s;\n ']),
4
- _templateObject2 = _taggedTemplateLiteralLoose(['\n display: flex;\n flex-direction: column;\n align-items: center;\n '], ['\n display: flex;\n flex-direction: column;\n align-items: center;\n ']),
5
- _templateObject3 = _taggedTemplateLiteralLoose(['\n --custom-prop: some-val;\n '], ['\n --custom-prop: some-val;\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('css features', function () {
22
- beforeEach(function () {
23
- styled = (0, _utils.resetStyled)();
24
- });
25
-
26
- it('should add vendor prefixes in the right order', function () {
27
- var Comp = styled.div(_templateObject);
28
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
29
- (0, _utils.expectCSSMatches)('.sc-a {} .b { -webkit-transition: opacity 0.3s; transition: opacity 0.3s; }');
30
- });
31
-
32
- it('should add vendor prefixes for display', function () {
33
- var Comp = styled.div(_templateObject2);
34
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
35
- (0, _utils.expectCSSMatches)('\n .sc-a {}\n .b {\n display: -webkit-box; display: -webkit-flex; display: -ms-flexbox; display: flex; -webkit-flex-direction: column; -ms-flex-direction: column; flex-direction: column; -webkit-align-items: center; -webkit-box-align: center; -ms-flex-align: center; align-items: center;\n }\n ');
36
- });
37
-
38
- it('should pass through custom properties', function () {
39
- var Comp = styled.div(_templateObject3);
40
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
41
- (0, _utils.expectCSSMatches)('.sc-a {} .b { --custom-prop: some-val; }');
42
- });
43
- });
@@ -1,90 +0,0 @@
1
- 'use strict';
2
-
3
- var _templateObject = _taggedTemplateLiteralLoose([''], ['']);
4
-
5
- var _react = require('react');
6
-
7
- var _react2 = _interopRequireDefault(_react);
8
-
9
- var _enzyme = require('enzyme');
10
-
11
- var _utils = require('./utils');
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
16
-
17
- var styled = void 0;
18
-
19
- describe('expanded api', function () {
20
- /**
21
- * Make sure the setup is the same for every test
22
- */
23
- beforeEach(function () {
24
- styled = (0, _utils.resetStyled)();
25
- });
26
-
27
- describe('displayName', function () {
28
- it('should be auto-generated if none passed', function () {
29
- var Comp = styled.div(_templateObject);
30
- expect(Comp.displayName).toBe('styled.div');
31
- });
32
-
33
- it('should be attached if supplied', function () {
34
- var Comp = styled.div.withConfig({ displayName: 'Comp' })(_templateObject);
35
- expect(Comp.displayName).toBe('Comp');
36
- });
37
- });
38
-
39
- describe('componentId', function () {
40
- it('should be generated as "sc" + hash', function () {
41
- var Comp = styled.div(_templateObject);
42
- var Comp2 = styled.div(_templateObject);
43
- expect(Comp.styledComponentId).toBe('sc-a');
44
- expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).prop('className')).toMatch(/sc-a/);
45
- expect(Comp2.styledComponentId).toBe('sc-b');
46
- expect((0, _enzyme.shallow)(_react2.default.createElement(Comp2, null)).prop('className')).toMatch(/sc-b/);
47
- });
48
-
49
- it('should be generated from displayName + hash', function () {
50
- var Comp = styled.div.withConfig({ displayName: 'Comp' })(_templateObject);
51
- var Comp2 = styled.div.withConfig({ displayName: 'Comp2' })(_templateObject);
52
- expect(Comp.styledComponentId).toBe('Comp-a');
53
- expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).prop('className')).toMatch(/Comp-a/);
54
- expect(Comp2.styledComponentId).toBe('Comp2-b');
55
- expect((0, _enzyme.shallow)(_react2.default.createElement(Comp2, null)).prop('className')).toMatch(/Comp2-b/);
56
- });
57
-
58
- it('should be attached if passed in', function () {
59
- var Comp = styled.div.withConfig({ componentId: 'LOLOMG' })(_templateObject);
60
- var Comp2 = styled.div.withConfig({ componentId: 'OMGLOL' })(_templateObject);
61
- expect(Comp.styledComponentId).toBe('LOLOMG');
62
- expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).prop('className')).toMatch(/LOLOMG/);
63
- expect(Comp2.styledComponentId).toBe('OMGLOL');
64
- expect((0, _enzyme.shallow)(_react2.default.createElement(Comp2, null)).prop('className')).toMatch(/OMGLOL/);
65
- });
66
-
67
- it('should be combined with displayName if both passed in', function () {
68
- var Comp = styled.div.withConfig({ displayName: 'Comp', componentId: 'LOLOMG' })(_templateObject);
69
- var Comp2 = styled.div.withConfig({ displayName: 'Comp2', componentId: 'OMGLOL' })(_templateObject);
70
- expect(Comp.styledComponentId).toBe('Comp-LOLOMG');
71
- expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).prop('className')).toMatch(/Comp-LOLOMG/);
72
- expect(Comp2.styledComponentId).toBe('Comp2-OMGLOL');
73
- expect((0, _enzyme.shallow)(_react2.default.createElement(Comp2, null)).prop('className')).toMatch(/Comp2-OMGLOL/);
74
- });
75
- });
76
-
77
- describe('chaining', function () {
78
- it('should merge the options strings', function () {
79
- var Comp = styled.div.withConfig({ componentId: 'id-1' }).withConfig({ displayName: 'dn-2' })(_templateObject);
80
- expect(Comp.displayName).toBe('dn-2');
81
- expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).prop('className')).toBe('dn-2-id-1 a');
82
- });
83
-
84
- it('should keep the last value passed in when merging', function () {
85
- var Comp = styled.div.withConfig({ displayName: 'dn-2', componentId: 'id-3' }).withConfig({ displayName: 'dn-5', componentId: 'id-4' })(_templateObject);
86
- expect(Comp.displayName).toBe('dn-5');
87
- expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).prop('className')).toBe('dn-5-id-4 a');
88
- });
89
- });
90
- });
@@ -1,198 +0,0 @@
1
- 'use strict';
2
-
3
- var _templateObject = _taggedTemplateLiteralLoose([''], ['']),
4
- _templateObject2 = _taggedTemplateLiteralLoose(['color: blue;'], ['color: blue;']),
5
- _templateObject3 = _taggedTemplateLiteralLoose(['color: red;'], ['color: red;']),
6
- _templateObject4 = _taggedTemplateLiteralLoose(['\n color: blue;\n > h1 { font-size: 4rem; }\n '], ['\n color: blue;\n > h1 { font-size: 4rem; }\n ']),
7
- _templateObject5 = _taggedTemplateLiteralLoose(['\n color: ', ';\n '], ['\n color: ', ';\n ']),
8
- _templateObject6 = _taggedTemplateLiteralLoose(['background-color: green;'], ['background-color: green;']),
9
- _templateObject7 = _taggedTemplateLiteralLoose(['color: green;'], ['color: green;']),
10
- _templateObject8 = _taggedTemplateLiteralLoose(['color:red;'], ['color:red;']),
11
- _templateObject9 = _taggedTemplateLiteralLoose(['\n background-color: red;\n '], ['\n background-color: red;\n ']),
12
- _templateObject10 = _taggedTemplateLiteralLoose(['\n color: blue;\n '], ['\n color: blue;\n ']),
13
- _templateObject11 = _taggedTemplateLiteralLoose(['\n border: 2px solid black;\n '], ['\n border: 2px solid black;\n ']),
14
- _templateObject12 = _taggedTemplateLiteralLoose(['\n border-width: 10;\n '], ['\n border-width: 10;\n ']),
15
- _templateObject13 = _taggedTemplateLiteralLoose(['\n color: red;\n '], ['\n color: red;\n ']),
16
- _templateObject14 = _taggedTemplateLiteralLoose(['\n color: green;\n '], ['\n color: green;\n ']);
17
-
18
- var _react = require('react');
19
-
20
- var _react2 = _interopRequireDefault(_react);
21
-
22
- var _propTypes = require('prop-types');
23
-
24
- var _propTypes2 = _interopRequireDefault(_propTypes);
25
-
26
- var _enzyme = require('enzyme');
27
-
28
- var _utils = require('./utils');
29
-
30
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
31
-
32
- function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
33
-
34
- var styled = void 0;
35
-
36
- describe('extending', function () {
37
- /**
38
- * Make sure the setup is the same for every test
39
- */
40
- beforeEach(function () {
41
- styled = (0, _utils.resetStyled)();
42
- });
43
-
44
- it('should generate empty classes with no styles', function () {
45
- var Parent = styled.div(_templateObject);
46
- var Child = Parent.extend(_templateObject);
47
-
48
- (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
49
- (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
50
-
51
- (0, _utils.expectCSSMatches)('.sc-a {} .sc-b {}');
52
- });
53
-
54
- it('should attach styles to both classes if only parent has styles', function () {
55
- var Parent = styled.div(_templateObject2);
56
- var Child = Parent.extend(_templateObject);
57
-
58
- (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
59
- (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
60
-
61
- (0, _utils.expectCSSMatches)('.sc-a {} .c { color: blue; } .sc-b {} .d { color: blue; }');
62
- });
63
-
64
- it('should attach styles to child class if only child has styles', function () {
65
- var Parent = styled.div(_templateObject);
66
- var Child = Parent.extend(_templateObject2);
67
-
68
- (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
69
- (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
70
-
71
- (0, _utils.expectCSSMatches)('.sc-a {} .sc-b {} .d { color: blue; }');
72
- });
73
-
74
- it('should generate a class for the child with the rules of the parent', function () {
75
- var Parent = styled.div(_templateObject2);
76
- var Child = Parent.extend(_templateObject3);
77
-
78
- (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
79
-
80
- (0, _utils.expectCSSMatches)('.sc-b {} .c { color: blue;color: red; }');
81
- });
82
-
83
- it('should generate different classes for both parent and child', function () {
84
- var Parent = styled.div(_templateObject2);
85
- var Child = Parent.extend(_templateObject3);
86
-
87
- (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
88
- (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
89
-
90
- (0, _utils.expectCSSMatches)('.sc-a {} .c { color: blue; } .sc-b {} .d { color: blue;color: red; }');
91
- });
92
-
93
- it('should copy nested rules to the child', function () {
94
- var Parent = styled.div(_templateObject4);
95
- var Child = Parent.extend(_templateObject3);
96
-
97
- (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
98
- (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
99
-
100
- (0, _utils.expectCSSMatches)('\n .sc-a {}\n .c{ color: blue; }\n .c > h1{ font-size: 4rem; }\n .sc-b {}\n .d { color: blue; color: red; }\n .d > h1 { font-size: 4rem; }\n ');
101
- });
102
-
103
- it('should keep default props from parent', function () {
104
- var Parent = styled.div(_templateObject5, function (props) {
105
- return props.color;
106
- });
107
- Parent.defaultProps = {
108
- color: 'red'
109
- };
110
-
111
- var Child = Parent.extend(_templateObject6);
112
-
113
- (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
114
- (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
115
-
116
- (0, _utils.expectCSSMatches)('\n .sc-a {} .c { color: red; }\n .sc-b {} .d { color: red; background-color: green; }\n ');
117
- });
118
-
119
- it('should keep prop types from parent', function () {
120
- var Parent = styled.div(_templateObject5, function (props) {
121
- return props.color;
122
- });
123
- Parent.propTypes = {
124
- color: _propTypes2.default.string
125
- };
126
-
127
- var Child = Parent.extend(_templateObject6);
128
-
129
- expect(Child.propTypes).toEqual(Parent.propTypes);
130
- });
131
-
132
- it('should keep custom static member from parent', function () {
133
- var Parent = styled.div(_templateObject3);
134
-
135
- Parent.fetchData = function () {
136
- return 1;
137
- };
138
-
139
- var Child = Parent.extend(_templateObject7);
140
-
141
- expect(Child.fetchData).toBeTruthy();
142
- expect(Child.fetchData()).toEqual(1);
143
- });
144
-
145
- it('should keep static member in triple inheritance', function () {
146
- var GrandParent = styled.div(_templateObject3);
147
- GrandParent.fetchData = function () {
148
- return 1;
149
- };
150
-
151
- var Parent = GrandParent.extend(_templateObject3);
152
- var Child = Parent.extend(_templateObject8);
153
-
154
- expect(Child.fetchData).toBeTruthy();
155
- expect(Child.fetchData()).toEqual(1);
156
- });
157
-
158
- it('should keep styles in >= 3 inheritances', function () {
159
- var GrandGrandParent = styled.div(_templateObject9);
160
-
161
- var GrandParent = GrandGrandParent.extend(_templateObject10);
162
-
163
- var Parent = GrandParent.extend(_templateObject11);
164
-
165
- var Child = Parent.extend(_templateObject12);
166
-
167
- (0, _enzyme.shallow)(_react2.default.createElement(GrandGrandParent, null));
168
- (0, _enzyme.shallow)(_react2.default.createElement(GrandParent, null));
169
- (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
170
- (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
171
-
172
- (0, _utils.expectCSSMatches)('\n .sc-a { }\n .e { background-color: red; }\n .sc-b { }\n .f { background-color: red; color: blue; }\n .sc-c { }\n .g { background-color: red; color: blue; border: 2px solid black; }\n .sc-d { }\n .h { background-color: red; color: blue; border: 2px solid black; border-width: 10; }\n ');
173
- });
174
-
175
- it('should allow changing component', function () {
176
- var Parent = styled.div(_templateObject3);
177
- var Child = Parent.withComponent('span');
178
-
179
- expect((0, _enzyme.shallow)(_react2.default.createElement(Child, null)).html()).toEqual('<span class="sc-b c"></span>');
180
- });
181
-
182
- it('should allow changing component and extending', function () {
183
- var Parent = styled.div(_templateObject13);
184
- var Child = Parent.withComponent('span').extend(_templateObject14);
185
-
186
- expect((0, _enzyme.shallow)(_react2.default.createElement(Child, null)).html()).toEqual('<span class="sc-c d"></span>');
187
- (0, _utils.expectCSSMatches)('\n .sc-c {} .d { color: red; color: green; }\n ');
188
- });
189
-
190
- it('should allow changing component and adding attributes', function () {
191
- var Parent = styled.button(_templateObject13);
192
- var Child = Parent.withComponent('a').extend.attrs({
193
- href: '/test'
194
- })(_templateObject);
195
-
196
- expect((0, _enzyme.shallow)(_react2.default.createElement(Child, null)).html()).toEqual('<a href="/test" class="sc-c d"></a>');
197
- });
198
- });
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
3
- var _templateObject = _taggedTemplateLiteralLoose(['\n color: blue;\n font-weight: light;\n '], ['\n color: blue;\n font-weight: light;\n ']),
4
- _templateObject2 = _taggedTemplateLiteralLoose(['\n padding: 1rem;\n > ', ' {\n font-weight: bold;\n }\n '], ['\n padding: 1rem;\n > ', ' {\n font-weight: bold;\n }\n ']);
5
-
6
- var _react = require('react');
7
-
8
- var _react2 = _interopRequireDefault(_react);
9
-
10
- var _enzyme = require('enzyme');
11
-
12
- var _utils = require('./utils');
13
-
14
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
15
-
16
- function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
17
-
18
- var styled = void 0;
19
-
20
- describe('extending', function () {
21
- /**
22
- * Make sure the setup is the same for every test
23
- */
24
- beforeEach(function () {
25
- styled = (0, _utils.resetStyled)();
26
- });
27
-
28
- it('should let you use another component in a css rule', function () {
29
- var Inner = styled.div(_templateObject);
30
- var Outer = styled.div(_templateObject2, Inner);
31
- (0, _enzyme.shallow)(_react2.default.createElement(Inner, null));
32
- (0, _enzyme.shallow)(_react2.default.createElement(Outer, null));
33
- (0, _utils.expectCSSMatches)('\n .sc-a {}\n .c { color: blue; font-weight: light; }\n .sc-b {}\n .d { padding: 1rem; }\n .d > .sc-a { font-weight: bold; }\n ');
34
- });
35
- });
@@ -1,38 +0,0 @@
1
- 'use strict';
2
-
3
- var _templateObject = _taggedTemplateLiteralLoose(['\n color: ', ';\n '], ['\n color: ', ';\n ']);
4
-
5
- var _react = require('react');
6
-
7
- var _react2 = _interopRequireDefault(_react);
8
-
9
- var _enzyme = require('enzyme');
10
-
11
- var _utils = require('./utils');
12
-
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
14
-
15
- function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
16
-
17
- var styled = void 0;
18
-
19
- describe('props', function () {
20
- beforeEach(function () {
21
- styled = (0, _utils.resetStyled)();
22
- });
23
-
24
- it('should execute interpolations and fall back', function () {
25
- var Comp = styled.div(_templateObject, function (props) {
26
- return props.fg || 'black';
27
- });
28
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
29
- (0, _utils.expectCSSMatches)('.sc-a {} .b { color: black; }');
30
- });
31
- it('should execute interpolations and inject props', function () {
32
- var Comp = styled.div(_templateObject, function (props) {
33
- return props.fg || 'black';
34
- });
35
- (0, _enzyme.shallow)(_react2.default.createElement(Comp, { fg: 'red' }));
36
- (0, _utils.expectCSSMatches)('.sc-a {} .b { color: red; }');
37
- });
38
- });