Skip to content

Commit

Permalink
fix: filter out cropper props (#1077)
Browse files Browse the repository at this point in the history
  • Loading branch information
shekhar-shubhendu committed Mar 14, 2023
1 parent f0ebd92 commit 4a9955d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/react-cropper.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, {useEffect, useRef} from 'react';
import Cropper from 'cropperjs';
import {cleanImageProps} from './utils';

const REQUIRED_IMAGE_STYLES = {opacity: 0, maxWidth: '100%'};

Expand Down Expand Up @@ -121,7 +122,7 @@ const ReactCropper = React.forwardRef<ReactCropperElement | HTMLImageElement, Re
};
}, [combinedRef]);

const imageProps = React.useMemo(() => ({...rest, crossOrigin, src, alt}), [rest, crossOrigin, src, alt]);
const imageProps = cleanImageProps({...rest, crossOrigin, src, alt});

return (
<div style={style} className={className}>
Expand Down
53 changes: 53 additions & 0 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
interface CropperImageOptions extends Cropper.Options<HTMLImageElement> {
[key: string]: unknown;
}

type CropperKeys = keyof Cropper.Options;

const cropperProps: Array<CropperKeys> = [
'aspectRatio',
'autoCrop',
'autoCropArea',
'background',
'center',
'checkCrossOrigin',
'checkOrientation',
'cropBoxMovable',
'cropBoxResizable',
'data',
'dragMode',
'guides',
'highlight',
'initialAspectRatio',
'minCanvasHeight',
'minCanvasWidth',
'minContainerHeight',
'minContainerWidth',
'minCropBoxHeight',
'minCropBoxWidth',
'modal',
'movable',
'preview',
'responsive',
'restore',
'rotatable',
'scalable',
'toggleDragModeOnDblclick',
'viewMode',
'wheelZoomRatio',
'zoomOnTouch',
'zoomOnWheel',
'zoomable',
'cropstart',
'cropmove',
'cropend',
'crop',
'zoom',
'ready',
];

export const cleanImageProps = (imageProps: CropperImageOptions) =>
cropperProps.reduce((acc, key) => {
const {[key]: _, ...rest} = acc;
return rest;
}, imageProps);

0 comments on commit 4a9955d

Please sign in to comment.