main
Last change
on this file was 5d6f37a, checked in by Naum Shapkarovski <naumshapkarovski@…>, 8 weeks ago |
add customer
|
-
Property mode
set to
100644
|
File size:
1.8 KB
|
Rev | Line | |
---|
[5d6f37a] | 1 | import { Theme, SxProps } from '@mui/material/styles';
|
---|
| 2 | import Box from '@mui/material/Box';
|
---|
| 3 | import Stack from '@mui/material/Stack';
|
---|
| 4 | import Tooltip from '@mui/material/Tooltip';
|
---|
| 5 | //
|
---|
| 6 | import { fileData, fileFormat, fileThumb } from './utils';
|
---|
| 7 | import DownloadButton from './download-button';
|
---|
| 8 |
|
---|
| 9 | // ----------------------------------------------------------------------
|
---|
| 10 |
|
---|
| 11 | type FileIconProps = {
|
---|
| 12 | file: File | string;
|
---|
| 13 | tooltip?: boolean;
|
---|
| 14 | imageView?: boolean;
|
---|
| 15 | onDownload?: VoidFunction;
|
---|
| 16 | sx?: SxProps<Theme>;
|
---|
| 17 | imgSx?: SxProps<Theme>;
|
---|
| 18 | };
|
---|
| 19 |
|
---|
| 20 | export default function FileThumbnail({
|
---|
| 21 | file,
|
---|
| 22 | tooltip,
|
---|
| 23 | imageView,
|
---|
| 24 | onDownload,
|
---|
| 25 | sx,
|
---|
| 26 | imgSx,
|
---|
| 27 | }: FileIconProps) {
|
---|
| 28 | const { name = '', path = '', preview = '' } = fileData(file);
|
---|
| 29 |
|
---|
| 30 | const format = fileFormat(path || preview);
|
---|
| 31 |
|
---|
| 32 | const renderContent =
|
---|
| 33 | format === 'image' && imageView ? (
|
---|
| 34 | <Box
|
---|
| 35 | component="img"
|
---|
| 36 | src={preview}
|
---|
| 37 | sx={{
|
---|
| 38 | width: 1,
|
---|
| 39 | height: 1,
|
---|
| 40 | flexShrink: 0,
|
---|
| 41 | objectFit: 'cover',
|
---|
| 42 | ...imgSx,
|
---|
| 43 | }}
|
---|
| 44 | />
|
---|
| 45 | ) : (
|
---|
| 46 | <Box
|
---|
| 47 | component="img"
|
---|
| 48 | src={fileThumb(format)}
|
---|
| 49 | sx={{
|
---|
| 50 | width: 32,
|
---|
| 51 | height: 32,
|
---|
| 52 | flexShrink: 0,
|
---|
| 53 | ...sx,
|
---|
| 54 | }}
|
---|
| 55 | />
|
---|
| 56 | );
|
---|
| 57 |
|
---|
| 58 | if (tooltip) {
|
---|
| 59 | return (
|
---|
| 60 | <Tooltip title={name}>
|
---|
| 61 | <Stack
|
---|
| 62 | flexShrink={0}
|
---|
| 63 | component="span"
|
---|
| 64 | alignItems="center"
|
---|
| 65 | justifyContent="center"
|
---|
| 66 | sx={{
|
---|
| 67 | width: 'fit-content',
|
---|
| 68 | height: 'inherit',
|
---|
| 69 | }}
|
---|
| 70 | >
|
---|
| 71 | {renderContent}
|
---|
| 72 | {onDownload && <DownloadButton onDownload={onDownload} />}
|
---|
| 73 | </Stack>
|
---|
| 74 | </Tooltip>
|
---|
| 75 | );
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | return (
|
---|
| 79 | <>
|
---|
| 80 | {renderContent}
|
---|
| 81 | {onDownload && <DownloadButton onDownload={onDownload} />}
|
---|
| 82 | </>
|
---|
| 83 | );
|
---|
| 84 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.