Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add cropperProps option to specify additional props for cropper #593

Merged
merged 1 commit into from
Feb 25, 2025
Merged
Show file tree
Hide file tree
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,7 @@ See [#428](https://github.com/ValentinH/react-easy-crop/issues/428), [#409](http
| `style` | `{ containerStyle: object, mediaStyle: object, cropAreaStyle: object }` | | Custom styles to be used with the Cropper. Styles passed via the style prop are merged with the defaults. |
| `classes` | `{ containerClassName: string, mediaClassName: string, cropAreaClassName: string }` | | Custom class names to be used with the Cropper. Classes passed via the classes prop are merged with the defaults. If you have CSS specificity issues, you should probably use the `disableAutomaticStylesInjection` prop. |
| `mediaProps` | object | | The properties you want to apply to the media tag (<img /> or <video /> depending on your media) |
| `cropperProps` | object | | The properties you want to apply to the cropper. |
| `restrictPosition` | boolean | | Whether the position of the media should be restricted to the boundaries of the cropper. Useful setting in case of `zoom < 1` or if the cropper should preserve all media content while forcing a specific aspect ratio for media throughout the application. Example: https://codesandbox.io/s/1rmqky233q. |
| `initialCroppedAreaPercentages` | `{ width: number, height: number, x: number, y: number}` | | Use this to set the initial crop position/zoom of the cropper (for example, when editing a previously cropped media). The value should be the same as the `croppedArea` passed to [`onCropComplete`](#onCropCompleteProp). This is the preferred way of restoring the previously set crop because `croppedAreaPixels` is rounded, and when used for restoration, may result in a slight drifting crop/zoom |
| `initialCroppedAreaPixels` | `{ width: number, height: number, x: number, y: number}` | | Use this to set the initial crop position/zoom of the cropper (for example, when editing a previously cropped media). The value should be the same as the `croppedAreaPixels` passed to [`onCropComplete`](#onCropCompleteProp) Example: https://codesandbox.io/s/pmj19vp2yx. |
Expand Down
4 changes: 4 additions & 0 deletions src/Cropper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export type CropperProps = {
}
restrictPosition: boolean
mediaProps: React.ImgHTMLAttributes<HTMLElement> | React.VideoHTMLAttributes<HTMLElement>
cropperProps: React.HTMLAttributes<HTMLDivElement>
disableAutomaticStylesInjection?: boolean
initialCroppedAreaPixels?: Area
initialCroppedAreaPercentages?: Area
Expand Down Expand Up @@ -96,6 +97,7 @@ class Cropper extends React.Component<CropperProps, State> {
style: {},
classes: {},
mediaProps: {},
cropperProps: {},
zoomSpeed: 1,
restrictPosition: true,
zoomWithScroll: true,
Expand Down Expand Up @@ -801,6 +803,7 @@ class Cropper extends React.Component<CropperProps, State> {
image,
video,
mediaProps,
cropperProps,
transform,
crop: { x, y },
rotation,
Expand Down Expand Up @@ -890,6 +893,7 @@ class Cropper extends React.Component<CropperProps, State> {
showGrid && 'reactEasyCrop_CropAreaGrid',
cropAreaClassName
)}
{...cropperProps}
/>
)}
</div>
Expand Down