accords-library.com/src/components/LightBox.tsx

37 lines
1.1 KiB
TypeScript
Raw Normal View History

2022-03-18 00:54:10 +00:00
import { Dispatch, SetStateAction } from "react";
import Lightbox from "react-image-lightbox";
2022-03-18 00:54:10 +00:00
export type LightBoxProps = {
setState:
| Dispatch<SetStateAction<boolean>>
| Dispatch<SetStateAction<boolean | undefined>>;
state: boolean;
images: string[];
index: number;
setIndex: Dispatch<SetStateAction<number>>;
2022-03-18 00:54:10 +00:00
};
export default function LightBox(props: LightBoxProps): JSX.Element {
const { state, setState, images, index, setIndex } = props;
2022-03-18 00:54:10 +00:00
return (
<>
{state && (
<Lightbox
reactModalProps={{
parentSelector: () => document.getElementById("MyAppLayout"),
}}
mainSrc={images[index]}
prevSrc={index > 0 ? images[index - 1] : undefined}
nextSrc={index < images.length ? images[index + 1] : undefined}
onMovePrevRequest={() => setIndex(index - 1)}
onMoveNextRequest={() => setIndex(index + 1)}
imageCaption=""
imageTitle=""
onCloseRequest={() => setState(false)}
imagePadding={50}
/>
)}
</>
2022-03-18 00:54:10 +00:00
);
}