Skip to content
This repository was archived by the owner on Jan 19, 2023. It is now read-only.

Commit 5272072

Browse files
committed
Add option to disable zoom functionality
1 parent 73e71bb commit 5272072

File tree

2 files changed

+32
-17
lines changed

2 files changed

+32
-17
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ toolbarButtons | node[] | | | Array of custom toolb
101101
reactModalStyle | Object | `{}` | | Set z-index style, etc., for the parent react-modal (format: https://github.com/reactjs/react-modal#styles )
102102
imagePadding | number | `10` | | Padding (px) between the edge of the window and the lightbox
103103
clickOutsideToClose | bool | `true` | | When true, clicks outside of the image close the lightbox
104+
enableZoom | bool | `true` | | Set to false to disable zoom functionality and hide zoom buttons
104105

105106
## Contributing
106107

src/react-image-lightbox.js

Lines changed: 31 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,11 @@ class ReactImageLightbox extends Component {
189189

190190
// Change zoom level
191191
changeZoom(zoomLevel, clientX, clientY) {
192+
// Ignore if zoom disabled
193+
if (!this.props.enableZoom) {
194+
return;
195+
}
196+
192197
// Constrain zoom level to the set bounds
193198
const nextZoomLevel = Math.max(MIN_ZOOM_LEVEL, Math.min(MAX_ZOOM_LEVEL, zoomLevel));
194199

@@ -834,6 +839,7 @@ class ReactImageLightbox extends Component {
834839
animationDuration,
835840
clickOutsideToClose,
836841
discourageDownloads,
842+
enableZoom,
837843
imageTitle,
838844
nextSrc,
839845
prevSrc,
@@ -1107,23 +1113,27 @@ class ReactImageLightbox extends Component {
11071113
<li key={i} className={`ril-toolbar__item ${styles.toolbarItem}`}>{button}</li>
11081114
))}
11091115

1110-
<li className={`ril-toolbar__item ${styles.toolbarItem}`}>
1111-
<button // Lightbox zoom in button
1112-
type="button"
1113-
key="zoom-in"
1114-
className={`zoom-in ril-zoom-in ${zoomInButtonClasses.join(' ')}`}
1115-
onClick={zoomInButtonHandler}
1116-
/>
1117-
</li>
1118-
1119-
<li className={`ril-toolbar__item ${styles.toolbarItem}`}>
1120-
<button // Lightbox zoom out button
1121-
type="button"
1122-
key="zoom-out"
1123-
className={`zoom-out ril-zoom-out ${zoomOutButtonClasses.join(' ')}`}
1124-
onClick={zoomOutButtonHandler}
1125-
/>
1126-
</li>
1116+
{enableZoom &&
1117+
<li className={`ril-toolbar__item ${styles.toolbarItem}`}>
1118+
<button // Lightbox zoom in button
1119+
type="button"
1120+
key="zoom-in"
1121+
className={`zoom-in ril-zoom-in ${zoomInButtonClasses.join(' ')}`}
1122+
onClick={zoomInButtonHandler}
1123+
/>
1124+
</li>
1125+
}
1126+
1127+
{enableZoom &&
1128+
<li className={`ril-toolbar__item ${styles.toolbarItem}`}>
1129+
<button // Lightbox zoom out button
1130+
type="button"
1131+
key="zoom-out"
1132+
className={`zoom-out ril-zoom-out ${zoomOutButtonClasses.join(' ')}`}
1133+
onClick={zoomOutButtonHandler}
1134+
/>
1135+
</li>
1136+
}
11271137

11281138
<li className={`ril-toolbar__item ${styles.toolbarItem}`}>
11291139
<button // Lightbox close button
@@ -1248,6 +1258,9 @@ ReactImageLightbox.propTypes = {
12481258

12491259
// When true, clicks outside of the image close the lightbox
12501260
clickOutsideToClose: PropTypes.bool,
1261+
1262+
// Set to false to disable zoom functionality and hide zoom buttons
1263+
enableZoom: PropTypes.bool,
12511264
};
12521265

12531266
ReactImageLightbox.defaultProps = {
@@ -1266,6 +1279,7 @@ ReactImageLightbox.defaultProps = {
12661279
reactModalStyle: {},
12671280
imagePadding: 10,
12681281
clickOutsideToClose: true,
1282+
enableZoom: true,
12691283
};
12701284

12711285
export default ReactImageLightbox;

0 commit comments

Comments
 (0)