px-react-ui-components 1.0.1 → 1.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +13 -1
- package/.babelrc +0 -3
- package/src/components/MyAlert/MyAlert.css +0 -113
- package/src/components/MyAlert/MyAlert.jsx +0 -96
- package/src/components/MyContainer/MyContainer.jsx +0 -90
- package/src/components/MyContainer/MyContainer.module.css +0 -110
- package/src/components/MyContainer/MyContainerBody.jsx +0 -8
- package/src/components/MyContainer/MyContainerFooter.jsx +0 -8
- package/src/components/MyContainer/MyContainerRight.jsx +0 -11
- package/src/components/MyEditor/MyEditor.jsx +0 -252
- package/src/components/MyEditor/MyEditor.scss +0 -277
- package/src/components/MyFileUpload/MyFileUpload.jsx +0 -371
- package/src/components/MyFileUpload/MyFileUpload.module.css +0 -86
- package/src/components/MyImageCropper/MyImageCropper.jsx +0 -108
- package/src/components/MyInput/MyInput.jsx +0 -895
- package/src/components/MyInput/MyInput.module.css +0 -420
- package/src/components/MyMaps/YandexMaps.jsx +0 -186
- package/src/components/MyMenu/MenuItem.jsx +0 -62
- package/src/components/MyMenu/MyMenu.module.css +0 -102
- package/src/components/MyModal/MyModal.css +0 -83
- package/src/components/MyModal/MyModal.jsx +0 -78
- package/src/components/MyModal/MyModalBody.jsx +0 -8
- package/src/components/MyModal/MyModalFooter.jsx +0 -8
- package/src/components/MyNotFound/MyNotFound.css +0 -22
- package/src/components/MyNotFound/MyNotFound.jsx +0 -11
- package/src/components/MyScrollableCard/MyScrollableCard.jsx +0 -86
- package/src/components/MyTable/MyTable.jsx +0 -459
- package/src/components/MyTable/MyTable.module.css +0 -350
- package/src/components/MyTable/MyTableBody.jsx +0 -8
- package/src/components/MyTable/MyTableHead.jsx +0 -10
- package/src/components/MyTabs/MyTabPane.jsx +0 -9
- package/src/components/MyTabs/MyTabs.css +0 -105
- package/src/components/MyTabs/MyTabs.jsx +0 -63
- package/src/components/MyWaiting/MyWaiting.css +0 -28
- package/src/components/MyWaiting/MyWaiting.jsx +0 -27
- package/src/components/MyZoomImage/MyZoomImage.css +0 -0
- package/src/components/MyZoomImage/MyZoomImage.jsx +0 -139
- package/src/index.js +0 -15
|
@@ -1,371 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useState, useRef } from "react";
|
|
2
|
-
import { PiCamera, PiFileArrowUpLight } from "react-icons/pi";
|
|
3
|
-
import Resizer from "react-image-file-resizer";
|
|
4
|
-
import Camera, { FACING_MODES, IMAGE_TYPES } from "react-html5-camera-photo";
|
|
5
|
-
import "react-html5-camera-photo/build/css/index.css";
|
|
6
|
-
import MyWaiting from "../MyWaiting/MyWaiting";
|
|
7
|
-
import { MyAlert, MyAlertType } from "../MyAlert/MyAlert";
|
|
8
|
-
import styles from "./MyFileUpload.module.css"
|
|
9
|
-
import MyModal from "../MyModal/MyModal";
|
|
10
|
-
import { MdOutlineAttachFile } from "react-icons/md";
|
|
11
|
-
|
|
12
|
-
export const AcceptType = {
|
|
13
|
-
ALL: "all",
|
|
14
|
-
FILE: "file",
|
|
15
|
-
IMAGE: "image",
|
|
16
|
-
MEDIA: "media",
|
|
17
|
-
PDF: "pdf",
|
|
18
|
-
IMAGEPDF: "imagepdf",
|
|
19
|
-
};
|
|
20
|
-
|
|
21
|
-
Object.freeze(MyAlertType);
|
|
22
|
-
|
|
23
|
-
export default function MyFileUpload({
|
|
24
|
-
multiple = false,
|
|
25
|
-
accept = AcceptType.ALL,
|
|
26
|
-
className = null,
|
|
27
|
-
camera = true,
|
|
28
|
-
maxSizeMB = 50,
|
|
29
|
-
onData,
|
|
30
|
-
}) {
|
|
31
|
-
|
|
32
|
-
const [loading, setLoading] = useState(false);
|
|
33
|
-
const [accepttypes, setAccepttypes] = useState(AcceptType.ALL);
|
|
34
|
-
const [acceptlabel, setAcceptlabel] = useState(AcceptType.ALL);
|
|
35
|
-
const [cameraopen, setCameraopen] = useState(false);
|
|
36
|
-
const [cameraopened, setCameraopened] = useState(false);
|
|
37
|
-
const [devices, setDevices] = useState([]);
|
|
38
|
-
const [selectedDeviceId, setSelectedDeviceId] = useState("");
|
|
39
|
-
|
|
40
|
-
const fileInputRef = useRef(null);
|
|
41
|
-
|
|
42
|
-
let type_files = ".pdf,.rar,.zip,.doc,.docx,.xls,.xlsx,.ppt,.pptx,msword,msexcel,vnd.ms-excel,vnd.openxmlformats-officedocument.spreadsheetml.sheet,vnd.openxmlformats-officedocument.wordprocessingml.document";
|
|
43
|
-
let type_image = ".jpg,.jpeg,.png";
|
|
44
|
-
let type_media = ".mp3,.mp4,.avi,.wav";
|
|
45
|
-
|
|
46
|
-
useEffect(() => {
|
|
47
|
-
switch (accept) {
|
|
48
|
-
case AcceptType.ALL:
|
|
49
|
-
setAccepttypes(
|
|
50
|
-
type_files + "," + type_image + "," + type_media
|
|
51
|
-
);
|
|
52
|
-
setAcceptlabel("PNG, JPG, PDF, RAR, ZIP, MP3, MP4, AVI, WAV, Word-Excel");
|
|
53
|
-
break;
|
|
54
|
-
case AcceptType.IMAGE:
|
|
55
|
-
setAccepttypes(type_image);
|
|
56
|
-
setAcceptlabel("PNG, JPG ");
|
|
57
|
-
break;
|
|
58
|
-
case AcceptType.MEDIA:
|
|
59
|
-
setAccepttypes(type_media);
|
|
60
|
-
setAcceptlabel("MP3, MP4, AVI, WAV");
|
|
61
|
-
break;
|
|
62
|
-
case AcceptType.FILE:
|
|
63
|
-
setAccepttypes(type_files + "," + type_image);
|
|
64
|
-
setAcceptlabel("PDF, RAR, ZIP, PNG, JPG, Word-Excel "
|
|
65
|
-
);
|
|
66
|
-
break;
|
|
67
|
-
case AcceptType.PDF:
|
|
68
|
-
setAccepttypes(".pdf");
|
|
69
|
-
setAcceptlabel("PDF");
|
|
70
|
-
break;
|
|
71
|
-
case AcceptType.IMAGEPDF:
|
|
72
|
-
setAccepttypes(type_image + ",.pdf");
|
|
73
|
-
setAcceptlabel("PNG, JPG, PDF");
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
navigator.mediaDevices.enumerateDevices().then((deviceInfos) => {
|
|
78
|
-
const videoDevices = deviceInfos.filter(
|
|
79
|
-
(device) => device.kind === "videoinput"
|
|
80
|
-
);
|
|
81
|
-
setDevices(videoDevices);
|
|
82
|
-
if (videoDevices.length > 0) {
|
|
83
|
-
setSelectedDeviceId(videoDevices[0].deviceId); // İlk kamerayı varsayılan olarak seç
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
}, []);
|
|
87
|
-
|
|
88
|
-
const responseData = (resdata, _error) => {
|
|
89
|
-
if (_error.length > 0) {
|
|
90
|
-
let message = _error.map((e, i) => {
|
|
91
|
-
return (
|
|
92
|
-
i +
|
|
93
|
-
1 +
|
|
94
|
-
".) <b><i>" +
|
|
95
|
-
e.filename +
|
|
96
|
-
"</i></b><br/>---- " +
|
|
97
|
-
e.message +
|
|
98
|
-
"<br/>"
|
|
99
|
-
);
|
|
100
|
-
});
|
|
101
|
-
|
|
102
|
-
MyAlert(
|
|
103
|
-
"<br/><br/><div style='display: block;font-size:13px;width: 100%;text-align: left;'>" +
|
|
104
|
-
message +
|
|
105
|
-
"</div>",
|
|
106
|
-
MyAlertType.WARNING
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
if (onData && (
|
|
111
|
-
(Array.isArray(resdata) && resdata.length > 0) ||
|
|
112
|
-
(!Array.isArray(resdata) && resdata)
|
|
113
|
-
)
|
|
114
|
-
)
|
|
115
|
-
onData(resdata);
|
|
116
|
-
|
|
117
|
-
setLoading(false);
|
|
118
|
-
};
|
|
119
|
-
|
|
120
|
-
const getBase64 = (files, callback = null) => {
|
|
121
|
-
let response_files = [];
|
|
122
|
-
let _error = [];
|
|
123
|
-
let fileReaderCalc = 0;
|
|
124
|
-
|
|
125
|
-
setLoading(true);
|
|
126
|
-
|
|
127
|
-
for (let i = 0; i < files.length; i++) {
|
|
128
|
-
const file = files[i];
|
|
129
|
-
let filesize = parseInt(file.size) / 1024 / 1024; //MB
|
|
130
|
-
|
|
131
|
-
let file_ext = file.type.split("/");
|
|
132
|
-
file_ext = file_ext[file_ext.length - 1];
|
|
133
|
-
|
|
134
|
-
if (filesize > maxSizeMB || accepttypes.indexOf(file_ext) == -1) {
|
|
135
|
-
if (filesize > maxSizeMB) {
|
|
136
|
-
_error.push({
|
|
137
|
-
filename: file.name,
|
|
138
|
-
// message: "Boyutu Max. Dosya Boyutundan büyük olamaz!" + ` <b>${maxSizeMB}MB</b>`,
|
|
139
|
-
message: "Size cannot be larger than Max. File Size!" + ` <b>${maxSizeMB}MB</b>`,
|
|
140
|
-
});
|
|
141
|
-
} else {
|
|
142
|
-
_error.push({
|
|
143
|
-
filename: file.name,
|
|
144
|
-
// message: t("Dosya türü desteklenmiyor!") + ` <b>${file_ext}</b>`,
|
|
145
|
-
message: "File type not supported!" + ` <b>${file_ext}</b>`,
|
|
146
|
-
});
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
if (files.length == i + 1 && response_files.length == 0) {
|
|
150
|
-
responseData(response_files, _error);
|
|
151
|
-
|
|
152
|
-
if (callback) {
|
|
153
|
-
callback();
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
continue;
|
|
158
|
-
}
|
|
159
|
-
|
|
160
|
-
let extension_type = type_image.indexOf(file_ext) > -1 ? "image" : "file";
|
|
161
|
-
|
|
162
|
-
if (extension_type == "file") {
|
|
163
|
-
const reader = new FileReader();
|
|
164
|
-
reader.onload = function() {
|
|
165
|
-
let fileitem = {
|
|
166
|
-
base64: reader.result,
|
|
167
|
-
extension: file_ext,
|
|
168
|
-
extension_type: type_image.indexOf(file_ext) > -1 ? "image" : "file",
|
|
169
|
-
file: file,
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
if (!multiple) {
|
|
173
|
-
response_files = fileitem;
|
|
174
|
-
} else {
|
|
175
|
-
response_files.push(fileitem);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
fileReaderCalc++;
|
|
179
|
-
if (files.length == fileReaderCalc) {
|
|
180
|
-
responseData(response_files, _error);
|
|
181
|
-
|
|
182
|
-
if (callback) {
|
|
183
|
-
callback();
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
reader.readAsDataURL(file);
|
|
188
|
-
} else {
|
|
189
|
-
let reader_param = {
|
|
190
|
-
file: file,
|
|
191
|
-
index: i,
|
|
192
|
-
ext: file_ext,
|
|
193
|
-
type_image: type_image,
|
|
194
|
-
};
|
|
195
|
-
|
|
196
|
-
Resizer.imageFileResizer(
|
|
197
|
-
file,
|
|
198
|
-
2600,
|
|
199
|
-
2600,
|
|
200
|
-
"JPEG",
|
|
201
|
-
100,
|
|
202
|
-
0,
|
|
203
|
-
(uri) => {
|
|
204
|
-
fileReaderCalc++;
|
|
205
|
-
|
|
206
|
-
let fileitem = {
|
|
207
|
-
base64: uri,
|
|
208
|
-
extension: reader_param.ext,
|
|
209
|
-
extension_type:
|
|
210
|
-
reader_param.type_image.indexOf(reader_param.ext) >
|
|
211
|
-
-1
|
|
212
|
-
? "image"
|
|
213
|
-
: "file",
|
|
214
|
-
file: reader_param.file,
|
|
215
|
-
};
|
|
216
|
-
|
|
217
|
-
if (!multiple) {
|
|
218
|
-
response_files = fileitem;
|
|
219
|
-
} else {
|
|
220
|
-
response_files.push(fileitem);
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
if (files.length == fileReaderCalc) {
|
|
224
|
-
responseData(response_files, _error);
|
|
225
|
-
|
|
226
|
-
if (callback) {
|
|
227
|
-
callback();
|
|
228
|
-
}
|
|
229
|
-
}
|
|
230
|
-
},
|
|
231
|
-
"base64"
|
|
232
|
-
);
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
// responseData(response_files, _error);
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
useEffect(() => {
|
|
240
|
-
if (!cameraopen) {
|
|
241
|
-
setCameraopened(false);
|
|
242
|
-
}
|
|
243
|
-
}, [cameraopen]);
|
|
244
|
-
|
|
245
|
-
const handleFileInputChange = (e) => {
|
|
246
|
-
getBase64(e.target.files, () => {
|
|
247
|
-
if (fileInputRef.current) {
|
|
248
|
-
fileInputRef.current.value = '';
|
|
249
|
-
fileInputRef.current.files = null;
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
};
|
|
253
|
-
|
|
254
|
-
const handleDeviceChange = (event) => {
|
|
255
|
-
setSelectedDeviceId(event.target.value);
|
|
256
|
-
};
|
|
257
|
-
const handleTakePhoto = (dataUri) => {
|
|
258
|
-
let fileitem = {
|
|
259
|
-
base64: dataUri,
|
|
260
|
-
extension: "jpg",
|
|
261
|
-
extension_type: "image",
|
|
262
|
-
file: "",
|
|
263
|
-
};
|
|
264
|
-
|
|
265
|
-
responseData([fileitem], []);
|
|
266
|
-
|
|
267
|
-
setCameraopened(false);
|
|
268
|
-
setCameraopen(false);
|
|
269
|
-
};
|
|
270
|
-
|
|
271
|
-
const handleCameraError = () => {
|
|
272
|
-
// setCameraopened(false);
|
|
273
|
-
// setCameraopen(false);
|
|
274
|
-
};
|
|
275
|
-
|
|
276
|
-
const handleCameraStart = (stream) => {
|
|
277
|
-
setCameraopened(true);
|
|
278
|
-
};
|
|
279
|
-
|
|
280
|
-
const handleCameraStop = () => {
|
|
281
|
-
// setCameraopened(false);
|
|
282
|
-
};
|
|
283
|
-
|
|
284
|
-
return (
|
|
285
|
-
<>
|
|
286
|
-
<MyWaiting show={loading} message="" />
|
|
287
|
-
<div className={className}>
|
|
288
|
-
<div className={styles.myFileUploadContainer}>
|
|
289
|
-
<div className={styles.myFileUploadContainerItem}>
|
|
290
|
-
<div className={styles.myFileUploadContainerItemIcon}>
|
|
291
|
-
<PiFileArrowUpLight className={styles.Icon} />
|
|
292
|
-
<h2 className={styles.myFileUploadContainerItemIconText}>
|
|
293
|
-
{acceptlabel}
|
|
294
|
-
<br /> {maxSizeMB} MB
|
|
295
|
-
</h2>
|
|
296
|
-
</div>
|
|
297
|
-
<div className={styles.myFileUploadContainerItemFile}>
|
|
298
|
-
<input
|
|
299
|
-
type="file"
|
|
300
|
-
hidden
|
|
301
|
-
ref={fileInputRef}
|
|
302
|
-
onChange={handleFileInputChange}
|
|
303
|
-
multiple={multiple}
|
|
304
|
-
accept={accepttypes}
|
|
305
|
-
/>
|
|
306
|
-
<div
|
|
307
|
-
className={styles.myFileUploadButton}
|
|
308
|
-
onClick={() => fileInputRef.current.click()}
|
|
309
|
-
>
|
|
310
|
-
<MdOutlineAttachFile />
|
|
311
|
-
</div>
|
|
312
|
-
</div>
|
|
313
|
-
</div>
|
|
314
|
-
{camera && (
|
|
315
|
-
<div className={styles.myFileUploadContainerItem}>
|
|
316
|
-
<div className={styles.myFileUploadContainerItemIcon}>
|
|
317
|
-
<PiCamera className={styles.Icon} />
|
|
318
|
-
<div className={styles.myFileUploadContainerItemIconText}>
|
|
319
|
-
<span>
|
|
320
|
-
{/* {t("Kameradan fotoğraf çekebilirsin.")} */}
|
|
321
|
-
You can take a photo from the camera.
|
|
322
|
-
</span>
|
|
323
|
-
</div>
|
|
324
|
-
</div>
|
|
325
|
-
<div className={styles.myFileUploadContainerItemFile}>
|
|
326
|
-
<button
|
|
327
|
-
type="button"
|
|
328
|
-
className={styles.myFileUploadButton}
|
|
329
|
-
onClick={() => setCameraopen(true)}
|
|
330
|
-
>
|
|
331
|
-
<PiCamera />
|
|
332
|
-
</button>
|
|
333
|
-
</div>
|
|
334
|
-
</div>
|
|
335
|
-
)}
|
|
336
|
-
</div>
|
|
337
|
-
</div>
|
|
338
|
-
<MyModal show={cameraopen} onClose={() => setCameraopen(false)} title={t("Fotoğraf Çek")} closeOnEsc={false} closeOnBackdropClick={false} >
|
|
339
|
-
<div>
|
|
340
|
-
<Camera
|
|
341
|
-
videoConstraints={{
|
|
342
|
-
deviceId: selectedDeviceId
|
|
343
|
-
? { exact: selectedDeviceId }
|
|
344
|
-
: undefined,
|
|
345
|
-
}}
|
|
346
|
-
onTakePhoto={(dataUri) => {
|
|
347
|
-
console.log(dataUri);
|
|
348
|
-
handleTakePhoto(dataUri);
|
|
349
|
-
}}
|
|
350
|
-
onCameraError={handleCameraError}
|
|
351
|
-
onCameraStart={(stream) => {
|
|
352
|
-
handleCameraStart(stream);
|
|
353
|
-
}}
|
|
354
|
-
onCameraStop={() => {
|
|
355
|
-
handleCameraStop();
|
|
356
|
-
}}
|
|
357
|
-
idealFacingMode={FACING_MODES.ENVIRONMENT}
|
|
358
|
-
idealResolution={{ width: 1024, height: 1024 }}
|
|
359
|
-
imageType={IMAGE_TYPES.JPG}
|
|
360
|
-
isMaxResolution={true}
|
|
361
|
-
isImageMirror={false}
|
|
362
|
-
isSilentMode={false}
|
|
363
|
-
isDisplayStartCameraError={true}
|
|
364
|
-
isFullscreen={false}
|
|
365
|
-
sizeFactor={1}
|
|
366
|
-
/>
|
|
367
|
-
</div>
|
|
368
|
-
</MyModal>
|
|
369
|
-
</>
|
|
370
|
-
);
|
|
371
|
-
}
|
|
@@ -1,86 +0,0 @@
|
|
|
1
|
-
.myFileUploadContainer {
|
|
2
|
-
display: flex;
|
|
3
|
-
width: 100%;
|
|
4
|
-
flex-direction: row;
|
|
5
|
-
gap: 5px;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
.myFileUploadContainer .myFileUploadContainerItem {
|
|
9
|
-
width: 100%;
|
|
10
|
-
padding: 5px;
|
|
11
|
-
background-color: #f0f0f0;
|
|
12
|
-
border-radius: 5px;
|
|
13
|
-
border: 1px dashed #ccc;
|
|
14
|
-
display: flex;
|
|
15
|
-
flex-direction: row;
|
|
16
|
-
justify-content: center;
|
|
17
|
-
align-items: center;
|
|
18
|
-
gap: 3px;
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.myFileUploadContainer
|
|
22
|
-
.myFileUploadContainerItem
|
|
23
|
-
.myFileUploadContainerItemIcon {
|
|
24
|
-
display: flex;
|
|
25
|
-
width: 100%;
|
|
26
|
-
|
|
27
|
-
flex-direction: row;
|
|
28
|
-
justify-content: center;
|
|
29
|
-
align-items: center;
|
|
30
|
-
gap: 1px;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
.myFileUploadContainer
|
|
34
|
-
.myFileUploadContainerItem
|
|
35
|
-
.myFileUploadContainerItemIcon
|
|
36
|
-
.Icon {
|
|
37
|
-
font-size: 35px;
|
|
38
|
-
color: #17305b;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
.myFileUploadContainer
|
|
42
|
-
.myFileUploadContainerItem
|
|
43
|
-
.myFileUploadContainerItemIcon
|
|
44
|
-
.myFileUploadContainerItemIconText {
|
|
45
|
-
width: 100%;
|
|
46
|
-
|
|
47
|
-
text-align: center;
|
|
48
|
-
font-weight: normal;
|
|
49
|
-
color: #636363;
|
|
50
|
-
font-size: 12px;
|
|
51
|
-
line-height: 1.3;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
.myFileUploadContainer
|
|
55
|
-
.myFileUploadContainerItem
|
|
56
|
-
.myFileUploadContainerItemFile {
|
|
57
|
-
display: flex;
|
|
58
|
-
flex-direction: row;
|
|
59
|
-
justify-content: center;
|
|
60
|
-
align-items: center;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
.myFileUploadContainer
|
|
64
|
-
.myFileUploadContainerItem
|
|
65
|
-
.myFileUploadContainerItemFile
|
|
66
|
-
.myFileUploadButton {
|
|
67
|
-
display: flex;
|
|
68
|
-
width: 200px;
|
|
69
|
-
height: 35px;
|
|
70
|
-
flex-direction: column;
|
|
71
|
-
align-items: center;
|
|
72
|
-
justify-content: center;
|
|
73
|
-
gap: 10px;
|
|
74
|
-
flex-shrink: 0;
|
|
75
|
-
background-color: #334f7f;
|
|
76
|
-
color: #fff;
|
|
77
|
-
border-radius: 15px;
|
|
78
|
-
cursor: pointer;
|
|
79
|
-
font-size: 13px;
|
|
80
|
-
}
|
|
81
|
-
.myFileUploadContainer
|
|
82
|
-
.myFileUploadContainerItem
|
|
83
|
-
.myFileUploadContainerItemFile
|
|
84
|
-
.myFileUploadButton:hover {
|
|
85
|
-
background-color: #2a436a;
|
|
86
|
-
}
|
|
@@ -1,108 +0,0 @@
|
|
|
1
|
-
import React, { useState } from "react";
|
|
2
|
-
import ReactCrop from "react-image-crop";
|
|
3
|
-
import "react-image-crop/dist/ReactCrop.css";
|
|
4
|
-
import MyImageZoom from "../MyZoomImage/MyZoomImage";
|
|
5
|
-
|
|
6
|
-
const MyImageCropper = ({ image, style = null, onChange = null }) => {
|
|
7
|
-
const [crop, setCrop] = useState({
|
|
8
|
-
x: 0,
|
|
9
|
-
y: 0,
|
|
10
|
-
width: 0,
|
|
11
|
-
height: 0,
|
|
12
|
-
aspect: 1,
|
|
13
|
-
});
|
|
14
|
-
// const [croppedImageUrl, setCroppedImageUrl] = useState(null);
|
|
15
|
-
const [imageRef, setImageRef] = useState(null);
|
|
16
|
-
const [zoom, setZoom] = useState({ scale: 1, positionX: 0, positionY: 0 }); // Zoom seviyesini saklamak için state
|
|
17
|
-
const [scaleFactor, setScaleFactor] = useState(1.5);
|
|
18
|
-
|
|
19
|
-
// Görüntü yüklendiğinde çağrılır
|
|
20
|
-
const handleImageLoad = (e) => {
|
|
21
|
-
setImageRef(e.currentTarget); // HTMLImageElement olarak kaydediyoruz
|
|
22
|
-
};
|
|
23
|
-
|
|
24
|
-
// Zoom değiştiğinde çağrılır
|
|
25
|
-
const handleZoomChange = (newZoom) => {
|
|
26
|
-
setZoom(newZoom);
|
|
27
|
-
setScaleFactor(newZoom.scale * 3);
|
|
28
|
-
};
|
|
29
|
-
|
|
30
|
-
// Kırpma tamamlandığında çağrılır
|
|
31
|
-
const onCropComplete = (newCrop) => {
|
|
32
|
-
if (imageRef && newCrop.width && newCrop.height) {
|
|
33
|
-
// Zoom oranını kullanarak yeni koordinatlar hesapla
|
|
34
|
-
const adjustedCrop = {
|
|
35
|
-
...newCrop,
|
|
36
|
-
x: (newCrop.x - zoom.positionX) / zoom.scale,
|
|
37
|
-
y: (newCrop.y - zoom.positionY) / zoom.scale,
|
|
38
|
-
width: newCrop.width / zoom.scale,
|
|
39
|
-
height: newCrop.height / zoom.scale,
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
generateCroppedImage(imageRef, adjustedCrop);
|
|
43
|
-
}
|
|
44
|
-
};
|
|
45
|
-
|
|
46
|
-
// Kırpılmış görseli base64 formatında almak için
|
|
47
|
-
const generateCroppedImage = (image, crop) => {
|
|
48
|
-
if (!crop || !crop.width || !crop.height || crop.width === 0) {
|
|
49
|
-
console.warn("Geçersiz kırpma ölçüleri");
|
|
50
|
-
return;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
const canvas = document.createElement("canvas");
|
|
54
|
-
const scaleX = image.naturalWidth / image.width;
|
|
55
|
-
const scaleY = image.naturalHeight / image.height;
|
|
56
|
-
|
|
57
|
-
// Kesim boyutlarını scaleFactor ile çarp
|
|
58
|
-
const outputWidth = crop.width * scaleFactor;
|
|
59
|
-
const outputHeight = crop.height * scaleFactor;
|
|
60
|
-
|
|
61
|
-
canvas.width = outputWidth;
|
|
62
|
-
canvas.height = outputHeight;
|
|
63
|
-
const ctx = canvas.getContext("2d");
|
|
64
|
-
|
|
65
|
-
ctx.drawImage(
|
|
66
|
-
image,
|
|
67
|
-
crop.x * scaleX,
|
|
68
|
-
crop.y * scaleY,
|
|
69
|
-
crop.width * scaleX,
|
|
70
|
-
crop.height * scaleY,
|
|
71
|
-
0,
|
|
72
|
-
0,
|
|
73
|
-
outputWidth,
|
|
74
|
-
outputHeight // Büyütülmüş boyutlar
|
|
75
|
-
);
|
|
76
|
-
|
|
77
|
-
const base64Image = canvas.toDataURL("image/jpeg");
|
|
78
|
-
// setCroppedImageUrl(base64Image);
|
|
79
|
-
|
|
80
|
-
if (onChange) {
|
|
81
|
-
onChange({ value: base64Image });
|
|
82
|
-
}
|
|
83
|
-
};
|
|
84
|
-
|
|
85
|
-
return (
|
|
86
|
-
<div style={style}>
|
|
87
|
-
{image && (
|
|
88
|
-
<ReactCrop
|
|
89
|
-
crop={crop}
|
|
90
|
-
onComplete={onCropComplete}
|
|
91
|
-
onChange={(newCrop) => setCrop(newCrop)}
|
|
92
|
-
style={style}
|
|
93
|
-
>
|
|
94
|
-
<MyImageZoom onZoomChange={handleZoomChange}>
|
|
95
|
-
<img
|
|
96
|
-
src={image}
|
|
97
|
-
alt="Crop preview"
|
|
98
|
-
onLoad={handleImageLoad}
|
|
99
|
-
className="rounded-e-md"
|
|
100
|
-
/>
|
|
101
|
-
</MyImageZoom>
|
|
102
|
-
</ReactCrop>
|
|
103
|
-
)}
|
|
104
|
-
</div>
|
|
105
|
-
);
|
|
106
|
-
};
|
|
107
|
-
|
|
108
|
-
export default MyImageCropper;
|