react-image-gallery 1.0.6 → 1.0.7
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 +10 -8
- package/build/image-gallery.js +57 -53
- package/package.json +1 -1
- package/src/ImageGallery.jsx +30 -28
package/README.md
CHANGED
|
@@ -4,19 +4,21 @@ React Carousel Image Gallery
|
|
|
4
4
|
[](https://badge.fury.io/js/react-image-gallery)
|
|
5
5
|
[](http://www.npmjs.com/package/react-image-gallery)
|
|
6
6
|
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
### Live Demo (try it on mobile for swipe support)
|
|
8
|
+
[`linxtion.com/demo/react-image-gallery`](http://linxtion.com/demo/react-image-gallery)
|
|
9
9
|
|
|
10
10
|

|
|
11
11
|
|
|
12
12
|
React image gallery is a React component for building image galleries and carousels
|
|
13
13
|
|
|
14
|
-
Features
|
|
15
|
-
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
14
|
+
## Features
|
|
15
|
+
|
|
16
|
+
* Mobile swipe gestures
|
|
17
|
+
* Thumbnail navigation
|
|
18
|
+
* Fullscreen support
|
|
19
|
+
* Custom rendered slides
|
|
20
|
+
* RTL support
|
|
21
|
+
* Responsive design
|
|
20
22
|
* Tons of customization options (see props below)
|
|
21
23
|
* Lightweight ~7kb gzipped
|
|
22
24
|
|
package/build/image-gallery.js
CHANGED
|
@@ -176,9 +176,9 @@ var ImageGallery = function (_React$Component) {
|
|
|
176
176
|
window.removeEventListener('mousedown', this.handleMouseDown);
|
|
177
177
|
this.removeScreenChangeEvent();
|
|
178
178
|
this.removeResizeObserver();
|
|
179
|
-
if (this.
|
|
180
|
-
window.clearInterval(this.
|
|
181
|
-
this.
|
|
179
|
+
if (this.playPauseIntervalId) {
|
|
180
|
+
window.clearInterval(this.playPauseIntervalId);
|
|
181
|
+
this.playPauseIntervalId = null;
|
|
182
182
|
}
|
|
183
183
|
if (this.transitionTimer) {
|
|
184
184
|
window.clearTimeout(this.transitionTimer);
|
|
@@ -546,7 +546,7 @@ var ImageGallery = function (_React$Component) {
|
|
|
546
546
|
var slide = _react2.default.createElement(
|
|
547
547
|
'div',
|
|
548
548
|
{
|
|
549
|
-
key: 'slide-' + item.original,
|
|
549
|
+
key: 'slide-' + item.original + '-' + index,
|
|
550
550
|
tabIndex: '-1',
|
|
551
551
|
className: 'image-gallery-slide ' + alignment + ' ' + originalClass,
|
|
552
552
|
style: slideStyle,
|
|
@@ -577,7 +577,7 @@ var ImageGallery = function (_React$Component) {
|
|
|
577
577
|
thumbnails.push(_react2.default.createElement(
|
|
578
578
|
'button',
|
|
579
579
|
{
|
|
580
|
-
key: 'thumbnail-' + item.original,
|
|
580
|
+
key: 'thumbnail-' + item.original + '-' + index,
|
|
581
581
|
type: 'button',
|
|
582
582
|
tabIndex: '0',
|
|
583
583
|
'aria-pressed': currentIndex === index ? 'true' : 'false',
|
|
@@ -612,7 +612,7 @@ var ImageGallery = function (_React$Component) {
|
|
|
612
612
|
var igBulletClass = (0, _clsx2.default)('image-gallery-bullet', item.bulletClass, { active: currentIndex === index });
|
|
613
613
|
bullets.push(_react2.default.createElement('button', {
|
|
614
614
|
type: 'button',
|
|
615
|
-
key: 'bullet-' + item.original,
|
|
615
|
+
key: 'bullet-' + item.original + '-' + index,
|
|
616
616
|
className: igBulletClass,
|
|
617
617
|
onClick: bulletOnClick,
|
|
618
618
|
'aria-pressed': currentIndex === index ? 'true' : 'false',
|
|
@@ -887,13 +887,13 @@ var ImageGallery = function (_React$Component) {
|
|
|
887
887
|
|
|
888
888
|
switch (key) {
|
|
889
889
|
case LEFT_ARROW:
|
|
890
|
-
if (this.canSlideLeft() && !this.
|
|
891
|
-
this.slideLeft();
|
|
890
|
+
if (this.canSlideLeft() && !this.playPauseIntervalId) {
|
|
891
|
+
this.slideLeft(event);
|
|
892
892
|
}
|
|
893
893
|
break;
|
|
894
894
|
case RIGHT_ARROW:
|
|
895
|
-
if (this.canSlideRight() && !this.
|
|
896
|
-
this.slideRight();
|
|
895
|
+
if (this.canSlideRight() && !this.playPauseIntervalId) {
|
|
896
|
+
this.slideRight(event);
|
|
897
897
|
}
|
|
898
898
|
break;
|
|
899
899
|
case ESC_KEY:
|
|
@@ -976,7 +976,7 @@ var ImageGallery = function (_React$Component) {
|
|
|
976
976
|
}, {
|
|
977
977
|
key: 'togglePlay',
|
|
978
978
|
value: function togglePlay() {
|
|
979
|
-
if (this.
|
|
979
|
+
if (this.playPauseIntervalId) {
|
|
980
980
|
this.pause();
|
|
981
981
|
} else {
|
|
982
982
|
this.play();
|
|
@@ -988,12 +988,16 @@ var ImageGallery = function (_React$Component) {
|
|
|
988
988
|
/*
|
|
989
989
|
handles screen change events that the browser triggers e.g. esc key
|
|
990
990
|
*/
|
|
991
|
-
var
|
|
991
|
+
var _props13 = this.props,
|
|
992
|
+
onScreenChange = _props13.onScreenChange,
|
|
993
|
+
useBrowserFullscreen = _props13.useBrowserFullscreen;
|
|
992
994
|
|
|
993
995
|
var fullScreenElement = document.fullscreenElement || document.msFullscreenElement || document.mozFullScreenElement || document.webkitFullscreenElement;
|
|
994
996
|
|
|
995
|
-
if
|
|
996
|
-
this.
|
|
997
|
+
// check if screenchange element is the gallery
|
|
998
|
+
var isFullscreen = this.imageGallery.current === fullScreenElement;
|
|
999
|
+
if (onScreenChange) onScreenChange(isFullscreen);
|
|
1000
|
+
if (useBrowserFullscreen) this.setState({ isFullscreen: isFullscreen });
|
|
997
1001
|
}
|
|
998
1002
|
}, {
|
|
999
1003
|
key: 'slideToIndex',
|
|
@@ -1001,15 +1005,15 @@ var ImageGallery = function (_React$Component) {
|
|
|
1001
1005
|
var _state12 = this.state,
|
|
1002
1006
|
currentIndex = _state12.currentIndex,
|
|
1003
1007
|
isTransitioning = _state12.isTransitioning;
|
|
1004
|
-
var
|
|
1005
|
-
items =
|
|
1006
|
-
slideDuration =
|
|
1007
|
-
onBeforeSlide =
|
|
1008
|
+
var _props14 = this.props,
|
|
1009
|
+
items = _props14.items,
|
|
1010
|
+
slideDuration = _props14.slideDuration,
|
|
1011
|
+
onBeforeSlide = _props14.onBeforeSlide;
|
|
1008
1012
|
|
|
1009
1013
|
|
|
1010
1014
|
if (!isTransitioning) {
|
|
1011
1015
|
if (event) {
|
|
1012
|
-
if (this.
|
|
1016
|
+
if (this.playPauseIntervalId) {
|
|
1013
1017
|
// user triggered event while ImageGallery is playing, reset interval
|
|
1014
1018
|
this.pause(false);
|
|
1015
1019
|
this.play(false);
|
|
@@ -1039,24 +1043,24 @@ var ImageGallery = function (_React$Component) {
|
|
|
1039
1043
|
}
|
|
1040
1044
|
}, {
|
|
1041
1045
|
key: 'slideLeft',
|
|
1042
|
-
value: function slideLeft() {
|
|
1046
|
+
value: function slideLeft(event) {
|
|
1043
1047
|
var isRTL = this.props.isRTL;
|
|
1044
1048
|
|
|
1045
1049
|
if (isRTL) {
|
|
1046
|
-
this.slideNext();
|
|
1050
|
+
this.slideNext(event);
|
|
1047
1051
|
} else {
|
|
1048
|
-
this.slidePrevious();
|
|
1052
|
+
this.slidePrevious(event);
|
|
1049
1053
|
}
|
|
1050
1054
|
}
|
|
1051
1055
|
}, {
|
|
1052
1056
|
key: 'slideRight',
|
|
1053
|
-
value: function slideRight() {
|
|
1057
|
+
value: function slideRight(event) {
|
|
1054
1058
|
var isRTL = this.props.isRTL;
|
|
1055
1059
|
|
|
1056
1060
|
if (isRTL) {
|
|
1057
|
-
this.slidePrevious();
|
|
1061
|
+
this.slidePrevious(event);
|
|
1058
1062
|
} else {
|
|
1059
|
-
this.slideNext();
|
|
1063
|
+
this.slideNext(event);
|
|
1060
1064
|
}
|
|
1061
1065
|
}
|
|
1062
1066
|
}, {
|
|
@@ -1235,15 +1239,15 @@ var ImageGallery = function (_React$Component) {
|
|
|
1235
1239
|
key: 'play',
|
|
1236
1240
|
value: function play() {
|
|
1237
1241
|
var shouldCallOnPlay = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
|
1238
|
-
var
|
|
1239
|
-
onPlay =
|
|
1240
|
-
slideInterval =
|
|
1241
|
-
slideDuration =
|
|
1242
|
+
var _props15 = this.props,
|
|
1243
|
+
onPlay = _props15.onPlay,
|
|
1244
|
+
slideInterval = _props15.slideInterval,
|
|
1245
|
+
slideDuration = _props15.slideDuration;
|
|
1242
1246
|
var currentIndex = this.state.currentIndex;
|
|
1243
1247
|
|
|
1244
|
-
if (!this.
|
|
1248
|
+
if (!this.playPauseIntervalId) {
|
|
1245
1249
|
this.setState({ isPlaying: true });
|
|
1246
|
-
this.
|
|
1250
|
+
this.playPauseIntervalId = window.setInterval(this.pauseOrPlay, Math.max(slideInterval, slideDuration));
|
|
1247
1251
|
if (onPlay && shouldCallOnPlay) {
|
|
1248
1252
|
onPlay(currentIndex);
|
|
1249
1253
|
}
|
|
@@ -1256,9 +1260,9 @@ var ImageGallery = function (_React$Component) {
|
|
|
1256
1260
|
var onPause = this.props.onPause;
|
|
1257
1261
|
var currentIndex = this.state.currentIndex;
|
|
1258
1262
|
|
|
1259
|
-
if (this.
|
|
1260
|
-
window.clearInterval(this.
|
|
1261
|
-
this.
|
|
1263
|
+
if (this.playPauseIntervalId) {
|
|
1264
|
+
window.clearInterval(this.playPauseIntervalId);
|
|
1265
|
+
this.playPauseIntervalId = null;
|
|
1262
1266
|
this.setState({ isPlaying: false });
|
|
1263
1267
|
if (onPause && shouldCallOnPause) {
|
|
1264
1268
|
onPause(currentIndex);
|
|
@@ -1314,9 +1318,9 @@ var ImageGallery = function (_React$Component) {
|
|
|
1314
1318
|
},
|
|
1315
1319
|
onError: handleImageError
|
|
1316
1320
|
},
|
|
1317
|
-
item.imageSet.map(function (source) {
|
|
1321
|
+
item.imageSet.map(function (source, index) {
|
|
1318
1322
|
return _react2.default.createElement('source', {
|
|
1319
|
-
key: source.
|
|
1323
|
+
key: 'media-' + source.srcSet + '-' + index,
|
|
1320
1324
|
media: source.media,
|
|
1321
1325
|
srcSet: source.srcSet,
|
|
1322
1326
|
type: source.type
|
|
@@ -1378,23 +1382,23 @@ var ImageGallery = function (_React$Component) {
|
|
|
1378
1382
|
isFullscreen = _state15.isFullscreen,
|
|
1379
1383
|
modalFullscreen = _state15.modalFullscreen,
|
|
1380
1384
|
isPlaying = _state15.isPlaying;
|
|
1381
|
-
var
|
|
1382
|
-
additionalClass =
|
|
1383
|
-
indexSeparator =
|
|
1384
|
-
isRTL =
|
|
1385
|
-
items =
|
|
1386
|
-
thumbnailPosition =
|
|
1387
|
-
renderFullscreenButton =
|
|
1388
|
-
renderCustomControls =
|
|
1389
|
-
renderLeftNav =
|
|
1390
|
-
renderRightNav =
|
|
1391
|
-
showBullets =
|
|
1392
|
-
showFullscreenButton =
|
|
1393
|
-
showIndex =
|
|
1394
|
-
showThumbnails =
|
|
1395
|
-
showNav =
|
|
1396
|
-
showPlayButton =
|
|
1397
|
-
renderPlayPauseButton =
|
|
1385
|
+
var _props16 = this.props,
|
|
1386
|
+
additionalClass = _props16.additionalClass,
|
|
1387
|
+
indexSeparator = _props16.indexSeparator,
|
|
1388
|
+
isRTL = _props16.isRTL,
|
|
1389
|
+
items = _props16.items,
|
|
1390
|
+
thumbnailPosition = _props16.thumbnailPosition,
|
|
1391
|
+
renderFullscreenButton = _props16.renderFullscreenButton,
|
|
1392
|
+
renderCustomControls = _props16.renderCustomControls,
|
|
1393
|
+
renderLeftNav = _props16.renderLeftNav,
|
|
1394
|
+
renderRightNav = _props16.renderRightNav,
|
|
1395
|
+
showBullets = _props16.showBullets,
|
|
1396
|
+
showFullscreenButton = _props16.showFullscreenButton,
|
|
1397
|
+
showIndex = _props16.showIndex,
|
|
1398
|
+
showThumbnails = _props16.showThumbnails,
|
|
1399
|
+
showNav = _props16.showNav,
|
|
1400
|
+
showPlayButton = _props16.showPlayButton,
|
|
1401
|
+
renderPlayPauseButton = _props16.renderPlayPauseButton;
|
|
1398
1402
|
|
|
1399
1403
|
|
|
1400
1404
|
var thumbnailStyle = this.getThumbnailStyle();
|
package/package.json
CHANGED
package/src/ImageGallery.jsx
CHANGED
|
@@ -305,9 +305,9 @@ export default class ImageGallery extends React.Component {
|
|
|
305
305
|
window.removeEventListener('mousedown', this.handleMouseDown);
|
|
306
306
|
this.removeScreenChangeEvent();
|
|
307
307
|
this.removeResizeObserver();
|
|
308
|
-
if (this.
|
|
309
|
-
window.clearInterval(this.
|
|
310
|
-
this.
|
|
308
|
+
if (this.playPauseIntervalId) {
|
|
309
|
+
window.clearInterval(this.playPauseIntervalId);
|
|
310
|
+
this.playPauseIntervalId = null;
|
|
311
311
|
}
|
|
312
312
|
if (this.transitionTimer) {
|
|
313
313
|
window.clearTimeout(this.transitionTimer);
|
|
@@ -622,7 +622,7 @@ export default class ImageGallery extends React.Component {
|
|
|
622
622
|
|
|
623
623
|
const slide = (
|
|
624
624
|
<div
|
|
625
|
-
key={`slide-${item.original}`}
|
|
625
|
+
key={`slide-${item.original}-${index}`}
|
|
626
626
|
tabIndex="-1"
|
|
627
627
|
className={`image-gallery-slide ${alignment} ${originalClass}`}
|
|
628
628
|
style={slideStyle}
|
|
@@ -657,7 +657,7 @@ export default class ImageGallery extends React.Component {
|
|
|
657
657
|
);
|
|
658
658
|
thumbnails.push(
|
|
659
659
|
<button
|
|
660
|
-
key={`thumbnail-${item.original}`}
|
|
660
|
+
key={`thumbnail-${item.original}-${index}`}
|
|
661
661
|
type="button"
|
|
662
662
|
tabIndex="0"
|
|
663
663
|
aria-pressed={currentIndex === index ? 'true' : 'false'}
|
|
@@ -690,7 +690,7 @@ export default class ImageGallery extends React.Component {
|
|
|
690
690
|
bullets.push(
|
|
691
691
|
<button
|
|
692
692
|
type="button"
|
|
693
|
-
key={`bullet-${item.original}`}
|
|
693
|
+
key={`bullet-${item.original}-${index}`}
|
|
694
694
|
className={igBulletClass}
|
|
695
695
|
onClick={bulletOnClick}
|
|
696
696
|
aria-pressed={currentIndex === index ? 'true' : 'false'}
|
|
@@ -911,13 +911,13 @@ export default class ImageGallery extends React.Component {
|
|
|
911
911
|
|
|
912
912
|
switch (key) {
|
|
913
913
|
case LEFT_ARROW:
|
|
914
|
-
if (this.canSlideLeft() && !this.
|
|
915
|
-
this.slideLeft();
|
|
914
|
+
if (this.canSlideLeft() && !this.playPauseIntervalId) {
|
|
915
|
+
this.slideLeft(event);
|
|
916
916
|
}
|
|
917
917
|
break;
|
|
918
918
|
case RIGHT_ARROW:
|
|
919
|
-
if (this.canSlideRight() && !this.
|
|
920
|
-
this.slideRight();
|
|
919
|
+
if (this.canSlideRight() && !this.playPauseIntervalId) {
|
|
920
|
+
this.slideRight(event);
|
|
921
921
|
}
|
|
922
922
|
break;
|
|
923
923
|
case ESC_KEY:
|
|
@@ -990,7 +990,7 @@ export default class ImageGallery extends React.Component {
|
|
|
990
990
|
}
|
|
991
991
|
|
|
992
992
|
togglePlay() {
|
|
993
|
-
if (this.
|
|
993
|
+
if (this.playPauseIntervalId) {
|
|
994
994
|
this.pause();
|
|
995
995
|
} else {
|
|
996
996
|
this.play();
|
|
@@ -1002,14 +1002,16 @@ export default class ImageGallery extends React.Component {
|
|
|
1002
1002
|
/*
|
|
1003
1003
|
handles screen change events that the browser triggers e.g. esc key
|
|
1004
1004
|
*/
|
|
1005
|
-
const { onScreenChange } = this.props;
|
|
1005
|
+
const { onScreenChange, useBrowserFullscreen } = this.props;
|
|
1006
1006
|
const fullScreenElement = document.fullscreenElement
|
|
1007
1007
|
|| document.msFullscreenElement
|
|
1008
1008
|
|| document.mozFullScreenElement
|
|
1009
1009
|
|| document.webkitFullscreenElement;
|
|
1010
1010
|
|
|
1011
|
-
if
|
|
1012
|
-
this.
|
|
1011
|
+
// check if screenchange element is the gallery
|
|
1012
|
+
const isFullscreen = this.imageGallery.current === fullScreenElement;
|
|
1013
|
+
if (onScreenChange) onScreenChange(isFullscreen);
|
|
1014
|
+
if (useBrowserFullscreen) this.setState({ isFullscreen });
|
|
1013
1015
|
}
|
|
1014
1016
|
|
|
1015
1017
|
slideToIndex(index, event) {
|
|
@@ -1018,7 +1020,7 @@ export default class ImageGallery extends React.Component {
|
|
|
1018
1020
|
|
|
1019
1021
|
if (!isTransitioning) {
|
|
1020
1022
|
if (event) {
|
|
1021
|
-
if (this.
|
|
1023
|
+
if (this.playPauseIntervalId) {
|
|
1022
1024
|
// user triggered event while ImageGallery is playing, reset interval
|
|
1023
1025
|
this.pause(false);
|
|
1024
1026
|
this.play(false);
|
|
@@ -1047,21 +1049,21 @@ export default class ImageGallery extends React.Component {
|
|
|
1047
1049
|
}
|
|
1048
1050
|
}
|
|
1049
1051
|
|
|
1050
|
-
slideLeft() {
|
|
1052
|
+
slideLeft(event) {
|
|
1051
1053
|
const { isRTL } = this.props;
|
|
1052
1054
|
if (isRTL) {
|
|
1053
|
-
this.slideNext();
|
|
1055
|
+
this.slideNext(event);
|
|
1054
1056
|
} else {
|
|
1055
|
-
this.slidePrevious();
|
|
1057
|
+
this.slidePrevious(event);
|
|
1056
1058
|
}
|
|
1057
1059
|
}
|
|
1058
1060
|
|
|
1059
|
-
slideRight() {
|
|
1061
|
+
slideRight(event) {
|
|
1060
1062
|
const { isRTL } = this.props;
|
|
1061
1063
|
if (isRTL) {
|
|
1062
|
-
this.slidePrevious();
|
|
1064
|
+
this.slidePrevious(event);
|
|
1063
1065
|
} else {
|
|
1064
|
-
this.slideNext();
|
|
1066
|
+
this.slideNext(event);
|
|
1065
1067
|
}
|
|
1066
1068
|
}
|
|
1067
1069
|
|
|
@@ -1207,9 +1209,9 @@ export default class ImageGallery extends React.Component {
|
|
|
1207
1209
|
slideDuration,
|
|
1208
1210
|
} = this.props;
|
|
1209
1211
|
const { currentIndex } = this.state;
|
|
1210
|
-
if (!this.
|
|
1212
|
+
if (!this.playPauseIntervalId) {
|
|
1211
1213
|
this.setState({ isPlaying: true });
|
|
1212
|
-
this.
|
|
1214
|
+
this.playPauseIntervalId = window.setInterval(
|
|
1213
1215
|
this.pauseOrPlay,
|
|
1214
1216
|
Math.max(slideInterval, slideDuration),
|
|
1215
1217
|
);
|
|
@@ -1222,9 +1224,9 @@ export default class ImageGallery extends React.Component {
|
|
|
1222
1224
|
pause(shouldCallOnPause = true) {
|
|
1223
1225
|
const { onPause } = this.props;
|
|
1224
1226
|
const { currentIndex } = this.state;
|
|
1225
|
-
if (this.
|
|
1226
|
-
window.clearInterval(this.
|
|
1227
|
-
this.
|
|
1227
|
+
if (this.playPauseIntervalId) {
|
|
1228
|
+
window.clearInterval(this.playPauseIntervalId);
|
|
1229
|
+
this.playPauseIntervalId = null;
|
|
1228
1230
|
this.setState({ isPlaying: false });
|
|
1229
1231
|
if (onPause && shouldCallOnPause) {
|
|
1230
1232
|
onPause(currentIndex);
|
|
@@ -1271,9 +1273,9 @@ export default class ImageGallery extends React.Component {
|
|
|
1271
1273
|
onError={handleImageError}
|
|
1272
1274
|
>
|
|
1273
1275
|
{
|
|
1274
|
-
item.imageSet.map(source => (
|
|
1276
|
+
item.imageSet.map((source, index) => (
|
|
1275
1277
|
<source
|
|
1276
|
-
key={source.
|
|
1278
|
+
key={`media-${source.srcSet}-${index}`}
|
|
1277
1279
|
media={source.media}
|
|
1278
1280
|
srcSet={source.srcSet}
|
|
1279
1281
|
type={source.type}
|