/**
* @license
* Copyright Google LLC All Rights Reserved.
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://angular.io/license
*/
import {Component, ViewEncapsulation, ChangeDetectionStrategy} from '@angular/core';
import {MatIconRegistry} from '@angular/material/icon';
import {DomSanitizer} from '@angular/platform-browser';
import {CdkDragDrop, moveItemInArray, transferArrayItem} from '@angular/cdk/drag-drop';
@Component({
moduleId: module.id,
selector: 'drag-drop-demo',
templateUrl: 'drag-drop-demo.html',
styleUrls: ['drag-drop-demo.css'],
encapsulation: ViewEncapsulation.None,
changeDetection: ChangeDetectionStrategy.OnPush,
})
export class DragAndDropDemo {
axisLock: 'x' | 'y';
dragStartDelay = 0;
todo = [
'Go out for Lunch',
'Make a cool app',
'Watch TV',
'Eat a healthy dinner',
'Go to sleep'
];
done = [
'Get up',
'Have breakfast',
'Brush teeth',
'Check reddit'
];
horizontalData = [
'Bronze age',
'Iron age',
'Middle ages',
'Early modern period',
'Long nineteenth century'
];
constructor(iconRegistry: MatIconRegistry, sanitizer: DomSanitizer) {
iconRegistry.addSvgIconLiteral('dnd-move', sanitizer.bypassSecurityTrustHtml(`
`));
}
drop(event: CdkDragDrop) {
if (event.previousContainer === event.container) {
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
} else {
transferArrayItem(
event.previousContainer.data,
event.container.data,
event.previousIndex,
event.currentIndex);
}
}
}