react-slideshow-image 3.6.0 → 3.7.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 +2 -2
- package/dist/react-slideshow-image.min.js +1 -1
- package/dist/react-slideshow-image.min.js.map +1 -1
- package/lib/props.js +25 -4
- package/lib/slide.js +54 -25
- package/package.json +7 -7
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;
|
@@ -162,7 +163,7 @@ function (_Component) {
|
|
162
163
|
var clientX = e.touches ? e.touches[0].pageX : e.clientX;
|
163
164
|
|
164
165
|
if (this.dragging) {
|
165
|
-
var translateValue = this.width * (this.state.index + slidesToShow);
|
166
|
+
var translateValue = this.width * (this.state.index + this.getOffset(infinite, slidesToShow));
|
166
167
|
var distance = clientX - this.startingClientX;
|
167
168
|
|
168
169
|
if (!infinite && this.state.index === children.length - slidesToScroll && distance < 0) {
|
@@ -197,7 +198,15 @@ function (_Component) {
|
|
197
198
|
this.allImages = this.wrapper && Array.prototype.slice.call(this.wrapper.querySelectorAll(".images-wrap > div"), 0) || [];
|
198
199
|
|
199
200
|
var _getProps5 = (0, _props.getProps)(this.props),
|
200
|
-
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
|
+
}
|
201
210
|
|
202
211
|
this.width = (this.wrapper && this.wrapper.clientWidth || 0) / slidesToShow;
|
203
212
|
|
@@ -207,7 +216,7 @@ function (_Component) {
|
|
207
216
|
|
208
217
|
if (this.imageContainer) {
|
209
218
|
this.imageContainer.style.width = "".concat(fullwidth, "px");
|
210
|
-
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)");
|
211
220
|
}
|
212
221
|
|
213
222
|
this.applySlideStyle();
|
@@ -386,7 +395,17 @@ function (_Component) {
|
|
386
395
|
}
|
387
396
|
}, {
|
388
397
|
key: "renderTrailingSlides",
|
389
|
-
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
|
+
|
390
409
|
return children.slice(0, slidesToShow).map(function (each, index) {
|
391
410
|
return _react["default"].createElement("div", {
|
392
411
|
"data-index": children.length + index,
|
@@ -396,22 +415,32 @@ function (_Component) {
|
|
396
415
|
}, each);
|
397
416
|
});
|
398
417
|
}
|
418
|
+
}, {
|
419
|
+
key: "getOffset",
|
420
|
+
value: function getOffset(infinite, slidesToShow) {
|
421
|
+
if (!infinite) {
|
422
|
+
return 0;
|
423
|
+
}
|
424
|
+
|
425
|
+
return slidesToShow;
|
426
|
+
}
|
399
427
|
}, {
|
400
428
|
key: "render",
|
401
429
|
value: function render() {
|
402
430
|
var _this7 = this;
|
403
431
|
|
404
|
-
var
|
405
|
-
children =
|
406
|
-
indicators =
|
407
|
-
arrows =
|
408
|
-
cssClass =
|
409
|
-
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;
|
410
439
|
|
411
440
|
var unhandledProps = (0, _helpers.getUnhandledProps)(_props.propTypes, this.props);
|
412
441
|
var index = this.state.index;
|
413
442
|
var style = {
|
414
|
-
transform: "translate(-".concat((index + slidesToShow) * this.width, "px)")
|
443
|
+
transform: "translate(-".concat((index + this.getOffset(infinite, slidesToShow)) * this.width, "px)")
|
415
444
|
};
|
416
445
|
return _react["default"].createElement("div", _extends({
|
417
446
|
dir: "ltr",
|
@@ -440,7 +469,7 @@ function (_Component) {
|
|
440
469
|
ref: function ref(_ref3) {
|
441
470
|
return _this7.imageContainer = _ref3;
|
442
471
|
}
|
443
|
-
}, this.renderPreceedingSlides(children, slidesToShow), children.map(function (each, key) {
|
472
|
+
}, infinite ? this.renderPreceedingSlides(children, slidesToShow) : '', children.map(function (each, key) {
|
444
473
|
var isSlideActive = _this7.isSlideActive(key);
|
445
474
|
|
446
475
|
return _react["default"].createElement("div", {
|
@@ -450,23 +479,23 @@ function (_Component) {
|
|
450
479
|
"aria-roledescription": "slide",
|
451
480
|
"aria-hidden": isSlideActive ? 'false' : 'true'
|
452
481
|
}, each);
|
453
|
-
}), 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));
|
454
483
|
}
|
455
484
|
}, {
|
456
485
|
key: "slideImages",
|
457
486
|
value: function slideImages(index, animationDuration) {
|
458
487
|
var _this8 = this;
|
459
488
|
|
460
|
-
var
|
461
|
-
children =
|
462
|
-
transitionDuration =
|
463
|
-
autoplay =
|
464
|
-
infinite =
|
465
|
-
duration =
|
466
|
-
onChange =
|
467
|
-
easing =
|
468
|
-
slidesToShow =
|
469
|
-
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;
|
470
499
|
|
471
500
|
transitionDuration = animationDuration || transitionDuration;
|
472
501
|
var existingTweens = this.tweenGroup.getAll();
|
@@ -474,10 +503,10 @@ function (_Component) {
|
|
474
503
|
if (!existingTweens.length) {
|
475
504
|
clearTimeout(this.timeout);
|
476
505
|
var value = {
|
477
|
-
margin: -this.width * (this.state.index + slidesToShow) + this.distanceSwiped
|
506
|
+
margin: -this.width * (this.state.index + this.getOffset(infinite, slidesToShow)) + this.distanceSwiped
|
478
507
|
};
|
479
508
|
var tween = new _tween["default"].Tween(value, this.tweenGroup).to({
|
480
|
-
margin: -this.width * (index + slidesToShow)
|
509
|
+
margin: -this.width * (index + this.getOffset(infinite, slidesToShow))
|
481
510
|
}, transitionDuration).onUpdate(function (value) {
|
482
511
|
if (_this8.imageContainer) {
|
483
512
|
_this8.imageContainer.style.transform = "translate(".concat(value.margin, "px)");
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "react-slideshow-image",
|
3
|
-
"version": "3.
|
3
|
+
"version": "3.7.1",
|
4
4
|
"author": "Femi Oladeji",
|
5
5
|
"description": "An image slideshow with react",
|
6
6
|
"files": [
|
@@ -45,19 +45,19 @@
|
|
45
45
|
"html-webpack-plugin": "^3.0.0",
|
46
46
|
"husky": "^0.14.3",
|
47
47
|
"jest": "^26.0.1",
|
48
|
-
"lint-staged": "^
|
48
|
+
"lint-staged": "^12.3.7",
|
49
49
|
"prettier": "^1.14.3",
|
50
50
|
"react": "^17.0.2",
|
51
51
|
"react-dom": "^17.0.2",
|
52
52
|
"react-router": "^5.1.2",
|
53
53
|
"react-router-dom": "^5.1.2",
|
54
54
|
"react-syntax-highlighter": "^15.4.3",
|
55
|
-
"serve": "^
|
55
|
+
"serve": "^13.0.2",
|
56
56
|
"style-loader": "^1.2.1",
|
57
57
|
"uglifycss": "0.0.29",
|
58
58
|
"webpack": "^4.42.0",
|
59
59
|
"webpack-cli": "^3.3.4",
|
60
|
-
"webpack-dev-server": "^
|
60
|
+
"webpack-dev-server": "^4.7.4"
|
61
61
|
},
|
62
62
|
"peerDependencies": {
|
63
63
|
"react": "^0.14.0 || ^15.0.1 || ^16.0.0 || ^17.0.0",
|
@@ -72,15 +72,15 @@
|
|
72
72
|
"main": "dist/react-slideshow-image.min.js",
|
73
73
|
"scripts": {
|
74
74
|
"dev": "webpack-dev-server",
|
75
|
-
"build": "webpack --config webpack.config.dist.js && uglifycss src/css/styles.css > dist/styles.css
|
76
|
-
"heroku-postbuild": "npm i --only=dev && webpack --prod",
|
75
|
+
"build": "webpack --config webpack.config.dist.js && uglifycss src/css/styles.css > dist/styles.css",
|
76
|
+
"heroku-postbuild": "npm i --only=dev && webpack --prod && echo '/* /index.html 200' | cat >public/_redirects",
|
77
77
|
"start": "serve public -s",
|
78
78
|
"precommit": "lint-staged",
|
79
79
|
"test": "jest && codecov",
|
80
80
|
"prepublishOnly": "NODE_ENV=production babel src --out-dir lib --copy-files && npm run build"
|
81
81
|
},
|
82
82
|
"dependencies": {
|
83
|
-
"@tweenjs/tween.js": "^18.
|
83
|
+
"@tweenjs/tween.js": "^18.6.4",
|
84
84
|
"resize-observer-polyfill": "^1.5.1"
|
85
85
|
}
|
86
86
|
}
|