Skip to content

Instantly share code, notes, and snippets.

@morlay
Created December 3, 2015 15:50
Show Gist options
  • Save morlay/ffd7d1a8b469d4e23917 to your computer and use it in GitHub Desktop.
Save morlay/ffd7d1a8b469d4e23917 to your computer and use it in GitHub Desktop.
A trick way to write nesting css by css-modules
.app {
padding: 6px 20px 30px;
}
.subText {
composes: text from "./Child.css";
color: red;
}
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;
.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;
}
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