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

133 lines
4.5 KiB
JavaScript

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";
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Carousel from './Carousel';
import CarouselItem from './CarouselItem';
import CarouselControl from './CarouselControl';
import CarouselIndicators from './CarouselIndicators';
import CarouselCaption from './CarouselCaption';
var propTypes = {
items: PropTypes.array.isRequired,
indicators: PropTypes.bool,
controls: PropTypes.bool,
autoPlay: PropTypes.bool,
defaultActiveIndex: PropTypes.number,
activeIndex: PropTypes.number,
next: PropTypes.func,
previous: PropTypes.func,
goToIndex: PropTypes.func
};
var UncontrolledCarousel = /*#__PURE__*/function (_Component) {
_inheritsLoose(UncontrolledCarousel, _Component);
function UncontrolledCarousel(props) {
var _this;
_this = _Component.call(this, props) || this;
_this.animating = false;
_this.state = {
activeIndex: props.defaultActiveIndex || 0
};
_this.next = _this.next.bind(_assertThisInitialized(_this));
_this.previous = _this.previous.bind(_assertThisInitialized(_this));
_this.goToIndex = _this.goToIndex.bind(_assertThisInitialized(_this));
_this.onExiting = _this.onExiting.bind(_assertThisInitialized(_this));
_this.onExited = _this.onExited.bind(_assertThisInitialized(_this));
return _this;
}
var _proto = UncontrolledCarousel.prototype;
_proto.onExiting = function onExiting() {
this.animating = true;
};
_proto.onExited = function onExited() {
this.animating = false;
};
_proto.next = function next() {
if (this.animating) return;
var nextIndex = this.state.activeIndex === this.props.items.length - 1 ? 0 : this.state.activeIndex + 1;
this.setState({
activeIndex: nextIndex
});
};
_proto.previous = function previous() {
if (this.animating) return;
var nextIndex = this.state.activeIndex === 0 ? this.props.items.length - 1 : this.state.activeIndex - 1;
this.setState({
activeIndex: nextIndex
});
};
_proto.goToIndex = function goToIndex(newIndex) {
if (this.animating) return;
this.setState({
activeIndex: newIndex
});
};
_proto.render = function render() {
var _this2 = this;
var _this$props = this.props,
defaultActiveIndex = _this$props.defaultActiveIndex,
autoPlay = _this$props.autoPlay,
indicators = _this$props.indicators,
controls = _this$props.controls,
items = _this$props.items,
goToIndex = _this$props.goToIndex,
props = _objectWithoutPropertiesLoose(_this$props, ["defaultActiveIndex", "autoPlay", "indicators", "controls", "items", "goToIndex"]);
var activeIndex = this.state.activeIndex;
var slides = items.map(function (item) {
var key = item.key || item.src;
return /*#__PURE__*/React.createElement(CarouselItem, {
onExiting: _this2.onExiting,
onExited: _this2.onExited,
key: key
}, /*#__PURE__*/React.createElement("img", {
className: "d-block w-100",
src: item.src,
alt: item.altText
}), /*#__PURE__*/React.createElement(CarouselCaption, {
captionText: item.caption,
captionHeader: item.header || item.caption
}));
});
return /*#__PURE__*/React.createElement(Carousel, _extends({
activeIndex: activeIndex,
next: this.next,
previous: this.previous,
ride: autoPlay ? 'carousel' : undefined
}, props), indicators && /*#__PURE__*/React.createElement(CarouselIndicators, {
items: items,
activeIndex: props.activeIndex || activeIndex,
onClickHandler: goToIndex || this.goToIndex
}), slides, controls && /*#__PURE__*/React.createElement(CarouselControl, {
direction: "prev",
directionText: "Previous",
onClickHandler: props.previous || this.previous
}), controls && /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
directionText: "Next",
onClickHandler: props.next || this.next
}));
};
return UncontrolledCarousel;
}(Component);
UncontrolledCarousel.propTypes = propTypes;
UncontrolledCarousel.defaultProps = {
controls: true,
indicators: true,
autoPlay: true
};
export default UncontrolledCarousel;