Guest User

Untitled

a guest
Nov 18th, 2017
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. const Li = styled.li`
  2. border: 0;
  3.  
  4. //Set color to red if this component is selected
  5. ${this.state => this.state.selectedLanguage`
  6. color: 'red';
  7. `}
  8.  
  9. `;
  10.  
  11. class Popular extends Component {
  12. constructor(props) {
  13. super(props);
  14. this.state = {
  15. selectedLanguage: 'All'
  16. }
  17.  
  18. this.updateLanguage = this.updateLanguage.bind(this);
  19. }
  20.  
  21. updateLanguage(lang) {
  22. this.setState(function() {
  23. return {
  24. selectedLanguage: lang
  25. };
  26. });
  27. }
  28. render() {
  29. const languages = ['All', 'Javascript', 'Java', 'Go', 'Rust'];
  30. return (
  31. <ul className={`list-group d-flex flex-row justify-content-center ${this.props.className}`}>
  32. {languages.map(function(lang){
  33. return (
  34. <Li
  35. key={lang}
  36. // style={lang === this.state.selectedLanguage ? {color: '#d00d1b'} : null}
  37. onClick={this.updateLanguage.bind(null, lang)}
  38. className={`list-group-item p-2 ${this.props.className}`}>
  39. {lang}
  40. </Li>
  41. )
  42. }, this)}
  43. </ul>
  44. );
  45. }
  46. }
  47.  
  48. export default Popular;
Add Comment
Please, Sign In to add comment