-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathImageInput.tsx
More file actions
52 lines (47 loc) · 1.12 KB
/
ImageInput.tsx
File metadata and controls
52 lines (47 loc) · 1.12 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
import FileInput from "./FileInput";
import { File } from "aws-sdk/lib/dynamodb/document_client";
export interface ImageInputProps {
style?: React.CSSProperties;
className?: string;
name?: string;
value?: string;
onChange: (v: File, fileName?: string) => void;
}
const ImageInput: React.FC<ImageInputProps> = ({
style,
className,
name,
value,
onChange,
}) => {
return (
<FileInput
value={value}
style={style}
className={className}
name={name}
accept="image/*"
onChange={async (file) => {
if (file) {
const config = {
quality: 0.7,
maxWidth: 1680,
maxHeight: 1680,
autoRotate: true,
};
const shouldResize = file.size > 512 * 1024;
const resizedFile = shouldResize
? await import("browser-image-resizer").then((r) =>
r.readAndCompressImage(file, config),
)
: file;
onChange(resizedFile, file.name);
} else {
onChange(null, null);
}
return;
}}
/>
);
};
export default ImageInput;