diff --git a/src/app/app.component.html b/src/app/app.component.html index 09aaae4..100e6ce 100644 --- a/src/app/app.component.html +++ b/src/app/app.component.html @@ -165,9 +165,38 @@

Destroyed ng-container

Drag & Drop :)

- + +
+

To do

+ +
+ +
+
+ +
+

Done

+ +
+ +
+

diff --git a/src/app/app.component.scss b/src/app/app.component.scss index fec5cce..3c5a510 100644 --- a/src/app/app.component.scss +++ b/src/app/app.component.scss @@ -25,3 +25,61 @@ textarea { padding-bottom: 15px; } } + + +.drag-and-drop-container { + width: 200px; + max-width: 100%; + margin: 0 25px 25px 0; + display: inline-block; + vertical-align: top; +} + +.drag-and-drop-list { + border: solid 1px #ccc; + min-height: 60px; + background: white; + border-radius: 4px; + overflow: hidden; + display: block; +} + +.drag-and-drop-box { + margin: 3px; + border-bottom: solid 1px #ccc; + color: rgba(0, 0, 0, 0.87); + /* display: flex; */ + /* flex-direction: row; */ + /* align-items: center; */ + /* justify-content: space-between; */ + /* box-sizing: border-box; */ + cursor: move; + background: white; + /* font-size: 14px; */ + width: 189px; + min-width: auto; +} + +.cdk-drag-preview { + box-sizing: border-box; + border-radius: 4px; + box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2), + 0 8px 10px 1px rgba(0, 0, 0, 0.14), + 0 3px 14px 2px rgba(0, 0, 0, 0.12); +} + +.cdk-drag-placeholder { + opacity: 0; +} + +.cdk-drag-animating { + transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); +} + +.drag-and-drop-box:last-child { + border: none; +} + +.drag-and-drop-list.cdk-drop-list-dragging .drag-and-drop-box:not(.cdk-drag-placeholder) { + transition: transform 250ms cubic-bezier(0, 0, 0.2, 1); +} diff --git a/src/app/app.component.ts b/src/app/app.component.ts index 4103bc3..3c68c18 100644 --- a/src/app/app.component.ts +++ b/src/app/app.component.ts @@ -1,5 +1,6 @@ import {Component, OnInit} from '@angular/core'; import {FormControl, FormGroup} from "@angular/forms"; +import {CdkDragDrop, moveItemInArray, transferArrayItem} from '@angular/cdk/drag-drop'; const longText = `Mega Man X, known in Japan as Rockman X,[a] is an action-platform video game developed and published by Capcom for the Super Nintendo Entertainment System (SNES). 1 @@ -30,6 +31,15 @@ export class AppComponent implements OnInit { public showAreaInContainer = true; + public todo = [ + 'Get to work', + 'Go home', + ]; + + public done = [ + 'Get up', + ]; + reactiveText = new FormControl(longText); reactiveForm = new FormGroup({ reactiveText: new FormControl(longText) @@ -62,4 +72,19 @@ export class AppComponent implements OnInit { onResized(newHeight) { console.log(newHeight); } + + + + 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 + ); + } + } }