forked from reactstrap/reactstrap
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCarouselItem.js
More file actions
114 lines (99 loc) · 3.17 KB
/
CarouselItem.js
File metadata and controls
114 lines (99 loc) · 3.17 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import Transition from 'react-transition-group/Transition';
import { mapToCssModules, TransitionTimeouts, TransitionStatuses } from './utils';
class CarouselItem extends React.Component {
constructor(props) {
super(props);
this.state = {
startAnimation: false,
};
this.onEnter = this.onEnter.bind(this);
this.onEntering = this.onEntering.bind(this);
this.onExit = this.onExit.bind(this);
this.onExiting = this.onExiting.bind(this);
this.onExited = this.onExited.bind(this);
}
onEnter(node, isAppearing) {
this.setState({ startAnimation: false });
this.props.onEnter(node, isAppearing);
}
onEntering(node, isAppearing) {
// getting this variable triggers a reflow
const offsetHeight = node.offsetHeight;
this.setState({ startAnimation: true });
this.props.onEntering(node, isAppearing);
return offsetHeight;
}
onExit(node) {
this.setState({ startAnimation: false });
this.props.onExit(node);
}
onExiting(node) {
this.setState({ startAnimation: true });
node.dispatchEvent(new CustomEvent('slide.bs.carousel'));
this.props.onExiting(node);
}
onExited(node) {
node.dispatchEvent(new CustomEvent('slid.bs.carousel'));
this.props.onExited(node);
}
render() {
const { in: isIn, children, cssModule, slide, tag: Tag, className, ...transitionProps } = this.props;
return (
<Transition
{...transitionProps}
enter={slide}
exit={slide}
in={isIn}
onEnter={this.onEnter}
onEntering={this.onEntering}
onExit={this.onExit}
onExiting={this.onExiting}
onExited={this.onExited}
>
{(status) => {
const { direction } = this.context;
const isActive = (status === TransitionStatuses.ENTERED) || (status === TransitionStatuses.EXITING);
const directionClassName = (status === TransitionStatuses.ENTERING || status === TransitionStatuses.EXITING) &&
this.state.startAnimation &&
(direction === 'right' ? 'carousel-item-left' : 'carousel-item-right');
const orderClassName = (status === TransitionStatuses.ENTERING) &&
(direction === 'right' ? 'carousel-item-next' : 'carousel-item-prev');
const itemClasses = mapToCssModules(classNames(
className,
'carousel-item',
isActive && 'active',
directionClassName,
orderClassName,
), cssModule);
return (
<Tag className={itemClasses}>
{children}
</Tag>
);
}}
</Transition>
);
}
}
CarouselItem.propTypes = {
...Transition.propTypes,
tag: PropTypes.oneOfType([PropTypes.func, PropTypes.string]),
in: PropTypes.bool,
cssModule: PropTypes.object,
children: PropTypes.node,
slide: PropTypes.bool,
className: PropTypes.string,
};
CarouselItem.defaultProps = {
...Transition.defaultProps,
tag: 'div',
timeout: TransitionTimeouts.Carousel,
slide: true,
};
CarouselItem.contextTypes = {
direction: PropTypes.string
};
export default CarouselItem;