GoScrobble/web/node_modules/reactstrap/es/CarouselItem.js

126 lines
5.1 KiB
JavaScript

import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
import _extends from "@babel/runtime/helpers/esm/extends";
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames';
import { Transition } from 'react-transition-group';
import { mapToCssModules, TransitionTimeouts, TransitionStatuses, tagPropType } from './utils';
var CarouselItem = /*#__PURE__*/function (_React$Component) {
_inheritsLoose(CarouselItem, _React$Component);
function CarouselItem(props) {
var _this;
_this = _React$Component.call(this, props) || this;
_this.state = {
startAnimation: false
};
_this.onEnter = _this.onEnter.bind(_assertThisInitialized(_this));
_this.onEntering = _this.onEntering.bind(_assertThisInitialized(_this));
_this.onExit = _this.onExit.bind(_assertThisInitialized(_this));
_this.onExiting = _this.onExiting.bind(_assertThisInitialized(_this));
_this.onExited = _this.onExited.bind(_assertThisInitialized(_this));
return _this;
}
var _proto = CarouselItem.prototype;
_proto.onEnter = function onEnter(node, isAppearing) {
this.setState({
startAnimation: false
});
this.props.onEnter(node, isAppearing);
};
_proto.onEntering = function onEntering(node, isAppearing) {
// getting this variable triggers a reflow
var offsetHeight = node.offsetHeight;
this.setState({
startAnimation: true
});
this.props.onEntering(node, isAppearing);
return offsetHeight;
};
_proto.onExit = function onExit(node) {
this.setState({
startAnimation: false
});
this.props.onExit(node);
};
_proto.onExiting = function onExiting(node) {
this.setState({
startAnimation: true
});
node.dispatchEvent(new CustomEvent('slide.bs.carousel'));
this.props.onExiting(node);
};
_proto.onExited = function onExited(node) {
node.dispatchEvent(new CustomEvent('slid.bs.carousel'));
this.props.onExited(node);
};
_proto.render = function render() {
var _this2 = this;
var _this$props = this.props,
isIn = _this$props.in,
children = _this$props.children,
cssModule = _this$props.cssModule,
slide = _this$props.slide,
Tag = _this$props.tag,
className = _this$props.className,
transitionProps = _objectWithoutPropertiesLoose(_this$props, ["in", "children", "cssModule", "slide", "tag", "className"]);
return /*#__PURE__*/React.createElement(Transition, _extends({}, transitionProps, {
enter: slide,
exit: slide,
in: isIn,
onEnter: this.onEnter,
onEntering: this.onEntering,
onExit: this.onExit,
onExiting: this.onExiting,
onExited: this.onExited
}), function (status) {
var direction = _this2.context.direction;
var isActive = status === TransitionStatuses.ENTERED || status === TransitionStatuses.EXITING;
var directionClassName = (status === TransitionStatuses.ENTERING || status === TransitionStatuses.EXITING) && _this2.state.startAnimation && (direction === 'right' ? 'carousel-item-left' : 'carousel-item-right');
var orderClassName = status === TransitionStatuses.ENTERING && (direction === 'right' ? 'carousel-item-next' : 'carousel-item-prev');
var itemClasses = mapToCssModules(classNames(className, 'carousel-item', isActive && 'active', directionClassName, orderClassName), cssModule);
return /*#__PURE__*/React.createElement(Tag, {
className: itemClasses
}, children);
});
};
return CarouselItem;
}(React.Component);
CarouselItem.propTypes = _objectSpread(_objectSpread({}, Transition.propTypes), {}, {
tag: tagPropType,
in: PropTypes.bool,
cssModule: PropTypes.object,
children: PropTypes.node,
slide: PropTypes.bool,
className: PropTypes.string
});
CarouselItem.defaultProps = _objectSpread(_objectSpread({}, Transition.defaultProps), {}, {
tag: 'div',
timeout: TransitionTimeouts.Carousel,
slide: true
});
CarouselItem.contextTypes = {
direction: PropTypes.string
};
export default CarouselItem;