import { MouseEvent } from "react"; import { Image } from "./Image"; import { useContainerWidth } from "./useContainerWidth"; import { buildLayoutFlat } from "./buildLayout"; import { Image as ImageInterface, GalleryProps } from "./types"; import * as styles from "./styles"; export const Gallery = ({ images, id = "ReactGridGallery", enableImageSelection = true, onSelect = () => {}, rowHeight = 180, maxRows, margin = 2, defaultContainerWidth = 0, onClick = () => {}, tileViewportStyle, thumbnailStyle, tagStyle, thumbnailImageComponent, }: GalleryProps): JSX.Element => { const { containerRef, containerWidth } = useContainerWidth( defaultContainerWidth ); const thumbnails = buildLayoutFlat(images, { containerWidth, maxRows, rowHeight, margin, }); const handleSelect = (index: number, event: MouseEvent) => { event.preventDefault(); onSelect(index, images[index], event); }; const handleClick = (index: number, event: MouseEvent) => { onClick(index, images[index], event); }; return (
{thumbnails.map((item, index) => ( ))}
); }; Gallery.displayName = "Gallery";