|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134 |
- import _extends from "@babel/runtime/helpers/esm/extends";
- import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
- import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
- import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
- 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(_assertThisInitialized(_this)));
- _this.previous = _this.previous.bind(_assertThisInitialized(_assertThisInitialized(_this)));
- _this.goToIndex = _this.goToIndex.bind(_assertThisInitialized(_assertThisInitialized(_this)));
- _this.onExiting = _this.onExiting.bind(_assertThisInitialized(_assertThisInitialized(_this)));
- _this.onExited = _this.onExited.bind(_assertThisInitialized(_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) {
- return React.createElement(CarouselItem, {
- onExiting: _this2.onExiting,
- onExited: _this2.onExited,
- key: item.src
- }, React.createElement("img", {
- className: "d-block w-100",
- src: item.src,
- alt: item.altText
- }), React.createElement(CarouselCaption, {
- captionText: item.caption,
- captionHeader: item.header || item.caption
- }));
- });
- return React.createElement(Carousel, _extends({
- activeIndex: activeIndex,
- next: this.next,
- previous: this.previous,
- ride: autoPlay ? 'carousel' : undefined
- }, props), indicators && React.createElement(CarouselIndicators, {
- items: items,
- activeIndex: props.activeIndex || activeIndex,
- onClickHandler: goToIndex || this.goToIndex
- }), slides, controls && React.createElement(CarouselControl, {
- direction: "prev",
- directionText: "Previous",
- onClickHandler: props.previous || this.previous
- }), controls && 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;
|