Skip to content

Commit

Permalink
Modified getDimensions to use getBoundingClientRect
Browse files Browse the repository at this point in the history
  • Loading branch information
paweljaspinski-tomtom committed Aug 18, 2021
1 parent fc090a8 commit b36c0e0
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 13 deletions.
5 changes: 3 additions & 2 deletions dist/ReactFlow.esm.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ReactFlow.esm.js.map

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions dist/ReactFlow.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/ReactFlow.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/utils/index.d.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { DraggableEvent } from 'react-draggable';
import { MouseEvent as ReactMouseEvent } from 'react';
import { DraggableEvent } from 'react-draggable';
import { Dimensions, XYPosition } from '../types';
export declare const isInputDOMNode: (e: ReactMouseEvent | DraggableEvent | KeyboardEvent) => boolean;
export declare const getDimensions: (node: HTMLDivElement) => Dimensions;
Expand Down
17 changes: 11 additions & 6 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { DraggableEvent } from 'react-draggable';
import { MouseEvent as ReactMouseEvent } from 'react';
import { DraggableEvent } from 'react-draggable';
import { Dimensions, NodeExtent, XYPosition } from '../types';

import { Dimensions, XYPosition, NodeExtent } from '../types';

export const isInputDOMNode = (e: ReactMouseEvent | DraggableEvent | KeyboardEvent) => {
const target = e?.target as HTMLElement;
Expand All @@ -11,10 +11,15 @@ export const isInputDOMNode = (e: ReactMouseEvent | DraggableEvent | KeyboardEve
);
};

export const getDimensions = (node: HTMLDivElement): Dimensions => ({
width: node.offsetWidth,
height: node.offsetHeight,
});
export const getDimensions = (node: HTMLDivElement): Dimensions => {
const rect = node.getBoundingClientRect();
return {width: rect.width, height: rect.height}
}
// ({
// width: node.offsetWidth,
// height: node.offsetHeight,
// })
;

export const clamp = (val: number, min: number = 0, max: number = 1): number => Math.min(Math.max(val, min), max);

Expand Down

0 comments on commit b36c0e0

Please sign in to comment.