1 | # angular 15.0+ drag and drop
|
2 |
|
3 | [![Sponsorship](https://img.shields.io/badge/funding-github-%23EA4AAA)](https://github.com/users/mattlewis92/sponsorship)
|
4 | [![Build Status](https://github.com/mattlewis92/angular-draggable-droppable/actions/workflows/ci.yml/badge.svg)](https://github.com/mattlewis92/angular-draggable-droppable/actions/workflows/ci.yml)
|
5 | [![codecov](https://codecov.io/gh/mattlewis92/angular-draggable-droppable/branch/main/graph/badge.svg)](https://codecov.io/gh/mattlewis92/angular-draggable-droppable)
|
6 | [![npm version](https://badge.fury.io/js/angular-draggable-droppable.svg)](http://badge.fury.io/js/angular-draggable-droppable)
|
7 | [![Twitter Follow](https://img.shields.io/twitter/follow/mattlewis92_.svg)](https://twitter.com/mattlewis92_)
|
8 |
|
9 | ## Demo
|
10 |
|
11 | https://mattlewis92.github.io/angular-draggable-droppable/
|
12 |
|
13 | ## Table of contents
|
14 |
|
15 | - [About](#about)
|
16 | - [Installation](#installation)
|
17 | - [Documentation](#documentation)
|
18 | - [Development](#development)
|
19 | - [License](#licence)
|
20 |
|
21 | ## About
|
22 |
|
23 | Observable powered drag and drop for angular 15.0+
|
24 |
|
25 | ## Installation
|
26 |
|
27 | Install through npm:
|
28 |
|
29 | ```
|
30 | npm install angular-draggable-droppable
|
31 | ```
|
32 |
|
33 | Then use it in your app like so:
|
34 |
|
35 | ```typescript
|
36 | import { Component, NgModule } from '@angular/core';
|
37 | import { DragAndDropModule } from 'angular-draggable-droppable';
|
38 |
|
39 | @NgModule({
|
40 | declarations: [DemoApp],
|
41 | imports: [DragAndDropModule],
|
42 | bootstrap: [DemoApp],
|
43 | })
|
44 | class DemoModule {}
|
45 |
|
46 | @Component({
|
47 | selector: 'demo-app',
|
48 | template: `
|
49 | <div mwlDraggable (dragEnd)="dragEnd($event)">Drag me!</div>
|
50 | <div mwlDroppable (drop)="this.droppedData = $event.dropData">
|
51 | <span [hidden]="droppedData">Drop here</span>
|
52 | <span [hidden]="!droppedData"
|
53 | >Item dropped here with data: "{{ droppedData }}"!</span
|
54 | >
|
55 | </div>
|
56 | `,
|
57 | })
|
58 | class DemoApp {
|
59 | droppedData: string;
|
60 |
|
61 | dragEnd(event) {
|
62 | console.log('Element was dragged', event);
|
63 | }
|
64 | }
|
65 | ```
|
66 |
|
67 | Note: if draggable elements are inside a scrollable element then you will need to add `mwlDraggableScrollContainer` as an attribute to the scrollable container.
|
68 |
|
69 | You may also find it useful to view the [demo source](https://github.com/mattlewis92/angular-draggable-droppable/tree/main/src/demo).
|
70 |
|
71 | ## Documentation
|
72 |
|
73 | All documentation is auto-generated from the source and can be viewed here:
|
74 | https://mattlewis92.github.io/angular-draggable-droppable/docs/
|
75 |
|
76 | ## Alternatives
|
77 |
|
78 | I wrote this library because I needed drag and drop whilst snapping to a grid. If you don't need this feature then I recommend checking out one of these other awesome drag and drop libraries:
|
79 |
|
80 | - [Angular CDK drag and drop](https://material.angular.io/cdk/drag-drop/overview)
|
81 | - [angular-skyhook](https://github.com/cormacrelf/angular-skyhook)
|
82 | - [ng-drag-drop](https://github.com/ObaidUrRehman/ng-drag-drop)
|
83 |
|
84 | ## Development
|
85 |
|
86 | ### Prepare your environment
|
87 |
|
88 | - Install [Node.js (>=14.19.0 or >=16.9.0)](http://nodejs.org/)
|
89 | - Install pnpm: `corepack enable`
|
90 | - Install local dev dependencies: `pnpm install` while current directory is this repo
|
91 |
|
92 | ### Development server
|
93 |
|
94 | Run `pnpm start` to start a development server on port 8000 with auto reload + tests.
|
95 |
|
96 | ### Testing
|
97 |
|
98 | Run `pnpm test` to run tests once or `pnpm test:watch` to continually run tests.
|
99 |
|
100 | ### Release
|
101 |
|
102 | ```bash
|
103 | pnpm release
|
104 | ```
|
105 |
|
106 | ## License
|
107 |
|
108 | MIT
|