UNPKG

reactstrap

Version:
137 lines 9.96 kB
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); } var _excluded = ["in", "children", "cssModule", "slide", "tag", "className"]; 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; } 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; } 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; } 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); } 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; } 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; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } 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); } } function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; } 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); } function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } 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); }; } 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); } function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } 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; } } function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } import React from 'react'; import PropTypes from 'prop-types'; import classNames from 'classnames'; import { Transition } from 'react-transition-group'; import { CarouselContext } from './CarouselContext'; import { mapToCssModules, TransitionTimeouts, TransitionStatuses, tagPropType } from './utils'; var CarouselItem = /*#__PURE__*/function (_React$Component) { _inherits(CarouselItem, _React$Component); var _super = _createSuper(CarouselItem); function CarouselItem(props) { var _this; _classCallCheck(this, CarouselItem); _this = _super.call(this, props); _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; } _createClass(CarouselItem, [{ key: "onEnter", value: function onEnter(node, isAppearing) { this.setState({ startAnimation: false }); this.props.onEnter(node, isAppearing); } }, { key: "onEntering", value: 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; } }, { key: "onExit", value: function onExit(node) { this.setState({ startAnimation: false }); this.props.onExit(node); } }, { key: "onExiting", value: function onExiting(node) { this.setState({ startAnimation: true }); node.dispatchEvent(new CustomEvent('slide.bs.carousel')); this.props.onExiting(node); } }, { key: "onExited", value: function onExited(node) { node.dispatchEvent(new CustomEvent('slid.bs.carousel')); this.props.onExited(node); } }, { key: "render", value: function render() { var _this2 = this; var _this$props = this.props, isIn = _this$props["in"], children = _this$props.children, cssModule = _this$props.cssModule, _this$props$slide = _this$props.slide, slide = _this$props$slide === void 0 ? true : _this$props$slide, _this$props$tag = _this$props.tag, Tag = _this$props$tag === void 0 ? 'div' : _this$props$tag, className = _this$props.className, transitionProps = _objectWithoutProperties(_this$props, _excluded); 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 === 'end' ? 'carousel-item-start' : 'carousel-item-end'); var orderClassName = status === TransitionStatuses.ENTERING && (direction === 'end' ? '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), {}, { /** Set a custom element for this component */ tag: tagPropType, "in": PropTypes.bool, /** Change underlying component's CSS base class name */ cssModule: PropTypes.object, children: PropTypes.node, /** Enable/disable animation */ slide: PropTypes.bool, /** Add custom class */ className: PropTypes.string }); CarouselItem.defaultProps = _objectSpread(_objectSpread({}, Transition.defaultProps), {}, { timeout: TransitionTimeouts.Carousel }); CarouselItem.contextType = CarouselContext; export default CarouselItem;