import { useState, MouseEvent } from "react"; import { CheckButton } from "./CheckButton"; import { ImageExtended, ImageProps } from "./types"; import * as styles from "./styles"; import { getStyle } from "./styles"; export const Image = ({ item, thumbnailImageComponent: ThumbnailImageComponent, isSelectable = true, thumbnailStyle, tagStyle, tileViewportStyle, margin, index, onSelect, onClick, }: ImageProps): JSX.Element => { const styleContext = { item }; const [hover, setHover] = useState(false); const thumbnailProps = { key: index, "data-testid": "grid-gallery-item_thumbnail", src: item.src, alt: item.alt ? item.alt : "", title: typeof item.caption === "string" ? item.caption : null, style: getStyle(thumbnailStyle, styles.thumbnail, styleContext), }; const handleCheckButtonClick = (event: MouseEvent) => { if (!isSelectable) { return; } onSelect(index, event); }; const handleViewportClick = (event: MouseEvent) => { onClick(index, event); }; const thumbnailImageProps = { item, index, margin, onSelect, onClick, isSelectable, tileViewportStyle, thumbnailStyle, tagStyle, }; return (
setHover(true)} onMouseLeave={() => setHover(false)} style={styles.galleryItem({ margin })} >
{!!item.tags && (
{item.tags.map((tag, index) => (
{tag.value}
))}
)} {!!item.customOverlay && (
{item.customOverlay}
)}
{ThumbnailImageComponent ? ( ) : ( )}
{item.thumbnailCaption && (
{item.thumbnailCaption}
)}
); };