-
Notifications
You must be signed in to change notification settings - Fork 11
feat: Draggable List #1483
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: Draggable List #1483
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7b3f03a
Dragganble List in progress
77847a0
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Dragg…
c0e0556
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Dragg…
c6524fc
feat: add draggable list
32e07e5
feat: fixing lint
7877340
feat: fixing lint
321a0d7
feat: fix prettier
cf92ffb
feat: adding disabled styles and modify child component
9bc4e35
feat: adding T to draggable list
e7891cf
Merge branch 'main' of github.com:hypertrace/hypertrace-ui into Dragg…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
15 changes: 15 additions & 0 deletions
15
projects/components/src/draggable-list/draggable-item/draggable-item.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| import { ChangeDetectionStrategy, Component, Input } from '@angular/core'; | ||
| import { ContentHolder, CONTENT_HOLDER_TEMPLATE } from '../../public-api'; | ||
|
|
||
| @Component({ | ||
| selector: 'ht-draggable-item', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| template: CONTENT_HOLDER_TEMPLATE | ||
| }) | ||
| export class DraggableItemComponent<T> extends ContentHolder { | ||
| @Input() | ||
| public disabled: boolean = false; | ||
|
|
||
| @Input() | ||
| public data?: T; | ||
| } |
11 changes: 11 additions & 0 deletions
11
projects/components/src/draggable-list/draggable-list.component.scss
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,11 @@ | ||
| @import 'color-palette'; | ||
|
|
||
| .draggable-list .draggable-item { | ||
| cursor: move; | ||
|
|
||
| &.disabled { | ||
| background-color: $gray-2; | ||
| color: $gray-5; | ||
| cursor: not-allowed; | ||
| } | ||
| } |
52 changes: 52 additions & 0 deletions
52
projects/components/src/draggable-list/draggable-list.component.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import { CdkDragDrop, moveItemInArray } from '@angular/cdk/drag-drop'; | ||
| import { | ||
| AfterContentInit, | ||
| ChangeDetectionStrategy, | ||
| Component, | ||
| ContentChildren, | ||
| EventEmitter, | ||
| Input, | ||
| Output, | ||
| QueryList | ||
| } from '@angular/core'; | ||
| import { DraggableItemComponent } from './draggable-item/draggable-item.component'; | ||
|
|
||
| @Component({ | ||
| selector: 'ht-draggable-list', | ||
| changeDetection: ChangeDetectionStrategy.OnPush, | ||
| styleUrls: ['./draggable-list.component.scss'], | ||
| template: ` | ||
| <div cdkDropList class="draggable-list" (cdkDropListDropped)="this.dropList($event)"> | ||
| <div | ||
| *ngFor="let draggableItem of this.draggableItems" | ||
| cdkDrag | ||
| class="draggable-item" | ||
| [ngClass]="{ disabled: disabled || draggableItem.disabled }" | ||
| [cdkDragDisabled]="disabled || draggableItem.disabled" | ||
| > | ||
| <ng-container *ngTemplateOutlet="draggableItem.content"></ng-container> | ||
| </div> | ||
| </div> | ||
| ` | ||
| }) | ||
| export class DraggableListComponent<T> implements AfterContentInit { | ||
| @Input() | ||
| public disabled: boolean = false; | ||
|
|
||
| @Output() | ||
| public readonly draggableListChange: EventEmitter<T[]> = new EventEmitter(); | ||
|
|
||
| @ContentChildren(DraggableItemComponent) | ||
| public draggableItemsRef!: QueryList<DraggableItemComponent<T>>; | ||
|
|
||
| public draggableItems: DraggableItemComponent<T>[] = []; | ||
|
|
||
| public ngAfterContentInit(): void { | ||
| this.draggableItems = this.draggableItemsRef.toArray(); | ||
| } | ||
|
|
||
| public dropList(event: CdkDragDrop<DraggableItemComponent<unknown>[]>): void { | ||
| moveItemInArray(this.draggableItems, event.previousIndex, event.currentIndex); | ||
| this.draggableListChange.emit(this.draggableItems.map(dragabbleItem => dragabbleItem.data!)); | ||
| } | ||
| } | ||
12 changes: 12 additions & 0 deletions
12
projects/components/src/draggable-list/draggable-list.module.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import { DragDropModule } from '@angular/cdk/drag-drop'; | ||
| import { CommonModule } from '@angular/common'; | ||
| import { NgModule } from '@angular/core'; | ||
| import { DraggableItemComponent } from './draggable-item/draggable-item.component'; | ||
| import { DraggableListComponent } from './draggable-list.component'; | ||
|
|
||
| @NgModule({ | ||
| declarations: [DraggableListComponent, DraggableItemComponent], | ||
| imports: [CommonModule, DragDropModule], | ||
| exports: [DraggableListComponent, DraggableItemComponent] | ||
| }) | ||
| export class DraggableListModule {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.