2018-11-14 18:47:19 +00:00
|
|
|
import React from 'react';
|
|
|
|
import classNames from 'classnames';
|
|
|
|
|
|
|
|
import { Localizer } from '../../types/Util';
|
|
|
|
import { AttachmentType } from './types';
|
|
|
|
|
|
|
|
interface Props {
|
|
|
|
alt: string;
|
|
|
|
attachment: AttachmentType;
|
|
|
|
url: string;
|
|
|
|
|
|
|
|
height?: number;
|
|
|
|
width?: number;
|
|
|
|
|
|
|
|
overlayText?: string;
|
|
|
|
|
|
|
|
bottomOverlay?: boolean;
|
2018-12-02 01:48:53 +00:00
|
|
|
closeButton?: boolean;
|
2018-11-14 18:47:19 +00:00
|
|
|
curveBottomLeft?: boolean;
|
|
|
|
curveBottomRight?: boolean;
|
|
|
|
curveTopLeft?: boolean;
|
|
|
|
curveTopRight?: boolean;
|
|
|
|
darkOverlay?: boolean;
|
|
|
|
playIconOverlay?: boolean;
|
2018-12-02 01:48:53 +00:00
|
|
|
softCorners?: boolean;
|
2018-11-14 18:47:19 +00:00
|
|
|
|
|
|
|
i18n: Localizer;
|
|
|
|
onClick?: (attachment: AttachmentType) => void;
|
2018-12-02 01:48:53 +00:00
|
|
|
onClickClose?: (attachment: AttachmentType) => void;
|
2018-11-14 18:47:19 +00:00
|
|
|
onError?: () => void;
|
|
|
|
}
|
|
|
|
|
|
|
|
export class Image extends React.Component<Props> {
|
2018-12-02 01:48:53 +00:00
|
|
|
// tslint:disable-next-line max-func-body-length cyclomatic-complexity
|
2018-11-14 18:47:19 +00:00
|
|
|
public render() {
|
|
|
|
const {
|
|
|
|
alt,
|
|
|
|
attachment,
|
|
|
|
bottomOverlay,
|
2018-12-02 01:48:53 +00:00
|
|
|
closeButton,
|
2018-11-14 18:47:19 +00:00
|
|
|
curveBottomLeft,
|
|
|
|
curveBottomRight,
|
|
|
|
curveTopLeft,
|
|
|
|
curveTopRight,
|
|
|
|
darkOverlay,
|
|
|
|
height,
|
|
|
|
i18n,
|
|
|
|
onClick,
|
2018-12-02 01:48:53 +00:00
|
|
|
onClickClose,
|
2018-11-14 18:47:19 +00:00
|
|
|
onError,
|
|
|
|
overlayText,
|
|
|
|
playIconOverlay,
|
2018-12-02 01:48:53 +00:00
|
|
|
softCorners,
|
2018-11-14 18:47:19 +00:00
|
|
|
url,
|
|
|
|
width,
|
|
|
|
} = this.props;
|
|
|
|
|
|
|
|
const { caption } = attachment || { caption: null };
|
|
|
|
|
|
|
|
return (
|
|
|
|
<div
|
2018-12-02 01:48:53 +00:00
|
|
|
role={onClick ? 'button' : undefined}
|
2018-11-14 18:47:19 +00:00
|
|
|
onClick={() => {
|
|
|
|
if (onClick) {
|
|
|
|
onClick(attachment);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
className={classNames(
|
|
|
|
'module-image',
|
2018-12-02 01:48:53 +00:00
|
|
|
onClick ? 'module-image__with-click-handler' : null,
|
2018-11-14 18:47:19 +00:00
|
|
|
curveBottomLeft ? 'module-image--curved-bottom-left' : null,
|
|
|
|
curveBottomRight ? 'module-image--curved-bottom-right' : null,
|
|
|
|
curveTopLeft ? 'module-image--curved-top-left' : null,
|
2018-12-02 01:48:53 +00:00
|
|
|
curveTopRight ? 'module-image--curved-top-right' : null,
|
|
|
|
softCorners ? 'module-image--soft-corners' : null
|
2018-11-14 18:47:19 +00:00
|
|
|
)}
|
|
|
|
>
|
|
|
|
<img
|
|
|
|
onError={onError}
|
|
|
|
className="module-image__image"
|
|
|
|
alt={alt}
|
|
|
|
height={height}
|
|
|
|
width={width}
|
|
|
|
src={url}
|
|
|
|
/>
|
|
|
|
{caption ? (
|
|
|
|
<img
|
|
|
|
className="module-image__caption-icon"
|
|
|
|
src="images/caption-shadow.svg"
|
|
|
|
alt={i18n('imageCaptionIconAlt')}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-image__border-overlay',
|
|
|
|
curveTopLeft ? 'module-image--curved-top-left' : null,
|
|
|
|
curveTopRight ? 'module-image--curved-top-right' : null,
|
|
|
|
curveBottomLeft ? 'module-image--curved-bottom-left' : null,
|
|
|
|
curveBottomRight ? 'module-image--curved-bottom-right' : null,
|
2018-12-02 01:48:53 +00:00
|
|
|
softCorners ? 'module-image--soft-corners' : null,
|
2018-11-14 18:47:19 +00:00
|
|
|
darkOverlay ? 'module-image__border-overlay--dark' : null
|
|
|
|
)}
|
|
|
|
/>
|
2018-12-02 01:48:53 +00:00
|
|
|
{closeButton ? (
|
|
|
|
<div
|
|
|
|
role="button"
|
|
|
|
onClick={(e: React.MouseEvent<{}>) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
if (onClickClose) {
|
|
|
|
onClickClose(attachment);
|
|
|
|
}
|
|
|
|
}}
|
|
|
|
className="module-image__close-button"
|
|
|
|
/>
|
|
|
|
) : null}
|
2018-11-14 18:47:19 +00:00
|
|
|
{bottomOverlay ? (
|
|
|
|
<div
|
|
|
|
className={classNames(
|
|
|
|
'module-image__bottom-overlay',
|
|
|
|
curveBottomLeft ? 'module-image--curved-bottom-left' : null,
|
|
|
|
curveBottomRight ? 'module-image--curved-bottom-right' : null
|
|
|
|
)}
|
|
|
|
/>
|
|
|
|
) : null}
|
|
|
|
{playIconOverlay ? (
|
|
|
|
<div className="module-image__play-overlay__circle">
|
|
|
|
<div className="module-image__play-overlay__icon" />
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
{overlayText ? (
|
|
|
|
<div
|
|
|
|
className="module-image__text-container"
|
|
|
|
style={{ lineHeight: `${height}px` }}
|
|
|
|
>
|
|
|
|
{overlayText}
|
|
|
|
</div>
|
|
|
|
) : null}
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|