Skip to content

Commit 20b6d66

Browse files
author
Georgi Peltekov
committed
Add onFileOver and onFileLeave functions
1 parent 03b65d8 commit 20b6d66

File tree

6 files changed

+45
-16
lines changed

6 files changed

+45
-16
lines changed

README.md

+24-5
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class AppModule { }
5252

5353
```TypeScript
5454
import { Component } from '@angular/core';
55-
import { UploadFile, UploadEvent } from 'ngx-file-drop/lib/ngx-drop';
55+
import { FileDropModule } from 'ngx-file-drop/lib/ngx-drop';;
5656

5757
@Component({
5858
selector: 'demo-root',
@@ -63,16 +63,30 @@ export class AppComponent {
6363

6464
public files: UploadFile[] = [];
6565

66-
public dropped(event: UploadEvent) {
66+
public dropped(event: UploadEvent) {
6767
this.files = event.files;
68-
console.log(this.files);
68+
for (var file of event.files) {
69+
file.fileEntry.file(info => {
70+
console.log(info);
71+
});
72+
}
73+
}
74+
75+
public fileOver(event){
76+
console.log(event);
77+
}
78+
79+
public fileLeave(event){
80+
console.log(event);
6981
}
7082
}
7183

84+
7285
```
7386
```HTML
7487
<div class="center">
75-
<file-drop headertext="Drop files here" (onFileDrop)="dropped($event)"></file-drop>
88+
<file-drop headertext="Drop files here" (onFileDrop)="dropped($event)"
89+
(onFileOver)="fileOver($event)" (onFileLeave)="fileLeave($event)"></file-drop>
7690
<div class="upload-table">
7791
<table class="table">
7892
<thead>
@@ -95,6 +109,8 @@ export class AppComponent {
95109
Name | Description | Example |
96110
------------- | ------------- | -------------
97111
(onFileDrop) | On drop function called after the files are read | (onFileDrop)="dropped($event)"
112+
(onFileOver) | On drop over function| (onFileOver)="fileOver($event)"
113+
(onFileLeave) | On drop leave function| (onFileOver)="fileLeave($event)"
98114
headertext | Text to be displayed inside the drop box | headertext="Drop files here"
99115
customstyle | Custom style class name to be used | customstyle="my-style"
100116

@@ -104,7 +120,10 @@ customstyle | Custom style class name to be used | customstyle="my-style"
104120

105121
## Change Log
106122

107-
### 1.0.7
123+
### 1.0.9
124+
* Add onFileOver and onFileLeave functions
125+
126+
### 1.0.8
108127
* Remove some not needed dependencies
109128

110129
### 1.0.7

lib/ngx-drop/file-drop.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div id="dropZone" [className]="customstyle" [class.over]="dragoverflag"
2-
(dragover)="allowDrop($event)" (drop)="dropFiles($event)"
2+
(drop)="dropFiles($event)"
33
(dragover)="onDragOver($event)" (dragleave)="onDragLeave($event)">
44
<div class="content">
55
{{headertext}}

lib/ngx-drop/file-drop.component.ts

+10-8
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export class FileComponent {
2121

2222
@Output()
2323
public onFileDrop: EventEmitter<UploadEvent> = new EventEmitter<UploadEvent>();
24+
@Output()
25+
public onFileOver: EventEmitter<any> = new EventEmitter<any>();
26+
@Output()
27+
public onFileLeave: EventEmitter<any> = new EventEmitter<any>();
2428

2529
stack = [];
2630
files: UploadFile[] = [];
@@ -44,22 +48,20 @@ export class FileComponent {
4448
ngOnInit() {
4549
}
4650

47-
allowDrop(event: any) {
48-
this.preventAndStop(event);
49-
}
50-
5151
public onDragOver(event: Event): void {
52-
if (this.files.length == 0 || !this.dragoverflag) {
52+
if (!this.dragoverflag) {
5353
this.dragoverflag = true;
54-
this.preventAndStop(event);
54+
this.onFileOver.emit(event);
5555
}
56+
this.preventAndStop(event);
5657
}
5758

5859
public onDragLeave(event: Event): void {
59-
if (this.files.length != 0 || this.dragoverflag) {
60+
if (this.dragoverflag) {
6061
this.dragoverflag = false;
61-
this.preventAndStop(event);
62+
this.onFileLeave.emit(event);
6263
}
64+
this.preventAndStop(event);
6365
}
6466

6567

lib/sandbox/app/app.component.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<div class="center">
2-
<file-drop headertext="Drop files here" (onFileDrop)="dropped($event)"></file-drop>
2+
<file-drop headertext="Drop files here" (onFileDrop)="dropped($event)" (onFileOver)="fileOver($event)" (onFileLeave)="fileLeave($event)"></file-drop>
33
<div class="upload-table">
44
<table class="table">
55
<thead>

lib/sandbox/app/app.component.ts

+8
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,12 @@ export class AppComponent {
1818
});
1919
}
2020
}
21+
22+
public fileOver(event){
23+
console.log(event);
24+
}
25+
26+
public fileLeave(event){
27+
console.log(event);
28+
}
2129
}

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "ngx-file-drop",
3-
"version": "1.0.8",
3+
"version": "1.0.9",
44
"license": "MIT",
55
"scripts": {
66
"ng": "ng",

0 commit comments

Comments
 (0)