import React from 'react'; import classNames from 'classnames'; import { areAllAttachmentsVisual, AttachmentType, getAlt, getImageDimensions, getThumbnailUrl, getUrl, isVideoAttachment, } from '../../types/Attachment'; import { Image } from './Image'; type Props = { attachments: Array; withContentAbove?: boolean; withContentBelow?: boolean; bottomOverlay?: boolean; onError: () => void; onClickAttachment?: (attachment: AttachmentType) => void; }; export const ImageGrid = (props: Props) => { // tslint:disable-next-line max-func-body-length */ const { attachments, bottomOverlay, onError, onClickAttachment, withContentAbove, withContentBelow, } = props; const curveTopLeft = !Boolean(withContentAbove); const curveTopRight = curveTopLeft; const curveBottom = !Boolean(withContentBelow); const curveBottomLeft = curveBottom; const curveBottomRight = curveBottom; const withBottomOverlay = Boolean(bottomOverlay && curveBottom); if (!attachments || !attachments.length) { return null; } if (attachments.length === 1 || !areAllAttachmentsVisual(attachments)) { const { height, width } = getImageDimensions(attachments[0]); return (
{getAlt(attachments[0])}
); } if (attachments.length === 2) { return (
{getAlt(attachments[0])} {getAlt(attachments[1])}
); } if (attachments.length === 3) { return (
{getAlt(attachments[0])}
{getAlt(attachments[1])} {getAlt(attachments[2])}
); } if (attachments.length === 4) { return (
{getAlt(attachments[0])} {getAlt(attachments[1])}
{getAlt(attachments[2])} {getAlt(attachments[3])}
); } const moreMessagesOverlay = attachments.length > 5; const moreMessagesOverlayText = moreMessagesOverlay ? `+${attachments.length - 5}` : undefined; return (
{getAlt(attachments[0])} {getAlt(attachments[1])}
{getAlt(attachments[2])} {getAlt(attachments[3])} {getAlt(attachments[4])}
); };