Skip to content

Commit

Permalink
fix events after drag bug
Browse files Browse the repository at this point in the history
  • Loading branch information
susielu committed Jan 26, 2019
1 parent 8f15a75 commit 0ec73ad
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 19 deletions.
2 changes: 1 addition & 1 deletion bundle.js

Large diffs are not rendered by default.

38 changes: 20 additions & 18 deletions src/components/Annotation.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
import React from "react";
import classnames from "./classnames";
import PropTypes from "prop-types";
import React from "react"
import classnames from "./classnames"
import PropTypes from "prop-types"

export default class Annotation extends React.Component {
render() {
const { x, y, nx, ny, events } = this.props;
const { x, y, nx, ny, events } = this.props

const cleanedProps = Object.assign({}, this.props);
delete cleanedProps.children;
const cleanedProps = Object.assign({}, this.props)
delete cleanedProps.children

const cleanedWithoutEvents = Object.assign({}, cleanedProps);
delete cleanedWithoutEvents.events;
const cleanedWithoutEvents = Object.assign({}, cleanedProps)
delete cleanedWithoutEvents.events

if (nx !== undefined) cleanedProps.dx = nx - x;
if (ny !== undefined) cleanedProps.dy = ny - y;
if (nx !== undefined) cleanedProps.dx = nx - x
if (ny !== undefined) cleanedProps.dy = ny - y

const childrenWithProps = React.Children.toArray(this.props.children).map(
child =>
Expand All @@ -24,21 +24,23 @@ export default class Annotation extends React.Component {

...child.props
})
);

)
const wrappedEvents = {}
Object.keys(events).forEach(k => {
events[k] = events[k].bind(this, this.props, this.state);
});
wrappedEvents[k] = e => {
events[k](this.props, this.state, e)
}
})

return (
<g
className={classnames("annotation", this.props.className)}
transform={`translate(${x}, ${y})`}
{...events}
{...wrappedEvents}
>
{childrenWithProps}
</g>
);
)
}
}

Expand All @@ -49,7 +51,7 @@ Annotation.defaultProps = {
dy: 0,
color: "grey",
events: {}
};
}

Annotation.propTypes = {
x: PropTypes.number,
Expand All @@ -59,4 +61,4 @@ Annotation.propTypes = {
color: PropTypes.string,
editMode: PropTypes.bool,
events: PropTypes.object
};
}

0 comments on commit 0ec73ad

Please sign in to comment.