-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
/
dialog.jsx
81 lines (66 loc) · 1.79 KB
/
dialog.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/** @jsx React.DOM */
var $ = require('jquery');
var Classable = require('./mixins/classable');
var Paper = require('./paper.jsx');
var React = require('react');
var Dialog = React.createClass({
mixins: [Classable],
propTypes: {
openImmediately: React.PropTypes.bool,
title: React.PropTypes.string,
actions: React.PropTypes.array,
onShow: React.PropTypes.func
},
getDefaultProps: function() {
return {
actions: []
};
},
getInitialState: function() {
return {
open: this.props.openImmediately || false
};
},
componentDidUpdate: function (prevProps, prevState) {
//calculate height and use that to center the dialog vertically
var $el = $(this.getDOMNode()),
height = $el.innerHeight();
$el.css('margin-top', -height / 2);
},
_handleClickAway: function() {
this.dismiss();
},
render: function() {
var mainClasses = this.getClasses('dialog', { 'show': this.state.open }),
actions = this.props.actions.map(function(a) {
if (a.onClick) return <div className="action" onClick={a.onClick}>{a.text}</div>;
return <div className="action" onClick={this.dismiss}>{a.text}</div>;
}.bind(this));
return (
<div className={mainClasses}>
<Paper zDepth={4}>
<h3 className="dialog-title">
{this.props.title}
</h3>
<div className="dialog-content">
{this.state.open ? this.props.children : ''}
</div>
<div className="dialog-actions">
<div className="actions-right">
{actions}
</div>
</div>
</Paper>
<div className="dialog-overlay" onClick={this._handleClickAway}></div>
</div>
);
},
dismiss: function() {
this.setState({ open: false });
},
show: function() {
this.setState({ open: true });
if (this.props.onShow) this.props.onShow();
}
});
module.exports = Dialog;