Skip to content

Commit e157740

Browse files
Aleksandyrjosephperrott
authored andcommitted
docs(chips): add drag and drop sample (#15276)
* docs(chips): add drag and drop sample Closes #13215 * docs(chips): fix tslint erros drag and drop sample Closes #13215 * docs(chips): fix space indentations and apply animation drag&drop fix spaces indentation and apply animation Closes #15276 * docs(chips): fix lint errors Closes #15276 * docs(chips): wrap drag animations within another class Closes #13215 * fix(chips): add title drag and drop example Closes #13215 * fix(chips-drag-drop): fix lint errors Closes #13215
1 parent 5da724b commit e157740

File tree

3 files changed

+48
-0
lines changed

3 files changed

+48
-0
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
.example-box.cdk-drag-animating {
2+
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
3+
}
4+
5+
.example-chip .cdk-drop-list-dragging {
6+
transition: transform 250ms cubic-bezier(0, 0, 0.2, 1);
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<mat-chip-list
2+
class="example-chip"
3+
cdkDropList
4+
cdkDropListOrientation="horizontal"
5+
(cdkDropListDropped)="drop($event)">
6+
<mat-chip
7+
class="example-box"
8+
cdkDrag
9+
*ngFor="let vegetable of vegetables">
10+
{{vegetable.name}}
11+
</mat-chip>
12+
</mat-chip-list>
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import {CdkDragDrop, moveItemInArray} from '@angular/cdk/drag-drop';
2+
import {Component} from '@angular/core';
3+
4+
export interface Vegetable {
5+
name: string;
6+
}
7+
8+
/**
9+
* @title Chips Drag and Drop
10+
*/
11+
@Component({
12+
selector: 'chips-drag-drop-example',
13+
templateUrl: 'chips-drag-drop-example.html',
14+
styleUrls: ['chips-drag-drop-example.css']
15+
})
16+
export class ChipsDragDropExample {
17+
vegetables: Vegetable[] = [
18+
{name: 'apple'},
19+
{name: 'banana'},
20+
{name: 'strawberry'},
21+
{name: 'orange'},
22+
{name: 'kiwi'},
23+
{name: 'cherry'},
24+
];
25+
26+
drop(event: CdkDragDrop<Vegetable[]>) {
27+
moveItemInArray(this.vegetables, event.previousIndex, event.currentIndex);
28+
}
29+
}

0 commit comments

Comments
 (0)