// Copyright 2018-2020 Signal Messenger, LLC // SPDX-License-Identifier: AGPL-3.0-only import React from 'react'; import classNames from 'classnames'; import type { AttachmentType } from '../../types/Attachment'; import { areAllAttachmentsVisual, getAlt, getImageDimensions, getThumbnailUrl, getUrl, isVideoAttachment, } from '../../types/Attachment'; import { Image } from './Image'; import type { LocalizerType, ThemeType } from '../../types/Util'; export type Props = { attachments: Array; withContentAbove?: boolean; withContentBelow?: boolean; bottomOverlay?: boolean; isSticker?: boolean; stickerSize?: number; tabIndex?: number; i18n: LocalizerType; theme?: ThemeType; onError: () => void; onClick?: (attachment: AttachmentType) => void; }; const GAP = 1; export const ImageGrid = ({ attachments, bottomOverlay, i18n, isSticker, stickerSize, onError, onClick, tabIndex, theme, withContentAbove, withContentBelow, }: Props): JSX.Element | null => { const curveTopLeft = !withContentAbove; const curveTopRight = curveTopLeft; const curveBottom = !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], isSticker ? stickerSize : undefined ); 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],
); };