Skip to content

Commit 260e221

Browse files
committed
WIP at turning MemberInfo into a ContextualMenu
1 parent 048260b commit 260e221

2 files changed

Lines changed: 107 additions & 0 deletions

File tree

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
'use strict';
18+
19+
var React = require('react');
20+
var classNames = require('classnames');
21+
22+
var dis = require("../../../../src/dispatcher");
23+
24+
var MatrixClientPeg = require("../../../../src/MatrixClientPeg");
25+
26+
module.exports = React.createClass({
27+
displayName: 'ContextualMenu',
28+
29+
render: function() {
30+
return (
31+
<div className="mx_ContextualMenu">
32+
</div>
33+
);
34+
}
35+
});

‎src/ContextualMenu.js‎

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
Copyright 2015 OpenMarket Ltd
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
18+
'use strict';
19+
20+
var React = require('react');
21+
var q = require('q');
22+
23+
// Shamelessly ripped off Modal.js. There's probably a better way
24+
// of doing reusable widgets like dialog boxes & menus where we go and
25+
// pass in a custom control as the actual body.
26+
27+
module.exports = {
28+
ContextualMenuContainerId: "mx_ContextualMenu_Container",
29+
30+
getOrCreateContainer: function() {
31+
var container = document.getElementById(this.ContextualMenuContainerId);
32+
33+
if (!container) {
34+
container = document.createElement("div");
35+
container.id = this.ContextualMenuContainerId;
36+
document.body.appendChild(container);
37+
}
38+
39+
return container;
40+
},
41+
42+
createMenu: function (Element, props) {
43+
var self = this;
44+
45+
var closeMenu = function() {
46+
React.unmountComponentAtNode(self.getOrCreateContainer());
47+
48+
if (props && props.onFinished) props.onFinished.apply(null, arguments);
49+
};
50+
51+
var position = {
52+
top: props.top - 20,
53+
right: props.right + 8,
54+
};
55+
56+
// FIXME: If a menu uses getDefaultProps it clobbers the onFinished
57+
// property set here so you can't close the menu from a button click!
58+
var menu = (
59+
<div className="mx_ContextualMenu_wrapper">
60+
<div className="mx_ContextualMenu" style={position}>
61+
<img className="mx_ContextualMenu_chevron" src="img/chevron-right.png" width="9" height="16" />
62+
<Element {...props} onFinished={closeMenu}/>
63+
</div>
64+
<div className="mx_ContextualMenu_background" onClick={closeMenu}></div>
65+
</div>
66+
);
67+
68+
React.render(menu, this.getOrCreateContainer());
69+
70+
return {close: closeMenu};
71+
},
72+
};

0 commit comments

Comments
 (0)