1 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2 | var _excluded = ["in", "children", "cssModule", "slide", "tag", "className"];
|
3 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
4 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
5 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
6 | function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
7 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
8 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
9 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
10 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
11 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
12 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
13 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
14 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
15 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
16 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
17 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
18 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
19 | import React from 'react';
|
20 | import PropTypes from 'prop-types';
|
21 | import classNames from 'classnames';
|
22 | import { Transition } from 'react-transition-group';
|
23 | import { CarouselContext } from './CarouselContext';
|
24 | import { mapToCssModules, TransitionTimeouts, TransitionStatuses, tagPropType } from './utils';
|
25 | var CarouselItem = function (_React$Component) {
|
26 | _inherits(CarouselItem, _React$Component);
|
27 | var _super = _createSuper(CarouselItem);
|
28 | function CarouselItem(props) {
|
29 | var _this;
|
30 | _classCallCheck(this, CarouselItem);
|
31 | _this = _super.call(this, props);
|
32 | _this.state = {
|
33 | startAnimation: false
|
34 | };
|
35 | _this.onEnter = _this.onEnter.bind(_assertThisInitialized(_this));
|
36 | _this.onEntering = _this.onEntering.bind(_assertThisInitialized(_this));
|
37 | _this.onExit = _this.onExit.bind(_assertThisInitialized(_this));
|
38 | _this.onExiting = _this.onExiting.bind(_assertThisInitialized(_this));
|
39 | _this.onExited = _this.onExited.bind(_assertThisInitialized(_this));
|
40 | return _this;
|
41 | }
|
42 | _createClass(CarouselItem, [{
|
43 | key: "onEnter",
|
44 | value: function onEnter(node, isAppearing) {
|
45 | this.setState({
|
46 | startAnimation: false
|
47 | });
|
48 | this.props.onEnter(node, isAppearing);
|
49 | }
|
50 | }, {
|
51 | key: "onEntering",
|
52 | value: function onEntering(node, isAppearing) {
|
53 |
|
54 | var offsetHeight = node.offsetHeight;
|
55 | this.setState({
|
56 | startAnimation: true
|
57 | });
|
58 | this.props.onEntering(node, isAppearing);
|
59 | return offsetHeight;
|
60 | }
|
61 | }, {
|
62 | key: "onExit",
|
63 | value: function onExit(node) {
|
64 | this.setState({
|
65 | startAnimation: false
|
66 | });
|
67 | this.props.onExit(node);
|
68 | }
|
69 | }, {
|
70 | key: "onExiting",
|
71 | value: function onExiting(node) {
|
72 | this.setState({
|
73 | startAnimation: true
|
74 | });
|
75 | node.dispatchEvent(new CustomEvent('slide.bs.carousel'));
|
76 | this.props.onExiting(node);
|
77 | }
|
78 | }, {
|
79 | key: "onExited",
|
80 | value: function onExited(node) {
|
81 | node.dispatchEvent(new CustomEvent('slid.bs.carousel'));
|
82 | this.props.onExited(node);
|
83 | }
|
84 | }, {
|
85 | key: "render",
|
86 | value: function render() {
|
87 | var _this2 = this;
|
88 | var _this$props = this.props,
|
89 | isIn = _this$props["in"],
|
90 | children = _this$props.children,
|
91 | cssModule = _this$props.cssModule,
|
92 | _this$props$slide = _this$props.slide,
|
93 | slide = _this$props$slide === void 0 ? true : _this$props$slide,
|
94 | _this$props$tag = _this$props.tag,
|
95 | Tag = _this$props$tag === void 0 ? 'div' : _this$props$tag,
|
96 | className = _this$props.className,
|
97 | transitionProps = _objectWithoutProperties(_this$props, _excluded);
|
98 | return React.createElement(Transition, _extends({}, transitionProps, {
|
99 | enter: slide,
|
100 | exit: slide,
|
101 | "in": isIn,
|
102 | onEnter: this.onEnter,
|
103 | onEntering: this.onEntering,
|
104 | onExit: this.onExit,
|
105 | onExiting: this.onExiting,
|
106 | onExited: this.onExited
|
107 | }), function (status) {
|
108 | var direction = _this2.context.direction;
|
109 | var isActive = status === TransitionStatuses.ENTERED || status === TransitionStatuses.EXITING;
|
110 | var directionClassName = (status === TransitionStatuses.ENTERING || status === TransitionStatuses.EXITING) && _this2.state.startAnimation && (direction === 'end' ? 'carousel-item-start' : 'carousel-item-end');
|
111 | var orderClassName = status === TransitionStatuses.ENTERING && (direction === 'end' ? 'carousel-item-next' : 'carousel-item-prev');
|
112 | var itemClasses = mapToCssModules(classNames(className, 'carousel-item', isActive && 'active', directionClassName, orderClassName), cssModule);
|
113 | return React.createElement(Tag, {
|
114 | className: itemClasses
|
115 | }, children);
|
116 | });
|
117 | }
|
118 | }]);
|
119 | return CarouselItem;
|
120 | }(React.Component);
|
121 | CarouselItem.propTypes = _objectSpread(_objectSpread({}, Transition.propTypes), {}, {
|
122 |
|
123 | tag: tagPropType,
|
124 | "in": PropTypes.bool,
|
125 |
|
126 | cssModule: PropTypes.object,
|
127 | children: PropTypes.node,
|
128 |
|
129 | slide: PropTypes.bool,
|
130 |
|
131 | className: PropTypes.string
|
132 | });
|
133 | CarouselItem.defaultProps = _objectSpread(_objectSpread({}, Transition.defaultProps), {}, {
|
134 | timeout: TransitionTimeouts.Carousel
|
135 | });
|
136 | CarouselItem.contextType = CarouselContext;
|
137 | export default CarouselItem; |
\ | No newline at end of file |