Skip to content

Commit

Permalink
Remove unnecessary passing of excessive props
Browse files Browse the repository at this point in the history
  • Loading branch information
dan-lee committed Nov 27, 2023
1 parent f266ca3 commit c7d6db4
Showing 1 changed file with 14 additions and 42 deletions.
56 changes: 14 additions & 42 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 = {
width: dimensions.canvas.width * this.pixelRatio,
height: dimensions.canvas.height * this.pixelRatio,
onMouseDown: this.handleMouseDown,
onTouchStart: this.handleTouchStart,
style: { ...defaultStyle, ...style },
}

return React.createElement('canvas', {
...attributes,
...rest,
ref: this.canvas,
})
style: {
width: dimensions.canvas.width,
height: dimensions.canvas.height,
cursor: this.state.drag ? 'grabbing' : 'grab',
touchAction: 'none',
...this.props.style,
},
} satisfies AllHTMLAttributes<HTMLCanvasElement>

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

Expand Down

0 comments on commit c7d6db4

Please sign in to comment.