diff --git a/src/components/menu-bar/menu-bar-menu.jsx b/src/components/menu-bar/menu-bar-menu.jsx index d71d9e049..24891f973 100644 --- a/src/components/menu-bar/menu-bar-menu.jsx +++ b/src/components/menu-bar/menu-bar-menu.jsx @@ -5,7 +5,6 @@ import Menu from '../../containers/menu.jsx'; const MenuBarMenu = ({ children, className, - onRequestClose, open, place = 'right' }) => ( @@ -13,7 +12,6 @@ const MenuBarMenu = ({ {children} @@ -23,7 +21,6 @@ const MenuBarMenu = ({ MenuBarMenu.propTypes = { children: PropTypes.node, className: PropTypes.string, - onRequestClose: PropTypes.func, open: PropTypes.bool, place: PropTypes.oneOf(['left', 'right']) }; diff --git a/src/components/menu-bar/menu-bar.jsx b/src/components/menu-bar/menu-bar.jsx index 667477c65..dcdf5b1b8 100644 --- a/src/components/menu-bar/menu-bar.jsx +++ b/src/components/menu-bar/menu-bar.jsx @@ -18,6 +18,7 @@ import Divider from '../divider/divider.jsx'; import SaveStatus from './save-status.jsx'; import ProjectWatcher from '../../containers/project-watcher.jsx'; import MenuBarMenu from './menu-bar-menu.jsx'; +import MenuLabel from './tw-menu-label.jsx'; import {MenuItem, MenuSection} from '../menu/menu.jsx'; import ProjectTitleInput from './project-title-input.jsx'; import AuthorInfo from './author-info.jsx'; @@ -391,11 +392,10 @@ class MenuBar extends React.Component { // each item must have a 'title' FormattedMessage and a 'handleClick' function // generate a menu with items for each object in the array return ( -
{ onClickAbout.map(itemProps => ( @@ -420,7 +419,7 @@ class MenuBar extends React.Component { )) } -
+ ); } wrapAboutMenuCallback (callback) { @@ -483,11 +482,10 @@ class MenuBar extends React.Component {
{this.props.errors.length > 0 &&
-
@@ -534,7 +531,7 @@ class MenuBar extends React.Component { ))} -
+
} {(this.props.canChangeTheme || this.props.canChangeLanguage) && ()} {(this.props.canManageFiles) && ( -
-
+ )} -
{this.props.isPlayerOnly ? null : ( {(handleRestore, {restorable, deletedItem}) => ( @@ -823,26 +816,22 @@ class MenuBar extends React.Component { -
+ {this.props.isTotallyNormal && ( -
-
- -
+ @@ -869,13 +858,13 @@ class MenuBar extends React.Component { -
+ )} {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 };