allow ContextualMenu to run without background, for tooltips & fix copy
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
e3c455e599
commit
64bcf6fd7e
2 changed files with 16 additions and 12 deletions
|
@ -1,5 +1,6 @@
|
||||||
/*
|
/*
|
||||||
Copyright 2015, 2016 OpenMarket Ltd
|
Copyright 2015, 2016 OpenMarket Ltd
|
||||||
|
Copyright 2018 Vector Creations Ltd
|
||||||
|
|
||||||
Licensed under the Apache License, Version 2.0 (the "License");
|
Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
you may not use this file except in compliance with the License.
|
you may not use this file except in compliance with the License.
|
||||||
|
@ -15,12 +16,10 @@ limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
'use strict';
|
import React from 'react';
|
||||||
|
import ReactDOM from 'react-dom';
|
||||||
const classNames = require('classnames');
|
|
||||||
const React = require('react');
|
|
||||||
const ReactDOM = require('react-dom');
|
|
||||||
import PropTypes from 'prop-types';
|
import PropTypes from 'prop-types';
|
||||||
|
import classNames from 'classnames';
|
||||||
|
|
||||||
// Shamelessly ripped off Modal.js. There's probably a better way
|
// Shamelessly ripped off Modal.js. There's probably a better way
|
||||||
// of doing reusable widgets like dialog boxes & menus where we go and
|
// of doing reusable widgets like dialog boxes & menus where we go and
|
||||||
|
@ -61,7 +60,12 @@ export default class ContextualMenu extends React.Component {
|
||||||
// If true, insert an invisible screen-sized element behind the
|
// If true, insert an invisible screen-sized element behind the
|
||||||
// menu that when clicked will close it.
|
// menu that when clicked will close it.
|
||||||
hasBackground: PropTypes.bool,
|
hasBackground: PropTypes.bool,
|
||||||
}
|
|
||||||
|
// The component to render as the context menu
|
||||||
|
elementClass: PropTypes.element.isRequired,
|
||||||
|
// on resize callback
|
||||||
|
windowResize: PropTypes.func
|
||||||
|
};
|
||||||
|
|
||||||
render() {
|
render() {
|
||||||
const position = {};
|
const position = {};
|
||||||
|
@ -112,7 +116,7 @@ export default class ContextualMenu extends React.Component {
|
||||||
`;
|
`;
|
||||||
}
|
}
|
||||||
|
|
||||||
const chevron = <div style={chevronOffset} className={"mx_ContextualMenu_chevron_" + chevronFace}></div>;
|
const chevron = <div style={chevronOffset} className={"mx_ContextualMenu_chevron_" + chevronFace} />;
|
||||||
const className = 'mx_ContextualMenu_wrapper';
|
const className = 'mx_ContextualMenu_wrapper';
|
||||||
|
|
||||||
const menuClasses = classNames({
|
const menuClasses = classNames({
|
||||||
|
@ -158,13 +162,13 @@ export default 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>
|
||||||
{ props.hasBackground && <div className="mx_ContextualMenu_background" onClick={props.closeMenu}></div> }
|
{ props.hasBackground && <div className="mx_ContextualMenu_background" onClick={props.closeMenu} /> }
|
||||||
<style>{ chevronCSS }</style>
|
<style>{ chevronCSS }</style>
|
||||||
</div>;
|
</div>;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function createMenu(ElementClass, props) {
|
export function createMenu(ElementClass, props, hasBackground=true) {
|
||||||
const closeMenu = function(...args) {
|
const closeMenu = function(...args) {
|
||||||
ReactDOM.unmountComponentAtNode(getOrCreateContainer());
|
ReactDOM.unmountComponentAtNode(getOrCreateContainer());
|
||||||
|
|
||||||
|
@ -175,8 +179,8 @@ export function createMenu(ElementClass, props) {
|
||||||
|
|
||||||
// We only reference closeMenu once per call to createMenu
|
// We only reference closeMenu once per call to createMenu
|
||||||
const menu = <ContextualMenu
|
const menu = <ContextualMenu
|
||||||
|
hasBackground={hasBackground}
|
||||||
{...props}
|
{...props}
|
||||||
hasBackground={true}
|
|
||||||
elementClass={ElementClass}
|
elementClass={ElementClass}
|
||||||
closeMenu={closeMenu} // eslint-disable-line react/jsx-no-bind
|
closeMenu={closeMenu} // eslint-disable-line react/jsx-no-bind
|
||||||
windowResize={closeMenu} // eslint-disable-line react/jsx-no-bind
|
windowResize={closeMenu} // eslint-disable-line react/jsx-no-bind
|
||||||
|
|
|
@ -336,8 +336,8 @@ module.exports = React.createClass({
|
||||||
left: x,
|
left: x,
|
||||||
top: y,
|
top: y,
|
||||||
message: successful ? _t('Copied!') : _t('Failed to copy'),
|
message: successful ? _t('Copied!') : _t('Failed to copy'),
|
||||||
});
|
}, false);
|
||||||
e.target.onmouseout = close;
|
e.target.onmouseleave = close;
|
||||||
};
|
};
|
||||||
p.appendChild(button);
|
p.appendChild(button);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue