UNPKG

9.21 kBJavaScriptView Raw
1function _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); }
2var _excluded = ["defaultActiveIndex", "autoPlay", "indicators", "controls", "items", "goToIndex"];
3function _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); }
4function _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; }
5function _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; }
6function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
7function _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); } }
8function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
9function _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); }
10function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
11function _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); }; }
12function _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); }
13function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
14function _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; } }
15function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
16import React, { Component } from 'react';
17import PropTypes from 'prop-types';
18import Carousel from './Carousel';
19import CarouselItem from './CarouselItem';
20import CarouselControl from './CarouselControl';
21import CarouselIndicators from './CarouselIndicators';
22import CarouselCaption from './CarouselCaption';
23var propTypes = {
24 items: PropTypes.array.isRequired,
25 indicators: PropTypes.bool,
26 controls: PropTypes.bool,
27 autoPlay: PropTypes.bool,
28 defaultActiveIndex: PropTypes.number,
29 activeIndex: PropTypes.number,
30 next: PropTypes.func,
31 previous: PropTypes.func,
32 goToIndex: PropTypes.func
33};
34var UncontrolledCarousel = /*#__PURE__*/function (_Component) {
35 _inherits(UncontrolledCarousel, _Component);
36 var _super = _createSuper(UncontrolledCarousel);
37 function UncontrolledCarousel(props) {
38 var _this;
39 _classCallCheck(this, UncontrolledCarousel);
40 _this = _super.call(this, props);
41 _this.animating = false;
42 _this.state = {
43 activeIndex: props.defaultActiveIndex || 0
44 };
45 _this.next = _this.next.bind(_assertThisInitialized(_this));
46 _this.previous = _this.previous.bind(_assertThisInitialized(_this));
47 _this.goToIndex = _this.goToIndex.bind(_assertThisInitialized(_this));
48 _this.onExiting = _this.onExiting.bind(_assertThisInitialized(_this));
49 _this.onExited = _this.onExited.bind(_assertThisInitialized(_this));
50 return _this;
51 }
52 _createClass(UncontrolledCarousel, [{
53 key: "onExiting",
54 value: function onExiting() {
55 this.animating = true;
56 }
57 }, {
58 key: "onExited",
59 value: function onExited() {
60 this.animating = false;
61 }
62 }, {
63 key: "next",
64 value: function next() {
65 var _this2 = this;
66 if (this.animating) return;
67 this.setState(function (prevState) {
68 var nextIndex = prevState.activeIndex === _this2.props.items.length - 1 ? 0 : prevState.activeIndex + 1;
69 return {
70 activeIndex: nextIndex
71 };
72 });
73 }
74 }, {
75 key: "previous",
76 value: function previous() {
77 var _this3 = this;
78 if (this.animating) return;
79 this.setState(function (prevState) {
80 var nextIndex = prevState.activeIndex === 0 ? _this3.props.items.length - 1 : prevState.activeIndex - 1;
81 return {
82 activeIndex: nextIndex
83 };
84 });
85 }
86 }, {
87 key: "goToIndex",
88 value: function goToIndex(newIndex) {
89 if (this.animating) return;
90 this.setState({
91 activeIndex: newIndex
92 });
93 }
94 }, {
95 key: "render",
96 value: function render() {
97 var _this4 = this;
98 var _this$props = this.props,
99 defaultActiveIndex = _this$props.defaultActiveIndex,
100 _this$props$autoPlay = _this$props.autoPlay,
101 autoPlay = _this$props$autoPlay === void 0 ? true : _this$props$autoPlay,
102 _this$props$indicator = _this$props.indicators,
103 indicators = _this$props$indicator === void 0 ? true : _this$props$indicator,
104 _this$props$controls = _this$props.controls,
105 controls = _this$props$controls === void 0 ? true : _this$props$controls,
106 items = _this$props.items,
107 goToIndex = _this$props.goToIndex,
108 props = _objectWithoutProperties(_this$props, _excluded);
109 var activeIndex = this.state.activeIndex;
110 var slides = items.map(function (item) {
111 var key = item.key || item.src;
112 return /*#__PURE__*/React.createElement(CarouselItem, {
113 onExiting: _this4.onExiting,
114 onExited: _this4.onExited,
115 key: key
116 }, /*#__PURE__*/React.createElement("img", {
117 className: "d-block w-100",
118 src: item.src,
119 alt: item.altText
120 }), /*#__PURE__*/React.createElement(CarouselCaption, {
121 captionText: item.caption,
122 captionHeader: item.header || item.caption
123 }));
124 });
125 return /*#__PURE__*/React.createElement(Carousel, _extends({
126 activeIndex: activeIndex,
127 next: this.next,
128 previous: this.previous,
129 ride: autoPlay ? 'carousel' : undefined
130 }, props), indicators && /*#__PURE__*/React.createElement(CarouselIndicators, {
131 items: items,
132 activeIndex: props.activeIndex || activeIndex,
133 onClickHandler: goToIndex || this.goToIndex
134 }), slides, controls && /*#__PURE__*/React.createElement(CarouselControl, {
135 direction: "prev",
136 directionText: "Previous",
137 onClickHandler: props.previous || this.previous
138 }), controls && /*#__PURE__*/React.createElement(CarouselControl, {
139 direction: "next",
140 directionText: "Next",
141 onClickHandler: props.next || this.next
142 }));
143 }
144 }]);
145 return UncontrolledCarousel;
146}(Component);
147UncontrolledCarousel.propTypes = propTypes;
148export default UncontrolledCarousel;
\No newline at end of file