@@ -21,9 +21,10 @@ const DEFAULT_OPTIONS = {
21
21
mapThemrProps : defaultMapThemrProps
22
22
}
23
23
24
- const THEMR_CONFIG = typeof Symbol !== 'undefined' ?
25
- Symbol ( 'THEMR_CONFIG' ) :
26
- '__REACT_CSS_THEMR_CONFIG__'
24
+ const THEMR_CONFIG =
25
+ typeof Symbol !== 'undefined'
26
+ ? Symbol ( 'THEMR_CONFIG' )
27
+ : '__REACT_CSS_THEMR_CONFIG__'
27
28
28
29
/**
29
30
* Themr decorator
@@ -32,7 +33,7 @@ const THEMR_CONFIG = typeof Symbol !== 'undefined' ?
32
33
* @param {{} } [options] - Themr options
33
34
* @returns {function(ThemedComponent:Function):Function } - ThemedComponent
34
35
*/
35
- export default ( componentName , localTheme , options = { } ) => ( ThemedComponent ) => {
36
+ export default ( componentName , localTheme , options = { } ) => ThemedComponent => {
36
37
const {
37
38
composeTheme : optionComposeTheme ,
38
39
mapThemrProps : optionMapThemrProps
@@ -54,15 +55,21 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
54
55
* @property {{wrappedInstance: *} } refs
55
56
*/
56
57
class Themed extends Component {
57
- static displayName = `Themed${ ( ThemedComponent . displayName || ThemedComponent . name || "Component" ) } ` ;
58
+ static displayName = `Themed${ ThemedComponent . displayName ||
59
+ ThemedComponent . name ||
60
+ 'Component' } `
58
61
59
62
static contextTypes = {
60
63
themr : PropTypes . object
61
64
}
62
65
63
66
static propTypes = {
64
67
...ThemedComponent . propTypes ,
65
- composeTheme : PropTypes . oneOf ( [ COMPOSE_DEEPLY , COMPOSE_SOFTLY , DONT_COMPOSE ] ) ,
68
+ composeTheme : PropTypes . oneOf ( [
69
+ COMPOSE_DEEPLY ,
70
+ COMPOSE_SOFTLY ,
71
+ DONT_COMPOSE
72
+ ] ) ,
66
73
innerRef : PropTypes . func ,
67
74
theme : PropTypes . object ,
68
75
themeNamespace : PropTypes . string ,
@@ -81,9 +88,10 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
81
88
}
82
89
83
90
getWrappedInstance ( ) {
84
- invariant ( true ,
91
+ invariant (
92
+ true ,
85
93
'DEPRECATED: To access the wrapped instance, you have to pass ' +
86
- '{ innerRef: fn } and retrieve with a callback ref style.'
94
+ '{ innerRef: fn } and retrieve with a callback ref style.'
87
95
)
88
96
89
97
return this . refs . wrappedInstance
@@ -94,13 +102,21 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
94
102
if ( ! themeNamespace ) return theme
95
103
96
104
if ( themeNamespace && ! theme ) {
97
- throw new Error ( 'Invalid themeNamespace use in friendsofreactjs/react-css-themr. ' +
98
- 'themeNamespace prop should be used only with theme prop.' )
105
+ throw new Error (
106
+ 'Invalid themeNamespace use in friendsofreactjs/react-css-themr. ' +
107
+ 'themeNamespace prop should be used only with theme prop.'
108
+ )
99
109
}
100
110
101
111
return Object . keys ( theme )
102
112
. filter ( key => key . startsWith ( themeNamespace ) )
103
- . reduce ( ( result , key ) => ( { ...result , [ removeNamespace ( key , themeNamespace ) ] : theme [ key ] } ) , { } )
113
+ . reduce (
114
+ ( result , key ) => ( {
115
+ ...result ,
116
+ [ removeNamespace ( key , themeNamespace ) ] : theme [ key ]
117
+ } ) ,
118
+ { }
119
+ )
104
120
}
105
121
106
122
getThemeNotComposed ( props ) {
@@ -118,14 +134,14 @@ export default (componentName, localTheme, options = {}) => (ThemedComponent) =>
118
134
getTheme ( props ) {
119
135
return props . composeTheme === COMPOSE_SOFTLY
120
136
? {
121
- ...this . getContextTheme ( ) ,
122
- ...config . localTheme ,
123
- ...this . getNamespacedTheme ( props )
124
- }
137
+ ...this . getContextTheme ( ) ,
138
+ ...config . localTheme ,
139
+ ...this . getNamespacedTheme ( props )
140
+ }
125
141
: themeable (
126
- themeable ( this . getContextTheme ( ) , config . localTheme ) ,
127
- this . getNamespacedTheme ( props )
128
- )
142
+ themeable ( this . getContextTheme ( ) , config . localTheme ) ,
143
+ this . getNamespacedTheme ( props )
144
+ )
129
145
}
130
146
131
147
calcTheme ( props ) {
@@ -208,7 +224,9 @@ function merge(original = {}, mixin = {}) {
208
224
209
225
default : {
210
226
//can't merge an object with a non-object
211
- throw new Error ( `You are merging object ${ key } with a non-object ${ originalValue } ` )
227
+ throw new Error (
228
+ `You are merging object ${ key } with a non-object ${ originalValue } `
229
+ )
212
230
}
213
231
}
214
232
break
@@ -225,7 +243,9 @@ function merge(original = {}, mixin = {}) {
225
243
switch ( typeof originalValue ) {
226
244
case 'object' : {
227
245
//can't merge a non-object with an object
228
- throw new Error ( `You are merging non-object ${ mixinValue } with an object ${ key } , (can occur when using empty or :global only base theme stylesheet)` )
246
+ throw new Error (
247
+ `You are merging non-object ${ mixinValue } with an object ${ key } , (can occur when using empty or :global only base theme stylesheet)`
248
+ )
229
249
}
230
250
231
251
case 'undefined' : {
@@ -240,9 +260,12 @@ function merge(original = {}, mixin = {}) {
240
260
241
261
default : {
242
262
//finally we can merge
243
- result [ key ] = originalValue . split ( ' ' )
263
+ result [ key ] = originalValue
264
+ . split ( ' ' )
244
265
. concat ( mixinValue . split ( ' ' ) )
245
- . filter ( ( item , pos , self ) => self . indexOf ( item ) === pos && item !== '' )
266
+ . filter (
267
+ ( item , pos , self ) => self . indexOf ( item ) === pos && item !== ''
268
+ )
246
269
. join ( ' ' )
247
270
break
248
271
}
@@ -263,7 +286,9 @@ function merge(original = {}, mixin = {}) {
263
286
* @returns {undefined }
264
287
*/
265
288
function validateComposeOption ( composeTheme ) {
266
- if ( [ COMPOSE_DEEPLY , COMPOSE_SOFTLY , DONT_COMPOSE ] . indexOf ( composeTheme ) === - 1 ) {
289
+ if (
290
+ [ COMPOSE_DEEPLY , COMPOSE_SOFTLY , DONT_COMPOSE ] . indexOf ( composeTheme ) === - 1
291
+ ) {
267
292
throw new Error (
268
293
`Invalid composeTheme option for friendsofreactjs/react-css-themr. Valid composition options\
269
294
are ${ COMPOSE_DEEPLY } , ${ COMPOSE_SOFTLY } and ${ DONT_COMPOSE } . The given\
@@ -294,10 +319,10 @@ function removeNamespace(key, themeNamespace) {
294
319
*/
295
320
function defaultMapThemrProps ( ownProps , theme ) {
296
321
const {
297
- composeTheme, //eslint-disable-line no-unused-vars
322
+ composeTheme, //eslint-disable-line no-unused-vars
298
323
innerRef,
299
324
themeNamespace, //eslint-disable-line no-unused-vars
300
- mapThemrProps, //eslint-disable-line no-unused-vars
325
+ mapThemrProps, //eslint-disable-line no-unused-vars
301
326
...rest
302
327
} = ownProps
303
328
0 commit comments