Skip to content

Commit 2494ae2

Browse files
committed
Added drag-droo component in MiscModule
1 parent 57f13db commit 2494ae2

File tree

5 files changed

+128
-7
lines changed

5 files changed

+128
-7
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div cdkDropListGroup>
2+
<div class="drag-drop-container">
3+
<h4>To do</h4>
4+
5+
<div
6+
cdkDropList
7+
[cdkDropListData]="todo"
8+
class="drag-drop-list"
9+
(cdkDropListDropped)="drop($event)">
10+
<div class="drag-drop-box" *ngFor="let item of todo" cdkDrag>{{item}}</div>
11+
</div>
12+
</div>
13+
14+
<div class="drag-drop-container">
15+
<h4>Done</h4>
16+
17+
<div
18+
cdkDropList
19+
[cdkDropListData]="done"
20+
class="drag-drop-list"
21+
(cdkDropListDropped)="drop($event)">
22+
<div class="drag-drop-box" *ngFor="let item of done" cdkDrag>{{item}}</div>
23+
</div>
24+
</div>
25+
</div>
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
.drag-drop-container {
2+
width: 400px;
3+
max-width: 100%;
4+
margin: 0 25px 25px 0;
5+
display: inline-block;
6+
vertical-align: top;
7+
}
8+
9+
.drag-drop-list {
10+
border: solid 1px #ccc;
11+
min-height: 60px;
12+
background: white;
13+
border-radius: 4px;
14+
overflow: hidden;
15+
display: block;
16+
}
17+
18+
.drag-drop-box {
19+
padding: 20px 10px;
20+
border-bottom: solid 1px #ccc;
21+
color: rgba(0, 0, 0, 0.87);
22+
display: flex;
23+
flex-direction: row;
24+
align-items: center;
25+
justify-content: space-between;
26+
box-sizing: border-box;
27+
cursor: move;
28+
background: white;
29+
font-size: 14px;
30+
}
31+
32+
.cdk-drag-preview {
33+
box-sizing: border-box;
34+
border-radius: 4px;
35+
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
36+
0 8px 10px 1px rgba(0, 0, 0, 0.14),
37+
0 3px 14px 2px rgba(0, 0, 0, 0.12);
38+
}
39+
40+
.cdk-drag-placeholder {
41+
opacity: 0;
42+
}
43+
44+
.cdk-drag-animating {
45+
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
46+
}
47+
48+
.drag-drop-box:last-child {
49+
border: none;
50+
}
51+
52+
.drag-drop-list.cdk-drop-list-dragging .drag-drop-box:not(.cdk-drag-placeholder) {
53+
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
54+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
import {Component} from '@angular/core';
2+
import {CdkDragDrop, moveItemInArray, transferArrayItem} from '@angular/cdk/drag-drop';
3+
4+
@Component({
5+
selector: 'app-drag-drop',
6+
templateUrl: 'drag-drop.component.html',
7+
styleUrls: ['drag-drop.component.scss'],
8+
})
9+
export class DragDropComponent {
10+
public todo: string[] = [
11+
'Add new features',
12+
'Get 1000 stars'
13+
];
14+
15+
public done: string[] = [
16+
'Angular',
17+
'Firebase',
18+
'Material desing',
19+
];
20+
21+
public drop(event: CdkDragDrop<string[]>): void {
22+
if (event.previousContainer === event.container) {
23+
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
24+
} else {
25+
transferArrayItem(
26+
event.previousContainer.data,
27+
event.container.data,
28+
event.previousIndex,
29+
event.currentIndex
30+
);
31+
}
32+
}
33+
}

src/app/components/misc/misc.component.html

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,9 @@
55
<mat-card>
66
<h1>Misc</h1>
77
<h4>Various components ready to use in your own project.</h4>
8-
8+
99
<hr>
10-
10+
1111
<!-- Miscellaneous material components -->
1212
<h3>Two-way data binding :</h3>
1313
<mat-form-field class="full-width">
@@ -18,6 +18,11 @@ <h3>Two-way data binding :</h3>
1818

1919
<hr>
2020

21+
<h3>Drag & drop : </h3>
22+
<app-drag-drop></app-drag-drop>
23+
24+
<hr>
25+
2126
<h3>mat Datepicker : </h3>
2227
<mat-form-field>
2328
<input matInput [matDatepicker]="picker" placeholder="Choose a date">
@@ -42,7 +47,7 @@ <h3>mat Sidenav : </h3>
4247
</mat-sidenav-container>
4348

4449
<hr>
45-
50+
4651
<h3>mat Tooltip : </h3>
4752
<span matTooltip="This is a tooltip">Hover me!</span>
4853

@@ -59,7 +64,7 @@ <h3>mat Slide toggle : </h3>
5964

6065
<!-- Temporary disabled -->
6166
<!-- <app-table></app-table> -->
62-
67+
6368
<hr>
6469

6570
<app-expansion-panel></app-expansion-panel>
@@ -74,9 +79,9 @@ <h3>mat Slide toggle : </h3>
7479
<app-async-observable-pipe></app-async-observable-pipe>
7580

7681
<hr>
77-
82+
7883
<app-json-pipe></app-json-pipe>
79-
84+
8085
<hr>
8186

8287
<app-currency-pipe></app-currency-pipe>

src/app/components/misc/misc.module.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { MatButtonModule, MatCheckboxModule, MatInputModule, MatNativeDateModule
77
MatIconModule, MatToolbarModule } from '@angular/material';
88

99
// import { CdkTableModule } from '@angular/cdk';
10+
import { DragDropModule } from '@angular/cdk/drag-drop';
1011
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
1112
import { PipesModule } from '@shared/pipes/pipes.module';
1213

@@ -17,6 +18,7 @@ import { ChangeDetailComponent } from './change/change-detail.component';
1718
import { VirtRealComponent } from './virtual-reality/virtreal.component';
1819
import { TableComponent } from './table/table.component';
1920
import { StepperComponent } from './stepper/stepper.component';
21+
import { DragDropComponent } from './drag-drop/drag-drop.component';
2022
import { ExpansionPanelComponent } from './expansion-panel/expansion-panel.component';
2123

2224
@NgModule({
@@ -28,6 +30,7 @@ import { ExpansionPanelComponent } from './expansion-panel/expansion-panel.compo
2830
VirtRealComponent,
2931
TableComponent,
3032
StepperComponent,
33+
DragDropComponent,
3134
ExpansionPanelComponent
3235
],
3336
imports: [
@@ -37,7 +40,8 @@ import { ExpansionPanelComponent } from './expansion-panel/expansion-panel.compo
3740
MatTableModule, MatCardModule, MatDatepickerModule, MatExpansionModule,
3841
MatIconModule, MatToolbarModule,
3942
FormsModule, ReactiveFormsModule,
40-
PipesModule
43+
PipesModule,
44+
DragDropModule
4145
],
4246
exports: [
4347
CarouselComponent,

0 commit comments

Comments
 (0)