mirror of https://github.com/vector-im/riot-web
Export ContextualMenu component, with added `hasBackground` property
, which is only enabled when `createMenu` is used.pull/21833/head
parent
d503c86576
commit
9ec2570eab
|
@ -40,7 +40,7 @@ function getOrCreateContainer() {
|
||||||
return container;
|
return container;
|
||||||
}
|
}
|
||||||
|
|
||||||
class ContextualMenu extends React.Component {
|
export default class ContextualMenu extends React.Component {
|
||||||
propTypes: {
|
propTypes: {
|
||||||
top: PropTypes.number,
|
top: PropTypes.number,
|
||||||
bottom: PropTypes.number,
|
bottom: PropTypes.number,
|
||||||
|
@ -57,6 +57,10 @@ class ContextualMenu extends React.Component {
|
||||||
menuPaddingRight: PropTypes.number,
|
menuPaddingRight: PropTypes.number,
|
||||||
menuPaddingBottom: PropTypes.number,
|
menuPaddingBottom: PropTypes.number,
|
||||||
menuPaddingLeft: PropTypes.number,
|
menuPaddingLeft: PropTypes.number,
|
||||||
|
|
||||||
|
// If true, insert an invisible screen-sized element behind the
|
||||||
|
// menu that when clicked will close it.
|
||||||
|
hasBackground: PropTypes.bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
|
@ -154,14 +158,13 @@ class ContextualMenu extends React.Component {
|
||||||
{ chevron }
|
{ chevron }
|
||||||
<ElementClass {...props} onFinished={props.closeMenu} onResize={props.windowResize} />
|
<ElementClass {...props} onFinished={props.closeMenu} onResize={props.windowResize} />
|
||||||
</div>
|
</div>
|
||||||
<div className="mx_ContextualMenu_background" onClick={props.closeMenu}></div>
|
{ props.hasBackground && <div className="mx_ContextualMenu_background" onClick={props.closeMenu}></div> }
|
||||||
<style>{ chevronCSS }</style>
|
<style>{ chevronCSS }</style>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = {
|
export function createMenu(ElementClass, props) {
|
||||||
createMenu: function(ElementClass, props) {
|
|
||||||
const closeMenu = function(...args) {
|
const closeMenu = function(...args) {
|
||||||
ReactDOM.unmountComponentAtNode(getOrCreateContainer());
|
ReactDOM.unmountComponentAtNode(getOrCreateContainer());
|
||||||
|
|
||||||
|
@ -172,6 +175,7 @@ module.exports = {
|
||||||
|
|
||||||
const menu = <ContextualMenu
|
const menu = <ContextualMenu
|
||||||
{...props}
|
{...props}
|
||||||
|
hasBackground={true}
|
||||||
elementClass={ElementClass}
|
elementClass={ElementClass}
|
||||||
closeMenu={closeMenu}
|
closeMenu={closeMenu}
|
||||||
windowResize={closeMenu}
|
windowResize={closeMenu}
|
||||||
|
@ -180,5 +184,4 @@ module.exports = {
|
||||||
ReactDOM.render(menu, getOrCreateContainer());
|
ReactDOM.render(menu, getOrCreateContainer());
|
||||||
|
|
||||||
return {close: closeMenu};
|
return {close: closeMenu};
|
||||||
},
|
}
|
||||||
};
|
|
||||||
|
|
Loading…
Reference in New Issue