Last active
November 23, 2015 02:40
-
-
Save pascalpp/63cba29d3066b43de6a6 to your computer and use it in GitHub Desktop.
using a CSS module 'scope' with less and webpack's css loader
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
'use strict'; | |
var styles = require('./styles.less'); | |
// styles => { 'scope': 'oasduf98aus9df8ja9s8d' } | |
// this view uses the given scope as its classname | |
// so buttons in my view will be gold and green | |
// the color of buttons outside my view will not be affected | |
module.exports = Marionette.LayoutView.extend({ | |
className: styles.scope, | |
template: require('./template.html'), | |
}); | |
// this is a Marionette example, but the same idea | |
// could be used with any view framework (or with vanilla JS) |
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
// :local is a CSS module convention | |
// this will export an object with a `scope` property | |
// the value will be a unique classname to be used in my view | |
:local(.scope) { | |
.button.confirm { | |
background-color: gold; | |
} | |
.button.cancel { | |
background-color: green; | |
} | |
} | |
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
<p>Do you want to save your changes?</p> | |
<div class="button confirm">Save</div> | |
<div class="button cancel">Cancel</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment