Skip to content

Commit

Permalink
refactor: fix type error in image-crop.tsx
Browse files Browse the repository at this point in the history
Close #15
  • Loading branch information
javier-godoy committed Feb 13, 2025
1 parent 79a334c commit 3b4b66f
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions src/main/resources/META-INF/resources/frontend/src/image-crop.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import { ReactAdapterElement, RenderHooks } from 'Frontend/generated/flow/ReactAdapter';
import { JSXElementConstructor, ReactElement, useRef } from "react";
import React from 'react';
import { type Crop, ReactCrop, PixelCrop, makeAspectCrop, centerCrop } from "react-image-crop";
import { type Crop, ReactCrop, PixelCrop, PercentCrop, makeAspectCrop, centerCrop } from "react-image-crop";

class ImageCropElement extends ReactAdapterElement {

Expand All @@ -45,23 +45,19 @@ class ImageCropElement extends ReactAdapterElement {
const onImageLoad = () => {
if (imgRef.current && crop) {
const { width, height } = imgRef.current;
const newcrop = centerCrop(
makeAspectCrop(
{
unit: crop.unit,
width: crop.width,
height: crop.height,
x: crop.x,
y: crop.y
},
aspect,
if (crop.unit==='px') {
setCrop(centerCrop(
makeAspectCrop(crop as PixelCrop, aspect, width, height),
width,
height
),
width,
height
)
setCrop(newcrop);
));
} else if (crop.unit==='%') {
setCrop(centerCrop(
makeAspectCrop(crop as PercentCrop, aspect, width, height),
width,
height
));
}
}
};

Expand Down

0 comments on commit 3b4b66f

Please sign in to comment.