Skip to content

Commit 47b0f3a

Browse files
committed
Angular Material In Depth
1 parent fc2eaf3 commit 47b0f3a

6 files changed

+200
-1
lines changed

src/_mixins.scss

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
@mixin drag-drop {
2+
3+
.cdk-drag-preview {
4+
box-sizing: border-box;
5+
border-radius: 4px;
6+
font-family: Roboto;
7+
box-shadow: 0 5px 5px -3px rgba(0, 0, 0, 0.2),
8+
0 8px 10px 1px rgba(0, 0, 0, 0.14),
9+
0 3px 14px 2px rgba(0, 0, 0, 0.12);
10+
}
11+
12+
.cdk-drag-animating {
13+
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
14+
}
15+
16+
.lesson:last-child {
17+
border: none;
18+
}
19+
20+
.drag-drop-list.cdk-drop-list-dragging .drag-drop-item:not(.cdk-drag-placeholder) {
21+
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
22+
}
23+
24+
.drop-placeholder {
25+
background: #ccc;
26+
border: dotted 3px #999;
27+
min-height: 60px;
28+
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
29+
}
30+
31+
}

src/app/app-routing.module.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import {AboutComponent} from "./about/about.component";
55
import {CourseComponent} from "./course/course.component";
66
import {CourseResolver} from "./services/course.resolver";
77
import {CreateCourseComponent} from './create-course/create-course.component';
8+
import {DragDropComponent} from './drag-drop/drag-drop.component';
89

910
const routes: Routes = [
1011
{
@@ -26,6 +27,10 @@ const routes: Routes = [
2627
{
2728
path: 'add-new-course',
2829
component: CreateCourseComponent
30+
},
31+
{
32+
path: "drag-drop-example",
33+
component: DragDropComponent
2934
},
3035
{
3136
path: "**",

src/app/app.module.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@ import {MatRadioModule} from '@angular/material/radio';
3939
import {MatNativeDateModule} from '@angular/material/core';
4040
import {MatSliderModule} from '@angular/material/slider';
4141
import {MatTooltipModule} from '@angular/material/tooltip';
42+
import {DragDropModule} from '@angular/cdk/drag-drop';
43+
import {DragDropComponent} from './drag-drop/drag-drop.component';
44+
4245

4346
@NgModule({
4447
declarations: [
@@ -50,7 +53,8 @@ import {MatTooltipModule} from '@angular/material/tooltip';
5053
CourseDialogComponent,
5154
CreateCourseComponent,
5255
CreateCourseStep1Component,
53-
CreateCourseStep2Component
56+
CreateCourseStep2Component,
57+
DragDropComponent
5458
],
5559
imports: [
5660
BrowserModule,
@@ -75,6 +79,7 @@ import {MatTooltipModule} from '@angular/material/tooltip';
7579
AppRoutingModule,
7680
MatSelectModule,
7781
MatCheckboxModule,
82+
DragDropModule,
7883
MatRadioModule,
7984
MatSliderModule,
8085
MatDatepickerModule,
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
2+
<div class="drag-drop-container">
3+
4+
<div class="pending">
5+
6+
<h3>Lessons To Watch:</h3>
7+
8+
</div>
9+
10+
<!-- div class="done">
11+
12+
<h3>Done:</h3>
13+
14+
</div-->
15+
16+
</div>
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
2+
.drag-drop-container {
3+
font-family: "Roboto";
4+
display: flex;
5+
justify-content: center;
6+
}
7+
8+
.lessons-list {
9+
width: 500px;
10+
max-width: 100%;
11+
border: solid 1px #ccc;
12+
min-height: 60px;
13+
display: block;
14+
background: white;
15+
border-radius: 4px;
16+
overflow: hidden;
17+
}
18+
19+
20+
.lesson {
21+
padding: 20px 10px;
22+
border-bottom: solid 1px #ccc;
23+
color: rgba(0, 0, 0, 0.87);
24+
display: flex;
25+
flex-direction: row;
26+
align-items: center;
27+
justify-content: space-between;
28+
box-sizing: border-box;
29+
cursor: move;
30+
background: white;
31+
font-size: 14px;
32+
}
33+
34+
.done {
35+
margin-left: 30px;
36+
}
37+
38+
39+
40+
41+
42+
43+
44+
45+
46+
47+
48+
49+
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
import {Component} from '@angular/core';
2+
import {CdkDragDrop, moveItemInArray, transferArrayItem} from '@angular/cdk/drag-drop';
3+
import {Lesson} from '../model/lesson';
4+
5+
6+
@Component({
7+
selector: 'drag-drop-example',
8+
templateUrl: "drag-drop.component.html",
9+
styleUrls: ["drag-drop.component.scss"]
10+
})
11+
export class DragDropComponent {
12+
13+
lessons = [
14+
{
15+
id: 120,
16+
'description': 'Introduction to Angular Material',
17+
'duration': '4:17',
18+
'seqNo': 1,
19+
courseId: 11
20+
},
21+
{
22+
id: 121,
23+
'description': 'Navigation and Containers',
24+
'duration': '6:37',
25+
'seqNo': 2,
26+
courseId: 11
27+
},
28+
{
29+
id: 122,
30+
'description': 'Data Tables',
31+
'duration': '8:03',
32+
'seqNo': 3,
33+
courseId: 11
34+
},
35+
{
36+
id: 123,
37+
'description': 'Dialogs and Overlays',
38+
'duration': '11:46',
39+
'seqNo': 4,
40+
courseId: 11
41+
},
42+
{
43+
id: 124,
44+
'description': 'Commonly used Form Controls',
45+
'duration': '7:17',
46+
'seqNo': 5,
47+
courseId: 11
48+
},
49+
{
50+
id: 125,
51+
'description': 'Drag and Drop',
52+
'duration': '8:16',
53+
'seqNo': 6,
54+
courseId: 11
55+
},
56+
{
57+
id: 126,
58+
'description': 'Responsive Design',
59+
'duration': '7:28',
60+
'seqNo': 7,
61+
courseId: 11
62+
},
63+
{
64+
id: 127,
65+
'description': 'Tree Component',
66+
'duration': '11:09',
67+
'seqNo': 8,
68+
courseId: 11
69+
},
70+
{
71+
id: 128,
72+
'description': 'Virtual Scrolling',
73+
'duration': '3:44',
74+
'seqNo': 9,
75+
courseId: 11
76+
},
77+
{
78+
id: 129,
79+
'description': 'Custom Themes',
80+
'duration': '8:55',
81+
'seqNo': 10,
82+
courseId: 11
83+
},
84+
{
85+
id: 130,
86+
'description': 'Changing Theme at Runtime',
87+
'duration': '12:37',
88+
'seqNo': 11,
89+
courseId: 11
90+
}
91+
];
92+
93+
}

0 commit comments

Comments
 (0)