This repository has been archived by the owner on Nov 9, 2017. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathTabPane.js
82 lines (72 loc) · 1.85 KB
/
TabPane.js
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
82
var React = require('react');
var joinClasses = require('./utils/joinClasses');
var classSet = require('./utils/classSet');
var TransitionEvents = require('./utils/TransitionEvents');
var TabPane = React.createClass({displayName: "TabPane",
getDefaultProps: function () {
return {
animation: true
};
},
getInitialState: function () {
return {
animateIn: false,
animateOut: false
};
},
componentWillReceiveProps: function (nextProps) {
if (this.props.animation) {
if (!this.state.animateIn && nextProps.active && !this.props.active) {
this.setState({
animateIn: true
});
} else if (!this.state.animateOut && !nextProps.active && this.props.active) {
this.setState({
animateOut: true
});
}
}
},
componentDidUpdate: function () {
if (this.state.animateIn) {
setTimeout(this.startAnimateIn, 0);
}
if (this.state.animateOut) {
TransitionEvents.addEndEventListener(
this.getDOMNode(),
this.stopAnimateOut
);
}
},
startAnimateIn: function () {
if (this.isMounted()) {
this.setState({
animateIn: false
});
}
},
stopAnimateOut: function () {
if (this.isMounted()) {
this.setState({
animateOut: false
});
if (typeof this.props.onAnimateOutEnd === 'function') {
this.props.onAnimateOutEnd();
}
}
},
render: function () {
var classes = {
'tab-pane': true,
'fade': true,
'active': this.props.active || this.state.animateOut,
'in': this.props.active && !this.state.animateIn
};
return (
React.createElement("div", React.__spread({}, this.props, {className: joinClasses(this.props.className, classSet(classes))}),
this.props.children
)
);
}
});
module.exports = TabPane;