2016-11-22 21:19:08 +01:00
|
|
|
import React from 'react';
|
|
|
|
import ReactDOM from 'react-dom';
|
|
|
|
import {Icon} from './common.js';
|
|
|
|
|
2016-12-07 22:24:33 +01:00
|
|
|
export let Menu = React.createClass({
|
2017-01-09 08:24:32 +01:00
|
|
|
propTypes: {
|
|
|
|
onClickOut: React.PropTypes.func.isRequired,
|
|
|
|
},
|
2016-08-07 22:10:44 +02:00
|
|
|
handleWindowClick: function(e) {
|
2017-01-09 08:24:32 +01:00
|
|
|
if (!this._div.contains(e.target)) {
|
2016-08-07 22:10:44 +02:00
|
|
|
// Menu is open and user clicked outside of it
|
2017-01-09 08:24:32 +01:00
|
|
|
this.props.onClickOut();
|
2016-08-07 22:10:44 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
componentDidMount: function() {
|
|
|
|
window.addEventListener('click', this.handleWindowClick, false);
|
|
|
|
},
|
|
|
|
componentWillUnmount: function() {
|
|
|
|
window.removeEventListener('click', this.handleWindowClick, false);
|
|
|
|
},
|
|
|
|
render: function() {
|
2017-01-09 08:24:32 +01:00
|
|
|
const {onClickOut, ...other} = this.props;
|
2016-08-07 22:10:44 +02:00
|
|
|
return (
|
2017-01-09 08:24:32 +01:00
|
|
|
<div ref={(div) => this._div = div} className={'menu ' + (this.props.className || '')}
|
|
|
|
{... other}>
|
2016-08-07 22:10:44 +02:00
|
|
|
{this.props.children}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-12-07 22:24:33 +01:00
|
|
|
export let MenuItem = React.createClass({
|
2016-08-07 22:10:44 +02:00
|
|
|
propTypes: {
|
|
|
|
href: React.PropTypes.string,
|
|
|
|
label: React.PropTypes.string,
|
|
|
|
icon: React.PropTypes.string,
|
|
|
|
onClick: React.PropTypes.func,
|
|
|
|
},
|
|
|
|
getDefaultProps: function() {
|
|
|
|
return {
|
|
|
|
iconPosition: 'left',
|
|
|
|
}
|
|
|
|
},
|
|
|
|
render: function() {
|
|
|
|
var icon = (this.props.icon ? <Icon icon={this.props.icon} fixed /> : null);
|
|
|
|
|
|
|
|
return (
|
2017-01-09 09:03:13 +01:00
|
|
|
<a className="button-text menu__menu-item" onClick={this.props.onClick}
|
2016-08-07 22:10:44 +02:00
|
|
|
href={this.props.href || 'javascript:'} label={this.props.label}>
|
|
|
|
{this.props.iconPosition == 'left' ? icon : null}
|
|
|
|
{this.props.label}
|
|
|
|
{this.props.iconPosition == 'left' ? null : icon}
|
|
|
|
</a>
|
|
|
|
);
|
|
|
|
}
|
2016-11-22 21:19:08 +01:00
|
|
|
});
|