spee.ch/react/components/AssetPreview/index.js

52 lines
1.4 KiB
JavaScript
Raw Normal View History

import React from 'react';
import { Link } from 'react-router-dom';
2018-01-31 19:40:26 +01:00
const AssetPreview = ({ name, claimId, fileExt, contentType }) => {
const directSourceLink = `${claimId}/${name}.${fileExt}`;
const showUrlLink = `${claimId}/${name}`;
2018-01-31 19:40:26 +01:00
const previewHolderStyle = {
2018-02-05 01:40:28 +01:00
clear : 'both',
display: 'inline-block',
width : '31%',
padding: '0px',
margin : '1%',
2018-01-31 19:40:26 +01:00
};
const assetStyle = {
width : '100%',
2018-01-31 19:40:26 +01:00
padding: '0px',
margin : '0px',
2018-01-31 19:40:26 +01:00
};
return (
<div style={previewHolderStyle}>
<Link to={showUrlLink} >
{(() => {
switch (contentType) {
case 'image/jpeg':
case 'image/jpg':
case 'image/png':
return (
<img style={assetStyle} className={'asset-preview--image'} src={directSourceLink} alt={name}/>
);
case 'image/gif':
return (
<img style={assetStyle} className={'asset-preview--gif'} src={directSourceLink} alt={name}/>
);
case 'video/mp4':
return (
<video style={assetStyle}>
<source src={directSourceLink} type={contentType}/>
</video>
);
default:
return (
<p>unsupported file type</p>
);
}
})()}
</Link>
</div>
);
};
export default AssetPreview;