Created
December 3, 2015 15:50
-
-
Save morlay/ffd7d1a8b469d4e23917 to your computer and use it in GitHub Desktop.
A trick way to write nesting css by css-modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.app { | |
padding: 6px 20px 30px; | |
} | |
.subText { | |
composes: text from "./Child.css"; | |
color: red; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import Child from './Child'; | |
import AppStyles from './App.css'; | |
class App extends React.Component { | |
render() { | |
return ( | |
<div className={AppStyles.app}> | |
<Child classNames={{ | |
text: AppStyles.subText | |
}}/> | |
</div> | |
); | |
} | |
}; | |
export default App; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.root { | |
border-width: 2px; | |
border-style: solid; | |
border-color: #777; | |
padding: 0 20px; | |
margin: 0 6px; | |
max-width: 400px; | |
} | |
.text { | |
color: #777; | |
font-family: helvetica, arial, sans-serif; | |
font-weight: 600; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React from 'react'; | |
import ChildStyles from './Child.css'; | |
class Child extends React.Component { | |
render() { | |
const newStyles = Object.assign(ChildStyles, this.props.classNames || {}); | |
return ( | |
<div className={ newStyles.root }> | |
<p className={ newStyles.text }>Scoped Selectors</p> | |
</div> | |
); | |
} | |
} | |
export default Child |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment