1 | import { m, AnimatePresence } from 'framer-motion';
|
---|
2 | // @mui
|
---|
3 | import { alpha } from '@mui/material/styles';
|
---|
4 | import Stack from '@mui/material/Stack';
|
---|
5 | import IconButton from '@mui/material/IconButton';
|
---|
6 | import ListItemText from '@mui/material/ListItemText';
|
---|
7 | // utils
|
---|
8 | import { fData } from 'src/utils/format-number';
|
---|
9 | //
|
---|
10 | import Iconify from '../iconify';
|
---|
11 | import { varFade } from '../animate';
|
---|
12 | import FileThumbnail, { fileData } from '../file-thumbnail';
|
---|
13 | //
|
---|
14 | import { UploadProps } from './types';
|
---|
15 |
|
---|
16 | // ----------------------------------------------------------------------
|
---|
17 |
|
---|
18 | export default function MultiFilePreview({ thumbnail, files, onRemove, sx }: UploadProps) {
|
---|
19 | return (
|
---|
20 | <AnimatePresence initial={false}>
|
---|
21 | {files?.map((file) => {
|
---|
22 | const { key, name = '', size = 0 } = fileData(file);
|
---|
23 |
|
---|
24 | const isNotFormatFile = typeof file === 'string';
|
---|
25 |
|
---|
26 | if (thumbnail) {
|
---|
27 | return (
|
---|
28 | <Stack
|
---|
29 | key={key}
|
---|
30 | component={m.div}
|
---|
31 | {...varFade().inUp}
|
---|
32 | alignItems="center"
|
---|
33 | display="inline-flex"
|
---|
34 | justifyContent="center"
|
---|
35 | sx={{
|
---|
36 | m: 0.5,
|
---|
37 | width: 80,
|
---|
38 | height: 80,
|
---|
39 | borderRadius: 1.25,
|
---|
40 | overflow: 'hidden',
|
---|
41 | position: 'relative',
|
---|
42 | border: (theme) => `solid 1px ${alpha(theme.palette.grey[500], 0.16)}`,
|
---|
43 | ...sx,
|
---|
44 | }}
|
---|
45 | >
|
---|
46 | <FileThumbnail
|
---|
47 | tooltip
|
---|
48 | imageView
|
---|
49 | file={file}
|
---|
50 | sx={{ position: 'absolute' }}
|
---|
51 | imgSx={{ position: 'absolute' }}
|
---|
52 | />
|
---|
53 |
|
---|
54 | {onRemove && (
|
---|
55 | <IconButton
|
---|
56 | size="small"
|
---|
57 | onClick={() => onRemove(file)}
|
---|
58 | sx={{
|
---|
59 | p: 0.5,
|
---|
60 | top: 4,
|
---|
61 | right: 4,
|
---|
62 | position: 'absolute',
|
---|
63 | color: 'common.white',
|
---|
64 | bgcolor: (theme) => alpha(theme.palette.grey[900], 0.48),
|
---|
65 | '&:hover': {
|
---|
66 | bgcolor: (theme) => alpha(theme.palette.grey[900], 0.72),
|
---|
67 | },
|
---|
68 | }}
|
---|
69 | >
|
---|
70 | <Iconify icon="mingcute:close-line" width={14} />
|
---|
71 | </IconButton>
|
---|
72 | )}
|
---|
73 | </Stack>
|
---|
74 | );
|
---|
75 | }
|
---|
76 |
|
---|
77 | return (
|
---|
78 | <Stack
|
---|
79 | key={key}
|
---|
80 | component={m.div}
|
---|
81 | {...varFade().inUp}
|
---|
82 | spacing={2}
|
---|
83 | direction="row"
|
---|
84 | alignItems="center"
|
---|
85 | sx={{
|
---|
86 | my: 1,
|
---|
87 | py: 1,
|
---|
88 | px: 1.5,
|
---|
89 | borderRadius: 1,
|
---|
90 | border: (theme) => `solid 1px ${alpha(theme.palette.grey[500], 0.16)}`,
|
---|
91 | ...sx,
|
---|
92 | }}
|
---|
93 | >
|
---|
94 | <FileThumbnail file={file} />
|
---|
95 |
|
---|
96 | <ListItemText
|
---|
97 | primary={isNotFormatFile ? file : name}
|
---|
98 | secondary={isNotFormatFile ? '' : fData(size)}
|
---|
99 | secondaryTypographyProps={{
|
---|
100 | component: 'span',
|
---|
101 | typography: 'caption',
|
---|
102 | }}
|
---|
103 | />
|
---|
104 |
|
---|
105 | {onRemove && (
|
---|
106 | <IconButton size="small" onClick={() => onRemove(file)}>
|
---|
107 | <Iconify icon="mingcute:close-line" width={16} />
|
---|
108 | </IconButton>
|
---|
109 | )}
|
---|
110 | </Stack>
|
---|
111 | );
|
---|
112 | })}
|
---|
113 | </AnimatePresence>
|
---|
114 | );
|
---|
115 | }
|
---|