2018-02-19 14:23:47 +01:00
|
|
|
/**
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* FileIcon
|
|
|
|
*/
|
|
|
|
|
|
|
|
import React from 'react';
|
|
|
|
import PropTypes from 'prop-types';
|
2018-02-26 12:16:15 +01:00
|
|
|
import { trim } from 'lodash';
|
2018-02-19 14:23:47 +01:00
|
|
|
|
2018-02-23 14:57:15 +01:00
|
|
|
import ext from './extensions.json';
|
2019-09-10 16:34:43 +02:00
|
|
|
import Wrapper from './Wrapper';
|
2018-02-19 14:23:47 +01:00
|
|
|
|
|
|
|
function FileIcon({ fileType }) {
|
2018-02-22 12:55:13 +01:00
|
|
|
const iconType = (() => {
|
2018-02-23 14:57:15 +01:00
|
|
|
switch (true) {
|
2018-02-26 12:16:15 +01:00
|
|
|
case ext.archive.includes(trim(fileType, '.')):
|
2019-11-19 16:17:15 +01:00
|
|
|
return 'file-archive';
|
2018-02-26 12:16:15 +01:00
|
|
|
case ext.code.includes(trim(fileType, '.')):
|
2019-11-19 16:17:15 +01:00
|
|
|
return 'file-code';
|
2018-02-26 12:16:15 +01:00
|
|
|
case ext.img.includes(trim(fileType, '.')):
|
2019-11-19 16:17:15 +01:00
|
|
|
return 'file-image';
|
2018-02-26 12:16:15 +01:00
|
|
|
case ext.pdf.includes(trim(fileType, '.')):
|
2019-11-19 16:17:15 +01:00
|
|
|
return 'file-pdf';
|
2018-02-26 12:16:15 +01:00
|
|
|
case ext.powerpoint.includes(trim(fileType, '.')):
|
2019-11-19 16:17:15 +01:00
|
|
|
return 'file-powerpoint';
|
2018-02-26 12:16:15 +01:00
|
|
|
case ext.video.includes(trim(fileType, '.')):
|
2019-11-19 16:17:15 +01:00
|
|
|
return 'file-video';
|
2018-02-26 12:16:15 +01:00
|
|
|
case ext.word.includes(trim(fileType, '.')):
|
2019-11-19 16:17:15 +01:00
|
|
|
return 'file-word';
|
2018-02-22 12:55:13 +01:00
|
|
|
default:
|
2018-02-23 14:57:15 +01:00
|
|
|
return 'file';
|
2018-02-22 14:01:24 +01:00
|
|
|
}
|
2018-02-22 12:55:13 +01:00
|
|
|
})();
|
2018-02-19 14:23:47 +01:00
|
|
|
|
|
|
|
return (
|
2019-09-10 16:34:43 +02:00
|
|
|
<Wrapper type={iconType}>
|
2018-02-23 14:57:15 +01:00
|
|
|
<i className={`fa fa-${iconType}`} />
|
2019-09-10 16:34:43 +02:00
|
|
|
</Wrapper>
|
2018-02-19 14:23:47 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
FileIcon.defaultProps = {
|
|
|
|
fileType: 'zip',
|
|
|
|
};
|
|
|
|
|
|
|
|
FileIcon.propTypes = {
|
|
|
|
fileType: PropTypes.string,
|
|
|
|
};
|
|
|
|
|
|
|
|
export default FileIcon;
|