styled-components 3.3.2 → 3.3.3
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 +21 -1
- package/dist/styled-components-no-parser.browser.cjs.js +24 -21
- package/dist/styled-components-no-parser.browser.cjs.js.map +1 -1
- package/dist/styled-components-no-parser.browser.es.js +24 -21
- package/dist/styled-components-no-parser.browser.es.js.map +1 -1
- package/dist/styled-components-no-parser.cjs.js +24 -21
- package/dist/styled-components-no-parser.cjs.js.map +1 -1
- package/dist/styled-components-no-parser.es.js +24 -21
- package/dist/styled-components-no-parser.es.js.map +1 -1
- package/dist/styled-components-primitives.cjs.js +17 -7
- package/dist/styled-components-primitives.cjs.js.map +1 -1
- package/dist/styled-components-primitives.es.js +17 -7
- package/dist/styled-components-primitives.es.js.map +1 -1
- package/dist/styled-components.browser.cjs.js +24 -21
- package/dist/styled-components.browser.cjs.js.map +1 -1
- package/dist/styled-components.browser.cjs.min.js +1 -1
- package/dist/styled-components.browser.cjs.min.js.map +1 -1
- package/dist/styled-components.browser.es.js +24 -21
- package/dist/styled-components.browser.es.js.map +1 -1
- package/dist/styled-components.browser.es.min.js +1 -1
- package/dist/styled-components.browser.es.min.js.map +1 -1
- package/dist/styled-components.cjs.js +24 -21
- package/dist/styled-components.cjs.js.map +1 -1
- package/dist/styled-components.cjs.min.js +1 -1
- package/dist/styled-components.cjs.min.js.map +1 -1
- package/dist/styled-components.es.js +24 -21
- package/dist/styled-components.es.js.map +1 -1
- package/dist/styled-components.es.min.js +1 -1
- package/dist/styled-components.es.min.js.map +1 -1
- package/dist/styled-components.js +24 -21
- package/dist/styled-components.js.map +1 -1
- package/dist/styled-components.min.js +1 -1
- package/dist/styled-components.min.js.map +1 -1
- package/dist/styled-components.native.cjs.js +17 -7
- package/dist/styled-components.native.cjs.js.map +1 -1
- package/docs/tips-and-tricks.md +33 -2
- package/package.json +1 -1
- package/src/models/StyledComponent.js +28 -24
- package/src/models/StyledNativeComponent.js +18 -7
- package/src/test/__snapshots__/extending.test.js.snap +3 -0
- package/src/test/basic.test.js +32 -1
- package/src/test/extending.test.js +79 -23
- package/typings/styled-components.d.ts +2 -3
- package/typings/tests/issue1068.tsx +265 -0
- package/typings/tests/themed-tests/issue1068.tsx +265 -0
|
@@ -26,7 +26,9 @@ describe('extending', () => {
|
|
|
26
26
|
})
|
|
27
27
|
|
|
28
28
|
it('should attach styles to both classes if only parent has styles', () => {
|
|
29
|
-
const Parent = styled.div`
|
|
29
|
+
const Parent = styled.div`
|
|
30
|
+
color: blue;
|
|
31
|
+
`
|
|
30
32
|
const Child = Parent.extend``
|
|
31
33
|
|
|
32
34
|
shallow(<Parent />)
|
|
@@ -37,7 +39,9 @@ describe('extending', () => {
|
|
|
37
39
|
|
|
38
40
|
it('should attach styles to child class if only child has styles', () => {
|
|
39
41
|
const Parent = styled.div``
|
|
40
|
-
const Child = Parent.extend`
|
|
42
|
+
const Child = Parent.extend`
|
|
43
|
+
color: blue;
|
|
44
|
+
`
|
|
41
45
|
|
|
42
46
|
shallow(<Parent />)
|
|
43
47
|
shallow(<Child />)
|
|
@@ -46,8 +50,12 @@ describe('extending', () => {
|
|
|
46
50
|
})
|
|
47
51
|
|
|
48
52
|
it('should generate a class for the child with the rules of the parent', () => {
|
|
49
|
-
const Parent = styled.div`
|
|
50
|
-
|
|
53
|
+
const Parent = styled.div`
|
|
54
|
+
color: blue;
|
|
55
|
+
`
|
|
56
|
+
const Child = Parent.extend`
|
|
57
|
+
color: red;
|
|
58
|
+
`
|
|
51
59
|
|
|
52
60
|
shallow(<Child />)
|
|
53
61
|
|
|
@@ -55,21 +63,31 @@ describe('extending', () => {
|
|
|
55
63
|
})
|
|
56
64
|
|
|
57
65
|
it('should generate different classes for both parent and child', () => {
|
|
58
|
-
const Parent = styled.div`
|
|
59
|
-
|
|
66
|
+
const Parent = styled.div`
|
|
67
|
+
color: blue;
|
|
68
|
+
`
|
|
69
|
+
const Child = Parent.extend`
|
|
70
|
+
color: red;
|
|
71
|
+
`
|
|
60
72
|
|
|
61
73
|
shallow(<Parent />)
|
|
62
74
|
shallow(<Child />)
|
|
63
75
|
|
|
64
|
-
expectCSSMatches(
|
|
76
|
+
expectCSSMatches(
|
|
77
|
+
'.sc-a {} .c { color:blue; } .sc-b {} .d { color:blue;color:red; }'
|
|
78
|
+
)
|
|
65
79
|
})
|
|
66
80
|
|
|
67
81
|
it('should copy nested rules to the child', () => {
|
|
68
82
|
const Parent = styled.div`
|
|
69
83
|
color: blue;
|
|
70
|
-
> h1 {
|
|
84
|
+
> h1 {
|
|
85
|
+
font-size: 4rem;
|
|
86
|
+
}
|
|
87
|
+
`
|
|
88
|
+
const Child = Parent.extend`
|
|
89
|
+
color: red;
|
|
71
90
|
`
|
|
72
|
-
const Child = Parent.extend`color: red;`
|
|
73
91
|
|
|
74
92
|
shallow(<Parent />)
|
|
75
93
|
shallow(<Child />)
|
|
@@ -86,13 +104,15 @@ describe('extending', () => {
|
|
|
86
104
|
|
|
87
105
|
it('should keep default props from parent', () => {
|
|
88
106
|
const Parent = styled.div`
|
|
89
|
-
color: ${
|
|
107
|
+
color: ${props => props.color};
|
|
90
108
|
`
|
|
91
109
|
Parent.defaultProps = {
|
|
92
|
-
color: 'red'
|
|
110
|
+
color: 'red',
|
|
93
111
|
}
|
|
94
112
|
|
|
95
|
-
const Child = Parent.extend`
|
|
113
|
+
const Child = Parent.extend`
|
|
114
|
+
background-color: green;
|
|
115
|
+
`
|
|
96
116
|
|
|
97
117
|
shallow(<Parent />)
|
|
98
118
|
shallow(<Child />)
|
|
@@ -105,34 +125,46 @@ describe('extending', () => {
|
|
|
105
125
|
|
|
106
126
|
it('should keep prop types from parent', () => {
|
|
107
127
|
const Parent = styled.div`
|
|
108
|
-
color: ${
|
|
128
|
+
color: ${props => props.color};
|
|
109
129
|
`
|
|
110
130
|
Parent.propTypes = {
|
|
111
|
-
color: PropTypes.string
|
|
131
|
+
color: PropTypes.string,
|
|
112
132
|
}
|
|
113
133
|
|
|
114
|
-
const Child = Parent.extend`
|
|
134
|
+
const Child = Parent.extend`
|
|
135
|
+
background-color: green;
|
|
136
|
+
`
|
|
115
137
|
|
|
116
138
|
expect(Child.propTypes).toEqual(Parent.propTypes)
|
|
117
139
|
})
|
|
118
140
|
|
|
119
141
|
it('should keep custom static member from parent', () => {
|
|
120
|
-
const Parent = styled.div`
|
|
142
|
+
const Parent = styled.div`
|
|
143
|
+
color: red;
|
|
144
|
+
`
|
|
121
145
|
|
|
122
146
|
Parent.fetchData = () => 1
|
|
123
147
|
|
|
124
|
-
const Child = Parent.extend`
|
|
148
|
+
const Child = Parent.extend`
|
|
149
|
+
color: green;
|
|
150
|
+
`
|
|
125
151
|
|
|
126
152
|
expect(Child.fetchData).toBeTruthy()
|
|
127
153
|
expect(Child.fetchData()).toEqual(1)
|
|
128
154
|
})
|
|
129
155
|
|
|
130
156
|
it('should keep static member in triple inheritance', () => {
|
|
131
|
-
const GrandParent = styled.div`
|
|
157
|
+
const GrandParent = styled.div`
|
|
158
|
+
color: red;
|
|
159
|
+
`
|
|
132
160
|
GrandParent.fetchData = () => 1
|
|
133
161
|
|
|
134
|
-
const Parent = GrandParent.extend`
|
|
135
|
-
|
|
162
|
+
const Parent = GrandParent.extend`
|
|
163
|
+
color: red;
|
|
164
|
+
`
|
|
165
|
+
const Child = Parent.extend`
|
|
166
|
+
color: red;
|
|
167
|
+
`
|
|
136
168
|
|
|
137
169
|
expect(Child.fetchData).toBeTruthy()
|
|
138
170
|
expect(Child.fetchData()).toEqual(1)
|
|
@@ -173,7 +205,9 @@ describe('extending', () => {
|
|
|
173
205
|
})
|
|
174
206
|
|
|
175
207
|
it('should allow changing component', () => {
|
|
176
|
-
const Parent = styled.div`
|
|
208
|
+
const Parent = styled.div`
|
|
209
|
+
color: red;
|
|
210
|
+
`
|
|
177
211
|
const Child = Parent.withComponent('span')
|
|
178
212
|
|
|
179
213
|
expect(shallow(<Child />).html()).toEqual('<span class="sc-b c"></span>')
|
|
@@ -198,9 +232,31 @@ describe('extending', () => {
|
|
|
198
232
|
color: red;
|
|
199
233
|
`
|
|
200
234
|
const Child = Parent.withComponent('a').extend.attrs({
|
|
201
|
-
href: '/test'
|
|
235
|
+
href: '/test',
|
|
202
236
|
})``
|
|
203
237
|
|
|
204
|
-
expect(shallow(<Child />).html()).toEqual(
|
|
238
|
+
expect(shallow(<Child />).html()).toEqual(
|
|
239
|
+
'<a href="/test" class="sc-c d"></a>'
|
|
240
|
+
)
|
|
241
|
+
})
|
|
242
|
+
|
|
243
|
+
it('regression test for #1781, extending a Styled(StyledComponent)', () => {
|
|
244
|
+
const Title = styled.h1`
|
|
245
|
+
color: red;
|
|
246
|
+
`
|
|
247
|
+
|
|
248
|
+
const ExtendedTitle = styled(Title)`
|
|
249
|
+
background-color: blue;
|
|
250
|
+
`
|
|
251
|
+
|
|
252
|
+
const ExtendedExtendedTitle = ExtendedTitle.extend`
|
|
253
|
+
border: 2px solid green;
|
|
254
|
+
`
|
|
255
|
+
|
|
256
|
+
expect(shallow(<ExtendedExtendedTitle />).html()).toMatchSnapshot()
|
|
257
|
+
expectCSSMatches(`
|
|
258
|
+
.sc-a { } .e { color:red; }
|
|
259
|
+
.sc-c { } .d { background-color:blue; border:2px solid green; }
|
|
260
|
+
`)
|
|
205
261
|
})
|
|
206
262
|
})
|
|
@@ -40,8 +40,7 @@ export interface StyledComponentClass<P, T, O = P> extends ComponentClass<Themed
|
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
export interface ThemedStyledFunction<P, T, O = P> {
|
|
43
|
-
(strings: TemplateStringsArray, ...interpolations: Interpolation<ThemedStyledProps<P, T>>[]): StyledComponentClass<P, T, O>;
|
|
44
|
-
<U>(strings: TemplateStringsArray, ...interpolations: Interpolation<ThemedStyledProps<P & U, T>>[]): StyledComponentClass<P & U, T, O & U>;
|
|
43
|
+
<U = {}>(strings: TemplateStringsArray, ...interpolations: Interpolation<ThemedStyledProps<P & U, T>>[]): StyledComponentClass<P & U, T, O & U>;
|
|
45
44
|
attrs<U, A extends Partial<P & U> = {}>(attrs: Attrs<P & U, A, T>): ThemedStyledFunction<P & A & U, T, O & U>;
|
|
46
45
|
}
|
|
47
46
|
|
|
@@ -73,7 +72,7 @@ export interface ThemedCssFunction<T> {
|
|
|
73
72
|
|
|
74
73
|
// Helper type operators
|
|
75
74
|
type KeyofBase = keyof any;
|
|
76
|
-
type Diff<T extends KeyofBase, U extends KeyofBase> = ({ [P in T]: P } & { [P in U]: never }
|
|
75
|
+
type Diff<T extends KeyofBase, U extends KeyofBase> = ({ [P in T]: P } & { [P in U]: never })[T];
|
|
77
76
|
type Omit<T, K extends keyof T> = Pick<T, Diff<keyof T, K>>;
|
|
78
77
|
type WithOptionalTheme<P extends { theme?: T; }, T> = Omit<P, "theme"> & { theme?: T; };
|
|
79
78
|
|
|
@@ -4,6 +4,9 @@ import styled from "../..";
|
|
|
4
4
|
interface OptionalProps {
|
|
5
5
|
text?: string;
|
|
6
6
|
}
|
|
7
|
+
interface IndexedProps {
|
|
8
|
+
[prop: string]: any;
|
|
9
|
+
}
|
|
7
10
|
interface ThemedOptionalProps extends OptionalProps {
|
|
8
11
|
theme: any;
|
|
9
12
|
}
|
|
@@ -13,6 +16,13 @@ interface RequiredProps {
|
|
|
13
16
|
interface ThemedRequiredProps extends RequiredProps {
|
|
14
17
|
theme: any;
|
|
15
18
|
}
|
|
19
|
+
interface IndexedAndRequiredProps extends IndexedProps, RequiredProps { }
|
|
20
|
+
interface ThemedIndexedProps extends IndexedProps {
|
|
21
|
+
theme: any;
|
|
22
|
+
}
|
|
23
|
+
interface ThemedIndexedAndRequiredProps extends IndexedProps, RequiredProps {
|
|
24
|
+
theme: any;
|
|
25
|
+
}
|
|
16
26
|
|
|
17
27
|
declare const theme: any;
|
|
18
28
|
|
|
@@ -79,6 +89,85 @@ function statelessFunctionalComponents() {
|
|
|
79
89
|
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
80
90
|
}
|
|
81
91
|
|
|
92
|
+
function indexedProps() {
|
|
93
|
+
const Component = (props: IndexedProps) => <div>{props.text}</div>;
|
|
94
|
+
|
|
95
|
+
const StyledComponent = styled(Component)``;
|
|
96
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
97
|
+
|
|
98
|
+
<Component />; // text is optional through index signature
|
|
99
|
+
<Component text="test" />; // text is allowed through index signature
|
|
100
|
+
<StyledComponent />; // text is optional through index signature
|
|
101
|
+
<StyledComponent text="test" />; // text is allowed through index signature; theme is optional
|
|
102
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
103
|
+
<StyledStyledComponent />; // text is optional through index signature
|
|
104
|
+
<StyledStyledComponent text="test" />; // text is allowed through index signature; theme is optional
|
|
105
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
function indexedAndRequiredProps() {
|
|
109
|
+
const Component = (props: IndexedAndRequiredProps) => <div>{props.text}</div>;
|
|
110
|
+
|
|
111
|
+
const StyledComponent = styled(Component)``;
|
|
112
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
113
|
+
|
|
114
|
+
// <Component />; // text is required
|
|
115
|
+
<Component text="test" />; // text is required
|
|
116
|
+
<Component text="test" foo="bar" />; // text is required; foo is allowed through index signature
|
|
117
|
+
// <StyledComponent />; // text is required
|
|
118
|
+
// <StyledComponent foo="bar"/>; // text is required; foo is indexed; theme is optional
|
|
119
|
+
<StyledComponent text="test" />; // text is required; theme is optional
|
|
120
|
+
<StyledComponent text="test" foo="bar" />; // text is required; foo is indexed; theme is optional
|
|
121
|
+
<StyledComponent text="test" theme={theme} />; // text is required; theme is allowed
|
|
122
|
+
<StyledComponent text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is allowed
|
|
123
|
+
// <StyledStyledComponent />; // text is required
|
|
124
|
+
// <StyledStyledComponent foo="bar"/>; // text is required; foo is indexed; theme is optional
|
|
125
|
+
<StyledStyledComponent text="test" />; // text is required; theme is optional
|
|
126
|
+
<StyledStyledComponent text="test" foo="bar" />; // text is required; foo is indexed; theme is optional
|
|
127
|
+
<StyledStyledComponent text="test" theme={theme} />; // text is required; theme is allowed
|
|
128
|
+
<StyledStyledComponent text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is allowed
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
function indexedPropsWithRequiredTheme() {
|
|
132
|
+
const Component = (props: ThemedIndexedProps) => <div>{props.text}</div>;
|
|
133
|
+
|
|
134
|
+
const StyledComponent = styled(Component)``;
|
|
135
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
// <Component />; // theme is required
|
|
139
|
+
<Component theme={theme} />; // theme is required
|
|
140
|
+
<Component foo="bar" theme={theme} />; // theme is required; foo is indexed prop
|
|
141
|
+
<StyledComponent />; // theme is optional
|
|
142
|
+
<StyledComponent foo="bar" />; // theme is optional; foo is indexed prop
|
|
143
|
+
<StyledComponent foo="bar" theme={theme} />; // theme is allowed; foo is indexed prop
|
|
144
|
+
<StyledStyledComponent />; // theme is optional
|
|
145
|
+
<StyledStyledComponent foo="bar" />; // theme is optional; foo is indexed prop
|
|
146
|
+
<StyledStyledComponent foo="bar" theme={theme} />; // theme is allowed; foo is indexed prop
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
function indexedAndRequiredPropsWithRequiredTheme() {
|
|
150
|
+
const Component = (props: ThemedIndexedAndRequiredProps) => <div>{props.text}</div>;
|
|
151
|
+
|
|
152
|
+
const StyledComponent = styled(Component)``;
|
|
153
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
154
|
+
|
|
155
|
+
// <Component />; // text and theme are required
|
|
156
|
+
// <Component text="test" />; // theme is required
|
|
157
|
+
// <Component text="test" foo="bar" />; theme is required
|
|
158
|
+
<Component text="foo" theme={theme} />; // text is required; theme is required
|
|
159
|
+
<Component text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is required
|
|
160
|
+
// <StyledComponent />; // text is required; theme is optional
|
|
161
|
+
// <StyledComponent foo="bar"/>; // text is required; theme is optional
|
|
162
|
+
<StyledComponent text="test" />; // text is required; theme is optional
|
|
163
|
+
<StyledComponent text="test" foo="bar" />; // text is required; theme is optional; foo is indexed
|
|
164
|
+
<StyledComponent text="test" theme={theme} />; // text is required; theme is allowed
|
|
165
|
+
<Component text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is allowed
|
|
166
|
+
// <StyledStyledComponent />; // text is required; theme is optional
|
|
167
|
+
// <StyledStyledComponent foo="bar"/>; // text is required; theme is optional
|
|
168
|
+
<StyledStyledComponent text="test" />; // text is indexed; theme is optional
|
|
169
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
170
|
+
}
|
|
82
171
|
}
|
|
83
172
|
|
|
84
173
|
// Tests of pure components
|
|
@@ -151,6 +240,94 @@ function pureComponents() {
|
|
|
151
240
|
<StyledStyledComponent text="test" />; // theme is optional
|
|
152
241
|
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
153
242
|
}
|
|
243
|
+
|
|
244
|
+
function indexedProps() {
|
|
245
|
+
class Component extends React.PureComponent<IndexedProps> {
|
|
246
|
+
render() { return <div>{this.props.text}</div>; }
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const StyledComponent = styled(Component)``;
|
|
250
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
251
|
+
|
|
252
|
+
<Component />; // text is optional through index signature
|
|
253
|
+
<Component text="test" />; // text is allowed through index signature
|
|
254
|
+
<StyledComponent />; // text is optional through index signature
|
|
255
|
+
<StyledComponent text="test" />; // text is allowed through index signature; theme is optional
|
|
256
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
257
|
+
<StyledStyledComponent />; // text is optional through index signature
|
|
258
|
+
<StyledStyledComponent text="test" />; // text is allowed through index signature; theme is optional
|
|
259
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
function indexedAndRequiredProps() {
|
|
263
|
+
class Component extends React.PureComponent<IndexedAndRequiredProps> {
|
|
264
|
+
render() { return <div>{this.props.text}</div>; }
|
|
265
|
+
}
|
|
266
|
+
|
|
267
|
+
const StyledComponent = styled(Component)``;
|
|
268
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
269
|
+
|
|
270
|
+
// <Component />; // text is required
|
|
271
|
+
<Component text="test" />; // text is required
|
|
272
|
+
<Component text="test" foo="bar" />; // text is required; foo is allowed through index signature
|
|
273
|
+
// <StyledComponent />; // text is required
|
|
274
|
+
// <StyledComponent foo="bar"/>; // text is required; foo is indexed; theme is optional
|
|
275
|
+
<StyledComponent text="test" />; // text is required; theme is optional
|
|
276
|
+
<StyledComponent text="test" foo="bar" />; // text is required; foo is indexed; theme is optional
|
|
277
|
+
<StyledComponent text="test" theme={theme} />; // text is required; theme is allowed
|
|
278
|
+
<StyledComponent text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is allowed
|
|
279
|
+
// <StyledStyledComponent />; // text is required
|
|
280
|
+
// <StyledStyledComponent foo="bar"/>; // text is required; foo is indexed; theme is optional
|
|
281
|
+
<StyledStyledComponent text="test" />; // text is required; theme is optional
|
|
282
|
+
<StyledStyledComponent text="test" foo="bar" />; // text is required; foo is indexed; theme is optional
|
|
283
|
+
<StyledStyledComponent text="test" theme={theme} />; // text is required; theme is allowed
|
|
284
|
+
<StyledStyledComponent text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is allowed
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
function indexedPropsWithRequiredTheme() {
|
|
288
|
+
class Component extends React.PureComponent<ThemedIndexedProps> {
|
|
289
|
+
render() { return <div>{this.props.text}</div>; }
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
const StyledComponent = styled(Component)``;
|
|
293
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
294
|
+
|
|
295
|
+
|
|
296
|
+
// <Component />; // theme is required
|
|
297
|
+
<Component theme={theme} />; // theme is required
|
|
298
|
+
<Component foo="bar" theme={theme} />; // theme is required; foo is indexed prop
|
|
299
|
+
<StyledComponent />; // theme is optional
|
|
300
|
+
<StyledComponent foo="bar" />; // theme is optional; foo is indexed prop
|
|
301
|
+
<StyledComponent foo="bar" theme={theme} />; // theme is allowed; foo is indexed prop
|
|
302
|
+
<StyledStyledComponent />; // theme is optional
|
|
303
|
+
<StyledStyledComponent foo="bar" />; // theme is optional; foo is indexed prop
|
|
304
|
+
<StyledStyledComponent foo="bar" theme={theme} />; // theme is allowed; foo is indexed prop
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
function indexedAndRequiredPropsWithRequiredTheme() {
|
|
308
|
+
class Component extends React.PureComponent<ThemedIndexedAndRequiredProps> {
|
|
309
|
+
render() { return <div>{this.props.text}</div>; }
|
|
310
|
+
}
|
|
311
|
+
|
|
312
|
+
const StyledComponent = styled(Component)``;
|
|
313
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
314
|
+
|
|
315
|
+
// <Component />; // text and theme are required
|
|
316
|
+
// <Component text="test" />; // theme is required
|
|
317
|
+
// <Component text="test" foo="bar" />; theme is required
|
|
318
|
+
<Component text="foo" theme={theme} />; // text is required; theme is required
|
|
319
|
+
<Component text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is required
|
|
320
|
+
// <StyledComponent />; // text is required; theme is optional
|
|
321
|
+
// <StyledComponent foo="bar"/>; // text is required; theme is optional
|
|
322
|
+
<StyledComponent text="test" />; // text is required; theme is optional
|
|
323
|
+
<StyledComponent text="test" foo="bar" />; // text is required; theme is optional; foo is indexed
|
|
324
|
+
<StyledComponent text="test" theme={theme} />; // text is required; theme is allowed
|
|
325
|
+
<Component text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is allowed
|
|
326
|
+
// <StyledStyledComponent />; // text is required; theme is optional
|
|
327
|
+
// <StyledStyledComponent foo="bar"/>; // text is required; theme is optional
|
|
328
|
+
<StyledStyledComponent text="test" />; // text is indexed; theme is optional
|
|
329
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
330
|
+
}
|
|
154
331
|
}
|
|
155
332
|
|
|
156
333
|
// Tests of classic components
|
|
@@ -223,4 +400,92 @@ function classicComponents() {
|
|
|
223
400
|
<StyledStyledComponent text="test" />; // theme is optional
|
|
224
401
|
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
225
402
|
}
|
|
403
|
+
|
|
404
|
+
function indexedProps() {
|
|
405
|
+
class Component extends React.Component<IndexedProps> {
|
|
406
|
+
render() { return <div>{this.props.text}</div>; }
|
|
407
|
+
}
|
|
408
|
+
|
|
409
|
+
const StyledComponent = styled(Component)``;
|
|
410
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
411
|
+
|
|
412
|
+
<Component />; // text is optional through index signature
|
|
413
|
+
<Component text="test" />; // text is allowed through index signature
|
|
414
|
+
<StyledComponent />; // text is optional through index signature
|
|
415
|
+
<StyledComponent text="test" />; // text is allowed through index signature; theme is optional
|
|
416
|
+
<StyledComponent text="test" theme={theme} />; // theme is allowed
|
|
417
|
+
<StyledStyledComponent />; // text is optional through index signature
|
|
418
|
+
<StyledStyledComponent text="test" />; // text is allowed through index signature; theme is optional
|
|
419
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
function indexedAndRequiredProps() {
|
|
423
|
+
class Component extends React.Component<IndexedAndRequiredProps> {
|
|
424
|
+
render() { return <div>{this.props.text}</div>; }
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
const StyledComponent = styled(Component)``;
|
|
428
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
429
|
+
|
|
430
|
+
// <Component />; // text is required
|
|
431
|
+
<Component text="test" />; // text is required
|
|
432
|
+
<Component text="test" foo="bar" />; // text is required; foo is allowed through index signature
|
|
433
|
+
// <StyledComponent />; // text is required
|
|
434
|
+
// <StyledComponent foo="bar"/>; // text is required; foo is indexed; theme is optional
|
|
435
|
+
<StyledComponent text="test" />; // text is required; theme is optional
|
|
436
|
+
<StyledComponent text="test" foo="bar" />; // text is required; foo is indexed; theme is optional
|
|
437
|
+
<StyledComponent text="test" theme={theme} />; // text is required; theme is allowed
|
|
438
|
+
<StyledComponent text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is allowed
|
|
439
|
+
// <StyledStyledComponent />; // text is required
|
|
440
|
+
// <StyledStyledComponent foo="bar"/>; // text is required; foo is indexed; theme is optional
|
|
441
|
+
<StyledStyledComponent text="test" />; // text is required; theme is optional
|
|
442
|
+
<StyledStyledComponent text="test" foo="bar" />; // text is required; foo is indexed; theme is optional
|
|
443
|
+
<StyledStyledComponent text="test" theme={theme} />; // text is required; theme is allowed
|
|
444
|
+
<StyledStyledComponent text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is allowed
|
|
445
|
+
}
|
|
446
|
+
|
|
447
|
+
function indexedPropsWithRequiredTheme() {
|
|
448
|
+
class Component extends React.Component<ThemedIndexedProps> {
|
|
449
|
+
render() { return <div>{this.props.text}</div>; }
|
|
450
|
+
}
|
|
451
|
+
|
|
452
|
+
const StyledComponent = styled(Component)``;
|
|
453
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
454
|
+
|
|
455
|
+
|
|
456
|
+
// <Component />; // theme is required
|
|
457
|
+
<Component theme={theme} />; // theme is required
|
|
458
|
+
<Component foo="bar" theme={theme} />; // theme is required; foo is indexed prop
|
|
459
|
+
<StyledComponent />; // theme is optional
|
|
460
|
+
<StyledComponent foo="bar" />; // theme is optional; foo is indexed prop
|
|
461
|
+
<StyledComponent foo="bar" theme={theme} />; // theme is allowed; foo is indexed prop
|
|
462
|
+
<StyledStyledComponent />; // theme is optional
|
|
463
|
+
<StyledStyledComponent foo="bar" />; // theme is optional; foo is indexed prop
|
|
464
|
+
<StyledStyledComponent foo="bar" theme={theme} />; // theme is allowed; foo is indexed prop
|
|
465
|
+
}
|
|
466
|
+
|
|
467
|
+
function indexedAndRequiredPropsWithRequiredTheme() {
|
|
468
|
+
class Component extends React.Component<ThemedIndexedAndRequiredProps> {
|
|
469
|
+
render() { return <div>{this.props.text}</div>; }
|
|
470
|
+
}
|
|
471
|
+
|
|
472
|
+
const StyledComponent = styled(Component)``;
|
|
473
|
+
const StyledStyledComponent = styled(StyledComponent)``;
|
|
474
|
+
|
|
475
|
+
// <Component />; // text and theme are required
|
|
476
|
+
// <Component text="test" />; // theme is required
|
|
477
|
+
// <Component text="test" foo="bar" />; theme is required
|
|
478
|
+
<Component text="foo" theme={theme} />; // text is required; theme is required
|
|
479
|
+
<Component text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is required
|
|
480
|
+
// <StyledComponent />; // text is required; theme is optional
|
|
481
|
+
// <StyledComponent foo="bar"/>; // text is required; theme is optional
|
|
482
|
+
<StyledComponent text="test" />; // text is required; theme is optional
|
|
483
|
+
<StyledComponent text="test" foo="bar" />; // text is required; theme is optional; foo is indexed
|
|
484
|
+
<StyledComponent text="test" theme={theme} />; // text is required; theme is allowed
|
|
485
|
+
<Component text="test" foo="bar" theme={theme} />; // text is required; foo is indexed; theme is allowed
|
|
486
|
+
// <StyledStyledComponent />; // text is required; theme is optional
|
|
487
|
+
// <StyledStyledComponent foo="bar"/>; // text is required; theme is optional
|
|
488
|
+
<StyledStyledComponent text="test" />; // text is indexed; theme is optional
|
|
489
|
+
<StyledStyledComponent text="test" theme={theme} />; // theme is allowed
|
|
490
|
+
}
|
|
226
491
|
}
|