-
Notifications
You must be signed in to change notification settings - Fork 0
/
ModalCropper.js
125 lines (117 loc) · 2.79 KB
/
ModalCropper.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
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
import React, { useState } from "react";
import CloseIcon from "@material-ui/icons/Close";
import Slider from "@material-ui/core/Slider";
import Cropper from "react-easy-crop";
import Button from "@material-ui/core/Button";
import styled from "styled-components";
export const ModalCropper = ({
onClickClose,
onCropComplete,
src,
showCroppedImage,
}) => {
const [crop, setCrop] = useState({ x: 0, y: 0 });
const [zoom, setZoom] = useState(1);
return (
<ModalCropperWrap>
<ModalCropperInner>
<CloseIcon onClick={onClickClose} />
<div className="cropper-wrap">
<Cropper
image={src}
crop={crop}
zoom={zoom}
aspect={1}
cropShape="round"
onCropChange={setCrop}
onCropComplete={onCropComplete}
onZoomChange={setZoom}
/>
</div>
<div className="slider-wrap">
<Slider
value={zoom}
min={1}
max={3}
step={0.1}
aria-labelledby="Zoom"
onChange={(e, zoom) => setZoom(zoom)}
classes={{ root: "slider" }}
/>
</div>
<Button
className="cropper-ok"
variant="contained"
onClick={showCroppedImage}
>
OK
</Button>
</ModalCropperInner>
</ModalCropperWrap>
);
};
const ModalCropperWrap = styled.div`
z-index: 6;
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-color: rgba(0, 0, 0, 0.5);
display: flex;
align-items: center;
justify-content: center;
`;
const ModalCropperInner = styled.div`
z-index: 7;
height: 49.6vw; //87.5rem;
width: 40.2vw; //77.2rem;
border-radius: 3.4vw; //6.5rem;
background-color: #fff;
.MuiSvgIcon-root {
font-size: 2.6vw; //5rem;
margin: 2.1vw 2.86vw 0 0; //4rem 5.5rem 0 0;
float: right;
cursor: pointer;
color: #EF4565;
}
.cropper-wrap {
position: relative;
height: 25.62vw; //49.2rem;
width: 25.62vw; //49.2rem;
margin: 6.25vw auto 2.38vw; //12rem auto 4.57rem;
.reactEasyCrop_Container {
height: 100%;
width: 100%;
object-fit: contain;
img {
height: 26vw; //50rem;
}
div {
height: 100%;
width: 100%;
}
}
}
.slider-wrap {
width: 50%;
margin: 0 auto;
}
.cropper-ok {
display: block;
margin: 2.4vw auto 0; //4.6rem auto 0;
background-color: #ef4565;
color: #fff;
font-size: 1.8vw; //3.5rem;
border-radius: 0.62vw; //1.2rem;
width: 11.4vw; //21.9rem;
height: 3.9vw; //7.5rem;
font-family: "ヒラギノ丸ゴ ProN";
font-weight: normal;
line-height: 3.1vw; //6rem;
:hover {
background-color: #dc004e;
}
}
}
`;