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
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import styled from "../..";
|
|
3
|
+
|
|
4
|
+
interface OptionalProps {
|
|
5
|
+
text?: string;
|
|
6
|
+
}
|
|
7
|
+
interface ThemedOptionalProps extends OptionalProps {
|
|
8
|
+
theme: any;
|
|
9
|
+
}
|
|
10
|
+
interface RequiredProps {
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
interface ThemedRequiredProps extends RequiredProps {
|
|
14
|
+
theme: any;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare const theme: any;
|
|
18
|
+
|
|
19
|
+
// Tests of stateless functional components
|
|
20
|
+
function statelessFunctionalComponents() {
|
|
21
|
+
|
|
22
|
+
function optionalProps() {
|
|
23
|
+
const Component = (props: OptionalProps) => <div>{props.text}</div>;
|
|
24
|
+
|
|
25
|
+
const StyledComponent = styled(Component)``;
|
|
26
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
27
|
+
|
|
28
|
+
<Component />;
|
|
29
|
+
<Component text="test" />;
|
|
30
|
+
<StyledComponent text="test" />;
|
|
31
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
32
|
+
<StyledStyledComponent text="test" />;
|
|
33
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function optionalPropsWithRequiredTheme() {
|
|
37
|
+
const Component = (props: ThemedOptionalProps) => <div>{props.text}</div>;
|
|
38
|
+
|
|
39
|
+
const StyledComponent = styled(Component)``;
|
|
40
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
41
|
+
|
|
42
|
+
<Component theme={theme} />; // theme is required
|
|
43
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
44
|
+
<StyledComponent text="test" />; // theme is optional
|
|
45
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
46
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
47
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function requiredProps() {
|
|
51
|
+
const Component = (props: RequiredProps) => <div>{props.text}</div>;
|
|
52
|
+
|
|
53
|
+
const StyledComponent = styled(Component)``;
|
|
54
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
55
|
+
|
|
56
|
+
// <Component />; // text required
|
|
57
|
+
<Component text="test" />;
|
|
58
|
+
// <StyledComponent />; // text required
|
|
59
|
+
<StyledComponent text="test" />;
|
|
60
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
61
|
+
// <StyledStyledComponent />; // text allowed
|
|
62
|
+
<StyledStyledComponent text="test" />;
|
|
63
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function requiredPropsWithRequiredTheme() {
|
|
67
|
+
const Component = (props: ThemedRequiredProps) => <div>{props.text}</div>;
|
|
68
|
+
|
|
69
|
+
const StyledComponent = styled(Component)``;
|
|
70
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
71
|
+
|
|
72
|
+
// <Component theme={theme} />; // theme is required
|
|
73
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
74
|
+
// <StyledComponent />; // text required
|
|
75
|
+
<StyledComponent text="test" />; // theme is optional
|
|
76
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
77
|
+
// <StyledStyledComponent />; // text required
|
|
78
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
79
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Tests of pure components
|
|
85
|
+
function pureComponents() {
|
|
86
|
+
|
|
87
|
+
function optionalProps() {
|
|
88
|
+
class Component extends React.PureComponent<OptionalProps> {
|
|
89
|
+
render() { return <div>{this.props.text}</div>; }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const StyledComponent = styled(Component)``;
|
|
93
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
94
|
+
|
|
95
|
+
<Component />;
|
|
96
|
+
<Component text="test" />;
|
|
97
|
+
<StyledComponent text="test" />;
|
|
98
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
99
|
+
<StyledStyledComponent text="test" />;
|
|
100
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function optionalPropsWithRequiredTheme() {
|
|
104
|
+
class Component extends React.PureComponent<ThemedOptionalProps> {
|
|
105
|
+
render() { return <div>{this.props.text}</div>; }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const StyledComponent = styled(Component)``;
|
|
109
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
110
|
+
|
|
111
|
+
<Component theme={theme} />; // theme is required
|
|
112
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
113
|
+
<StyledComponent text="test" />; // theme is optional
|
|
114
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
115
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
116
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function requiredProps() {
|
|
120
|
+
class Component extends React.PureComponent<RequiredProps> {
|
|
121
|
+
render() { return <div>{this.props.text}</div>; }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const StyledComponent = styled(Component)``;
|
|
125
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
126
|
+
|
|
127
|
+
// <Component />; // text required
|
|
128
|
+
<Component text="test" />;
|
|
129
|
+
// <StyledComponent />; // text required
|
|
130
|
+
<StyledComponent text="test" />;
|
|
131
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
132
|
+
// <StyledStyledComponent />; // text allowed
|
|
133
|
+
<StyledStyledComponent text="test" />;
|
|
134
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function requiredPropsWithRequiredTheme() {
|
|
138
|
+
class Component extends React.PureComponent<ThemedRequiredProps> {
|
|
139
|
+
render() { return <div>{this.props.text}</div>; }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const StyledComponent = styled(Component)``;
|
|
143
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
144
|
+
|
|
145
|
+
// <Component theme={theme} />; // theme is required
|
|
146
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
147
|
+
// <StyledComponent />; // text required
|
|
148
|
+
<StyledComponent text="test" />; // theme is optional
|
|
149
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
150
|
+
// <StyledStyledComponent />; // text required
|
|
151
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
152
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Tests of classic components
|
|
157
|
+
function classicComponents() {
|
|
158
|
+
|
|
159
|
+
function optionalProps() {
|
|
160
|
+
class Component extends React.Component<OptionalProps> {
|
|
161
|
+
render() { return <div>{this.props.text}</div>; }
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const StyledComponent = styled(Component)``;
|
|
165
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
166
|
+
|
|
167
|
+
<Component />;
|
|
168
|
+
<Component text="test" />;
|
|
169
|
+
<StyledComponent text="test" />;
|
|
170
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
171
|
+
<StyledStyledComponent text="test" />;
|
|
172
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function optionalPropsWithRequiredTheme() {
|
|
176
|
+
class Component extends React.Component<ThemedOptionalProps> {
|
|
177
|
+
render() { return <div>{this.props.text}</div>; }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const StyledComponent = styled(Component)``;
|
|
181
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
182
|
+
|
|
183
|
+
<Component theme={theme} />; // theme is required
|
|
184
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
185
|
+
<StyledComponent text="test" />; // theme is optional
|
|
186
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
187
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
188
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function requiredProps() {
|
|
192
|
+
class Component extends React.Component<RequiredProps> {
|
|
193
|
+
render() { return <div>{this.props.text}</div>; }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const StyledComponent = styled(Component)``;
|
|
197
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
198
|
+
|
|
199
|
+
// <Component />; // text required
|
|
200
|
+
<Component text="test" />;
|
|
201
|
+
// <StyledComponent />; // text required
|
|
202
|
+
<StyledComponent text="test" />;
|
|
203
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
204
|
+
// <StyledStyledComponent />; // text allowed
|
|
205
|
+
<StyledStyledComponent text="test" />;
|
|
206
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function requiredPropsWithRequiredTheme() {
|
|
210
|
+
class Component extends React.Component<ThemedRequiredProps> {
|
|
211
|
+
render() { return <div>{this.props.text}</div>; }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const StyledComponent = styled(Component)``;
|
|
215
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
216
|
+
|
|
217
|
+
// <Component theme={theme} />; // theme is required
|
|
218
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
219
|
+
// <StyledComponent />; // text required
|
|
220
|
+
<StyledComponent text="test" />; // theme is optional
|
|
221
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
222
|
+
// <StyledStyledComponent />; // text required
|
|
223
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
224
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import styled from "../..";
|
|
4
|
+
|
|
5
|
+
// Create a <Link> react component that renders an <a> which is
|
|
6
|
+
// centered, palevioletred and sized at 1.5em
|
|
7
|
+
const Link = styled.a`
|
|
8
|
+
font-size: 1.5em;
|
|
9
|
+
text-align: center;
|
|
10
|
+
color: palevioletred;
|
|
11
|
+
`;
|
|
12
|
+
|
|
13
|
+
// A Link instance should be backed by an HTMLAnchorElement
|
|
14
|
+
const MyComponent = () =>
|
|
15
|
+
<Link
|
|
16
|
+
onClick={(e: React.MouseEvent<HTMLAnchorElement>) => undefined}
|
|
17
|
+
/>;
|
|
18
|
+
|
|
19
|
+
// Create a <LinkFromString> react component that renders an <a> which is
|
|
20
|
+
// centered, palevioletred and sized at 1.5em
|
|
21
|
+
const LinkFromString = styled("a")`
|
|
22
|
+
font-size: 1.5em;
|
|
23
|
+
text-align: center;
|
|
24
|
+
color: palevioletred;
|
|
25
|
+
`;
|
|
26
|
+
|
|
27
|
+
// A LinkFromString instance should be backed by an HTMLAnchorElement
|
|
28
|
+
const MyOtherComponent = () =>
|
|
29
|
+
<LinkFromString
|
|
30
|
+
onClick={(e: React.MouseEvent<HTMLAnchorElement>) => undefined}
|
|
31
|
+
/>;
|
|
32
|
+
|
|
33
|
+
// Create a <LinkFromStringWithProps> react component that renders an <a>
|
|
34
|
+
// which takes extra props
|
|
35
|
+
type LinkProps = {canClick: boolean};
|
|
36
|
+
const LinkFromStringWithProps = styled("a")`
|
|
37
|
+
font-size: 1.5em;
|
|
38
|
+
text-align: center;
|
|
39
|
+
color: ${(a: LinkProps) => a.canClick ? "palevioletred" : "gray"};
|
|
40
|
+
`;
|
|
41
|
+
|
|
42
|
+
// A LinkFromStringWithProps instance should be backed by an HTMLAnchorElement
|
|
43
|
+
const MyOtherComponentWithProps = () =>
|
|
44
|
+
<LinkFromStringWithProps
|
|
45
|
+
canClick={false}
|
|
46
|
+
onClick={(e: React.MouseEvent<HTMLAnchorElement>) => undefined}
|
|
47
|
+
/>;
|
|
48
|
+
|
|
49
|
+
// Create a <LinkFromStringWithPropsAndGenerics> react component that renders an <a>
|
|
50
|
+
// which takes extra props passed as a generic type argument
|
|
51
|
+
const LinkFromStringWithPropsAndGenerics = styled<LinkProps, "a">("a")`
|
|
52
|
+
font-size: 1.5em;
|
|
53
|
+
text-align: center;
|
|
54
|
+
color: ${a => a.canClick ? "palevioletred" : "gray"};
|
|
55
|
+
`;
|
|
56
|
+
|
|
57
|
+
// A LinkFromStringWithPropsAndGenerics instance should be backed by an HTMLAnchorElement
|
|
58
|
+
const MyOtherComponentWithPropsAndGenerics = () =>
|
|
59
|
+
<LinkFromStringWithPropsAndGenerics
|
|
60
|
+
canClick={false}
|
|
61
|
+
onClick={(e: React.MouseEvent<HTMLAnchorElement>) => undefined}
|
|
62
|
+
/>;
|
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import styled, { MyTheme } from "./mytheme-styled-components";
|
|
3
|
+
|
|
4
|
+
interface OptionalProps {
|
|
5
|
+
text?: string;
|
|
6
|
+
}
|
|
7
|
+
interface ThemedOptionalProps extends OptionalProps {
|
|
8
|
+
theme: MyTheme;
|
|
9
|
+
}
|
|
10
|
+
interface RequiredProps {
|
|
11
|
+
text: string;
|
|
12
|
+
}
|
|
13
|
+
interface ThemedRequiredProps extends RequiredProps {
|
|
14
|
+
theme: MyTheme;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
declare const theme: MyTheme;
|
|
18
|
+
|
|
19
|
+
// Tests of stateless functional components
|
|
20
|
+
function statelessFunctionalComponents() {
|
|
21
|
+
|
|
22
|
+
function optionalProps() {
|
|
23
|
+
const Component = (props: OptionalProps) => <div>{props.text}</div>;
|
|
24
|
+
|
|
25
|
+
const StyledComponent = styled(Component)``;
|
|
26
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
27
|
+
|
|
28
|
+
<Component />;
|
|
29
|
+
<Component text="test" />;
|
|
30
|
+
<StyledComponent text="test" />;
|
|
31
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
32
|
+
<StyledStyledComponent text="test" />;
|
|
33
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function optionalPropsWithRequiredTheme() {
|
|
37
|
+
const Component = (props: ThemedOptionalProps) => <div>{props.text}</div>;
|
|
38
|
+
|
|
39
|
+
const StyledComponent = styled(Component)``;
|
|
40
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
41
|
+
|
|
42
|
+
<Component theme={theme} />; // theme is required
|
|
43
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
44
|
+
<StyledComponent text="test" />; // theme is optional
|
|
45
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
46
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
47
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function requiredProps() {
|
|
51
|
+
const Component = (props: RequiredProps) => <div>{props.text}</div>;
|
|
52
|
+
|
|
53
|
+
const StyledComponent = styled(Component)``;
|
|
54
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
55
|
+
|
|
56
|
+
// <Component />; // text required
|
|
57
|
+
<Component text="test" />;
|
|
58
|
+
// <StyledComponent />; // text required
|
|
59
|
+
<StyledComponent text="test" />;
|
|
60
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
61
|
+
// <StyledStyledComponent />; // text allowed
|
|
62
|
+
<StyledStyledComponent text="test" />;
|
|
63
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function requiredPropsWithRequiredTheme() {
|
|
67
|
+
const Component = (props: ThemedRequiredProps) => <div>{props.text}</div>;
|
|
68
|
+
|
|
69
|
+
const StyledComponent = styled(Component)``;
|
|
70
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
71
|
+
|
|
72
|
+
// <Component theme={theme} />; // theme is required
|
|
73
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
74
|
+
// <StyledComponent />; // text required
|
|
75
|
+
<StyledComponent text="test" />; // theme is optional
|
|
76
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
77
|
+
// <StyledStyledComponent />; // text required
|
|
78
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
79
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
// Tests of pure components
|
|
85
|
+
function pureComponents() {
|
|
86
|
+
|
|
87
|
+
function optionalProps() {
|
|
88
|
+
class Component extends React.PureComponent<OptionalProps> {
|
|
89
|
+
render() { return <div>{this.props.text}</div>; }
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
const StyledComponent = styled(Component)``;
|
|
93
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
94
|
+
|
|
95
|
+
<Component />;
|
|
96
|
+
<Component text="test" />;
|
|
97
|
+
<StyledComponent text="test" />;
|
|
98
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
99
|
+
<StyledStyledComponent text="test" />;
|
|
100
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
function optionalPropsWithRequiredTheme() {
|
|
104
|
+
class Component extends React.PureComponent<ThemedOptionalProps> {
|
|
105
|
+
render() { return <div>{this.props.text}</div>; }
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
const StyledComponent = styled(Component)``;
|
|
109
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
110
|
+
|
|
111
|
+
<Component theme={theme} />; // theme is required
|
|
112
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
113
|
+
<StyledComponent text="test" />; // theme is optional
|
|
114
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
115
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
116
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
function requiredProps() {
|
|
120
|
+
class Component extends React.PureComponent<RequiredProps> {
|
|
121
|
+
render() { return <div>{this.props.text}</div>; }
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
const StyledComponent = styled(Component)``;
|
|
125
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
126
|
+
|
|
127
|
+
// <Component />; // text required
|
|
128
|
+
<Component text="test" />;
|
|
129
|
+
// <StyledComponent />; // text required
|
|
130
|
+
<StyledComponent text="test" />;
|
|
131
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
132
|
+
// <StyledStyledComponent />; // text allowed
|
|
133
|
+
<StyledStyledComponent text="test" />;
|
|
134
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
function requiredPropsWithRequiredTheme() {
|
|
138
|
+
class Component extends React.PureComponent<ThemedRequiredProps> {
|
|
139
|
+
render() { return <div>{this.props.text}</div>; }
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
const StyledComponent = styled(Component)``;
|
|
143
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
144
|
+
|
|
145
|
+
// <Component theme={theme} />; // theme is required
|
|
146
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
147
|
+
// <StyledComponent />; // text required
|
|
148
|
+
<StyledComponent text="test" />; // theme is optional
|
|
149
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
150
|
+
// <StyledStyledComponent />; // text required
|
|
151
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
152
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// Tests of classic components
|
|
157
|
+
function classicComponents() {
|
|
158
|
+
|
|
159
|
+
function optionalProps() {
|
|
160
|
+
class Component extends React.Component<OptionalProps> {
|
|
161
|
+
render() { return <div>{this.props.text}</div>; }
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
const StyledComponent = styled(Component)``;
|
|
165
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
166
|
+
|
|
167
|
+
<Component />;
|
|
168
|
+
<Component text="test" />;
|
|
169
|
+
<StyledComponent text="test" />;
|
|
170
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
171
|
+
<StyledStyledComponent text="test" />;
|
|
172
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
function optionalPropsWithRequiredTheme() {
|
|
176
|
+
class Component extends React.Component<ThemedOptionalProps> {
|
|
177
|
+
render() { return <div>{this.props.text}</div>; }
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
const StyledComponent = styled(Component)``;
|
|
181
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
182
|
+
|
|
183
|
+
<Component theme={theme} />; // theme is required
|
|
184
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
185
|
+
<StyledComponent text="test" />; // theme is optional
|
|
186
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
187
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
188
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
function requiredProps() {
|
|
192
|
+
class Component extends React.Component<RequiredProps> {
|
|
193
|
+
render() { return <div>{this.props.text}</div>; }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
const StyledComponent = styled(Component)``;
|
|
197
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
198
|
+
|
|
199
|
+
// <Component />; // text required
|
|
200
|
+
<Component text="test" />;
|
|
201
|
+
// <StyledComponent />; // text required
|
|
202
|
+
<StyledComponent text="test" />;
|
|
203
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
204
|
+
// <StyledStyledComponent />; // text allowed
|
|
205
|
+
<StyledStyledComponent text="test" />;
|
|
206
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
function requiredPropsWithRequiredTheme() {
|
|
210
|
+
class Component extends React.Component<ThemedRequiredProps> {
|
|
211
|
+
render() { return <div>{this.props.text}</div>; }
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
const StyledComponent = styled(Component)``;
|
|
215
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
216
|
+
|
|
217
|
+
// <Component theme={theme} />; // theme is required
|
|
218
|
+
<Component text="test" theme={theme} />; // theme is required
|
|
219
|
+
// <StyledComponent />; // text required
|
|
220
|
+
<StyledComponent text="test" />; // theme is optional
|
|
221
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
222
|
+
// <StyledStyledComponent />; // text required
|
|
223
|
+
<StyledStyledComponent text="test" />; // theme is optional
|
|
224
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
225
|
+
}
|
|
226
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
|
|
3
|
+
import styled, { withTheme } from "../..";
|
|
4
|
+
|
|
5
|
+
interface Props {
|
|
6
|
+
theme: {
|
|
7
|
+
color: string;
|
|
8
|
+
};
|
|
9
|
+
text: string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
const Component = (props: Props) => <div style={{color: props.theme.color}}>{props.text}</div>;
|
|
13
|
+
|
|
14
|
+
const ComponentWithTheme = withTheme(Component);
|
|
15
|
+
|
|
16
|
+
<ComponentWithTheme text={"hi"} />; // ok
|
|
17
|
+
<ComponentWithTheme text={"hi"} theme={{ color: "red" }} />; // ok
|
|
@@ -1,63 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _templateObject = _taggedTemplateLiteralLoose(['\n html {\n ', '\n }\n '], ['\n html {\n ', '\n }\n ']),
|
|
4
|
-
_templateObject2 = _taggedTemplateLiteralLoose(['\n a {\n ', '\n }\n '], ['\n a {\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 _injectGlobal2 = require('../injectGlobal');
|
|
14
|
-
|
|
15
|
-
var _injectGlobal3 = _interopRequireDefault(_injectGlobal2);
|
|
16
|
-
|
|
17
|
-
var _stringifyRules = require('../../utils/stringifyRules');
|
|
18
|
-
|
|
19
|
-
var _stringifyRules2 = _interopRequireDefault(_stringifyRules);
|
|
20
|
-
|
|
21
|
-
var _css = require('../css');
|
|
22
|
-
|
|
23
|
-
var _css2 = _interopRequireDefault(_css);
|
|
24
|
-
|
|
25
|
-
var _utils = require('../../test/utils');
|
|
26
|
-
|
|
27
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
28
|
-
|
|
29
|
-
function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
|
|
30
|
-
|
|
31
|
-
var injectGlobal = (0, _injectGlobal3.default)(_stringifyRules2.default, _css2.default);
|
|
32
|
-
|
|
33
|
-
var styled = (0, _utils.resetStyled)();
|
|
34
|
-
var rule1 = 'width: 100%;';
|
|
35
|
-
var rule2 = 'padding: 10px;';
|
|
36
|
-
var rule3 = 'color: blue;';
|
|
37
|
-
|
|
38
|
-
describe('injectGlobal', function () {
|
|
39
|
-
beforeEach(function () {
|
|
40
|
-
(0, _utils.resetStyled)();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('should inject rules into the head', function () {
|
|
44
|
-
injectGlobal(_templateObject, rule1);
|
|
45
|
-
(0, _utils.expectCSSMatches)('\n html {\n ' + rule1 + '\n }\n ');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
it('should non-destructively inject styles when called repeatedly', function () {
|
|
49
|
-
injectGlobal(_templateObject, rule1);
|
|
50
|
-
|
|
51
|
-
injectGlobal(_templateObject2, rule2);
|
|
52
|
-
(0, _utils.expectCSSMatches)('\n html {\n ' + rule1 + '\n }\n a {\n ' + rule2 + '\n }\n ');
|
|
53
|
-
});
|
|
54
|
-
|
|
55
|
-
it('should non-destructively inject styles when called after a component', function () {
|
|
56
|
-
var Comp = styled.div(_templateObject3, rule3);
|
|
57
|
-
(0, _enzyme.shallow)(_react2.default.createElement(Comp, null));
|
|
58
|
-
|
|
59
|
-
injectGlobal(_templateObject, rule1);
|
|
60
|
-
|
|
61
|
-
(0, _utils.expectCSSMatches)('\n .sc-a {}\n .b {\n ' + rule3 + '\n }\n html {\n ' + rule1 + '\n }\n ');
|
|
62
|
-
});
|
|
63
|
-
});
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var _templateObject = _taggedTemplateLiteralLoose(['\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n '], ['\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n ']),
|
|
4
|
-
_templateObject2 = _taggedTemplateLiteralLoose(['', ''], ['', '']);
|
|
5
|
-
|
|
6
|
-
var _keyframes2 = require('../keyframes');
|
|
7
|
-
|
|
8
|
-
var _keyframes3 = _interopRequireDefault(_keyframes2);
|
|
9
|
-
|
|
10
|
-
var _stringifyRules = require('../../utils/stringifyRules');
|
|
11
|
-
|
|
12
|
-
var _stringifyRules2 = _interopRequireDefault(_stringifyRules);
|
|
13
|
-
|
|
14
|
-
var _css = require('../css');
|
|
15
|
-
|
|
16
|
-
var _css2 = _interopRequireDefault(_css);
|
|
17
|
-
|
|
18
|
-
var _utils = require('../../test/utils');
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
function _taggedTemplateLiteralLoose(strings, raw) { strings.raw = raw; return strings; }
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* Setup
|
|
26
|
-
*/
|
|
27
|
-
var index = 0;
|
|
28
|
-
var keyframes = (0, _keyframes3.default)(function () {
|
|
29
|
-
return 'keyframe_' + index++;
|
|
30
|
-
}, _stringifyRules2.default, _css2.default);
|
|
31
|
-
|
|
32
|
-
describe('keyframes', function () {
|
|
33
|
-
beforeEach(function () {
|
|
34
|
-
(0, _utils.resetStyled)();
|
|
35
|
-
index = 0;
|
|
36
|
-
});
|
|
37
|
-
|
|
38
|
-
it('should return its name', function () {
|
|
39
|
-
expect(keyframes(_templateObject)).toEqual('keyframe_0');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('should insert the correct styles', function () {
|
|
43
|
-
var rules = '\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n ';
|
|
44
|
-
|
|
45
|
-
var name = keyframes(_templateObject2, rules);
|
|
46
|
-
(0, _utils.expectCSSMatches)('\n @-webkit-keyframes ' + name + ' {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n\n @keyframes ' + name + ' {\n 0% {\n opacity: 0;\n }\n 100% {\n opacity: 1;\n }\n }\n ');
|
|
47
|
-
});
|
|
48
|
-
});
|