1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 | var _react = _interopRequireWildcard(require("react"));
|
8 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
9 | var _Carousel = _interopRequireDefault(require("./Carousel"));
|
10 | var _CarouselItem = _interopRequireDefault(require("./CarouselItem"));
|
11 | var _CarouselControl = _interopRequireDefault(require("./CarouselControl"));
|
12 | var _CarouselIndicators = _interopRequireDefault(require("./CarouselIndicators"));
|
13 | var _CarouselCaption = _interopRequireDefault(require("./CarouselCaption"));
|
14 | const _excluded = ["defaultActiveIndex", "autoPlay", "indicators", "controls", "items", "goToIndex"];
|
15 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
16 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
17 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
18 | 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); }
|
19 | 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; }
|
20 | 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; }
|
21 | const propTypes = {
|
22 | items: _propTypes.default.array.isRequired,
|
23 | indicators: _propTypes.default.bool,
|
24 | controls: _propTypes.default.bool,
|
25 | autoPlay: _propTypes.default.bool,
|
26 | defaultActiveIndex: _propTypes.default.number,
|
27 | activeIndex: _propTypes.default.number,
|
28 | next: _propTypes.default.func,
|
29 | previous: _propTypes.default.func,
|
30 | goToIndex: _propTypes.default.func
|
31 | };
|
32 | class UncontrolledCarousel extends _react.Component {
|
33 | constructor(props) {
|
34 | super(props);
|
35 | this.animating = false;
|
36 | this.state = {
|
37 | activeIndex: props.defaultActiveIndex || 0
|
38 | };
|
39 | this.next = this.next.bind(this);
|
40 | this.previous = this.previous.bind(this);
|
41 | this.goToIndex = this.goToIndex.bind(this);
|
42 | this.onExiting = this.onExiting.bind(this);
|
43 | this.onExited = this.onExited.bind(this);
|
44 | }
|
45 | onExiting() {
|
46 | this.animating = true;
|
47 | }
|
48 | onExited() {
|
49 | this.animating = false;
|
50 | }
|
51 | next() {
|
52 | if (this.animating) return;
|
53 | this.setState(prevState => {
|
54 | const nextIndex = prevState.activeIndex === this.props.items.length - 1 ? 0 : prevState.activeIndex + 1;
|
55 | return {
|
56 | activeIndex: nextIndex
|
57 | };
|
58 | });
|
59 | }
|
60 | previous() {
|
61 | if (this.animating) return;
|
62 | this.setState(prevState => {
|
63 | const nextIndex = prevState.activeIndex === 0 ? this.props.items.length - 1 : prevState.activeIndex - 1;
|
64 | return {
|
65 | activeIndex: nextIndex
|
66 | };
|
67 | });
|
68 | }
|
69 | goToIndex(newIndex) {
|
70 | if (this.animating) return;
|
71 | this.setState({
|
72 | activeIndex: newIndex
|
73 | });
|
74 | }
|
75 | render() {
|
76 | const _this$props = this.props,
|
77 | {
|
78 | defaultActiveIndex,
|
79 | autoPlay = true,
|
80 | indicators = true,
|
81 | controls = true,
|
82 | items,
|
83 | goToIndex
|
84 | } = _this$props,
|
85 | props = _objectWithoutProperties(_this$props, _excluded);
|
86 | const {
|
87 | activeIndex
|
88 | } = this.state;
|
89 | const slides = items.map(item => {
|
90 | const key = item.key || item.src;
|
91 | return _react.default.createElement(_CarouselItem.default, {
|
92 | onExiting: this.onExiting,
|
93 | onExited: this.onExited,
|
94 | key: key
|
95 | }, _react.default.createElement("img", {
|
96 | className: "d-block w-100",
|
97 | src: item.src,
|
98 | alt: item.altText
|
99 | }), _react.default.createElement(_CarouselCaption.default, {
|
100 | captionText: item.caption,
|
101 | captionHeader: item.header || item.caption
|
102 | }));
|
103 | });
|
104 | return _react.default.createElement(_Carousel.default, _extends({
|
105 | activeIndex: activeIndex,
|
106 | next: this.next,
|
107 | previous: this.previous,
|
108 | ride: autoPlay ? 'carousel' : undefined
|
109 | }, props), indicators && _react.default.createElement(_CarouselIndicators.default, {
|
110 | items: items,
|
111 | activeIndex: props.activeIndex || activeIndex,
|
112 | onClickHandler: goToIndex || this.goToIndex
|
113 | }), slides, controls && _react.default.createElement(_CarouselControl.default, {
|
114 | direction: "prev",
|
115 | directionText: "Previous",
|
116 | onClickHandler: props.previous || this.previous
|
117 | }), controls && _react.default.createElement(_CarouselControl.default, {
|
118 | direction: "next",
|
119 | directionText: "Next",
|
120 | onClickHandler: props.next || this.next
|
121 | }));
|
122 | }
|
123 | }
|
124 | UncontrolledCarousel.propTypes = propTypes;
|
125 | var _default = UncontrolledCarousel;
|
126 | exports.default = _default; |
\ | No newline at end of file |