react-slideshow-image 3.5.0 → 3.7.0
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 +53 -13
- package/lib/props.js +25 -4
- package/lib/slide.js +73 -27
- package/lib/zoom.js +54 -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,16 +260,49 @@ 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 =
|
270
|
-
cssClass =
|
301
|
+
var _getProps8 = (0, _props.getProps)(this.props),
|
302
|
+
indicators = _getProps8.indicators,
|
303
|
+
children = _getProps8.children,
|
304
|
+
arrows = _getProps8.arrows,
|
305
|
+
cssClass = _getProps8.cssClass;
|
271
306
|
|
272
307
|
var index = this.state.index;
|
273
308
|
var unhandledProps = (0, _helpers.getUnhandledProps)(_props.propTypes, this.props);
|
@@ -279,6 +314,11 @@ function (_Component) {
|
|
279
314
|
onMouseEnter: this.pauseSlides,
|
280
315
|
onMouseOver: this.pauseSlides,
|
281
316
|
onMouseLeave: this.startSlides,
|
317
|
+
onMouseDown: this.startSwipe,
|
318
|
+
onMouseUp: this.endSwipe,
|
319
|
+
onTouchStart: this.startSwipe,
|
320
|
+
onTouchEnd: this.endSwipe,
|
321
|
+
onTouchCancel: this.endSwipe,
|
282
322
|
ref: this.reactSlideshowWrapper
|
283
323
|
}, arrows && (0, _helpers.showPreviousArrow)((0, _props.getProps)(this.props), this.state.index, this.preFade), _react["default"].createElement("div", {
|
284
324
|
className: "react-slideshow-fade-wrapper ".concat(cssClass),
|
@@ -308,14 +348,14 @@ function (_Component) {
|
|
308
348
|
|
309
349
|
var index = this.state.index;
|
310
350
|
|
311
|
-
var
|
312
|
-
autoplay =
|
313
|
-
children =
|
314
|
-
infinite =
|
315
|
-
duration =
|
316
|
-
transitionDuration =
|
317
|
-
onChange =
|
318
|
-
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;
|
319
359
|
|
320
360
|
var existingTweens = this.tweenGroup.getAll();
|
321
361
|
|
package/lib/props.js
CHANGED
@@ -31,7 +31,14 @@ var defaultProps = {
|
|
31
31
|
canSwipe: true,
|
32
32
|
slidesToShow: 1,
|
33
33
|
slidesToScroll: 1,
|
34
|
-
cssClass: ''
|
34
|
+
cssClass: '',
|
35
|
+
responsive: []
|
36
|
+
};
|
37
|
+
|
38
|
+
var getResponsiveSettings = function getResponsiveSettings(windowWidth, responsive) {
|
39
|
+
return responsive.find(function (each) {
|
40
|
+
return each.breakpoint <= windowWidth;
|
41
|
+
});
|
35
42
|
};
|
36
43
|
|
37
44
|
var getProps = function getProps(componentProps) {
|
@@ -39,7 +46,18 @@ var getProps = function getProps(componentProps) {
|
|
39
46
|
return each;
|
40
47
|
});
|
41
48
|
|
42
|
-
|
49
|
+
var settings = {};
|
50
|
+
|
51
|
+
if (typeof window !== 'undefined' && Array.isArray(componentProps.responsive)) {
|
52
|
+
var windowWidth = window.innerWidth;
|
53
|
+
var responsiveSettings = getResponsiveSettings(windowWidth, componentProps.responsive);
|
54
|
+
|
55
|
+
if (responsiveSettings) {
|
56
|
+
settings = responsiveSettings.settings;
|
57
|
+
}
|
58
|
+
}
|
59
|
+
|
60
|
+
return _objectSpread({}, defaultProps, {}, componentProps, {}, settings, {
|
43
61
|
children: children
|
44
62
|
});
|
45
63
|
};
|
@@ -62,7 +80,8 @@ var propTypes = {
|
|
62
80
|
canSwipe: 'boolean',
|
63
81
|
slidesToShow: 'number',
|
64
82
|
slidesToScroll: 'number',
|
65
|
-
cssClass: 'string'
|
83
|
+
cssClass: 'string',
|
84
|
+
responsive: 'array'
|
66
85
|
};
|
67
86
|
exports.propTypes = propTypes;
|
68
87
|
|
@@ -73,7 +92,9 @@ var validatePropTypes = function validatePropTypes(props) {
|
|
73
92
|
if (propTypes[key]) {
|
74
93
|
if (Array.isArray(propTypes[key]) && !propTypes[key].includes(propValueType)) {
|
75
94
|
console.warn("".concat(key, " must be of one of type ").concat(propTypes[key].join(', ')));
|
76
|
-
} else if (
|
95
|
+
} else if (propTypes[key] === 'array' && !Array.isArray(props[key])) {
|
96
|
+
console.warn("".concat(key, " must be of type ").concat(propTypes[key]));
|
97
|
+
} else if (propTypes[key] !== 'array' && !Array.isArray(propTypes[key]) && propValueType !== propTypes[key]) {
|
77
98
|
console.warn("".concat(key, " must be of type ").concat(propTypes[key]));
|
78
99
|
}
|
79
100
|
}
|
package/lib/slide.js
CHANGED
@@ -51,6 +51,7 @@ function (_Component) {
|
|
51
51
|
|
52
52
|
_this = _possibleConstructorReturn(this, _getPrototypeOf(Slideshow).call(this));
|
53
53
|
_this.state = {
|
54
|
+
slidesToShow: props.slidesToShow || 1,
|
54
55
|
index: props.defaultIndex && props.defaultIndex < props.children.length ? props.defaultIndex : 0
|
55
56
|
};
|
56
57
|
_this.width = 0;
|
@@ -153,14 +154,31 @@ function (_Component) {
|
|
153
154
|
value: function swipe(e) {
|
154
155
|
var _getProps4 = (0, _props.getProps)(this.props),
|
155
156
|
canSwipe = _getProps4.canSwipe,
|
156
|
-
slidesToShow = _getProps4.slidesToShow
|
157
|
+
slidesToShow = _getProps4.slidesToShow,
|
158
|
+
children = _getProps4.children,
|
159
|
+
infinite = _getProps4.infinite,
|
160
|
+
slidesToScroll = _getProps4.slidesToScroll;
|
157
161
|
|
158
162
|
if (canSwipe) {
|
159
163
|
var clientX = e.touches ? e.touches[0].pageX : e.clientX;
|
160
164
|
|
161
165
|
if (this.dragging) {
|
162
|
-
var translateValue = this.width * (this.state.index + slidesToShow);
|
163
|
-
|
166
|
+
var translateValue = this.width * (this.state.index + this.getOffset(infinite, slidesToShow));
|
167
|
+
var distance = clientX - this.startingClientX;
|
168
|
+
|
169
|
+
if (!infinite && this.state.index === children.length - slidesToScroll && distance < 0) {
|
170
|
+
// if it is the last and infinite is false and you're swiping left
|
171
|
+
// then nothing happens
|
172
|
+
return;
|
173
|
+
}
|
174
|
+
|
175
|
+
if (!infinite && this.state.index === 0 && distance > 0) {
|
176
|
+
// if it is the first and infinite is false and you're swiping right
|
177
|
+
// then nothing happens
|
178
|
+
return;
|
179
|
+
}
|
180
|
+
|
181
|
+
this.distanceSwiped = distance;
|
164
182
|
translateValue -= this.distanceSwiped;
|
165
183
|
this.imageContainer.style.transform = "translate(-".concat(translateValue, "px)");
|
166
184
|
}
|
@@ -180,7 +198,15 @@ function (_Component) {
|
|
180
198
|
this.allImages = this.wrapper && Array.prototype.slice.call(this.wrapper.querySelectorAll(".images-wrap > div"), 0) || [];
|
181
199
|
|
182
200
|
var _getProps5 = (0, _props.getProps)(this.props),
|
183
|
-
slidesToShow = _getProps5.slidesToShow
|
201
|
+
slidesToShow = _getProps5.slidesToShow,
|
202
|
+
infinite = _getProps5.infinite;
|
203
|
+
|
204
|
+
if (this.state.slidesToShow !== slidesToShow) {
|
205
|
+
this.setState({
|
206
|
+
slidesToShow: slidesToShow,
|
207
|
+
index: 0
|
208
|
+
});
|
209
|
+
}
|
184
210
|
|
185
211
|
this.width = (this.wrapper && this.wrapper.clientWidth || 0) / slidesToShow;
|
186
212
|
|
@@ -190,7 +216,7 @@ function (_Component) {
|
|
190
216
|
|
191
217
|
if (this.imageContainer) {
|
192
218
|
this.imageContainer.style.width = "".concat(fullwidth, "px");
|
193
|
-
this.imageContainer.style.transform = "translate(-".concat(this.width * (this.state.index + slidesToShow), "px)");
|
219
|
+
this.imageContainer.style.transform = "translate(-".concat(this.width * (this.state.index + this.getOffset(infinite, slidesToShow)), "px)");
|
194
220
|
}
|
195
221
|
|
196
222
|
this.applySlideStyle();
|
@@ -369,7 +395,17 @@ function (_Component) {
|
|
369
395
|
}
|
370
396
|
}, {
|
371
397
|
key: "renderTrailingSlides",
|
372
|
-
value: function renderTrailingSlides(
|
398
|
+
value: function renderTrailingSlides() {
|
399
|
+
var _getProps13 = (0, _props.getProps)(this.props),
|
400
|
+
children = _getProps13.children,
|
401
|
+
slidesToShow = _getProps13.slidesToShow,
|
402
|
+
slidesToScroll = _getProps13.slidesToScroll,
|
403
|
+
infinite = _getProps13.infinite;
|
404
|
+
|
405
|
+
if (!infinite && slidesToShow === slidesToScroll) {
|
406
|
+
return;
|
407
|
+
}
|
408
|
+
|
373
409
|
return children.slice(0, slidesToShow).map(function (each, index) {
|
374
410
|
return _react["default"].createElement("div", {
|
375
411
|
"data-index": children.length + index,
|
@@ -379,22 +415,32 @@ function (_Component) {
|
|
379
415
|
}, each);
|
380
416
|
});
|
381
417
|
}
|
418
|
+
}, {
|
419
|
+
key: "getOffset",
|
420
|
+
value: function getOffset(infinite, slidesToShow) {
|
421
|
+
if (!infinite) {
|
422
|
+
return 0;
|
423
|
+
}
|
424
|
+
|
425
|
+
return slidesToShow;
|
426
|
+
}
|
382
427
|
}, {
|
383
428
|
key: "render",
|
384
429
|
value: function render() {
|
385
430
|
var _this7 = this;
|
386
431
|
|
387
|
-
var
|
388
|
-
children =
|
389
|
-
indicators =
|
390
|
-
arrows =
|
391
|
-
cssClass =
|
392
|
-
slidesToShow =
|
432
|
+
var _getProps14 = (0, _props.getProps)(this.props),
|
433
|
+
children = _getProps14.children,
|
434
|
+
indicators = _getProps14.indicators,
|
435
|
+
arrows = _getProps14.arrows,
|
436
|
+
cssClass = _getProps14.cssClass,
|
437
|
+
slidesToShow = _getProps14.slidesToShow,
|
438
|
+
infinite = _getProps14.infinite;
|
393
439
|
|
394
440
|
var unhandledProps = (0, _helpers.getUnhandledProps)(_props.propTypes, this.props);
|
395
441
|
var index = this.state.index;
|
396
442
|
var style = {
|
397
|
-
transform: "translate(-".concat((index + slidesToShow) * this.width, "px)")
|
443
|
+
transform: "translate(-".concat((index + this.getOffset(infinite, slidesToShow)) * this.width, "px)")
|
398
444
|
};
|
399
445
|
return _react["default"].createElement("div", _extends({
|
400
446
|
dir: "ltr",
|
@@ -423,7 +469,7 @@ function (_Component) {
|
|
423
469
|
ref: function ref(_ref3) {
|
424
470
|
return _this7.imageContainer = _ref3;
|
425
471
|
}
|
426
|
-
}, this.renderPreceedingSlides(children, slidesToShow), children.map(function (each, key) {
|
472
|
+
}, infinite ? this.renderPreceedingSlides(children, slidesToShow) : '', children.map(function (each, key) {
|
427
473
|
var isSlideActive = _this7.isSlideActive(key);
|
428
474
|
|
429
475
|
return _react["default"].createElement("div", {
|
@@ -433,23 +479,23 @@ function (_Component) {
|
|
433
479
|
"aria-roledescription": "slide",
|
434
480
|
"aria-hidden": isSlideActive ? 'false' : 'true'
|
435
481
|
}, each);
|
436
|
-
}), this.renderTrailingSlides(
|
482
|
+
}), this.renderTrailingSlides())), 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));
|
437
483
|
}
|
438
484
|
}, {
|
439
485
|
key: "slideImages",
|
440
486
|
value: function slideImages(index, animationDuration) {
|
441
487
|
var _this8 = this;
|
442
488
|
|
443
|
-
var
|
444
|
-
children =
|
445
|
-
transitionDuration =
|
446
|
-
autoplay =
|
447
|
-
infinite =
|
448
|
-
duration =
|
449
|
-
onChange =
|
450
|
-
easing =
|
451
|
-
slidesToShow =
|
452
|
-
slidesToScroll =
|
489
|
+
var _getProps15 = (0, _props.getProps)(this.props),
|
490
|
+
children = _getProps15.children,
|
491
|
+
transitionDuration = _getProps15.transitionDuration,
|
492
|
+
autoplay = _getProps15.autoplay,
|
493
|
+
infinite = _getProps15.infinite,
|
494
|
+
duration = _getProps15.duration,
|
495
|
+
onChange = _getProps15.onChange,
|
496
|
+
easing = _getProps15.easing,
|
497
|
+
slidesToShow = _getProps15.slidesToShow,
|
498
|
+
slidesToScroll = _getProps15.slidesToScroll;
|
453
499
|
|
454
500
|
transitionDuration = animationDuration || transitionDuration;
|
455
501
|
var existingTweens = this.tweenGroup.getAll();
|
@@ -457,10 +503,10 @@ function (_Component) {
|
|
457
503
|
if (!existingTweens.length) {
|
458
504
|
clearTimeout(this.timeout);
|
459
505
|
var value = {
|
460
|
-
margin: -this.width * (this.state.index + slidesToShow) + this.distanceSwiped
|
506
|
+
margin: -this.width * (this.state.index + this.getOffset(infinite, slidesToShow)) + this.distanceSwiped
|
461
507
|
};
|
462
508
|
var tween = new _tween["default"].Tween(value, this.tweenGroup).to({
|
463
|
-
margin: -this.width * (index + slidesToShow)
|
509
|
+
margin: -this.width * (index + this.getOffset(infinite, slidesToShow))
|
464
510
|
}, transitionDuration).onUpdate(function (value) {
|
465
511
|
if (_this8.imageContainer) {
|
466
512
|
_this8.imageContainer.style.transform = "translate(".concat(value.margin, "px)");
|
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,16 +259,49 @@ 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 =
|
269
|
-
cssClass =
|
300
|
+
var _getProps8 = (0, _props.getProps)(this.props),
|
301
|
+
indicators = _getProps8.indicators,
|
302
|
+
arrows = _getProps8.arrows,
|
303
|
+
children = _getProps8.children,
|
304
|
+
cssClass = _getProps8.cssClass;
|
270
305
|
|
271
306
|
var index = this.state.index;
|
272
307
|
var unhandledProps = (0, _helpers.getUnhandledProps)(_props.propTypes, this.props);
|
@@ -278,6 +313,11 @@ function (_Component) {
|
|
278
313
|
onMouseEnter: this.pauseSlides,
|
279
314
|
onMouseOver: this.pauseSlides,
|
280
315
|
onMouseLeave: this.startSlides,
|
316
|
+
onMouseDown: this.startSwipe,
|
317
|
+
onMouseUp: this.endSwipe,
|
318
|
+
onTouchStart: this.startSwipe,
|
319
|
+
onTouchEnd: this.endSwipe,
|
320
|
+
onTouchCancel: this.endSwipe,
|
281
321
|
ref: this.reactSlideshowWrapper
|
282
322
|
}, arrows && (0, _helpers.showPreviousArrow)((0, _props.getProps)(this.props), this.state.index, this.preZoom), _react["default"].createElement("div", {
|
283
323
|
className: "react-slideshow-zoom-wrapper ".concat(cssClass),
|
@@ -309,15 +349,15 @@ function (_Component) {
|
|
309
349
|
|
310
350
|
var index = this.state.index;
|
311
351
|
|
312
|
-
var
|
313
|
-
children =
|
314
|
-
scale =
|
315
|
-
autoplay =
|
316
|
-
infinite =
|
317
|
-
transitionDuration =
|
318
|
-
duration =
|
319
|
-
onChange =
|
320
|
-
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;
|
321
361
|
|
322
362
|
var existingTweens = this.tweenGroup.getAll();
|
323
363
|
|
package/package.json
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-slideshow-image",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.7.0",
|
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/",
|