Skip to content

Commit d304b41

Browse files
crisbetojelbourn
authored andcommitted
docs(drag-drop): add missing example (#14548)
Adds an example that was being embedded in the readme, but isn't in the docs. It seems like it was missed in #13754 where a reference to it was introduced.
1 parent 04c3d6e commit d304b41

File tree

4 files changed

+118
-1
lines changed

4 files changed

+118
-1
lines changed

src/cdk/drag-drop/drag-drop.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ by referencing the `id` of another drop container:
4141

4242
If you have an unknown number of connected drop lists, you can use the `cdkDropListGroup` directive
4343
to set up the connection automatically. Note that any new `cdkDropList` that is added under a group
44-
will be connected to all other automatically.
44+
will be connected to all other lists automatically.
4545

4646
```html
4747
<div cdkDropListGroup>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
.example-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+
.example-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+
.example-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+
.example-box:last-child {
49+
border: none;
50+
}
51+
52+
.example-list.cdk-drop-list-dragging .example-box:not(.cdk-drag-placeholder) {
53+
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<div cdkDropListGroup>
2+
<div class="example-container">
3+
<h2>To do</h2>
4+
5+
<div
6+
cdkDropList
7+
[cdkDropListData]="todo"
8+
class="example-list"
9+
(cdkDropListDropped)="drop($event)">
10+
<div class="example-box" *ngFor="let item of todo" cdkDrag>{{item}}</div>
11+
</div>
12+
</div>
13+
14+
<div class="example-container">
15+
<h2>Done</h2>
16+
17+
<div
18+
cdkDropList
19+
[cdkDropListData]="done"
20+
class="example-list"
21+
(cdkDropListDropped)="drop($event)">
22+
<div class="example-box" *ngFor="let item of done" cdkDrag>{{item}}</div>
23+
</div>
24+
</div>
25+
</div>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import {Component} from '@angular/core';
2+
import {CdkDragDrop, moveItemInArray, transferArrayItem} from '@angular/cdk/drag-drop';
3+
4+
/**
5+
* @title Drag&Drop connected sorting group
6+
*/
7+
@Component({
8+
selector: 'cdk-drag-drop-connected-sorting-group-example',
9+
templateUrl: 'cdk-drag-drop-connected-sorting-group-example.html',
10+
styleUrls: ['cdk-drag-drop-connected-sorting-group-example.css'],
11+
})
12+
export class CdkDragDropConnectedSortingGroupExample {
13+
todo = [
14+
'Get to work',
15+
'Pick up groceries',
16+
'Go home',
17+
'Fall asleep'
18+
];
19+
20+
done = [
21+
'Get up',
22+
'Brush teeth',
23+
'Take a shower',
24+
'Check e-mail',
25+
'Walk dog'
26+
];
27+
28+
drop(event: CdkDragDrop<string[]>) {
29+
if (event.previousContainer === event.container) {
30+
moveItemInArray(event.container.data, event.previousIndex, event.currentIndex);
31+
} else {
32+
transferArrayItem(event.previousContainer.data,
33+
event.container.data,
34+
event.previousIndex,
35+
event.currentIndex);
36+
}
37+
}
38+
}

0 commit comments

Comments
 (0)