2020-03-02 00:21:43 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2020-03-18 23:31:02 +01:00
|
|
|
import { getExtension, getType } from '../../utils';
|
2020-03-16 13:37:10 +01:00
|
|
|
|
|
|
|
import BrokenFile from '../../icons/BrokenFile';
|
2020-03-02 00:21:43 +01:00
|
|
|
import FileIcon from '../FileIcon';
|
|
|
|
import Wrapper from './Wrapper';
|
|
|
|
import Image from './Image';
|
|
|
|
|
2020-03-10 11:32:52 +01:00
|
|
|
const CardPreview = ({ hasError, url, type }) => {
|
2020-03-16 13:37:10 +01:00
|
|
|
const isFile = getType(type) === 'file';
|
2020-03-10 11:32:52 +01:00
|
|
|
|
2020-03-16 15:33:58 +01:00
|
|
|
if (hasError) {
|
|
|
|
return (
|
|
|
|
<Wrapper isFile>
|
|
|
|
<BrokenFile />
|
|
|
|
</Wrapper>
|
|
|
|
);
|
|
|
|
}
|
2020-03-10 11:32:52 +01:00
|
|
|
|
2020-03-20 23:19:18 +01:00
|
|
|
return (
|
|
|
|
<Wrapper isFile={isFile}>
|
|
|
|
{isFile ? <FileIcon ext={getExtension(type)} /> : <Image src={url} />}
|
|
|
|
</Wrapper>
|
|
|
|
);
|
2020-03-02 00:21:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
CardPreview.defaultProps = {
|
2020-03-10 11:32:52 +01:00
|
|
|
hasError: false,
|
2020-03-02 00:21:43 +01:00
|
|
|
url: null,
|
2020-03-06 17:19:20 +01:00
|
|
|
type: '',
|
2020-03-02 00:21:43 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
CardPreview.propTypes = {
|
2020-03-10 11:32:52 +01:00
|
|
|
hasError: PropTypes.bool,
|
2020-03-02 00:21:43 +01:00
|
|
|
url: PropTypes.string,
|
|
|
|
type: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default CardPreview;
|