2020-03-02 00:21:43 +01:00
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
|
|
|
|
2020-03-16 13:37:10 +01:00
|
|
|
import { getType } from '../../utils';
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
const renderFile = () => <FileIcon fileType={type} />;
|
|
|
|
|
|
|
|
const renderImage = () => <Image src={url} />;
|
|
|
|
|
2020-03-05 16:13:44 +01:00
|
|
|
return (
|
2020-03-10 11:32:52 +01:00
|
|
|
<Wrapper isFile={isFile || hasError}>
|
|
|
|
{!hasError && isFile && renderFile()}
|
|
|
|
{!hasError && !isFile && renderImage()}
|
2020-03-16 13:37:10 +01:00
|
|
|
{hasError && <BrokenFile />}
|
2020-03-10 11:32:52 +01:00
|
|
|
</Wrapper>
|
2020-03-05 16:13:44 +01:00
|
|
|
);
|
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;
|