platformbutton.jsx 1.1 KB

123456789101112131415161718192021222324252627282930313233343536
  1. var Preact = require('preact');
  2. var h = require('preact').h;
  3. var createClass = require('preact-compat').createClass;
  4. var PlatformButton = createClass({
  5. getInitialState: function() {
  6. return {
  7. isActive: this.props.initiallyActive
  8. };
  9. },
  10. onClick: function() {
  11. this.props.toggleCondition('platforms', this.props.keyword);
  12. this.setState(function(prevState, currentProps) {
  13. return {
  14. isActive: !prevState.isActive
  15. };
  16. });
  17. },
  18. render: function() {
  19. if(this.state.isActive) {
  20. return (
  21. <button className="btn btn-primary" onClick={this.onClick}>
  22. <span className="glyphicon glyphicon-ok"></span><i>&nbsp;</i>{this.props.platform}
  23. </button>
  24. );
  25. } else {
  26. return (
  27. <button className="btn btn-default" onClick={this.onClick}>
  28. {this.props.platform}
  29. </button>
  30. );
  31. }
  32. }
  33. });
  34. module.exports = PlatformButton;