This repository has been archived by the owner on Mar 26, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
custom-ModalTrigger.jsx
78 lines (67 loc) · 1.7 KB
/
custom-ModalTrigger.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
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
}
);
},
// Original
// render: function () {
// var child = React.Children.only(this.props.children);
// return cloneWithProps(
// child,
// {
// onClick: createChainedFunction(child.props.onClick, this.toggle)
// }
// );
// }
// https://github.com/react-bootstrap/react-bootstrap/issues/527
render: function render() {
var child = React.Children.only(this.props.children);
var props = {};
props.onClick = createChainedFunction(child.props.onClick, this.toggle);
for (var name in this.props) {
if (name.indexOf('on') === 0) {
props[name] = createChainedFunction(child.props[name], this.props[name]);
}
}
return cloneWithProps(
child,
props
);
}
});
module.exports = ModalTrigger;