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

40 lines
1.2 KiB
TypeScript
Raw Normal View History

2022-03-18 13:01:25 +00:00
import { useMediaMobile } from "hooks/useMediaQuery";
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 | undefined>>
| Dispatch<SetStateAction<boolean>>;
2022-03-18 00:54:10 +00:00
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 13:01:25 +00:00
const mobile = useMediaMobile();
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)}
2022-03-18 13:01:25 +00:00
imagePadding={mobile ? 0 : 70}
/>
)}
</>
2022-03-18 00:54:10 +00:00
);
}