From d634a414c3ad4c10ebd3273effd1daaf74e574bd Mon Sep 17 00:00:00 2001 From: Daniel Gasienica Date: Sun, 15 Apr 2018 01:48:43 -0400 Subject: [PATCH] Make visibility of previous/next buttons opt-in --- ts/components/Lightbox.tsx | 41 ++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/ts/components/Lightbox.tsx b/ts/components/Lightbox.tsx index e44572328..2e7a1f897 100644 --- a/ts/components/Lightbox.tsx +++ b/ts/components/Lightbox.tsx @@ -8,7 +8,11 @@ import classNames from 'classnames'; interface Props { close: () => void; imageURL?: string; + onNext?: () => void; + onPrevious?: () => void; onSave: () => void; + shouldShowNextButton: boolean; + shouldShowPreviousButton: boolean; } const styles = { @@ -54,6 +58,11 @@ const IconButton = ({ onClick, type }: IconButtonProps) => ( export class Lightbox extends React.Component { private containerRef: HTMLDivElement | null = null; + public static defaultProps: Partial = { + shouldShowNextButton: false, + shouldShowPreviousButton: false, + }; + public componentDidMount() { const useCapture = true; document.addEventListener('keyup', this.onKeyUp, useCapture); @@ -65,17 +74,33 @@ export class Lightbox extends React.Component { } public render() { - const { imageURL } = this.props; + const { + imageURL, + shouldShowNextButton, + shouldShowPreviousButton, + } = this.props; return ( -
+
- +
- - + {shouldShowPreviousButton ? ( + + ) : null} + {shouldShowNextButton ? ( + + ) : null}
); @@ -83,7 +108,7 @@ export class Lightbox extends React.Component { private setContainerRef = (value: HTMLDivElement) => { this.containerRef = value; - } + }; private onClose = () => { this.props.close(); @@ -102,10 +127,10 @@ export class Lightbox extends React.Component { return; } this.onClose(); - } + }; private onImageClick = (event: React.MouseEvent) => { event.stopPropagation(); this.onClose(); - } + }; }