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.
Files changed (45) hide show
  1. package/CHANGELOG.md +21 -1
  2. package/dist/styled-components-no-parser.browser.cjs.js +24 -21
  3. package/dist/styled-components-no-parser.browser.cjs.js.map +1 -1
  4. package/dist/styled-components-no-parser.browser.es.js +24 -21
  5. package/dist/styled-components-no-parser.browser.es.js.map +1 -1
  6. package/dist/styled-components-no-parser.cjs.js +24 -21
  7. package/dist/styled-components-no-parser.cjs.js.map +1 -1
  8. package/dist/styled-components-no-parser.es.js +24 -21
  9. package/dist/styled-components-no-parser.es.js.map +1 -1
  10. package/dist/styled-components-primitives.cjs.js +17 -7
  11. package/dist/styled-components-primitives.cjs.js.map +1 -1
  12. package/dist/styled-components-primitives.es.js +17 -7
  13. package/dist/styled-components-primitives.es.js.map +1 -1
  14. package/dist/styled-components.browser.cjs.js +24 -21
  15. package/dist/styled-components.browser.cjs.js.map +1 -1
  16. package/dist/styled-components.browser.cjs.min.js +1 -1
  17. package/dist/styled-components.browser.cjs.min.js.map +1 -1
  18. package/dist/styled-components.browser.es.js +24 -21
  19. package/dist/styled-components.browser.es.js.map +1 -1
  20. package/dist/styled-components.browser.es.min.js +1 -1
  21. package/dist/styled-components.browser.es.min.js.map +1 -1
  22. package/dist/styled-components.cjs.js +24 -21
  23. package/dist/styled-components.cjs.js.map +1 -1
  24. package/dist/styled-components.cjs.min.js +1 -1
  25. package/dist/styled-components.cjs.min.js.map +1 -1
  26. package/dist/styled-components.es.js +24 -21
  27. package/dist/styled-components.es.js.map +1 -1
  28. package/dist/styled-components.es.min.js +1 -1
  29. package/dist/styled-components.es.min.js.map +1 -1
  30. package/dist/styled-components.js +24 -21
  31. package/dist/styled-components.js.map +1 -1
  32. package/dist/styled-components.min.js +1 -1
  33. package/dist/styled-components.min.js.map +1 -1
  34. package/dist/styled-components.native.cjs.js +17 -7
  35. package/dist/styled-components.native.cjs.js.map +1 -1
  36. package/docs/tips-and-tricks.md +33 -2
  37. package/package.json +1 -1
  38. package/src/models/StyledComponent.js +28 -24
  39. package/src/models/StyledNativeComponent.js +18 -7
  40. package/src/test/__snapshots__/extending.test.js.snap +3 -0
  41. package/src/test/basic.test.js +32 -1
  42. package/src/test/extending.test.js +79 -23
  43. package/typings/styled-components.d.ts +2 -3
  44. package/typings/tests/issue1068.tsx +265 -0
  45. package/typings/tests/themed-tests/issue1068.tsx +265 -0
@@ -4,6 +4,9 @@ import styled, { MyTheme } from "./mytheme-styled-components";
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: MyTheme;
9
12
  }
@@ -13,6 +16,13 @@ interface RequiredProps {
13
16
  interface ThemedRequiredProps extends RequiredProps {
14
17
  theme: MyTheme;
15
18
  }
19
+ interface IndexedAndRequiredProps extends IndexedProps, RequiredProps { }
20
+ interface ThemedIndexedProps extends IndexedProps {
21
+ theme: MyTheme;
22
+ }
23
+ interface ThemedIndexedAndRequiredProps extends IndexedProps, RequiredProps {
24
+ theme: MyTheme;
25
+ }
16
26
 
17
27
  declare const theme: MyTheme;
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
  }