Skip to content
Open
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
10 changes: 10 additions & 0 deletions packages/visx-annotation/src/components/EditableAnnotation.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ export type EditableAnnotationProps = Pick<AnnotationContextType, 'x' | 'y' | 'd
onDragMove?: ({ x, y, dx, dy, event }: HandlerArgs) => void;
/** Callback invoked on drag end. */
onDragEnd?: ({ x, y, dx, dy, event }: HandlerArgs) => void;
/** Optional x/y desired bounds for subject/label. */
restrict?: {
xMin?: number;
xMax?: number;
yMin?: number;
yMax?: number;
};
};

export type HandlerArgs = {
Expand Down Expand Up @@ -58,6 +65,7 @@ export default function EditableAnnotation({
width,
x: subjectX = 0,
y: subjectY = 0,
restrict,
}: EditableAnnotationProps) {
// chicken before the egg, we need these to reference drag state
// in drag callbacks which are defined before useDrag() state is available
Expand Down Expand Up @@ -115,6 +123,7 @@ export default function EditableAnnotation({
onDragEnd: handleDragEnd,
x: subjectX,
y: subjectY,
restrict: restrict,
});

const labelDrag = useDrag({
Expand All @@ -123,6 +132,7 @@ export default function EditableAnnotation({
onDragEnd: handleDragEnd,
x: labelDx,
y: labelDy,
restrict: restrict,
});

// enable referencing these in the callbacks defined before useDrag is called
Expand Down