Skip to content

Commit

Permalink
feat: add maxSnapElementGapDistance prop #707
Browse files Browse the repository at this point in the history
  • Loading branch information
daybrush committed Aug 6, 2022
1 parent 176c1b3 commit 5f71c30
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export function getGapGuidelines(
) {
const {
maxSnapElementGuidelineDistance = Infinity,
maxSnapElementGapDistance = Infinity,
} = moveable.props;
const elementRects = moveable.state.elementRects;
const gapGuidelines: SnapGuideline[] = [];
Expand Down Expand Up @@ -196,6 +197,9 @@ export function getGapGuidelines(
if (!checkBetweenRects(targetRect, rect2, type, maxSnapElementGuidelineDistance)) {
return;
}
if (gap > maxSnapElementGapDistance) {
return;
}
gapGuidelines.push({
type,
pos: type === "vertical" ? [pos, 0] : [0, pos],
Expand Down
5 changes: 5 additions & 0 deletions packages/react-moveable/src/react-moveable/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2154,6 +2154,11 @@ export interface SnappableOptions {
* @default Infinity
*/
maxSnapElementGuidelineDistance?: number;
/**
* Maximum distance to which element gap guidelines can be snapped.
* @default Infinity
*/
maxSnapElementGapDistance?: number;
/**
* You can set up boundaries.
* @default null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ export default function App(props: Record<string, any>) {
"center": true,
"middle": true,
}}
maxSnapElementGuidelineDistance={props.maxSnapElementGuidelineDistance}
maxSnapElementGapDistance={props.maxSnapElementGapDistance}
onDrag={e => {
e.target.style.transform = e.transform;
}}
Expand Down

0 comments on commit 5f71c30

Please sign in to comment.