import React from 'react'; import { FormattedMessage } from 'react-intl'; import { REM_SIZE } from '../config.js'; import { fitImageSize } from '../lib/blob-helpers.js'; import { bytesToHumanSize } from '../lib/strformat.js'; export default class ImagePreview extends React.PureComponent { constructor(props) { super(props); this.state = {}; } componentDidMount() { this.setState({ width: this.container.clientWidth, height: this.container.clientHeight }); } render() { if (!this.props.content) { return null; } const instance = this; const dim = fitImageSize(this.props.content.width, this.props.content.height, this.state.width, this.state.height, false); const size = dim ? { width: dim.dstWidth + 'px', height: dim.dstHeight + 'px' } : ((this.props.content.width > this.props.content.height) ? {width: '100%'} : {height: '100%'}); size.maxWidth = '100%'; size.maxHeight = '100%'; let filename = this.props.content.filename; const maxlength = (this.props.content.width / REM_SIZE) | 0; if (filename.length > maxlength) { filename = filename.slice(0, maxlength-2) + '...' + filename.slice(2-maxlength); } const width = this.props.content.width || '-'; const height = this.props.content.height || '-'; return (
); } };