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.
- package/CHANGELOG.md +31 -1
- package/CODE_OF_CONDUCT.md +1 -1
- package/README.md +12 -67
- package/dist/styled-components.es.js +273 -110
- package/dist/styled-components.js +325 -119
- package/dist/styled-components.min.js +2 -2
- package/lib/hoc/withTheme.js +13 -7
- package/lib/models/BrowserStyleSheet.js +11 -0
- package/lib/models/ComponentStyle.js +45 -2
- package/lib/models/InlineStyle.js +1 -1
- package/lib/models/ServerStyleSheet.js +33 -17
- package/lib/models/StyleSheet.js +9 -0
- package/lib/models/StyledComponent.js +82 -38
- package/lib/models/StyledNativeComponent.js +31 -15
- package/lib/models/ThemeProvider.js +44 -12
- package/lib/native/index.js +1 -1
- package/lib/test/utils.js +5 -2
- package/lib/utils/create-broadcast.js +34 -24
- package/lib/utils/domElements.js +1 -1
- package/lib/utils/flatten.js +4 -1
- package/lib/utils/generateAlphabeticName.js +1 -1
- package/lib/utils/nonce.js +10 -0
- package/lib/utils/once.js +17 -0
- package/package.json +10 -10
- package/src/hoc/withTheme.js +14 -7
- package/src/models/BrowserStyleSheet.js +8 -0
- package/src/models/ComponentStyle.js +42 -2
- package/src/models/InlineStyle.js +1 -1
- package/src/models/ServerStyleSheet.js +27 -12
- package/src/models/StyleSheet.js +9 -0
- package/src/models/StyledComponent.js +81 -26
- package/src/models/StyledNativeComponent.js +30 -10
- package/src/models/ThemeProvider.js +38 -9
- package/src/models/test/ThemeProvider.test.js +7 -8
- package/src/native/index.js +1 -1
- package/src/native/test/native.test.js +14 -0
- package/src/test/__snapshots__/ssr.test.js.snap +147 -0
- package/src/test/expanded-api.test.js +24 -0
- package/src/test/props.test.js +14 -3
- package/src/test/ssr.test.js +90 -123
- package/src/test/styles.test.js +52 -0
- package/src/test/utils.js +5 -2
- package/src/utils/create-broadcast.js +31 -17
- package/src/utils/domElements.js +1 -0
- package/src/utils/flatten.js +16 -6
- package/src/utils/generateAlphabeticName.js +1 -1
- package/src/utils/nonce.js +6 -0
- package/src/utils/once.js +12 -0
- package/typings/styled-components.d.ts +15 -21
- package/typings/tests/issue1068.tsx +226 -0
- package/typings/tests/main-test.tsx +1 -1
- package/typings/tests/string-tags-test.tsx +62 -0
- package/typings/tests/themed-tests/issue1068.tsx +226 -0
- package/typings/tests/themed-tests/mytheme-styled-components.tsx +1 -1
- package/typings/tests/themed-tests/with-theme-test.tsx +2 -1
- package/typings/tests/with-theme-test.tsx +17 -0
- package/lib/constructors/test/injectGlobal.test.js +0 -63
- package/lib/constructors/test/keyframes.test.js +0 -48
- package/lib/constructors/test/styled.test.js +0 -19
- package/lib/models/AbstractStyledComponent.js +0 -43
- package/lib/models/test/ThemeProvider.test.js +0 -200
- package/lib/native/test/native.test.js +0 -290
- package/lib/no-parser/test/basic.test.js +0 -46
- package/lib/no-parser/test/flatten.test.js +0 -125
- package/lib/no-parser/test/keyframes.test.js +0 -45
- package/lib/primitives/test/primitives.test.js +0 -289
- package/lib/test/attrs.test.js +0 -158
- package/lib/test/basic.test.js +0 -267
- package/lib/test/css.test.js +0 -43
- package/lib/test/expanded-api.test.js +0 -90
- package/lib/test/extending.test.js +0 -198
- package/lib/test/overriding.test.js +0 -35
- package/lib/test/props.test.js +0 -38
- package/lib/test/rehydration.test.js +0 -306
- package/lib/test/ssr.test.js +0 -187
- package/lib/test/styles.test.js +0 -146
- package/lib/test/theme.test.js +0 -497
- package/lib/test/warnTooManyClasses.test.js +0 -71
- package/lib/utils/test/extractCompsFromCSS.test.js +0 -46
- package/lib/utils/test/flatten.test.js +0 -109
- package/lib/utils/test/generateAlphabeticName.test.js +0 -14
- package/lib/utils/test/interleave.test.js +0 -22
- package/lib/utils/test/validAttr.test.js +0 -560
- package/src/models/AbstractStyledComponent.js +0 -21
- package/typings/tags.d.ts +0 -137
|
@@ -1,125 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _flatten = require('../flatten');
|
|
4
|
-
|
|
5
|
-
var _flatten2 = _interopRequireDefault(_flatten);
|
|
6
|
-
|
|
7
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
8
|
-
|
|
9
|
-
describe('preparsed flatten without executionContext', function () {
|
|
10
|
-
it('doesnt merge strings', function () {
|
|
11
|
-
expect((0, _flatten2.default)([['foo', 'bar', 'baz']])).toEqual([['foo', 'bar', 'baz']]);
|
|
12
|
-
});
|
|
13
|
-
|
|
14
|
-
it('drops nulls', function () {
|
|
15
|
-
// $FlowInvalidInputTest
|
|
16
|
-
expect((0, _flatten2.default)([['foo', false, 'bar', undefined, 'baz', null]])).toEqual([['foo', 'bar', 'baz']]);
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
it('doesnt drop any numbers', function () {
|
|
20
|
-
expect((0, _flatten2.default)([['foo', 0, 'bar', NaN, 'baz', -1]])).toEqual([['foo', '0', 'bar', 'NaN', 'baz', '-1']]);
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
it('toStrings everything', function () {
|
|
24
|
-
// $FlowInvalidInputTest
|
|
25
|
-
expect((0, _flatten2.default)([[1, true]])).toEqual([['1', 'true']]);
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('hypenates objects', function () {
|
|
29
|
-
var obj = {
|
|
30
|
-
fontSize: '14px',
|
|
31
|
-
WebkitFilter: 'blur(2px)'
|
|
32
|
-
};
|
|
33
|
-
var css = 'font-size: 14px; -webkit-filter: blur(2px);';
|
|
34
|
-
// $FlowFixMe
|
|
35
|
-
expect((0, _flatten2.default)([[obj]])).toEqual([[css]]);
|
|
36
|
-
// $FlowFixMe
|
|
37
|
-
expect((0, _flatten2.default)([['some:thing;', obj, 'something: else;']])).toEqual([['some:thing;', css, 'something: else;']]);
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
it('flattens nested rulesets', function () {
|
|
41
|
-
expect((0, _flatten2.default)([['a', [['c']], 'b']])).toEqual([['a', 'b'], ['c']]);
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
it('flattens double nested rulesets', function () {
|
|
45
|
-
expect((0, _flatten2.default)([['a', [['c', [['d']]]], 'b']])).toEqual([['a', 'b'], ['c'], ['d']]);
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('flattens subarrays', function () {
|
|
49
|
-
expect((0, _flatten2.default)([[1, 2, [3, 4, 5], 'come:on;', 'lets:ride;']])).toEqual([['1', '2', '3', '4', '5', 'come:on;', 'lets:ride;']]);
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
it('defers functions', function () {
|
|
53
|
-
var func = function func() {
|
|
54
|
-
return 'bar';
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
expect((0, _flatten2.default)([['foo', func, 'baz']])).toEqual([['foo', func, 'baz']]);
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
describe('preparsed flatten with executionContext', function () {
|
|
63
|
-
it('merges strings', function () {
|
|
64
|
-
expect((0, _flatten2.default)([['foo', 'bar', 'baz']], {})).toEqual(['foobarbaz']);
|
|
65
|
-
});
|
|
66
|
-
|
|
67
|
-
it('drops nulls', function () {
|
|
68
|
-
// $FlowInvalidInputTest
|
|
69
|
-
expect((0, _flatten2.default)([['foo', false, 'bar', undefined, 'baz', null]], {})).toEqual(['foobarbaz']);
|
|
70
|
-
});
|
|
71
|
-
|
|
72
|
-
it('doesnt drop any numbers', function () {
|
|
73
|
-
expect((0, _flatten2.default)([['foo', 0, 'bar', NaN, 'baz', -1]], {})).toEqual(['foo0barNaNbaz-1']);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('toStrings everything', function () {
|
|
77
|
-
// $FlowInvalidInputTest
|
|
78
|
-
expect((0, _flatten2.default)([[1, true]], {})).toEqual(['1true']);
|
|
79
|
-
});
|
|
80
|
-
|
|
81
|
-
it('hypenates objects', function () {
|
|
82
|
-
var obj = {
|
|
83
|
-
fontSize: '14px',
|
|
84
|
-
WebkitFilter: 'blur(2px)'
|
|
85
|
-
};
|
|
86
|
-
var css = 'font-size: 14px; -webkit-filter: blur(2px);';
|
|
87
|
-
// $FlowFixMe
|
|
88
|
-
expect((0, _flatten2.default)([[obj]], {})).toEqual([css]);
|
|
89
|
-
// $FlowFixMe
|
|
90
|
-
expect((0, _flatten2.default)([['some:thing;', obj, 'something: else;']], {})).toEqual(['some:thing;' + css + 'something: else;']);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('flattens nested rulesets', function () {
|
|
94
|
-
expect((0, _flatten2.default)([['a', [['c']], 'b']], {})).toEqual(['ab', 'c']);
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it('flattens double nested rulesets', function () {
|
|
98
|
-
expect((0, _flatten2.default)([['a', [['c', 'd', [['e', 'f'], ['g', 'h']]]], 'b']], {})).toEqual(['ab', 'cd', 'ef', 'gh']);
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('flattens subarrays', function () {
|
|
102
|
-
expect((0, _flatten2.default)([[1, 2, [3, 4, 5], 'come:on;', 'lets:ride;']], {})).toEqual(['12345come:on;lets:ride;']);
|
|
103
|
-
});
|
|
104
|
-
|
|
105
|
-
it('executes functions', function () {
|
|
106
|
-
var func = function func() {
|
|
107
|
-
return 'bar';
|
|
108
|
-
};
|
|
109
|
-
expect((0, _flatten2.default)([['foo', func, 'baz']], {})).toEqual(['foobarbaz']);
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('resolves rulesets after executing functions', function () {
|
|
113
|
-
var func = function func() {
|
|
114
|
-
return [['add me to the end']];
|
|
115
|
-
};
|
|
116
|
-
expect((0, _flatten2.default)([['foo', func, 'baz']], {})).toEqual(['foobaz', 'add me to the end']);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
it('resolves double nested rulesets after executing functions', function () {
|
|
120
|
-
var func = function func() {
|
|
121
|
-
return [['a', [['b']]]];
|
|
122
|
-
};
|
|
123
|
-
expect((0, _flatten2.default)([['foo', func, 'baz']], {})).toEqual(['foobaz', 'a', 'b']);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _react = require('react');
|
|
4
|
-
|
|
5
|
-
var _react2 = _interopRequireDefault(_react);
|
|
6
|
-
|
|
7
|
-
var _keyframes2 = require('../../constructors/keyframes');
|
|
8
|
-
|
|
9
|
-
var _keyframes3 = _interopRequireDefault(_keyframes2);
|
|
10
|
-
|
|
11
|
-
var _stringifyRules = require('../stringifyRules');
|
|
12
|
-
|
|
13
|
-
var _stringifyRules2 = _interopRequireDefault(_stringifyRules);
|
|
14
|
-
|
|
15
|
-
var _css = require('../css');
|
|
16
|
-
|
|
17
|
-
var _css2 = _interopRequireDefault(_css);
|
|
18
|
-
|
|
19
|
-
var _utils = require('../../test/utils');
|
|
20
|
-
|
|
21
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
22
|
-
|
|
23
|
-
var index = 0;
|
|
24
|
-
|
|
25
|
-
var keyframes = (0, _keyframes3.default)(function () {
|
|
26
|
-
return 'keyframe_' + index++;
|
|
27
|
-
}, _stringifyRules2.default, _css2.default);
|
|
28
|
-
|
|
29
|
-
describe('keyframes', function () {
|
|
30
|
-
beforeEach(function () {
|
|
31
|
-
(0, _utils.resetNoParserStyled)();
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
it('should correctly assemble preprocessed CSS', function () {
|
|
35
|
-
var name = keyframes([
|
|
36
|
-
// $FlowFixMe
|
|
37
|
-
['@-webkit-keyframes '],
|
|
38
|
-
// $FlowFixMe
|
|
39
|
-
[' {from {background-position: 0vw 0px;}to {background-position: 100vw 0px;}} @keyframes '],
|
|
40
|
-
// $FlowFixMe
|
|
41
|
-
[' {from {background-position: 0vw 0px;}to {background-position: 100vw 0px;}}']]);
|
|
42
|
-
|
|
43
|
-
(0, _utils.expectCSSMatches)('@-webkit-keyframes ' + name + ' {from {background-position: 0vw 0px;}to {background-position: 100vw 0px;}} @keyframes ' + name + ' {from {background-position: 0vw 0px;}to {background-position: 100vw 0px;}}');
|
|
44
|
-
});
|
|
45
|
-
});
|
|
@@ -1,289 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _templateObject = _taggedTemplateLiteralLoose([''], ['']),
|
|
4
|
-
_templateObject2 = _taggedTemplateLiteralLoose(['\n padding-top: 10;\n '], ['\n padding-top: 10;\n ']),
|
|
5
|
-
_templateObject3 = _taggedTemplateLiteralLoose(['opacity: 0.9;'], ['opacity: 0.9;']),
|
|
6
|
-
_templateObject4 = _taggedTemplateLiteralLoose(['padding: 10px;'], ['padding: 10px;']),
|
|
7
|
-
_templateObject5 = _taggedTemplateLiteralLoose(['background-color: red;'], ['background-color: red;']),
|
|
8
|
-
_templateObject6 = _taggedTemplateLiteralLoose(['borderWidth: 10;'], ['borderWidth: 10;']);
|
|
9
|
-
|
|
10
|
-
require('react-primitives');
|
|
11
|
-
|
|
12
|
-
var _react = require('react');
|
|
13
|
-
|
|
14
|
-
var _react2 = _interopRequireDefault(_react);
|
|
15
|
-
|
|
16
|
-
var _index = require('../index');
|
|
17
|
-
|
|
18
|
-
var _index2 = _interopRequireDefault(_index);
|
|
19
|
-
|
|
20
|
-
var _enzyme = require('enzyme');
|
|
21
|
-
|
|
22
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
23
|
-
|
|
24
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
25
|
-
|
|
26
|
-
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; }
|
|
27
|
-
|
|
28
|
-
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; }
|
|
29
|
-
|
|
30
|
-
function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
|
|
31
|
-
|
|
32
|
-
// NOTE: These tests are copy pasted from ../native/test/native.test.js
|
|
33
|
-
|
|
34
|
-
describe('primitives', function () {
|
|
35
|
-
it('should not throw an error when called', function () {
|
|
36
|
-
_index2.default.View(_templateObject);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
it('should generate inline styles', function () {
|
|
40
|
-
var Comp = _index2.default.View(_templateObject);
|
|
41
|
-
var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
|
|
42
|
-
var view = wrapper.find('View').first();
|
|
43
|
-
|
|
44
|
-
expect(view.prop('style')).toEqual([{}, undefined]);
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
it('should combine inline styles and the style prop', function () {
|
|
48
|
-
var Comp = _index2.default.View(_templateObject2);
|
|
49
|
-
|
|
50
|
-
var style = { opacity: 0.9 };
|
|
51
|
-
var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, { style: style }));
|
|
52
|
-
var view = wrapper.find('View').first();
|
|
53
|
-
|
|
54
|
-
expect(view.prop('style')).toEqual([{ paddingTop: 10 }, style]);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
describe('extending', function () {
|
|
58
|
-
it('should combine styles of extending components', function () {
|
|
59
|
-
var Parent = _index2.default.View(_templateObject3);
|
|
60
|
-
var Child = Parent.extend(_templateObject4);
|
|
61
|
-
|
|
62
|
-
var parent = (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
|
|
63
|
-
var child = (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
|
|
64
|
-
|
|
65
|
-
expect(parent.find('View').prop('style')).toEqual([{ opacity: 0.9 }, undefined]);
|
|
66
|
-
|
|
67
|
-
expect(child.find('View').prop('style')).toEqual([{
|
|
68
|
-
opacity: 0.9,
|
|
69
|
-
paddingTop: 10,
|
|
70
|
-
paddingRight: 10,
|
|
71
|
-
paddingBottom: 10,
|
|
72
|
-
paddingLeft: 10
|
|
73
|
-
}, undefined]);
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('should combine styles of extending components in >= 3 inheritances', function () {
|
|
77
|
-
var GrandGrandParent = _index2.default.View(_templateObject5);
|
|
78
|
-
var GrandParent = GrandGrandParent.extend(_templateObject6);
|
|
79
|
-
var Parent = GrandParent.extend(_templateObject3);
|
|
80
|
-
var Child = Parent.extend(_templateObject4);
|
|
81
|
-
|
|
82
|
-
var grandGrandParent = (0, _enzyme.shallow)(_react2.default.createElement(GrandGrandParent, null));
|
|
83
|
-
var grandParent = (0, _enzyme.shallow)(_react2.default.createElement(GrandParent, null));
|
|
84
|
-
var parent = (0, _enzyme.shallow)(_react2.default.createElement(Parent, null));
|
|
85
|
-
var child = (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
|
|
86
|
-
|
|
87
|
-
expect(grandGrandParent.find('View').prop('style')).toEqual([{
|
|
88
|
-
backgroundColor: 'red'
|
|
89
|
-
}, undefined]);
|
|
90
|
-
|
|
91
|
-
expect(grandParent.find('View').prop('style')).toEqual([{
|
|
92
|
-
backgroundColor: 'red',
|
|
93
|
-
borderWidth: 10
|
|
94
|
-
}, undefined]);
|
|
95
|
-
|
|
96
|
-
expect(parent.find('View').prop('style')).toEqual([{
|
|
97
|
-
backgroundColor: 'red',
|
|
98
|
-
borderWidth: 10,
|
|
99
|
-
opacity: 0.9
|
|
100
|
-
}, undefined]);
|
|
101
|
-
|
|
102
|
-
expect(child.find('View').prop('style')).toEqual([{
|
|
103
|
-
backgroundColor: 'red',
|
|
104
|
-
borderWidth: 10,
|
|
105
|
-
opacity: 0.9,
|
|
106
|
-
paddingTop: 10,
|
|
107
|
-
paddingRight: 10,
|
|
108
|
-
paddingBottom: 10,
|
|
109
|
-
paddingLeft: 10
|
|
110
|
-
}, undefined]);
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
describe('attrs', function () {
|
|
115
|
-
it('works fine with an empty object', function () {
|
|
116
|
-
var Comp = _index2.default.View.attrs({})(_templateObject);
|
|
117
|
-
var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
|
|
118
|
-
var view = wrapper.find('View').first();
|
|
119
|
-
|
|
120
|
-
expect(view.props()).toEqual({
|
|
121
|
-
style: [{}, undefined]
|
|
122
|
-
});
|
|
123
|
-
});
|
|
124
|
-
|
|
125
|
-
it('passes simple props on', function () {
|
|
126
|
-
var Comp = _index2.default.View.attrs({
|
|
127
|
-
test: true
|
|
128
|
-
})(_templateObject);
|
|
129
|
-
|
|
130
|
-
var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
|
|
131
|
-
var view = wrapper.find('View').first();
|
|
132
|
-
|
|
133
|
-
expect(view.props()).toEqual({
|
|
134
|
-
style: [{}, undefined],
|
|
135
|
-
test: true
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
it('calls an attr-function with context', function () {
|
|
140
|
-
var Comp = _index2.default.View.attrs({
|
|
141
|
-
copy: function copy(props) {
|
|
142
|
-
return props.test;
|
|
143
|
-
}
|
|
144
|
-
})(_templateObject);
|
|
145
|
-
|
|
146
|
-
var test = 'Put that cookie down!';
|
|
147
|
-
var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, { test: test }));
|
|
148
|
-
var view = wrapper.find('View').first();
|
|
149
|
-
|
|
150
|
-
expect(view.props()).toEqual({
|
|
151
|
-
style: [{}, undefined],
|
|
152
|
-
copy: test,
|
|
153
|
-
test: test
|
|
154
|
-
});
|
|
155
|
-
});
|
|
156
|
-
|
|
157
|
-
it('merges multiple calls', function () {
|
|
158
|
-
var Comp = _index2.default.View.attrs({
|
|
159
|
-
first: 'first',
|
|
160
|
-
test: '_'
|
|
161
|
-
}).attrs({
|
|
162
|
-
second: 'second',
|
|
163
|
-
test: 'test'
|
|
164
|
-
})(_templateObject);
|
|
165
|
-
|
|
166
|
-
var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
|
|
167
|
-
var view = wrapper.find('View').first();
|
|
168
|
-
|
|
169
|
-
expect(view.props()).toEqual({
|
|
170
|
-
style: [{}, undefined],
|
|
171
|
-
first: 'first',
|
|
172
|
-
second: 'second',
|
|
173
|
-
test: 'test'
|
|
174
|
-
});
|
|
175
|
-
});
|
|
176
|
-
|
|
177
|
-
it('merges attrs when inheriting SC', function () {
|
|
178
|
-
var Parent = _index2.default.View.attrs({
|
|
179
|
-
first: 'first'
|
|
180
|
-
})(_templateObject);
|
|
181
|
-
|
|
182
|
-
var Child = Parent.extend.attrs({
|
|
183
|
-
second: 'second'
|
|
184
|
-
})(_templateObject);
|
|
185
|
-
|
|
186
|
-
var wrapper = (0, _enzyme.shallow)(_react2.default.createElement(Child, null));
|
|
187
|
-
var view = wrapper.find('View').first();
|
|
188
|
-
|
|
189
|
-
expect(view.props()).toEqual({
|
|
190
|
-
style: [{}, undefined],
|
|
191
|
-
first: 'first',
|
|
192
|
-
second: 'second'
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
});
|
|
196
|
-
|
|
197
|
-
describe('expanded API', function () {
|
|
198
|
-
it('should attach a displayName', function () {
|
|
199
|
-
var Comp = _index2.default.View(_templateObject);
|
|
200
|
-
expect(Comp.displayName).toBe('Styled(View)');
|
|
201
|
-
|
|
202
|
-
var CompTwo = _index2.default.View.withConfig({ displayName: 'Test' })(_templateObject);
|
|
203
|
-
expect(CompTwo.displayName).toBe('Test');
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
it('should allow multiple calls to be chained', function () {
|
|
207
|
-
var Comp = _index2.default.View.withConfig({ displayName: 'Test1' }).withConfig({ displayName: 'Test2' })(_templateObject);
|
|
208
|
-
|
|
209
|
-
expect(Comp.displayName).toBe('Test2');
|
|
210
|
-
});
|
|
211
|
-
});
|
|
212
|
-
|
|
213
|
-
describe('innerRef', function () {
|
|
214
|
-
it('should pass the ref to the component', function () {
|
|
215
|
-
var Comp = _index2.default.View(_templateObject);
|
|
216
|
-
var ref = jest.fn();
|
|
217
|
-
|
|
218
|
-
var wrapper = (0, _enzyme.mount)(_react2.default.createElement(Comp, { innerRef: ref }));
|
|
219
|
-
var view = wrapper.find('View').first();
|
|
220
|
-
var comp = wrapper.find(Comp).first();
|
|
221
|
-
|
|
222
|
-
// $FlowFixMe
|
|
223
|
-
expect(ref).toHaveBeenCalledWith(view.node);
|
|
224
|
-
expect(view.prop('innerRef')).toBeFalsy();
|
|
225
|
-
expect(comp.node.root).toBeTruthy();
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
var InnerComponent = function (_React$Component) {
|
|
229
|
-
_inherits(InnerComponent, _React$Component);
|
|
230
|
-
|
|
231
|
-
function InnerComponent() {
|
|
232
|
-
_classCallCheck(this, InnerComponent);
|
|
233
|
-
|
|
234
|
-
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
InnerComponent.prototype.render = function render() {
|
|
238
|
-
return null;
|
|
239
|
-
};
|
|
240
|
-
|
|
241
|
-
return InnerComponent;
|
|
242
|
-
}(_react2.default.Component);
|
|
243
|
-
|
|
244
|
-
it('should not leak the innerRef prop to the wrapped child', function () {
|
|
245
|
-
var OuterComponent = (0, _index2.default)(InnerComponent)(_templateObject);
|
|
246
|
-
var ref = jest.fn();
|
|
247
|
-
|
|
248
|
-
var wrapper = (0, _enzyme.mount)(_react2.default.createElement(OuterComponent, { innerRef: ref }));
|
|
249
|
-
var innerComponent = wrapper.find(InnerComponent).first();
|
|
250
|
-
var outerComponent = wrapper.find(OuterComponent).first();
|
|
251
|
-
|
|
252
|
-
// $FlowFixMe
|
|
253
|
-
expect(ref).toHaveBeenCalledWith(innerComponent.node);
|
|
254
|
-
expect(innerComponent.prop('innerRef')).toBeFalsy();
|
|
255
|
-
expect(outerComponent.node.root).toBeTruthy();
|
|
256
|
-
});
|
|
257
|
-
|
|
258
|
-
it('should pass the innerRef to the wrapped styled component', function () {
|
|
259
|
-
var InnerComponent = _index2.default.View(_templateObject);
|
|
260
|
-
var OuterComponent = (0, _index2.default)(InnerComponent)(_templateObject);
|
|
261
|
-
var ref = jest.fn();
|
|
262
|
-
|
|
263
|
-
var wrapper = (0, _enzyme.mount)(_react2.default.createElement(OuterComponent, { innerRef: ref }));
|
|
264
|
-
var view = wrapper.find('View').first();
|
|
265
|
-
var innerComponent = wrapper.find(InnerComponent).first();
|
|
266
|
-
var outerComponent = wrapper.find(OuterComponent).first();
|
|
267
|
-
|
|
268
|
-
// $FlowFixMe
|
|
269
|
-
expect(ref).toHaveBeenCalledWith(view.node);
|
|
270
|
-
expect(outerComponent.node.root).toBeTruthy();
|
|
271
|
-
});
|
|
272
|
-
|
|
273
|
-
it('should pass innerRef instead of ref to a wrapped stateless functional component', function () {
|
|
274
|
-
var InnerComponent = function InnerComponent() {
|
|
275
|
-
return null;
|
|
276
|
-
};
|
|
277
|
-
var OuterComponent = (0, _index2.default)(InnerComponent)(_templateObject);
|
|
278
|
-
// NOTE: A ref should always be passed, so we don't need to (setNativeProps feature)
|
|
279
|
-
|
|
280
|
-
var wrapper = (0, _enzyme.mount)(_react2.default.createElement(OuterComponent, null));
|
|
281
|
-
var outerComponent = wrapper.find(OuterComponent).first();
|
|
282
|
-
var innerComponent = wrapper.find(InnerComponent).first();
|
|
283
|
-
|
|
284
|
-
expect(innerComponent.prop('ref')).toBeFalsy();
|
|
285
|
-
expect(innerComponent.prop('innerRef')).toBeTruthy();
|
|
286
|
-
expect(outerComponent.node.root).toBeFalsy();
|
|
287
|
-
});
|
|
288
|
-
});
|
|
289
|
-
});
|
package/lib/test/attrs.test.js
DELETED
|
@@ -1,158 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _templateObject = _taggedTemplateLiteralLoose([''], ['']),
|
|
4
|
-
_templateObject2 = _taggedTemplateLiteralLoose(['\n color: blue;\n &.', ' {\n color: red;\n }\n '], ['\n color: blue;\n &.', ' {\n color: red;\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('attrs', function () {
|
|
21
|
-
beforeEach(function () {
|
|
22
|
-
styled = (0, _utils.resetStyled)();
|
|
23
|
-
});
|
|
24
|
-
|
|
25
|
-
it('work fine with an empty object', function () {
|
|
26
|
-
var Comp = styled.div.attrs({})(_templateObject);
|
|
27
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<div class="sc-a b"></div>');
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
it('pass a simple attr', function () {
|
|
31
|
-
var Comp = styled.button.attrs({
|
|
32
|
-
type: 'button'
|
|
33
|
-
})(_templateObject);
|
|
34
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<button type="button" class="sc-a b"></button>');
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
it('call an attr function', function () {
|
|
38
|
-
var Comp = styled.button.attrs({
|
|
39
|
-
type: function type() {
|
|
40
|
-
return 'button';
|
|
41
|
-
}
|
|
42
|
-
})(_templateObject);
|
|
43
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<button type="button" class="sc-a b"></button>');
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it('pass props to the attr function', function () {
|
|
47
|
-
var Comp = styled.button.attrs({
|
|
48
|
-
type: function type(props) {
|
|
49
|
-
return props.submit ? 'submit' : 'button';
|
|
50
|
-
}
|
|
51
|
-
})(_templateObject);
|
|
52
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<button type="button" class="sc-a b"></button>');
|
|
53
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, { submit: true })).html()).toEqual('<button type="submit" class="sc-a b"></button>');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
it('should replace attrs with props', function () {
|
|
57
|
-
var Comp = styled.button.attrs({
|
|
58
|
-
type: function type(props) {
|
|
59
|
-
return props.submit ? 'submit' : 'button';
|
|
60
|
-
},
|
|
61
|
-
tabIndex: 0
|
|
62
|
-
})(_templateObject);
|
|
63
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<button type="button" tabindex="0" class="sc-a b"></button>');
|
|
64
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, { type: 'reset' })).html()).toEqual('<button type="reset" tabindex="0" class="sc-a b"></button>');
|
|
65
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, { type: 'reset', tabIndex: '-1' })).html()).toEqual('<button type="reset" tabindex="-1" class="sc-a b"></button>');
|
|
66
|
-
});
|
|
67
|
-
|
|
68
|
-
it('should merge className', function () {
|
|
69
|
-
var Comp = styled.div.attrs({
|
|
70
|
-
className: 'meow nya'
|
|
71
|
-
})(_templateObject);
|
|
72
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<div class="sc-a meow nya b"></div>');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('should merge className even if its a function', function () {
|
|
76
|
-
var Comp = styled.div.attrs({
|
|
77
|
-
className: function className(props) {
|
|
78
|
-
return 'meow ' + (props.purr ? 'purr' : 'nya');
|
|
79
|
-
}
|
|
80
|
-
})(_templateObject);
|
|
81
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<div class="sc-a meow nya b"></div>');
|
|
82
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, { purr: true })).html()).toEqual('<div class="sc-a meow purr b"></div>');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('should work with data and aria attributes', function () {
|
|
86
|
-
var Comp = styled.div.attrs({
|
|
87
|
-
'data-foo': 'bar',
|
|
88
|
-
'aria-label': 'A simple FooBar'
|
|
89
|
-
})(_templateObject);
|
|
90
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<div data-foo="bar" aria-label="A simple FooBar" class="sc-a b"></div>');
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
it('merge attrs', function () {
|
|
94
|
-
var Comp = styled.button.attrs({
|
|
95
|
-
type: 'button',
|
|
96
|
-
tabIndex: 0
|
|
97
|
-
}).attrs({
|
|
98
|
-
type: 'submit'
|
|
99
|
-
})(_templateObject);
|
|
100
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<button type="submit" tabindex="0" class="sc-a b"></button>');
|
|
101
|
-
});
|
|
102
|
-
|
|
103
|
-
it('merge attrs when inheriting SC', function () {
|
|
104
|
-
var Parent = styled.button.attrs({
|
|
105
|
-
type: 'button',
|
|
106
|
-
tabIndex: 0
|
|
107
|
-
})(_templateObject);
|
|
108
|
-
var Child = Parent.extend.attrs({
|
|
109
|
-
type: 'submit'
|
|
110
|
-
})(_templateObject);
|
|
111
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Child, null)).html()).toEqual('<button type="submit" tabindex="0" class="sc-b c"></button>');
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('pass attrs to style block', function () {
|
|
115
|
-
/* Would be a React Router Link in IRL */
|
|
116
|
-
var Comp = styled.a.attrs({
|
|
117
|
-
href: '#',
|
|
118
|
-
activeClassName: '--is-active'
|
|
119
|
-
})(_templateObject2, function (props) {
|
|
120
|
-
return props.activeClassName;
|
|
121
|
-
});
|
|
122
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<a href="#" class="sc-a b"></a>');
|
|
123
|
-
(0, _utils.expectCSSMatches)('.sc-a {} .b { color: blue; } .b.--is-active { color: red; }');
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('should pass through children as a normal prop', function () {
|
|
127
|
-
var Comp = styled.div.attrs({
|
|
128
|
-
children: 'Probably a bad idea'
|
|
129
|
-
})(_templateObject);
|
|
130
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<div class="sc-a b">Probably a bad idea</div>');
|
|
131
|
-
});
|
|
132
|
-
|
|
133
|
-
it('should pass through complex children as well', function () {
|
|
134
|
-
var Comp = styled.div.attrs({
|
|
135
|
-
children: _react2.default.createElement(
|
|
136
|
-
'span',
|
|
137
|
-
null,
|
|
138
|
-
'Probably a bad idea'
|
|
139
|
-
)
|
|
140
|
-
})(_templateObject);
|
|
141
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(Comp, null)).html()).toEqual('<div class="sc-a b"><span>Probably a bad idea</span></div>');
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it('should override children of course', function () {
|
|
145
|
-
var Comp = styled.div.attrs({
|
|
146
|
-
children: _react2.default.createElement(
|
|
147
|
-
'span',
|
|
148
|
-
null,
|
|
149
|
-
'Amazing'
|
|
150
|
-
)
|
|
151
|
-
})(_templateObject);
|
|
152
|
-
expect((0, _enzyme.shallow)(_react2.default.createElement(
|
|
153
|
-
Comp,
|
|
154
|
-
null,
|
|
155
|
-
'Something else'
|
|
156
|
-
)).html()).toEqual('<div class="sc-a b">Something else</div>');
|
|
157
|
-
});
|
|
158
|
-
});
|