import React from 'react'; import ReactDOM from 'react-dom'; import {Icon} from './common.js'; // Generic menu styles var menuStyle = { whiteSpace: 'nowrap' }; var Menu = React.createClass({ handleWindowClick: function(e) { if (this.props.toggleButton && ReactDOM.findDOMNode(this.props.toggleButton).contains(e.target)) { // Toggle button was clicked this.setState({ open: !this.state.open }); } else if (this.state.open && !this.refs.div.contains(e.target)) { // Menu is open and user clicked outside of it this.setState({ open: false }); } }, propTypes: { openButton: React.PropTypes.element, }, getInitialState: function() { return { open: false, }; }, componentDidMount: function() { window.addEventListener('click', this.handleWindowClick, false); }, componentWillUnmount: function() { window.removeEventListener('click', this.handleWindowClick, false); }, render: function() { return (