forked from react-bootstrap/react-bootstrap-npm
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathFadeMixin.js
53 lines (45 loc) · 1.38 KB
/
FadeMixin.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
var React = require('react');
// TODO: listen for onTransitionEnd to remove el
module.exports = {
_fadeIn: function () {
var els;
if (this.isMounted()) {
els = this.getDOMNode().querySelectorAll('.fade');
if (els.length) {
Array.prototype.forEach.call(els, function (el) {
el.className += ' in';
});
}
}
},
_fadeOut: function () {
var els = this._fadeOutEl.querySelectorAll('.fade.in');
if (els.length) {
Array.prototype.forEach.call(els, function (el) {
el.className = el.className.replace(/\bin\b/, '');
});
}
setTimeout(this._handleFadeOutEnd, 300);
},
_handleFadeOutEnd: function () {
if (this._fadeOutEl && this._fadeOutEl.parentNode) {
this._fadeOutEl.parentNode.removeChild(this._fadeOutEl);
}
},
componentDidMount: function () {
if (document.querySelectorAll) {
// Firefox needs delay for transition to be triggered
setTimeout(this._fadeIn, 20);
}
},
componentWillUnmount: function () {
var els = this.getDOMNode().querySelectorAll('.fade');
if (els.length) {
this._fadeOutEl = document.createElement('div');
document.body.appendChild(this._fadeOutEl);
this._fadeOutEl.appendChild(this.getDOMNode().cloneNode(true));
// Firefox needs delay for transition to be triggered
setTimeout(this._fadeOut, 20);
}
}
};