Last active
August 29, 2015 14:27
-
-
Save namuol/a64b58b8902bfc30bb59 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
var Style = require('react-free-style').create() | |
var BUTTON_STYLE = Style.registerStyle({ | |
backgroundColor: 'red', | |
padding: 10 | |
}) | |
var ButtonComponent = Style.component(React.createClass({ | |
// You must define `contextTypes` to access `freeStyle`. | |
contextTypes: { | |
freeStyle: React.PropTypes.object.isRequired | |
}, | |
componentWillMount: function () { | |
this.inlineStyle = this.context.freeStyle.registerStyle(this.props.style) | |
}, | |
componentWillUnmount: function () { | |
this.context.freeStyle.remove(this.inlineStyle) | |
}, | |
render: function () { | |
return ( | |
<button | |
className={Style.join(this.inlineStyle.className, BUTTON_STYLE.className)}> | |
{this.props.children} | |
</button> | |
) | |
} | |
})) | |
var App = Style.component(React.createClass({ | |
render: function () { | |
return ( | |
<div> | |
<ButtonComponent style={{ | |
backgroundColor: this.props.bgColor, | |
}}> | |
Hello world! | |
</ButtonComponent> | |
<Style.Element /> | |
</div> | |
) | |
} | |
})) | |
React.render(<App bgColor={`rgb(${Math.random()*255},${Math.random()*255},${Math.random()*255}`} />, document.body) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment