Skip welcome & menu and move to editor
Welcome to JS Bin
Load cached copy from
 
<!DOCTYPE html>
<html>
<head>
<!-- uncomment for React master
<script src="http://react.zpao.com/builds/master/latest/react.js"></script>
-->
<script src="//fb.me/react-with-addons-0.13.1.js"></script>
  <meta charset="utf-8">
  <title>JS Bin</title>
</head>
<body>
</body>
</html>
 
function bits(n){
  var res = [];
  while(n){
    res.push(n & 1);
    n >>= 1;
  }
  return res;
}
class App extends React.Component {
  constructor(){
    super();
    this.state = {buttons: 0};
  }
  
  render(){
    const preventDefault = (e) => { e.preventDefault() }
    const handleChange = (e) => {
      preventDefault(e);
      this.setState({buttons: e.buttons});
    };
    
    var names = [
      'Left', 'Right', 'Middle', 'Back', 'Forward'
    ];
    
    // buttons is a bitmask
    var pad = "00000";
    var buttons = bits(this.state.buttons).concat([0, 0, 0, 0, 0]).slice(0, names.length);
    
    var active = buttons.map((x, i) => {
      return <div>{names[i]}: {x === 1 ? 'Yes' : 'No'}</div>;
    });
    
    
    return (
      <section 
        onContextMenu={preventDefault}
        onMouseDown={handleChange}
        tabIndex={-1}>
        <div>
          <h4>Buttons: {this.state.buttons} ({buttons.join('')})</h4>
          {active}
        </div>
      </section>
    );
  }
}
React.render(<App />, document.body);
Output

You can jump to the latest bin by adding /latest to your URL

Dismiss x
public
Bin info
brigandpro
0viewers