Skip to content

Instantly share code, notes, and snippets.

@mindspank
Created May 31, 2015 16:04
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 mindspank/e63f1d83929a0b48b3f6 to your computer and use it in GitHub Desktop.
Save mindspank/e63f1d83929a0b48b3f6 to your computer and use it in GitHub Desktop.
reactjs filter
var Data = {
title: 'Member State',
row: [{
state: 'S',
qText: 'Europe'
},{
state: 'S',
qText: 'Asia'
},{
state: 'S',
qText: 'Africa'
}]
};
var Item = React.createClass({
render: function() {
return <li>{this.props.item.qText}</li>;
}
});
var FilterItems = React.createClass({
show: function() {
},
render: function() {
return <div className={'items'}>
<ul>
{this.props.items.map(function(item, i) {
return <Item item = {item} />;
})}
</ul>
</div>;
}
});
var Title = React.createClass({
render: function() {
return <div className={'title'}>
{this.props.data.title}
<div className={'right'}>
<div className={'count'}> 1 of 4 </div>
<img src={'img/toggle.svg'} />
</div>
</div>
}
})
var Filter = React.createClass({
getInitialState: function() {
return {
listVisible: false
};
},
show: function() {
this.setState({ listVisible: true });
document.addEventListener("click", this.hide);
},
hide: function() {
this.setState({ listVisible: false });
document.removeEventListener("click", this.hide);
},
render: function() {
return <div className={'filter ' + (this.state.listVisible ? 'expanded' : '')} onClick={this.show}>
<Title data={this.props.data} />
<FilterItems items={this.props.data.row} />
</div>;
}
});
React.render(<Filter data={Data} />, document.getElementById("filter-container"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment