-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Example: Reordering
- Loading branch information
Showing
7 changed files
with
108 additions
and
2 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
@@ -1,5 +1,8 @@ | ||
# Changelog | ||
|
||
## 1.0.2+1 | ||
- New example: Reordering | ||
|
||
## 1.0.2 | ||
- Live examples | ||
|
||
|
This file contains 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
This file contains 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,56 @@ | ||
import 'package:angular2/angular2.dart'; | ||
|
||
import '../../common.dart'; | ||
|
||
@Component( | ||
selector: 'drag-drop-example-22', | ||
templateUrl: 'drag_drop_22.html', | ||
styleUrls: const ['drag_drop_22.css'], | ||
directives: const [ | ||
CORE_DIRECTIVES, | ||
DRAG_DROP_DIRECTIVES, | ||
BasketComponent, | ||
FruitComponent | ||
] | ||
) | ||
class DragDropExample22Component { | ||
|
||
final FruitFactory fruits; | ||
final ExampleEventsHandler handler; | ||
final Basket<FruitModel> basket = new Basket<FruitModel>(); | ||
|
||
|
||
DragOptions dragOptions = new DragOptions( | ||
selector: 'fruit-component' | ||
); | ||
|
||
DropOptions dropOptions = new DropOptions( | ||
selector: '.fruit-wrapper', | ||
canEnter: (DragSource source) => source.model is FruitModel | ||
); | ||
|
||
DragDropExample22Component(this.fruits, this.handler) { | ||
basket.addAll(fruits.getFruits(7)); | ||
} | ||
|
||
MovementDirection _movementDirection; | ||
bool get movingLeft => _movementDirection?.x == MovementDirectionType.negative; | ||
bool get movingRight => _movementDirection?.x == MovementDirectionType.positive; | ||
|
||
void onDragOver(DragOverEvent event) { | ||
_movementDirection = event.movement.direction; | ||
} | ||
|
||
void onDrop(DropEvent event) { | ||
FruitModel fruit = event.source.model; | ||
FruitModel anchorFruit = event.target.model; | ||
|
||
basket.items.remove(fruit); | ||
int pos = basket.items.indexOf(anchorFruit); | ||
if (movingRight) { | ||
pos++; | ||
} | ||
basket.items.insert(pos, fruit); | ||
} | ||
|
||
} |
This file contains 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,21 @@ | ||
<h2>Drag Drop Example 22: Reorder items</h2> | ||
<p>Due to the declarative approach of Angular, | ||
we must do reordering the same way by configuring drop-target for each place where the item can be dropped.</p> | ||
|
||
<basket-component [basket]="basket" | ||
[drag-options]="dragOptions" | ||
[drop-options]="dropOptions" | ||
(onDragOver)="onDragOver($event)" | ||
(onDrop)="onDrop($event)" | ||
[class.shift-left]="movingLeft" | ||
[class.shift-right]="movingRight" | ||
> | ||
<div *ngFor="let fruit of basket.items" | ||
class="fruit-wrapper" | ||
[drag-drop-model]="fruit" | ||
> | ||
<fruit-component [model]="fruit" | ||
[drag-drop-model]="fruit" | ||
></fruit-component> | ||
</div> | ||
</basket-component> |
This file contains 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,23 @@ | ||
|
||
:host { | ||
display: block; | ||
|
||
.fruit-wrapper { | ||
padding-right: 6px; | ||
display: inline-block; | ||
transition: padding 0.1s; | ||
} | ||
|
||
basket-component.drag-drop-container-over.shift-left { | ||
.fruit-wrapper.drop-target-over-valid { | ||
padding-left: 40px; | ||
} | ||
} | ||
|
||
basket-component.drag-drop-container-over.shift-right { | ||
.fruit-wrapper.drop-target-over-valid { | ||
padding-right: 40px; | ||
} | ||
} | ||
|
||
} |
This file contains 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
This file contains 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