patternplate-transform-cssmodules
patternplate
transform to enable usage of
css modules.
:warning: This transform is intended to be used in conjunction with
patternplate-transform-cssmodules-symbols
to produce markup using the transformed css source
See the Configuration section for details.
Installation
npm install --save patternplate-transform-cssmodules patternplate-transform-cssmodules-symbols
Configuration
module.exports = {
formats: {
css: {
name: 'Style',
transforms: ['cssmodules']
},
jsx: {
name: 'Markup',
transforms: ['cssmodules-symbols', 'react', 'react-to-markup']
}
}
};
module.exports = {
'cssmodules-symbols': {
inFormat: 'jsx',
outFormat: 'jsx'
},
cssmodules: {
inFormat: 'css',
outFormat: 'css'
}
};
Usage
Sources
import styles from 'style://Pattern';
import cx from 'classnames';
const className = cx(styles.default, {
[styles.disabled]: this.props.disabled
});
<button className={className}>
{this.props.children}
</button>
.default {
padding: 5px 10px;
background: blue;
color: white;
}
.disabled {
background: grey;
}
Transformed
<button class="_button_4erg9ut2">
Lorem Ipsum dolor si amnet
</button>
<button class="_button_4erg9ut2 _button_iert9832">
Lorem Ipsum dolor si amnet
</button>
._button_4erg9ut2 {
padding: 5px 10px;
background: blue;
color: white;
}
._button_iert9832 {
background: grey;
}