|
1
|
|
|
var React = require("react"); |
|
2
|
|
|
|
|
3
|
|
|
var Modal = React.createClass({ |
|
4
|
|
|
propTypes: { |
|
5
|
|
|
show: React.PropTypes.bool, |
|
6
|
|
|
keyboard: React.PropTypes.bool, |
|
7
|
|
|
closeHandler: React.PropTypes.func, |
|
8
|
|
|
className: React.PropTypes.string, |
|
9
|
|
|
closeTitle: React.PropTypes.string, |
|
10
|
|
|
options: React.PropTypes.array |
|
11
|
|
|
}, |
|
12
|
|
|
|
|
13
|
|
|
getDefaultProps: function() { |
|
14
|
|
|
return { |
|
15
|
|
|
show: true, |
|
16
|
|
|
keyboard: true, |
|
17
|
|
|
closeTitle: "×" |
|
18
|
|
|
}; |
|
19
|
|
|
}, |
|
20
|
|
|
|
|
21
|
|
|
componentDidMount: function() { |
|
22
|
|
|
this.modal({show: this.props.show, keyboard: this.props.keyboard}); |
|
23
|
|
|
}, |
|
24
|
|
|
|
|
25
|
|
|
componentWillReceiveProps: function(props) { |
|
26
|
|
|
this.modal({show: props.show, keyboard: props.keyboard}); |
|
27
|
|
|
}, |
|
28
|
|
|
|
|
29
|
|
|
componentWillUnmount: function() { |
|
30
|
|
|
this.modal('hide'); |
|
31
|
|
|
}, |
|
32
|
|
|
|
|
33
|
|
|
getCloseTitle: function() { |
|
34
|
|
|
return {__html: this.props.closeTitle}; |
|
35
|
|
|
}, |
|
36
|
|
|
|
|
37
|
|
|
modal: function(options) { |
|
38
|
|
|
var selector = $(this.selector); |
|
39
|
|
|
selector.modal(options); |
|
40
|
|
|
selector.on('hidden.bs.modal', function() { |
|
41
|
|
|
this.props.closeHandler(); |
|
42
|
|
|
}.bind(this)); |
|
43
|
|
|
}, |
|
44
|
|
|
|
|
45
|
|
|
selector: null, |
|
46
|
|
|
|
|
47
|
|
|
render: function() { |
|
48
|
|
|
let classNames = 'modal'; |
|
49
|
|
|
if (this.props.className) { |
|
50
|
|
|
classNames += ' ' + this.props.className; |
|
51
|
|
|
} |
|
52
|
|
|
|
|
53
|
|
|
let options = null; |
|
54
|
|
|
if (this.props.options && this.props.options.length) { |
|
55
|
|
|
options = ( |
|
56
|
|
|
<li className="dropdown"> |
|
57
|
|
|
<a data-toggle="dropdown" aria-haspopup="true" aria-expanded="false" aria-label="Options"> |
|
58
|
|
|
Options <i className="glyphicon glyphicon-menu-down"></i> |
|
59
|
|
|
</a> |
|
60
|
|
|
<ul className="dropdown-menu"> |
|
61
|
|
|
{this.props.options.map(function(item) { |
|
62
|
|
|
let icon = null; |
|
63
|
|
|
if (item.icon !== "") { |
|
64
|
|
|
icon = ( |
|
65
|
|
|
<i className={"icon " + item.icon} aria-hidden="true"></i> |
|
66
|
|
|
); |
|
67
|
|
|
} |
|
68
|
|
|
return ( |
|
69
|
|
|
<li key={item.title}> |
|
70
|
|
|
<a href={"javascript:void(0);"} onClick={item.handler}>{icon}{item.title}</a> |
|
71
|
|
|
</li> |
|
72
|
|
|
); |
|
73
|
|
|
})} |
|
74
|
|
|
</ul> |
|
75
|
|
|
</li> |
|
76
|
|
|
); |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
return ( |
|
80
|
|
|
<div className={classNames} ref={function(node) { this.selector = node; }.bind(this)}> |
|
81
|
|
|
<div className="modal-dialog modal-lg"> |
|
82
|
|
|
<div className="modal-content"> |
|
83
|
|
|
<div className="modal-header"> |
|
84
|
|
|
<ul className="nav nav-tabs"> |
|
85
|
|
|
{options} |
|
86
|
|
|
<li> |
|
87
|
|
|
<a className="close" data-dismiss="modal" aria-label="Close" dangerouslySetInnerHTML={this.getCloseTitle()} /> |
|
|
|
|
|
|
88
|
|
|
</li> |
|
89
|
|
|
</ul> |
|
90
|
|
|
<h4 className="modal-title">{this.props.title}</h4> |
|
91
|
|
|
</div> |
|
92
|
|
|
<div className="modal-body"> |
|
93
|
|
|
{this.props.children} |
|
94
|
|
|
</div> |
|
95
|
|
|
</div> |
|
96
|
|
|
</div> |
|
97
|
|
|
</div> |
|
98
|
|
|
); |
|
99
|
|
|
} |
|
100
|
|
|
}); |
|
101
|
|
|
|
|
102
|
|
|
module.exports = Modal; |
|
103
|
|
|
|