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

Remove unnecessary passing of excessive props #406

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
52 changes: 12 additions & 40 deletions packages/lib/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import React, {
type TouchEventHandler,
type CSSProperties,
type MouseEventHandler,
type AllHTMLAttributes,
} from 'react'

import { loadImageURL } from './utils/loadImageURL'
Expand Down Expand Up @@ -126,6 +127,8 @@ export interface Props {
disableBoundaryChecks?: boolean
disableHiDPIScaling?: boolean
disableCanvasRotation?: boolean
showGrid?: boolean
gridColor?: string
}

export interface Position {
Expand Down Expand Up @@ -688,54 +691,23 @@ class AvatarEditor extends React.Component<PropsWithDefaults, State> {
}

render() {
const {
scale,
rotate,
image,
border,
borderRadius,
width,
height,
position,
color,
backgroundColor,
style,
crossOrigin,
onLoadFailure,
onLoadSuccess,
onImageReady,
onImageChange,
onMouseUp,
onMouseMove,
onPositionChange,
disableBoundaryChecks,
disableHiDPIScaling,
disableCanvasRotation,
...rest
} = this.props

const dimensions = this.getDimensions()

const defaultStyle: CSSProperties = {
width: dimensions.canvas.width,
height: dimensions.canvas.height,
cursor: this.state.drag ? 'grabbing' : 'grab',
touchAction: 'none',
}

const attributes: JSX.IntrinsicElements['canvas'] = {
const attributes: AllHTMLAttributes<HTMLCanvasElement> = {
width: dimensions.canvas.width * this.pixelRatio,
height: dimensions.canvas.height * this.pixelRatio,
onMouseDown: this.handleMouseDown,
onTouchStart: this.handleTouchStart,
style: { ...defaultStyle, ...style },
style: {
width: dimensions.canvas.width,
height: dimensions.canvas.height,
cursor: this.state.drag ? 'grabbing' : 'grab',
touchAction: 'none',
...this.props.style,
},
}

return React.createElement('canvas', {
...attributes,
...rest,
ref: this.canvas,
})
return React.createElement('canvas', { ...attributes, ref: this.canvas })
}
}

Expand Down