import React from 'react'; import classNames from 'classnames'; import { areAllAttachmentsVisual, AttachmentType, getAlt, getImageDimensions, getThumbnailUrl, getUrl, isVideoAttachment, } from '../../types/Attachment'; import { Image } from './Image'; import { LocalizerType } from '../../types/Util'; interface Props { attachments: Array; withContentAbove?: boolean; withContentBelow?: boolean; bottomOverlay?: boolean; isSticker?: boolean; stickerSize?: number; i18n: LocalizerType; onError: () => void; onClick?: (attachment: AttachmentType) => void; } export class ImageGrid extends React.Component { // tslint:disable-next-line max-func-body-length */ public render() { const { attachments, bottomOverlay, i18n, isSticker, stickerSize, onError, onClick, withContentAbove, withContentBelow, } = this.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]); const finalHeight = isSticker ? stickerSize : height; const finalWidth = isSticker ? stickerSize : width; 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],
); } }