Skip to content

Commit 1b43586

Browse files
committed
Add a basic modal dialog implementation
1 parent 2b81f46 commit 1b43586

2 files changed

Lines changed: 86 additions & 0 deletions

File tree

‎skins/base/css/common.css‎

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,31 @@ h2 {
3333
margin-top: 16px;
3434
margin-bottom: 16px;
3535
}
36+
37+
.mx_Dialog_Background {
38+
position: fixed;
39+
top: 0;
40+
left: 0;
41+
width: 100%;
42+
height: 100%;
43+
background-color: #ccc;
44+
opacity: 0.5;
45+
z-index: -200;
46+
}
47+
48+
.mx_Dialog_Wrapper {
49+
position: fixed;
50+
top: 0;
51+
left: 0;
52+
width: 100%;
53+
height: 100%;
54+
}
55+
56+
.mx_Dialog {
57+
background-color: #fff;
58+
margin: auto;
59+
max-width: 500px;
60+
z-index: -100;
61+
position: relative;
62+
top: 100px;
63+
}

‎src/Modal.js‎

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
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+
module.exports = {
24+
DialogContainerId: "mx_Dialog_Container",
25+
26+
getOrCreateContainer: function() {
27+
var container = document.getElementById(this.DialogContainerId);
28+
29+
if (!container) {
30+
container = document.createElement("div");
31+
container.id = this.DialogContainerId;
32+
document.body.appendChild(container);
33+
}
34+
35+
return container;
36+
},
37+
38+
createDialog: function (Element, props) {
39+
var self = this;
40+
41+
var closeDialog = function() {
42+
React.unmountComponentAtNode(self.getOrCreateContainer());
43+
44+
if (props && props.onFinished) props.onFinished.apply(arguments);
45+
};
46+
47+
var dialog = (
48+
<div className="mx_Dialog_Wrapper">
49+
<div className="mx_Dialog">
50+
<Element {...props} onFinished={closeDialog}/>
51+
</div>
52+
<div className="mx_Dialog_Background" onClick={closeDialog}></div>
53+
</div>
54+
);
55+
56+
React.render(dialog, this.getOrCreateContainer());
57+
},
58+
};

0 commit comments

Comments
 (0)