projects/i-components/src/lib/directives/drop-zone.directive.ts
Directive to provide a DropZone for draggable items
Selector | [wmDropZone] |
Properties |
Methods |
Inputs |
Outputs |
HostBindings |
HostListeners |
constructor(elementRef: ElementRef, dragDropService: DragDropService)
|
|||||||||
Creates an instance of DropZoneDirective
Parameters :
|
wmDropZone | |
Type : literal type
|
|
Pair of values representing the target node and desire drop position |
dragEnter | |
Type : EventEmitter
|
|
Events that get triggered when dragenter event is called |
dragLeave | |
Type : EventEmitter
|
|
Events that get triggered when dragleave event is called |
dropped | |
Type : EventEmitter
|
|
Events that get triggered when drop event is called |
class.dragover |
Type : boolean
|
Default value : false
|
Default class applied to elements that use this directive |
class.dropzone |
Type : boolean
|
Default value : true
|
Default class applied to elements that use this directive |
dragenter | ||||
Arguments : '$event'
|
||||
Listener for dragenter event, notifies the dragDropService Item drag enter another element event handler
Parameters :
|
dragleave | ||||
Arguments : '$event'
|
||||
Item drag leave another element event handler
Parameters :
|
drop | ||||
Arguments : '$event'
|
||||
Item dropped event handler
Parameters :
|
onDragEnter | ||||||
onDragEnter(event: any)
|
||||||
Decorators :
@HostListener('dragenter', ['$event'])
|
||||||
Listener for dragenter event, notifies the dragDropService Item drag enter another element event handler
Parameters :
Returns :
void
|
onDragLeave | ||||||
onDragLeave(event: any)
|
||||||
Decorators :
@HostListener('dragleave', ['$event'])
|
||||||
Item drag leave another element event handler
Parameters :
Returns :
void
|
onDrop | ||||||
onDrop(event: any)
|
||||||
Decorators :
@HostListener('drop', ['$event'])
|
||||||
Item dropped event handler
Parameters :
Returns :
void
|
dragEnter |
Default value : new EventEmitter<DragEvent>()
|
Decorators :
@Output()
|
Events that get triggered when dragenter event is called |
dragLeave |
Default value : new EventEmitter<DragEvent>()
|
Decorators :
@Output()
|
Events that get triggered when dragleave event is called |
drop |
Default value : true
|
Decorators :
@HostBinding('class.dropzone')
|
Default class applied to elements that use this directive |
dropped |
Default value : new EventEmitter<DragEvent>()
|
Decorators :
@Output()
|
Events that get triggered when drop event is called |
isOver |
Default value : false
|
Decorators :
@HostBinding('class.dragover')
|
Default class applied to elements that use this directive |
Public wmDropZone |
Type : literal type
|
Decorators :
@Input()
|
Pair of values representing the target node and desire drop position |
import {
Directive,
ElementRef,
EventEmitter,
HostBinding,
HostListener,
Input,
Output,
} from '@angular/core';
import { DragDropService } from '../services/drag-drop.service';
/**
* Directive to provide a DropZone for draggable items
*
* @export
* @class DropZoneDirective
*/
@Directive({
selector: '[wmDropZone]',
})
export class DropZoneDirective {
/**
* Default class applied to elements that use this directive
*
* @type {boolean}
* @memberof DropZoneDirective
*/
@HostBinding('class.dropzone') drop = true;
/**
* Default class applied to elements that use this directive
*
* @type {boolean}
* @memberof DropZoneDirective
*/
@HostBinding('class.dragover') isOver = false;
/**
* Pair of values representing the target node and desire drop position
*
* @type {[any, string]}
* @memberof DropZoneDirective
*/
@Input() public wmDropZone: { target: any; position: string };
/**
* Events that get triggered when dragenter event is called
*
* @type {EventEmitter<DragEvent>}
* @memberof DraggableDirective
*/
@Output() dragEnter = new EventEmitter<DragEvent>();
/**
* Events that get triggered when dragleave event is called
*
* @type {EventEmitter<DragEvent>}
* @memberof DraggableDirective
*/
@Output() dragLeave = new EventEmitter<DragEvent>();
/**
* Events that get triggered when drop event is called
*
* @type {EventEmitter<DragEvent>}
* @memberof DraggableDirective
*/
@Output() dropped = new EventEmitter<DragEvent>();
/**
* Creates an instance of DropZoneDirective
*
* @param {ElementRef} elementRef
* @param {DragDropService} dragDropService
* @memberof DropZoneDirective
*/
constructor(
private elementRef: ElementRef,
private dragDropService: DragDropService
) {}
/**
* Listener for dragenter event, notifies the dragDropService
* Item drag enter another element event handler
*
* @param {*} event
* @memberof DropZoneDirective
*/
@HostListener('dragenter', ['$event'])
onDragEnter(event: any): void {
this.isOver = true;
this.dragEnter.emit(event);
}
/**
* Item drag leave another element event handler
*
* @param {any} event
* @memberof DraggableDirective
*/
@HostListener('dragleave', ['$event'])
onDragLeave(event: any): void {
this.isOver = false;
this.dragLeave.emit(event);
}
/**
* Item dropped event handler
*
* @param {any} event
* @memberof DraggableDirective
*/
@HostListener('drop', ['$event'])
onDrop(event: any): void {
event.preventDefault();
this.isOver = false;
const customEvent: any = event;
customEvent.dragData = this.dragDropService.currentDragging.wmDraggable;
customEvent.dropData = this.wmDropZone;
this.dropped.emit(customEvent);
}
}