Skip to content

Instantly share code, notes, and snippets.

@motleydev
Created March 19, 2015 10:48
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 motleydev/6d5e980e4d90cc5d52fd to your computer and use it in GitHub Desktop.
Save motleydev/6d5e980e4d90cc5d52fd to your computer and use it in GitHub Desktop.
var Tabs = React.createClass({
handleClick: function(event){
event.preventDefault();
console.log(this);
},
render: function(){
var self = this;
var tabs = this.props.tabs.map(function(tab,index){
var clickHandler = self.handleClick;
return (<li key={'tab'+index}><a ref={'tab'+index} href="#" onClick={clickHandler} > {tab.meta.title}</a></li>)
});
return (
<nav>
<ul>
{tabs}
</ul>
</nav>
)
}
});
var Content = React.createClass({
render: function(){
return(
<article>
<header>
<h4>{this.props.content.meta.title}</h4>
</header>
<section>
{this.props.content.content}
</section>
</article>
)
}
});
var Images = React.createClass({
render: function(){
var images = this.props.images.map(function(image,index){
var imageUrl = image.meta.image;
var imageStyle = {
backgroundImage: 'url("/images/'+imageUrl+'")'
};
return (<article key={image+index} style={imageStyle}></article>)
});
return(
<section>
{images}
</section>
)
}
});
var Container = React.createClass({
getInitialState: function(){
return({
activeIndex: 0
})
},
changeTabs: function(index){
this.setState({activeIndex: index});
console.log(index)
},
render: function(){
var content = this.props.content[this.state.activeIndex];
return (
<section className="wrapper grid-text-top">
<Tabs tabs={this.props.content} tabHandler={this.changeTabs}/>
<Content content={content}/>
<Images images={this.props.content}/>
</section>
)
}
});
var targetId = '{{currentPage.subRoutes[0].urlSegment}}-1';
React.render(<Container content={machines} />, document.getElementById(targetId));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment