react-slideshow-image 3.4.7 → 3.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -37
- package/dist/react-slideshow-image.min.js +1 -1
- package/dist/react-slideshow-image.min.js.map +1 -1
- package/lib/fade.js +55 -13
- package/lib/helpers.js +19 -13
- package/lib/props.js +8 -6
- package/lib/slide.js +150 -53
- package/lib/zoom.js +56 -14
- package/package.json +2 -2
package/lib/fade.js
CHANGED
@@ -67,6 +67,8 @@ function (_Component) {
|
|
67
67
|
_this.tweenGroup = new _tween["default"].Group();
|
68
68
|
_this.reactSlideshowWrapper = (0, _react.createRef)();
|
69
69
|
_this.wrapper = (0, _react.createRef)();
|
70
|
+
_this.startSwipe = _this.startSwipe.bind(_assertThisInitialized(_this));
|
71
|
+
_this.endSwipe = _this.endSwipe.bind(_assertThisInitialized(_this));
|
70
72
|
return _this;
|
71
73
|
}
|
72
74
|
|
@@ -258,28 +260,68 @@ function (_Component) {
|
|
258
260
|
this.goNext();
|
259
261
|
}
|
260
262
|
}
|
263
|
+
}, {
|
264
|
+
key: "startSwipe",
|
265
|
+
value: function startSwipe(e) {
|
266
|
+
var _getProps6 = (0, _props.getProps)(this.props),
|
267
|
+
canSwipe = _getProps6.canSwipe;
|
268
|
+
|
269
|
+
if (canSwipe) {
|
270
|
+
this.startingClientX = e.touches ? e.touches[0].pageX : e.clientX;
|
271
|
+
clearTimeout(this.timeout);
|
272
|
+
this.dragging = true;
|
273
|
+
}
|
274
|
+
}
|
275
|
+
}, {
|
276
|
+
key: "endSwipe",
|
277
|
+
value: function endSwipe(e) {
|
278
|
+
var clientX = e.changedTouches ? e.changedTouches[0].pageX : e.clientX;
|
279
|
+
var distance = clientX - this.startingClientX;
|
280
|
+
|
281
|
+
var _getProps7 = (0, _props.getProps)(this.props),
|
282
|
+
canSwipe = _getProps7.canSwipe;
|
283
|
+
|
284
|
+
if (canSwipe) {
|
285
|
+
this.dragging = false;
|
286
|
+
|
287
|
+
if (Math.abs(distance) / this.width > 0.2) {
|
288
|
+
if (distance < 0) {
|
289
|
+
this.goNext();
|
290
|
+
} else {
|
291
|
+
this.goBack();
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
295
|
+
}
|
261
296
|
}, {
|
262
297
|
key: "render",
|
263
298
|
value: function render() {
|
264
299
|
var _this5 = this;
|
265
300
|
|
266
|
-
var
|
267
|
-
indicators =
|
268
|
-
children =
|
269
|
-
arrows =
|
301
|
+
var _getProps8 = (0, _props.getProps)(this.props),
|
302
|
+
indicators = _getProps8.indicators,
|
303
|
+
children = _getProps8.children,
|
304
|
+
arrows = _getProps8.arrows,
|
305
|
+
cssClass = _getProps8.cssClass;
|
270
306
|
|
271
307
|
var index = this.state.index;
|
272
308
|
var unhandledProps = (0, _helpers.getUnhandledProps)(_props.propTypes, this.props);
|
273
309
|
return _react["default"].createElement("div", _extends({
|
310
|
+
dir: "ltr",
|
274
311
|
"aria-roledescription": "carousel"
|
275
312
|
}, unhandledProps), _react["default"].createElement("div", {
|
276
313
|
className: "react-slideshow-container",
|
277
314
|
onMouseEnter: this.pauseSlides,
|
278
315
|
onMouseOver: this.pauseSlides,
|
279
316
|
onMouseLeave: this.startSlides,
|
317
|
+
onMouseDown: this.startSwipe,
|
318
|
+
onMouseUp: this.endSwipe,
|
319
|
+
onTouchStart: this.startSwipe,
|
320
|
+
onTouchEnd: this.endSwipe,
|
321
|
+
onTouchCancel: this.endSwipe,
|
280
322
|
ref: this.reactSlideshowWrapper
|
281
323
|
}, arrows && (0, _helpers.showPreviousArrow)((0, _props.getProps)(this.props), this.state.index, this.preFade), _react["default"].createElement("div", {
|
282
|
-
className: "react-slideshow-fade-wrapper",
|
324
|
+
className: "react-slideshow-fade-wrapper ".concat(cssClass),
|
283
325
|
ref: this.wrapper
|
284
326
|
}, _react["default"].createElement("div", {
|
285
327
|
className: "react-slideshow-fade-images-wrap",
|
@@ -306,14 +348,14 @@ function (_Component) {
|
|
306
348
|
|
307
349
|
var index = this.state.index;
|
308
350
|
|
309
|
-
var
|
310
|
-
autoplay =
|
311
|
-
children =
|
312
|
-
infinite =
|
313
|
-
duration =
|
314
|
-
transitionDuration =
|
315
|
-
onChange =
|
316
|
-
easing =
|
351
|
+
var _getProps9 = (0, _props.getProps)(this.props),
|
352
|
+
autoplay = _getProps9.autoplay,
|
353
|
+
children = _getProps9.children,
|
354
|
+
infinite = _getProps9.infinite,
|
355
|
+
duration = _getProps9.duration,
|
356
|
+
transitionDuration = _getProps9.transitionDuration,
|
357
|
+
onChange = _getProps9.onChange,
|
358
|
+
easing = _getProps9.easing;
|
317
359
|
|
318
360
|
var existingTweens = this.tweenGroup.getAll();
|
319
361
|
|
package/lib/helpers.js
CHANGED
@@ -76,11 +76,12 @@ var showPreviousArrow = function showPreviousArrow(_ref, currentIndex, moveSlide
|
|
76
76
|
|
77
77
|
exports.showPreviousArrow = showPreviousArrow;
|
78
78
|
|
79
|
-
var showNextArrow = function showNextArrow(
|
80
|
-
var nextArrow =
|
81
|
-
infinite =
|
82
|
-
children =
|
83
|
-
|
79
|
+
var showNextArrow = function showNextArrow(properties, currentIndex, moveSlides) {
|
80
|
+
var nextArrow = properties.nextArrow,
|
81
|
+
infinite = properties.infinite,
|
82
|
+
children = properties.children,
|
83
|
+
slidesToScroll = properties.slidesToScroll;
|
84
|
+
var isDisabled = currentIndex >= children.length - slidesToScroll && !infinite;
|
84
85
|
var props = {
|
85
86
|
'data-type': 'next',
|
86
87
|
'aria-label': 'Next Slide',
|
@@ -108,39 +109,44 @@ var showNextArrow = function showNextArrow(_ref2, currentIndex, moveSlides) {
|
|
108
109
|
|
109
110
|
exports.showNextArrow = showNextArrow;
|
110
111
|
|
111
|
-
var showDefaultIndicator = function showDefaultIndicator(
|
112
|
+
var showDefaultIndicator = function showDefaultIndicator(isCurrentPageActive, key, indicatorProps) {
|
112
113
|
return _react["default"].createElement("li", {
|
113
114
|
key: key
|
114
115
|
}, _react["default"].createElement("button", _extends({
|
115
|
-
className: "each-slideshow-indicator ".concat(
|
116
|
+
className: "each-slideshow-indicator ".concat(isCurrentPageActive ? 'active' : '')
|
116
117
|
}, indicatorProps)));
|
117
118
|
};
|
118
119
|
|
119
|
-
var showCustomIndicator = function showCustomIndicator(
|
120
|
+
var showCustomIndicator = function showCustomIndicator(isCurrentPageActive, key, indicatorProps, eachIndicator) {
|
120
121
|
return _react["default"].cloneElement(eachIndicator, _objectSpread({
|
121
|
-
className: "".concat(eachIndicator.props.className, " ").concat(
|
122
|
+
className: "".concat(eachIndicator.props.className, " ").concat(isCurrentPageActive ? 'active' : ''),
|
122
123
|
key: key
|
123
124
|
}, indicatorProps));
|
124
125
|
};
|
125
126
|
|
126
127
|
var showIndicators = function showIndicators(props, currentIndex, navigate) {
|
127
128
|
var children = props.children,
|
128
|
-
indicators = props.indicators
|
129
|
+
indicators = props.indicators,
|
130
|
+
slidesToScroll = props.slidesToScroll;
|
129
131
|
var isCustomIndicator = typeof indicators !== 'boolean';
|
132
|
+
var pages = Math.ceil(children.length / slidesToScroll);
|
130
133
|
return _react["default"].createElement("ul", {
|
131
134
|
className: "indicators"
|
132
|
-
},
|
135
|
+
}, Array.from({
|
136
|
+
length: pages
|
137
|
+
}, function (_, key) {
|
133
138
|
var indicatorProps = {
|
134
139
|
'data-key': key,
|
135
140
|
'aria-label': "Go to slide ".concat(key + 1),
|
136
141
|
onClick: navigate
|
137
142
|
};
|
143
|
+
var isCurrentPageActive = Math.floor((currentIndex + slidesToScroll - 1) / slidesToScroll) === key;
|
138
144
|
|
139
145
|
if (isCustomIndicator) {
|
140
|
-
return showCustomIndicator(
|
146
|
+
return showCustomIndicator(isCurrentPageActive, key, indicatorProps, indicators(key));
|
141
147
|
}
|
142
148
|
|
143
|
-
return showDefaultIndicator(
|
149
|
+
return showDefaultIndicator(isCurrentPageActive, key, indicatorProps);
|
144
150
|
}));
|
145
151
|
};
|
146
152
|
|
package/lib/props.js
CHANGED
@@ -28,7 +28,10 @@ var defaultProps = {
|
|
28
28
|
pauseOnHover: true,
|
29
29
|
scale: 1,
|
30
30
|
easing: 'linear',
|
31
|
-
canSwipe: true
|
31
|
+
canSwipe: true,
|
32
|
+
slidesToShow: 1,
|
33
|
+
slidesToScroll: 1,
|
34
|
+
cssClass: ''
|
32
35
|
};
|
33
36
|
|
34
37
|
var getProps = function getProps(componentProps) {
|
@@ -36,10 +39,6 @@ var getProps = function getProps(componentProps) {
|
|
36
39
|
return each;
|
37
40
|
});
|
38
41
|
|
39
|
-
if (!Array.isArray(children)) {
|
40
|
-
children = [children];
|
41
|
-
}
|
42
|
-
|
43
42
|
return _objectSpread({}, defaultProps, {}, componentProps, {
|
44
43
|
children: children
|
45
44
|
});
|
@@ -60,7 +59,10 @@ var propTypes = {
|
|
60
59
|
nextArrow: ['object', 'function'],
|
61
60
|
scale: 'number',
|
62
61
|
easing: 'string',
|
63
|
-
canSwipe: 'boolean'
|
62
|
+
canSwipe: 'boolean',
|
63
|
+
slidesToShow: 'number',
|
64
|
+
slidesToScroll: 'number',
|
65
|
+
cssClass: 'string'
|
64
66
|
};
|
65
67
|
exports.propTypes = propTypes;
|
66
68
|
|
package/lib/slide.js
CHANGED
@@ -152,14 +152,32 @@ function (_Component) {
|
|
152
152
|
key: "swipe",
|
153
153
|
value: function swipe(e) {
|
154
154
|
var _getProps4 = (0, _props.getProps)(this.props),
|
155
|
-
canSwipe = _getProps4.canSwipe
|
155
|
+
canSwipe = _getProps4.canSwipe,
|
156
|
+
slidesToShow = _getProps4.slidesToShow,
|
157
|
+
children = _getProps4.children,
|
158
|
+
infinite = _getProps4.infinite,
|
159
|
+
slidesToScroll = _getProps4.slidesToScroll;
|
156
160
|
|
157
161
|
if (canSwipe) {
|
158
162
|
var clientX = e.touches ? e.touches[0].pageX : e.clientX;
|
159
163
|
|
160
164
|
if (this.dragging) {
|
161
|
-
var translateValue = this.width * (this.state.index +
|
162
|
-
|
165
|
+
var translateValue = this.width * (this.state.index + this.getOffset(infinite, slidesToShow));
|
166
|
+
var distance = clientX - this.startingClientX;
|
167
|
+
|
168
|
+
if (!infinite && this.state.index === children.length - slidesToScroll && distance < 0) {
|
169
|
+
// if it is the last and infinite is false and you're swiping left
|
170
|
+
// then nothing happens
|
171
|
+
return;
|
172
|
+
}
|
173
|
+
|
174
|
+
if (!infinite && this.state.index === 0 && distance > 0) {
|
175
|
+
// if it is the first and infinite is false and you're swiping right
|
176
|
+
// then nothing happens
|
177
|
+
return;
|
178
|
+
}
|
179
|
+
|
180
|
+
this.distanceSwiped = distance;
|
163
181
|
translateValue -= this.distanceSwiped;
|
164
182
|
this.imageContainer.style.transform = "translate(-".concat(translateValue, "px)");
|
165
183
|
}
|
@@ -177,12 +195,20 @@ function (_Component) {
|
|
177
195
|
value: function setWidth() {
|
178
196
|
// the .slice.call was needed to support ie11
|
179
197
|
this.allImages = this.wrapper && Array.prototype.slice.call(this.wrapper.querySelectorAll(".images-wrap > div"), 0) || [];
|
180
|
-
|
181
|
-
var
|
198
|
+
|
199
|
+
var _getProps5 = (0, _props.getProps)(this.props),
|
200
|
+
slidesToShow = _getProps5.slidesToShow,
|
201
|
+
infinite = _getProps5.infinite;
|
202
|
+
|
203
|
+
this.width = (this.wrapper && this.wrapper.clientWidth || 0) / slidesToShow;
|
204
|
+
|
205
|
+
var numberOfSlides = _react["default"].Children.count(this.props.children);
|
206
|
+
|
207
|
+
var fullwidth = this.width * (numberOfSlides + slidesToShow * 2);
|
182
208
|
|
183
209
|
if (this.imageContainer) {
|
184
210
|
this.imageContainer.style.width = "".concat(fullwidth, "px");
|
185
|
-
this.imageContainer.style.transform = "translate(-".concat(this.width * (this.state.index +
|
211
|
+
this.imageContainer.style.transform = "translate(-".concat(this.width * (this.state.index + this.getOffset(infinite, slidesToShow)), "px)");
|
186
212
|
}
|
187
213
|
|
188
214
|
this.applySlideStyle();
|
@@ -192,10 +218,10 @@ function (_Component) {
|
|
192
218
|
value: function componentDidUpdate(props) {
|
193
219
|
var _this4 = this;
|
194
220
|
|
195
|
-
var
|
196
|
-
autoplay =
|
197
|
-
duration =
|
198
|
-
children =
|
221
|
+
var _getProps6 = (0, _props.getProps)(this.props),
|
222
|
+
autoplay = _getProps6.autoplay,
|
223
|
+
duration = _getProps6.duration,
|
224
|
+
children = _getProps6.children;
|
199
225
|
|
200
226
|
var newProps = (0, _props.getProps)(props);
|
201
227
|
|
@@ -243,10 +269,10 @@ function (_Component) {
|
|
243
269
|
value: function startSlides() {
|
244
270
|
var _this6 = this;
|
245
271
|
|
246
|
-
var
|
247
|
-
pauseOnHover =
|
248
|
-
autoplay =
|
249
|
-
duration =
|
272
|
+
var _getProps7 = (0, _props.getProps)(this.props),
|
273
|
+
pauseOnHover = _getProps7.pauseOnHover,
|
274
|
+
autoplay = _getProps7.autoplay,
|
275
|
+
duration = _getProps7.duration;
|
250
276
|
|
251
277
|
if (this.dragging) {
|
252
278
|
this.endSwipe();
|
@@ -273,58 +299,133 @@ function (_Component) {
|
|
273
299
|
key: "goToSlide",
|
274
300
|
value: function goToSlide(_ref2) {
|
275
301
|
var currentTarget = _ref2.currentTarget;
|
276
|
-
|
302
|
+
|
303
|
+
var _getProps8 = (0, _props.getProps)(this.props),
|
304
|
+
slidesToScroll = _getProps8.slidesToScroll;
|
305
|
+
|
306
|
+
this.goTo(parseInt(currentTarget.dataset.key * slidesToScroll));
|
277
307
|
}
|
278
308
|
}, {
|
279
309
|
key: "goTo",
|
280
310
|
value: function goTo(index) {
|
281
|
-
this.slideImages(index);
|
311
|
+
this.slideImages(this.calculateIndex(index));
|
312
|
+
}
|
313
|
+
}, {
|
314
|
+
key: "calculateIndex",
|
315
|
+
value: function calculateIndex(nextIndex) {
|
316
|
+
var _getProps9 = (0, _props.getProps)(this.props),
|
317
|
+
children = _getProps9.children,
|
318
|
+
slidesToScroll = _getProps9.slidesToScroll;
|
319
|
+
|
320
|
+
if (nextIndex < children.length && nextIndex + slidesToScroll > children.length) {
|
321
|
+
if ((children.length - slidesToScroll) % slidesToScroll) {
|
322
|
+
return children.length - slidesToScroll;
|
323
|
+
}
|
324
|
+
|
325
|
+
return nextIndex;
|
326
|
+
}
|
327
|
+
|
328
|
+
return nextIndex;
|
282
329
|
}
|
283
330
|
}, {
|
284
331
|
key: "goNext",
|
285
332
|
value: function goNext() {
|
286
333
|
var index = this.state.index;
|
287
334
|
|
288
|
-
var
|
289
|
-
children =
|
290
|
-
infinite =
|
335
|
+
var _getProps10 = (0, _props.getProps)(this.props),
|
336
|
+
children = _getProps10.children,
|
337
|
+
infinite = _getProps10.infinite,
|
338
|
+
slidesToScroll = _getProps10.slidesToScroll;
|
291
339
|
|
292
|
-
if (!infinite && index === children.length -
|
340
|
+
if (!infinite && index === children.length - slidesToScroll) {
|
293
341
|
return;
|
294
342
|
}
|
295
343
|
|
296
|
-
this.
|
344
|
+
var nextIndex = this.calculateIndex(index + slidesToScroll);
|
345
|
+
this.slideImages(nextIndex);
|
297
346
|
}
|
298
347
|
}, {
|
299
348
|
key: "goBack",
|
300
349
|
value: function goBack() {
|
301
350
|
var index = this.state.index;
|
302
351
|
|
303
|
-
var
|
304
|
-
infinite =
|
352
|
+
var _getProps11 = (0, _props.getProps)(this.props),
|
353
|
+
infinite = _getProps11.infinite,
|
354
|
+
slidesToScroll = _getProps11.slidesToScroll;
|
305
355
|
|
306
356
|
if (!infinite && index === 0) {
|
307
357
|
return;
|
308
358
|
}
|
309
359
|
|
310
|
-
|
360
|
+
var previousIndex = index - slidesToScroll;
|
361
|
+
|
362
|
+
if (previousIndex % slidesToScroll) {
|
363
|
+
previousIndex = Math.ceil(previousIndex / slidesToScroll) * slidesToScroll;
|
364
|
+
}
|
365
|
+
|
366
|
+
this.slideImages(previousIndex);
|
367
|
+
}
|
368
|
+
}, {
|
369
|
+
key: "isSlideActive",
|
370
|
+
value: function isSlideActive(key) {
|
371
|
+
var _getProps12 = (0, _props.getProps)(this.props),
|
372
|
+
slidesToShow = _getProps12.slidesToShow;
|
373
|
+
|
374
|
+
return key < this.state.index + slidesToShow && key >= this.state.index;
|
375
|
+
}
|
376
|
+
}, {
|
377
|
+
key: "renderPreceedingSlides",
|
378
|
+
value: function renderPreceedingSlides(children, slidesToShow) {
|
379
|
+
return children.slice(-slidesToShow).map(function (each, index) {
|
380
|
+
return _react["default"].createElement("div", {
|
381
|
+
"data-index": index - slidesToShow,
|
382
|
+
"aria-roledescription": "slide",
|
383
|
+
"aria-hidden": "true",
|
384
|
+
key: index - slidesToShow
|
385
|
+
}, each);
|
386
|
+
});
|
387
|
+
}
|
388
|
+
}, {
|
389
|
+
key: "renderTrailingSlides",
|
390
|
+
value: function renderTrailingSlides(children, slidesToShow) {
|
391
|
+
return children.slice(0, slidesToShow).map(function (each, index) {
|
392
|
+
return _react["default"].createElement("div", {
|
393
|
+
"data-index": children.length + index,
|
394
|
+
"aria-roledescription": "slide",
|
395
|
+
"aria-hidden": "true",
|
396
|
+
key: children.length + index
|
397
|
+
}, each);
|
398
|
+
});
|
399
|
+
}
|
400
|
+
}, {
|
401
|
+
key: "getOffset",
|
402
|
+
value: function getOffset(infinite, slidesToShow) {
|
403
|
+
if (!infinite) {
|
404
|
+
return 0;
|
405
|
+
}
|
406
|
+
|
407
|
+
return slidesToShow;
|
311
408
|
}
|
312
409
|
}, {
|
313
410
|
key: "render",
|
314
411
|
value: function render() {
|
315
412
|
var _this7 = this;
|
316
413
|
|
317
|
-
var
|
318
|
-
children =
|
319
|
-
indicators =
|
320
|
-
arrows =
|
414
|
+
var _getProps13 = (0, _props.getProps)(this.props),
|
415
|
+
children = _getProps13.children,
|
416
|
+
indicators = _getProps13.indicators,
|
417
|
+
arrows = _getProps13.arrows,
|
418
|
+
cssClass = _getProps13.cssClass,
|
419
|
+
slidesToShow = _getProps13.slidesToShow,
|
420
|
+
infinite = _getProps13.infinite;
|
321
421
|
|
322
422
|
var unhandledProps = (0, _helpers.getUnhandledProps)(_props.propTypes, this.props);
|
323
423
|
var index = this.state.index;
|
324
424
|
var style = {
|
325
|
-
transform: "translate(-".concat((index +
|
425
|
+
transform: "translate(-".concat((index + this.getOffset(infinite, slidesToShow)) * this.width, "px)")
|
326
426
|
};
|
327
427
|
return _react["default"].createElement("div", _extends({
|
428
|
+
dir: "ltr",
|
328
429
|
"aria-roledescription": "carousel"
|
329
430
|
}, unhandledProps), _react["default"].createElement("div", {
|
330
431
|
className: "react-slideshow-container",
|
@@ -340,7 +441,7 @@ function (_Component) {
|
|
340
441
|
onTouchMove: this.swipe,
|
341
442
|
ref: this.reactSlideshowWrapper
|
342
443
|
}, arrows && (0, _helpers.showPreviousArrow)((0, _props.getProps)(this.props), this.state.index, this.moveSlides), _react["default"].createElement("div", {
|
343
|
-
className: "react-slideshow-wrapper slide",
|
444
|
+
className: "react-slideshow-wrapper slide ".concat(cssClass),
|
344
445
|
ref: function ref(_ref4) {
|
345
446
|
return _this7.wrapper = _ref4;
|
346
447
|
}
|
@@ -350,37 +451,33 @@ function (_Component) {
|
|
350
451
|
ref: function ref(_ref3) {
|
351
452
|
return _this7.imageContainer = _ref3;
|
352
453
|
}
|
353
|
-
},
|
354
|
-
|
355
|
-
|
356
|
-
"aria-hidden": "false"
|
357
|
-
}, children[children.length - 1]), children.map(function (each, key) {
|
454
|
+
}, infinite ? this.renderPreceedingSlides(children, slidesToShow) : '', children.map(function (each, key) {
|
455
|
+
var isSlideActive = _this7.isSlideActive(key);
|
456
|
+
|
358
457
|
return _react["default"].createElement("div", {
|
359
458
|
"data-index": key,
|
360
459
|
key: key,
|
361
|
-
className:
|
460
|
+
className: isSlideActive ? 'active' : '',
|
362
461
|
"aria-roledescription": "slide",
|
363
|
-
"aria-hidden":
|
462
|
+
"aria-hidden": isSlideActive ? 'false' : 'true'
|
364
463
|
}, each);
|
365
|
-
}),
|
366
|
-
"data-index": "-1",
|
367
|
-
"aria-roledescription": "slide",
|
368
|
-
"aria-hidden": "false"
|
369
|
-
}, children[0]))), arrows && (0, _helpers.showNextArrow)((0, _props.getProps)(this.props), this.state.index, this.moveSlides)), indicators && (0, _helpers.showIndicators)((0, _props.getProps)(this.props), this.state.index, this.goToSlide));
|
464
|
+
}), infinite ? this.renderTrailingSlides(children, slidesToShow) : '')), arrows && (0, _helpers.showNextArrow)((0, _props.getProps)(this.props), this.state.index, this.moveSlides)), indicators && (0, _helpers.showIndicators)((0, _props.getProps)(this.props), this.state.index, this.goToSlide));
|
370
465
|
}
|
371
466
|
}, {
|
372
467
|
key: "slideImages",
|
373
468
|
value: function slideImages(index, animationDuration) {
|
374
469
|
var _this8 = this;
|
375
470
|
|
376
|
-
var
|
377
|
-
children =
|
378
|
-
transitionDuration =
|
379
|
-
autoplay =
|
380
|
-
infinite =
|
381
|
-
duration =
|
382
|
-
onChange =
|
383
|
-
easing =
|
471
|
+
var _getProps14 = (0, _props.getProps)(this.props),
|
472
|
+
children = _getProps14.children,
|
473
|
+
transitionDuration = _getProps14.transitionDuration,
|
474
|
+
autoplay = _getProps14.autoplay,
|
475
|
+
infinite = _getProps14.infinite,
|
476
|
+
duration = _getProps14.duration,
|
477
|
+
onChange = _getProps14.onChange,
|
478
|
+
easing = _getProps14.easing,
|
479
|
+
slidesToShow = _getProps14.slidesToShow,
|
480
|
+
slidesToScroll = _getProps14.slidesToScroll;
|
384
481
|
|
385
482
|
transitionDuration = animationDuration || transitionDuration;
|
386
483
|
var existingTweens = this.tweenGroup.getAll();
|
@@ -388,10 +485,10 @@ function (_Component) {
|
|
388
485
|
if (!existingTweens.length) {
|
389
486
|
clearTimeout(this.timeout);
|
390
487
|
var value = {
|
391
|
-
margin: -this.width * (this.state.index +
|
488
|
+
margin: -this.width * (this.state.index + this.getOffset(infinite, slidesToShow)) + this.distanceSwiped
|
392
489
|
};
|
393
490
|
var tween = new _tween["default"].Tween(value, this.tweenGroup).to({
|
394
|
-
margin: -this.width * (index +
|
491
|
+
margin: -this.width * (index + this.getOffset(infinite, slidesToShow))
|
395
492
|
}, transitionDuration).onUpdate(function (value) {
|
396
493
|
if (_this8.imageContainer) {
|
397
494
|
_this8.imageContainer.style.transform = "translate(".concat(value.margin, "px)");
|
@@ -421,7 +518,7 @@ function (_Component) {
|
|
421
518
|
var newIndex = index;
|
422
519
|
|
423
520
|
if (newIndex < 0) {
|
424
|
-
newIndex = children.length -
|
521
|
+
newIndex = children.length - slidesToScroll;
|
425
522
|
} else if (newIndex >= children.length) {
|
426
523
|
newIndex = 0;
|
427
524
|
}
|
package/lib/zoom.js
CHANGED
@@ -66,6 +66,8 @@ function (_Component) {
|
|
66
66
|
_this.tweenGroup = new _tween["default"].Group();
|
67
67
|
_this.initResizeObserver = _this.initResizeObserver.bind(_assertThisInitialized(_this));
|
68
68
|
_this.reactSlideshowWrapper = (0, _react.createRef)();
|
69
|
+
_this.startSwipe = _this.startSwipe.bind(_assertThisInitialized(_this));
|
70
|
+
_this.endSwipe = _this.endSwipe.bind(_assertThisInitialized(_this));
|
69
71
|
return _this;
|
70
72
|
}
|
71
73
|
|
@@ -257,28 +259,68 @@ function (_Component) {
|
|
257
259
|
this.goNext();
|
258
260
|
}
|
259
261
|
}
|
262
|
+
}, {
|
263
|
+
key: "startSwipe",
|
264
|
+
value: function startSwipe(e) {
|
265
|
+
var _getProps6 = (0, _props.getProps)(this.props),
|
266
|
+
canSwipe = _getProps6.canSwipe;
|
267
|
+
|
268
|
+
if (canSwipe) {
|
269
|
+
this.startingClientX = e.touches ? e.touches[0].pageX : e.clientX;
|
270
|
+
clearTimeout(this.timeout);
|
271
|
+
this.dragging = true;
|
272
|
+
}
|
273
|
+
}
|
274
|
+
}, {
|
275
|
+
key: "endSwipe",
|
276
|
+
value: function endSwipe(e) {
|
277
|
+
var clientX = e.changedTouches ? e.changedTouches[0].pageX : e.clientX;
|
278
|
+
var distance = clientX - this.startingClientX;
|
279
|
+
|
280
|
+
var _getProps7 = (0, _props.getProps)(this.props),
|
281
|
+
canSwipe = _getProps7.canSwipe;
|
282
|
+
|
283
|
+
if (canSwipe) {
|
284
|
+
this.dragging = false;
|
285
|
+
|
286
|
+
if (Math.abs(distance) / this.width > 0.2) {
|
287
|
+
if (distance < 0) {
|
288
|
+
this.goNext();
|
289
|
+
} else {
|
290
|
+
this.goBack();
|
291
|
+
}
|
292
|
+
}
|
293
|
+
}
|
294
|
+
}
|
260
295
|
}, {
|
261
296
|
key: "render",
|
262
297
|
value: function render() {
|
263
298
|
var _this5 = this;
|
264
299
|
|
265
|
-
var
|
266
|
-
indicators =
|
267
|
-
arrows =
|
268
|
-
children =
|
300
|
+
var _getProps8 = (0, _props.getProps)(this.props),
|
301
|
+
indicators = _getProps8.indicators,
|
302
|
+
arrows = _getProps8.arrows,
|
303
|
+
children = _getProps8.children,
|
304
|
+
cssClass = _getProps8.cssClass;
|
269
305
|
|
270
306
|
var index = this.state.index;
|
271
307
|
var unhandledProps = (0, _helpers.getUnhandledProps)(_props.propTypes, this.props);
|
272
308
|
return _react["default"].createElement("div", _extends({
|
309
|
+
dir: "ltr",
|
273
310
|
"aria-roledescription": "carousel"
|
274
311
|
}, unhandledProps), _react["default"].createElement("div", {
|
275
312
|
className: "react-slideshow-container",
|
276
313
|
onMouseEnter: this.pauseSlides,
|
277
314
|
onMouseOver: this.pauseSlides,
|
278
315
|
onMouseLeave: this.startSlides,
|
316
|
+
onMouseDown: this.startSwipe,
|
317
|
+
onMouseUp: this.endSwipe,
|
318
|
+
onTouchStart: this.startSwipe,
|
319
|
+
onTouchEnd: this.endSwipe,
|
320
|
+
onTouchCancel: this.endSwipe,
|
279
321
|
ref: this.reactSlideshowWrapper
|
280
322
|
}, arrows && (0, _helpers.showPreviousArrow)((0, _props.getProps)(this.props), this.state.index, this.preZoom), _react["default"].createElement("div", {
|
281
|
-
className: "react-slideshow-zoom-wrapper",
|
323
|
+
className: "react-slideshow-zoom-wrapper ".concat(cssClass),
|
282
324
|
ref: function ref(_ref3) {
|
283
325
|
return _this5.wrapper = _ref3;
|
284
326
|
}
|
@@ -307,15 +349,15 @@ function (_Component) {
|
|
307
349
|
|
308
350
|
var index = this.state.index;
|
309
351
|
|
310
|
-
var
|
311
|
-
children =
|
312
|
-
scale =
|
313
|
-
autoplay =
|
314
|
-
infinite =
|
315
|
-
transitionDuration =
|
316
|
-
duration =
|
317
|
-
onChange =
|
318
|
-
easing =
|
352
|
+
var _getProps9 = (0, _props.getProps)(this.props),
|
353
|
+
children = _getProps9.children,
|
354
|
+
scale = _getProps9.scale,
|
355
|
+
autoplay = _getProps9.autoplay,
|
356
|
+
infinite = _getProps9.infinite,
|
357
|
+
transitionDuration = _getProps9.transitionDuration,
|
358
|
+
duration = _getProps9.duration,
|
359
|
+
onChange = _getProps9.onChange,
|
360
|
+
easing = _getProps9.easing;
|
319
361
|
|
320
362
|
var existingTweens = this.tweenGroup.getAll();
|
321
363
|
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-slideshow-image",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.6.1",
|
4
4
|
"author": "Femi Oladeji",
|
5
5
|
"description": "An image slideshow with react",
|
6
6
|
"files": [
|
7
7
|
"lib",
|
8
8
|
"dist"
|
9
9
|
],
|
10
|
-
"homepage": "https://react-slideshow.
|
10
|
+
"homepage": "https://react-slideshow-image.netlify.com",
|
11
11
|
"npmFileMap": [
|
12
12
|
{
|
13
13
|
"basePath": "/dist/",
|