diff --git a/README.md b/README.md index f2bdf2f..e177a75 100644 --- a/README.md +++ b/README.md @@ -80,7 +80,8 @@ rowHeight | number | 180 | Optional. The height o margin | number | 2 | Optional. The margin around each image in the gallery. enableLightbox | bool | true | Optional. Enable lightbox display of full size image when thumbnail clicked. onClickThumbnail | func | openLightbox | Optional. Function to execute when gallery thumbnail clicked. Optional args: index (index of selected image in images array), event (the click event). Overrides openLightbox. - +lightboxWillOpen | func | undefined | Optional. Function to be called before opening lightbox. Optional arg: index (index of selected image in images array). +lightboxWillClose | func | undefined | Optional. Function to be called before closing lightbox. ## Lightbox Options NOTE: these options are passed inside the Gallery tag. diff --git a/examples/index.html b/examples/index.html index b352d83..02ca3a8 100644 --- a/examples/index.html +++ b/examples/index.html @@ -188,6 +188,18 @@

openLightbox Optional. Function to execute when gallery thumbnail clicked. Optional args: index (index of selected image in images array), event (the click event). Overrides openLightbox. + +lightboxWillOpen +func +undefined +Optional. Function to be called before opening lightbox. Optional arg: index (index of selected image in images array). + + +lightboxWillClose +func +undefined +Optional. Function to be called before closing lightbox. +

Lightbox Options

diff --git a/src/Gallery.js b/src/Gallery.js index bd354c9..7557968 100644 --- a/src/Gallery.js +++ b/src/Gallery.js @@ -56,6 +56,10 @@ class Gallery extends Component { openLightbox (index, event) { event.preventDefault(); + if (this.props.lightboxWillOpen) { + this.props.lightboxWillOpen(index); + } + this.setState({ currentImage: index, lightboxIsOpen: true @@ -63,6 +67,10 @@ class Gallery extends Component { } closeLightbox () { + if (this.props.lightboxWillClose) { + this.props.lightboxWillClose(); + } + this.setState({ currentImage: 0, lightboxIsOpen: false @@ -262,6 +270,8 @@ Gallery.propTypes = { rowHeight: PropTypes.number, margin: PropTypes.number, onClickThumbnail: PropTypes.func, + lightboxWillOpen: PropTypes.func, + lightboxWillClose: PropTypes.func, enableLightbox: PropTypes.bool, backdropClosesModal: PropTypes.bool, currentImage: PropTypes.number,