Skip to content

Ks89/ngx-drag-n-drop

Repository files navigation

@ks89/ngx-drag-n-drop

@ks89/ngx-drag-n-drop is an Angular library to add drag and drop features


Based on angular4-drag-drop, but with support for Angular >=7 and other improvements.


npm@latest npm@beta npm@next

Downloads/week Downloads/month Downloads/year

Known Vulnerabilities david-dm Dependencies code style: prettier

Stackblitz AngularStyleGuide

NPMLicense Semver

Do you like @ks89/ngx-drag-n-drop? Please, add a ⭐ to support this library

Table of Contents

  1. Features
  2. Installation
  3. Choose the version
  4. Usage
  5. News
  6. Contributing
  7. License

💥 Features 💥

  • Angular Module to import this library
  • supports all recommended Angular Compiler Options
  • compliant to Angular Package Format specifications
  • use Semantic versioning 2.0.0 also known as 'semver'
  • official example with angular-cli

📦 Installation 📦

  • npm install --save @ks89/ngx-drag-n-drop

⚠️ Choose the right version ⚠️

@ks89/ngx-drag-n-drop
AngularJS NOT WORKING
Angular 2 NOT OFFICIALLY SUPPORTED
Angular 4 NOT OFFICIALLY SUPPORTED
Angular 5 NOT OFFICIALLY SUPPORTED
Angular 6 NOT OFFICIALLY SUPPORTED
Angular 7 >= 1.0.0 and <2.0.0
Angular 8 >= 1.0.0 and <2.0.0
Angular 9 >= 2.0.0 and <3.0.0
Angular 10 >= 3.0.0 and <4.0.0
Angular 11 >= 3.0.0 and <4.0.0
Angular 12 >= 4.0.0
Angular 13 >= 5.0.0
Angular 14 >= 5.0.0
Angular 15 >= 6.0.1
Angular 16 >= 7.0.0
Angular 17 >= 7.0.0
Angular 18 >= 8.0.0

Usage

To import the module into a module in which you wish to use the directive on components.

import { DragDropDirectiveModule} from "@ks89/ngx-drag-n-drop";

This module exports two attribute directives, 'DragDirective' and 'DropDirective'. DragDirectve is used with a component from which you want to drag items, while DropDirective is used with the component in which you wish to drop items.

Both accept inputs for CSS class highlighting. If you do not pass a string then highlighting will be ignored. Both will emit the dragged item when it is dropped in the 'DroppableDirective' component or element.

'DragDirective' emits an event when dragging is started.

'DropDirective' emits events when a drag enters a drop element, leaves a drop element, and as stated above when an element is dropped.

DragDirective

<div *ngFor="let item of itemsToDrop" ksDragDirective [draggedItem]='item' [dragHightlight]="'highlight'" (releaseDrop)="releaseDrop($event)" (startDrag)="startDrag(item)">
</div>

'[draggedItem]="item"' Applies the drag directive, and passes it an item.

'[dragHighlight]="'highlight'"' Passes a string to add a css class to the css class list of the element.

'(releaseDrop)="releaseDrop($event)"' Calls a function to act on the dragged item once it is dropped into the drop area.

'(startDrag)="startDrag(item)" Calls a function when the user starts dragging the item.

DropDirectve

<div ksDropDirective (dropEvent)="addDropItem($event)" (dropEventMouse)="dropEventMouse($event) (dragenterEvent)="dragEnter($event)" (dragleaveEvent)="dragLeave()" class="droppable" [dropHighlight]="'highlight'" >
</div>

'ksDropDirective' applies the directive to an element, making it a drop target. '[dropHighlight]="'highlight'"' passes a string to add a css class to the css class list of the element.

'(dropEvent)="addDropItem($event)"' calls a function and passes the dropped item when an item is dropped into the drop element.

'(dropEventMouse)="dropEventMouse($event)"'. dropEventMouse is emitting the html drop event. From this you can get x,y cordinates of the drop etc. If you wish you can use this to get the dropped item as well: let droppedObject = JSON.parse(event.dataTransfer.getData('text')).

'(dragenterEvent)="dragEnter($event)"' calls a function and passes the dragged item when an item is dragged into the drop element.

'(dragleaveEvent)="dragLeave($event)"' calls a function and passes the dragged item when the item is dragged out of the drop element.

🔥 News 🔥

  • 31/05/2024 - 8.0.0 - @ks89/ngx-drag-n-drop - HERE
  • 16/08/2023 - 7.0.1 - @ks89/ngx-drag-n-drop - HERE
  • 17/11/2022 - 6.0.1 - @ks89/ngx-drag-n-drop - HERE
  • 11/04/2021 - 5.0.0 - @ks89/ngx-drag-n-drop - HERE
  • 08/06/2021 - 4.0.0 - @ks89/ngx-drag-n-drop - HERE
  • 13/08/2019 - 3.0.0 - @ks89/ngx-drag-n-drop - HERE
  • 21/02/2019 - 2.0.0 - @ks89/ngx-drag-n-drop - HERE
  • 24/07/2019 - 1.0.1 - @ks89/ngx-drag-n-drop - HERE
  • 24/07/2019 - 1.0.0 - @ks89/ngx-drag-n-drop - HERE

💻 Contributing 💻

Check CONTRIBUTING.md in this repository. To understand how to contribute to an open source project, HERE you can find useful information.

When you create a pull request, please, format your code to be consistent with the existing code. I suggest to use WebStorm as IDE and when you commit don't use a third party software, but the official command line git. In this way, prettier will run using my configuration and it will auto-format the code. If it will fail, add files with git add . again and retry.


©️ License ©️

The MIT License (MIT)

Copyright (c) 2019-2024 Stefano Cappa (Ks89)

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON INFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.


Created by Stefano Cappa

⬆ back to top