Skip to content

Commit cf92ffb

Browse files
Patricio AlbizuPatricio Albizu
authored andcommitted
feat: adding disabled styles and modify child component
1 parent 321a0d7 commit cf92ffb

File tree

3 files changed

+29
-16
lines changed

3 files changed

+29
-16
lines changed
Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,15 @@
1-
import { ChangeDetectionStrategy, Component, Input, TemplateRef, ViewChild } from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, Input } from '@angular/core';
2+
import { ContentHolder, CONTENT_HOLDER_TEMPLATE } from '../../public-api';
23

34
@Component({
45
selector: 'ht-draggable-item',
56
changeDetection: ChangeDetectionStrategy.OnPush,
6-
template: `
7-
<ng-template #draggableItem>
8-
<ng-content></ng-content>
9-
</ng-template>
10-
`
7+
template: CONTENT_HOLDER_TEMPLATE
118
})
12-
export class DraggableItemComponent {
13-
@ViewChild('draggableItem', { static: true })
14-
public content!: TemplateRef<unknown>;
15-
9+
export class DraggableItemComponent<T> extends ContentHolder {
1610
@Input()
1711
public disabled: boolean = false;
12+
13+
@Input()
14+
public data?: T;
1815
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
@import 'color-palette';
2+
3+
.draggable-list .draggable-item {
4+
cursor: move;
5+
6+
&.disabled {
7+
background-color: $gray-2;
8+
color: $gray-5;
9+
cursor: not-allowed;
10+
}
11+
}

projects/components/src/draggable-list/draggable-list.component.ts

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,14 @@ import { DraggableItemComponent } from './draggable-item/draggable-item.componen
1414
@Component({
1515
selector: 'ht-draggable-list',
1616
changeDetection: ChangeDetectionStrategy.OnPush,
17+
styleUrls: ['./draggable-list.component.scss'],
1718
template: `
18-
<div cdkDropList class="example-list" (cdkDropListDropped)="dropList($event)">
19+
<div cdkDropList class="draggable-list" (cdkDropListDropped)="this.dropList($event)">
1920
<div
2021
*ngFor="let draggableItem of this.draggableItems"
2122
cdkDrag
23+
class="draggable-item"
24+
[ngClass]="{ disabled: disabled || draggableItem.disabled }"
2225
[cdkDragDisabled]="disabled || draggableItem.disabled"
2326
>
2427
<ng-container *ngTemplateOutlet="draggableItem.content"></ng-container>
@@ -31,19 +34,21 @@ export class DraggableListComponent implements AfterContentInit {
3134
public disabled: boolean = false;
3235

3336
@Output()
34-
public readonly listOrderChange: EventEmitter<DraggableItemComponent[]> = new EventEmitter();
37+
public readonly draggableListChange: EventEmitter<unknown> = new EventEmitter();
3538

3639
@ContentChildren(DraggableItemComponent)
37-
public draggableItemsRef!: QueryList<DraggableItemComponent>;
40+
public draggableItemsRef!: QueryList<DraggableItemComponent<unknown>>;
3841

39-
public draggableItems: DraggableItemComponent[] = [];
42+
public draggableItems: DraggableItemComponent<unknown>[] = [];
4043

4144
public ngAfterContentInit(): void {
4245
this.draggableItems = this.draggableItemsRef.toArray();
4346
}
4447

45-
public dropList(event: CdkDragDrop<DraggableItemComponent[]>): void {
48+
public dropList(event: CdkDragDrop<DraggableItemComponent<unknown>[]>): void {
4649
moveItemInArray(this.draggableItems, event.previousIndex, event.currentIndex);
47-
this.listOrderChange.emit(this.draggableItems);
50+
this.draggableListChange.emit(
51+
this.draggableItems.find((_dragabbleItem, index) => event.currentIndex === index)?.data
52+
);
4853
}
4954
}

0 commit comments

Comments
 (0)