npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@bdnithin/angular-drag-drop

v1.0.7

Published

This library provides a simple, lightweight drag and drop functionality for Angular applications. It supports both single-item and multi-item drag and drop operations with visual feedback.

Downloads

8

Readme

Angular Drag and Drop Library

This library provides a simple, lightweight drag and drop functionality for Angular applications. It supports both single-item and multi-item drag and drop operations with visual feedback.

Installation

To install this package, run the following command in your Angular project:

npm install @bdnithin/angular-drag-drop

Usage

  1. Import the DragDropModule in your app.module.ts or any other module where you want to use the drag and drop functionality:
import { NgModule } from '@angular/core';
import { DragDropModule } from '@bdnithin/angular-drag-drop';

@NgModule({
  // ...
  imports: [
    // ...
    DragDropModule
  ],
  // ...
})
export class AppModule { }
  1. Use the libDragDrop directive in your component template:
<ul libDragDrop (itemMoved)="onItemMoved($event)">
  <li *ngFor="let item of items" class="drag-drop-item">{{ item }}</li>
</ul>
  1. Handle the itemMoved event in your component:
@Component({
  // ...
})
export class YourComponent {
  items = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5'];

  onItemMoved(event: { oldIndex: number, newIndex: number, items: any[] }) {
    console.log('Items moved:', event);
    // Update your data model here
  }
}
  1. Add styling in your component's CSS:
    .drag-drop-item {
  cursor: move;
  padding: 10px;
  border: 1px solid #ddd;
  margin-bottom: 5px;
  transition: transform 0.1s ease-out;
}

.drag-drop-multiple {
  background-color: #e0e0e0;
  border: 2px solid #007bff;
}

.drag-drop-dragging {
  transform: scale(1.05);
  box-shadow: 0 5px 15px rgba(0,0,0,0.2);
  opacity: 0.8;
}

Features

  1. Single-item drag and drop: Click and drag any item to reorder.
  2. Multi-item selection and drag: Hold Ctrl (or Cmd on Mac) and click to select multiple items. Then drag any selected item to move all selected items together.
  3. Visual feedback: Selected items have a distinct style, and items being dragged have a visual effect applied.

API

Directive

libDragDrop: Apply this directive to the container element of your draggable items.

Inputs

dragDropEnabled: Boolean to enable/disable drag and drop functionality. Default is true. dragDropClass: CSS class for draggable items. Default is 'drag-drop-item'. dragDropMultipleClass: CSS class for selected items in multi-select mode. Default is 'drag-drop-multiple'. dragDropDraggingClass: CSS class applied to items while being dragged. Default is 'drag-drop-dragging'.

Outputs

itemMoved: Emits an event when items are moved. The event contains:

oldIndex: The original index of the moved item(s). newIndex: The new index of the moved item(s). items: An array of the moved items

Example

@Component({
  selector: 'app-root',
  template: `
    <ul libDragDrop 
        [dragDropEnabled]="true"
        [dragDropClass]="'my-drag-item'"
        [dragDropMultipleClass]="'my-selected-item'"
        [dragDropDraggingClass]="'my-dragging-item'"
        (itemMoved)="onItemMoved($event)">
      <li *ngFor="let item of items" class="my-drag-item">{{ item }}</li>
    </ul>
  `,
  styles: [`
    .my-drag-item {
      cursor: move;
      padding: 10px;
      border: 1px solid #ddd;
      margin-bottom: 5px;
    }
    .my-selected-item {
      background-color: #e0e0e0;
      border: 2px solid #007bff;
    }
    .my-dragging-item {
      transform: scale(1.05);
      box-shadow: 0 5px 15px rgba(0,0,0,0.2);
      opacity: 0.8;
    }
  `]
})
export class AppComponent {
  items = ['Item 1', 'Item 2', 'Item 3', 'Item 4', 'Item 5'];

  onItemMoved(event: { oldIndex: number, newIndex: number, items: any[] }) {
    console.log('Items moved:', event);
    // Reorder your items array here based on the new indices
  }
}

Notes

This library does not depend on any external drag and drop libraries. It's compatible with Angular 17 and should work with future versions as well. The library uses only HTML, CSS, and TypeScript for its implementation.

Support

For any issues or feature requests, please open an issue on the GitHub repository.

License

This project is licensed under the MIT License.