-
-
Notifications
You must be signed in to change notification settings - Fork 223
Expand file tree
/
Copy pathindex.tsx
More file actions
62 lines (56 loc) · 2.19 KB
/
index.tsx
File metadata and controls
62 lines (56 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, { useState } from 'react';
import Box from '@cloudscape-design/components/box';
import SpaceBetween from '@cloudscape-design/components/space-between';
import StatusIndicator from '@cloudscape-design/components/status-indicator';
export interface IProps {
file: File;
showImage?: boolean;
truncateLength?: number;
i18nStrings?: {
numberOfBytes: (n: number) => string;
lastModified: (d: Date) => string;
};
}
export const FileEntry: React.FC<IProps> = ({ file, showImage = false, truncateLength = 20, i18nStrings }) => {
const [imageData, setImageData] = useState<string>();
const reader = new FileReader();
reader.onload = (event) => {
setImageData(event.target.result as string);
};
reader.readAsDataURL(file);
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
const ext = file.name.split('.').pop()!;
const displayFileName =
file.name.length - ext.length - 1 > truncateLength ? `${file.name.slice(0, truncateLength)}... .${ext}` : file.name;
const lastModifiedDate = new Date(file.lastModified);
const fileSize = file.size;
return (
<SpaceBetween size="s" direction="horizontal">
<StatusIndicator type="success" />
{showImage && (
<img
alt={file.name}
style={{
width: '5em',
height: '5em',
objectFit: 'cover',
}}
src={imageData}
/>
)}
<SpaceBetween size="xxxs">
<Box>{displayFileName}</Box>
{false && (
<>
<Box variant="small">{i18nStrings ? i18nStrings.numberOfBytes(fileSize) : `${fileSize} bytes`}</Box>
<Box variant="small">
{i18nStrings
? i18nStrings.lastModified(lastModifiedDate)
: `Last modified: ${lastModifiedDate.toDateString()}`}
</Box>
</>
)}
</SpaceBetween>
</SpaceBetween>
);
};