Skip to content

Instantly share code, notes, and snippets.

@haustraliaer
Last active August 29, 2015 14:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haustraliaer/85aced44471109b3db09 to your computer and use it in GitHub Desktop.
Save haustraliaer/85aced44471109b3db09 to your computer and use it in GitHub Desktop.
Everything is private to it's local context with no global side effects. But our library component allows it's parent to overide styles (without defining a million props).
.root {
width: 200px;
height: 200px;
background-color: red;
}
.title {
font-size: 20px;
}
/* here you just need to know what classes the library uses */
.root {
width: 500px;
height: auto;
background-color: green;
}
/* for the lib style */
.library__root__3wefoi2 {
width: 200px;
height: 200px;
background-color: red;
}
.library__title__ewflnw3 {
font-size: 20px;
}
/* for the wrapping style */
.wrapping__root__wk3jn2o {
width: 500px;
height: auto;
background-color: green;
}
<!-- and the output markup, if I use the wrapping style -->
<div className='wrapping__root__wk3jn2o'>
<h2 className='library__title__ewflnw3'>Hello contrived example</h2>
</div>
var style = require('library.css')
if(typeof this.props.style !== 'undefined') {
// style is just an object (if using webpack/postcss) so we can use js to overide class keys
// (arbitrary merge function)
merge(style, this.props.style)
}
render() {
return (
<div className={style.root}>
<h2 className={style.title}>Hello contrived example</h2>
</div>
)
}
// The wrapping component
var SomeLibraryComponent = require('SomeLibraryComponent')
var overidingStyle = require('libraryWrapper.css')
render() {
return (
<SomeLibraryComponent style={overidingStyle}
)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment