Skip to content

Commit a7c9c69

Browse files
committed
feat: add snap props
1 parent 8819639 commit a7c9c69

File tree

4 files changed

+62
-1
lines changed

4 files changed

+62
-1
lines changed

packages/ngx-moveable/projects/ngx-moveable/src/ngx-moveable.component.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ export class NgxMoveableComponent
5353
@Input() public edge!: boolean;
5454
@Input() public pinchThreshold!: number;
5555
@Input() public snapCenter!: boolean;
56+
@Input() public snapVertical!: boolean;
57+
@Input() public snapElement!: boolean;
58+
@Input() public snapHorizontal!: boolean;
5659
@Input() public snapThreshold!: number;
5760
@Input() public horizontalGuidelines!: number[];
5861
@Input() public verticalGuidelines!: number[];

src/Moveable.tsx

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,11 +364,58 @@ class Moveable extends EgComponent implements MoveableInterface {
364364
* @example
365365
* import Moveable from "moveable";
366366
*
367-
* const moveable = new Moveable(document.body);
367+
* const moveable = new Moveable(document.body, {
368+
* snappable: true,
369+
* });
368370
*
369371
* moveable.snapCenter = true;
370372
*/
371373

374+
/**
375+
* When you drag, make the snap in the vertical guidelines. (default: true)
376+
* @name Moveable#snapVertical
377+
* @example
378+
* import Moveable from "moveable";
379+
*
380+
* const moveable = new Moveable(document.body, {
381+
* snappable: true,
382+
* snapVertical: true,
383+
* snapHorizontal: true,
384+
* snapElement: true,
385+
* });
386+
*
387+
* moveable.snapVertical = false;
388+
*/
389+
/**
390+
* When you drag, make the snap in the horizontal guidelines. (default: true)
391+
* @name Moveable#snapHorizontal
392+
* @example
393+
* import Moveable from "moveable";
394+
*
395+
* const moveable = new Moveable(document.body, {
396+
* snappable: true,
397+
* snapVertical: true,
398+
* snapHorizontal: true,
399+
* snapElement: true,
400+
* });
401+
*
402+
* moveable.snapHorizontal = false;
403+
*/
404+
/**
405+
* When you drag, make the snap in the element guidelines. (default: true)
406+
* @name Moveable#snapElement
407+
* @example
408+
* import Moveable from "moveable";
409+
*
410+
* const moveable = new Moveable(document.body, {
411+
* snappable: true,
412+
* snapVertical: true,
413+
* snapHorizontal: true,
414+
* snapElement: true,
415+
* });
416+
*
417+
* moveable.snapElement = false;
418+
*/
372419
/**
373420
* Distance value that can snap to guidelines. (default: 5)
374421
* @name Moveable#snapThreshold

src/consts.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ export const PROPERTIES: Array<keyof MoveableOptions> = [
1818
"scrollContainer",
1919
"scrollThreshold",
2020
"baseDirection",
21+
"snapElement",
22+
"snapVertical",
23+
"snapHorizontal",
2124
];
2225
export const EVENTS: Array<keyof MoveableEvents> = [
2326
"dragStart",

src/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,10 @@ import {
3737
* @property - Whether to scale and resize through edge lines. (default: false)
3838
* @property - Minimum distance to pinch. (default: 20)
3939
* @property - When you drag, make the snap in the center of the target. (default: false)
40+
* @property - When you drag, make the snap in the vertical guidelines. (default: true)
41+
* @property - When you drag, make the snap in the horizontal guidelines. (default: true)
42+
* @property - When you drag, make the snap in the element guidelines. (default: true)
43+
4044
* @property - Distance value that can snap to guidelines. (default: 0)
4145
* @property - Add guidelines in the horizontal direction. (default: [])
4246
* @property - Add guidelines in the vertical direction. (default: [])
@@ -78,6 +82,10 @@ export interface MoveableOptions {
7882
pinchThreshold?: number;
7983

8084
snapCenter?: boolean;
85+
snapVertical?: boolean;
86+
snapHorizontal?: boolean;
87+
snapElement?: boolean;
88+
8189
snapThreshold?: number;
8290
horizontalGuidelines?: number[];
8391
verticalGuidelines?: number[];

0 commit comments

Comments
 (0)