Created
October 6, 2015 13:42
-
-
Save renren89/dd4364260a25349c6d13 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
import React, { Component, PropType } from 'react'; | |
import { ListGroup, ListGroupItem, Grid, Row, Input } from 'react-bootstrap'; | |
import Channels from './Channels'; | |
export default class App extends Component { | |
static defaultProps = { | |
channels: [ | |
"reactjs", | |
"general", | |
"random", | |
"flux", | |
"relay", | |
"immutablejs", | |
"flow", | |
"webpack", | |
"babel" | |
] | |
}; | |
constructor(props) { | |
super(props); | |
this.state = { searchQuery: '' }; | |
this.changeSearchQuery = this.changeSearchQuery.bind(this); | |
this.filteredChannels = this.filteredChannels.bind(this); | |
} | |
changeSearchQuery(ev) { | |
this.setState({ searchQuery: ev.target.value }); | |
} | |
filteredChannels() { | |
let { channels } = this.props, | |
{ searchQuery } = this.state; | |
return channels.filter(channel => { | |
return channel.indexOf(searchQuery) === 0; | |
}); | |
} | |
render() { | |
let { channels } = this.filteredChannels(), | |
{ searchQuery } = this.state; | |
return ( | |
<Grid fluid={true}> | |
<Row> | |
<Input type="text" | |
placeholder="Search channels..." | |
bsSize="large" | |
value={searchQuery} | |
onChange={this.changeSearchQuery} /> | |
<Channels channels={channels} /> | |
</Row> | |
</Grid> | |
); | |
} | |
} |
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
import React, { Component } from 'react'; | |
import { ListGroupItem, ListGroup } from 'react-bootstrap'; | |
export default class Channels extends Component { | |
render() { | |
let { channels } = this.props; | |
return ( | |
<ListGroup> | |
{channels.map(channel => | |
<ListGroupItem key={channel} href={`#${channel}`}> | |
#{channel} | |
</ListGroupItem> | |
)} | |
</ListGroup> | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment