1 | import React, { useMemo } from 'react';
|
2 | import PropTypes from 'prop-types';
|
3 | import { Table } from 'reactstrap';
|
4 | import FileRow from './FileRow';
|
5 |
|
6 | const FileList = ({ files, children, onRemoveFile, ...rest }) => {
|
7 | const list = useMemo(
|
8 | () =>
|
9 | files.map(file => (
|
10 | <FileRow key={file.id} file={file} onRemove={onRemoveFile}>
|
11 | {children}
|
12 | </FileRow>
|
13 | )),
|
14 | [files, children, onRemoveFile]
|
15 | );
|
16 |
|
17 | if (typeof children === 'function') {
|
18 | return list;
|
19 | }
|
20 |
|
21 | return files.length > 0 ? (
|
22 | <Table size="sm" hover style={{ tableLayout: 'fixed' }} {...rest}>
|
23 | <caption className="sr-only">List of files uploaded</caption>
|
24 | <thead>
|
25 | <tr>
|
26 | <th style={{ width: '10%', border: 0 }} scope="col">
|
27 | <span className="sr-only">File Icon</span>
|
28 | </th>
|
29 | <th style={{ width: '35%', border: 0 }} scope="col">
|
30 | <span className="sr-only">File Name</span>
|
31 | </th>
|
32 | <th style={{ width: '45%', border: 0 }} scope="col">
|
33 | <span className="sr-only">Upload Progress</span>
|
34 | </th>
|
35 | <th style={{ width: '10%', border: 0 }} scope="col">
|
36 | <span className="sr-only">File Actions</span>
|
37 | </th>
|
38 | </tr>
|
39 | </thead>
|
40 | <tbody className="w-100">{list}</tbody>
|
41 | </Table>
|
42 | ) : null;
|
43 | };
|
44 |
|
45 | FileList.propTypes = {
|
46 | files: PropTypes.array,
|
47 | children: PropTypes.func,
|
48 | onRemoveFile: PropTypes.func,
|
49 | };
|
50 |
|
51 | export default FileList;
|