-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathApp.js
64 lines (55 loc) · 1.47 KB
/
App.js
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
63
64
import React, { useRef } from "react";
import { ImageCropper, HiddenCropper } from "react-bootstrap-image-cropper";
import "bootstrap/dist/css/bootstrap.min.css";
function App() {
return (
<div style={{ padding: 16 }}>
<ImageCropperDemo />
<hr />
<HiddenCropperDemo />
</div>
);
}
export default App;
function ImageCropperDemo() {
// if you don't care the onChange event, you can use a ref to retrieve the cropped file
const fileRef = useRef();
function handleChange(croppedFile) {
console.log(croppedFile);
console.log(fileRef.current);
// croppedFile === fileRef.current
}
return (
<div>
<h1>ImageCropper</h1>
<ImageCropper
fileRef={fileRef}
onChange={handleChange}
cropOptions={{ aspect: 4 / 3, maxZoom: 10 }}
outputOptions={{ maxWidth: 400, maxHeight: 300 }}
previewOptions={{ width: 400, height: 300 }}
/>
</div>
);
}
function HiddenCropperDemo() {
const triggerRef = useRef();
function handleCropped(file) {
console.log(file);
}
return (
<div>
<h1>HiddenCropper</h1>
<button onClick={() => triggerRef.current.trigger()}>
trigger hidden cropper
</button>
<HiddenCropper
triggerRef={triggerRef}
onCropped={handleCropped}
cropOptions={{ aspect: 4 / 3, maxZoom: 10 }}
outputOptions={{ maxWidth: 400, maxHeight: 300 }}
previewOptions={{ width: 400, height: 300 }}
/>
</div>
);
}