import React, { useCallback, useState } from "react"; import * as GQL from "src/core/generated-graphql"; import { LightboxComponent } from "./Lightbox"; type Image = Pick; export interface IState { images: Image[]; isVisible: boolean; isLoading: boolean; showNavigation: boolean; initialIndex?: number; pageCallback?: (direction: number) => boolean; pageHeader?: string; slideshowEnabled: boolean; onClose?: () => void; } interface IContext { setLightboxState: (state: Partial) => void; } export const LightboxContext = React.createContext({ setLightboxState: () => {}, }); const Lightbox: React.FC = ({ children }) => { const [lightboxState, setLightboxState] = useState({ images: [], isVisible: false, isLoading: false, showNavigation: true, slideshowEnabled: false, }); const setPartialState = useCallback( (state: Partial) => { setLightboxState((currentState: IState) => ({ ...currentState, ...state, })); }, [setLightboxState] ); const onHide = () => { setLightboxState({ ...lightboxState, isVisible: false }); if (lightboxState.onClose) { lightboxState.onClose(); } }; return ( {children} {lightboxState.isVisible && ( )} ); }; export default Lightbox;