Simple JS-based StyleSheets with no cascading.
That's right. There is intentionally no support for 'externalizing' the CSS, or any cascading support. This is a feature. Be explicit. It's best for everyone.
Also a feature: CSS variables are expanded as soon as the objects are merged. So no, you can't change a variable and have it automatically update any currently rendered nodes.
Example usage:
var S= require('./style-builder.js')
S.vars({
defaultColor: 'dodgerblue',
shadowColor: 'rgba(0,0,255, 0.2)'
})
var Button= S({
border: '1px solid @defaultColor',
color: '@defaultColor',
boxShadow: '0 0 0 2px @shadowColor' // Auto-prefixed via react-prefixr
})
// No cascade, but you can 'Subclass' existing styles
var DangerButton= S(Button, {
borderColor: 'red',
color: 'red
})
module.exports= React.createClass({
render() {
var {styles, ...rest}= this.props
return (
<div {...rest} styles={ S(DangerButton, styles || {}) }>
{ this.props.children }
</div>
}
}
})
- Support "CSS-style" variables:
var(var-name)
- Mayhaps: Add support for deferring variable merging until usage. It would allow for a more dynamic stylesheet, but it would no longer be a simple object.
Copyright © 2014 Matt McCray matt@elucidata
This work is free. You can redistribute it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar. See http://www.wtfpl.net/ for more details.