// Webpack config { test: /\.scss$/, loaders: [ 'style', 'css', 'autoprefixer-loader?browsers=last 2 version', 'sass' ] }
// Components import 'assets/styles/components/jobs.scss'
CSS has fundamental flaws at scale that can be solved by writing styles in JS. #openyourmind https://t.co/FeesMwPmc8 pic.twitter.com/D5v3ouXnPo
— Vjeux (@Vjeux) November 8, 2014import Stylesheet from 'react-style'; const styles = Stylesheet.create({ button: { padding: '0.7rem', textTransform: 'uppercase' } });
render() { const customColor = { color: this.props.color }; return ( <button styles={[styles.button, customColor]}> Click me! </button> ); }
It's all Javascript
const variables = { brandColor: 'red', gutterSize: 40 } export default variables;
import Stylesheet from 'react-style'; import { brandColor } from 'shared/variables'; const styles = Stylesheet.create({ button: { backgroundColor: brandColor } });
const styles = Stylesheet.create({ button: { width: '4rem' }, '@media screen and (max-device-width: 736px)': { button: { width: '100%' } } });
@withHover class SubmitButton extends React.Component { const styles = Stylesheet.create({ button: { backgroundColor: 'red' }, hover: { opacity: '0.8' } }); render() { const hoverStyle = this.props.hover ? styles.hover : null; const buttonStyles = [ styles.button, hoverStyle ]; return ( <button styles={buttonStyles}>Click me!</button> ); } }
render() { return ( <InnerContent> <h2>Layout can be hard...</h2> <p>to handle</p> </InnerContent> ); }