}
{(this.props.canChangeTheme || this.props.canChangeLanguage) && (
)}
{(this.props.canManageFiles) && (
-
+
)}
-
+
{this.props.isTotallyNormal && (
-
+
)}
{this.props.onClickAddonSettings && (

(
-
{canChangeLanguage && }
@@ -69,7 +68,7 @@ const SettingsMenu = ({
)}
-
+
);
SettingsMenu.propTypes = {
diff --git a/src/components/menu-bar/tw-menu-label.jsx b/src/components/menu-bar/tw-menu-label.jsx
new file mode 100644
index 000000000..016d21336
--- /dev/null
+++ b/src/components/menu-bar/tw-menu-label.jsx
@@ -0,0 +1,75 @@
+import React from 'react';
+import PropTypes from 'prop-types';
+import bindAll from 'lodash.bindall';
+import classNames from 'classnames';
+
+import styles from './menu-bar.css';
+
+class MenuLabel extends React.Component {
+ constructor (props) {
+ super(props);
+ bindAll(this, [
+ 'handleClick',
+ 'handleMouseUp',
+ 'menuRef'
+ ]);
+ }
+ componentDidMount () {
+ if (this.props.open) this.addListeners();
+ }
+ componentDidUpdate (prevProps) {
+ if (this.props.open && !prevProps.open) this.addListeners();
+ if (!this.props.open && prevProps.open) this.removeListeners();
+ }
+ componentWillUnmount () {
+ this.removeListeners();
+ }
+ addListeners () {
+ document.addEventListener('mouseup', this.handleMouseUp);
+ }
+ removeListeners () {
+ document.removeEventListener('mouseup', this.handleMouseUp);
+ }
+ handleClick (e) {
+ // this is a bit sketchy, but we want to allow clicking on the menu itself and the images
+ // and text directly inside it, but not the items inside the menu, which are under the button
+ // in the DOM.
+ if (e.target.closest('div') === this.menuEl) {
+ if (this.props.open) {
+ this.props.onClose();
+ } else {
+ this.props.onOpen();
+ }
+ }
+ }
+ handleMouseUp (e) {
+ if (this.props.open && !this.menuEl.contains(e.target)) {
+ this.props.onClose();
+ }
+ }
+ menuRef (c) {
+ this.menuEl = c;
+ }
+ render () {
+ return (
+
+ {this.props.children}
+
+ );
+ }
+}
+
+MenuLabel.propTypes = {
+ children: PropTypes.node,
+ open: PropTypes.bool,
+ onOpen: PropTypes.func,
+ onClose: PropTypes.func
+};
+
+export default MenuLabel;
diff --git a/src/containers/menu.jsx b/src/containers/menu.jsx
index e9a51cd4c..6500fa8a5 100644
--- a/src/containers/menu.jsx
+++ b/src/containers/menu.jsx
@@ -1,64 +1,18 @@
-import bindAll from 'lodash.bindall';
import PropTypes from 'prop-types';
import React from 'react';
import MenuComponent from '../components/menu/menu.jsx';
-class Menu extends React.Component {
- constructor (props) {
- super(props);
- bindAll(this, [
- 'addListeners',
- 'removeListeners',
- 'handleClick',
- 'ref'
- ]);
- }
- componentDidMount () {
- if (this.props.open) this.addListeners();
- }
- componentDidUpdate (prevProps) {
- if (this.props.open && !prevProps.open) this.addListeners();
- if (!this.props.open && prevProps.open) this.removeListeners();
- }
- componentWillUnmount () {
- this.removeListeners();
- }
- addListeners () {
- document.addEventListener('mouseup', this.handleClick);
- }
- removeListeners () {
- document.removeEventListener('mouseup', this.handleClick);
- }
- handleClick (e) {
- if (this.props.open && !this.menu.contains(e.target)) {
- this.props.onRequestClose();
- }
- }
- ref (c) {
- this.menu = c;
- }
- render () {
- const {
- open,
- children,
- ...props
- } = this.props;
- if (!open) return null;
- return (
-
- {children}
-
- );
- }
-}
+const Menu = ({open, children, ...props}) => (
+ open ? (
+
+ {children}
+
+ ) : null
+);
Menu.propTypes = {
children: PropTypes.node,
- onRequestClose: PropTypes.func.isRequired,
open: PropTypes.bool.isRequired
};