Add `?locale=<localecode>` to load in a new langage. Add `?enable=language` to enable the language selector Or combine the two: `?enable=language&locale=<localecode>` Still accepts a hash, but requires that the hash be a sequence of digits. Added new locales reducer to gui: - initializes default react-intl/localeData - initializes default locale messages for all locales - default locale is ‘en’ (can be overridden by URL) Removed dependency on react-intl-redux, added ConnectedIntlProvider (uses correct locale messages from redux based on current locale)
66 lines
1.6 KiB
React
66 lines
1.6 KiB
React
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 (
|
|
<MenuComponent
|
|
componentRef={this.ref}
|
|
{...props}
|
|
>
|
|
{children}
|
|
</MenuComponent>
|
|
);
|
|
}
|
|
}
|
|
|
|
Menu.propTypes = {
|
|
children: PropTypes.node,
|
|
onRequestClose: PropTypes.func.isRequired,
|
|
open: PropTypes.bool.isRequired
|
|
};
|
|
|
|
export default Menu;
|