forked from react-bootstrap/react-bootstrap-bower
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathModalTrigger.js
More file actions
63 lines (52 loc) · 1.24 KB
/
ModalTrigger.js
File metadata and controls
63 lines (52 loc) · 1.24 KB
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
define(function (require, exports, module) {var React = require('react');
var OverlayMixin = require('./OverlayMixin');
var cloneWithProps = require('./utils/cloneWithProps');
var createChainedFunction = require('./utils/createChainedFunction');
var ModalTrigger = React.createClass({displayName: 'ModalTrigger',
mixins: [OverlayMixin],
propTypes: {
modal: React.PropTypes.node.isRequired
},
getInitialState: function () {
return {
isOverlayShown: false
};
},
show: function () {
this.setState({
isOverlayShown: true
});
},
hide: function () {
this.setState({
isOverlayShown: false
});
},
toggle: function () {
this.setState({
isOverlayShown: !this.state.isOverlayShown
});
},
renderOverlay: function () {
if (!this.state.isOverlayShown) {
return React.createElement("span", null);
}
return cloneWithProps(
this.props.modal,
{
onRequestHide: this.hide
}
);
},
render: function () {
var child = React.Children.only(this.props.children);
return cloneWithProps(
child,
{
onClick: createChainedFunction(child.props.onClick, this.toggle)
}
);
}
});
module.exports = ModalTrigger;
});