Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added loop functionality to gallery #252

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ images | array | undefined | Required. Array of image objects See image options
imageCountSeparator | String | ' of ' | Customize separator in the image count
isOpen | bool | false | Whether or not the lightbox is displayed
leftArrowTitle | string | ' Previous (Left arrow key) ' | Customize of left arrow title
loop | bool | false | Allows looping the gallery
onClickPrev | func | undefined | Fired on request of the previous image
onClickNext | func | undefined | Fired on request of the next image
onClose | func | undefined | Required. Handle closing of the lightbox
Expand Down
76 changes: 40 additions & 36 deletions dist/react-images.es.js
Original file line number Diff line number Diff line change
Expand Up @@ -1124,11 +1124,12 @@ var Lightbox = function (_Component) {
value: function gotoNext(event) {
var _props = this.props,
currentImage = _props.currentImage,
images = _props.images;
images = _props.images,
loop = _props.loop;
var imageLoaded = this.state.imageLoaded;


if (!imageLoaded || currentImage === images.length - 1) return;
if (!imageLoaded || !loop && currentImage === images.length - 1) return;

if (event) {
event.preventDefault();
Expand All @@ -1140,11 +1141,13 @@ var Lightbox = function (_Component) {
}, {
key: 'gotoPrev',
value: function gotoPrev(event) {
var currentImage = this.props.currentImage;
var _props2 = this.props,
currentImage = _props2.currentImage,
loop = _props2.loop;
var imageLoaded = this.state.imageLoaded;


if (!imageLoaded || currentImage === 0) return;
if (!imageLoaded || !loop && currentImage === 0) return;

if (event) {
event.preventDefault();
Expand Down Expand Up @@ -1193,7 +1196,7 @@ var Lightbox = function (_Component) {
}, {
key: 'renderArrowPrev',
value: function renderArrowPrev() {
if (this.props.currentImage === 0) return null;
if (!this.props.loop && this.props.currentImage === 0) return null;

return React.createElement(Arrow, {
direction: 'left',
Expand All @@ -1206,7 +1209,7 @@ var Lightbox = function (_Component) {
}, {
key: 'renderArrowNext',
value: function renderArrowNext() {
if (this.props.currentImage === this.props.images.length - 1) return null;
if (!this.props.loop && this.props.currentImage === this.props.images.length - 1) return null;

return React.createElement(Arrow, {
direction: 'right',
Expand All @@ -1219,11 +1222,11 @@ var Lightbox = function (_Component) {
}, {
key: 'renderDialog',
value: function renderDialog() {
var _props2 = this.props,
backdropClosesModal = _props2.backdropClosesModal,
isOpen = _props2.isOpen,
showThumbnails = _props2.showThumbnails,
width = _props2.width;
var _props3 = this.props,
backdropClosesModal = _props3.backdropClosesModal,
isOpen = _props3.isOpen,
showThumbnails = _props3.showThumbnails,
width = _props3.width;
var imageLoaded = this.state.imageLoaded;


Expand Down Expand Up @@ -1262,11 +1265,11 @@ var Lightbox = function (_Component) {
}, {
key: 'renderImages',
value: function renderImages() {
var _props3 = this.props,
currentImage = _props3.currentImage,
images = _props3.images,
onClickImage = _props3.onClickImage,
showThumbnails = _props3.showThumbnails;
var _props4 = this.props,
currentImage = _props4.currentImage,
images = _props4.images,
onClickImage = _props4.onClickImage,
showThumbnails = _props4.showThumbnails;
var imageLoaded = this.state.imageLoaded;


Expand Down Expand Up @@ -1299,12 +1302,12 @@ var Lightbox = function (_Component) {
}, {
key: 'renderThumbnails',
value: function renderThumbnails() {
var _props4 = this.props,
images = _props4.images,
currentImage = _props4.currentImage,
onClickThumbnail = _props4.onClickThumbnail,
showThumbnails = _props4.showThumbnails,
thumbnailOffset = _props4.thumbnailOffset;
var _props5 = this.props,
images = _props5.images,
currentImage = _props5.currentImage,
onClickThumbnail = _props5.onClickThumbnail,
showThumbnails = _props5.showThumbnails,
thumbnailOffset = _props5.thumbnailOffset;


if (!showThumbnails) return;
Expand All @@ -1319,11 +1322,11 @@ var Lightbox = function (_Component) {
}, {
key: 'renderHeader',
value: function renderHeader() {
var _props5 = this.props,
closeButtonTitle = _props5.closeButtonTitle,
customControls = _props5.customControls,
onClose = _props5.onClose,
showCloseButton = _props5.showCloseButton;
var _props6 = this.props,
closeButtonTitle = _props6.closeButtonTitle,
customControls = _props6.customControls,
onClose = _props6.onClose,
showCloseButton = _props6.showCloseButton;


return React.createElement(Header, {
Expand All @@ -1336,11 +1339,11 @@ var Lightbox = function (_Component) {
}, {
key: 'renderFooter',
value: function renderFooter() {
var _props6 = this.props,
currentImage = _props6.currentImage,
images = _props6.images,
imageCountSeparator = _props6.imageCountSeparator,
showImageCount = _props6.showImageCount;
var _props7 = this.props,
currentImage = _props7.currentImage,
images = _props7.images,
imageCountSeparator = _props7.imageCountSeparator,
showImageCount = _props7.showImageCount;


if (!images || !images.length) return null;
Expand All @@ -1356,10 +1359,10 @@ var Lightbox = function (_Component) {
}, {
key: 'renderSpinner',
value: function renderSpinner() {
var _props7 = this.props,
spinner = _props7.spinner,
spinnerColor = _props7.spinnerColor,
spinnerSize = _props7.spinnerSize;
var _props8 = this.props,
spinner = _props8.spinner,
spinnerColor = _props8.spinnerColor,
spinnerSize = _props8.spinnerSize;
var imageLoaded = this.state.imageLoaded;

var Spinner$$1 = spinner;
Expand Down Expand Up @@ -1424,6 +1427,7 @@ Lightbox.defaultProps = {
enableKeyboardInput: true,
imageCountSeparator: ' of ',
leftArrowTitle: 'Previous (Left arrow key)',
loop: false,
onClickShowNextImage: true,
preloadNextImage: true,
preventScroll: true,
Expand Down
76 changes: 40 additions & 36 deletions dist/react-images.js
Original file line number Diff line number Diff line change
Expand Up @@ -1126,11 +1126,12 @@ var Lightbox = function (_Component) {
value: function gotoNext(event) {
var _props = this.props,
currentImage = _props.currentImage,
images = _props.images;
images = _props.images,
loop = _props.loop;
var imageLoaded = this.state.imageLoaded;


if (!imageLoaded || currentImage === images.length - 1) return;
if (!imageLoaded || !loop && currentImage === images.length - 1) return;

if (event) {
event.preventDefault();
Expand All @@ -1142,11 +1143,13 @@ var Lightbox = function (_Component) {
}, {
key: 'gotoPrev',
value: function gotoPrev(event) {
var currentImage = this.props.currentImage;
var _props2 = this.props,
currentImage = _props2.currentImage,
loop = _props2.loop;
var imageLoaded = this.state.imageLoaded;


if (!imageLoaded || currentImage === 0) return;
if (!imageLoaded || !loop && currentImage === 0) return;

if (event) {
event.preventDefault();
Expand Down Expand Up @@ -1195,7 +1198,7 @@ var Lightbox = function (_Component) {
}, {
key: 'renderArrowPrev',
value: function renderArrowPrev() {
if (this.props.currentImage === 0) return null;
if (!this.props.loop && this.props.currentImage === 0) return null;

return React__default.createElement(Arrow, {
direction: 'left',
Expand All @@ -1208,7 +1211,7 @@ var Lightbox = function (_Component) {
}, {
key: 'renderArrowNext',
value: function renderArrowNext() {
if (this.props.currentImage === this.props.images.length - 1) return null;
if (!this.props.loop && this.props.currentImage === this.props.images.length - 1) return null;

return React__default.createElement(Arrow, {
direction: 'right',
Expand All @@ -1221,11 +1224,11 @@ var Lightbox = function (_Component) {
}, {
key: 'renderDialog',
value: function renderDialog() {
var _props2 = this.props,
backdropClosesModal = _props2.backdropClosesModal,
isOpen = _props2.isOpen,
showThumbnails = _props2.showThumbnails,
width = _props2.width;
var _props3 = this.props,
backdropClosesModal = _props3.backdropClosesModal,
isOpen = _props3.isOpen,
showThumbnails = _props3.showThumbnails,
width = _props3.width;
var imageLoaded = this.state.imageLoaded;


Expand Down Expand Up @@ -1264,11 +1267,11 @@ var Lightbox = function (_Component) {
}, {
key: 'renderImages',
value: function renderImages() {
var _props3 = this.props,
currentImage = _props3.currentImage,
images = _props3.images,
onClickImage = _props3.onClickImage,
showThumbnails = _props3.showThumbnails;
var _props4 = this.props,
currentImage = _props4.currentImage,
images = _props4.images,
onClickImage = _props4.onClickImage,
showThumbnails = _props4.showThumbnails;
var imageLoaded = this.state.imageLoaded;


Expand Down Expand Up @@ -1301,12 +1304,12 @@ var Lightbox = function (_Component) {
}, {
key: 'renderThumbnails',
value: function renderThumbnails() {
var _props4 = this.props,
images = _props4.images,
currentImage = _props4.currentImage,
onClickThumbnail = _props4.onClickThumbnail,
showThumbnails = _props4.showThumbnails,
thumbnailOffset = _props4.thumbnailOffset;
var _props5 = this.props,
images = _props5.images,
currentImage = _props5.currentImage,
onClickThumbnail = _props5.onClickThumbnail,
showThumbnails = _props5.showThumbnails,
thumbnailOffset = _props5.thumbnailOffset;


if (!showThumbnails) return;
Expand All @@ -1321,11 +1324,11 @@ var Lightbox = function (_Component) {
}, {
key: 'renderHeader',
value: function renderHeader() {
var _props5 = this.props,
closeButtonTitle = _props5.closeButtonTitle,
customControls = _props5.customControls,
onClose = _props5.onClose,
showCloseButton = _props5.showCloseButton;
var _props6 = this.props,
closeButtonTitle = _props6.closeButtonTitle,
customControls = _props6.customControls,
onClose = _props6.onClose,
showCloseButton = _props6.showCloseButton;


return React__default.createElement(Header, {
Expand All @@ -1338,11 +1341,11 @@ var Lightbox = function (_Component) {
}, {
key: 'renderFooter',
value: function renderFooter() {
var _props6 = this.props,
currentImage = _props6.currentImage,
images = _props6.images,
imageCountSeparator = _props6.imageCountSeparator,
showImageCount = _props6.showImageCount;
var _props7 = this.props,
currentImage = _props7.currentImage,
images = _props7.images,
imageCountSeparator = _props7.imageCountSeparator,
showImageCount = _props7.showImageCount;


if (!images || !images.length) return null;
Expand All @@ -1358,10 +1361,10 @@ var Lightbox = function (_Component) {
}, {
key: 'renderSpinner',
value: function renderSpinner() {
var _props7 = this.props,
spinner = _props7.spinner,
spinnerColor = _props7.spinnerColor,
spinnerSize = _props7.spinnerSize;
var _props8 = this.props,
spinner = _props8.spinner,
spinnerColor = _props8.spinnerColor,
spinnerSize = _props8.spinnerSize;
var imageLoaded = this.state.imageLoaded;

var Spinner$$1 = spinner;
Expand Down Expand Up @@ -1426,6 +1429,7 @@ Lightbox.defaultProps = {
enableKeyboardInput: true,
imageCountSeparator: ' of ',
leftArrowTitle: 'Previous (Left arrow key)',
loop: false,
onClickShowNextImage: true,
preloadNextImage: true,
preventScroll: true,
Expand Down
2 changes: 1 addition & 1 deletion dist/react-images.min.js

Large diffs are not rendered by default.

10 changes: 5 additions & 5 deletions examples/dist/example.css
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ h6,
color: black;
font-weight: 500;
line-height: 1;
margin-bottom: .66em;
margin-bottom: 0.66em;
margin-top: 0;
}
h1,
Expand All @@ -85,11 +85,11 @@ h4,
}
h5,
.h5 {
font-size: .85em;
font-size: 0.85em;
}
h6,
.h6 {
font-size: .75em;
font-size: 0.75em;
}
.page-header {
padding: 20px 0;
Expand Down Expand Up @@ -167,7 +167,7 @@ h6,
margin-bottom: 40px;
}
.hint {
font-size: .85em;
font-size: 0.85em;
margin: 15px 0;
color: #666;
}
Expand All @@ -181,7 +181,7 @@ kbd {
color: #666;
display: inline-block;
font-family: Consolas, "Liberation Mono", Courier, monospace;
font-size: .85em;
font-size: 0.85em;
font-weight: 500;
line-height: inherit;
padding: 1px 4px;
Expand Down
2 changes: 1 addition & 1 deletion examples/src/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ render(
caption,
orientation,
useForDemo,
}))} />
}))} loop />

<h3>With Thumbnails</h3>
<Gallery images={THUMBNAIL_IMAGES.map(({ caption, id, orientation, useForDemo }) => ({
Expand Down
Loading