Skip to content

Instantly share code, notes, and snippets.

@bensmithett
Created August 7, 2014 13:19
Show Gist options
  • Save bensmithett/20063151bfe8f173d2d7 to your computer and use it in GitHub Desktop.
Save bensmithett/20063151bfe8f173d2d7 to your computer and use it in GitHub Desktop.
Trying out react-style
/**
* @jsx React.DOM
*/
"use strict";
var React = require("react/addons");
var ReactStyle = require("react-style");
var MyComponent = React.createClass({
css: ReactStyle(function () {
return {
backgroundColor: "green",
"> b": {
fontStyle: "italic"
}
};
}),
css__subcomponent: ReactStyle(function () {
return {
backgroundColor: "blue",
color: "white"
};
}),
render: function () {
return(
<div styles={this.css()}>
This is a <b styles={this.css__subcomponent()}>Rad Component!!!</b>
</div>
);
}
});
module.exports = MyComponent;
<div class="a" data-reactid=".0">
<span data-reactid=".0.0">This is a </span>
<b class="b" data-reactid=".0.1">Rad Component!!!</b>
</div>
.a { background-color: green; }
.a > b { font-style: italic; }
.b { background-color: blue; color: white; }
@SanderSpies
Copy link

I see that you are using a feature I didn't know we had - cascading (tnx css-builder!). Due to the problems that come with it, which is mostly caused by implicit behaviour, this will be disabled in the next version. Sorry for the inconvenience.

I am thinking of adding a form of cascading that is more explicit, and therefore easier to maintain. Something in the direction of:

foo: ReactStyle(function(){
   return {
     backgroundColor: 'white',
     text: {
       color: 'black'
     }
   }
})
<div styles={this.foo()}>
<div styles={this.foo().text}>
</div>
</div>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment