Socket
Socket
Sign inDemoInstall

@elemental-concept/drag-and-drop

Package Overview
Dependencies
5
Maintainers
2
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @elemental-concept/drag-and-drop

Use this library if you need a simple `drag and drop` solution. The library will return a list of files `File[]`.


Version published
Weekly downloads
144
increased by102.82%
Maintainers
2
Install size
120 kB
Created
Weekly downloads
 

Readme

Source

Drag And Drop

Use this library if you need a simple drag and drop solution. The library will return a list of files File[].

npm version

🛠 Installation

  • With npm: npm i --save @elemental-concept/drag-and-drop

Add DragAndDropModule to your Module imports section.

import { DragAndDropModule } from '@elemental-concept/drag-and-drop';

@NgModule({
  imports: [
    DragAndDropModule
  ]
})
export class TestModule {
}

📖 Usage

  • To use the drag and drop you need to add <drag-and-drop> into your template.
  • This component accepts multiple as flag (by default true) to allow multiple files upload or single file upload.
  • The file browser allow only one file at the time.

When files are dropped into the dropZone the @Output fileDropped will send a File[] object as event.

<drag-and-drop (fileDropped)="onFileUpload($event)">
  <mat-icon>cloud_upload</mat-icon>
  <h4>
    Drag and drop your files
    <br>or<br>
    Click to browse your files
  </h4>
</drag-and-drop>

<div class="files-list" *ngIf="files.length > 0">
  <h4>List of file names</h4>
  <div class="file" *ngFor="let fileName of files">{{  fileName }}</div>
</div>
@Component({
  selector: 'app-drag-and-drop-page',
  template: './drag-and-drop-page.component.html',
  styleUrls: ['./drag-and-drop-page.component.scss']
})
export class DragAndDropPageComponent {
  files: string[] = [];

  onFileUpload = (files: File[]) => {
    this.files = files.map(file => file.name);
  };
}

The component contain a hidden input and uses the dropZone directive in the main container. Inside the main container there's a <ng-content></ng-content> to allow any kind of info presentation.

Style

To change the css style just use css variables into your main style.scss file. Here you can find the default values:

:root {
  --drag-and-drop-height: auto;
  --drag-and-drop-width: 400px;
  --drag-and-drop-padding: 12px 16px;
  --drag-and-drop-border: dashed 1px #6091dc;
  --drag-and-drop-margin: 0 auto;
  --drag-and-drop-background: #a0cee0;
}

Keywords

FAQs

Last updated on 29 Dec 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc