Gathering detailed insights and metrics for @dnd-kit-vue/modifiers
Gathering detailed insights and metrics for @dnd-kit-vue/modifiers
Gathering detailed insights and metrics for @dnd-kit-vue/modifiers
Gathering detailed insights and metrics for @dnd-kit-vue/modifiers
npm install @dnd-kit-vue/modifiers
Typescript
Module System
Node Version
NPM Version
49.4
Supply Chain
94.2
Quality
79.5
Maintenance
100
Vulnerability
99.6
License
TypeScript (93.42%)
Vue (4.51%)
CSS (1.76%)
JavaScript (0.18%)
HTML (0.13%)
Total Downloads
2,708
Last Day
1
Last Week
4
Last Month
31
Last Year
1,295
12 Stars
512 Commits
1 Watchers
5 Branches
32 Contributors
Updated on Aug 12, 2024
Minified
Minified + Gzipped
Latest Version
0.1.2
Package Id
@dnd-kit-vue/modifiers@0.1.2
Unpacked Size
10.18 kB
Size
4.01 kB
File Count
15
NPM Version
10.5.2
Node Version
20.13.1
Published on
Jun 13, 2024
Cumulative downloads
Total Downloads
Last Day
0%
1
Compared to previous day
Last Week
100%
4
Compared to previous week
Last Month
-54.4%
31
Compared to previous month
Last Year
87.4%
1,295
Compared to previous year
2
Modifiers let you dynamically modify the movement coordinates that are detected by sensors. They can be used for a wide range of use cases, for example:
To start using modifiers, install the modifiers package via yarn or npm:
npm install @dnd-kit/modifiers
The modifiers repository contains a number of useful modifiers that can be applied on DndContext
as well as DragOverlay
.
1import {DndContext, DragOverlay} from '@dnd-kit'; 2import { 3 restrictToVerticalAxis, 4 restrictToWindowEdges, 5} from '@dnd-kit/modifiers'; 6 7function App() { 8 return ( 9 <DndContext modifiers={[restrictToVerticalAxis]}> 10 {/* ... */} 11 <DragOverlay modifiers={[restrictToWindowEdges]}>{/* ... */}</DragOverlay> 12 </DndContext> 13 ); 14}
As you can see from the example above, DndContext
and DragOverlay
can both have different modifiers.
restrictToHorizontalAxis
Restrict movement to only the horizontal axis.
restrictToVerticalAxis
Restrict movement to only the vertical axis.
restrictToWindowEdges
Restrict movement to the edges of the window. This modifier can be useful to prevent the DragOverlay
from being moved outside of the bounds of the window.
restrictToParentElement
Restrict movement to the parent element of the draggable item that is picked up.
restrictToFirstScrollableAncestor
Restrict movement to the first scrollable ancestor of the draggable item that is picked up.
createSnapModifier
Function to create modifiers to snap to a given grid size.
1import {createSnapModifier} from '@dnd-kit/modifiers'; 2 3const gridSize = 20; // pixels 4const snapToGridModifier = createSnapModifier(gridSize);
snapCenterToCursor
Snaps the center of the draggable item to the cursor when it is picked up. Has no effect when using the Keyboard sensor.
To build your own custom modifiers, refer to the implementation of the built-in modifiers of this package.
For example, here is an implementation to create a modifier to snap to grid:
1const gridSize = 20; 2 3function snapToGrid(args) { 4 const {transform} = args; 5 6 return { 7 ...transform, 8 x: Math.ceil(transform.x / gridSize) * gridSize, 9 y: Math.ceil(transform.y / gridSize) * gridSize, 10 }; 11}
No vulnerabilities found.
No security vulnerabilities found.