File tree Expand file tree Collapse file tree 3 files changed +47
-16
lines changed Expand file tree Collapse file tree 3 files changed +47
-16
lines changed Original file line number Diff line number Diff line change
1
+ # react-css-modules
2
+
3
+ ` index.css ` :
4
+
5
+ ``` css
6
+ .foo {
7
+ color : #f00 ;
8
+ }
9
+ ```
10
+
11
+ ` Rainbow.js ` :
12
+
13
+ ``` js
14
+ import React from ' react' ;
15
+ import styles from ' ./index.css' ;
16
+ import CSSModules from ' react-css-modules' ;
17
+
18
+ class Rainbow extends React .Component {
19
+ render () {
20
+ return < div>
21
+ < span className= ' foo' > I am rainbow! < / span>
22
+ < span className= ' bar' > I am rainbow! < / span>
23
+ < / div> ;
24
+ }
25
+ }
26
+
27
+ export default CSSModules (Rainbow, styles);
28
+ ```
29
+
30
+ When used, this component will generate:
31
+
32
+ ``` html
33
+ <div data-reactid =" .0" >
34
+ <div data-reactid =" .0.0" >
35
+ <span class =" foo index__foo___1fSgh" data-reactid =" .0.0.0" >I am rainbow!</span >
36
+ <span class =" bar" data-reactid =" .0.0.1" >I am rainbow!</span >
37
+ </div >
38
+ </div >
39
+ ```
Original file line number Diff line number Diff line change @@ -82,6 +82,7 @@ exports['default'] = function (Target, styles) {
82
82
83
83
if ( ( 0 , _lodashLangIsArray2 [ 'default' ] ) ( element . props . children ) ) {
84
84
element . props . children = element . props . children . map ( function ( node ) {
85
+ // React.isValidElement
85
86
if ( node instanceof element . constructor ) {
86
87
return changeClass ( node ) ;
87
88
} else {
@@ -108,19 +109,11 @@ exports['default'] = function (Target, styles) {
108
109
}
109
110
110
111
_createClass ( CSSModules , [ {
111
- key : 'componentDidMount' ,
112
- value : function componentDidMount ( ) {
113
- console . log ( 'OK' ) ;
114
- }
115
- } , {
116
112
key : 'render' ,
117
113
value : function render ( ) {
118
- // <Target />
119
- return _react2 [ 'default' ] . createElement (
120
- 'div' ,
121
- { ref : 'test' } ,
122
- 'test'
123
- ) ;
114
+ // At this point I would need to use linkClass, but I cannot find a way to access
115
+ // children of Target.
116
+ return _react2 [ 'default' ] . createElement ( Target , { ref : 'test' } ) ;
124
117
}
125
118
} ] ) ;
126
119
Original file line number Diff line number Diff line change @@ -57,6 +57,7 @@ export default (Target, styles) => {
57
57
58
58
if ( isArray ( element . props . children ) ) {
59
59
element . props . children = element . props . children . map ( ( node ) => {
60
+ // React.isValidElement
60
61
if ( node instanceof element . constructor ) {
61
62
return changeClass ( node ) ;
62
63
} else {
@@ -74,12 +75,10 @@ export default (Target, styles) => {
74
75
} ;
75
76
76
77
return class CSSModules extends React . Component {
77
- componentDidMount ( ) {
78
- console . log ( 'OK' ) ;
79
- }
80
78
render ( ) {
81
- // <Target />
82
- return < div ref = 'test' > test</ div > ;
79
+ // At this point I would need to use linkClass, but I cannot find a way to access
80
+ // children of Target.
81
+ return < Target ref = 'test' /> ;
83
82
}
84
83
}
85
84
} ;
You can’t perform that action at this time.
0 commit comments