|
@@ -11,49 +11,50 @@ const AttachmentLink = Attachment;
|
|
|
* 1. when 'fileFormat' is image, render Attachment as an image
|
|
* 1. when 'fileFormat' is image, render Attachment as an image
|
|
|
* 2. when 'fileFormat' is not image, render Attachment as an Attachment component
|
|
* 2. when 'fileFormat' is not image, render Attachment as an Attachment component
|
|
|
*/
|
|
*/
|
|
|
-export default class AttachmentExtracted extends React.PureComponent {
|
|
|
|
|
|
|
+export default class ExtractedAttachments extends React.PureComponent {
|
|
|
|
|
|
|
|
- renderExtractedImage(attachment) {
|
|
|
|
|
|
|
+ renderExtractedImage(attachment, styles) {
|
|
|
const { refsContext } = this.props;
|
|
const { refsContext } = this.props;
|
|
|
const { options } = refsContext;
|
|
const { options } = refsContext;
|
|
|
|
|
|
|
|
- const {
|
|
|
|
|
- width,
|
|
|
|
|
- height,
|
|
|
|
|
- 'max-width': maxWidth,
|
|
|
|
|
- 'max-height': maxHeight,
|
|
|
|
|
- } = options;
|
|
|
|
|
-
|
|
|
|
|
- const styles = {
|
|
|
|
|
- width, height, maxWidth, maxHeight,
|
|
|
|
|
- };
|
|
|
|
|
-
|
|
|
|
|
// determine alt
|
|
// determine alt
|
|
|
let alt = refsContext.isSingle ? options.alt : undefined; // use only when single mode
|
|
let alt = refsContext.isSingle ? options.alt : undefined; // use only when single mode
|
|
|
alt = alt || attachment.originalName; // use 'originalName' if options.alt is not specified
|
|
alt = alt || attachment.originalName; // use 'originalName' if options.alt is not specified
|
|
|
|
|
|
|
|
return (
|
|
return (
|
|
|
- <div>
|
|
|
|
|
- <a href="#">
|
|
|
|
|
- <img src={attachment.filePathProxied} alt={alt} style={styles} />
|
|
|
|
|
- </a>
|
|
|
|
|
- </div>
|
|
|
|
|
|
|
+ <a key={attachment._id} href="#" style={styles}>
|
|
|
|
|
+ <img src={attachment.filePathProxied} alt={alt} style={styles} />
|
|
|
|
|
+ </a>
|
|
|
);
|
|
);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
render() {
|
|
render() {
|
|
|
- const { attachment } = this.props;
|
|
|
|
|
|
|
+ const { refsContext } = this.props;
|
|
|
|
|
+ const { options } = refsContext;
|
|
|
|
|
+
|
|
|
|
|
+ const {
|
|
|
|
|
+ width,
|
|
|
|
|
+ height,
|
|
|
|
|
+ 'max-width': maxWidth,
|
|
|
|
|
+ 'max-height': maxHeight,
|
|
|
|
|
+ } = options;
|
|
|
|
|
+
|
|
|
|
|
+ const styles = {
|
|
|
|
|
+ width, height, maxWidth, maxHeight, display: 'block',
|
|
|
|
|
+ };
|
|
|
|
|
|
|
|
- const isImage = attachment.fileFormat.startsWith('image/');
|
|
|
|
|
|
|
+ return this.props.attachments.map((attachment) => {
|
|
|
|
|
+ const isImage = attachment.fileFormat.startsWith('image/');
|
|
|
|
|
|
|
|
- return (isImage)
|
|
|
|
|
- ? this.renderExtractedImage(attachment)
|
|
|
|
|
- : <AttachmentLink key={attachment._id} attachment={attachment} />;
|
|
|
|
|
|
|
+ return (isImage)
|
|
|
|
|
+ ? this.renderExtractedImage(attachment, styles)
|
|
|
|
|
+ : <AttachmentLink key={attachment._id} attachment={attachment} />;
|
|
|
|
|
+ });
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-AttachmentExtracted.propTypes = {
|
|
|
|
|
- attachment: PropTypes.object.isRequired,
|
|
|
|
|
|
|
+ExtractedAttachments.propTypes = {
|
|
|
|
|
+ attachments: PropTypes.arrayOf(PropTypes.object).isRequired,
|
|
|
refsContext: PropTypes.instanceOf(RefsContext).isRequired,
|
|
refsContext: PropTypes.instanceOf(RefsContext).isRequired,
|
|
|
};
|
|
};
|