import { Dispatch, SetStateAction, useCallback } from "react"; import Hotkeys from "react-hot-keys"; import { useSwipeable } from "react-swipeable"; import { Img } from "./Img"; import { Button } from "./Inputs/Button"; import { Popup } from "./Popup"; import { Icon } from "components/Ico"; /* * ╭─────────────╮ * ────────────────────────────────────────╯ CONSTANTS ╰────────────────────────────────────────── */ const SENSIBILITY_SWIPE = 0.5; /* * ╭─────────────╮ * ───────────────────────────────────────╯ COMPONENT ╰─────────────────────────────────────────── */ interface Props { setState: | Dispatch> | Dispatch>; state: boolean; images: string[]; index: number; setIndex: Dispatch>; } // ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ export const LightBox = ({ state, setState, images, index, setIndex, }: Props): JSX.Element => { const handlePrevious = useCallback(() => { if (index > 0) setIndex(index - 1); }, [index, setIndex]); const handleNext = useCallback(() => { if (index < images.length - 1) setIndex(index + 1); }, [images.length, index, setIndex]); const handlers = useSwipeable({ onSwipedLeft: (SwipeEventData) => { if (SwipeEventData.velocity < SENSIBILITY_SWIPE) return; handleNext(); }, onSwipedRight: (SwipeEventData) => { if (SwipeEventData.velocity < SENSIBILITY_SWIPE) return; handlePrevious(); }, }); return ( <> {state && ( { if (keyName === "left") { handlePrevious(); } else { handleNext(); } }} >
{index > 0 && (
{index < images.length - 1 && (
)} ); };