Skip to content

Commit dc82384

Browse files
committed
refactor: fix type error in image-crop.tsx
Close #15
1 parent 79a334c commit dc82384

File tree

1 file changed

+12
-16
lines changed

1 file changed

+12
-16
lines changed

src/main/resources/META-INF/resources/frontend/src/image-crop.tsx

+12-16
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
import { ReactAdapterElement, RenderHooks } from 'Frontend/generated/flow/ReactAdapter';
2222
import { JSXElementConstructor, ReactElement, useRef } from "react";
2323
import React from 'react';
24-
import { type Crop, ReactCrop, PixelCrop, makeAspectCrop, centerCrop } from "react-image-crop";
24+
import { type Crop, ReactCrop, PixelCrop, PercentCrop, makeAspectCrop, centerCrop } from "react-image-crop";
2525

2626
class ImageCropElement extends ReactAdapterElement {
2727

@@ -45,23 +45,19 @@ class ImageCropElement extends ReactAdapterElement {
4545
const onImageLoad = () => {
4646
if (imgRef.current && crop) {
4747
const { width, height } = imgRef.current;
48-
const newcrop = centerCrop(
49-
makeAspectCrop(
50-
{
51-
unit: crop.unit,
52-
width: crop.width,
53-
height: crop.height,
54-
x: crop.x,
55-
y: crop.y
56-
},
57-
aspect,
48+
if (crop.unit==='px') {
49+
setCrop(centerCrop(
50+
makeAspectCrop(crop as PixelCrop, aspect, width, height),
5851
width,
5952
height
60-
),
61-
width,
62-
height
63-
)
64-
setCrop(newcrop);
53+
));
54+
} else if (crop.unit==='%') {
55+
setCrop(centerCrop(
56+
makeAspectCrop(crop as PercentCrop, aspect, width, height),
57+
width,
58+
height
59+
));
60+
}
6561
}
6662
};
6763

0 commit comments

Comments
 (0)