import React from 'react'; import Lightbox, { Image } from 'react-images'; import Img from 'gatsby-image'; import { Box } from '@rebass/emotion'; import { FluidContainer } from 'utils/styles/mixins'; import { MultiImageModuleProps } from '../multi-image-module.types'; import { GridLayoutState } from './grid-layout.types'; import { LightboxTheme } from './grid-layout.constants'; import * as Styles from './grid-layout.styles'; class GridLayout extends React.Component< MultiImageModuleProps, GridLayoutState > { constructor(props: MultiImageModuleProps) { super(props); this.state = { lightbox: false, currentImage: 0, images: this.buildLightboxImages() }; } buildLightboxImages = (): Image[] => this.props.data.images.map(image => ({ src: image.fluid.src, srcset: image.fluid.srcSet.split(','), caption: image.alt })) openLightbox = ( currentImage: number, event: React.MouseEvent ): void => { event.preventDefault(); this.setState({ lightbox: true, currentImage }); } onClickPrev = (): void => this.setState({ currentImage: this.state.currentImage - 1 }) onClickNext = (): void => this.setState({ currentImage: this.state.currentImage + 1 }) onClose = (): void => { this.setState({ lightbox: false }); } render(): JSX.Element { return ( { this.props.data.images.map((image, index) => ( this.openLightbox(index, e)} > )) } ); } } export default GridLayout;