Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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