Skip to content

Commit

Permalink
docs - update the readme to show how to use stackConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
ksachdeva committed Aug 18, 2016
1 parent 309461e commit 7419f3d
Showing 1 changed file with 15 additions and 1 deletion.
16 changes: 15 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ npm install angular2-swing --save
import {Component, ViewChild, ViewChildren, QueryList} from '@angular/core';
import {
StackConfig,
Stack,
Card,
ThrowEvent,
Expand All @@ -20,7 +21,7 @@ import {
directives: [SwingStackComponent, SwingCardComponent],
template: `
<div id="viewport">
<ul class="stack" swing-stack #myswing1 (throwout)="onThrowOut($event)">
<ul class="stack" swing-stack [stackConfig]="stackConfig" #myswing1 (throwout)="onThrowOut($event)">
<li swing-card #mycards1 [ngClass]="c.name" *ngFor="let c of cards">{{ c.symbol }}</li>
</ul>
</div>
Expand All @@ -43,9 +44,19 @@ export class App {
@ViewChildren('mycards1') swingCards: QueryList<SwingCardComponent>;
cards: Array<any>;
stackConfig: StackConfig;
constructor() {
this.stackConfig = {
throwOutConfidence: (offset: number, targetElement: HTMLElement) => {
// you would put ur logic based on offset & targetelement to determine
// what is your throwout confidence
return 1;
},
minThrowOutDistance: 700 // default value is 400
};
this.cards = [
{ name: 'clubs', symbol: '♣' },
{ name: 'diamonds', symbol: '♦' },
Expand Down Expand Up @@ -74,6 +85,8 @@ export class App {
(event: ThrowEvent) => console.log('Manual hook: ', event));
this.swingStack.dragstart.subscribe((event: DragEvent) => console.log(event));
this.swingStack.dragmove.subscribe((event: DragEvent) => console.log(event));
}
// This method is called by hooking up the event
Expand All @@ -83,6 +96,7 @@ export class App {
}
}
```

See [angular2-swing-example](https://github.com/ksachdeva/angular2-swing-example) repository for the full example

0 comments on commit 7419f3d

Please sign in to comment.